com.compomics.util.db.interfaces
Interface DBElement


public interface DBElement

This interface indicates that the implementing class can be stored, manipulated and deleted in a permanent storage (typically a RDBMS).

Author:
Lennart Martens

Method Summary
 HashMap getAllProperties()
          This method will return a HashMap with all the properties for this DBElement.
 boolean isChanged()
          This method signals whether the DBElement has changes that should be persisted.
 boolean isDeleted()
          This method signals whether the DBElement has been deleted in the persistent store.
 boolean isToBeDeleted()
          This method signals whether the DBElement is marked for deletion.
 void load(Connection aConn, HashMap ahmKeys)
          This method should be called to fill the DBElement with current data as present in the database.
 int remove(Connection aConn)
          This method provides a convenient short-cut to delete the DBElement from the persistent store.
 int save(Connection aConn)
          This method can be called when changes need to be persisted.
 

Method Detail

load

void load(Connection aConn,
          HashMap ahmKeys)
          throws SQLException
This method should be called to fill the DBElement with current data as present in the database. The HashMap should contain the correct keys and corresponding values to construct the primary key for this DBElement. The keys should be stated in the implementation class as public static final variables so errors in these matters can be minimized.

Parameters:
aConn - The Connection on which to execute SQL statements. It should be an open connection and the implementation should refrain from closing it, so the caller can reuse it.
ahmKeys - HashMap with the 'key-value' pairs necessary for the construction of the primary key for the DBElement to be retrieved.
Throws:
SQLException - When the retrieve fails (e.g.: PK does not exist).

save

int save(Connection aConn)
         throws SQLException
This method can be called when changes need to be persisted. This method should be able to determine the nature of the persistence operation to be performed (INSERT, UPDATE or DELETE). How this is done is up to the implementation, yet the caller must be assured that the correct operation is executed.

Parameters:
aConn - The Connection on which to execute SQL statements. It should be an open connection and the implementation should refrain from closing it, so the caller can reuse it.
Throws:
SQLException - When the save fails (e.g.: Connection gone stale).

remove

int remove(Connection aConn)
           throws SQLException
This method provides a convenient short-cut to delete the DBElement from the persistent store. It is particularly interesting to use if the implementation has no clear mechanism to flag a DBElement for deletion, thereby preventing the 'save' method from acting as a DELETE call.

Parameters:
aConn - The Connection on which to execute SQL statements. It should be an open connection and the implementation should refrain from closing it, so the caller can reuse it.
Throws:
SQLException - When the save fails (e.g.: PK not found).

getAllProperties

HashMap getAllProperties()
This method will return a HashMap with all the properties for this DBElement. The keys in this HashMap should be stated as public static final variables on the implementation class.

Returns:
HashMap with all the properties, associated with their corresponding keys, as defined in the implementation class.

isChanged

boolean isChanged()
This method signals whether the DBElement has changes that should be persisted.

Returns:
boolean Is this DBElement changed as compared to the original entry, retrieved from the DB?

isToBeDeleted

boolean isToBeDeleted()
This method signals whether the DBElement is marked for deletion.

Returns:
boolean Is this DBElement marked for deletion from the DB?

isDeleted

boolean isDeleted()
This method signals whether the DBElement has been deleted in the persistent store.

Returns:
boolean Is this DBElement deleted from the DB?


Copyright © 2011. All Rights Reserved.