uk.ac.cisban.rod.dao
Class DAO

java.lang.Object
  extended by uk.ac.cisban.rod.dao.DAO

public class DAO
extends java.lang.Object

The main class for connections to the the database. All other connections to the database are first routed through this class.

Since:
06-Oct-2009, 15:47:03
Author:
Morgan Taschuk

Field Summary
 Delete delete
          Accessor for the DAO delete something methods
 Exists exists
          Accessor for the DAO check-if-something-exists methods
 Find find
          Accessor for the DAO find-something methods
protected  Persist persist
          Accessor for the DAO persist-my-thing methods
 
Method Summary
 void addDatabaseProgressListener(DatabaseProgressListener listener)
          Allows any class to listen in on what is happening currently in the database.
 ActionApplication addInoculation(java.lang.Long actionApplicationId, java.util.Set<Inoculation> logs, java.util.Map<java.lang.String,java.lang.Exception> exceptionMap, java.util.Map<java.lang.String,java.lang.String> barcodeSubs)
          Adds a set of Inoculation logs to an existing ActionApplication.
 ActionApplication addSpotting(java.lang.Long actionApplicationId, java.util.Collection<Spotting> logs, java.util.Map<java.lang.String,java.lang.Exception> exceptionMap, java.util.Map<java.lang.String,java.lang.String> barcodeSubs)
          Adds a set of Spotting logs to an existing ActionApplication.
 ActionApplication applyAction(long pAppId, long startACVId, long aCVId)
          Creates an ActionApplication in a ProtocolApplication based upon the trail of the ProtocolCV and ActionCV.
 java.util.Map<java.lang.String,java.lang.Exception> exportImage(java.lang.Long repeatId, Image refImage, ResultPrinter srl)
          Prints the results from a particular Image to the passed ResultPrinter.
 java.util.Collection<BackgroundMutationCV> getBackgroundMutationCVs()
          Returns the whole list of BackgroundMutationCVs in the database.
 java.util.Collection<Experiment> getExperiments()
          Returns the whole list of Experiments in the database.
 Find getFind()
          Returns the helper class for finding objects in the database
static DAO getInstance()
          Lazy instantiation and return of this singleton class.
 java.util.Collection<MasterplateLibraryCV> getMasterplateLibraryCVs()
          Returns the whole list of MasterplateLibraryCVs in the database.
 java.util.Collection<MasterplateSet> getMasterplateSets()
          Returns the whole list of MasterplateSets in the database.
 java.util.Collection<MediumCV> getMediumCVs()
          Returns the whole list of MediumCVs in the database.
 Persist getPersist()
          Returns the helper class for persisting objects to the database
 java.util.Collection<PlateCV> getPlateCVs()
          Returns the whole list of PlateCVs in the database.
 java.util.Collection<Plate> getPlates()
          Returns the whole list of Plates in the database.
 javax.jdo.PersistenceManagerFactory getPmf()
          Returns the PersistenceManagerFactory initialized by this class.
 java.util.Collection<ProtocolCV> getProtocols()
          Returns the whole list of ProtocolCVs in the database.
 Repeat getRepeat(java.lang.Long repeatID)
          Return a repeat using its id.
 java.util.Collection<Repeat> getRepeats(java.lang.Long experimentId)
          Returns all Repeats from an Experiment.
 java.util.Collection<TreatmentCV> getTreatmentCVs()
          Returns the whole list of TreatmentCVs in the database.
 void iterateProtocol(ProtocolApplication protocol)
          Iterates through a ProtocolApplication and its ActionApplications recursively.
 void iterateProtocol(ProtocolCV protocol)
          Iterates through a ProtocolCV and its ActionCVs recursively.
 Experiment loadExperiment(java.lang.Long experimentId)
          Loads an experiment given its id (PK).
 java.util.Collection<Image> loadImagesBrief(java.util.List<java.lang.String> nonMappedPlates, java.lang.String barcodeString)
          Loads the collection of images associated with a Barcode without retrieving the individual ImageSpots (hence the "Brief").
 java.util.Collection<LogEvent> loadLogs(java.lang.Long actionAppId)
          Loads the LogEvents of an ActionApplication, given the AA's PK.
 java.util.Collection<LogEventMapping> loadSpots(java.util.Collection<java.lang.String> sourceBarcodes, long aAppId)
          Accesses the spot log for the given source barcodes based on ActionApplication id.
 java.util.Map<java.lang.String,java.lang.Exception> makeMasterplateSet(java.util.List<java.lang.String> barcodes, java.util.Map<java.lang.Integer,java.util.Set<MasterplatePosition>> mp, java.lang.String description, MasterplateLibraryCV mpcv, BackgroundMutationCV bmcv, PlateCV pcv)
          Creates a new MasterplateSet based on the given parameters.
 java.util.Map<java.lang.String,java.lang.Exception> pourPlates(java.util.Date datePoured, java.util.List<java.lang.String> barcodes, MediumCV medium, PlateCV plateCV)
          Adds a set of plates to the database.
 void removeDatabaseProgressListener(DatabaseProgressListener listener)
          Removes this listener from listening to what is happening in the database
 void reportProgress(int progress)
          Reports the progress of the database to whichever DatabaseProgressListener is interested.
 void reportProgressStatus(java.lang.String s)
          Tells interested DatabaseProgressListeners what is happening currently with the database.
 java.util.Collection<java.lang.Exception> threadImageLogs(java.lang.Long actionApplicationId, java.util.Collection<Image> logs)
          Enters the image logs each in individual threads to improve performance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

find

public Find find
Accessor for the DAO find-something methods


persist

protected Persist persist
Accessor for the DAO persist-my-thing methods


exists

public Exists exists
Accessor for the DAO check-if-something-exists methods


delete

public Delete delete
Accessor for the DAO delete something methods

Method Detail

getPmf

public javax.jdo.PersistenceManagerFactory getPmf()
Returns the PersistenceManagerFactory initialized by this class.

Returns:
the PersistenceManagerFactory initialized by this class.

getInstance

public static DAO getInstance()
Lazy instantiation and return of this singleton class. This method should be called whenever the class is used.

Returns:
the static, lazily instantiated instance of the access to the database

getPersist

public Persist getPersist()
Returns the helper class for persisting objects to the database

Returns:
the Persist class that is related to this DAO

getFind

public Find getFind()
Returns the helper class for finding objects in the database

Returns:
the Find class that is related to this DAO

iterateProtocol

public void iterateProtocol(ProtocolCV protocol)
Iterates through a ProtocolCV and its ActionCVs recursively. Used to load objects from the database into memory, otherwise DataNucleus would not populate all the way through the hierarchy.

Parameters:
protocol - The protocol to iterate recursively through

iterateProtocol

public void iterateProtocol(ProtocolApplication protocol)
Iterates through a ProtocolApplication and its ActionApplications recursively. Used to load objects from the database into memory, otherwise DataNucleus would not populate all the way through the hierarchy.

Parameters:
protocol - The protocol to iterate recursively through

loadExperiment

public Experiment loadExperiment(java.lang.Long experimentId)
Loads an experiment given its id (PK). Populates its Repeats, ProtocolCVs and ProtocolApplications, Masterplate Sets and their BackgroundMutationCVs and MasterPlateCVs, and Masterplates and their barcodes.

Parameters:
experimentId - the primary key of the experiment
Returns:
the populated Experiment object

getRepeats

public java.util.Collection<Repeat> getRepeats(java.lang.Long experimentId)
Returns all Repeats from an Experiment.

Parameters:
experimentId - the DB id of the experiment
Returns:
all Repeats from an Experiment.

getRepeat

public Repeat getRepeat(java.lang.Long repeatID)
Return a repeat using its id.

Parameters:
repeatID - the DB id
Returns:
a repeat

loadLogs

public java.util.Collection<LogEvent> loadLogs(java.lang.Long actionAppId)
                                        throws QueryNotFoundException
Loads the LogEvents of an ActionApplication, given the AA's PK. Can be a Spotting, an Inoculation, or ImageSpot. For each LogEvent, loads the source (and destination, for Spotting and Inoculation) plate barcode and plate position.

Parameters:
actionAppId - primary key of the ActionApplication
Returns:
a collection of the LogEvents associated with the ActionApplication
Throws:
QueryNotFoundException - if the ActionApplication with that PK cannot be found

loadImagesBrief

public java.util.Collection<Image> loadImagesBrief(java.util.List<java.lang.String> nonMappedPlates,
                                                   java.lang.String barcodeString)
                                            throws QueryNotFoundException
Loads the collection of images associated with a Barcode without retrieving the individual ImageSpots (hence the "Brief"). The Barcode is located based on the barcodeValue.

Parameters:
nonMappedPlates - a collection that holds the Barcodes that do not have associated images. Intended to be re-used with several calls to this method for error-checking purposes.
barcodeString - the barcodeValue of the plate
Returns:
a Collection of Images (can be several from different times) of this barcoded Plate
Throws:
QueryNotFoundException - if the Barcode cannot be found based on the parameter

applyAction

public ActionApplication applyAction(long pAppId,
                                     long startACVId,
                                     long aCVId)

Creates an ActionApplication in a ProtocolApplication based upon the trail of the ProtocolCV and ActionCV.

This method calls the private createTrail method after locating the ProtocolApplication and ActionCV objects from the passed primary key identifiers.

In the createTrail method, A path is created from the ProtocolApplication to the ActionApplication through any intervening Protocol/Action steps. For example, in a simple situation, a ProtocolCV (P1) has an ActionCV (A1), which links to ProtocolCV 2 (P2), which has an ActionCV (A2):

P1 -> A1 -> P2 - A2

In this particular experiment, MyExp, only the top-level step exists so far.

PA1

To this method applyAction, I can pass the id for PA1, and the id for A2, and it will create the following structure:

PA1 -> AA1 -> PA2 -> AA2

Clear as mud?

Parameters:
pAppId - the ProtocolApplication to add the Action to
startACVId - the ActionCV at the top of the tree from which to start looking for the aCVId. This variable was included in case there were several of the same ActionCVs at the top of the protocol tree.
aCVId - the ActionCV that the ActionApplication should be created from
Returns:
the new ActionApplication created from the aCVId

loadSpots

public java.util.Collection<LogEventMapping> loadSpots(java.util.Collection<java.lang.String> sourceBarcodes,
                                                       long aAppId)
                                                throws QueryNotFoundException
Accesses the spot log for the given source barcodes based on ActionApplication id.

Parameters:
sourceBarcodes - barcodes that occur in the sourcePlatePosition of Spotting
aAppId - the ActionApplication id
Returns:
a collection of mappings from the given source barcodes to a number of destination barcodes
Throws:
QueryNotFoundException - if the Barcodes or ActionApplication cannot be found

makeMasterplateSet

public java.util.Map<java.lang.String,java.lang.Exception> makeMasterplateSet(java.util.List<java.lang.String> barcodes,
                                                                              java.util.Map<java.lang.Integer,java.util.Set<MasterplatePosition>> mp,
                                                                              java.lang.String description,
                                                                              MasterplateLibraryCV mpcv,
                                                                              BackgroundMutationCV bmcv,
                                                                              PlateCV pcv)
Creates a new MasterplateSet based on the given parameters.

Parameters:
barcodes - an ordered list of barcodes of the Masterplates in the set
mp - a map of the order number from the barcodes parameter to the set of MasterplatePositions on the Masterplate
description - a description of the MasterplateSet
mpcv - the MasterplateLibraryCV term
bmcv - the BackgroundMutationCV term
pcv - the PlateCV
Returns:
a Map of Exceptions that occurred during this operation

addInoculation

public ActionApplication addInoculation(java.lang.Long actionApplicationId,
                                        java.util.Set<Inoculation> logs,
                                        java.util.Map<java.lang.String,java.lang.Exception> exceptionMap,
                                        java.util.Map<java.lang.String,java.lang.String> barcodeSubs)
Adds a set of Inoculation logs to an existing ActionApplication.

Parameters:
actionApplicationId - the primary key of the ActionApplication
logs - the set of Inoculation logs to add to the ActionApplication
exceptionMap - a Map of Exceptions that occurred during this operation
barcodeSubs - a list of barcodes keys to substitute with their given values (used for no-reads and other barcode errors)
Returns:
the ActionApplication with the added Inoculation logs
See Also:
DAO#applyAction(long, long)

addSpotting

public ActionApplication addSpotting(java.lang.Long actionApplicationId,
                                     java.util.Collection<Spotting> logs,
                                     java.util.Map<java.lang.String,java.lang.Exception> exceptionMap,
                                     java.util.Map<java.lang.String,java.lang.String> barcodeSubs)
Adds a set of Spotting logs to an existing ActionApplication. This method presumes that all Barcodes and Plates in the logs actually exist!

Parameters:
actionApplicationId - the primary key of the ActionApplication
logs - the set of Spotting logs to add to the ActionApplication
exceptionMap - a Map of Exceptions that occurred during this operation
barcodeSubs - a list of barcodes keys to substitute with their given values (used for no-reads and other barcode errors)
Returns:
the ActionApplication with the added Spotting logs
See Also:
DAO#applyAction(long, long)

threadImageLogs

public java.util.Collection<java.lang.Exception> threadImageLogs(java.lang.Long actionApplicationId,
                                                                 java.util.Collection<Image> logs)
Enters the image logs each in individual threads to improve performance.

Parameters:
actionApplicationId - the DB id of the ActionApplication to add the image logs to
logs - the images to add
Returns:
a collection of the exceptions that occurred while working

pourPlates

public java.util.Map<java.lang.String,java.lang.Exception> pourPlates(java.util.Date datePoured,
                                                                      java.util.List<java.lang.String> barcodes,
                                                                      MediumCV medium,
                                                                      PlateCV plateCV)
Adds a set of plates to the database.

Parameters:
datePoured - the date that the plates were poured on (in the real world)
barcodes - a list of the barcodes of the plates
medium - the medium on the plates
plateCV - the type of plate that was poured
Returns:
a Map of the Exceptions that occurred during this operation

exportImage

public java.util.Map<java.lang.String,java.lang.Exception> exportImage(java.lang.Long repeatId,
                                                                       Image refImage,
                                                                       ResultPrinter srl)
Prints the results from a particular Image to the passed ResultPrinter.

Parameters:
repeatId - the primary key of the Repeat
refImage - the image whose results will be printed
srl - the ResultPrinter that will print (export) the results to some kind of stream
Returns:

getTreatmentCVs

public java.util.Collection<TreatmentCV> getTreatmentCVs()
                                                  throws QueryNotFoundException
Returns the whole list of TreatmentCVs in the database.

Returns:
a Collection of TreatmentCVs
Throws:
QueryNotFoundException - if there are no TreatmentCVs to find

getMediumCVs

public java.util.Collection<MediumCV> getMediumCVs()
                                            throws QueryNotFoundException
Returns the whole list of MediumCVs in the database.

Returns:
a Collection of MediumCVs
Throws:
QueryNotFoundException - if there are no MediumCVs to find

getPlateCVs

public java.util.Collection<PlateCV> getPlateCVs()
                                          throws QueryNotFoundException
Returns the whole list of PlateCVs in the database.

Returns:
a Collection of PlateCVs
Throws:
QueryNotFoundException - if there are no PlateCVs to find

getExperiments

public java.util.Collection<Experiment> getExperiments()
                                                throws QueryNotFoundException
Returns the whole list of Experiments in the database.

Returns:
a Collection of Experiments
Throws:
QueryNotFoundException - if there are no Experiments to find

getMasterplateSets

public java.util.Collection<MasterplateSet> getMasterplateSets()
                                                        throws QueryNotFoundException
Returns the whole list of MasterplateSets in the database. The Masterplates and their Barcodes and MediumCVs are populated as well as the MasterplateSet's BackgroundMutationCv and MasterPlateCV.

Returns:
a Collection of MasterplateSets
Throws:
QueryNotFoundException - if there are no TreatmentCVs to find

getBackgroundMutationCVs

public java.util.Collection<BackgroundMutationCV> getBackgroundMutationCVs()
                                                                    throws QueryNotFoundException
Returns the whole list of BackgroundMutationCVs in the database.

Returns:
a Collection of BackgroundMutationCVs
Throws:
QueryNotFoundException - if there are no BackgroundMutationCVs to find

getMasterplateLibraryCVs

public java.util.Collection<MasterplateLibraryCV> getMasterplateLibraryCVs()
                                                                    throws QueryNotFoundException
Returns the whole list of MasterplateLibraryCVs in the database.

Returns:
a Collection of MasterplateLibraryCVs
Throws:
QueryNotFoundException - if there are no MasterplateLibraryCVs to find

getPlates

public java.util.Collection<Plate> getPlates()
                                      throws QueryNotFoundException
Returns the whole list of Plates in the database. All Barcodes, Treatments, and MediumCVs are available.

Returns:
a Collection of Plates
Throws:
QueryNotFoundException - if there are no Plates to find

getProtocols

public java.util.Collection<ProtocolCV> getProtocols()
                                              throws QueryNotFoundException
Returns the whole list of ProtocolCVs in the database. All child ActionCVs and ProtocolCVs are available.

Returns:
a Collection of ProtocolCVs
Throws:
QueryNotFoundException - if there are no ProtocolCVs to find

addDatabaseProgressListener

public void addDatabaseProgressListener(DatabaseProgressListener listener)
Allows any class to listen in on what is happening currently in the database.

Parameters:
listener - an interested class

removeDatabaseProgressListener

public void removeDatabaseProgressListener(DatabaseProgressListener listener)
Removes this listener from listening to what is happening in the database

Parameters:
listener - an uninterested class

reportProgressStatus

public void reportProgressStatus(java.lang.String s)
Tells interested DatabaseProgressListeners what is happening currently with the database.

Parameters:
s - an interesting status message

reportProgress

public void reportProgress(int progress)
Reports the progress of the database to whichever DatabaseProgressListener is interested.

Parameters:
progress - the progress percent (from 0-99).


Copyright © 2010. All Rights Reserved.