/** * INTERNAL: * Return if the two object match completely. * This checks the objects attributes and their private parts. */ public boolean compareObjects(Object firstObject, Object secondObject) { if ((firstObject == null) && (secondObject == null)) { return true; } if ((firstObject == null) || (secondObject == null)) { return false; } if (!(firstObject.getClass().equals(secondObject.getClass()))) { return false; } ObjectBuilder builder = getDescriptor(firstObject.getClass()).getObjectBuilder(); return builder.compareObjects(builder.unwrapObject(firstObject, this), builder.unwrapObject(secondObject, this), this); }
/** * INTERNAL: * Unwrap the object if required. * This is used for the wrapper policy support and EJB. */ public Object unwrapObject(Object proxy) { return getDescriptor(proxy).getObjectBuilder().unwrapObject(proxy, this); }
/** * ADVANCED: * Set optmistic read lock on the object. This feature is overide by normal optimistic lock. * when the object is changed in UnitOfWork. The cloneFromUOW must be the clone of from this * UnitOfWork and it must implements version locking or timestamp locking. * The SQL would look like the followings. * * If shouldModifyVersionField is true, * "UPDATE EMPLOYEE SET VERSION = 2 WHERE EMP_ID = 9 AND VERSION = 1" * * If shouldModifyVersionField is false, * "UPDATE EMPLOYEE SET VERSION = 1 WHERE EMP_ID = 9 AND VERSION = 1" */ public void forceUpdateToVersionField(Object lockObject, boolean shouldModifyVersionField) { ClassDescriptor descriptor = getDescriptor(lockObject); if (descriptor == null) { throw DescriptorException.missingDescriptor(lockObject.getClass().toString()); } getOptimisticReadLockObjects().put(descriptor.getObjectBuilder().unwrapObject(lockObject, this), new Boolean(shouldModifyVersionField)); }
/** * ADVANCED: * Extract and return the primary key from the object. */ public Vector keyFromObject(Object domainObject, ClassDescriptor descriptor) throws ValidationException { if (descriptor == null) { throw ValidationException.missingDescriptor(domainObject.getClass().getName()); } Object implemention = descriptor.getObjectBuilder().unwrapObject(domainObject, this); if (implemention == null) { return null; } return descriptor.getObjectBuilder().extractPrimaryKeyFromObject(implemention, this); }
/** * TESTING: * This is used by testing code to ensure that a deletion was successful. */ public boolean verifyDelete(Object domainObject) { ObjectBuilder builder = getDescriptor(domainObject).getObjectBuilder(); Object implementation = builder.unwrapObject(domainObject, this); return builder.verifyDelete(implementation, this); }
/** * INTERNAL: * Object reference must unwrap the reference object if required. */ public Object getRealAttributeValueFromObject(Object object, AbstractSession session) { Object value = super.getRealAttributeValueFromObject(object, session); value = getReferenceDescriptor().getObjectBuilder().unwrapObject(value, session); return value; }
/** * INTERNAL: * Extract the reference pk for rvh usage in remote model. */ public Vector extractPrimaryKeysFromRealReferenceObject(Object object, AbstractSession session) { if (object == null) { return new Vector(1); } else { Object implementation = getReferenceDescriptor().getObjectBuilder().unwrapObject(object, session); return getReferenceDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(implementation, session); } }
/** * INTERNAL: * Iterate on the attribute value. * The value holder has already been processed. */ public void iterateOnRealAttributeValue(DescriptorIterator iterator, Object realAttributeValue) { // This may be wrapped as the caller in iterate on foreign reference does not unwrap as the type is generic. Object unwrappedAttributeValue = getReferenceDescriptor().getObjectBuilder().unwrapObject(realAttributeValue, iterator.getSession()); iterator.iterateReferenceObjectForMapping(unwrappedAttributeValue, this); }
/** * INTERNAL: * Return the next object from the iterator. * This is used to stream over a collection independent of JDK 1.1 and 1.2. * The session may be required to unwrap for the wrapper policy. */ public Object next(Object iterator, AbstractSession session) { Object next = next(iterator); if (hasElementDescriptor()) { next = getElementDescriptor().getObjectBuilder().unwrapObject(next, session); } return next; }
/** * INTERNAL: * Either create a new change record or update the change record with the new value. * This is used by attribute change tracking. */ public void updateChangeRecord(Object clone, Object newValue, Object oldValue, ObjectChangeSet objectChangeSet, UnitOfWorkImpl uow) { // Must ensure values are unwrapped. Object unwrappedNewValue = newValue; Object unwrappedOldValue = oldValue; if (newValue != null) { unwrappedNewValue = getReferenceDescriptor().getObjectBuilder().unwrapObject(newValue, uow); } if (oldValue != null) { unwrappedOldValue = getReferenceDescriptor().getObjectBuilder().unwrapObject(oldValue, uow); } ObjectReferenceChangeRecord changeRecord = (ObjectReferenceChangeRecord)objectChangeSet.getChangesForAttributeNamed(this.getAttributeName()); if (changeRecord == null) { changeRecord = internalBuildChangeRecord(unwrappedNewValue, objectChangeSet, uow); changeRecord.setOldValue(unwrappedOldValue); objectChangeSet.addChange(changeRecord); } else { setNewValueInChangeRecord(unwrappedNewValue, changeRecord, objectChangeSet, uow); } }
/** * INTERNAL: * Check if the object is contained in the collection. * This is used to check contains in a collection independent of JDK 1.1 and 1.2. * The session may be required to unwrap for the wrapper policy. */ public boolean contains(Object element, Object container, AbstractSession session) { if (hasElementDescriptor() && getElementDescriptor().hasWrapperPolicy()) { // The wrapper for the object must be removed. Object iterator = iteratorFor(container); while (hasNext(iterator)) { Object next = next(iterator); if (getElementDescriptor().getObjectBuilder().unwrapObject(next, session).equals(element)) { return true; } } return false; } else { return contains(element, container); } }
/** * INTERNAL: * Remove the object from the collection. * This is used to remove from a collection independent of JDK 1.1 and 1.2. * The session may be required to unwrap for the wrapper policy. */ public boolean removeFrom(Object key, Object element, Object container, AbstractSession session) { Object objectToRemove = element; if (hasElementDescriptor() && getElementDescriptor().hasWrapperPolicy()) { // The wrapper for the object must be removed. Object iterator = iteratorFor(container); while (hasNext(iterator)) { Object next = next(iterator); if (getElementDescriptor().getObjectBuilder().unwrapObject(next, session).equals(element)) { objectToRemove = next; break; } } } return removeFrom(key, objectToRemove, container); }
/** * ADVANCED: * Assign sequence number to the object. * This allows for an object's id to be assigned before commit. * It can be used if the application requires to use the object id before the object exists on the database. * Normally all ids are assigned during the commit automatically. */ public void assignSequenceNumber(Object object) throws DatabaseException { //** sequencing refactoring startOperationProfile(SessionProfiler.AssignSequence); try { ObjectBuilder builder = getDescriptor(object).getObjectBuilder(); // This is done outside of a transaction to ensure optimial concurrency and deadlock avoidance in the sequence table. if (builder.getDescriptor().usesSequenceNumbers() && !getSequencing().shouldAcquireValueAfterInsert(object.getClass())) { Object implementation = builder.unwrapObject(object, this); builder.assignSequenceNumber(implementation, this); } } catch (RuntimeException exception) { handleException(exception); } endOperationProfile(SessionProfiler.AssignSequence); }
/** * INTERNAL: * Remove a value and its change set from the collection change record. This is used by * attribute change tracking. */ public void removeFromCollectionChangeRecord(Object newKey, Object newValue, ObjectChangeSet objectChangeSet, UnitOfWorkImpl uow) { if (newValue != null) { ClassDescriptor descriptor; //PERF: Use referenceDescriptor if it does not have inheritance if (!getReferenceDescriptor().hasInheritance()) { descriptor = getReferenceDescriptor(); } else { descriptor = uow.getDescriptor(newValue); } newValue = descriptor.getObjectBuilder().unwrapObject(newValue, uow); ObjectChangeSet newSet = descriptor.getObjectBuilder().createObjectChangeSet(newValue, (UnitOfWorkChangeSet)objectChangeSet.getUOWChangeSet(), uow); simpleRemoveFromCollectionChangeRecord(newKey, newSet, objectChangeSet, uow); } }
/** * INTERNAL: * Add a new value and its change set to the collection change record. This is used by * attribute change tracking. */ public void addToCollectionChangeRecord(Object newKey, Object newValue, ObjectChangeSet objectChangeSet, UnitOfWorkImpl uow) { if (newValue != null) { ClassDescriptor descriptor; //PERF: Use referenceDescriptor if it does not have inheritance if (!getReferenceDescriptor().hasInheritance()) { descriptor = getReferenceDescriptor(); } else { descriptor = uow.getDescriptor(newValue); } newValue = descriptor.getObjectBuilder().unwrapObject(newValue, uow); ObjectChangeSet newSet = descriptor.getObjectBuilder().createObjectChangeSet(newValue, (UnitOfWorkChangeSet)objectChangeSet.getUOWChangeSet(), uow); simpleAddToCollectionChangeRecord(newKey, newSet, objectChangeSet, uow); } }
/** * INTERNAL: * Merge the attributes of the clone into the unit of work copy. */ public Object mergeClone(Object rmiClone, int cascadeDepth) { if (rmiClone == null) { return null; } //CR#2272 logDebugMessage(rmiClone, "merge_clone"); startOperationProfile(SessionProfiler.Merge); ObjectBuilder builder = getDescriptor(rmiClone).getObjectBuilder(); Object implementation = builder.unwrapObject(rmiClone, this); MergeManager manager = new MergeManager(this); manager.mergeCloneIntoWorkingCopy(); manager.setCascadePolicy(cascadeDepth); Object merged = null; try { merged = manager.mergeChanges(implementation, null); } catch (RuntimeException exception) { merged = handleException(exception); } endOperationProfile(SessionProfiler.Merge); return merged; }
/** * INTERNAL: * Prepare the receiver for execution in a session. * In particular check that the tables on the descriptor are set. */ protected void prepare() throws QueryException { checkDescriptor(getSession()); if (getObject() != null) {// Prepare can be called without the object set yet. setObject(getDescriptor().getObjectBuilder().unwrapObject(getObject(), getSession())); } if (getDescriptor().isAggregateDescriptor()) { throw QueryException.aggregateObjectCannotBeDeletedOrWritten(getDescriptor(), this); } super.prepare(); }
/** * INTERNAL: * Prepare the receiver for execution in a session. */ protected void prepare() throws QueryException { if (getDescriptor() == null) { //Bug#3947714 Pass the object instead of class in case object is proxy setDescriptor(getSession().getDescriptor(getObject())); } if (getObject() != null) {// Prepare can be called without the object set yet. setObject(getDescriptor().getObjectBuilder().unwrapObject(getObject(), getSession())); } super.prepare(); // It will only get to prepare if check database if required. getQueryMechanism().prepareDoesExist(getDoesExistField()); }
/** * INTERNAL: * Prepare the receiver for execution in a session. * In particular check that the tables on the descriptor are set. */ public void prepareForExecution() throws QueryException { super.prepareForExecution(); if (getObject() == null) { throw QueryException.objectToModifyNotSpecified(this); } setObject(getDescriptor().getObjectBuilder().unwrapObject(getObject(), getSession())); if (getPrimaryKey() == null) { if (getObjectChangeSet() != null) { setPrimaryKey(getObjectChangeSet().getPrimaryKeys()); } else { setPrimaryKey(getSession().keyFromObject(getObject())); } } }
/** * INTERNAL: * Prepare the receiver for execution in a session. */ public void prepareForExecution() throws QueryException { super.prepareForExecution(); if (getObject() == null) { throw QueryException.objectToModifyNotSpecified(this); } setObject(getDescriptor().getObjectBuilder().unwrapObject(getObject(), getSession())); if (getDescriptor() == null) { setDescriptor(getSession().getDescriptor(getObject().getClass())); } if (getPrimaryKey() == null) { setPrimaryKey(getDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(getObject(), getSession())); } if ((getTranslationRow() == null) || (getTranslationRow().isEmpty())) { setTranslationRow(getDescriptor().getObjectBuilder().buildRowForTranslation(getObject(), getSession())); } }