/** * Validates the object builder. This is done once the object builder initialized and descriptor * fires this validation. */ public void validate(AbstractSession session) throws DescriptorException { if (getDescriptor().usesSequenceNumbers()) { if (getMappingForField(getDescriptor().getSequenceNumberField()) == null) { throw DescriptorException.mappingForSequenceNumberField(getDescriptor()); } } }
/** * INTERNAL: * THis method is used by the UnitOfWork to cascade registration of new objects. * It may rais exceptions as described inthe EJB 3.x specification */ public void cascadePerformRemove(Object object, UnitOfWorkImpl uow, IdentityHashtable visitedObjects) { Iterator mappings = getDescriptor().getMappings().iterator(); while (mappings.hasNext()) { ((DatabaseMapping)mappings.next()).cascadePerformRemoveIfRequired(object, uow, visitedObjects); } }
/** * INTERNAL: * Perform the itteration opperation on the objects attributes through the mappings. */ public void iterate(DescriptorIterator iterator) { // PERF: Avoid synchronized enumerator as is concurrency bottleneck. Vector mappings = getDescriptor().getMappings(); int mappingsSize = mappings.size(); for (int index = 0; index < mappingsSize; index++) { ((DatabaseMapping)mappings.get(index)).iterate(iterator); } }
/** * INTERNAL: * THis method is used by the UnitOfWork to cascade registration of new objects. * It may rais exceptions as described inthe EJB 3.x specification */ public void cascadeRegisterNewForCreate(Object object, UnitOfWorkImpl uow, IdentityHashtable visitedObjects) { Iterator mappings = getDescriptor().getMappings().iterator(); while (mappings.hasNext()) { ((DatabaseMapping)mappings.next()).cascadeRegisterNewIfRequired(object, uow, visitedObjects); } }
/** * Build the row representation of the object for update. The row built does not * contain entries for non-relationship fields. */ public AbstractRecord buildRowForShallowDelete(AbstractRecord databaseRow, Object object, AbstractSession session) { // PERF: Avoid synchronized enumerator as is concurrency bottleneck. Vector mappings = getDescriptor().getMappings(); int mappingsSize = mappings.size(); for (int index = 0; index < mappingsSize; index++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(index); mapping.writeFromObjectIntoRowForShallowDelete(object, databaseRow, session); } return databaseRow; }
/** * 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. */ public Expression buildDeleteExpression(DatabaseTable table, AbstractRecord row) { if (getDescriptor().usesOptimisticLocking() && (getDescriptor().getTables().firstElement().equals(table))) { return getDescriptor().getOptimisticLockingPolicy().buildDeleteExpression(table, primaryKeyExpression, row); } else { return buildPrimaryKeyExpression(table); } }
public String toString() { return Helper.getShortClassName(getClass()) + "(" + getDescriptor().toString() + ")"; }
/** * INTERNAL: * This method creates an records changes for a particular object * @return ChangeRecord */ public ObjectChangeSet compareForChange(Object clone, Object backUp, UnitOfWorkChangeSet changeSet, AbstractSession session) { // delegate the change comparision to this objects ObjectChangePolicy - TGW return descriptor.getObjectChangePolicy().calculateChanges(clone, backUp, changeSet, session, getDescriptor(), true); }
/** * Return a new instance of the receiver's javaClass. */ public Object buildNewInstance() { return getDescriptor().getInstantiationPolicy().buildNewInstance(); }
/** * 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. */ public Expression buildUpdateExpression(DatabaseTable table, AbstractRecord transactionRow, AbstractRecord modifyRow) { // Only the first table must use the lock check. Expression primaryKeyExpression = buildPrimaryKeyExpression(table); if (getDescriptor().usesOptimisticLocking()) { return getDescriptor().getOptimisticLockingPolicy().buildUpdateExpression(table, primaryKeyExpression, transactionRow, modifyRow); } else { return primaryKeyExpression; } }
/** * Returns the clone of the specified object. This is called only from unit of work. * This only instatiates the clone instance, it does not clone the attributes, * this allows the stub of the clone to be registered before cloning its parts. */ public Object instantiateClone(Object domainObject, AbstractSession session) { return getDescriptor().getCopyPolicy().buildClone(domainObject, 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. */ public Object instantiateWorkingCopyClone(Object domainObject, AbstractSession session) { return getDescriptor().getCopyPolicy().buildWorkingCopyClone(domainObject, session); }
/** * Build the row representation of an object. */ public AbstractRecord buildRowForWhereClause(ObjectLevelModifyQuery query) { AbstractRecord databaseRow = createRecord(); for (Iterator mappings = getDescriptor().getMappings().iterator(); mappings.hasNext();) { DatabaseMapping mapping = (DatabaseMapping)mappings.next(); mapping.writeFromObjectIntoRowForWhereClause(query, databaseRow); } // If this descriptor has multiple tables then we need to append the primary keys for // the non default tables. if (!getDescriptor().isAggregateDescriptor()) { addPrimaryKeyForNonDefaultTable(databaseRow); } return databaseRow; }
/** * Build the row representation of an object. */ public AbstractRecord buildRowWithChangeSet(AbstractRecord databaseRow, ObjectChangeSet objectChangeSet, AbstractSession session) { for (Enumeration changeRecords = objectChangeSet.getChanges().elements(); changeRecords.hasMoreElements();) { ChangeRecord changeRecord = (ChangeRecord)changeRecords.nextElement(); DatabaseMapping mapping = changeRecord.getMapping(); mapping.writeFromObjectIntoRowWithChangeRecord(changeRecord, databaseRow, session); } // If this descriptor is involved in inheritence add the class type. if (getDescriptor().hasInheritance()) { getDescriptor().getInheritancePolicy().addClassIndicatorFieldToRow(databaseRow); } return databaseRow; }
/** * Build the row representation of the object for update. The row built does not * contain entries for uninstantiated attributes. */ public AbstractRecord buildTemplateUpdateRow(AbstractSession session) { AbstractRecord databaseRow = createRecord(); for (Iterator mappings = getNonPrimaryKeyMappings().iterator(); mappings.hasNext();) { DatabaseMapping mapping = (DatabaseMapping)mappings.next(); mapping.writeUpdateFieldsIntoRow(databaseRow, session); } if (getDescriptor().usesOptimisticLocking()) { getDescriptor().getOptimisticLockingPolicy().addLockFieldsToUpdateRow(databaseRow, session); } return databaseRow; }
/** * Returns the clone of the specified object. This is called only from unit of work. * The clonedDomainObject sent as parameter is always a working copy from the unit of work. */ public Object buildBackupClone(Object clone, UnitOfWorkImpl unitOfWork) { // The copy policy builds clone Object backup = getDescriptor().getCopyPolicy().buildClone(clone, unitOfWork); // PERF: Avoid synchronized enumerator as is concurrency bottleneck. List mappings = getCloningMappings(); for (int index = 0; index < mappings.size(); index++) { ((DatabaseMapping)mappings.get(index)).buildBackupClone(clone, backup, unitOfWork); } return backup; }
/** * Build the row from the primary key values. */ public AbstractRecord buildRowFromPrimaryKeyValues(Vector key, AbstractSession session) { AbstractRecord databaseRow = createRecord(key.size()); int keySize = key.size(); for (int index = 0; index < keySize; index++) { DatabaseField field = (DatabaseField)getDescriptor().getPrimaryKeyFields().get(index); Object value = key.elementAt(index); value = session.getPlatform(getDescriptor().getJavaClass()).getConversionManager().convertObject(value, field.getType()); databaseRow.put(field, value); } return databaseRow; }
/** * Extract the value of the primary key attribute from the specified object. */ public Object extractValueFromObjectForField(Object domainObject, DatabaseField field, AbstractSession session) throws DescriptorException { // Allow for inheritance, the concrete descriptor must always be used. ClassDescriptor descriptor = null;//this variable will be assigned in the final if (getDescriptor().hasInheritance() && (domainObject.getClass() != getDescriptor().getJavaClass()) && ((descriptor = session.getDescriptor(domainObject)).getJavaClass() != getDescriptor().getJavaClass())) { return descriptor.getObjectBuilder().extractValueFromObjectForField(domainObject, field, session); } else { DatabaseMapping mapping = getMappingForField(field); if (mapping == null) { throw DescriptorException.missingMappingForField(field, getDescriptor()); } return mapping.valueFromObject(domainObject, field, session); } }
/** * It is now possible to build working copy clones directly from rows. * <p>An intermediary original is no longer needed. * <p>This has ramifications to the copy policy and cmp, for clones are * no longer built via cloning. * <p>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. */ public Object instantiateWorkingCopyCloneFromRow(AbstractRecord row, ObjectBuildingQuery query) { if (query.isObjectLevelReadQuery()){ //for backward compat reasons cast this return getDescriptor().getCopyPolicy().buildWorkingCopyCloneFromRow(row, ((ObjectLevelReadQuery)query)); }else{ return getDescriptor().getCopyPolicy().buildWorkingCopyCloneFromRow(row, query); } }
/** * INTERNAL: return a database field based on a query key name */ public DatabaseField getTargetFieldForQueryKeyName(String queryKeyName) { DatabaseMapping mapping = (DatabaseMapping)getMappingForAttributeName(queryKeyName); if ((mapping != null) && mapping.isDirectToFieldMapping()) { return ((AbstractDirectMapping)mapping).getField(); } //mapping is either null or not direct to field. //check query keys QueryKey queryKey = getDescriptor().getQueryKeyNamed(queryKeyName); if ((queryKey != null) && queryKey.isDirectQueryKey()) { return ((DirectQueryKey)queryKey).getField(); } //nothing found return null; }