Skip to content

Commit

Permalink
Move query caches into org.datanucleus.store.query.cache. Fixes #234
Browse files Browse the repository at this point in the history
Change query caching so that we always have the 3 query caches (not
possible to turn them off). Fixes #235
  • Loading branch information
andyjefferson committed Jul 6, 2017
1 parent 7346493 commit 2fa9adb
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 85 deletions.
Expand Up @@ -275,7 +275,6 @@ public void applyDefaultProperties(Configuration conf)

conf.addDefaultProperty(PropertyNames.PROPERTY_CACHE_QUERYCOMPILE_TYPE, null, "soft", null, false, false);
conf.addDefaultProperty(PropertyNames.PROPERTY_CACHE_QUERYCOMPILEDATASTORE_TYPE, null, "soft", null, false, false);

conf.addDefaultProperty(PropertyNames.PROPERTY_CACHE_QUERYRESULTS_TYPE, null, "soft", null, false, false);
conf.addDefaultProperty(PropertyNames.PROPERTY_CACHE_QUERYRESULTS_NAME, null, "datanucleus-query", null, false, false);
conf.addDefaultIntegerProperty(PropertyNames.PROPERTY_CACHE_QUERYRESULTS_MAXSIZE, null, -1, false, false);
Expand Down
Expand Up @@ -22,8 +22,8 @@

import org.datanucleus.ExecutionContext;
import org.datanucleus.query.compiler.QueryCompilation;
import org.datanucleus.query.compiler.QueryCompilationCache;
import org.datanucleus.query.inmemory.InvocationEvaluator;
import org.datanucleus.store.query.cache.QueryCompilationCache;
import org.datanucleus.store.query.cache.QueryDatastoreCompilationCache;
import org.datanucleus.store.query.cache.QueryResultsCache;

Expand Down
144 changes: 71 additions & 73 deletions src/main/java/org/datanucleus/store/query/QueryManagerImpl.java
Expand Up @@ -40,11 +40,11 @@
import org.datanucleus.plugin.PluginManager;
import org.datanucleus.query.QueryUtils;
import org.datanucleus.query.compiler.QueryCompilation;
import org.datanucleus.query.compiler.QueryCompilationCache;
import org.datanucleus.query.inmemory.InvocationEvaluator;
import org.datanucleus.query.inmemory.method.ArrayContainsMethod;
import org.datanucleus.query.inmemory.method.ArraySizeMethod;
import org.datanucleus.store.StoreManager;
import org.datanucleus.store.query.cache.QueryCompilationCache;
import org.datanucleus.store.query.cache.QueryDatastoreCompilationCache;
import org.datanucleus.store.query.cache.QueryResultsCache;
import org.datanucleus.util.Localiser;
Expand All @@ -62,13 +62,13 @@ public class QueryManagerImpl implements QueryManager
protected StoreManager storeMgr;

/** Cache for generic query compilations. */
protected QueryCompilationCache queryCompilationCache = null;
protected final QueryCompilationCache queryCompilationCache;

/** Cache for datastore query compilations. */
protected QueryDatastoreCompilationCache queryCompilationCacheDatastore = null;
protected final QueryDatastoreCompilationCache queryCompilationCacheDatastore;

/** Cache for query results. */
protected QueryResultsCache queryResultsCache = null;
protected final QueryResultsCache queryResultsCache;

/** Cache of InvocationEvaluator objects keyed by the method name, for use by in-memory querying. */
protected Map<String, Map<Object, InvocationEvaluator>> inmemoryQueryMethodEvaluatorMap = new ConcurrentHashMap<String, Map<Object,InvocationEvaluator>>();
Expand All @@ -78,90 +78,91 @@ public QueryManagerImpl(NucleusContext nucleusContext, StoreManager storeMgr)
this.nucleusCtx = nucleusContext;
this.storeMgr = storeMgr;

// Instantiate the query compilation cache (generic)
Configuration conf = nucleusCtx.getConfiguration();

// QueryCompilationCache (generic compilation)
String cacheType = conf.getStringProperty(PropertyNames.PROPERTY_CACHE_QUERYCOMPILE_TYPE);
if (cacheType != null && !cacheType.equalsIgnoreCase("none"))
if (cacheType == null)
{
String cacheClassName = nucleusCtx.getPluginManager().getAttributeValueForExtension("org.datanucleus.cache_query_compilation", "name", cacheType, "class-name");
if (cacheClassName == null)
{
// Plugin of this name not found
throw new NucleusUserException(Localiser.msg("021500", cacheType)).setFatal();
}

try
{
// Create an instance of the Query Cache
queryCompilationCache = (QueryCompilationCache)nucleusCtx.getPluginManager().createExecutableExtension("org.datanucleus.cache_query_compilation",
"name", cacheType, "class-name", new Class[] {ClassConstants.NUCLEUS_CONTEXT}, new Object[] {nucleusCtx});
if (NucleusLogger.CACHE.isDebugEnabled())
{
NucleusLogger.CACHE.debug(Localiser.msg("021502", cacheClassName));
}
}
catch (Exception e)
cacheType = "soft";
}
String cacheClassName = nucleusCtx.getPluginManager().getAttributeValueForExtension("org.datanucleus.cache_query_compilation", "name", cacheType, "class-name");
if (cacheClassName == null)
{
// Plugin of this name not found
throw new NucleusUserException(Localiser.msg("021500", cacheType)).setFatal();
}
try
{
// Create an instance of the Query Cache
queryCompilationCache = (QueryCompilationCache)nucleusCtx.getPluginManager().createExecutableExtension("org.datanucleus.cache_query_compilation",
"name", cacheType, "class-name", new Class[] {ClassConstants.NUCLEUS_CONTEXT}, new Object[] {nucleusCtx});
if (NucleusLogger.CACHE.isDebugEnabled())
{
// Class name for this Query cache plugin is not found!
throw new NucleusUserException(Localiser.msg("021501", cacheType, cacheClassName), e).setFatal();
NucleusLogger.CACHE.debug(Localiser.msg("021502", cacheClassName));
}
}
catch (Exception e)
{
// Class name for this Query cache plugin is not found!
throw new NucleusUserException(Localiser.msg("021501", cacheType, cacheClassName), e).setFatal();
}

// Instantiate the query compilation cache (datastore)
// QueryCompilationCache (datastore compilation)
cacheType = conf.getStringProperty(PropertyNames.PROPERTY_CACHE_QUERYCOMPILEDATASTORE_TYPE);
if (cacheType != null && !cacheType.equalsIgnoreCase("none"))
if (cacheType == null)
{
String cacheClassName = nucleusCtx.getPluginManager().getAttributeValueForExtension("org.datanucleus.cache_query_compilation_store", "name", cacheType, "class-name");
if (cacheClassName == null)
{
// Plugin of this name not found
throw new NucleusUserException(Localiser.msg("021500", cacheType)).setFatal();
}

try
{
// Create an instance of the Query Cache
queryCompilationCacheDatastore = (QueryDatastoreCompilationCache)nucleusCtx.getPluginManager().createExecutableExtension("org.datanucleus.cache_query_compilation_store",
"name", cacheType, "class-name", new Class[] {ClassConstants.NUCLEUS_CONTEXT}, new Object[] {nucleusCtx});
if (NucleusLogger.CACHE.isDebugEnabled())
{
NucleusLogger.CACHE.debug(Localiser.msg("021502", cacheClassName));
}
}
catch (Exception e)
cacheType = "soft";
}
cacheClassName = nucleusCtx.getPluginManager().getAttributeValueForExtension("org.datanucleus.cache_query_compilation_store", "name", cacheType, "class-name");
if (cacheClassName == null)
{
// Plugin of this name not found
throw new NucleusUserException(Localiser.msg("021500", cacheType)).setFatal();
}
try
{
// Create an instance of the Query Cache
queryCompilationCacheDatastore = (QueryDatastoreCompilationCache)nucleusCtx.getPluginManager().createExecutableExtension("org.datanucleus.cache_query_compilation_store",
"name", cacheType, "class-name", new Class[] {ClassConstants.NUCLEUS_CONTEXT}, new Object[] {nucleusCtx});
if (NucleusLogger.CACHE.isDebugEnabled())
{
// Class name for this Query cache plugin is not found!
throw new NucleusUserException(Localiser.msg("021501", cacheType, cacheClassName), e).setFatal();
NucleusLogger.CACHE.debug(Localiser.msg("021502", cacheClassName));
}
}
catch (Exception e)
{
// Class name for this Query cache plugin is not found!
throw new NucleusUserException(Localiser.msg("021501", cacheType, cacheClassName), e).setFatal();
}

// Instantiate the query results cache
// Query results cache
cacheType = conf.getStringProperty(PropertyNames.PROPERTY_CACHE_QUERYRESULTS_TYPE);
if (cacheType != null && !cacheType.equalsIgnoreCase("none"))
if (cacheType == null)
{
String cacheClassName = nucleusCtx.getPluginManager().getAttributeValueForExtension("org.datanucleus.cache_query_result", "name", cacheType, "class-name");
if (cacheClassName == null)
{
// Plugin of this name not found
throw new NucleusUserException(Localiser.msg("021500", cacheType)).setFatal();
}

try
{
// Create an instance of the Query Cache
queryResultsCache = (QueryResultsCache)nucleusCtx.getPluginManager().createExecutableExtension("org.datanucleus.cache_query_result",
"name", cacheType, "class-name", new Class[] {ClassConstants.NUCLEUS_CONTEXT}, new Object[] {nucleusCtx});
if (NucleusLogger.CACHE.isDebugEnabled())
{
NucleusLogger.CACHE.debug(Localiser.msg("021502", cacheClassName));
}
}
catch (Exception e)
cacheType = "soft";
}
cacheClassName = nucleusCtx.getPluginManager().getAttributeValueForExtension("org.datanucleus.cache_query_result", "name", cacheType, "class-name");
if (cacheClassName == null)
{
// Plugin of this name not found
throw new NucleusUserException(Localiser.msg("021500", cacheType)).setFatal();
}
try
{
// Create an instance of the Query Cache
queryResultsCache = (QueryResultsCache)nucleusCtx.getPluginManager().createExecutableExtension("org.datanucleus.cache_query_result",
"name", cacheType, "class-name", new Class[] {ClassConstants.NUCLEUS_CONTEXT}, new Object[] {nucleusCtx});
if (NucleusLogger.CACHE.isDebugEnabled())
{
// Class name for this Query cache plugin is not found!
throw new NucleusUserException(Localiser.msg("021501", cacheType, cacheClassName), e).setFatal();
NucleusLogger.CACHE.debug(Localiser.msg("021502", cacheClassName));
}
}
catch (Exception e)
{
// Class name for this Query cache plugin is not found!
throw new NucleusUserException(Localiser.msg("021501", cacheType, cacheClassName), e).setFatal();
}
}

/* (non-Javadoc)
Expand All @@ -173,17 +174,14 @@ public void close()
if (queryCompilationCache != null)
{
queryCompilationCache.close();
queryCompilationCache = null;
}
if (queryCompilationCacheDatastore != null)
{
queryCompilationCacheDatastore.close();
queryCompilationCacheDatastore = null;
}
if (queryResultsCache != null)
{
queryResultsCache.close();
queryResultsCache = null;
}

inmemoryQueryMethodEvaluatorMap.clear();
Expand Down
Expand Up @@ -15,10 +15,12 @@
Contributors:
...
**********************************************************************/
package org.datanucleus.query.compiler;
package org.datanucleus.store.query.cache;

import java.util.Map;

import org.datanucleus.query.compiler.QueryCompilation;

/**
* Abstract representation of a cache of generic query compilations.
*/
Expand Down
Expand Up @@ -15,7 +15,7 @@
Contributors:
...
**********************************************************************/
package org.datanucleus.query.compiler;
package org.datanucleus.store.query.cache;

import java.io.Serializable;

Expand All @@ -29,6 +29,7 @@

import org.datanucleus.NucleusContext;
import org.datanucleus.exceptions.NucleusException;
import org.datanucleus.query.compiler.QueryCompilation;
import org.datanucleus.util.NucleusLogger;

/**
Expand Down
Expand Up @@ -15,7 +15,9 @@
Contributors:
...
**********************************************************************/
package org.datanucleus.query.compiler;
package org.datanucleus.store.query.cache;

import org.datanucleus.query.compiler.QueryCompilation;

/**
* Cache for query compilations (generic).
Expand Down
Expand Up @@ -15,7 +15,7 @@
Contributors:
...
**********************************************************************/
package org.datanucleus.query.compiler;
package org.datanucleus.store.query.cache;

import org.datanucleus.NucleusContext;
import org.datanucleus.util.ConcurrentReferenceHashMap;
Expand Down
Expand Up @@ -15,7 +15,7 @@
Contributors:
...
**********************************************************************/
package org.datanucleus.query.compiler;
package org.datanucleus.store.query.cache;

import java.util.concurrent.ConcurrentHashMap;

Expand Down
Expand Up @@ -15,9 +15,10 @@
Contributors:
...
**********************************************************************/
package org.datanucleus.query.compiler;
package org.datanucleus.store.query.cache;

import org.datanucleus.NucleusContext;
import org.datanucleus.query.compiler.QueryCompilation;
import org.datanucleus.util.ConcurrentReferenceHashMap;
import org.datanucleus.util.ConcurrentReferenceHashMap.ReferenceType;

Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/plugin.xml
Expand Up @@ -374,10 +374,10 @@ Contributors:

<!-- QUERY COMPILATION CACHE (GENERIC) -->
<extension point="org.datanucleus.cache_query_compilation">
<cache name="soft" class-name="org.datanucleus.query.compiler.SoftQueryCompilationCache"/>
<cache name="weak" class-name="org.datanucleus.query.compiler.WeakQueryCompilationCache"/>
<cache name="strong" class-name="org.datanucleus.query.compiler.StrongQueryCompilationCache"/>
<cache name="javax.cache" class-name="org.datanucleus.query.compiler.JavaxCacheQueryCompilationCache"/>
<cache name="soft" class-name="org.datanucleus.store.query.cache.SoftQueryCompilationCache"/>
<cache name="weak" class-name="org.datanucleus.store.query.cache.WeakQueryCompilationCache"/>
<cache name="strong" class-name="org.datanucleus.store.query.cache.StrongQueryCompilationCache"/>
<cache name="javax.cache" class-name="org.datanucleus.store.query.cache.JavaxCacheQueryCompilationCache"/>
</extension>

<!-- QUERY COMPILATION CACHE (DATASTORE) -->
Expand Down

0 comments on commit 2fa9adb

Please sign in to comment.