/** * INTERNAL: * This method performs the operations of finding the cacheKey and locking it if possible. * Returns True if the lock was acquired, false otherwise */ protected CacheKey attemptToAcquireLock(Class objectClass, CacheKey cacheKey, AbstractSession session) { return session.getIdentityMapAccessorInstance().acquireLockNoWait(cacheKey.getKey(), objectClass, true, session.getDescriptor(objectClass)); }
/** * INTERNAL: * This method performs the operations of finding the cacheKey and locking it if possible. * Waits until the lock can be acquired */ protected CacheKey waitOnObjectLock(Class objectClass, CacheKey cacheKey, AbstractSession session) { return session.getIdentityMapAccessorInstance().acquireLock(cacheKey.getKey(), objectClass, true, session.getDescriptor(objectClass)); } }
/** * INTERNAL: * Get the IdentityMapManager for this IdentityMapAccessor * This method should be used for all IdentityMapManager access since it may * be overridden in sub classes. */ public IdentityMapManager getIdentityMapManager() { if (session.hasBroker()) { return getSession().getBroker().getIdentityMapAccessorInstance().getIdentityMapManager(); } return identityMapManager; }
/** * Perform a cache lookup for the query. * If the translation row contains all the primary key fields, * then a cache check will be performed. * If the object is found in the cache, return it; * otherwise return null. */ public Object checkCacheForObject(AbstractRecord translationRow, AbstractSession session) { // Null check added for CR#4295 - TW if ((translationRow == null) || (translationRow.isEmpty())) { return null; } List keyFields = getDescriptor().getPrimaryKeyFields(); Vector primaryKey = new Vector(keyFields.size()); for (int index = 0; index < keyFields.size(); index++) { Object value = translationRow.get((DatabaseField)keyFields.get(index)); if (value == null) { return null; } else { primaryKey.add(value); } } return session.getIdentityMapAccessorInstance().getFromIdentityMapWithDeferredLock(primaryKey, getReadObjectQuery().getReferenceClass(), false, getDescriptor()); }
/** * INTERNAL: * Return if their is an object for the primary key. */ public boolean containsObjectInIdentityMap(Vector primaryKey, Class theClass, ClassDescriptor descriptor) { if (getIdentityMapManager().containsKey(primaryKey, theClass, descriptor)) { return true; } return ((UnitOfWorkImpl)getSession()).getParent().getIdentityMapAccessorInstance().containsObjectInIdentityMap(primaryKey, theClass, descriptor); }
/** * INTERNAL: * Return whether the clone object is already registered. */ public boolean isObjectRegistered(Object clone) { if (getCloneMapping().containsKey(clone)) { return true; } // We do smart merge here if (isSmartMerge()){ ClassDescriptor descriptor = getDescriptor(clone); if (getParent().getIdentityMapAccessorInstance().containsObjectInIdentityMap(keyFromObject(clone, descriptor), clone.getClass(), descriptor) ) { mergeCloneWithReferences(clone); // don't put clone in clone mapping since it would result in duplicate clone return true; } } return false; }
/** * Store the query object in the identity map. */ protected void registerObjectInIdentityMap() { WriteObjectQuery writeQuery = getWriteObjectQuery(); Object object = writeQuery.getObject(); if (writeQuery.shouldMaintainCache()) { if (getDescriptor().usesOptimisticLocking()) { Object optimisticLockValue = getDescriptor().getOptimisticLockingPolicy().getValueToPutInCache(writeQuery.getModifyRow(), getSession()); getSession().getIdentityMapAccessorInstance().putInIdentityMap(object, writeQuery.getPrimaryKey(), optimisticLockValue, System.currentTimeMillis(), getDescriptor()); } else { getSession().getIdentityMapAccessorInstance().putInIdentityMap(object, writeQuery.getPrimaryKey(), null, System.currentTimeMillis(), getDescriptor()); } } }
CacheKey lockedCacheKey = session.getIdentityMapAccessorInstance().acquireLockNoWait(primaryKeys, descriptor.getJavaClass(), true, descriptor); if (lockedCacheKey == null){ lockedCacheKey = session.getIdentityMapAccessorInstance().acquireReadLockOnCacheKey(primaryKeys, descriptor.getJavaClass(), descriptor); Object cachedObject = lockedCacheKey.getObject(); lockedCacheKey.releaseReadLock();
/** * PUBLIC: * Set the profiler for the session. * This allows for performance operations to be profiled. */ public void setProfiler(SessionProfiler profiler) { this.profiler = profiler; if (profiler != null) { profiler.setSession(this); setIsInProfile(getProfiler().getProfileWeight() != SessionProfiler.NONE); // Clear cached flag that bybasses the profiler check. getIdentityMapAccessorInstance().getIdentityMapManager().clearCacheAccessPreCheck(); } else { setIsInProfile(false); } }
Object original = getParent().getIdentityMapAccessorInstance().getFromIdentityMap(primaryKey, implementation.getClass(), descriptor);
Object original = getParent().getIdentityMapAccessorInstance().getFromIdentityMap(primaryKey, implementation.getClass(), descriptor);
if ((objectFromCache != object) && (getParent().getIdentityMapAccessorInstance().getFromIdentityMap(primaryKey, object.getClass(), descriptor) != object)) { throw ValidationException.wrongObjectRegistered(object, objectFromCache);
/** * Recursively merge to original from its parent into the clone. * The hastable is used to resolv recursion. */ protected Object mergeChangesOfOriginalIntoWorkingCopy(Object clone) { ClassDescriptor descriptor = getSession().getDescriptor(clone); // Find the original object, if it is not there then do nothing. Object original = ((UnitOfWorkImpl)getSession()).getOriginalVersionOfObjectOrNull(clone); if (original == null) { return clone; } // Merge into the clone from the original, use clone as backup as anything different should be merged. descriptor.getObjectBuilder().mergeIntoObject(clone, false, original, this); //update the change policies with the refresh descriptor.getObjectChangePolicy().revertChanges(clone, descriptor, (UnitOfWorkImpl)this.getSession(), ((UnitOfWorkImpl)this.getSession()).getCloneMapping()); Vector primaryKey = getSession().keyFromObject(clone); if (descriptor.usesOptimisticLocking()) { descriptor.getOptimisticLockingPolicy().mergeIntoParentCache((UnitOfWorkImpl)getSession(), primaryKey, clone); } CacheKey parentCacheKey = ((UnitOfWorkImpl)getSession()).getParent().getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKey, clone.getClass(), descriptor); CacheKey uowCacheKey = getSession().getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKey, clone.getClass(), descriptor); // Check for null because when there is NoIdentityMap, CacheKey will be null if ((parentCacheKey != null) && (uowCacheKey != null)) { uowCacheKey.setReadTime(parentCacheKey.getReadTime()); } return clone; }
/** * INTERNAL: * Called after transaction is completed (committed or rolled back) */ public void afterTransaction(boolean committed, boolean isExternalTransaction) { if (!committed && isExternalTransaction) { // In case jts transaction was internally started but rolled back // directly by TransactionManager this flag may still be true during afterCompletion getParent().setWasJTSTransactionInternallyStarted(false); //bug#4699614 -- added a new life cycle status so we know if the external transaction was rolledback and we don't try to rollback again later setLifecycle(AfterExternalTransactionRolledBack); } if ((getMergeManager() != null) && (getMergeManager().getAcquiredLocks() != null) && (!getMergeManager().getAcquiredLocks().isEmpty())) { //may have unreleased cache locks because of a rollback... getParent().getIdentityMapAccessorInstance().getWriteLockManager().releaseAllAcquiredLocks(getMergeManager()); this.setMergeManager(null); } getParent().afterTransaction(committed, isExternalTransaction); }
/** * 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(); }
/** * Remove the query object from the identity map. */ protected void addObjectDeletedDuringCommit() { WriteObjectQuery writeQuery = getWriteObjectQuery(); Object object = writeQuery.getObject(); // CR3510313, avoid removing aggregate collections from cache (maintain cache is false). if (writeQuery.shouldMaintainCache()) { if (getSession().isUnitOfWork()) { ((UnitOfWorkImpl)getSession()).addObjectDeletedDuringCommit(object, getDescriptor()); } else { getSession().getIdentityMapAccessorInstance().removeFromIdentityMap(writeQuery.getPrimaryKey(), getDescriptor().getJavaClass(), getDescriptor()); } } }
setMergeManager(new MergeManager(this)); getParent().getIdentityMapAccessorInstance().getWriteLockManager().acquireRequiredLocks(getMergeManager(), (UnitOfWorkChangeSet)getUnitOfWorkChangeSet()); if (getDatasourceLogin().shouldSynchronizeObjectLevelReadWriteDatabase() && (getMergeManager() != null)) { getParent().getIdentityMapAccessorInstance().getWriteLockManager().releaseAllAcquiredLocks(getMergeManager()); this.setMergeManager(null); if (getDatasourceLogin().shouldSynchronizeObjectLevelReadWriteDatabase() && (getMergeManager() != null)) { getParent().getIdentityMapAccessorInstance().getWriteLockManager().releaseAllAcquiredLocks(getMergeManager()); this.setMergeManager(null);
Object objectFromCache = getSession().getIdentityMapAccessorInstance().getFromIdentityMap(primaryKey, descriptor.getJavaClass(), false, descriptor); if (objectFromCache != null) { return objectFromCache;
attributeValue = session.getIdentityMapAccessorInstance().getIdentityMapManager().getFromIdentityMap(getPrimaryKeys(), getClassType(session), descriptor);
builder.copyInto(cachedObject, getSelectionObject()); session.getIdentityMapAccessorInstance().putInIdentityMap(getSelectionObject()); cachedObject = getSelectionObject();