/** * INTERNAL: * Return the remaining life of this object */ public long getRemainingValidTime(CacheKey key) { long expiryTime = getExpiryTimeInMillis(key); long remainingTime = expiryTime - System.currentTimeMillis(); if (remainingTime > 0) { return remainingTime; } return 0; }
/** * INTERNAL: * return true if this object is expire, false otherwise. */ public abstract boolean isInvalidated(CacheKey key, long currentTimeMillis);
public Object clone() { TimeToLiveCacheInvalidationPolicy clone = null; try { clone = (TimeToLiveCacheInvalidationPolicy)super.clone(); clone.timeToLive = this.timeToLive; } catch (Exception exception) { throw new InternalError("clone failed"); } return clone; } }
public Object clone() { CacheInvalidationPolicy clone = null; try { clone = (CacheInvalidationPolicy)super.clone(); clone.setShouldUpdateReadTimeOnUpdate(this.shouldUpdateReadTimeOnUpdate); clone.setShouldRefreshInvalidObjectsOnClone(this.shouldRefreshInvalidObjectsOnClone); clone.setIsInvalidationRandomized(this.isInvalidationRandomized); } catch (Exception exception) { throw new InternalError("clone failed"); } return clone; } }
/** * INTERNAL: * Check if the object is invalid and *should* be refreshed. * This is used to ensure that no invalid objects are cloned. */ public boolean isConsideredInvalid(Object object, CacheKey cacheKey, ClassDescriptor descriptor) { if (cacheKey.getObject() != null) { CacheInvalidationPolicy cachePolicy = descriptor.getCacheInvalidationPolicy(); // BUG#6671556 refresh invalid objects when accessed in the unit of work. return (cachePolicy.shouldRefreshInvalidObjectsOnClone() && cachePolicy.isInvalidated(cacheKey)); } return false; }
/** * INTERNAL: * Check if the object is invalid and should be refreshed, return true, otherwise return false. * This is used to ensure that no invalid objects are registered. */ public boolean checkInvalidObject(Object object, CacheKey cacheKey, ClassDescriptor descriptor, UnitOfWorkImpl unitOfWork) { if (!unitOfWork.isNestedUnitOfWork() && (cacheKey.getObject() != null)) { CacheInvalidationPolicy cachePolicy = descriptor.getCacheInvalidationPolicy(); // BUG#6671556 refresh invalid objects when accessed in the unit of work. return (cachePolicy.shouldRefreshInvalidObjectsInUnitOfWork() && cachePolicy.isInvalidated(cacheKey)); } return false; }
protected void addCacheInvalidationPolicyLines(NonreflectiveMethodDefinition method, ClassDescriptor descriptor) { CacheInvalidationPolicy policy = descriptor.getCacheInvalidationPolicy(); if (policy instanceof NoExpiryCacheInvalidationPolicy) { if (policy.shouldUpdateReadTimeOnUpdate()) { method.addLine("// Cache Invalidation Policy"); method.addLine("NoExpiryCacheInvalidationPolicy policy = new NoExpiryCacheInvalidationPolicy();"); method.addLine("policy.setShouldUpdateReadTimeOnUpdate(" + policy.shouldUpdateReadTimeOnUpdate() + ");"); method.addLine("descriptor.setCacheInvalidationPolicy(policy);"); } } else if (policy instanceof TimeToLiveCacheInvalidationPolicy) { method.addLine("// Cache Invalidation Policy"); method.addLine("TimeToLiveCacheInvalidationPolicy policy = new TimeToLiveCacheInvalidationPolicy(" + ((TimeToLiveCacheInvalidationPolicy)policy).getTimeToLive() + ");"); method.addLine("policy.setShouldUpdateReadTimeOnUpdate(" + policy.shouldUpdateReadTimeOnUpdate() + ");"); method.addLine("descriptor.setCacheInvalidationPolicy(policy);"); } else if (policy instanceof DailyCacheInvalidationPolicy) { Calendar calendar = ((DailyCacheInvalidationPolicy)policy).getExpiryTime(); int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); int millisecond = calendar.get(Calendar.MILLISECOND); method.addLine("// Cache Invalidation Policy"); method.addLine("DailyCacheInvalidationPolicy policy = new DailyCacheInvalidationPolicy(" + hour + ", " + minute + ", " + second + ", " + millisecond + ");"); method.addLine("policy.setShouldUpdateReadTimeOnUpdate(" + policy.shouldUpdateReadTimeOnUpdate() + ");"); method.addLine("descriptor.setCacheInvalidationPolicy(policy);"); } }
/** * ADVANCED: * Return the remaining life of this object. This method is associated with use of * cache invalidation 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) { Object primaryKey = getSession().getId(object); ClassDescriptor descriptor = getSession().getDescriptor(object); CacheKey key = getCacheKeyForObjectForLock(primaryKey, object.getClass(), descriptor); if (key == null) { throw QueryException.objectDoesNotExistInCache(object); } return descriptor.getCacheInvalidationPolicy().getRemainingValidTime(key); }
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isReadQuery()) { if (((ReadQuery)query).getQueryResultsCachePolicy() == null) { ((ReadQuery)query).cacheQueryResults(); } if (((ReadQuery)query).getQueryResultsCachePolicy().getCacheInvalidationPolicy() == null) { ((ReadQuery)query).getQueryResultsCachePolicy().setCacheInvalidationPolicy(new TimeToLiveCacheInvalidationPolicy()); } ((ReadQuery)query).getQueryResultsCachePolicy().getCacheInvalidationPolicy().setIsInvalidationRandomized(((Boolean)valueToApply).booleanValue()); } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }
protected void addCacheInvalidationPolicyLines(NonreflectiveMethodDefinition method, ClassDescriptor descriptor) { CacheInvalidationPolicy policy = descriptor.getCacheInvalidationPolicy(); if (policy instanceof NoExpiryCacheInvalidationPolicy) { if (policy.shouldUpdateReadTimeOnUpdate()) { method.addLine("// Cache Invalidation Policy"); method.addLine("NoExpiryCacheInvalidationPolicy policy = new NoExpiryCacheInvalidationPolicy();"); method.addLine("policy.setShouldUpdateReadTimeOnUpdate(" + policy.shouldUpdateReadTimeOnUpdate() + ");"); method.addLine("descriptor.setCacheInvalidationPolicy(policy);"); } } else if (policy instanceof TimeToLiveCacheInvalidationPolicy) { method.addLine("// Cache Invalidation Policy"); method.addLine("TimeToLiveCacheInvalidationPolicy policy = new TimeToLiveCacheInvalidationPolicy(" + ((TimeToLiveCacheInvalidationPolicy)policy).getTimeToLive() + ");"); method.addLine("policy.setShouldUpdateReadTimeOnUpdate(" + policy.shouldUpdateReadTimeOnUpdate() + ");"); method.addLine("descriptor.setCacheInvalidationPolicy(policy);"); } else if (policy instanceof DailyCacheInvalidationPolicy) { Calendar calendar = ((DailyCacheInvalidationPolicy)policy).getExpiryTime(); int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); int millisecond = calendar.get(Calendar.MILLISECOND); method.addLine("// Cache Invalidation Policy"); method.addLine("DailyCacheInvalidationPolicy policy = new DailyCacheInvalidationPolicy(" + hour + ", " + minute + ", " + second + ", " + millisecond + ");"); method.addLine("policy.setShouldUpdateReadTimeOnUpdate(" + policy.shouldUpdateReadTimeOnUpdate() + ");"); method.addLine("descriptor.setCacheInvalidationPolicy(policy);"); } }
public Object clone() { CacheInvalidationPolicy clone = null; try { clone = (CacheInvalidationPolicy)super.clone(); clone.setShouldUpdateReadTimeOnUpdate(this.shouldUpdateReadTimeOnUpdate); clone.setShouldRefreshInvalidObjectsOnClone(this.shouldRefreshInvalidObjectsOnClone); clone.setIsInvalidationRandomized(this.isInvalidationRandomized); } catch (Exception exception) { throw new InternalError("clone failed"); } return clone; } }
/** * INTERNAL: * Check if the object is invalid and *should* be refreshed. * This is used to ensure that no invalid objects are cloned. */ public boolean isConsideredInvalid(Object object, CacheKey cacheKey, ClassDescriptor descriptor) { if (cacheKey.getObject() != null) { CacheInvalidationPolicy cachePolicy = descriptor.getCacheInvalidationPolicy(); // BUG#6671556 refresh invalid objects when accessed in the unit of work. return (cachePolicy.shouldRefreshInvalidObjectsOnClone() && cachePolicy.isInvalidated(cacheKey)); } return false; }
/** * INTERNAL: * Check if the object is invalid and refresh it. * This is used to ensure that no invalid objects are registered. */ public void checkInvalidObject(Object object, CacheKey cacheKey, ClassDescriptor descriptor) { if (!isNestedUnitOfWork() && (cacheKey.getObject() != null)) { CacheInvalidationPolicy cachePolicy = descriptor.getCacheInvalidationPolicy(); // BUG#6671556 refresh invalid objects when accessed in the unit of work. if (cachePolicy.shouldRefreshInvalidObjectsInUnitOfWork() && cachePolicy.isInvalidated(cacheKey)) { ReadObjectQuery query = new ReadObjectQuery(); query.setReferenceClass(object.getClass()); query.setSelectionKey(cacheKey.getKey()); query.refreshIdentityMapResult(); query.setIsExecutionClone(true); parent.executeQuery(query); } } }
/** * ADVANCED: * Return the remaining life of this object. This method is associated with use of * cache invalidation 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) { Object primaryKey = getSession().getId(object); ClassDescriptor descriptor = getSession().getDescriptor(object); CacheKey key = getCacheKeyForObjectForLock(primaryKey, object.getClass(), descriptor); if (key == null) { throw QueryException.objectDoesNotExistInCache(object); } return descriptor.getCacheInvalidationPolicy().getRemainingValidTime(key); }
/** * INTERNAL: * return true if this object is expire, false otherwise. */ public abstract boolean isInvalidated(CacheKey key, long currentTimeMillis);
protected void addCacheInvalidationPolicyLines(NonreflectiveMethodDefinition method, ClassDescriptor descriptor) { CacheInvalidationPolicy policy = descriptor.getCacheInvalidationPolicy(); if (policy instanceof NoExpiryCacheInvalidationPolicy) { if (policy.shouldUpdateReadTimeOnUpdate()) { method.addLine("// Cache Invalidation Policy"); method.addLine("NoExpiryCacheInvalidationPolicy policy = new NoExpiryCacheInvalidationPolicy();"); method.addLine("policy.setShouldUpdateReadTimeOnUpdate(" + policy.shouldUpdateReadTimeOnUpdate() + ");"); method.addLine("descriptor.setCacheInvalidationPolicy(policy);"); } } else if (policy instanceof TimeToLiveCacheInvalidationPolicy) { method.addLine("// Cache Invalidation Policy"); method.addLine("TimeToLiveCacheInvalidationPolicy policy = new TimeToLiveCacheInvalidationPolicy(" + ((TimeToLiveCacheInvalidationPolicy)policy).getTimeToLive() + ");"); method.addLine("policy.setShouldUpdateReadTimeOnUpdate(" + policy.shouldUpdateReadTimeOnUpdate() + ");"); method.addLine("descriptor.setCacheInvalidationPolicy(policy);"); } else if (policy instanceof DailyCacheInvalidationPolicy) { Calendar calendar = ((DailyCacheInvalidationPolicy)policy).getExpiryTime(); int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); int millisecond = calendar.get(Calendar.MILLISECOND); method.addLine("// Cache Invalidation Policy"); method.addLine("DailyCacheInvalidationPolicy policy = new DailyCacheInvalidationPolicy(" + hour + ", " + minute + ", " + second + ", " + millisecond + ");"); method.addLine("policy.setShouldUpdateReadTimeOnUpdate(" + policy.shouldUpdateReadTimeOnUpdate() + ");"); method.addLine("descriptor.setCacheInvalidationPolicy(policy);"); } }
/** * INTERNAL: * Return the remaining life of this object */ public long getRemainingValidTime(CacheKey key) { long expiryTime = getExpiryTimeInMillis(key); long remainingTime = expiryTime - System.currentTimeMillis(); if (remainingTime > 0) { return remainingTime; } return 0; }
/** * ADVANCED: * Return the remaining life of this object. This method is associated with use of * cache invalidation 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 = getCacheKeyForObjectForLock(primaryKey, object.getClass(), descriptor); if (key == null) { throw QueryException.objectDoesNotExistInCache(object); } return descriptor.getCacheInvalidationPolicy().getRemainingValidTime(key); }
public Object clone() { TimeToLiveCacheInvalidationPolicy clone = null; try { clone = (TimeToLiveCacheInvalidationPolicy)super.clone(); clone.timeToLive = this.timeToLive; } catch (Exception exception) { throw new InternalError("clone failed"); } return clone; } }
/** * INTERNAL: * return true if this object is expire, false otherwise. */ public abstract boolean isInvalidated(CacheKey key, long currentTimeMillis);