Class ObjectBuilder
- java.lang.Object
-
- org.eclipse.persistence.internal.core.descriptors.CoreObjectBuilder<AbstractRecord,AbstractSession,DatabaseField,DatabaseMapping>
-
- org.eclipse.persistence.internal.descriptors.ObjectBuilder
-
- All Implemented Interfaces:
Serializable
,Cloneable
- Direct Known Subclasses:
XMLObjectBuilder
public class ObjectBuilder extends CoreObjectBuilder<AbstractRecord,AbstractSession,DatabaseField,DatabaseMapping> implements Cloneable, Serializable
Purpose: Object builder is one of the behavior class attached to descriptor. It is responsible for building objects, rows, and extracting primary keys from the object and the rows.
- Since:
- TOPLink/Java 1.0
- Author:
- Sati
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected List<DatabaseMapping>
batchFetchedAttributes
PERF: Cache mapping that use batch fetching.protected List<DatabaseMapping>
cloningMappings
PERF: Cache mappings that require cloning.protected ClassDescriptor
descriptor
protected List<DatabaseMapping>
eagerMappings
PERF: Cache mappings that are eager loaded.protected Map<DatabaseField,DatabaseField>
fieldsMap
Used to maintain identity on the field objects.protected boolean
hasCacheIndexesInSopObject
PERF: is there an cache index field that's would not be selected by SOP query.protected boolean
hasInBatchFetchedAttribute
PERF: Cache mapping that use batch fetching.protected boolean
hasWrapperPolicy
PERF: Cache if has a wrapper policy.protected boolean
isSimple
PERF: Cache if is a simple mapping, all direct.protected List<DatabaseMapping>
joinedAttributes
PERF: Cache mapping that use joining.protected String
lockAttribute
attribute name corresponding to optimistic lock field, set only if optimistic locking is usedprotected Map<String,DatabaseMapping>
mappingsByAttribute
Mappings keyed by attribute name.protected Map<DatabaseField,DatabaseMapping>
mappingsByField
Mappings keyed by database field.protected boolean
mayHaveNullInPrimaryKey
indicates whether part of primary key is unmapped - may happen only in case AggregateObject or AggregateCollection descriptor.protected List<DatabaseMapping>
nonPrimaryKeyMappings
All mapping other than primary key mappings.protected List<Class>
primaryKeyClassifications
The types for the primary key fields, in same order as descriptor's primary key fields.protected Expression
primaryKeyExpression
Expression for querying an object by primary key.protected List<DatabaseMapping>
primaryKeyMappings
Mapping for the primary key fields.protected Map<DatabaseField,List<DatabaseMapping>>
readOnlyMappingsByField
List of read-only mappings using a database field.protected List<DatabaseMapping>
relationshipMappings
PERF: Cache relationship mappings.protected AbstractDirectMapping
sequenceMapping
PERF: Cache sequence mappings.protected boolean
shouldKeepRow
PERF: is there a mapping using indirection (could be nested in aggregate(s)), or any other reason to keep row after the object has been created.
-
Constructor Summary
Constructors Constructor Description ObjectBuilder(ClassDescriptor descriptor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPrimaryKeyForNonDefaultTable(AbstractRecord databaseRow)
Add the primary key and its value to the Record for all the non default tables.void
addPrimaryKeyForNonDefaultTable(AbstractRecord databaseRow, Object object, AbstractSession session)
Add the primary key and its value to the Record for all the non default tables.void
assignReturnRow(Object object, AbstractSession writeSession, AbstractRecord row, ObjectChangeSet changeSet)
Assign the fields in the row back into the object.void
assignReturnValueForField(Object object, ReadObjectQuery query, AbstractRecord row, DatabaseField field, Collection handledMappings, ObjectChangeSet changeSet)
Assign the field value from the row to the object for all the mappings using field (read or write).protected void
assignReturnValueToMapping(Object object, ReadObjectQuery query, AbstractRecord row, DatabaseField field, DatabaseMapping mapping, Collection handledMappings, ObjectChangeSet changeSet)
INTERNAL: Assign values from objectRow to the object through the mapping.protected Object
assignSequenceNumber(Object object, Object sequenceValue, AbstractSession writeSession, WriteObjectQuery writeQuery)
INTERNAL: Update the object primary key by fetching a new sequence number from the accessor.Object
assignSequenceNumber(Object object, AbstractSession writeSession)
INTERNAL: Update the object primary key by fetching a new sequence number from the accessor.Object
assignSequenceNumber(WriteObjectQuery writeQuery)
INTERNAL: Update the writeQuery's object primary key by fetching a new sequence number from the accessor.Object
assignSequenceNumber(WriteObjectQuery writeQuery, Object sequenceValue)
INTERNAL: Update the writeQuery's object primary key by fetching a new sequence number from the accessor.void
buildAttributesIntoObject(Object domainObject, CacheKey cacheKey, AbstractRecord databaseRow, ObjectBuildingQuery query, JoinedAttributeManager joinManager, FetchGroup executionFetchGroup, boolean forRefresh, AbstractSession targetSession)
Each mapping is recursed to assign values from the Record to the attributes in the domain object.protected boolean
buildAttributesIntoObjectSOP(Object domainObject, CacheKey cacheKey, AbstractRecord databaseRow, ObjectBuildingQuery query, JoinedAttributeManager joinManager, FetchGroup executionFetchGroup, boolean forRefresh, AbstractSession targetSession)
Each mapping is recursed to assign values from the Record to the attributes in the domain object.void
buildAttributesIntoShallowObject(Object original, AbstractRecord databaseRow, ObjectBuildingQuery query)
INTERNAL: For reading through the write connection when in transaction, We need a partially populated original, so that we can build a clone using the copy policy, even though we can't put this original in the shared cache yet; just build a shallow original (i.e.void
buildAttributesIntoWorkingCopyClone(Object clone, CacheKey sharedCacheKey, ObjectBuildingQuery query, JoinedAttributeManager joinManager, AbstractRecord databaseRow, UnitOfWorkImpl unitOfWork, boolean forRefresh)
INTERNAL: For reading through the write connection when in transaction, populate the clone directly from the database row.protected boolean
buildAttributesIntoWorkingCopyCloneSOP(Object clone, CacheKey sharedCacheKey, ObjectBuildingQuery query, JoinedAttributeManager joinManager, AbstractRecord databaseRow, UnitOfWorkImpl unitOfWork, boolean forRefresh)
For reading through the write connection when in transaction, populate the clone directly from the database row.Object
buildBackupClone(Object clone, UnitOfWorkImpl unitOfWork)
Returns the backup clone of the specified object.Expression
buildDeleteExpression(DatabaseTable table, AbstractRecord row, boolean usesOptimisticLocking)
Build and return the expression to use as the where clause to delete an object.Expression
buildExpressionFromExample(Object queryObject, QueryByExamplePolicy policy, Expression expressionBuilder, Map processedObjects, AbstractSession session)
INTERNAL: This method is used when Query By Example is used.Object
buildNewInstance()
Return a new instance of the receiver's javaClass.protected Object
buildObject(boolean returnCacheKey, ObjectBuildingQuery query, AbstractRecord databaseRow, AbstractSession session, Object primaryKey, CacheKey preFetchedCacheKey, ClassDescriptor concreteDescriptor, JoinedAttributeManager joinManager)
Return an instance of the receivers javaClass.Object
buildObject(ObjectBuildingQuery query, AbstractRecord databaseRow, JoinedAttributeManager joinManager)
Return an instance of the receivers javaClass.Object
buildObject(ObjectBuildingQuery query, AbstractRecord databaseRow, JoinedAttributeManager joinManager, AbstractSession session, ClassDescriptor concreteDescriptor, InheritancePolicy inheritancePolicy, boolean isUnitOfWork, boolean shouldCacheQueryResults, boolean shouldUseWrapperPolicy)
Return an instance of the receivers javaClass.Object
buildObject(ObjectLevelReadQuery query, AbstractRecord databaseRow)
Return an instance of the receivers javaClass.Object
buildObjectFromResultSet(ObjectBuildingQuery query, JoinedAttributeManager joinManager, ResultSet resultSet, AbstractSession executionSession, DatabaseAccessor accessor, ResultSetMetaData metaData, DatabasePlatform platform, Vector fieldsList, DatabaseField[] fieldsArray)
INTERNAL: Builds a working copy clone directly from a result set.protected Object
buildObjectInUnitOfWork(ObjectBuildingQuery query, JoinedAttributeManager joinManager, AbstractRecord databaseRow, UnitOfWorkImpl unitOfWork, Object primaryKey, CacheKey preFetchedCacheKey, ClassDescriptor concreteDescriptor)
For executing all reads on the UnitOfWork, the session when building objects from rows will now be the UnitOfWork.Object
buildObjectsFromCursorInto(ReadAllQuery query, List databaseRows, Object domainObjects)
Return a container which contains the instances of the receivers javaClass.Object
buildObjectsFromResultSetInto(ReadAllQuery query, ResultSet resultSet, Vector fields, DatabaseField[] fieldsArray, Object domainObjects)
Version of buildObjectsInto method that takes call instead of rows.Object
buildObjectsInto(ReadAllQuery query, List databaseRows, Object domainObjects)
Return a container which contains the instances of the receivers javaClass.void
buildPrimaryKeyAttributesIntoObject(Object original, AbstractRecord databaseRow, ObjectBuildingQuery query, AbstractSession session)
INTERNAL: Build just the primary key mappings into the object.Expression
buildPrimaryKeyExpression(DatabaseTable table)
Build the primary key expression for the secondary table.Expression
buildPrimaryKeyExpressionFromKeys(Object primaryKey, AbstractSession session)
Build the primary key expression from the specified primary key values.Expression
buildPrimaryKeyExpressionFromObject(Object domainObject, AbstractSession session)
Build the primary key expression from the specified domain object.protected Object
buildProtectedObject(boolean returnCacheKey, ObjectBuildingQuery query, AbstractRecord databaseRow, AbstractSession session, Object primaryKey, CacheKey preFetchedCacheKey, ClassDescriptor concreteDescriptor, JoinedAttributeManager joinManager)
Return an instance of the receivers javaClass.AbstractRecord
buildRow(Object object, AbstractSession session, DatabaseMapping.WriteType writeType)
Build the row representation of an object.AbstractRecord
buildRow(AbstractRecord databaseRow, Object object, AbstractSession session, DatabaseMapping.WriteType writeType)
Build the row representation of an object.AbstractRecord
buildRowForShallowInsert(Object object, AbstractSession session)
Build the row representation of the object for update.AbstractRecord
buildRowForShallowInsert(AbstractRecord databaseRow, Object object, AbstractSession session)
Build the row representation of the object for update.AbstractRecord
buildRowForTranslation(Object object, AbstractSession session)
Build the row representation of an object.AbstractRecord
buildRowForUpdate(AbstractRecord databaseRow, WriteObjectQuery query)
Build into the row representation of the object for update.AbstractRecord
buildRowForUpdate(WriteObjectQuery query)
Build the row representation of the object for update.AbstractRecord
buildRowForUpdateAfterShallowInsert(Object object, AbstractSession session, DatabaseTable table)
Build the row representation of the object that contains only the fields nullified by shallow insert.AbstractRecord
buildRowForUpdateAfterShallowInsert(AbstractRecord databaseRow, Object object, AbstractSession session, DatabaseTable table)
Build the row representation of the object that contains only the fields nullified by shallow insert.AbstractRecord
buildRowForUpdateBeforeShallowDelete(Object object, AbstractSession session, DatabaseTable table)
Build the row representation of the object that contains only the fields nullified by shallow insert, with all values set to null.AbstractRecord
buildRowForUpdateBeforeShallowDelete(AbstractRecord databaseRow, Object object, AbstractSession session, DatabaseTable table)
Build the row representation of the object that contains only the fields nullified by shallow insert, with all values set to null.AbstractRecord
buildRowForUpdateWithChangeSet(WriteObjectQuery query)
Build the row representation of the object for update.AbstractRecord
buildRowForWhereClause(ObjectLevelModifyQuery query)
Build the row representation of an object.AbstractRecord
buildRowFromPrimaryKeyValues(Object key, AbstractSession session)
Build the row from the primary key values.AbstractRecord
buildRowWithChangeSet(AbstractRecord databaseRow, ObjectChangeSet objectChangeSet, AbstractSession session, DatabaseMapping.WriteType writeType)
Build the row representation of an object.AbstractRecord
buildTemplateInsertRow(AbstractSession session)
Build the row of all of the fields used for insertion.void
buildTemplateInsertRow(AbstractSession session, AbstractRecord databaseRow)
AbstractRecord
buildTemplateUpdateRow(AbstractSession session)
Build the row representation of the object for update.Expression
buildUpdateExpression(DatabaseTable table, AbstractRecord transactionRow, AbstractRecord modifyRow)
Build and return the expression to use as the where clause to an update object.protected Object
buildWorkingCopyCloneFromRow(ObjectBuildingQuery query, JoinedAttributeManager joinManager, AbstractRecord databaseRow, UnitOfWorkImpl unitOfWork, Object primaryKey, CacheKey preFetchedCacheKey)
INTERNAL: Builds a working copy clone directly from the database row.protected Object
buildWorkingCopyCloneNormally(ObjectBuildingQuery query, AbstractRecord databaseRow, UnitOfWorkImpl unitOfWork, Object primaryKey, CacheKey preFetchedCacheKey, ClassDescriptor concreteDescriptor, JoinedAttributeManager joinManager)
buildWorkingCopyCloneFromRow is an alternative to this which is the normal behavior.void
cacheForeignKeyValues(Object source, CacheKey cacheKey, ClassDescriptor descriptor, AbstractSession session)
INTERNAL: This method is used to store the FK values used for this mapping in the cachekey.void
cacheForeignKeyValues(AbstractRecord databaseRecord, CacheKey cacheKey, AbstractSession session)
INTERNAL: This method is used to store the FK values used for this mapping in the cachekey.void
cascadeDiscoverAndPersistUnregisteredNewObjects(Object object, Map newObjects, Map unregisteredExistingObjects, Map visitedObjects, UnitOfWorkImpl uow, Set cascadeErrors)
INTERNAL: Cascade discover and persist new objects during commit.void
cascadePerformRemove(Object object, UnitOfWorkImpl uow, Map visitedObjects)
INTERNAL: This method is used by the UnitOfWork to cascade registration of new objects.void
cascadePerformRemovePrivateOwnedObjectFromChangeSet(Object object, UnitOfWorkImpl uow, Map visitedObjects)
INTERNAL: This method is used to iterate over the specified object's mappings and cascade remove orphaned private owned objects from the UnitOfWorkChangeSet and IdentityMap.void
cascadeRegisterNewForCreate(Object object, UnitOfWorkImpl uow, Map visitedObjects)
INTERNAL: This method is used by the UnitOfWork to cascade registration of new objects.void
clearPrimaryKey(Object object)
Clear any primary key cache data in the object.Object
clone()
Returns a clone of itself.ObjectChangeSet
compareForChange(Object clone, Object backUp, UnitOfWorkChangeSet changeSet, AbstractSession session)
INTERNAL: This method creates a records change set for a particular object.boolean
compareObjects(Object firstObject, Object secondObject, AbstractSession session)
Compares the two specified objectsvoid
copyInto(Object source, Object target)
Copy each attribute from one object into the other.void
copyInto(Object source, Object target, boolean cloneOneToOneValueHolders)
Copy each attribute from one object into the other.Object
copyObject(Object original, CopyGroup copyGroup)
Return a copy of the object.protected void
copyQueryInfoToCacheKey(CacheKey cacheKey, ObjectBuildingQuery query, AbstractRecord databaseRow, AbstractSession session, ClassDescriptor concreteDescriptor)
Initialize a cache key.ObjectChangeSet
createObjectChangeSet(Object clone, UnitOfWorkChangeSet uowChangeSet, boolean isNew, boolean assignPrimaryKeyIfExisting, AbstractSession session)
INTERNAL: Used by the ObjectBuilder to create an ObjectChangeSet for the specified clone object.ObjectChangeSet
createObjectChangeSet(Object clone, UnitOfWorkChangeSet uowChangeSet, boolean isNew, AbstractSession session)
INTERNAL: Used by the ObjectBuilder to create an ObjectChangeSet for the specified clone object.ObjectChangeSet
createObjectChangeSet(Object clone, UnitOfWorkChangeSet uowChangeSet, AbstractSession session)
INTERNAL: Used by the ObjectBuilder to create an ObjectChangeSet for the specified clone object.void
createPrimaryKeyExpression(AbstractSession session)
Creates and stores primary key expression.AbstractRecord
createRecord(int size, AbstractSession session)
Create a new row/record for the object builder.AbstractRecord
createRecord(AbstractSession session)
Create a new row/record for the object builder.protected AbstractRecord
createRecordForPKExtraction(int size, AbstractSession session)
Create a new row/record for the object builder.AbstractRecord
createRecordFromXMLContext(XMLContext context)
Create a new row/record from XMLContext.Object
extractPrimaryKeyFromExpression(boolean requiresExactMatch, Expression expression, AbstractRecord translationRow, AbstractSession session)
Return the row with primary keys and their values from the given expression.Object
extractPrimaryKeyFromObject(Object domainObject, AbstractSession session)
Extract primary key attribute values from the domainObject.Object
extractPrimaryKeyFromObject(Object domainObject, AbstractSession session, boolean shouldReturnNullIfNull)
Extract primary key attribute values from the domainObject.Object
extractPrimaryKeyFromRow(AbstractRecord databaseRow, AbstractSession session)
Extract primary key values from the specified row.AbstractRecord
extractPrimaryKeyRowFromExpression(Expression expression, AbstractRecord translationRow, AbstractSession session)
Return the row with primary keys and their values from the given expression.AbstractRecord
extractPrimaryKeyRowFromObject(Object domainObject, AbstractSession session)
Extract primary key attribute values from the domainObject.AbstractRecord
extractRowFromExpression(Expression expression, AbstractRecord translationRow, AbstractSession session)
Return the row from the given expression.Object
extractValueFromObjectForField(Object domainObject, DatabaseField field, AbstractSession session)
Extract the value of the primary key attribute from the specified object.void
fixObjectReferences(Object object, Map objectDescriptors, Map processedObjects, ObjectLevelReadQuery query, DistributedSession session)
INTERNAL: An object has been serialized from the server to the client.ChangeRecord
getBaseChangeRecordForField(ObjectChangeSet objectChangeSet, Object object, DatabaseField databaseField, AbstractSession session)
Return the base ChangeRecord for the given DatabaseField.DatabaseMapping
getBaseMappingForField(DatabaseField databaseField)
Return the base mapping for the given DatabaseField.Object
getBaseValueForField(DatabaseField databaseField, Object domainObject)
Return the base value that is mapped to for given field.List<DatabaseMapping>
getBatchFetchedAttributes()
Return the mappings that are always batch fetched.List<DatabaseMapping>
getCloningMappings()
PERF: Return all mappings that require cloning.ClassDescriptor
getDescriptor()
Return the descriptorList<DatabaseMapping>
getEagerMappings()
PERF: Return all mappings that are eager loaded (but use indirection).Class
getFieldClassification(DatabaseField fieldToClassify)
INTERNAL: Return the classification for the field contained in the mapping.DatabaseField
getFieldForQueryKeyName(String name)
Return the field used for the query key name.Map<DatabaseField,DatabaseField>
getFieldsMap()
Return the fields map.List<DatabaseMapping>
getJoinedAttributes()
Answers the attributes which are always joined to the original query on reads.String
getLockAttribute()
DatabaseMapping
getMappingForAttributeName(String name)
Return the mapping for the specified attribute name.DatabaseMapping
getMappingForField(DatabaseField field)
Return al the mapping for the specified field.protected Map<String,DatabaseMapping>
getMappingsByAttribute()
Return all the mapping to attribute associationsMap<DatabaseField,DatabaseMapping>
getMappingsByField()
INTERNAL: Return all the mapping to field associationsprotected List<DatabaseMapping>
getNonPrimaryKeyMappings()
Return the non primary key mappings.Object
getParentObjectForField(DatabaseField databaseField, Object domainObject)
Return the base value that is mapped to for given field.List<Class>
getPrimaryKeyClassifications()
Return primary key classifications.Expression
getPrimaryKeyExpression()
Return the primary key expressionList<DatabaseMapping>
getPrimaryKeyMappings()
Return primary key mappings.Map<DatabaseField,List<DatabaseMapping>>
getReadOnlyMappingsByField()
INTERNAL: Return all the read-only mapping to field associationsList<DatabaseMapping>
getReadOnlyMappingsForField(DatabaseField field)
Return all the read-only mapping for the specified field.List<DatabaseMapping>
getRelationshipMappings()
PERF: Return all relationship mappings.AbstractDirectMapping
getSequenceMapping()
PERF: Return the sequence mapping.DatabaseField
getTargetFieldForQueryKeyName(String queryKeyName)
INTERNAL: return a database field based on a query key nameboolean
hasBatchFetchedAttributes()
Return is any mappings are always batch fetched.boolean
hasCacheIndexesInSopObject()
boolean
hasInBatchFetchedAttribute()
Return is any mappings are always batch fetched using IN.boolean
hasJoinedAttributes()
Answers if any attributes are to be joined / returned in the same select statement.boolean
hasWrapperPolicy()
Return if the descriptor has a wrapper policy.protected void
initialize(ClassDescriptor descriptor)
void
initialize(AbstractSession session)
Cache all the mappings by their attribute and fields.void
initializeBatchFetchedAttributes()
INTERNAL: Iterates through all one to one mappings and checks if any of them use batch fetching.void
initializeJoinedAttributes()
INTERNAL: Iterates through all one to one mappings and checks if any of them use joining.void
initializePrimaryKey(AbstractSession session)
Cache primary key and non primary key mappings.Object
instantiateClone(Object domainObject, AbstractSession session)
Returns the clone of the specified object.void
instantiateEagerMappings(Object object, AbstractSession session)
Force instantiation to any eager mappings.Object
instantiateWorkingCopyClone(Object domainObject, AbstractSession session)
Returns the clone of the specified object.Object
instantiateWorkingCopyCloneFromRow(AbstractRecord row, ObjectBuildingQuery query, Object primaryKey, UnitOfWorkImpl unitOfWork)
It is now possible to build working copy clones directly from rows.boolean
isPrimaryKeyComponentInvalid(Object keyValue, int index)
boolean
isPrimaryKeyExpression(boolean requiresExactMatch, Expression expression, AbstractSession session)
Return if the expression is by primary key.boolean
isPrimaryKeyMapping(DatabaseMapping mapping)
boolean
isSimple()
PERF: Return if the descriptor has no complex mappings, all direct.boolean
isXMLObjectBuilder()
void
iterate(DescriptorIterator iterator)
INTERNAL: Perform the iteration operation on the objects attributes through the mappings.void
load(Object object, AttributeGroup group, AbstractSession session, boolean fromFetchGroup)
Force instantiation to any mappings in the load group.void
loadAll(Object object, AbstractSession session)
Force instantiation of all indirections.void
loadAll(Object object, AbstractSession session, IdentityHashSet loaded)
protected void
loadBatchReadAttributes(ClassDescriptor concreteDescriptor, Object sourceObject, CacheKey cacheKey, AbstractRecord databaseRow, ObjectBuildingQuery query, JoinedAttributeManager joinManager, boolean isTargetProtected)
protected void
loadJoinedAttributes(ClassDescriptor concreteDescriptor, Object sourceObject, CacheKey cacheKey, AbstractRecord databaseRow, JoinedAttributeManager joinManager, ObjectBuildingQuery query, boolean isTargetProtected)
void
mergeChangesIntoObject(Object target, ObjectChangeSet changeSet, Object source, MergeManager mergeManager, AbstractSession targetSession)
INTERNAL: Merge changes between the objects, this merge algorithm is dependent on the merge manager.void
mergeChangesIntoObject(Object target, ObjectChangeSet changeSet, Object source, MergeManager mergeManager, AbstractSession targetSession, boolean isTargetCloneOfOriginal, boolean shouldMergeFetchGroup)
INTERNAL: Merge changes between the objects, this merge algorithm is dependent on the merge manager.void
mergeIntoObject(Object target, boolean isUnInitialized, Object source, MergeManager mergeManager, AbstractSession targetSession)
INTERNAL: Merge the contents of one object into another, this merge algorithm is dependent on the merge manager.void
mergeIntoObject(Object target, ObjectChangeSet changeSet, boolean isUnInitialized, Object source, MergeManager mergeManager, AbstractSession targetSession, boolean cascadeOnly, boolean isTargetCloneOfOriginal, boolean shouldMergeFetchGroup)
INTERNAL: Merge the contents of one object into another, this merge algorithm is dependent on the merge manager.void
populateAttributesForClone(Object original, CacheKey cacheKey, Object clone, Integer refreshCascade, AbstractSession cloningSession)
Clones the attributes of the specified object.protected void
postBuildAttributesIntoObjectEvent(Object domainObject, AbstractRecord databaseRow, ObjectBuildingQuery query, boolean forRefresh)
protected void
postBuildAttributesIntoWorkingCopyCloneEvent(Object clone, AbstractRecord databaseRow, ObjectBuildingQuery query, UnitOfWorkImpl unitOfWork, boolean forRefresh)
void
postInitialize(AbstractSession session)
INTERNAL: Post initializations after mappings are initialized.void
recordPrivateOwnedRemovals(Object object, UnitOfWorkImpl uow, boolean initialPass)
protected boolean
refreshObjectIfRequired(ClassDescriptor concreteDescriptor, CacheKey cacheKey, Object domainObject, ObjectBuildingQuery query, JoinedAttributeManager joinManager, AbstractRecord databaseRow, AbstractSession session, boolean targetIsProtected)
This method is called when a cached Entity needs to be refreshedvoid
rehashFieldDependancies(AbstractSession session)
Rehash any maps based on fields.void
setDescriptor(ClassDescriptor aDescriptor)
Set the descriptor.protected void
setFieldsMap(Map fieldsMap)
Return the fields map.void
setHasInBatchFetchedAttribute(boolean hasInBatchFetchedAttribute)
Set if any mappings are always batch fetched using IN.void
setHasWrapperPolicy(boolean hasWrapperPolicy)
Set if the descriptor has a wrapper policy.protected void
setMappingsByAttribute(Map<String,DatabaseMapping> theAttributeMappings)
All the mappings and their respective attribute associations are cached for performance improvement.void
setMappingsByField(Map<DatabaseField,DatabaseMapping> theFieldMappings)
INTERNAL: All the mappings and their respective field associations are cached for performance improvement.protected void
setNonPrimaryKeyMappings(List<DatabaseMapping> theNonPrimaryKeyMappings)
The non primary key mappings are cached to improve performance.void
setPrimaryKeyClassifications(List<Class> primaryKeyClassifications)
INTERNAL: Set primary key classifications.void
setPrimaryKeyExpression(Expression criteria)
The primary key expression is cached to improve performance.protected void
setPrimaryKeyMappings(List<DatabaseMapping> thePrimaryKeyMappings)
The primary key mappings are cached to improve performance.void
setReadOnlyMappingsByField(Map<DatabaseField,List<DatabaseMapping>> theReadOnlyFieldMappings)
INTERNAL: All the read-only mappings and their respective field associations are cached for performance improvement.void
setSequenceMapping(AbstractDirectMapping sequenceMapping)
PERF: Set the sequence mapping.boolean
shouldKeepRow()
String
toString()
void
trimFieldsForInsert(AbstractSession session, AbstractRecord databaseRow)
INTERNAL Remove a potential sequence number field and invoke the ReturningPolicy trimModifyRowsForInsert methodObject
unwrapObject(Object proxy, AbstractSession session)
Unwrap the object if required.void
updateCachedAttributes(PersistenceEntity persistenceEntity, CacheKey cacheKey, Object primaryKey)
INTERNAL: Used to updated any attributes that may be cached on a woven entityvoid
validate(AbstractSession session)
Validates the object builder.boolean
verifyDelete(Object object, AbstractSession session)
Verify that an object has been deleted from the database.Object
wrapObject(Object implementation, AbstractSession session)
Wrap the object if required.AbstractRecord
writeIntoRowFromPrimaryKeyValues(AbstractRecord row, Object primaryKey, AbstractSession session, boolean convert)
Build the row from the primary key values.
-
-
-
Field Detail
-
descriptor
protected ClassDescriptor descriptor
-
mappingsByAttribute
protected Map<String,DatabaseMapping> mappingsByAttribute
Mappings keyed by attribute name.
-
mappingsByField
protected Map<DatabaseField,DatabaseMapping> mappingsByField
Mappings keyed by database field.
-
readOnlyMappingsByField
protected Map<DatabaseField,List<DatabaseMapping>> readOnlyMappingsByField
List of read-only mappings using a database field.
-
fieldsMap
protected Map<DatabaseField,DatabaseField> fieldsMap
Used to maintain identity on the field objects. Ensure they get the correct index/type.
-
primaryKeyMappings
protected List<DatabaseMapping> primaryKeyMappings
Mapping for the primary key fields.
-
primaryKeyClassifications
protected List<Class> primaryKeyClassifications
The types for the primary key fields, in same order as descriptor's primary key fields.
-
nonPrimaryKeyMappings
protected transient List<DatabaseMapping> nonPrimaryKeyMappings
All mapping other than primary key mappings.
-
primaryKeyExpression
protected transient Expression primaryKeyExpression
Expression for querying an object by primary key.
-
joinedAttributes
protected List<DatabaseMapping> joinedAttributes
PERF: Cache mapping that use joining.
-
batchFetchedAttributes
protected List<DatabaseMapping> batchFetchedAttributes
PERF: Cache mapping that use batch fetching.
-
hasInBatchFetchedAttribute
protected boolean hasInBatchFetchedAttribute
PERF: Cache mapping that use batch fetching.
-
cloningMappings
protected List<DatabaseMapping> cloningMappings
PERF: Cache mappings that require cloning.
-
eagerMappings
protected List<DatabaseMapping> eagerMappings
PERF: Cache mappings that are eager loaded.
-
relationshipMappings
protected List<DatabaseMapping> relationshipMappings
PERF: Cache relationship mappings.
-
isSimple
protected boolean isSimple
PERF: Cache if is a simple mapping, all direct.
-
hasWrapperPolicy
protected boolean hasWrapperPolicy
PERF: Cache if has a wrapper policy.
-
sequenceMapping
protected AbstractDirectMapping sequenceMapping
PERF: Cache sequence mappings.
-
mayHaveNullInPrimaryKey
protected boolean mayHaveNullInPrimaryKey
indicates whether part of primary key is unmapped - may happen only in case AggregateObject or AggregateCollection descriptor.
-
lockAttribute
protected String lockAttribute
attribute name corresponding to optimistic lock field, set only if optimistic locking is used
-
shouldKeepRow
protected boolean shouldKeepRow
PERF: is there a mapping using indirection (could be nested in aggregate(s)), or any other reason to keep row after the object has been created. Used by ObjectLevelReadQuery ResultSetAccessOptimization.
-
hasCacheIndexesInSopObject
protected boolean hasCacheIndexesInSopObject
PERF: is there an cache index field that's would not be selected by SOP query. Ignored unless descriptor uses SOP and CachePolicy has cache indexes.
-
-
Constructor Detail
-
ObjectBuilder
public ObjectBuilder(ClassDescriptor descriptor)
-
-
Method Detail
-
initialize
protected void initialize(ClassDescriptor descriptor)
-
createRecord
public AbstractRecord createRecord(AbstractSession session)
Create a new row/record for the object builder. This allows subclasses to define different record types.- Specified by:
createRecord
in classCoreObjectBuilder<AbstractRecord,AbstractSession,DatabaseField,DatabaseMapping>
-
createRecord
public AbstractRecord createRecord(int size, AbstractSession session)
Create a new row/record for the object builder. This allows subclasses to define different record types.
-
createRecordForPKExtraction
protected AbstractRecord createRecordForPKExtraction(int size, AbstractSession session)
Create a new row/record for the object builder. This allows subclasses to define different record types. This will typically be called when a record will be used for temporarily holding on to primary key fields.
-
addPrimaryKeyForNonDefaultTable
public void addPrimaryKeyForNonDefaultTable(AbstractRecord databaseRow)
Add the primary key and its value to the Record for all the non default tables. This method is used while writing into the multiple tables.
-
addPrimaryKeyForNonDefaultTable
public void addPrimaryKeyForNonDefaultTable(AbstractRecord databaseRow, Object object, AbstractSession session)
Add the primary key and its value to the Record for all the non default tables. This method is used while writing into the multiple tables.
-
clearPrimaryKey
public void clearPrimaryKey(Object object)
Clear any primary key cache data in the object.
-
assignReturnRow
public void assignReturnRow(Object object, AbstractSession writeSession, AbstractRecord row, ObjectChangeSet changeSet) throws DatabaseException
Assign the fields in the row back into the object. This is used by returning, as well as events and version locking. If not null changeSet must correspond to object. changeSet is updated with all of the field values in the row.- Throws:
DatabaseException
-
assignReturnValueForField
public void assignReturnValueForField(Object object, ReadObjectQuery query, AbstractRecord row, DatabaseField field, Collection handledMappings, ObjectChangeSet changeSet)
Assign the field value from the row to the object for all the mappings using field (read or write). If not null changeSet must correspond to object. changeSet is updated with all of the field values in the row.
-
assignReturnValueToMapping
protected void assignReturnValueToMapping(Object object, ReadObjectQuery query, AbstractRecord row, DatabaseField field, DatabaseMapping mapping, Collection handledMappings, ObjectChangeSet changeSet)
INTERNAL: Assign values from objectRow to the object through the mapping. If not null changeSet must correspond to object. changeSet is updated with all of the field values in the row.
-
assignSequenceNumber
public Object assignSequenceNumber(Object object, AbstractSession writeSession) throws DatabaseException
INTERNAL: Update the object primary key by fetching a new sequence number from the accessor. This assume the uses sequence numbers check has already been done.- Returns:
- the sequence value or null if not assigned.
- Throws:
DatabaseException
- - an error has occurred on the database.
-
assignSequenceNumber
public Object assignSequenceNumber(WriteObjectQuery writeQuery) throws DatabaseException
INTERNAL: Update the writeQuery's object primary key by fetching a new sequence number from the accessor. This assume the uses sequence numbers check has already been done. Adds the assigned sequence value to writeQuery's modify row. If object has a changeSet then sets sequence value into change set as an Id adds it also to object's change set in a ChangeRecord if required.- Returns:
- the sequence value or null if not assigned.
- Throws:
DatabaseException
- - an error has occurred on the database.
-
assignSequenceNumber
public Object assignSequenceNumber(WriteObjectQuery writeQuery, Object sequenceValue) throws DatabaseException
INTERNAL: Update the writeQuery's object primary key by fetching a new sequence number from the accessor. This assume the uses sequence numbers check has already been done. Adds the assigned sequence value to writeQuery's modify row. If object has a changeSet then sets sequence value into change set as an Id adds it also to object's change set in a ChangeRecord if required.- Returns:
- the sequence value or null if not assigned.
- Throws:
DatabaseException
- - an error has occurred on the database.
-
assignSequenceNumber
protected Object assignSequenceNumber(Object object, Object sequenceValue, AbstractSession writeSession, WriteObjectQuery writeQuery) throws DatabaseException
INTERNAL: Update the object primary key by fetching a new sequence number from the accessor. This assume the uses sequence numbers check has already been done. Adds the assigned sequence value to writeQuery's modify row. If object has a changeSet then sets sequence value into change set as an Id adds it also to object's change set in a ChangeRecord if required.- Returns:
- the sequence value or null if not assigned.
- Throws:
DatabaseException
- - an error has occurred on the database.
-
buildAttributesIntoObject
public void buildAttributesIntoObject(Object domainObject, CacheKey cacheKey, AbstractRecord databaseRow, ObjectBuildingQuery query, JoinedAttributeManager joinManager, FetchGroup executionFetchGroup, boolean forRefresh, AbstractSession targetSession) throws DatabaseException
Each mapping is recursed to assign values from the Record to the attributes in the domain object.- Throws:
DatabaseException
-
buildAttributesIntoObjectSOP
protected boolean buildAttributesIntoObjectSOP(Object domainObject, CacheKey cacheKey, AbstractRecord databaseRow, ObjectBuildingQuery query, JoinedAttributeManager joinManager, FetchGroup executionFetchGroup, boolean forRefresh, AbstractSession targetSession) throws DatabaseException
Each mapping is recursed to assign values from the Record to the attributes in the domain object. Should not be called unless (this.descriptor.hasSerializedObjectPolicy() && query.shouldUseSerializedObjectPolicy()) This method populates the object only in if some mappings potentially should be read using sopObject and other mappings - not using it. That happens when the row has been just read from the database and potentially has serialized object still in deserialized bits as a field value. Note that domainObject == sopObject is the same case, but (because domainObject has to be set into cache beforehand) extraction of sopObject from bit was done right before this method is called. Alternative situation is processing an empty row that has been created by foreign reference mapping and holds nothing but sopObject (which is an attribute of the original sopObject) - this case falls through to buildAttributesIntoObject. If attempt to deserialize sopObject from bits has failed, but SOP was setup to allow recovery (all mapped all fields/value mapped to the object were read, not just those excluded from SOP) then fall through to buildAttributesIntoObject. Nothing should be done if sopObject is not null, but domainObject != sopObject: the only way to get into this case should be with original query not maintaining cache, through a back reference to the original object, which is already being built (or has been built).- Returns:
- whether the object has been populated with attributes, if not then buildAttributesIntoObject should be called.
- Throws:
DatabaseException
-
postBuildAttributesIntoObjectEvent
protected void postBuildAttributesIntoObjectEvent(Object domainObject, AbstractRecord databaseRow, ObjectBuildingQuery query, boolean forRefresh)
-
buildBackupClone
public Object buildBackupClone(Object clone, UnitOfWorkImpl unitOfWork)
Returns the backup clone of the specified object. This is called only from unit of work. The clone sent as parameter is always a working copy from the unit of work.
-
buildDeleteExpression
public Expression buildDeleteExpression(DatabaseTable table, AbstractRecord row, boolean usesOptimisticLocking)
Build and return the expression to use as the where clause to delete an object. The row is passed to allow the version number to be extracted from it. If called with usesOptimisticLocking==true the caller should make sure that descriptor uses optimistic locking policy.
-
buildExpressionFromExample
public Expression buildExpressionFromExample(Object queryObject, QueryByExamplePolicy policy, Expression expressionBuilder, Map processedObjects, AbstractSession session)
INTERNAL: This method is used when Query By Example is used. Going through the mappings one by one, this method calls the specific buildExpression method corresponding to the type of mapping. It then generates a complete Expression by joining the individual Expressions.
-
buildNewInstance
public Object buildNewInstance()
Return a new instance of the receiver's javaClass.- Specified by:
buildNewInstance
in classCoreObjectBuilder<AbstractRecord,AbstractSession,DatabaseField,DatabaseMapping>
-
buildObject
public Object buildObject(ObjectLevelReadQuery query, AbstractRecord databaseRow)
Return an instance of the receivers javaClass. Set the attributes of an instance from the values stored in the database row.
-
buildObject
public Object buildObject(ObjectBuildingQuery query, AbstractRecord databaseRow, JoinedAttributeManager joinManager)
Return an instance of the receivers javaClass. Set the attributes of an instance from the values stored in the database row.
-
buildObject
public Object buildObject(ObjectBuildingQuery query, AbstractRecord databaseRow, JoinedAttributeManager joinManager, AbstractSession session, ClassDescriptor concreteDescriptor, InheritancePolicy inheritancePolicy, boolean isUnitOfWork, boolean shouldCacheQueryResults, boolean shouldUseWrapperPolicy)
Return an instance of the receivers javaClass. Set the attributes of an instance from the values stored in the database row. This is wrapper method with semaphore logic.
-
instantiateEagerMappings
public void instantiateEagerMappings(Object object, AbstractSession session)
Force instantiation to any eager mappings.
-
load
public void load(Object object, AttributeGroup group, AbstractSession session, boolean fromFetchGroup)
Force instantiation to any mappings in the load group.
-
loadAll
public void loadAll(Object object, AbstractSession session)
Force instantiation of all indirections.
-
loadAll
public void loadAll(Object object, AbstractSession session, IdentityHashSet loaded)
-
buildObjectInUnitOfWork
protected Object buildObjectInUnitOfWork(ObjectBuildingQuery query, JoinedAttributeManager joinManager, AbstractRecord databaseRow, UnitOfWorkImpl unitOfWork, Object primaryKey, CacheKey preFetchedCacheKey, ClassDescriptor concreteDescriptor) throws DatabaseException, QueryException
For executing all reads on the UnitOfWork, the session when building objects from rows will now be the UnitOfWork. Useful if the rows were read via a dirty write connection and we want to avoid putting uncommitted data in the global cache.Decides whether to call either buildWorkingCopyCloneFromRow (bypassing shared cache) or buildWorkingCopyCloneNormally (placing the result in the shared cache).
- Throws:
DatabaseException
QueryException
-
buildWorkingCopyCloneNormally
protected Object buildWorkingCopyCloneNormally(ObjectBuildingQuery query, AbstractRecord databaseRow, UnitOfWorkImpl unitOfWork, Object primaryKey, CacheKey preFetchedCacheKey, ClassDescriptor concreteDescriptor, JoinedAttributeManager joinManager) throws DatabaseException, QueryException
buildWorkingCopyCloneFromRow is an alternative to this which is the normal behavior. A row is read from the database, an original is built/refreshed/returned from the shared cache, and the original is registered/conformed/reverted in the UnitOfWork.This default behavior is only safe when the query is executed on a read connection, otherwise uncommitted data might get loaded into the shared cache.
Represents the way TopLink has always worked.
- Throws:
DatabaseException
QueryException
-
buildObject
protected Object buildObject(boolean returnCacheKey, ObjectBuildingQuery query, AbstractRecord databaseRow, AbstractSession session, Object primaryKey, CacheKey preFetchedCacheKey, ClassDescriptor concreteDescriptor, JoinedAttributeManager joinManager) throws DatabaseException, QueryException
Return an instance of the receivers javaClass. Set the attributes of an instance from the values stored in the database row.- Throws:
DatabaseException
QueryException
-
buildProtectedObject
protected Object buildProtectedObject(boolean returnCacheKey, ObjectBuildingQuery query, AbstractRecord databaseRow, AbstractSession session, Object primaryKey, CacheKey preFetchedCacheKey, ClassDescriptor concreteDescriptor, JoinedAttributeManager joinManager) throws DatabaseException, QueryException
Return an instance of the receivers javaClass. Set the attributes of an instance from the values stored in the database row.- Throws:
DatabaseException
QueryException
-
buildObjectsInto
public Object buildObjectsInto(ReadAllQuery query, List databaseRows, Object domainObjects)
Return a container which contains the instances of the receivers javaClass. Set the fields of the instance to the values stored in the database rows.
-
buildObjectsFromResultSetInto
public Object buildObjectsFromResultSetInto(ReadAllQuery query, ResultSet resultSet, Vector fields, DatabaseField[] fieldsArray, Object domainObjects) throws SQLException
Version of buildObjectsInto method that takes call instead of rows. Return a container which contains the instances of the receivers javaClass. Set the fields of the instance to the values stored in the result set.- Throws:
SQLException
-
buildObjectsFromCursorInto
public Object buildObjectsFromCursorInto(ReadAllQuery query, List databaseRows, Object domainObjects)
Return a container which contains the instances of the receivers javaClass. Set the fields of the instance to the values stored in the database rows.
-
buildPrimaryKeyExpression
public Expression buildPrimaryKeyExpression(DatabaseTable table) throws DescriptorException
Build the primary key expression for the secondary table.- Throws:
DescriptorException
-
buildPrimaryKeyExpressionFromKeys
public Expression buildPrimaryKeyExpressionFromKeys(Object primaryKey, AbstractSession session)
Build the primary key expression from the specified primary key values.
-
buildPrimaryKeyExpressionFromObject
public Expression buildPrimaryKeyExpressionFromObject(Object domainObject, AbstractSession session)
Build the primary key expression from the specified domain object.
-
buildRow
public AbstractRecord buildRow(Object object, AbstractSession session, DatabaseMapping.WriteType writeType)
Build the row representation of an object.
-
buildRow
public AbstractRecord buildRow(AbstractRecord databaseRow, Object object, AbstractSession session, DatabaseMapping.WriteType writeType)
Build the row representation of an object.
-
buildRowForShallowInsert
public AbstractRecord buildRowForShallowInsert(Object object, AbstractSession session)
Build the row representation of the object for update. The row built does not contain entries for uninstantiated attributes.
-
buildRowForShallowInsert
public AbstractRecord buildRowForShallowInsert(AbstractRecord databaseRow, Object object, AbstractSession session)
Build the row representation of the object for update. The row built does not contain entries for uninstantiated attributes.
-
buildRowForUpdateAfterShallowInsert
public AbstractRecord buildRowForUpdateAfterShallowInsert(Object object, AbstractSession session, DatabaseTable table)
Build the row representation of the object that contains only the fields nullified by shallow insert.
-
buildRowForUpdateAfterShallowInsert
public AbstractRecord buildRowForUpdateAfterShallowInsert(AbstractRecord databaseRow, Object object, AbstractSession session, DatabaseTable table)
Build the row representation of the object that contains only the fields nullified by shallow insert.
-
buildRowForUpdateBeforeShallowDelete
public AbstractRecord buildRowForUpdateBeforeShallowDelete(Object object, AbstractSession session, DatabaseTable table)
Build the row representation of the object that contains only the fields nullified by shallow insert, with all values set to null.
-
buildRowForUpdateBeforeShallowDelete
public AbstractRecord buildRowForUpdateBeforeShallowDelete(AbstractRecord databaseRow, Object object, AbstractSession session, DatabaseTable table)
Build the row representation of the object that contains only the fields nullified by shallow insert, with all values set to null.
-
buildRowWithChangeSet
public AbstractRecord buildRowWithChangeSet(AbstractRecord databaseRow, ObjectChangeSet objectChangeSet, AbstractSession session, DatabaseMapping.WriteType writeType)
Build the row representation of an object. This is only used for aggregates.
-
buildRowForTranslation
public AbstractRecord buildRowForTranslation(Object object, AbstractSession session)
Build the row representation of an object. The row built is used only for translations for the expressions in the expression framework.
-
buildRowForUpdate
public AbstractRecord buildRowForUpdate(WriteObjectQuery query)
Build the row representation of the object for update. The row built does not contain entries for unchanged attributes.
-
buildRowForUpdate
public AbstractRecord buildRowForUpdate(AbstractRecord databaseRow, WriteObjectQuery query)
Build into the row representation of the object for update. The row does not contain entries for unchanged attributes.
-
buildRowForUpdateWithChangeSet
public AbstractRecord buildRowForUpdateWithChangeSet(WriteObjectQuery query)
Build the row representation of the object for update. The row built does not contain entries for uninstantiated attributes.
-
buildRowForWhereClause
public AbstractRecord buildRowForWhereClause(ObjectLevelModifyQuery query)
Build the row representation of an object.
-
writeIntoRowFromPrimaryKeyValues
public AbstractRecord writeIntoRowFromPrimaryKeyValues(AbstractRecord row, Object primaryKey, AbstractSession session, boolean convert)
Build the row from the primary key values.
-
buildRowFromPrimaryKeyValues
public AbstractRecord buildRowFromPrimaryKeyValues(Object key, AbstractSession session)
Build the row from the primary key values.
-
buildTemplateInsertRow
public AbstractRecord buildTemplateInsertRow(AbstractSession session)
Build the row of all of the fields used for insertion.
-
buildTemplateInsertRow
public void buildTemplateInsertRow(AbstractSession session, AbstractRecord databaseRow)
-
trimFieldsForInsert
public void trimFieldsForInsert(AbstractSession session, AbstractRecord databaseRow)
INTERNAL Remove a potential sequence number field and invoke the ReturningPolicy trimModifyRowsForInsert method
-
buildTemplateUpdateRow
public AbstractRecord buildTemplateUpdateRow(AbstractSession session)
Build the row representation of the object for update. The row built does not contain entries for uninstantiated attributes.
-
buildUpdateExpression
public Expression buildUpdateExpression(DatabaseTable table, AbstractRecord transactionRow, AbstractRecord modifyRow)
Build and return the expression to use as the where clause to an update object. The row is passed to allow the version number to be extracted from it.
-
buildPrimaryKeyAttributesIntoObject
public void buildPrimaryKeyAttributesIntoObject(Object original, AbstractRecord databaseRow, ObjectBuildingQuery query, AbstractSession session) throws DatabaseException, QueryException
INTERNAL: Build just the primary key mappings into the object.- Throws:
DatabaseException
QueryException
-
buildAttributesIntoShallowObject
public void buildAttributesIntoShallowObject(Object original, AbstractRecord databaseRow, ObjectBuildingQuery query) throws DatabaseException, QueryException
INTERNAL: For reading through the write connection when in transaction, We need a partially populated original, so that we can build a clone using the copy policy, even though we can't put this original in the shared cache yet; just build a shallow original (i.e. just enough to copy over the primary key and some direct attributes) and keep it on the UOW.- Throws:
DatabaseException
QueryException
-
buildAttributesIntoWorkingCopyClone
public void buildAttributesIntoWorkingCopyClone(Object clone, CacheKey sharedCacheKey, ObjectBuildingQuery query, JoinedAttributeManager joinManager, AbstractRecord databaseRow, UnitOfWorkImpl unitOfWork, boolean forRefresh) throws DatabaseException, QueryException
INTERNAL: For reading through the write connection when in transaction, populate the clone directly from the database row.- Throws:
DatabaseException
QueryException
-
buildAttributesIntoWorkingCopyCloneSOP
protected boolean buildAttributesIntoWorkingCopyCloneSOP(Object clone, CacheKey sharedCacheKey, ObjectBuildingQuery query, JoinedAttributeManager joinManager, AbstractRecord databaseRow, UnitOfWorkImpl unitOfWork, boolean forRefresh) throws DatabaseException
For reading through the write connection when in transaction, populate the clone directly from the database row. Should not be called unless (this.descriptor.hasSerializedObjectPolicy() && query.shouldUseSerializedObjectPolicy()) This method populates the object only in if some mappings potentially should be read using sopObject and other mappings - not using it. That happens when the row has been just read from the database and potentially has serialized object still in deserialized bits as a field value. Note that clone == sopObject is the same case, but (because clone has to be set into cache beforehand) extraction of sopObject from bit was done right before this method is called. If attempt to deserialize sopObject from bits has failed, but SOP was setup to allow recovery (all mapped all fields/value mapped to the object were read, not just those excluded from SOP) then fall through to buildAttributesIntoWorkingCopyClone. Nothing should be done if sopObject is not null, but clone != sopObject: the only way to get into this case should be with original query not maintaining cache, through a back reference to the original object, which is already being built (or has been built).- Returns:
- whether the object has been populated with attributes, if not then buildAttributesIntoWorkingCopyClone should be called.
- Throws:
DatabaseException
-
postBuildAttributesIntoWorkingCopyCloneEvent
protected void postBuildAttributesIntoWorkingCopyCloneEvent(Object clone, AbstractRecord databaseRow, ObjectBuildingQuery query, UnitOfWorkImpl unitOfWork, boolean forRefresh)
-
buildWorkingCopyCloneFromRow
protected Object buildWorkingCopyCloneFromRow(ObjectBuildingQuery query, JoinedAttributeManager joinManager, AbstractRecord databaseRow, UnitOfWorkImpl unitOfWork, Object primaryKey, CacheKey preFetchedCacheKey) throws DatabaseException, QueryException
INTERNAL: Builds a working copy clone directly from the database row. This is the key method that allows us to execute queries against a UnitOfWork while in transaction and not cache the results in the shared cache. This is because we might violate transaction isolation by putting uncommitted versions of objects in the shared cache.- Throws:
DatabaseException
QueryException
-
buildObjectFromResultSet
public Object buildObjectFromResultSet(ObjectBuildingQuery query, JoinedAttributeManager joinManager, ResultSet resultSet, AbstractSession executionSession, DatabaseAccessor accessor, ResultSetMetaData metaData, DatabasePlatform platform, Vector fieldsList, DatabaseField[] fieldsArray) throws SQLException
INTERNAL: Builds a working copy clone directly from a result set. PERF: This method is optimized for a specific case of building objects so can avoid many of the normal checks, only queries that have this criteria can use this method of building objects. This is wrapper method with semaphore logic.- Throws:
SQLException
-
cascadePerformRemove
public void cascadePerformRemove(Object object, UnitOfWorkImpl uow, Map visitedObjects)
INTERNAL: This method is used by the UnitOfWork to cascade registration of new objects. It may raise exceptions as described in the EJB3 specification
-
cascadePerformRemovePrivateOwnedObjectFromChangeSet
public void cascadePerformRemovePrivateOwnedObjectFromChangeSet(Object object, UnitOfWorkImpl uow, Map visitedObjects)
INTERNAL: This method is used to iterate over the specified object's mappings and cascade remove orphaned private owned objects from the UnitOfWorkChangeSet and IdentityMap.
-
cacheForeignKeyValues
public void cacheForeignKeyValues(AbstractRecord databaseRecord, CacheKey cacheKey, AbstractSession session)
INTERNAL: This method is used to store the FK values used for this mapping in the cachekey. This is used when the mapping is protected but we have retrieved the fk values and will cache them for use when the entity is cloned.
-
cacheForeignKeyValues
public void cacheForeignKeyValues(Object source, CacheKey cacheKey, ClassDescriptor descriptor, AbstractSession session)
INTERNAL: This method is used to store the FK values used for this mapping in the cachekey. This is used when the mapping is protected but we have retrieved the fk values and will cache them for use when the entity is cloned.
-
cascadeDiscoverAndPersistUnregisteredNewObjects
public void cascadeDiscoverAndPersistUnregisteredNewObjects(Object object, Map newObjects, Map unregisteredExistingObjects, Map visitedObjects, UnitOfWorkImpl uow, Set cascadeErrors)
INTERNAL: Cascade discover and persist new objects during commit. It may raise exceptions as described in the EJB3 specification
-
cascadeRegisterNewForCreate
public void cascadeRegisterNewForCreate(Object object, UnitOfWorkImpl uow, Map visitedObjects)
INTERNAL: This method is used by the UnitOfWork to cascade registration of new objects. It may raise exceptions as described in the EJB3 specification
-
compareForChange
public ObjectChangeSet compareForChange(Object clone, Object backUp, UnitOfWorkChangeSet changeSet, AbstractSession session)
INTERNAL: This method creates a records change set for a particular object. It should only be used by aggregates.- Returns:
- ObjectChangeSet
-
compareObjects
public boolean compareObjects(Object firstObject, Object secondObject, AbstractSession session)
Compares the two specified objects
-
copyInto
public void copyInto(Object source, Object target, boolean cloneOneToOneValueHolders)
Copy each attribute from one object into the other.
-
copyInto
public void copyInto(Object source, Object target)
Copy each attribute from one object into the other.
-
copyObject
public Object copyObject(Object original, CopyGroup copyGroup)
Return a copy of the object. This is NOT used for unit of work but for templatizing an object. The depth and primary key reseting are passed in.
-
createObjectChangeSet
public ObjectChangeSet createObjectChangeSet(Object clone, UnitOfWorkChangeSet uowChangeSet, AbstractSession session)
INTERNAL: Used by the ObjectBuilder to create an ObjectChangeSet for the specified clone object.- Parameters:
clone
- the object to convert to a changeSet.uowChangeSet
- the owner of this changeSet.- Returns:
- ObjectChangeSet the newly created changeSet representing the clone object
-
createObjectChangeSet
public ObjectChangeSet createObjectChangeSet(Object clone, UnitOfWorkChangeSet uowChangeSet, boolean isNew, AbstractSession session)
INTERNAL: Used by the ObjectBuilder to create an ObjectChangeSet for the specified clone object.- Parameters:
clone
- the object to convert to a changeSet.uowChangeSet
- the owner of this changeSet.isNew
- signifies if the clone object is a new object.- Returns:
- ObjectChangeSet the newly created changeSet representing the clone object
-
createObjectChangeSet
public ObjectChangeSet createObjectChangeSet(Object clone, UnitOfWorkChangeSet uowChangeSet, boolean isNew, boolean assignPrimaryKeyIfExisting, AbstractSession session)
INTERNAL: Used by the ObjectBuilder to create an ObjectChangeSet for the specified clone object.- Parameters:
clone
- the object to convert to a changeSet.uowChangeSet
- the owner of this changeSet.isNew
- signifies if the clone object is a new object.assignPrimaryKeyIfExisting
- signifies if the primary key of the change set should be updated if existing.- Returns:
- ObjectChangeSet the newly created changeSet representing the clone object
-
createPrimaryKeyExpression
public void createPrimaryKeyExpression(AbstractSession session)
Creates and stores primary key expression.
-
extractPrimaryKeyFromExpression
public Object extractPrimaryKeyFromExpression(boolean requiresExactMatch, Expression expression, AbstractRecord translationRow, AbstractSession session)
Return the row with primary keys and their values from the given expression.
-
isPrimaryKeyExpression
public boolean isPrimaryKeyExpression(boolean requiresExactMatch, Expression expression, AbstractSession session)
Return if the expression is by primary key.
-
extractPrimaryKeyFromObject
public Object extractPrimaryKeyFromObject(Object domainObject, AbstractSession session)
Extract primary key attribute values from the domainObject.- Specified by:
extractPrimaryKeyFromObject
in classCoreObjectBuilder<AbstractRecord,AbstractSession,DatabaseField,DatabaseMapping>
-
extractPrimaryKeyFromObject
public Object extractPrimaryKeyFromObject(Object domainObject, AbstractSession session, boolean shouldReturnNullIfNull)
Extract primary key attribute values from the domainObject.
-
extractPrimaryKeyFromRow
public Object extractPrimaryKeyFromRow(AbstractRecord databaseRow, AbstractSession session)
Extract primary key values from the specified row. null is returned if the row does not contain the key.
-
extractPrimaryKeyRowFromExpression
public AbstractRecord extractPrimaryKeyRowFromExpression(Expression expression, AbstractRecord translationRow, AbstractSession session)
Return the row with primary keys and their values from the given expression.
-
extractRowFromExpression
public AbstractRecord extractRowFromExpression(Expression expression, AbstractRecord translationRow, AbstractSession session)
Return the row from the given expression.
-
extractPrimaryKeyRowFromObject
public AbstractRecord extractPrimaryKeyRowFromObject(Object domainObject, AbstractSession session)
Extract primary key attribute values from the domainObject.
-
extractValueFromObjectForField
public Object extractValueFromObjectForField(Object domainObject, DatabaseField field, AbstractSession session) throws DescriptorException
Extract the value of the primary key attribute from the specified object.- Throws:
DescriptorException
-
fixObjectReferences
public void fixObjectReferences(Object object, Map objectDescriptors, Map processedObjects, ObjectLevelReadQuery query, DistributedSession session)
INTERNAL: An object has been serialized from the server to the client. Replace the transient attributes of the remote value holders with client-side objects.
-
getBaseChangeRecordForField
public ChangeRecord getBaseChangeRecordForField(ObjectChangeSet objectChangeSet, Object object, DatabaseField databaseField, AbstractSession session)
Return the base ChangeRecord for the given DatabaseField. The object and all its relevant aggregates must exist. The returned ChangeRecord is either DirectToFieldChangeRecord or TransformationMappingChangeRecord, or null.
-
getBaseMappingForField
public DatabaseMapping getBaseMappingForField(DatabaseField databaseField)
Return the base mapping for the given DatabaseField.
-
getBaseValueForField
public Object getBaseValueForField(DatabaseField databaseField, Object domainObject)
Return the base value that is mapped to for given field.
-
getDescriptor
public ClassDescriptor getDescriptor()
Return the descriptor
-
getFieldClassification
public Class getFieldClassification(DatabaseField fieldToClassify) throws DescriptorException
INTERNAL: Return the classification for the field contained in the mapping. This is used to convert the row value to a consistent java value.- Throws:
DescriptorException
-
getFieldForQueryKeyName
public DatabaseField getFieldForQueryKeyName(String name)
Return the field used for the query key name.
-
getFieldsMap
public Map<DatabaseField,DatabaseField> getFieldsMap()
Return the fields map. Used to maintain identity on the field objects. Ensure they get the correct index/type.
-
setFieldsMap
protected void setFieldsMap(Map fieldsMap)
Return the fields map. Used to maintain identity on the field objects. Ensure they get the correct index/type.
-
getCloningMappings
public List<DatabaseMapping> getCloningMappings()
PERF: Return all mappings that require cloning. This allows for simple directs to be avoided when using clone copying.
-
isSimple
public boolean isSimple()
PERF: Return if the descriptor has no complex mappings, all direct.
-
getRelationshipMappings
public List<DatabaseMapping> getRelationshipMappings()
PERF: Return all relationship mappings.
-
getEagerMappings
public List<DatabaseMapping> getEagerMappings()
PERF: Return all mappings that are eager loaded (but use indirection). This allows for eager mappings to still benefit from indirection for locking and change tracking.
-
getJoinedAttributes
public List<DatabaseMapping> getJoinedAttributes()
Answers the attributes which are always joined to the original query on reads.
-
getBatchFetchedAttributes
public List<DatabaseMapping> getBatchFetchedAttributes()
Return the mappings that are always batch fetched.
-
getSequenceMapping
public AbstractDirectMapping getSequenceMapping()
PERF: Return the sequence mapping.
-
setSequenceMapping
public void setSequenceMapping(AbstractDirectMapping sequenceMapping)
PERF: Set the sequence mapping.
-
hasJoinedAttributes
public boolean hasJoinedAttributes()
Answers if any attributes are to be joined / returned in the same select statement.
-
hasBatchFetchedAttributes
public boolean hasBatchFetchedAttributes()
Return is any mappings are always batch fetched.
-
hasInBatchFetchedAttribute
public boolean hasInBatchFetchedAttribute()
Return is any mappings are always batch fetched using IN.
-
setHasInBatchFetchedAttribute
public void setHasInBatchFetchedAttribute(boolean hasInBatchFetchedAttribute)
Set if any mappings are always batch fetched using IN.
-
getMappingForAttributeName
public DatabaseMapping getMappingForAttributeName(String name)
Return the mapping for the specified attribute name.
-
getMappingForField
public DatabaseMapping getMappingForField(DatabaseField field)
Return al the mapping for the specified field.- Specified by:
getMappingForField
in classCoreObjectBuilder<AbstractRecord,AbstractSession,DatabaseField,DatabaseMapping>
-
getReadOnlyMappingsForField
public List<DatabaseMapping> getReadOnlyMappingsForField(DatabaseField field)
Return all the read-only mapping for the specified field.
-
getMappingsByAttribute
protected Map<String,DatabaseMapping> getMappingsByAttribute()
Return all the mapping to attribute associations
-
getMappingsByField
public Map<DatabaseField,DatabaseMapping> getMappingsByField()
INTERNAL: Return all the mapping to field associations
-
getReadOnlyMappingsByField
public Map<DatabaseField,List<DatabaseMapping>> getReadOnlyMappingsByField()
INTERNAL: Return all the read-only mapping to field associations
-
getNonPrimaryKeyMappings
protected List<DatabaseMapping> getNonPrimaryKeyMappings()
Return the non primary key mappings.
-
getParentObjectForField
public Object getParentObjectForField(DatabaseField databaseField, Object domainObject)
Return the base value that is mapped to for given field.
-
getPrimaryKeyClassifications
public List<Class> getPrimaryKeyClassifications()
Return primary key classifications. These are used to ensure a consistent type for the pk values.
-
getPrimaryKeyExpression
public Expression getPrimaryKeyExpression()
Return the primary key expression
-
getPrimaryKeyMappings
public List<DatabaseMapping> getPrimaryKeyMappings()
Return primary key mappings.
-
getTargetFieldForQueryKeyName
public DatabaseField getTargetFieldForQueryKeyName(String queryKeyName)
INTERNAL: return a database field based on a query key name
-
initialize
public void initialize(AbstractSession session) throws DescriptorException
Cache all the mappings by their attribute and fields.- Throws:
DescriptorException
-
isPrimaryKeyComponentInvalid
public boolean isPrimaryKeyComponentInvalid(Object keyValue, int index)
-
recordPrivateOwnedRemovals
public void recordPrivateOwnedRemovals(Object object, UnitOfWorkImpl uow, boolean initialPass)
-
postInitialize
public void postInitialize(AbstractSession session) throws DescriptorException
INTERNAL: Post initializations after mappings are initialized.- Throws:
DescriptorException
-
initializeJoinedAttributes
public void initializeJoinedAttributes()
INTERNAL: Iterates through all one to one mappings and checks if any of them use joining.By caching the result query execution in the case where there are no joined attributes can be improved.
-
initializeBatchFetchedAttributes
public void initializeBatchFetchedAttributes()
INTERNAL: Iterates through all one to one mappings and checks if any of them use batch fetching.By caching the result query execution in the case where there are no batch fetched attributes can be improved.
-
copyQueryInfoToCacheKey
protected void copyQueryInfoToCacheKey(CacheKey cacheKey, ObjectBuildingQuery query, AbstractRecord databaseRow, AbstractSession session, ClassDescriptor concreteDescriptor)
Initialize a cache key. Called by buildObject and now also by buildWorkingCopyCloneFromRow.
-
initializePrimaryKey
public void initializePrimaryKey(AbstractSession session) throws DescriptorException
Cache primary key and non primary key mappings.- Throws:
DescriptorException
-
instantiateClone
public Object instantiateClone(Object domainObject, AbstractSession session)
Returns the clone of the specified object. This is called only from unit of work. This only instantiates the clone instance, it does not clone the attributes, this allows the stub of the clone to be registered before cloning its parts.
-
instantiateWorkingCopyClone
public Object instantiateWorkingCopyClone(Object domainObject, AbstractSession session)
Returns the clone of the specified object. This is called only from unit of work. The domainObject sent as parameter is always a copy from the parent of unit of work. bug 2612602 make a call to build a working clone. This will in turn call the copy policy to make a working clone. This allows for lighter and heavier clones to be created based on their use. this allows the stub of the clone to be registered before cloning its parts.
-
instantiateWorkingCopyCloneFromRow
public Object instantiateWorkingCopyCloneFromRow(AbstractRecord row, ObjectBuildingQuery query, Object primaryKey, UnitOfWorkImpl unitOfWork)
It is now possible to build working copy clones directly from rows.An intermediary original is no longer needed.
This has ramifications to the copy policy and cmp, for clones are no longer built via cloning.
Instead the copy policy must in some cases not copy at all. this allows the stub of the clone to be registered before cloning its parts.
-
isPrimaryKeyMapping
public boolean isPrimaryKeyMapping(DatabaseMapping mapping)
-
iterate
public void iterate(DescriptorIterator iterator)
INTERNAL: Perform the iteration operation on the objects attributes through the mappings.
-
mergeChangesIntoObject
public void mergeChangesIntoObject(Object target, ObjectChangeSet changeSet, Object source, MergeManager mergeManager, AbstractSession targetSession)
INTERNAL: Merge changes between the objects, this merge algorithm is dependent on the merge manager.
-
mergeChangesIntoObject
public void mergeChangesIntoObject(Object target, ObjectChangeSet changeSet, Object source, MergeManager mergeManager, AbstractSession targetSession, boolean isTargetCloneOfOriginal, boolean shouldMergeFetchGroup)
INTERNAL: Merge changes between the objects, this merge algorithm is dependent on the merge manager.
-
mergeIntoObject
public void mergeIntoObject(Object target, boolean isUnInitialized, Object source, MergeManager mergeManager, AbstractSession targetSession)
INTERNAL: Merge the contents of one object into another, this merge algorithm is dependent on the merge manager. This merge also prevents the extra step of calculating the changes when it is not required.
-
mergeIntoObject
public void mergeIntoObject(Object target, ObjectChangeSet changeSet, boolean isUnInitialized, Object source, MergeManager mergeManager, AbstractSession targetSession, boolean cascadeOnly, boolean isTargetCloneOfOriginal, boolean shouldMergeFetchGroup)
INTERNAL: Merge the contents of one object into another, this merge algorithm is dependent on the merge manager. This merge also prevents the extra step of calculating the changes when it is not required. If 'cascadeOnly' is true, only foreign reference mappings are merged. If 'isTargetCloneOfOriginal' then the target was create through a shallow clone of the source, so merge basics is not required.
-
populateAttributesForClone
public void populateAttributesForClone(Object original, CacheKey cacheKey, Object clone, Integer refreshCascade, AbstractSession cloningSession)
Clones the attributes of the specified object. This is called only from unit of work. The domainObject sent as parameter is always a copy from the parent of unit of work.
-
loadBatchReadAttributes
protected void loadBatchReadAttributes(ClassDescriptor concreteDescriptor, Object sourceObject, CacheKey cacheKey, AbstractRecord databaseRow, ObjectBuildingQuery query, JoinedAttributeManager joinManager, boolean isTargetProtected)
-
loadJoinedAttributes
protected void loadJoinedAttributes(ClassDescriptor concreteDescriptor, Object sourceObject, CacheKey cacheKey, AbstractRecord databaseRow, JoinedAttributeManager joinManager, ObjectBuildingQuery query, boolean isTargetProtected)
-
refreshObjectIfRequired
protected boolean refreshObjectIfRequired(ClassDescriptor concreteDescriptor, CacheKey cacheKey, Object domainObject, ObjectBuildingQuery query, JoinedAttributeManager joinManager, AbstractRecord databaseRow, AbstractSession session, boolean targetIsProtected)
This method is called when a cached Entity needs to be refreshed
-
rehashFieldDependancies
public void rehashFieldDependancies(AbstractSession session)
Rehash any maps based on fields. This is used to clone descriptors for aggregates, which hammer field names, it is probably better not to hammer the field name and this should be refactored.
-
setDescriptor
public void setDescriptor(ClassDescriptor aDescriptor)
Set the descriptor.
-
setMappingsByAttribute
protected void setMappingsByAttribute(Map<String,DatabaseMapping> theAttributeMappings)
All the mappings and their respective attribute associations are cached for performance improvement.
-
setMappingsByField
public void setMappingsByField(Map<DatabaseField,DatabaseMapping> theFieldMappings)
INTERNAL: All the mappings and their respective field associations are cached for performance improvement.
-
setReadOnlyMappingsByField
public void setReadOnlyMappingsByField(Map<DatabaseField,List<DatabaseMapping>> theReadOnlyFieldMappings)
INTERNAL: All the read-only mappings and their respective field associations are cached for performance improvement.
-
setNonPrimaryKeyMappings
protected void setNonPrimaryKeyMappings(List<DatabaseMapping> theNonPrimaryKeyMappings)
The non primary key mappings are cached to improve performance.
-
setPrimaryKeyClassifications
public void setPrimaryKeyClassifications(List<Class> primaryKeyClassifications)
INTERNAL: Set primary key classifications. These are used to ensure a consistent type for the pk values.
-
setPrimaryKeyExpression
public void setPrimaryKeyExpression(Expression criteria)
The primary key expression is cached to improve performance.
-
setPrimaryKeyMappings
protected void setPrimaryKeyMappings(List<DatabaseMapping> thePrimaryKeyMappings)
The primary key mappings are cached to improve performance.
-
unwrapObject
public Object unwrapObject(Object proxy, AbstractSession session)
Unwrap the object if required. This is used for the wrapper policy support and EJB.
-
updateCachedAttributes
public void updateCachedAttributes(PersistenceEntity persistenceEntity, CacheKey cacheKey, Object primaryKey)
INTERNAL: Used to updated any attributes that may be cached on a woven entity
-
validate
public void validate(AbstractSession session) throws DescriptorException
Validates the object builder. This is done once the object builder initialized and descriptor fires this validation.- Throws:
DescriptorException
-
verifyDelete
public boolean verifyDelete(Object object, AbstractSession session)
Verify that an object has been deleted from the database. An object can span multiple tables. A query is performed on each of these tables using the primary key values of the object as the selection criteria. If the query returns a result then the object has not been deleted from the database. If no result is returned then each of the mappings is asked to verify that the object has been deleted. If all mappings answer true then the result is true.
-
hasWrapperPolicy
public boolean hasWrapperPolicy()
Return if the descriptor has a wrapper policy. Cache for performance.
-
setHasWrapperPolicy
public void setHasWrapperPolicy(boolean hasWrapperPolicy)
Set if the descriptor has a wrapper policy. Cached for performance.
-
wrapObject
public Object wrapObject(Object implementation, AbstractSession session)
Wrap the object if required. This is used for the wrapper policy support and EJB.
-
isXMLObjectBuilder
public boolean isXMLObjectBuilder()
-
getLockAttribute
public String getLockAttribute()
-
shouldKeepRow
public boolean shouldKeepRow()
-
hasCacheIndexesInSopObject
public boolean hasCacheIndexesInSopObject()
-
createRecordFromXMLContext
public AbstractRecord createRecordFromXMLContext(XMLContext context)
Description copied from class:CoreObjectBuilder
Create a new row/record from XMLContext.- Specified by:
createRecordFromXMLContext
in classCoreObjectBuilder<AbstractRecord,AbstractSession,DatabaseField,DatabaseMapping>
-
-