gov.nih.nci.caarray.services.util.db
Class ManagerDB

java.lang.Object
  extended by gov.nih.nci.caarray.services.util.db.ManagerDB
Direct Known Subclasses:
AdminManagerDB, ArrayDesignFinder, ArrayDesignManagerDB, ArrayManagerDB, BioMaterialManagerDB, CompositeGroupManagerDB, ContactManagerDB, DesignElementManagerDB, ExperimentManagerDB, FeatureGroupManagerDB, FileParseManagerDB, FileUploadManagerDB, HardwareManagerDB, HybridizationManagerDB, IlluminaDataHandlerDataSourceManagerDB, JMSMessageManagerDB, MAGEManagerDB, MAGEMLExportManagerDB, MAGEMLImportManagerDB, MeasurementManagerDB, ProtocolManagerDB, QuantitationTypeManagerDB, ReporterGroupManagerDB, SecurityAdminService, SoftwareManagerDB, VocabManagerDB, ZoneGroupManagerDB

public abstract class ManagerDB
extends java.lang.Object

The super class of all ManagerDB classes to allow common OJB operations to be shared.

Author:
TranP

Field Summary
protected static int CASCADE_LINK
           
protected static int CASCADE_NONE
           
protected static int CASCADE_OBJECT
           
protected static long ID_UNSET
           
 
Constructor Summary
protected ManagerDB()
          Creates a new instance of ManagerDB
protected ManagerDB(java.lang.String profileName)
          Creates a new instance of ManagerDB
 
Method Summary
 void clearCache()
          clears the cache Fix for TT13110
 void close()
          Close database connection.
protected  long countObjects(org.apache.ojb.broker.query.Query query)
          Count the number of objects that match the specified Query.
protected  long countObjects(org.apache.ojb.broker.query.Query query, org.apache.ojb.broker.PersistenceBroker broker)
          Count the number of objects that match the specified Query.
protected  void deleteByQuery(org.apache.ojb.broker.query.Query query)
          Delegates to OJB's deleteByQuery which executes a DELETE query.
protected  boolean deleteMtoNRelation(java.lang.Object leftObject, java.lang.Object rightObject, java.lang.String collectionFieldName)
          Deletes a many-to-many association between two objects.
protected  boolean deleteObject(java.lang.Class clazz, java.lang.Object id)
          Deletes the object given its class type and ID.
protected  boolean deleteObject(java.lang.Object obj)
          Deletes an object.
protected  boolean deleteObject(java.lang.Object obj, org.apache.ojb.broker.PersistenceBroker broker)
          Deletes an object.
protected  boolean deleteObjectByQuery(org.apache.ojb.broker.query.Query query)
          Deletes an object by query.
 boolean exists(java.lang.Class clazz, java.lang.Object id)
          Check if the specified object that matches the specified ID and is of the specified Class type exists.
 Identifiable getIdentifiable(java.lang.Class identifiableClass, java.lang.String identifier)
           
 java.lang.Object getObject(java.lang.Class realClazz, java.lang.Class topLevelClazz, java.lang.Object id)
          Gets an object of the specified class that matches the specified ID.
protected  java.lang.Object getObject(java.lang.Class realClazz, java.lang.Class topLevelClazz, java.lang.Object id, org.apache.ojb.broker.PersistenceBroker broker)
          Gets an object of the specified class that matches the specified ID.
 java.lang.Object getObject(java.lang.Class clazz, java.lang.Object id)
          Gets an object of the specified class that matches the specified ID.
 java.lang.Object getObject(java.lang.Class clazz, java.lang.Object id, org.apache.ojb.broker.PersistenceBroker broker)
          Gets an object of the specified class that matches the specified ID.
protected  java.lang.Object getObject(org.apache.ojb.broker.query.Query query)
          This method will return a single object that matches the specified query.
protected  java.lang.Object getObject(org.apache.ojb.broker.query.Query query, org.apache.ojb.broker.PersistenceBroker broker)
          This method will return a single object that matches the specified query.
protected  java.util.Iterator getObjectIterator(org.apache.ojb.broker.query.Query query)
           
protected  java.util.Iterator getObjectIterator(org.apache.ojb.broker.query.Query query, org.apache.ojb.broker.PersistenceBroker broker)
          This method will return a lazy loading Iterator that materializes the object that meet the specification of the specified query each time the next() method is invoked.
 java.lang.Object[] getObjects(java.lang.Class clazz)
          Retrieve an array of objects of the specified class type.
protected  java.lang.Object[] getObjects(org.apache.ojb.broker.query.Query query)
          This method will return a collection of objects that meets the specified query.
protected  java.lang.Object[] getObjects(org.apache.ojb.broker.query.Query query, org.apache.ojb.broker.PersistenceBroker broker)
          This method will return a collection of objects that meets the specified query.
protected  org.apache.ojb.broker.PersistenceBroker getPersistenceBroker()
          Gets a PersistenceBroker from the pool for the default profile.
static int getSqlInLimit()
           
protected  boolean insertMtoNRelation(java.lang.Object leftObject, java.lang.Object rightObject, java.lang.String collectionFieldName)
          Inserts a many-to-many association between two objects.
protected  boolean insertMtoNRelation(java.lang.Object leftObject, java.lang.Object rightObject, java.lang.String collectionFieldName, boolean forceInsertAsNew)
           
protected  org.apache.ojb.broker.Identity insertObject(java.lang.Object obj)
          Inserts an object.
protected  org.apache.ojb.broker.Identity insertObject(java.lang.Object obj, org.apache.ojb.broker.PersistenceBroker broker)
           
 void link(java.lang.Object pInstance, boolean insert)
           
 void link(java.lang.Object pInstance, java.lang.String attributeName, boolean insert)
           
 void removeFromCache(java.lang.Object objectOrIdentity)
           
 void retrieveReference(java.lang.Object pInstance, java.lang.String attributeName)
           
 void retrieveReferences(java.lang.Object pInstance)
           
protected  int setCascadeDelete(org.apache.ojb.broker.PersistenceBroker broker, java.lang.Class theClass, java.lang.String referenceName, int cascadeValue)
           
protected  boolean setCascadeRetrieve(org.apache.ojb.broker.PersistenceBroker broker, java.lang.Class theClass, java.lang.String referenceName, boolean cascadeValue)
           
protected  int setCascadeStore(org.apache.ojb.broker.PersistenceBroker broker, java.lang.Class theClass, java.lang.String referenceName, int cascadeValue)
           
protected  org.apache.ojb.broker.Identity storeObject(java.lang.Object obj)
          Inserts or updates an object.
protected  org.apache.ojb.broker.Identity storeObject(java.lang.Object obj, org.apache.ojb.broker.PersistenceBroker broker)
           
 void unlink(java.lang.Object pInstance)
           
 void unlink(java.lang.Object pInstance, java.lang.String attributeName)
           
protected  boolean updateObject(java.lang.Object obj)
          Updates an object.
protected  boolean updateObject(java.lang.Object obj, org.apache.ojb.broker.PersistenceBroker broker)
          Updates an object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CASCADE_OBJECT

protected static final int CASCADE_OBJECT
See Also:
Constant Field Values

CASCADE_LINK

protected static final int CASCADE_LINK
See Also:
Constant Field Values

CASCADE_NONE

protected static final int CASCADE_NONE
See Also:
Constant Field Values

ID_UNSET

protected static final long ID_UNSET
See Also:
Constant Field Values
Constructor Detail

ManagerDB

protected ManagerDB()
Creates a new instance of ManagerDB


ManagerDB

protected ManagerDB(java.lang.String profileName)
Creates a new instance of ManagerDB

Method Detail

countObjects

protected long countObjects(org.apache.ojb.broker.query.Query query)
Count the number of objects that match the specified Query.

Parameters:
query - - The query to be matched against
Returns:
- The number of how many objects that match

countObjects

protected long countObjects(org.apache.ojb.broker.query.Query query,
                            org.apache.ojb.broker.PersistenceBroker broker)
Count the number of objects that match the specified Query.

Parameters:
query - - The query to be matched against
Returns:
- The number of how many objects that match

getObject

protected java.lang.Object getObject(org.apache.ojb.broker.query.Query query,
                                     org.apache.ojb.broker.PersistenceBroker broker)
                              throws java.lang.Exception
This method will return a single object that matches the specified query.

Parameters:
The - query to include any criteria for searching an object of a specific class.
Throws:
java.lang.Exception

getObject

protected java.lang.Object getObject(org.apache.ojb.broker.query.Query query)
                              throws java.lang.Exception
This method will return a single object that matches the specified query.

Parameters:
The - query to include any criteria for searching an object of a specific class.
Throws:
java.lang.Exception

getObjects

protected java.lang.Object[] getObjects(org.apache.ojb.broker.query.Query query)
                                 throws java.lang.Exception
This method will return a collection of objects that meets the specified query.

Parameters:
query - - The query to include any criteria for searching objects of a specific class as a collection
Throws:
java.lang.Exception

getObjects

protected java.lang.Object[] getObjects(org.apache.ojb.broker.query.Query query,
                                        org.apache.ojb.broker.PersistenceBroker broker)
                                 throws java.lang.Exception
This method will return a collection of objects that meets the specified query.

Parameters:
query - - The query to include any criteria for searching objects of a specific class as a collection
Throws:
java.lang.Exception

getObjects

public java.lang.Object[] getObjects(java.lang.Class clazz)
                              throws java.lang.Exception
Retrieve an array of objects of the specified class type.

Parameters:
clazz -
Returns:
Throws:
DBException
java.lang.Exception

getObjectIterator

protected java.util.Iterator getObjectIterator(org.apache.ojb.broker.query.Query query,
                                               org.apache.ojb.broker.PersistenceBroker broker)
                                        throws java.lang.Exception
This method will return a lazy loading Iterator that materializes the object that meet the specification of the specified query each time the next() method is invoked.

Parameters:
query - - The query to include any criteria for searching objects of a specific class as a collection
Returns:
An Iterator if the result set contains at least one matched object or null otherwise.
Throws:
java.lang.Exception

getObjectIterator

protected java.util.Iterator getObjectIterator(org.apache.ojb.broker.query.Query query)
                                        throws java.lang.Exception
Throws:
java.lang.Exception

updateObject

protected boolean updateObject(java.lang.Object obj,
                               org.apache.ojb.broker.PersistenceBroker broker)
Updates an object.

Parameters:
obj - - The object to be updated
Returns:
- True if the passed object was updated; false otherwise.

updateObject

protected boolean updateObject(java.lang.Object obj)
Updates an object.

Parameters:
obj - - The object to be updated
Returns:
- True if the passed object was updated; false otherwise.

storeObject

protected org.apache.ojb.broker.Identity storeObject(java.lang.Object obj)
                                              throws java.lang.Exception
Inserts or updates an object.

Parameters:
obj - - The object to be inserted
Returns:
- An Identity object that represents the primary key of the stored object. If the passed object is null, null is returned.
Throws:
java.lang.Exception

storeObject

protected org.apache.ojb.broker.Identity storeObject(java.lang.Object obj,
                                                     org.apache.ojb.broker.PersistenceBroker broker)
                                              throws java.lang.Exception
Throws:
java.lang.Exception

insertObject

protected org.apache.ojb.broker.Identity insertObject(java.lang.Object obj)
                                               throws java.lang.Exception
Inserts an object.

Parameters:
obj - - The object to be updated
Returns:
- An Identity object that represents the primary key of the stored object. If the passed object is null, null is returned.
Throws:
java.lang.Exception

insertObject

protected org.apache.ojb.broker.Identity insertObject(java.lang.Object obj,
                                                      org.apache.ojb.broker.PersistenceBroker broker)
                                               throws java.lang.Exception
Throws:
java.lang.Exception

deleteObject

protected boolean deleteObject(java.lang.Object obj)
                        throws java.lang.Exception
Deletes an object.

Parameters:
obj -
useTransaction -
Returns:
Throws:
java.lang.Exception

deleteObject

protected boolean deleteObject(java.lang.Object obj,
                               org.apache.ojb.broker.PersistenceBroker broker)
                        throws java.lang.Exception
Deletes an object.

Parameters:
obj -
broker -
Returns:
Throws:
java.lang.Exception

deleteObjectByQuery

protected boolean deleteObjectByQuery(org.apache.ojb.broker.query.Query query)
                               throws java.lang.Exception
Deletes an object by query.

Parameters:
query -
Returns:
True if at least one object is deleted successfully and false otherwise.
Throws:
DBException
java.lang.Exception

deleteByQuery

protected void deleteByQuery(org.apache.ojb.broker.query.Query query)
                      throws java.lang.Exception
Delegates to OJB's deleteByQuery which executes a DELETE query.

Parameters:
query -
Throws:
DBException
java.lang.Exception

deleteMtoNRelation

protected boolean deleteMtoNRelation(java.lang.Object leftObject,
                                     java.lang.Object rightObject,
                                     java.lang.String collectionFieldName)
Deletes a many-to-many association between two objects.

Parameters:
leftObject -
rightObject -
Returns:

insertMtoNRelation

protected boolean insertMtoNRelation(java.lang.Object leftObject,
                                     java.lang.Object rightObject,
                                     java.lang.String collectionFieldName)
Inserts a many-to-many association between two objects.

Parameters:
leftObject -
rightObject -
collectionFieldName -
Returns:

insertMtoNRelation

protected boolean insertMtoNRelation(java.lang.Object leftObject,
                                     java.lang.Object rightObject,
                                     java.lang.String collectionFieldName,
                                     boolean forceInsertAsNew)

getPersistenceBroker

protected org.apache.ojb.broker.PersistenceBroker getPersistenceBroker()
Gets a PersistenceBroker from the pool for the default profile.

Returns:
A PersistenceBroker instance.

getObject

public java.lang.Object getObject(java.lang.Class realClazz,
                                  java.lang.Class topLevelClazz,
                                  java.lang.Object id)
                           throws java.lang.Exception
Gets an object of the specified class that matches the specified ID.
Warning: Because the broker is closed when the method returns, lazy loading associations are not accessible from the returned object.

Parameters:
realClazz - - The concrete class of the object to be returned
topLevelClazz - - The highest persistence-capable class or interface (in the inheritance hierarchy) that the identified object is an instance of.
id - - The id of the object.
Returns:
An object of the specified class that matches the specified ID.
Throws:
DBException
java.lang.Exception

getIdentifiable

public Identifiable getIdentifiable(java.lang.Class identifiableClass,
                                    java.lang.String identifier)
                             throws java.lang.Exception
Throws:
java.lang.Exception

getObject

protected java.lang.Object getObject(java.lang.Class realClazz,
                                     java.lang.Class topLevelClazz,
                                     java.lang.Object id,
                                     org.apache.ojb.broker.PersistenceBroker broker)
                              throws java.lang.Exception
Gets an object of the specified class that matches the specified ID. Must enclose the call to this method in a transaction.

Parameters:
realClazz - - The concrete class of the object to be returned
topLevelClazz - - The highest persistence-capable class or interface (in the inheritance hierarchy) that the identified object is an instance of.
id - - The id of the object.
broker - - The PersistenceBroker to be used.
Returns:
An object of the specified class that matches the specified ID.
Throws:
java.lang.Exception

getObject

public java.lang.Object getObject(java.lang.Class clazz,
                                  java.lang.Object id,
                                  org.apache.ojb.broker.PersistenceBroker broker)
Gets an object of the specified class that matches the specified ID. The returned object is not cached before returned because it uses QueryByCriteria to search.

Parameters:
clazz -
id -

getObject

public java.lang.Object getObject(java.lang.Class clazz,
                                  java.lang.Object id)
                           throws java.lang.Exception
Gets an object of the specified class that matches the specified ID. The returned object is not cached before returned because it uses QueryByCriteria to search.

Parameters:
clazz -
id -
Throws:
java.lang.Exception

deleteObject

protected boolean deleteObject(java.lang.Class clazz,
                               java.lang.Object id)
                        throws java.lang.Exception
Deletes the object given its class type and ID.

Parameters:
clazz -
id -
Throws:
java.lang.Exception

exists

public boolean exists(java.lang.Class clazz,
                      java.lang.Object id)
Check if the specified object that matches the specified ID and is of the specified Class type exists.

Parameters:
clazz - - The Class type of the object to be searched.
id - - The ID of the object to be searched.
Returns:
- True if the searched object exists or false otherwise.

removeFromCache

public void removeFromCache(java.lang.Object objectOrIdentity)

clearCache

public void clearCache()
clears the cache Fix for TT13110


link

public void link(java.lang.Object pInstance,
                 boolean insert)

link

public void link(java.lang.Object pInstance,
                 java.lang.String attributeName,
                 boolean insert)

unlink

public void unlink(java.lang.Object pInstance)

unlink

public void unlink(java.lang.Object pInstance,
                   java.lang.String attributeName)

retrieveReference

public void retrieveReference(java.lang.Object pInstance,
                              java.lang.String attributeName)

retrieveReferences

public void retrieveReferences(java.lang.Object pInstance)

close

public void close()
Close database connection.


setCascadeRetrieve

protected boolean setCascadeRetrieve(org.apache.ojb.broker.PersistenceBroker broker,
                                     java.lang.Class theClass,
                                     java.lang.String referenceName,
                                     boolean cascadeValue)

setCascadeStore

protected int setCascadeStore(org.apache.ojb.broker.PersistenceBroker broker,
                              java.lang.Class theClass,
                              java.lang.String referenceName,
                              int cascadeValue)

setCascadeDelete

protected int setCascadeDelete(org.apache.ojb.broker.PersistenceBroker broker,
                               java.lang.Class theClass,
                               java.lang.String referenceName,
                               int cascadeValue)

getSqlInLimit

public static int getSqlInLimit()