Search in sources :

Example 1 with InvalidObject

use of org.eclipse.persistence.internal.helper.InvalidObject in project eclipselink by eclipse-ee4j.

the class IdentityMapManager method putQueryResult.

/**
 * Set the results for a query.
 * Query results are cached based on the parameter values provided to the query
 * different parameter values access different caches.
 */
public void putQueryResult(ReadQuery query, List parameters, Object results) {
    if ((results == null) || (results == InvalidObject.instance())) {
        if (query.getQueryResultsCachePolicy().isNullIgnored()) {
            return;
        }
    }
    // 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) {
        synchronized (this.queryResults) {
            map = this.queryResults.get(queryKey);
            if (map == null) {
                int size = query.getQueryResultsCachePolicy().getMaximumCachedResults();
                // PERF: If no parameters, then there can only be one result.
                if ((parameters == null) || parameters.isEmpty()) {
                    size = 1;
                }
                map = buildNewIdentityMap(query.getQueryResultsCachePolicy().getCacheType(), size, null, false);
                this.queryResults.put(queryKey, map);
                // Mark the query to be invalidated for the query classes.
                if (query.getQueryResultsCachePolicy().getInvalidateOnChange()) {
                    for (Class<?> queryClass : query.getQueryResultsCachePolicy().getInvalidationClasses()) {
                        Set invalidations = this.queryResultsInvalidationsByClass.get(queryClass);
                        if (invalidations == null) {
                            invalidations = new HashSet();
                            this.queryResultsInvalidationsByClass.put(queryClass, invalidations);
                        }
                        invalidations.add(queryKey);
                    }
                }
            }
        }
    }
    Object lookupParameters;
    if ((parameters == null) || parameters.isEmpty()) {
        lookupParameters = CacheId.EMPTY;
    } else {
        lookupParameters = new CacheId(parameters.toArray());
    }
    long queryTime = 0;
    if (query.isObjectLevelReadQuery()) {
        queryTime = ((ObjectLevelReadQuery) query).getExecutionTime();
    }
    if (queryTime == 0) {
        queryTime = System.currentTimeMillis();
    }
    // Bug 6138532 - store InvalidObject for "no results", do not store null
    if (results == null) {
        results = InvalidObject.instance();
    }
    map.put(lookupParameters, results, null, queryTime);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) InvalidObject(org.eclipse.persistence.internal.helper.InvalidObject) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 Set (java.util.Set)1 InvalidObject (org.eclipse.persistence.internal.helper.InvalidObject)1