SigPath

org.sigpath.database
Class EntityManager

java.lang.Object
  extended by org.sigpath.database.EntityManager
All Implemented Interfaces:
SigPathManager

public class EntityManager
extends Object
implements SigPathManager

EntityManager Provides database functionality regarding SigPathEntity objects.

Author:
Benjamin Chiang/Manda Wilson/Ethan Cerami

Constructor Summary
protected EntityManager(SPDBManager spdbManager)
          Constructor initializes database manager.
 
Method Summary
 boolean ACDBExists(String ac, String db)
          Determine if a given AC/DB pair exists in the database.
 void add(SigPathEntity spe)
          Adds a SigPathEntity object to the database.
 void addIndexed(SigPathEntity spe)
          Adds a SigPathEntity object to the database.
 void addIndexed(SigPathEntity spe, FTSManagerMeasurements measure)
          Adds a SigPathEntity object to the database.
 void close()
          This method is used to free any resources and closes any database connections used by the manager
 void delete(Object obj)
           
 void deleteAll(Collection c)
           
 Collection entityBackwardReferences(SigPathEntity spe, Query query)
          Query for a set of entities that contain the given SigPathEntity spe in their forward references list.
 Collection filterOrganisms(Collection chems, String orgName, boolean exact)
          Filters a collection of chemicals according to organism.
 Collection getAll(String classname)
          Returns a Collection of all SigPathEntity objects in the database.
 Iterator getAllExportable(String classname)
          Get an iterator on all exportable entities.
 Collection getAllIndexed(String classname)
           
 Iterator getAllIndexedIterator(String classname)
           
 Iterator getAllIterator(String classname)
          Returns an Iterator of all SigPathEntity objects in the database.
 Iterator getAllIterator(String classname, String indexname, String filter, boolean reset, int startIndex)
          Returns an Iterator of all SigPathEntity objects in the database.
 Collection getAllNotIndexed(String classname)
           
 Iterator getAllNotIndexedIterator(String classname)
           
 Iterator getAllOrganisms()
          Returns an iterator over each Organism instance defined in the database.
 Set getModifiedList()
          Get List of modified entities.
 int getNumEntities(String classname)
          Gets total Number of Entities of a given classname.
 int getSizeOfLlookupIntersection(String booleanQuery, String classname, String oraganism)
           
 String getSpidFromAc(String ac, String db)
          Obtains the spid of an entity.
static Integer getSpidIndex(String spid)
          Returns the index of this spid or bid.
 boolean isBioPolymer(String spid)
          Checks to see if a SigPathEntity is an instance of BioPolymer.
 boolean isChemical(String spid)
          Checks to see if a SigPathEntity is an instance of Chemical.
 boolean isComplex(String spid)
          Checks to see if a SigPathEntity is an instance of Complex.
 boolean isEnzymaticReaction(String spid)
          This method determines if the specified reaction is enzymatic.
 boolean isEnzyme(String spid)
           
 boolean isModifiedChemical(String spid)
          Checks to see if a SigPathEntity is a modified chemical.
 Collection lookupByAC(String ac, String orgName)
          Lookup a sigpath entity by accession code.
 SigPathEntity lookupByAC(String ac, String database, String orgName)
          Searches SigPathEntity objects in the database with names matching the given accession code and database.
 Collection lookupByACDB(String ac, String database)
          Searches SigPathEntity objects in the database with names matching the given accession code and database.
 Collection lookupByACDBOrg(String acdb, String organismName)
          Returns a colection of entities that match accession code in database and organism name.
 Collection lookupByExactName(String name, String classname)
          Searches SigPathEntity objects in the database with names matching exactly the given name.
 Collection lookupByName(String name, Class clazz)
           
 Collection lookupByName(String name, String classname)
          Searches SigPathEntity objects in the database with names matching the given name.
 SigPathEntity lookupBySpid(String spid)
          Searches SigPathEntity objects in the database with a SPID matching the given SPID.
 Collection lookupBySpids(Collection spids, Query query)
          Queries for a set of entities that have certain spids.
 Iterator lookupConcentrationsBySpid(String spid)
           
 Collection lookupIntersection(String booleanQuery, String classname)
           
 Collection lookupIntersection(String booleanQuery, String classname, int startIndex, int recordsNumber)
          Full text lookup of boolean query.
 Collection lookupIntersection(String booleanQuery, String classname, int startIndex, int recordsNumber, FTSManagerMeasurements measure)
           
 Collection lookupIntersectionByOrganism(String className, String query, String orgName, boolean exact)
           
 Collection lookupIntersectionByOrganism(String className, String keywords, String orgName, int startIndex, int recordsNumber)
           
 Kinetic lookupKineticByName(String name)
          Queries for kinetics using a name.
 Collection lookupOrganism(String subString)
          Lookup an organism by subString.
 Organism lookupOrganismBySpecies(String species)
          Lookup an organism by species.
 Collection lookupOrganismsBySpecies(String species)
          Lookup a organism by species.
 Object lookupSpidRangeByType(int type)
          Searches for SpidRange of a specific type.
 SigPathEntity newEntity(String eType, String name, String[] aliases, String[] ac, String[] db, String desc)
          Convenience method which returns a new SigPathEntity of type eType.
 SigPathEntity newEntityWithSPID(String eType, String spid, String name, String[] aliases, String[] ac, String[] db, String desc)
           
 boolean organismExists(String orgName)
          Checks to see if an Organism exists.
 void resolve(Object obj)
           
 void resolveAll(Collection c)
           
 void setSPEData(SigPathEntity spe, String name, String[] aliases, String[] ac, String[] db, String desc)
          Sets the SigPath Base Data.
 boolean uniqueACDB(String ac, String db)
          Determine if a given AC/DB pair is unique in the database.
 void updateModifiedList(SigPathEntity spe)
          Updates the Modified Entity List, so that we can easily keep track of all changes and then export any changes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EntityManager

protected EntityManager(SPDBManager spdbManager)
Constructor initializes database manager.

Parameters:
spdbManager - database manager
Method Detail

updateModifiedList

public void updateModifiedList(SigPathEntity spe)
                        throws SigPathDatabaseException
Updates the Modified Entity List, so that we can easily keep track of all changes and then export any changes.

Throws:
SigPathDatabaseException

getModifiedList

public Set getModifiedList()
                    throws SigPathDatabaseException
Get List of modified entities. Modified entities have been modified by user interaction since the initial XML import.

Returns:
SigPathEntity instances which have been modified.
Throws:
SigPathDatabaseException

newEntity

public SigPathEntity newEntity(String eType,
                               String name,
                               String[] aliases,
                               String[] ac,
                               String[] db,
                               String desc)
Convenience method which returns a new SigPathEntity of type eType.

Parameters:
eType - String type of SigPathEntity to create, currently provides functionality for Protein and SmallMolecule objects Set eType to "protein" to create a Protein object Set eType to "smallmolecule" to create a SmallMolecule object
name - String name of the SigPathEntity
aliases - String[] aliases of the SigPathEntity
ac - String[] accession code of the SigPathEntity
db - String[] database pair to accession code of SigPathEntity
desc - String description of the SigPathEntity
Returns:
SigPathEntity that is fully set with the provided parameter data
See Also:
SigPathEntity

newEntityWithSPID

public SigPathEntity newEntityWithSPID(String eType,
                                       String spid,
                                       String name,
                                       String[] aliases,
                                       String[] ac,
                                       String[] db,
                                       String desc)

setSPEData

public void setSPEData(SigPathEntity spe,
                       String name,
                       String[] aliases,
                       String[] ac,
                       String[] db,
                       String desc)
Sets the SigPath Base Data.


getAll

public Collection getAll(String classname)
                  throws SigPathDatabaseException
Returns a Collection of all SigPathEntity objects in the database. String classname is the fully-qualified class name of the SigPathEntity being searched for. This class name must be in the SigPathConstants class and mapped to an extent alias in the current database. !!! This method is very inefficient. What if the extent returns hundreds of thousands of elements? Use EntityManager.getAllIterator if possible. An advantage of this method is, that the returned collection can be transfered to other transactions, in contrary to the getAllIterator method.

Parameters:
classname - String name of class found in SigPathConstants to be used in finding class extent in the current database
Returns:
java.util.Collection of SigPathEntity objects
Throws:
SigPathDatabaseException - if there is an error with the database or the query
See Also:
SigPathEntity, SigPathConstants

getAllExportable

public Iterator getAllExportable(String classname)
                          throws SigPathDatabaseException
Get an iterator on all exportable entities.

Parameters:
classname -
Returns:
Throws:
SigPathDatabaseException

getAllIterator

public Iterator getAllIterator(String classname)
                        throws SigPathDatabaseException
Returns an Iterator of all SigPathEntity objects in the database. String classname is the fully-qualified class name of the SigPathEntity being searched for. This class name must be in the SigPathConstants class and mapped to an extent alias in the current database. An disadvantage of this method is, that the returned iterator cannot be transfered to other transactions, in contrary to the getAll method.

Parameters:
classname - String name of class found in SigPathConstants to be used in finding class extent in the current database. The iterators returns entitites ordered by Spid if an index exists on spid for the classname.
Returns:
java.util.Iterator of SigPathEntity objects if one is found, otherwise null
Throws:
SigPathDatabaseException - if there is an error with the database or the query
See Also:
SigPathEntity, SigPathConstants, SigPathConstants.INDEX_DOES_NOT_EXIST, SigPathConstants.getSpidIndexName(java.lang.String)

getAllIterator

public Iterator getAllIterator(String classname,
                               String indexname,
                               String filter,
                               boolean reset,
                               int startIndex)
                        throws SigPathDatabaseException
Returns an Iterator of all SigPathEntity objects in the database. String classname is the fully-qualified class name of the SigPathEntity being searched for. This class name must be in the SigPathConstants class and mapped to an extent alias in the current database. An disadvantage of this method is, that the returned iterator cannot be transfered to other transactions, in contrary to the getAll method.

Parameters:
classname - String name of class found in SigPathConstants to be used in finding class extent in the current database The iterators returns entitites ordered by Spid if an index exists on spid for the classname.
indexname - String name of index to use
filter - predicate to filter the extent by
reset - boolean value for resetting the extent or not
startIndex - int value of startIndex, set to -1 if no start index is to be used
Returns:
java.util.Iterator of SigPathEntity objects if one is found, otherwise null
Throws:
SigPathDatabaseException - if there is an error with the database or the query
See Also:
SigPathEntity, SigPathConstants, SigPathConstants.INDEX_DOES_NOT_EXIST, SigPathConstants.getSpidIndexName(java.lang.String)

getAllNotIndexedIterator

public Iterator getAllNotIndexedIterator(String classname)
                                  throws SigPathDatabaseException
Throws:
SigPathDatabaseException

getAllIndexedIterator

public Iterator getAllIndexedIterator(String classname)
                               throws SigPathDatabaseException
Throws:
SigPathDatabaseException

getAllNotIndexed

public Collection getAllNotIndexed(String classname)
                            throws SigPathDatabaseException
Throws:
SigPathDatabaseException

getAllIndexed

public Collection getAllIndexed(String classname)
                         throws SigPathDatabaseException
Throws:
SigPathDatabaseException

lookupIntersection

public Collection lookupIntersection(String booleanQuery,
                                     String classname,
                                     int startIndex,
                                     int recordsNumber)
                              throws SigPathDatabaseException
Full text lookup of boolean query. The query language currently only supports a list of keywords. The query is interpreted as the intersection of the sets matched by the individual keywords.

Parameters:
booleanQuery - The query, eg. "receptor kinase" succession of individual keywords separated by the delimiters recognized by FullTextSearchManager.
classname - The class of the results to be returned. It is guaranteed that only subclasses of this class will be returned.
Returns:
Collection of matching objects
Throws:
SigPathDatabaseException

lookupIntersection

public Collection lookupIntersection(String booleanQuery,
                                     String classname,
                                     int startIndex,
                                     int recordsNumber,
                                     FTSManagerMeasurements measure)
                              throws SigPathDatabaseException
Throws:
SigPathDatabaseException

lookupIntersection

public Collection lookupIntersection(String booleanQuery,
                                     String classname)
                              throws SigPathDatabaseException
Throws:
SigPathDatabaseException

getSizeOfLlookupIntersection

public int getSizeOfLlookupIntersection(String booleanQuery,
                                        String classname,
                                        String oraganism)
                                 throws SigPathDatabaseException
Throws:
SigPathDatabaseException

lookupByAC

public SigPathEntity lookupByAC(String ac,
                                String database,
                                String orgName)
                         throws SigPathDatabaseException
Searches SigPathEntity objects in the database with names matching the given accession code and database.

Parameters:
ac - accession code search String
database - database search String
Returns:
org.sigpath.datamodel.SigPathEntity, null if no matches are found
Throws:
SigPathDatabaseException - if there is an error with the database or the query
See Also:
SigPathEntity, SigPathConstants

lookupByAC

public Collection lookupByAC(String ac,
                             String orgName)
                      throws SigPathDatabaseException
Lookup a sigpath entity by accession code.

Parameters:
ac - accession code in an external database.
Returns:
The Collection of entities that match the accession code, or null.
Throws:
SigPathDatabaseException - if there is an error with the database or the query
See Also:
SigPathEntity

lookupConcentrationsBySpid

public Iterator lookupConcentrationsBySpid(String spid)
                                    throws SigPathDatabaseException
Throws:
SigPathDatabaseException

getAllOrganisms

public Iterator getAllOrganisms()
                         throws SigPathDatabaseException
Returns an iterator over each Organism instance defined in the database.

Returns:
an iterator over each Organism instance defined in the database.
Throws:
SigPathDatabaseException

lookupOrganism

public Collection lookupOrganism(String subString)
                          throws SigPathDatabaseException
Lookup an organism by subString. Find organisms that match a given substring.

Parameters:
subString - what to look for in the organism species and commonName fields.
Returns:
The set of organisms instances that start or end with the substring.
Throws:
SigPathDatabaseException

lookupOrganismBySpecies

public Organism lookupOrganismBySpecies(String species)
                                 throws SigPathDatabaseException
Lookup an organism by species. Find the organism that match exactly the species field.

Parameters:
species - species of the organism to be returned.
Returns:
The organism instances that have this species.
Throws:
SigPathDatabaseException

lookupOrganismsBySpecies

public Collection lookupOrganismsBySpecies(String species)
                                    throws SigPathDatabaseException
Lookup a organism by species. Find the organisms that match exactly the species field.

Parameters:
species - species of the organism to be returned.
Returns:
a collection of organism instances that have this species field.
Throws:
SigPathDatabaseException

lookupIntersectionByOrganism

public Collection lookupIntersectionByOrganism(String className,
                                               String keywords,
                                               String orgName,
                                               int startIndex,
                                               int recordsNumber)
                                        throws SigPathDatabaseException
Throws:
SigPathDatabaseException

lookupIntersectionByOrganism

public Collection lookupIntersectionByOrganism(String className,
                                               String query,
                                               String orgName,
                                               boolean exact)
                                        throws SigPathDatabaseException
Throws:
SigPathDatabaseException

filterOrganisms

public Collection filterOrganisms(Collection chems,
                                  String orgName,
                                  boolean exact)
Filters a collection of chemicals according to organism. Keep chemicals that match the organism. When exact is true.

Parameters:
chems - The set of chemicals to filter
orgName - The keyword to match in the name of the organism of each chemical
exact - true if the match must be exact or false if matching a substring of the chemical organism is good enough.
Returns:
The set of chemicals that match orgName.

organismExists

public boolean organismExists(String orgName)
                       throws SigPathDatabaseException
Checks to see if an Organism exists.

Parameters:
orgName - Species or Common Name of organism (exact matching)
Returns:
boolean true if Organism exists, false if Organism does not exist
Throws:
SigPathDatabaseException

lookupByACDBOrg

public Collection lookupByACDBOrg(String acdb,
                                  String organismName)
                           throws SigPathDatabaseException
Returns a colection of entities that match accession code in database and organism name.

Parameters:
acdb - Accession code and database name, in the format db:ac
organismName - orgnism name.
Returns:
a collection of sigpath entities that match the criteria. TODO: refactor lookupByAcDb to return a collection instead of an object.
Throws:
SigPathDatabaseException

lookupByACDB

public Collection lookupByACDB(String ac,
                               String database)
                        throws SigPathDatabaseException
Searches SigPathEntity objects in the database with names matching the given accession code and database.

Parameters:
ac - accession code search String
database - database search String
Returns:
The Collection of entities that match the accession code, or null.
Throws:
SigPathDatabaseException - if there is an error with the database or the query

ACDBExists

public boolean ACDBExists(String ac,
                          String db)
                   throws SigPathDatabaseException
Determine if a given AC/DB pair exists in the database.

Parameters:
ac - Accession code in an external database.
db - name of accession code database that the accession code references
Returns:
true if the pair exists, false otherwise.
Throws:
SigPathDatabaseException

uniqueACDB

public boolean uniqueACDB(String ac,
                          String db)
                   throws SigPathDatabaseException
Determine if a given AC/DB pair is unique in the database.

Parameters:
ac - Accession code in an external database.
db - name Database that the accession code references.
Returns:
true if the pair matches a single chemical in the running version of SigPath, false otherwise.
Throws:
SigPathDatabaseException

lookupSpidRangeByType

public Object lookupSpidRangeByType(int type)
                             throws SigPathDatabaseException
Searches for SpidRange of a specific type. The type is one of the following: SigPathConstants.SPID_RANGE_TYPE_CURRENT SigPathConstants.SPID_RANGE_TYPE_MARKED

Parameters:
type - as integer
Returns:
SpidRange as Object
Throws:
SigPathDatabaseException

lookupByName

public Collection lookupByName(String name,
                               String classname)
                        throws SigPathDatabaseException
Searches SigPathEntity objects in the database with names matching the given name. This is a case INSENSITIVE exact match search specified by name = . The user may prefix or suffix their search with a "*" for a wildcard search. Note searching with a wildcard prefix requires longer search times. String classname is the fully-qualified class name of the SigPathEntity being searched for. This class name must be in the SigPathConstants class and mapped to an extent alias in the current database.

Parameters:
name - Name of SigPathEntity to search for.
classname - String name of class found in SigPathConstants to be used in finding class extent in the current database
Returns:
java.util.Collection of SigPathEntity objects empty java.util.Collection if no matches are found
Throws:
SigPathDatabaseException - if there is an error with the database or the query
See Also:
SigPathEntity, SigPathConstants

lookupByName

public Collection lookupByName(String name,
                               Class clazz)
                        throws SigPathDatabaseException
Throws:
SigPathDatabaseException

lookupByExactName

public Collection lookupByExactName(String name,
                                    String classname)
                             throws SigPathDatabaseException
Searches SigPathEntity objects in the database with names matching exactly the given name.

Parameters:
name - Name of SigPathEntity to search for.
classname - String name of class found in SigPathConstants to be used in finding class extent in the current database
Returns:
java.util.Collection of SigPathEntity objects empty java.util.Collection if no matches are found
Throws:
SigPathDatabaseException - if there is an error with the database or the query
See Also:
SigPathEntity, SigPathConstants

getNumEntities

public int getNumEntities(String classname)
                   throws SigPathDatabaseException
Gets total Number of Entities of a given classname.

Throws:
SigPathDatabaseException

lookupBySpid

public SigPathEntity lookupBySpid(String spid)
                           throws SigPathDatabaseException
Searches SigPathEntity objects in the database with a SPID matching the given SPID.

Parameters:
spid - SPID of SigPathEntity to search for.
Returns:
Entity representing the object retrieved with the spid.
Throws:
SigPathDatabaseException - if there is an error with the database or the query

add

public void add(SigPathEntity spe)
         throws SigPathDatabaseException
Adds a SigPathEntity object to the database. (Does not perform full text indexing)

Parameters:
spe - SigPathEntity that will be added to database
Throws:
SigPathDatabaseException - if there is an error with the database
See Also:
SigPathEntity

addIndexed

public void addIndexed(SigPathEntity spe)
                throws SigPathDatabaseException
Adds a SigPathEntity object to the database. (Also performs the full text indexing of this entity.)

Parameters:
spe - SigPathEntity that will be added to database
Throws:
SigPathDatabaseException - if there is an error with the database
See Also:
SigPathEntity

addIndexed

public void addIndexed(SigPathEntity spe,
                       FTSManagerMeasurements measure)
                throws SigPathDatabaseException
Adds a SigPathEntity object to the database. (Also performs the full text indexing of this entity.)

Parameters:
spe - SigPathEntity that will be added to database
measure - FTSManagerMeasurements to measure the time used to fulltext index the element
Throws:
SigPathDatabaseException - if there is an error with the database
See Also:
SigPathEntity

delete

public void delete(Object obj)

deleteAll

public void deleteAll(Collection c)

resolve

public void resolve(Object obj)

resolveAll

public void resolveAll(Collection c)

isBioPolymer

public boolean isBioPolymer(String spid)
                     throws SigPathDatabaseException
Checks to see if a SigPathEntity is an instance of BioPolymer.

Parameters:
spid - spid of SigPathEntity
Returns:
boolean true if SigPathEnity is an instance of BioPolymer
Throws:
SigPathDatabaseException

close

public void close()
This method is used to free any resources and closes any database connections used by the manager

Specified by:
close in interface SigPathManager

getSpidFromAc

public String getSpidFromAc(String ac,
                            String db)
                     throws SigPathDatabaseException
Obtains the spid of an entity.

Parameters:
ac - Accession code of this entity.
db - Database
Returns:
The spid of the entity which matches the accession code and database pair.
Throws:
SigPathDatabaseException

isEnzymaticReaction

public boolean isEnzymaticReaction(String spid)
                            throws SigPathDatabaseException
This method determines if the specified reaction is enzymatic.

Parameters:
spid - SPID of the reaction to check
Returns:
True if the entity represents an enzymatic reaction.
Throws:
SigPathDatabaseException

isModifiedChemical

public boolean isModifiedChemical(String spid)
                           throws SigPathDatabaseException
Checks to see if a SigPathEntity is a modified chemical. To be a modified Chemical it must have a ComesFromInfo object.

Parameters:
spid - spid of SigPathEntity
Returns:
boolean true if SigPathEnity is a modified chemical
Throws:
SigPathDatabaseException

isComplex

public boolean isComplex(String spid)
                  throws SigPathDatabaseException
Checks to see if a SigPathEntity is an instance of Complex.

Parameters:
spid - spid of SigPathEntity
Returns:
boolean true if SigPathEnity is an instance of BioPolymer
Throws:
SigPathDatabaseException - When the entity cannot be found.

isChemical

public boolean isChemical(String spid)
                   throws SigPathDatabaseException
Checks to see if a SigPathEntity is an instance of Chemical.

Parameters:
spid - spid of SigPathEntity
Returns:
boolean true if SigPathEnity is an instance of Chemical
Throws:
SigPathDatabaseException

isEnzyme

public boolean isEnzyme(String spid)
                 throws SigPathDatabaseException
Throws:
SigPathDatabaseException

lookupBySpids

public Collection lookupBySpids(Collection spids,
                                Query query)
Queries for a set of entities that have certain spids.

Parameters:
spids - A collection of spids (String type)
query - A new query obtained with SPDBManager.newQuery. Use you query instance to free resources associated with the query.
Returns:
Collection of SigPathEntities

entityBackwardReferences

public Collection entityBackwardReferences(SigPathEntity spe,
                                           Query query)
Query for a set of entities that contain the given SigPathEntity spe in their forward references list. Thus, the method name entityBackwardReferences. This was originally a very slow query that was much improved by indexing forward references. Refer to datamodel.jdo for SPE_ForwardRefsIndex. When adding an index to datamodel.jdo for the first time, the following steps need to be done: 1. run ant target jdo_updateschema_fastobjects 2. update FastObjects using Administrator

Returns:

getSpidIndex

public static Integer getSpidIndex(String spid)
Returns the index of this spid or bid.

Parameters:
spid - Spid or bid, such as sp23 or bid45.
Returns:
Integer part of the spid, e.g., 23 or 45. TODO - move to SpidManager

lookupKineticByName

public Kinetic lookupKineticByName(String name)
                            throws SigPathDatabaseException
Queries for kinetics using a name. Kinetic names should be unique, thus returned kinetics should be single element collections. query instance to free resources associated with the query.

Returns:
Collection of SigPathEntities
Throws:
SigPathDatabaseException

SigPath

Copyright © 2002-2005 Institute for Computational Biomedicine, All Rights Reserved.