private void setCacheable(MetaClass metaClass, ClassDescriptor desc, Session session) { String property = (String) session.getProperty("eclipselink.cache.shared.default"); boolean defaultCache = property == null || Boolean.valueOf(property); if ((defaultCache && !desc.isIsolated()) || desc.getCacheIsolation() == CacheIsolationType.SHARED || desc.getCacheIsolation() == CacheIsolationType.PROTECTED) { metaClass.getAnnotations().put("cacheable", true); desc.getCachePolicy().setCacheCoordinationType(CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS); } }
/** * INTERNAL: * This method will be used to update the query with any settings required * For this session. It can also be used to validate execution. */ public void validateQuery(DatabaseQuery query) { if (query.isObjectLevelReadQuery() && (query.getDescriptor().isIsolated() || ((ObjectLevelReadQuery)query).shouldUseExclusiveConnection())) { throw QueryException.isolatedQueryExecutedOnServerSession(); } }
/** * INTERNAL: * Provides access for setting a concurrency lock on an object in the IdentityMap. * called with true from the merge process, if true then the refresh will not refresh the object. */ public CacheKey acquireLock(Vector primaryKey, Class domainClass, boolean forMerge, ClassDescriptor descriptor) { if (descriptor.isIsolated()) { return getIdentityMapManager().acquireLock(primaryKey, domainClass, forMerge, descriptor); } else { return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().acquireLock(primaryKey, domainClass, forMerge, descriptor); } }
/** * INTERNAL: * Provides access for setting a concurrency lock on an object in the IdentityMap. * called with true from the merge process, if true then the refresh will not refresh the object. */ public CacheKey acquireLockWithWait(Vector primaryKey, Class domainClass, boolean forMerge, ClassDescriptor descriptor, int wait) { if (descriptor.isIsolated()) { return getIdentityMapManager().acquireLockWithWait(primaryKey, domainClass, forMerge, descriptor, wait); } else { return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().acquireLockWithWait(primaryKey, domainClass, forMerge, descriptor, wait); } }
/** * INTERNAL: * Provides access for setting a concurrency lock on an object in the IdentityMap. * called with true from the merge process, if true then the refresh will not refresh the object. */ public CacheKey acquireLockNoWait(Vector primaryKey, Class domainClass, boolean forMerge, ClassDescriptor descriptor) { if (descriptor.isIsolated()) { return getIdentityMapManager().acquireLockNoWait(primaryKey, domainClass, forMerge, descriptor); } else { return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().acquireLockNoWait(primaryKey, domainClass, forMerge, descriptor); } }
/** * INTERNAL: * Get the identity map for the given class from the IdentityMapManager */ public IdentityMap getIdentityMap(ClassDescriptor descriptor) { if (descriptor.isIsolated()) { return getIdentityMapManager().getIdentityMap(descriptor); } else { return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().getIdentityMap(descriptor); } }
/** * ADVANCED: * Extract the write lock value from the identity map. */ public Object getWriteLockValue(Vector primaryKey, Class theClass, ClassDescriptor descriptor) { if (descriptor.isIsolated()) { return getIdentityMapManager().getWriteLockValue(primaryKey, theClass, descriptor); } else { return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().getWriteLockValue(primaryKey, theClass, descriptor); } }
/** * ADVANCED: * Remove the object from the object cache. */ public Object removeFromIdentityMap(Vector key, Class theClass, ClassDescriptor descriptor, Object object) { if (descriptor.isIsolated()) { return getIdentityMapManager().removeFromIdentityMap(key, theClass, descriptor, object); } else { return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().removeFromIdentityMap(key, theClass, descriptor, object); } }
/** * INTERNAL: * Deferred lock the identity map for the object, this is used for avoiding deadlock * The return cacheKey should be used to release the deferred lock */ public CacheKey acquireDeferredLock(Vector primaryKey, Class javaClass, ClassDescriptor descriptor) { if (descriptor.isIsolated()) { return getIdentityMapManager().acquireDeferredLock(primaryKey, javaClass, descriptor); } else { return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().acquireDeferredLock(primaryKey, javaClass, descriptor); } }
/** * INTERNAL: * Query the cache in-memory. * If the object is not found null is returned. * If the expression is too complex an exception will be thrown. */ public Object getFromIdentityMap(Expression selectionCriteria, Class theClass, Record translationRow, int valueHolderPolicy, boolean conforming, boolean shouldReturnInvalidatedObjects, ClassDescriptor descriptor) { if (descriptor.isIsolated()) { return getIdentityMapManager().getFromIdentityMap(selectionCriteria, theClass, translationRow, valueHolderPolicy, conforming, shouldReturnInvalidatedObjects, descriptor); } else { return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().getFromIdentityMap(selectionCriteria, theClass, translationRow, valueHolderPolicy, conforming, shouldReturnInvalidatedObjects, descriptor); } }
/** * INTERNAL: * Find the cachekey for the provided primary key and place a readlock on it. * This will allow multiple users to read the same object but prevent writes to * the object while the read lock is held. */ public CacheKey acquireReadLockOnCacheKey(Vector primaryKey, Class domainClass, ClassDescriptor descriptor) { if (descriptor.isIsolated()) { return getIdentityMapManager().acquireReadLockOnCacheKey(primaryKey, domainClass, descriptor); } else { return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().acquireReadLockOnCacheKey(primaryKey, domainClass, descriptor); } }
/** * ADVANCED: * Return the object from the identity with the primary and class. */ public Object getFromIdentityMap(Vector primaryKey, Class theClass, boolean shouldReturnInvalidatedObjects, ClassDescriptor descriptor) { if (descriptor.isIsolated()) { if (this.identityMapManager == null) { return null; } return getIdentityMapManager().getFromIdentityMap(primaryKey, theClass, shouldReturnInvalidatedObjects, descriptor); } else { return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().getFromIdentityMap(primaryKey, theClass, shouldReturnInvalidatedObjects, descriptor); } }
/** * ADVANCED: * Register the object with the identity map. * The object must always be registered with its version number if optimistic locking is used. * The readTime may also be included in the cache key as it is constructed. */ public CacheKey internalPutInIdentityMap(Object domainObject, Vector key, Object writeLockValue, long readTime, ClassDescriptor descriptor) { //no need to unwrap as the put will unwrap later anyway if (descriptor.isIsolated()) { return getIdentityMapManager().putInIdentityMap(domainObject, key, writeLockValue, readTime, descriptor); } else { return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().internalPutInIdentityMap(domainObject, key, writeLockValue, readTime, descriptor); } }
/** * INTERNAL: * Find the cachekey for the provided primary key and place a readlock on it. * This will allow multiple users to read the same object but prevent writes to * the object while the read lock is held. * If no readlock can be acquired then do not wait but return null. */ public CacheKey acquireReadLockOnCacheKeyNoWait(Vector primaryKey, Class domainClass, ClassDescriptor descriptor) { if (descriptor.isIsolated()) { return getIdentityMapManager().acquireReadLockOnCacheKeyNoWait(primaryKey, domainClass, descriptor); } else { return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().acquireReadLockOnCacheKeyNoWait(primaryKey, domainClass, descriptor); } }
/** * ADVANCED: * Return if their is an object for the primary key. */ public boolean containsObjectInIdentityMap(Vector primaryKey, Class theClass, ClassDescriptor descriptor) { if (descriptor.isIsolated()) { if (this.identityMapManager == null) { return false; } return getIdentityMapManager().containsKey(primaryKey, theClass, descriptor); } else { return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().containsObjectInIdentityMap(primaryKey, theClass, descriptor); } }
/** * INTERNAL: * Get the wrapper object from the cache key associated with the given primary key, * this is used for EJB. */ public Object getWrapper(Vector primaryKey, Class theClass) { if (session.getDescriptor(theClass).isIsolated()) { return getIdentityMapManager().getWrapper(primaryKey, theClass); } else { return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().getWrapper(primaryKey, theClass); } }
/** * ADVANCED: * Query the cache in-memory. * If the expression is too complex an exception will be thrown. * Only return objects that are invalid in the cache if specified. */ public Vector getAllFromIdentityMap(Expression selectionCriteria, Class theClass, Record translationRow, int valueHolderPolicy, boolean shouldReturnInvalidatedObjects) throws QueryException { if (session.getDescriptor(theClass).isIsolated()) { return getIdentityMapManager().getAllFromIdentityMap(selectionCriteria, theClass, translationRow, valueHolderPolicy, shouldReturnInvalidatedObjects); } else { return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().getAllFromIdentityMap(selectionCriteria, theClass, translationRow, valueHolderPolicy, shouldReturnInvalidatedObjects); } }
/** * INTERNAL: * Update the wrapper object the cache key associated with the given primary key, * this is used for EJB. */ public void setWrapper(Vector primaryKey, Class theClass, Object wrapper) { if (getSession().getDescriptor(theClass).isIsolated()) { getIdentityMapManager().setWrapper(primaryKey, theClass, wrapper); } else { ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().setWrapper(primaryKey, theClass, wrapper); } }
/** * ADVANCED: * Update the write lock value in the identity map. */ public void updateWriteLockValue(Vector primaryKey, Class theClass, Object writeLockValue) { if (getSession().getDescriptor(theClass).isIsolated()) { getIdentityMapManager().setWriteLockValue(primaryKey, theClass, writeLockValue); } else { ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().updateWriteLockValue(primaryKey, theClass, writeLockValue); } } }
/** * PUBLIC: * Used to print all the objects in the identity map of the passed in class. * The output of this method will be logged to this session's SessionLog at SEVERE level. */ public void printIdentityMap(Class businessClass) { if (getSession().shouldLog(SessionLog.SEVERE, SessionLog.CACHE)) { if (session.getDescriptor(businessClass).isIsolated()) { getIdentityMapManager().printIdentityMap(businessClass); } else { ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().printIdentityMap(businessClass); } } }