/** * INTERNAL: * Retrieve the cache key for the given object from the identity maps * @param Object object the object to get the cache key for * @return CacheKey */ public CacheKey getCacheKeyForObject(Object object, ClassDescriptor descriptor) { return getCacheKeyForObject(getSession().keyFromObject(object, descriptor), object.getClass(), descriptor); }
/** * ADVANCED: * Set an object to be invalid in the TopLink identity maps. * If the object does not exist in the cache, this method will return * without any action */ public void invalidateObject(Vector primaryKey, Class theClass) { ClassDescriptor descriptor = getSession().getDescriptor(theClass); //forward the call to getCacheKeyForObject locally in case subclasses overload CacheKey key = this.getCacheKeyForObject(primaryKey, theClass, descriptor); if (key != null) { key.setInvalidationState(CacheKey.CACHE_KEY_INVALID); } }
/** * ADVANCED: * Return true if this object is valid in TopLink's identity maps * return false otherwise */ public boolean isValid(Vector primaryKey, Class theClass) { ClassDescriptor descriptor = getSession().getDescriptor(theClass); //forward the call to getCacheKeyForObject locally in case subclasses overload CacheKey key = this.getCacheKeyForObject(primaryKey, theClass, descriptor); if (key == null) { throw QueryException.classPkDoesNotExistInCache(theClass, primaryKey); } return !descriptor.getCacheInvalidationPolicy().isInvalidated(key, System.currentTimeMillis()); }
/** * INTERNAL: * Retrieve the cache key for the given identity information * @param Vector the primary key of the cache key to be retrieved * @param Class the class of the cache key to be retrieved * @return CacheKey */ public CacheKey getCacheKeyForObject(Vector primaryKey, Class myClass, ClassDescriptor descriptor) { if (descriptor.isIsolated()) { return getIdentityMapManager().getCacheKeyForObject(primaryKey, myClass, descriptor); } else { return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKey, myClass, descriptor); } }
/** * ADVANCED: * Return the remaining life of this object. This method is associated with use of * TopLink's cache invalidation feature and returns the difference between the next expiry * time of the object and its read time. The method will return 0 for invalidated objects. */ public long getRemainingValidTime(Object object) { Vector primaryKey = getSession().keyFromObject(object); ClassDescriptor descriptor = getSession().getDescriptor(object); CacheKey key = getCacheKeyForObject(primaryKey, object.getClass(), descriptor); if (key == null) { throw QueryException.objectDoesNotExistInCache(object); } return descriptor.getCacheInvalidationPolicy().getRemainingValidTime(key); }
} else { return session.getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKeys, descriptor.getJavaClass(), descriptor);
Class objectClass = object.getClass(); if (session.isUnitOfWork()){ cacheKey = session.getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKey,objectClass, descriptor); if (cacheKey!=null){ //if in the UOW cache, it exists and can't be invalid return Boolean.TRUE; cacheKey = ((UnitOfWorkImpl)session).getParent().getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKey,objectClass, descriptor); }else{ cacheKey = session.getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKey,objectClass, descriptor);
/** * 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; }
activeCacheKey = session.getIdentityMapAccessorInstance().getCacheKeyForObject(objectChangeSet.getCacheKey().getKey(), objectClass, descriptor); Object[] params = new Object[2]; params[0] = activeCacheKey.getObject();
CacheKey cacheKey = ((UnitOfWorkImpl)getSession()).getParent().getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKey, theClass, descriptor); if ((cacheKey == null) && ((UnitOfWorkImpl)getSession()).getParent().isUnitOfWork()) {//for nested unit of work cacheKey = ((UnitOfWorkImpl)getSession()).getParent().getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKey, theClass, descriptor);
CacheKey originalCacheKey = unitOfWork.getParentIdentityMapSession(query).getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKey, getDescriptor().getJavaClass(), getDescriptor()); if (originalCacheKey != null) { unitOfWorkCacheKey = unitOfWork.getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKey, getDescriptor().getJavaClass(), getDescriptor());