/** * Build the primary key expression from the specified domain object. */ public Expression buildPrimaryKeyExpressionFromObject(Object domainObject, AbstractSession session) { return buildPrimaryKeyExpressionFromKeys(extractPrimaryKeyFromObject(domainObject, session), session); }
/** * INTERNAL: */ protected Vector getPrimaryKeyForObject(Object object, AbstractSession session) { return getReferenceDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(object, session); }
/** * 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); }
/** * INTERNAL: * Print the objects in the unit of work. */ protected void basicPrintRegisteredObjects() { String cr = Helper.cr(); StringWriter writer = new StringWriter(); writer.write(LoggingLocalization.buildMessage("unitofwork_identity_hashcode", new Object[] { cr, String.valueOf(System.identityHashCode(this)) })); if (hasDeletedObjects()) { writer.write(cr + LoggingLocalization.buildMessage("deleted_objects")); for (Enumeration enumtr = getDeletedObjects().keys(); enumtr.hasMoreElements();) { Object object = enumtr.nextElement(); writer.write(LoggingLocalization.buildMessage("key_identity_hash_code_object", new Object[] { cr, Helper.printVector(getDescriptor(object).getObjectBuilder().extractPrimaryKeyFromObject(object, this)), "\t", String.valueOf(System.identityHashCode(object)), object })); } } writer.write(cr + LoggingLocalization.buildMessage("all_registered_clones")); for (Enumeration enumtr = getCloneMapping().keys(); enumtr.hasMoreElements();) { Object object = enumtr.nextElement(); writer.write(LoggingLocalization.buildMessage("key_identity_hash_code_object", new Object[] { cr, Helper.printVector(getDescriptor(object).getObjectBuilder().extractPrimaryKeyFromObject(object, this)), "\t", String.valueOf(System.identityHashCode(object)), object })); } log(SessionLog.SEVERE, SessionLog.TRANSACTION, writer.toString(), null, null, false); }
/** * Get the object from the identity map which has the same identity information * as the given object. */ public Object getFromIdentityMap(Object object) { ClassDescriptor descriptor = getSession().getDescriptor(object); Vector primaryKey = descriptor.getObjectBuilder().extractPrimaryKeyFromObject(object, getSession()); return getFromIdentityMap(primaryKey, object.getClass(), descriptor); }
/** * 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); } }
public void iterate(Object object) { if (!containsObjectInIdentityMap(IdentityMapAccessor.this.session.getDescriptor(object.getClass()).getObjectBuilder().extractPrimaryKeyFromObject(object, IdentityMapAccessor.this.getSession()), object.getClass())) { IdentityMapAccessor.this.session.log(SessionLog.FINEST, SessionLog.CACHE, "stack_of_visited_objects_that_refer_to_the_corrupt_object", getVisitedStack()); IdentityMapAccessor.this.session.log(SessionLog.FINER, SessionLog.CACHE, "corrupt_object_referenced_through_mapping", getCurrentMapping()); IdentityMapAccessor.this.session.log(SessionLog.FINER, SessionLog.CACHE, "corrupt_object", object); } } };
/** * INTERNAL: * Return any new object matching the expression. * Used for in-memory querying. */ public Object getObjectFromNewObjects(Class theClass, Vector selectionKey) { // PERF: Avoid initialization of new objects if none. if (!hasNewObjects()) { return null; } ObjectBuilder objectBuilder = getDescriptor(theClass).getObjectBuilder(); for (Enumeration newObjectsEnum = getNewObjectsOriginalToClone().elements(); newObjectsEnum.hasMoreElements();) { Object object = newObjectsEnum.nextElement(); if (theClass.isInstance(object)) { // removed dead null check as this method is never called if selectionKey == null Vector primaryKey = objectBuilder.extractPrimaryKeyFromObject(object, this); if (new CacheKey(primaryKey).equals(new CacheKey(selectionKey))) { return object; } } } return null; }
throw QueryException.cannotConformExpression(); leftPrimaryKey = descriptor.getObjectBuilder().extractPrimaryKeyFromObject(leftValue, session); rightPrimaryKey = descriptor.getObjectBuilder().extractPrimaryKeyFromObject(rightValue, session);
/** * Compare two objects if their parts are not private owned */ protected boolean compareObjectsWithoutPrivateOwned(Object firstCollection, Object secondCollection, AbstractSession session) { ContainerPolicy cp = getContainerPolicy(); if (cp.sizeFor(firstCollection) != cp.sizeFor(secondCollection)) { return false; } Object firstIter = cp.iteratorFor(firstCollection); Object secondIter = cp.iteratorFor(secondCollection); Vector keyValue = new Vector(); while (cp.hasNext(secondIter)) { Object secondObject = cp.next(secondIter, session); Vector primaryKey = getReferenceDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(secondObject, session); keyValue.addElement(new CacheKey(primaryKey)); } while (cp.hasNext(firstIter)) { Object firstObject = cp.next(firstIter, session); Vector primaryKey = getReferenceDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(firstObject, session); if (!keyValue.contains(new CacheKey(primaryKey))) { return false; } } return true; }
/** * INTERNAL: */ public boolean checkForUnregisteredExistingObject(Object object) { ClassDescriptor descriptor = getDescriptor(object.getClass()); Vector primaryKey = descriptor.getObjectBuilder().extractPrimaryKeyFromObject(object, this); DoesExistQuery existQuery = descriptor.getQueryManager().getDoesExistQuery(); existQuery = (DoesExistQuery)existQuery.clone(); existQuery.setObject(object); existQuery.setPrimaryKey(primaryKey); existQuery.setDescriptor(descriptor); existQuery.setCheckCacheFirst(true); if (((Boolean)executeQuery(existQuery)).booleanValue()) { return true; } else { return false; } }
Object implementation = builder.unwrapObject(workingClone, this); Vector primaryKey = builder.extractPrimaryKeyFromObject(implementation, this); Object original = getParent().getIdentityMapAccessorInstance().getFromIdentityMap(primaryKey, implementation.getClass(), descriptor);
/** * INTERNAL: * Simply check that the object is not already locked then pass it on to the locking method */ protected CacheKey checkAndLockObject(Object objectToLock, Map lockedObjects, DatabaseMapping mapping, AbstractSession session) { //the cachekey should always reference an object otherwise what would we be cloning. if ((objectToLock != null) && !lockedObjects.containsKey(objectToLock)) { Vector primaryKeysToLock = null; ClassDescriptor referenceDescriptor = null; if (mapping.getReferenceDescriptor().hasInheritance()) { referenceDescriptor = session.getDescriptor(objectToLock); } else { referenceDescriptor = mapping.getReferenceDescriptor(); } // Need to traverse aggregates, but not lock aggregates directly. if (referenceDescriptor.isAggregateDescriptor() || referenceDescriptor.isAggregateCollectionDescriptor()) { traverseRelatedLocks(objectToLock, lockedObjects, referenceDescriptor, session); } else { primaryKeysToLock = referenceDescriptor.getObjectBuilder().extractPrimaryKeyFromObject(objectToLock, session); CacheKey toWaitOn = acquireLockAndRelatedLocks(objectToLock, lockedObjects, primaryKeysToLock, referenceDescriptor, session); if (toWaitOn != null) { return toWaitOn; } } } return null; }
public void iterate(Object object) { if (isClassReadOnly(object.getClass(), getCurrentDescriptor())) { setShouldBreak(true); return; } // Check if object exists in the IM. Vector primaryKey = getCurrentDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(object, UnitOfWorkImpl.this); // If object exists in IM remove it from the IM and also from clone mapping. getIdentityMapAccessorInstance().removeFromIdentityMap(primaryKey, object.getClass(), getCurrentDescriptor()); getCloneMapping().remove(object); // Remove object from the new object cache // PERF: Avoid initialization of new objects if none. if (hasNewObjects()) { Object original = getNewObjectsCloneToOriginal().remove(object); if (original != null) { getNewObjectsOriginalToClone().remove(original); } } } };
/** * INTERNAL: * Used by the ObjectBuilder to create an ObjectChangeSet for the specified clone object * @return oracle.toplink.essentials.internal.sessions.ObjectChangeSet the newly created changeSet representing the clone object * @param clone java.lang.Object the object to convert to a changeSet * @param uowChangeSet oracle.toplink.essentials.internal.sessions.UnitOfWorkChangeSet the owner of this changeSet * @param isNew boolean signifies if the clone object is a new object. */ public ObjectChangeSet createObjectChangeSet(Object clone, UnitOfWorkChangeSet uowChangeSet, boolean isNew, AbstractSession session) { ObjectChangeSet changes = (ObjectChangeSet)uowChangeSet.getObjectChangeSetForClone(clone); if (changes == null) { if (getDescriptor().isAggregateDescriptor()) { changes = new AggregateObjectChangeSet(new Vector(0), getDescriptor().getJavaClass(), clone, uowChangeSet, isNew); } else { changes = new ObjectChangeSet(extractPrimaryKeyFromObject(clone, session), getDescriptor().getJavaClass(), clone, uowChangeSet, isNew); } changes.setIsAggregate(getDescriptor().isAggregateDescriptor() || getDescriptor().isAggregateCollectionDescriptor()); uowChangeSet.addObjectChangeSetForIdentity(changes, clone); } return changes; }
/** * Return the coresponding value that should be assigned to the target object for the source object. * This value must be local to the targets object space. */ public Object getTargetVersionOfSourceObject(Object source) { if (shouldMergeWorkingCopyIntoOriginal() || shouldMergeWorkingCopyIntoRemote()) { // Target is in uow parent, or original instance for new object. return ((UnitOfWorkImpl)getSession()).getOriginalVersionOfObject(source); } else if (shouldMergeCloneIntoWorkingCopy() || shouldMergeOriginalIntoWorkingCopy() || shouldMergeCloneWithReferencesIntoWorkingCopy()) { // Target is clone from uow. //make sure we use the register for merge //bug 3584343 return registerObjectForMergeCloneIntoWorkingCopy(source); } else if (shouldRefreshRemoteObject()) { // Target is in session's cache. ClassDescriptor descriptor = getSession().getDescriptor(source); Vector primaryKey = descriptor.getObjectBuilder().extractPrimaryKeyFromObject(source, getSession()); return getSession().getIdentityMapAccessorInstance().getFromIdentityMap(primaryKey, source.getClass(), descriptor); } throw ValidationException.invalidMergePolicy(); }
/** * Update the foreign key fields when resolving a bi-directonal reference in a UOW. * This must always be dynamic as it is called within an insert query and is really part of the insert * and does not fire update events or worry about locking. */ protected void updateForeignKeyFieldAfterInsert() { WriteObjectQuery writeQuery = getWriteObjectQuery(); Object object = writeQuery.getObject(); writeQuery.setPrimaryKey(getDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(object, getSession())); // reset the translation row because the insert has occurred and the id has // been assigned to the object, but not the row writeQuery.setTranslationRow(getDescriptor().getObjectBuilder().buildRowForTranslation(object, getSession())); writeQuery.setModifyRow(getDescriptor().getObjectBuilder().buildRowForUpdate(writeQuery)); updateForeignKeyFieldShallow(writeQuery); }
/** * Null out the foreign key fields when resolving a bi-directonal reference in a UOW. * This must always be dynamic as it is called within a delete query and is really part of the delete * and does not fire update events or worry about locking. */ protected void updateForeignKeyFieldBeforeDelete() { WriteObjectQuery writeQuery = getWriteObjectQuery(); Object object = writeQuery.getObject(); writeQuery.setPrimaryKey(getDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(object, getSession())); // set the translation row writeQuery.setTranslationRow(getDescriptor().getObjectBuilder().buildRowForTranslation(object, getSession())); // build a query to null out the foreign keys writeQuery.setModifyRow(getDescriptor().getObjectBuilder().buildRowForShallowDelete(object, getSession())); updateForeignKeyFieldShallow(writeQuery); }
/** * 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())); } }
/** * Update the object's primary key by fetching a new sequence number from the accessor. */ protected void updateObjectAndRowWithSequenceNumber() throws DatabaseException { WriteObjectQuery writeQuery = getWriteObjectQuery(); Object object = writeQuery.getObject(); Object sequenceValue = getDescriptor().getObjectBuilder().assignSequenceNumber(object, getSession()); if (sequenceValue == null) { return; } Vector primaryKeys = getDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(object, getSession()); writeQuery.setPrimaryKey(primaryKeys); DatabaseField sequenceNumberField = getDescriptor().getSequenceNumberField(); // Now I need to update the row getModifyRow().put(sequenceNumberField, sequenceValue); getDescriptor().getObjectBuilder().addPrimaryKeyForNonDefaultTable(getModifyRow()); // update the changeSet if there is one if (getSession().isUnitOfWork()) { ObjectChangeSet objectChangeSet = writeQuery.getObjectChangeSet(); if ((objectChangeSet == null) && (((UnitOfWorkImpl)getSession()).getUnitOfWorkChangeSet() != null)) { objectChangeSet = (ObjectChangeSet)((UnitOfWorkImpl)getSession()).getUnitOfWorkChangeSet().getObjectChangeSetForClone(object); } if (objectChangeSet != null) { updateChangeSet(getDescriptor(), objectChangeSet, sequenceNumberField, object); objectChangeSet.setCacheKey(new CacheKey(primaryKeys)); } } }