Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Finish cleaning up apparent wikitransfer damage to code blocks

...

Code Block
public interface ItemDAO extends ContentDAO
implements CRUD<Item>, Link<Item, Bundle>
{
  public Item create(); throws AuthorizeException;
  public Item retrieve(int id);
  public Item retrieve(UUID uuid);
  public void update(Item item); throws AuthorizeException;
  public void delete(int id); throws AuthorizeException;
  public List<Item> getItems();
  public List<Item> getItemsBySubmitter(EPerson eperson);
  public List<Item> getItemsByCollection(Collection collection);
  public List<Item> getParentItems(Bundle bundle); 
}


org.dspace.content.dao.ItemDAOFactory

Code Block
public class ItemDAOFactory
{
  public static ItemDAO getInstance(Context context)
  { // Eventually, the implementation that is returned will be
    // defined in the configuration.
    return new ItemDAOPostgres(context);
  }}
}

org.dspace.content.dao.postgres.ItemDAOPostgres

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: Panelunmigrated-wiki-markup

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 <code>ItemIterator</code>s, and to generally make things a little more consistent with the rest of the code (this looks almost identical to, eg, CollectionDAO.getCollections().

...

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.

&nbsp;
public class ArchiveManager
&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;
{
    public static void withdrawItem(Context context, Item item)
&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    {        // ...
&nbsp;&nbsp;&nbsp;&nbsp;
      }
&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;

    public static void reinstateItem(Context context, Item item)
&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    {        // ...
&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
      }
    public static void moveItem(Context context,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 Item item, Collection source, Collection dest)
&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    {        // ...
&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;
      }
}
Code Block

Panel
Wiki Markup

org.dspace.storage

org.dspace.storage.dao.GlobalDAO

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.

&nbsp;
public interface GlobalDAO
&nbsp;
{
&nbsp;&nbsp;&nbsp;&nbsp;

    // The following methods actually currently throw SQLExceptions to
&nbsp;&nbsp;&nbsp;&nbsp;

    // keep things simple, but in future SQLExceptions should be
&nbsp;&nbsp;&nbsp;&nbsp;

    // eliminated from any code that doesn't directly touch a database.
&nbsp;&nbsp;&nbsp;&nbsp;

    public void startTransaction() throws GlobalDAOException;
&nbsp;&nbsp;&nbsp;&nbsp;

    public void endTransaction() throws GlobalDAOException;
&nbsp;&nbsp;&nbsp;&nbsp;

    public void saveTransaction() throws GlobalDAOException;
&nbsp;&nbsp;&nbsp;&nbsp;

    public void abortTransaction();
&nbsp;&nbsp;&nbsp;&nbsp;

    public boolean transactionOpen();
&nbsp;&nbsp;&nbsp;&nbsp;

    @Deprecated Connection getConnection();
&nbsp;

}
Code Block

Panel
Wiki Markup

org.dspace.storage.dao.GlobalDAOFactory

...

Implementation of the GlobalDAO interface for PostgreSQL. Panel Wiki Markup&nbsp;

Code Block

public class GlobalDAOPostgres implements GlobalDAO

...

{
    private Connection connection;

...


    // ...

...


    public void startTransaction()

...

    {
         connection = DatabaseManager.getConnection();
         connection.setAutoCommit(false)

...


    // ...

...


}