org.persvr.datasource
Class DynaObjectDBSource

java.lang.Object
  extended by org.persvr.datasource.BaseDataSource
      extended by org.persvr.datasource.DatabaseDataSource
          extended by org.persvr.datasource.DynaObjectDBSource
All Implemented Interfaces:
DataSource, DataSourceCanHaveOrphans, ListDataSource, ReferenceAwareDataSource, SourceDeleteAware, WritableDataSource
Direct Known Subclasses:
DynaArrayDBSource, DynaFileDBSource, DynaFunctionDBSource

public class DynaObjectDBSource
extends DatabaseDataSource
implements WritableDataSource, DataSource, ListDataSource, DataSourceCanHaveOrphans, ReferenceAwareDataSource, SourceDeleteAware

This is the dynamic object database source. This is the default primary data source used by Persevere.

Author:
Kris

Nested Class Summary
 
Nested classes/interfaces inherited from class org.persvr.datasource.DatabaseDataSource
DatabaseDataSource.DatabaseAction, DatabaseDataSource.QueryIterator, DatabaseDataSource.ThreadSpecificConnectionObject
 
Field Summary
 
Fields inherited from class org.persvr.datasource.DatabaseDataSource
connectionString
 
Fields inherited from class org.persvr.datasource.BaseDataSource
BINARY_HEADER, BOOLEAN_FALSE, BOOLEAN_TRUE, DATE_HEADER, DECIMAL_HEADER, DOUBLE_HEADER, FUNCTION_HEADER, INTEGER_HEADER, LINK_HEADER, LONG_HEADER, OBJECT_HEADER, REQUIRED_PREFIX, STRING_HEADER, UNDEFINED
 
Constructor Summary
DynaObjectDBSource()
           
 
Method Summary
protected  java.lang.String comparison(Node expression, Node valueNode, int conditionType)
           
protected  org.persvr.datasource.DynaObjectDBSource.ConnectionStatements getConnectionObject()
          This will return a thread specific connection object.
 java.lang.Object getFieldValue(LazyPropertyId valueId)
          This is called when a field value contains an unfulfilled value (ValueId)
 long getNextId()
           
 java.util.List<ObjectId> getOrphans()
           
 java.util.List<ObjectId> getReferrers(java.lang.String id)
           
 DynaObjectDBSource getSuperSource()
           
protected  java.lang.Object getValueFromRs(java.sql.ResultSet rs)
          This gets the value/object for the current result set row
 void initParameters(java.util.Map parameters)
          This is called on initialization and provides access to the data source configuration parameters
 void mapObject(PersistableInitializer initializer, java.lang.String objectId)
          This is called when an object is being activated to retrieve the persisted data for a given object
 java.util.Iterator mapQuery(Query query)
          This is called when an object is being activated to retrieve the persisted data for a given object with a filter
protected  java.lang.String nameInQuery(java.lang.String name)
           
 java.util.Map<java.lang.String,java.lang.Object> newSource()
           
protected  java.lang.String numberComparisonInQuery(double value, java.lang.String operator)
           
 void onDelete()
          When a source is deleted this is called
 void purgeOrphans()
           
 void recordDelete(java.lang.String objectId)
          This is called when an object should be deleted
 void recordList(java.lang.String id, java.util.List<? extends java.lang.Object> values)
           
 void recordListAdd(java.lang.String objectId, int index, java.lang.Object value)
           
 NewObjectPersister recordNewObject(Persistable object)
          This is called when a new object is persisted
 void recordPropertyAddition(java.lang.String id, java.lang.String key, java.lang.Object value, int attributes)
          This is called when a new property is added to an object
 void recordPropertyChange(java.lang.String id, java.lang.String key, java.lang.Object value, int attributes)
          This is called when a property value is changed
 void recordPropertyRemoval(java.lang.String id, java.lang.String name)
          This is called when a property value is removed
protected  java.lang.String stringComparisonInQuery(java.lang.String str)
           
protected  java.lang.String stringComparisonInQuery(java.lang.String str, int type)
           
 java.util.List testQuery(java.lang.String sql)
           
 void truncate(java.lang.String objectId, long newLength)
           
 
Methods inherited from class org.persvr.datasource.DatabaseDataSource
abortTransaction, addConditionToQuery, commitTransaction, createConnection, executeAndGetGeneratedKey, runStarterStatements, startTransaction, testLocks, tryExecution
 
Methods inherited from class org.persvr.datasource.BaseDataSource
convertObjectToString, convertStringToObject, getId, hiddenId, idForString, initializeFromMap, setId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.persvr.datasource.WritableDataSource
abortTransaction, commitTransaction, startTransaction
 
Methods inherited from interface org.persvr.datasource.DataSource
getId, hiddenId, setId
 

Constructor Detail

DynaObjectDBSource

public DynaObjectDBSource()
Method Detail

recordNewObject

public NewObjectPersister recordNewObject(Persistable object)
                                   throws java.lang.Exception
Description copied from interface: WritableDataSource
This is called when a new object is persisted

Specified by:
recordNewObject in interface WritableDataSource
Returns:
persister
Throws:
java.lang.Exception

mapQuery

public java.util.Iterator mapQuery(Query query)
                            throws java.lang.Exception
Description copied from interface: DataSource
This is called when an object is being activated to retrieve the persisted data for a given object with a filter

Specified by:
mapQuery in interface DataSource
Returns:
Throws:
java.lang.Exception

comparison

protected java.lang.String comparison(Node expression,
                                      Node valueNode,
                                      int conditionType)
Overrides:
comparison in class DatabaseDataSource

nameInQuery

protected java.lang.String nameInQuery(java.lang.String name)
Specified by:
nameInQuery in class DatabaseDataSource

numberComparisonInQuery

protected java.lang.String numberComparisonInQuery(double value,
                                                   java.lang.String operator)
Overrides:
numberComparisonInQuery in class DatabaseDataSource

stringComparisonInQuery

protected java.lang.String stringComparisonInQuery(java.lang.String str,
                                                   int type)

stringComparisonInQuery

protected java.lang.String stringComparisonInQuery(java.lang.String str)
Overrides:
stringComparisonInQuery in class DatabaseDataSource

initParameters

public void initParameters(java.util.Map parameters)
                    throws java.lang.Exception
Description copied from interface: DataSource
This is called on initialization and provides access to the data source configuration parameters

Specified by:
initParameters in interface DataSource
Overrides:
initParameters in class DatabaseDataSource
Throws:
java.lang.Exception

getOrphans

public java.util.List<ObjectId> getOrphans()
Specified by:
getOrphans in interface DataSourceCanHaveOrphans

purgeOrphans

public void purgeOrphans()
Specified by:
purgeOrphans in interface DataSourceCanHaveOrphans

getConnectionObject

protected org.persvr.datasource.DynaObjectDBSource.ConnectionStatements getConnectionObject()
Description copied from class: DatabaseDataSource
This will return a thread specific connection object. It will create a new one if necessary

Overrides:
getConnectionObject in class DatabaseDataSource
Returns:

getNextId

public long getNextId()

getValueFromRs

protected java.lang.Object getValueFromRs(java.sql.ResultSet rs)
                                   throws java.sql.SQLException
Description copied from class: DatabaseDataSource
This gets the value/object for the current result set row

Specified by:
getValueFromRs in class DatabaseDataSource
Returns:
Throws:
java.sql.SQLException

mapObject

public void mapObject(PersistableInitializer initializer,
                      java.lang.String objectId)
               throws java.lang.Exception
Description copied from interface: DataSource
This is called when an object is being activated to retrieve the persisted data for a given object

Specified by:
mapObject in interface DataSource
Throws:
java.lang.Exception

getFieldValue

public java.lang.Object getFieldValue(LazyPropertyId valueId)
                               throws java.sql.SQLException
Description copied from interface: DataSource
This is called when a field value contains an unfulfilled value (ValueId)

Specified by:
getFieldValue in interface DataSource
Returns:
the real value referred to by valueId
Throws:
java.sql.SQLException

getReferrers

public java.util.List<ObjectId> getReferrers(java.lang.String id)
Specified by:
getReferrers in interface ReferenceAwareDataSource

recordPropertyAddition

public void recordPropertyAddition(java.lang.String id,
                                   java.lang.String key,
                                   java.lang.Object value,
                                   int attributes)
                            throws java.sql.SQLException
Description copied from interface: WritableDataSource
This is called when a new property is added to an object

Specified by:
recordPropertyAddition in interface WritableDataSource
value - - The value should generally be an object one of the following classes: String, Boolean, Integer, Double, Date, ObjectId, or a null If the value is an ObjectId than it indicates that it is a reference to another object. The data source can check isPersisted to see if the object has been persisted yet. If it is true than it means it means it has already been persisted. If it is false, the object has not been persisted yet. If the data source can handle a new object at this point, it should call ObjectId.persist to persist the object
attributes - TODO
Throws:
java.sql.SQLException

recordPropertyChange

public void recordPropertyChange(java.lang.String id,
                                 java.lang.String key,
                                 java.lang.Object value,
                                 int attributes)
                          throws java.sql.SQLException
Description copied from interface: WritableDataSource
This is called when a property value is changed

Specified by:
recordPropertyChange in interface WritableDataSource
attributes - TODO
Throws:
java.sql.SQLException

recordPropertyRemoval

public void recordPropertyRemoval(java.lang.String id,
                                  java.lang.String name)
                           throws java.sql.SQLException
Description copied from interface: WritableDataSource
This is called when a property value is removed

Specified by:
recordPropertyRemoval in interface WritableDataSource
Throws:
java.sql.SQLException

recordListAdd

public void recordListAdd(java.lang.String objectId,
                          int index,
                          java.lang.Object value)
                   throws java.sql.SQLException
Throws:
java.sql.SQLException

testQuery

public java.util.List testQuery(java.lang.String sql)
                         throws java.sql.SQLException
Throws:
java.sql.SQLException

recordList

public void recordList(java.lang.String id,
                       java.util.List<? extends java.lang.Object> values)
                throws java.sql.SQLException
Specified by:
recordList in interface ListDataSource
Throws:
java.sql.SQLException

recordDelete

public void recordDelete(java.lang.String objectId)
                  throws java.lang.Exception
Description copied from interface: WritableDataSource
This is called when an object should be deleted

Specified by:
recordDelete in interface WritableDataSource
Throws:
java.lang.Exception

truncate

public void truncate(java.lang.String objectId,
                     long newLength)
              throws java.lang.Exception
Throws:
java.lang.Exception

newSource

public java.util.Map<java.lang.String,java.lang.Object> newSource()
                                                           throws java.lang.Exception
Throws:
java.lang.Exception

onDelete

public void onDelete()
              throws java.lang.Exception
Description copied from interface: SourceDeleteAware
When a source is deleted this is called

Specified by:
onDelete in interface SourceDeleteAware
Throws:
java.lang.Exception

getSuperSource

public DynaObjectDBSource getSuperSource()