DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isReadQuery()) { if (((ReadQuery)query).getQueryResultsCachePolicy() == null) { ((ReadQuery)query).cacheQueryResults(); } ((ReadQuery)query).getQueryResultsCachePolicy().setInvalidateOnChange(((Boolean)valueToApply).booleanValue()); } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isReadQuery()) { if (((ReadQuery)query).getQueryResultsCachePolicy() == null) { ((ReadQuery)query).cacheQueryResults(); } ((ReadQuery)query).getQueryResultsCachePolicy().setIsNullIgnored(((Boolean)valueToApply).booleanValue()); } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }
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; } }
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isReadQuery()) { if (((Boolean)valueToApply).booleanValue()) { if (((ReadQuery)query).getQueryResultsCachePolicy() == null) { ((ReadQuery)query).cacheQueryResults(); } } } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }
if (query.getQueryResultsCachePolicy().isNullIgnored()) { return; map = this.queryResults.get(queryKey); if (map == null) { int size = query.getQueryResultsCachePolicy().getMaximumCachedResults(); map = buildNewIdentityMap(query.getQueryResultsCachePolicy().getCacheType(), size, null, false); this.queryResults.put(queryKey, map); if (query.getQueryResultsCachePolicy().getInvalidateOnChange()) { for (Class queryClass : query.getQueryResultsCachePolicy().getInvalidationClasses()) { Set invalidations = this.queryResultsInvalidationsByClass.get(queryClass); if (invalidations == null) {
/** * Get the cached results associated with a query. Results are cached by the * values of the parameters to the query so different parameters will have * different cached results. */ public Object getQueryResult(ReadQuery query, List parameters, boolean shouldCheckExpiry) { if (query.getQueryResultsCachePolicy() == null) { return null; } // PERF: use query name, unless no name. Object queryKey = query.getName(); if ((queryKey == null) || ((String)queryKey).length() == 0) { queryKey = query; } IdentityMap map = this.queryResults.get(queryKey); if (map == null) { return null; } Object lookupParameters; if ((parameters == null) || parameters.isEmpty()) { lookupParameters = CacheId.EMPTY; } else { lookupParameters = new CacheId(parameters.toArray()); } CacheKey key = map.getCacheKey(lookupParameters, false); if ((key == null) || (shouldCheckExpiry && query.getQueryResultsCachePolicy().getCacheInvalidationPolicy().isInvalidated(key))) { return null; } return key.getObject(); }
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isReadQuery()) { ReadQuery readQuery = (ReadQuery)query; if (readQuery.getQueryResultsCachePolicy() == null) { readQuery.cacheQueryResults(); readQuery.getQueryResultsCachePolicy().setCacheType(ClassConstants.SoftCacheWeakIdentityMap_Class); } else if (valueToApply.equals(CacheType.FULL.name())) { readQuery.getQueryResultsCachePolicy().setCacheType(ClassConstants.FullIdentityMap_Class); } else if (valueToApply.equals(CacheType.WEAK.name())) { readQuery.getQueryResultsCachePolicy().setCacheType(ClassConstants.WeakIdentityMap_Class); } else if (valueToApply.equals(CacheType.SOFT.name())) { readQuery.getQueryResultsCachePolicy().setCacheType(ClassConstants.SoftIdentityMap_Class); } else if (valueToApply.equals(CacheType.HARD_WEAK.name())) { readQuery.getQueryResultsCachePolicy().setCacheType(ClassConstants.HardCacheWeakIdentityMap_Class); } else if (valueToApply.equals(CacheType.CACHE.name())) { readQuery.getQueryResultsCachePolicy().setCacheType(ClassConstants.CacheIdentityMap_Class); } else if (valueToApply.equals(CacheType.NONE.name())) { readQuery.getQueryResultsCachePolicy().setCacheType(ClassConstants.NoIdentityMap_Class); } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-query-hint-value",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)}));
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isReadQuery()) { ReadQuery readQuery = (ReadQuery)query; if (readQuery.getQueryResultsCachePolicy() == null) { readQuery.cacheQueryResults(); } try { readQuery.getQueryResultsCachePolicy().setMaximumCachedResults(Integer.parseInt((String)valueToApply)); } catch (NumberFormatException exception) { throw QueryException.queryHintContainedInvalidIntegerValue(QueryHints.QUERY_RESULTS_CACHE_SIZE, valueToApply, exception); } } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }
/** * Get the cached results associated with a query. Results are cached by the * values of the parameters to the query so different parameters will have * different cached results. */ public Object getQueryResult(ReadQuery query, List parameters, boolean shouldCheckExpiry) { if (query.getQueryResultsCachePolicy() == null) { return null; } // PERF: use query name, unless no name. Object queryKey = query.getName(); if ((queryKey == null) || ((String)queryKey).length() == 0) { queryKey = query; } IdentityMap map = this.queryResults.get(queryKey); if (map == null) { return null; } Object lookupParameters; if ((parameters == null) || parameters.isEmpty()) { lookupParameters = CacheId.EMPTY; } else { lookupParameters = new CacheId(parameters.toArray()); } CacheKey key = map.getCacheKey(lookupParameters, false); if ((key == null) || (shouldCheckExpiry && query.getQueryResultsCachePolicy().getCacheInvalidationPolicy().isInvalidated(key))) { return null; } return key.getObject(); }
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isReadQuery()) { ReadQuery readQuery = (ReadQuery)query; if (readQuery.getQueryResultsCachePolicy() == null) { readQuery.cacheQueryResults(); } try { Time time = Helper.timeFromString((String)valueToApply); Calendar calendar = Calendar.getInstance(); calendar.setTime(time); readQuery.getQueryResultsCachePolicy().setCacheInvalidationPolicy( new DailyCacheInvalidationPolicy(calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND), 0)); } catch (ConversionException exception) { throw QueryException.queryHintContainedInvalidIntegerValue(QueryHints.QUERY_RESULTS_CACHE_EXPIRY_TIME_OF_DAY, valueToApply, exception); } } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isReadQuery()) { ReadQuery readQuery = (ReadQuery)query; if (readQuery.getQueryResultsCachePolicy() == null) { readQuery.cacheQueryResults(); } try { readQuery.getQueryResultsCachePolicy().setCacheInvalidationPolicy( new TimeToLiveCacheInvalidationPolicy(Integer.parseInt((String)valueToApply))); } catch (NumberFormatException exception) { throw QueryException.queryHintContainedInvalidIntegerValue(QueryHints.QUERY_RESULTS_CACHE_EXPIRY, valueToApply, exception); } } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }
/** * Get the cached results associated with a query. Results are cached by the * values of the parameters to the query so different parameters will have * different cached results. */ public Object getQueryResult(ReadQuery query, Vector parameters, boolean shouldCheckExpiry) { if (query.getQueryResultsCachePolicy() == null) { return null; } // PERF: use query name, unless no name. Object queryKey = query.getName(); if ((queryKey == null) || ((String)queryKey).length() == 0) { queryKey = query; } IdentityMap map = this.queryResults.get(queryKey); if (map == null) { return null; } Vector lookupParameters = parameters; if (lookupParameters == null) { lookupParameters = new NonSynchronizedVector(0); } CacheKey key = map.getCacheKey(lookupParameters); if ((key == null) || (shouldCheckExpiry && query.getQueryResultsCachePolicy().getCacheInvalidationPolicy().isInvalidated(key))) { return null; } return key.getObject(); }
map = this.queryResults.get(queryKey); if (map == null) { map = buildNewIdentityMap(query.getQueryResultsCachePolicy().getCacheType(), query.getQueryResultsCachePolicy().getMaximumCachedResults(), null); this.queryResults.put(queryKey, map); if (query.getQueryResultsCachePolicy().isNullIgnored()) { return;
if (query.getQueryResultsCachePolicy().isNullIgnored()) { return; map = this.queryResults.get(queryKey); if (map == null) { int size = query.getQueryResultsCachePolicy().getMaximumCachedResults(); map = buildNewIdentityMap(query.getQueryResultsCachePolicy().getCacheType(), size, null, false); this.queryResults.put(queryKey, map); if (query.getQueryResultsCachePolicy().getInvalidateOnChange()) { for (Class queryClass : query.getQueryResultsCachePolicy().getInvalidationClasses()) { Set invalidations = this.queryResultsInvalidationsByClass.get(queryClass); if (invalidations == null) {
/** * INTERNAL: * This is different from 'prepareForExecution' in that this is called on the original query, * and the other is called on the copy of the query. * This query is copied for concurrency so this prepare can only setup things that * will apply to any future execution of this query. * * Clear the query cache when a query is prepared. */ protected void prepare() throws QueryException { super.prepare(); if (shouldCacheQueryResults()) { clearQueryResults(getSession()); if (getReferenceClass() != null) { getQueryResultsCachePolicy().getInvalidationClasses().add(getReferenceClass()); } } }
/** * INTERNAL: * This is different from 'prepareForExecution' in that this is called on the original query, * and the other is called on the copy of the query. * This query is copied for concurrency so this prepare can only setup things that * will apply to any future execution of this query. * * Clear the query cache when a query is prepared. */ protected void prepare() throws QueryException { super.prepare(); if (shouldCacheQueryResults()) { clearQueryResults(getSession()); if (getReferenceClass() != null) { getQueryResultsCachePolicy().getInvalidationClasses().add(getReferenceClass()); } } }
query.getQueryResultsCachePolicy().getInvalidationClasses().add(mapping.getReferenceDescriptor().getJavaClass()); } else { QueryKey queryKey = getQueryKeyOrNull(); if ((queryKey != null) && queryKey.isForeignReferenceQueryKey()) { query.getQueryResultsCachePolicy().getInvalidationClasses().add(((ForeignReferenceQueryKey)queryKey).getReferenceClass());
query.getQueryResultsCachePolicy().getInvalidationClasses().add(mapping.getReferenceDescriptor().getJavaClass()); } else { QueryKey queryKey = getQueryKeyOrNull(); if ((queryKey != null) && queryKey.isForeignReferenceQueryKey()) { query.getQueryResultsCachePolicy().getInvalidationClasses().add(((ForeignReferenceQueryKey)queryKey).getReferenceClass());
query.getQueryResultsCachePolicy().getInvalidationClasses().add(this.queryClass);
query.getQueryResultsCachePolicy().getInvalidationClasses().add(this.queryClass);