|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.jlf.dataMap.DataObject | +--org.jlf.dataMap.DataMappedObject
Abstract class used as the base of all objects in the data mapping framework.
DataMappedObject
is composed of four major capabilities:
1. The ability to store and retrieve attributes (primitive data types like Integer, Boolean, Date, ...) 2. The ability to store and retrieve related objects (other DataMappedObjects) 3. The ability to return the correct subclass when you read from an abstract superclass with many subclasses. 4. The ability to use the above capabilities to read attributes and related objects from a data source and write them out to a data sink.
DataObject
,
Relationship
,
RelationshipDescriptor
,
DataLocation
,
DataMapper
,
Serialized FormField Summary | |
protected static java.lang.String |
DATA_LOCATION_KEY_PROPERTY_SUFFIX
Property file key constant, appended to the name of the class, telling the default data location to use when none is specified. |
protected static java.lang.String |
DEFAULT_DATA_LOCATION_KEY
This is the property file key to the default data location. |
protected boolean |
deleteOnWrite
Flag to delete an object previously read from a database the next time the object is synchronized with the database. |
protected static java.lang.String |
FIND_ALL_CRITERIA_KEY
Default search criteria key for the framework to use when searching for information on how to query a data source for all objects of a particular object type. |
protected static java.lang.String |
FIND_BY_PRIMARY_KEY_CRITERIA_KEY
Default search criteria key for the framework to use when searching for information on how to query a data source for a particular object based on that object's primary key. |
protected boolean |
hasBeenReadFromDataSource
Flag to tell if the object has previously been read from the database. |
protected static java.lang.String |
HIERARCHY_HASHTABLE_VARIABLE_NAME
|
protected static java.lang.String |
HIERARCHY_TABLE_KEY_VECTOR_VARIABLE_NAME
|
protected static int |
INITIAL_HIERARCHY_HASHTABLE_SIZE
|
protected static int |
INITIAL_HIERARCHY_TABLE_KEY_VECTOR_SIZE
|
protected static int |
INITIAL_RELATIONSHIP_DESCRIPTOR_HASHTABLE_SIZE
|
protected static int |
INITIAL_RELATIONSHIPS_HASHTABLE_SIZE
|
protected DataMappedObjectKey |
key
Holds the key for the object. |
protected static java.lang.String |
RELATIONSHIP_DESCRIPTOR_VECTOR_VARIABLE_NAME
|
Fields inherited from class org.jlf.dataMap.DataObject |
ATTRIBUTE_DESCRIPTOR_VECTOR_VARIABLE_NAME, attributes, INITIAL_ATTRIBUTE_DESCRIPTOR_HASHTABLE_SIZE, INITIAL_ATTRIBUTE_HASHTABLE_SIZE |
Constructor Summary | |
DataMappedObject()
|
Method Summary | |
void |
addRelatedObject(java.lang.String name,
DataMappedObject dmo)
Convenience method to passthrough a related object to the relationship so it can track it. |
void |
addRelatedObjects(java.lang.String name,
java.util.Vector dmos)
Convenience method to passthrough a Vector of related objects to the relationship so it can track it. |
boolean |
areAllKeyAttributesPresent()
Checks to see if all key attributes are present. |
boolean |
areAllRequiredAttributesPresent()
Checks to see if all required attributes are present. |
protected java.util.Hashtable |
basicGetHierarchyTable()
Returns a hash table of DataMappedObjectKey
objects pertinent to the DataMappedObject . |
protected java.util.Vector |
basicGetHierarchyTableKeyAttributes()
Returns a vector of Strings which are the attribute names of any attributes in the hierarchy table. |
protected DataMappedObjectKey |
basicGetKey()
Creates a key from a list of all attribute descriptors that say that they are key attributes. |
protected java.util.Hashtable |
basicGetRelationshipDescriptors()
Returns a hash table of RelationshipDescriptor
objects pertinent to the DataMappedObject . |
void |
cleanupAfterWrite(DataMapper dataMapper)
Performs cleanup work after a write is committed to the database (for example, resets attribute values). |
void |
deleteOnWrite()
Sets a flag so that the next time you write your object to a data store, it will attempt to delete it. |
java.util.Vector |
findAll()
Quick accessor method to read all of this particular object's type from the default data location. |
java.util.Vector |
findAll(DataMapper dataMapper)
Quick accessor method to read all of this particular object's type from a specified data location. |
DataMappedObject |
findByPrimaryKey()
Quick accessor method to read one object of this particular object's type from the default data location, using its already populated primary key. |
DataMappedObject |
findByPrimaryKey(DataMapper dataMapper)
Quick accessor method to read one object of this particular object's type from a specified data mapper, using its already populated primary key. |
java.util.Vector |
findByRelationship(Relationship relationship,
DataMapper dataMapper)
Reads objects involved in a relationship that is not read in the same query as its primary object. |
java.util.Vector |
findManyBySearchCriteria(java.lang.String criteriaKey)
Helper method to read objects of a specific type and search criteria from a the default data mapper for the object. |
java.util.Vector |
findManyBySearchCriteria(java.lang.String criteriaKey,
DataMapper dataMapper)
Main kickoff method to read objects of a specific type and search criteria from a data mapper to a data location. |
DataMappedObject |
findOneBySearchCriteria(java.lang.String criteriaKey)
Helper method to read one object of a specific search criteria. |
DataMappedObject |
findOneBySearchCriteria(java.lang.String criteriaKey,
DataMapper dataMapper)
Helper method to read one object of a specific search criteria. |
java.util.Set |
getAllRelationshipNames()
Returns a set of relationship names (Strings) for all of the relationship descriptors available to the object. |
static DataMapper |
getDataMapper(java.lang.String dataLocationKey)
Convenience method to return an instance of a data mapper to the data location named by the key given. |
protected java.lang.String |
getDefaultDataLocationKey()
Returns the data location key to the properties file for this object's default data location. |
DataMapper |
getDefaultDataMapper()
Returns an instance of the default data mapper to the default data location. |
java.util.Vector |
getDeletedRelatedObjects(java.lang.String name)
Passthrough method for Relationship.getDeletedRelatedObjects(), given a particular relationship name. |
protected DataMappedObjectKey |
getHierachyTableKeyForDataArray(DataArray dataArray)
Retrieves a hierarchy table key for the current object given a data array. |
protected java.util.Hashtable |
getHierarchyTable()
Returns a lazy-initialized hierarchy table used to map incoming DataArray data to an object
of the correct subclass in an inheritance hierarchy. |
protected java.util.Vector |
getHierarchyTableKeyAttributes()
Returns a lazy-initialized vector of attribute names used to map to the hierarchy table. |
DataMappedObjectKey |
getKey()
Retrieves the key for this object. |
DataMappedObject |
getNewInstance()
Creates a new instance of a concrete subclass class of this object |
DataMappedObject |
getNewInstance(boolean reuseThisInstance)
Creates a new instance of a concrete subclass class of this object if the reuseThisInstance flag is false. |
DataMappedObject |
getNewInstance(DataArray dataArray)
Creates a new instance of a concrete subclass class of this object, taking into consideration the hierarchy table if one is defined. |
DataMappedObject |
getRelatedObject(java.lang.String name)
Passthrough method for Relationship.getRelatedObject(), given a particular relationship name. |
java.util.Vector |
getRelatedObjects(java.lang.String name)
Passthrough method for Relationship.getRelatedObjects(), given a particular relationship name. |
Relationship |
getRelationship(java.lang.String name)
Returns a relationship object for a particular relationship name. |
RelationshipDescriptor |
getRelationshipDescriptor(java.lang.String name)
Returns a relationship descriptor for a particular relationship name. |
protected java.util.Hashtable |
getRelationshipDescriptors()
Returns a lazy-initialized collection of RelationshipDescriptor
objects pertinent to the DataMappedObject . |
java.util.Vector |
getUndeletedRelatedObjects(java.lang.String name)
Passthrough method for Relationship.getUndeletedRelatedObjects(), given a particular relationship name. |
boolean |
hasBeenReadFromDataSource()
Returns a flag telling if the object has previously been read from the database. |
protected boolean |
hasHierarchyTable()
Signifies whether the class has a hierarchy table. |
boolean |
hasKey()
Checks to see if the object has any key fields. |
protected DataMappedObject |
newInstanceForDataArray(DataArray dataArray)
Creates a new instance of a concrete subclass class of this object, taking into consideration the hierarchy table defined. |
void |
populateFromDataArray(DataArray dataArray,
Relationship relationship)
Reads as many attributes as it can from the DataArray under the context of a particular relationship if available. |
protected void |
populateKeyFromParentRelationship(Relationship relationship,
DataMapper dataMapper)
Helper method to populate the key for this object as best as possible from a primary object/parent object's data. |
void |
preWriteValidation()
Hook method for data mapped objects to perform pre-write validation. |
void |
processRelationshipsFromDataArray(DataArray dataArray)
Processes any relationships from the DataArray
to populate related DataMappedObject s. |
void |
setHasBeenReadFromDataSource(boolean hasBeenRead)
Sets a flag to tell if the object has previously been read from the database. |
boolean |
shouldDeleteOnWrite()
Returns a flag telling if an object previously read from a database should be deleted the next time the object is synchronized with the database. |
void |
validateRequiredAttributesPresent()
Checks to see if all required attributes are present. |
void |
write(DataMapper dataMapper)
Writes an object out to a data source after it validates the object. |
Methods inherited from class org.jlf.dataMap.DataObject |
attributeEquals, basicGetAttributeDescriptors, equals, getAllAttributeNames, getAttribute, getAttributeDescriptor, getAttributeDescriptors, getAttributeValue, getDoubleAttribute, getLongAttribute, getStringAttribute, hasAttributeDefined, hashCode, setAttributeValue, setDoubleAttribute, setLongAttribute, setStringAttribute |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected DataMappedObjectKey key
protected static final int INITIAL_RELATIONSHIP_DESCRIPTOR_HASHTABLE_SIZE
protected static final int INITIAL_RELATIONSHIPS_HASHTABLE_SIZE
protected static final java.lang.String RELATIONSHIP_DESCRIPTOR_VECTOR_VARIABLE_NAME
protected static final int INITIAL_HIERARCHY_TABLE_KEY_VECTOR_SIZE
protected static final java.lang.String HIERARCHY_TABLE_KEY_VECTOR_VARIABLE_NAME
protected static final int INITIAL_HIERARCHY_HASHTABLE_SIZE
protected static final java.lang.String HIERARCHY_HASHTABLE_VARIABLE_NAME
protected static final java.lang.String DATA_LOCATION_KEY_PROPERTY_SUFFIX
protected static final java.lang.String DEFAULT_DATA_LOCATION_KEY
protected static final java.lang.String FIND_ALL_CRITERIA_KEY
protected static final java.lang.String FIND_BY_PRIMARY_KEY_CRITERIA_KEY
protected boolean hasBeenReadFromDataSource
protected boolean deleteOnWrite
Constructor Detail |
public DataMappedObject()
Method Detail |
protected DataMappedObjectKey basicGetKey()
public DataMappedObjectKey getKey()
protected java.util.Hashtable basicGetRelationshipDescriptors()
RelationshipDescriptor
objects pertinent to the DataMappedObject
. This
method is not lazy-initialized. Subclasses with relationships
SHOULD OVERRIDE this method, calling the superclass method of
same name and adding to the Hashtable any
RelationshipDescriptor
objects pertinent. Use
the relationship name as the key and a
RelationshipDescriptor
object as the value.At this level in the hierarchy, no relationship descriptors are known. Return an empty hash table that can be populated by the subclass(es).
protected java.util.Hashtable getRelationshipDescriptors()
RelationshipDescriptor
objects pertinent to the DataMappedObject
.
This method uses a ClassInstanceVariable
as a convenient way to do the lazy-initialization.
public RelationshipDescriptor getRelationshipDescriptor(java.lang.String name)
RelationshipDescriptor
if found.
DataMapError
- if a descriptor for the
relationship name not foundpublic java.util.Set getAllRelationshipNames()
public Relationship getRelationship(java.lang.String name)
Relationship
if found
DataMapError
- if a relationship descriptor
is not found for the relationship namepublic java.util.Vector getRelatedObjects(java.lang.String name)
DataMapError
- if the relationship descriptor
is not found for the relationshippublic java.util.Vector getUndeletedRelatedObjects(java.lang.String name)
DataMapError
- if the relationship descriptor
is not found for the relationshippublic java.util.Vector getDeletedRelatedObjects(java.lang.String name)
DataMapError
- if the relationship descriptor
is not found for the relationshippublic DataMappedObject getRelatedObject(java.lang.String name)
DataMapError
- if the relationship descriptor
is not found for the relationship namepublic void addRelatedObject(java.lang.String name, DataMappedObject dmo)
public void addRelatedObjects(java.lang.String name, java.util.Vector dmos)
protected boolean hasHierarchyTable()
NOTE: Methods hasHierarchyTable(), basicGetHierarchyTableKeyAttributes(), and basicGetHierarchyTable() must ALL be kept in sync or this will not work!
protected java.util.Vector basicGetHierarchyTableKeyAttributes()
This method is not lazy-initialized. Subclasses with hierarchy tables SHOULD OVERRIDE this method, calling the superclass method of same name and adding to the vector any attribute names appropriate.
At this level in the hierarchy, no hierarchy table members are known. Return an empty vector that can be populated by the subclass(es).
NOTE: Methods hasHierarchyTable(), basicGetHierarchyTableKeyAttributes(), and basicGetHierarchyTable() must ALL be kept in sync or this will not work!
protected java.util.Vector getHierarchyTableKeyAttributes()
This method uses a ClassInstanceVariable
as a convenient way to do the lazy-initialization.
protected java.util.Hashtable basicGetHierarchyTable()
DataMappedObjectKey
objects pertinent to the DataMappedObject
.
The key to the table is the DataAttribute which must
match attributes in the DataMappedObject
.
The value is the Java Class which should be instantiated,
when the key matches. That Java Class must be a the same
or a subclass of the current class.
This method is not lazy-initialized. Subclasses with hierarchy tables
SHOULD OVERRIDE this method, calling the superclass method of
same name and adding to the Hashtable any
DataMappedObjectKey
and Class
key/value
pairs pertinent. Use
the DataMappedObjectKey
as the key and a
Class
object as the value.
At this level in the hierarchy, no hierarchy table members are known. Return an empty hash table that can be populated by the subclass(es).
NOTE: Methods hasHierarchyTable(), basicGetHierarchyTableKeyAttributes(), and basicGetHierarchyTable() must ALL be kept in sync or this will not work!
protected java.util.Hashtable getHierarchyTable()
DataArray
data to an object
of the correct subclass in an inheritance hierarchy.
This method uses a ClassInstanceVariable
as a convenient way to do the lazy-initialization.
protected DataMappedObjectKey getHierachyTableKeyForDataArray(DataArray dataArray)
protected DataMappedObject newInstanceForDataArray(DataArray dataArray)
DataMappedObject
subclasspublic boolean hasBeenReadFromDataSource()
public void setHasBeenReadFromDataSource(boolean hasBeenRead)
public boolean shouldDeleteOnWrite()
public void deleteOnWrite()
protected java.lang.String getDefaultDataLocationKey()
public static DataMapper getDataMapper(java.lang.String dataLocationKey)
public DataMapper getDefaultDataMapper()
public DataMappedObject getNewInstance()
public DataMappedObject getNewInstance(boolean reuseThisInstance)
public DataMappedObject getNewInstance(DataArray dataArray)
DataArray
is required as input so that a subclass
can be found given a hierarchy key match to the data array row.
If no hierarchy table is defined, just returns a new instance
of this class.
DataMappedObject
subclasspublic void populateFromDataArray(DataArray dataArray, Relationship relationship)
public void processRelationshipsFromDataArray(DataArray dataArray)
DataArray
to populate related DataMappedObject
s.
public void validateRequiredAttributesPresent()
RequiredAttributeNotPresent
public boolean areAllRequiredAttributesPresent()
public boolean hasKey()
public boolean areAllKeyAttributesPresent()
public java.util.Vector findAll()
public DataMappedObject findByPrimaryKey()
public java.util.Vector findAll(DataMapper dataMapper)
public DataMappedObject findByPrimaryKey(DataMapper dataMapper)
protected void populateKeyFromParentRelationship(Relationship relationship, DataMapper dataMapper)
public java.util.Vector findByRelationship(Relationship relationship, DataMapper dataMapper)
You MUST override the default implemetation of this method if you want any other behavior, and since relationships are very tricky, you are likely to have to do so.
public DataMappedObject findOneBySearchCriteria(java.lang.String criteriaKey)
public DataMappedObject findOneBySearchCriteria(java.lang.String criteriaKey, DataMapper dataMapper)
public java.util.Vector findManyBySearchCriteria(java.lang.String criteriaKey)
public java.util.Vector findManyBySearchCriteria(java.lang.String criteriaKey, DataMapper dataMapper)
public void preWriteValidation()
Typically you should override this method, calling the super first, then adding your own extra validation logic.
public void write(DataMapper dataMapper)
public void cleanupAfterWrite(DataMapper dataMapper)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |