Page History
...
Note that it might be preferable to have a more generic implementation of the ItemDAO
interface that supports both PostgreSQL and Oracle, but given that one motivation for adopting DAOs is to remove db-specificities from the code making it easier to port, I thought it was sensible to start with just PostgreSQL. Eventually, it ought to be possible to drop in ItemDAOHibernate
(etc) implementations that make db portability far easier.
...
Basic implementation of the Item object. This class has been stripped down to remove all contact with the database, including (but not limited to) contstructors, factory methods, update()
, delete()
, find()
, etc. I haven't decided exactly how the Item API will look, but it will probably be much the same as before, only with any of the aforementioned methods. Another key difference is that it will have actual Java objects as member variables instead of pulling everything out of a TableRow
.
org.dspace.content.proxy.ItemProxy
This will be a fairly simple proxy implementation. Specifically, it will be closest to being a virtual proxy, in that it will appear to be a regular Item
object, but will have a slightly smarter implementation (not loading metadata until requested, keeping track of what has changed to make updates more efficient etc).
...
This is a fairly straightforward implementation of the above interface. As much as possible, code from the original Item
class will be used. For instance, this is how getItems()
is implemented:
Code Block |
---|
public List<Item> getItems() { try { TableRowIterator tri = DatabaseManager.queryTable(context, "item", "SELECT item_id FROM item WHERE in_archive = '1'"); List<Item> items = new ArrayList<Item>(); for (TableRow row : tri.toList()) { int id = row.getIntColumn("item_id"); items.add(retrieve(id)); } return items; } catch (SQLException sqle){ // Need to think more carefully about how we deal with SQLExceptions throw new RuntimeException(sqle); } } |
Some changes have been made to eliminate {{ItemIterator
}}s, and to generally make things a little more consistent with the rest of the code (this looks almost identical to, eg, CollectionDAO.getCollections()
.
org.dspace.core
org.dspace.core.ArchiveManager
The idea behind this class came from the realisation that Item.withdraw()
and Item.reinstate()
don't really make sense. What I'd much rather do is call (eg) ArchiveManager.withdrawItem(Item item)
.
I've been thinking that the ArchiveManager
could be used for certain maintenance operations as well, such as moving Items
between Collections
, and maybe acting as a wrapper for the CommunityFiliator
.
Code Block |
---|
public class ArchiveManager { public static void withdrawItem(Context context, Item item) { // ... } public static void reinstateItem(Context context, Item item) { // ... } public static void moveItem(Context context, Item item, Collection source, Collection dest) { // ... } } |
...
As suggested by Richard Jones, there probably ought to be a top-level general-purpose DAO interface that has implementations for the various storage mechanisms (GlobalDAOPostgres
etc). The idea is to have this top-level object capture any implementation-specific details in a single top-level object, rather than in every Postgres DAO implementation. For example, with the current database "abstraction layer", the top-level implementation of GlobalDAO
understands the Context
object, whereas a Hibernate implementation would know what a SessionFactory
is.
Code Block |
---|
public interface GlobalDAO { // The following methods actually currently throw SQLExceptions to // keep things simple, but in future SQLExceptions should be // eliminated from any code that doesn't directly touch a database. public void startTransaction() throws GlobalDAOException; public void endTransaction() throws GlobalDAOException; public void saveTransaction() throws GlobalDAOException; public void abortTransaction(); public boolean transactionOpen(); @Deprecated Connection getConnection(); } |
org.dspace.storage.dao.GlobalDAOFactory
Super-simple GlobalDAO
factory.
org.dspace.storage.dao.GlobalDAOPostgres
Implementation of the GlobalDAO
interface for PostgreSQL.
...