Revision: 15831
http://datanucleus.svn.sourceforge.net/datanucleus/?rev=15831&view=rev
Author: andy_jefferson
Date: 2012-10-26 09:48:39 +0000 (Fri, 26 Oct 2012)
Log Message:
-----------
Add TODO for DN4 to subclass this with the persistence-related fields
Modified Paths:
--------------
platform/core/trunk/src/java/org/datanucleus/NucleusContext.java
Modified: platform/core/trunk/src/java/org/datanucleus/NucleusContext.java
===================================================================
--- platform/core/trunk/src/java/org/datanucleus/NucleusContext.java 2012-10-26 06:46:58 UTC (rev 15830)
+++ platform/core/trunk/src/java/org/datanucleus/NucleusContext.java 2012-10-26 09:48:39 UTC (rev 15831)
@@ -70,6 +70,8 @@
/**
* Representation of the context being run within DataNucleus. Provides a series of services and can be used
* by JDO persistence, JPA persistence, JDO enhancement, JPA enhancement, amongst other things,
+ * TODO For DataNucleus 4.0 create PersistenceContext which extends this and has all of the persistence-related
+ * fields (storeMgr, jca, txManager, jtaTxManager, etc) and remove "type" variable.
*/
public class NucleusContext /*implements Serializable*/
{
@@ -85,30 +87,30 @@
private final ContextType type;
- /** Manager for the datastore used by this PMF/EMF. */
- private transient StoreManager storeMgr = null;
-
- /** MetaDataManager for handling the MetaData for this PMF/EMF. */
- private MetaDataManager metaDataManager = null;
-
- /** Flag defining if this is running within the JDO JCA adaptor. */
- private boolean jca = false;
-
/** Configuration defining features of the persistence process. */
private final PersistenceConfiguration config;
/** Manager for Plug-ins. */
private final PluginManager pluginManager;
- /** ApiAdapter used by the context. **/
- private final ApiAdapter apiAdapter;
+ /** MetaDataManager for handling the MetaData for this PMF/EMF. */
+ private MetaDataManager metaDataManager = null;
/** Name of the class providing the ClassLoaderResolver. */
private final String classLoaderResolverClassName;
+ /** ApiAdapter used by the context. **/
+ private final ApiAdapter apiAdapter;
+
/** Manager for java types and SCO wrappers. */
private TypeManager typeManager;
+ /** Manager for the datastore used by this PMF/EMF. */
+ private transient StoreManager storeMgr = null;
+
+ /** Flag defining if this is running within the JDO JCA adaptor. */
+ private boolean jca = false;
+
/** Level 2 Cache, caching across ObjectManagers. */
private Level2Cache cache;
@@ -258,6 +260,141 @@
}
/**
+ * Accessor for the type of this context (persistence, enhancer etc).
+ * @return The type
+ */
+ public ContextType getType()
+ {
+ return type;
+ }
+
+ /**
+ * Accessor for the ApiAdapter
+ * @return the ApiAdapter
+ */
+ public ApiAdapter getApiAdapter()
+ {
+ return apiAdapter;
+ }
+
+ /**
+ * Accessor for the name of the API (JDO, JPA, etc).
+ * @return the api
+ */
+ public String getApiName()
+ {
+ return apiAdapter.getName();
+ }
+
+ /**
+ * Accessor for the persistence configuration.
+ * @return Returns the persistence configuration.
+ */
+ public PersistenceConfiguration getPersistenceConfiguration()
+ {
+ return config;
+ }
+
+ /**
+ * Accessor for the Plugin Manager
+ * @return the PluginManager
+ */
+ public PluginManager getPluginManager()
+ {
+ return pluginManager;
+ }
+
+ /**
+ * Accessor for the Meta-Data Manager.
+ * @return Returns the MetaDataManager.
+ */
+ public synchronized MetaDataManager getMetaDataManager()
+ {
+ if (metaDataManager == null)
+ {
+ String apiName = apiAdapter.getName();
+ try
+ {
+ metaDataManager = (MetaDataManager) getPluginManager().createExecutableExtension(
+ "org.datanucleus.metadata_manager", new String[]{"name"}, new String[]{apiName},
+ "class", new Class[] {ClassConstants.NUCLEUS_CONTEXT}, new Object[]{this});
+ }
+ catch (Exception e)
+ {
+ throw new NucleusException(LOCALISER.msg("008010", apiName, e.getMessage()), e);
+ }
+ if (metaDataManager == null)
+ {
+ throw new NucleusException(LOCALISER.msg("008009", apiName));
+ }
+ }
+
+ return metaDataManager;
+ }
+
+ /**
+ * Accessor for the Type Manager
+ * @return the TypeManager
+ */
+ public TypeManager getTypeManager()
+ {
+ if (typeManager == null)
+ {
+ this.typeManager = new TypeManager(apiAdapter, pluginManager, getClassLoaderResolver(null));
+ }
+ return typeManager;
+ }
+
+ /**
+ * Accessor for a ClassLoaderResolver to use in resolving classes.
+ * Caches the resolver for the specified primary loader, and hands it out if present.
+ * @param primaryLoader Loader to use as the primary loader (or null)
+ * @return The ClassLoader resolver
+ */
+ public ClassLoaderResolver getClassLoaderResolver(ClassLoader primaryLoader)
+ {
+ // Set the key we will refer to this loader by
+ String resolverName = config.getStringProperty(PropertyNames.PROPERTY_CLASSLOADER_RESOLVER_NAME);
+ String key = resolverName;
+ if (primaryLoader != null)
+ {
+ key += ":[" + StringUtils.toJVMIDString(primaryLoader) + "]";
+ }
+
+ if (classLoaderResolverMap == null)
+ {
+ classLoaderResolverMap = new HashMap<String, ClassLoaderResolver>();
+ }
+
+ ClassLoaderResolver clr = classLoaderResolverMap.get(key);
+ if (clr != null)
+ {
+ // Return the cached loader resolver
+ return clr;
+ }
+
+ // Create the ClassLoaderResolver of this type with this primary loader
+ try
+ {
+ clr = (ClassLoaderResolver)pluginManager.createExecutableExtension(
+ "org.datanucleus.classloader_resolver", "name", resolverName,
+ "class-name", new Class[] {ClassLoader.class}, new Object[] {primaryLoader});
+ clr.registerUserClassLoader((ClassLoader)config.getProperty(PropertyNames.PROPERTY_CLASSLOADER_PRIMARY));
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ throw new NucleusUserException(LOCALISER.msg("001002", classLoaderResolverClassName), cnfe).setFatal();
+ }
+ catch (Exception e)
+ {
+ throw new NucleusUserException(LOCALISER.msg("001003", classLoaderResolverClassName), e).setFatal();
+ }
+ classLoaderResolverMap.put(key, clr);
+
+ return clr;
+ }
+
+ /**
* Method to initialise the context for use.
* This creates the required StoreManager(s).
*/
@@ -551,64 +688,6 @@
}
/**
- * Accessor for the type of this context (persistence, enhancer etc).
- * @return The type
- */
- public ContextType getType()
- {
- return type;
- }
-
- /**
- * Accessor for the ApiAdapter
- * @return the ApiAdapter
- */
- public ApiAdapter getApiAdapter()
- {
- return apiAdapter;
- }
-
- /**
- * Accessor for the name of the API (JDO, JPA, etc).
- * @return the api
- */
- public String getApiName()
- {
- return apiAdapter.getName();
- }
-
- /**
- * Accessor for the persistence configuration.
- * @return Returns the persistence configuration.
- */
- public PersistenceConfiguration getPersistenceConfiguration()
- {
- return config;
- }
-
- /**
- * Accessor for the Plugin Manager
- * @return the PluginManager
- */
- public PluginManager getPluginManager()
- {
- return pluginManager;
- }
-
- /**
- * Accessor for the Type Manager
- * @return the TypeManager
- */
- public TypeManager getTypeManager()
- {
- if (typeManager == null)
- {
- this.typeManager = new TypeManager(apiAdapter, pluginManager, getClassLoaderResolver(null));
- }
- return typeManager;
- }
-
- /**
* Method to log the configuration of this context.
*/
protected void logConfiguration()
@@ -825,55 +904,6 @@
return statistics;
}
- /**
- * Accessor for a ClassLoaderResolver to use in resolving classes.
- * Caches the resolver for the specified primary loader, and hands it out if present.
- * @param primaryLoader Loader to use as the primary loader (or null)
- * @return The ClassLoader resolver
- */
- public ClassLoaderResolver getClassLoaderResolver(ClassLoader primaryLoader)
- {
- // Set the key we will refer to this loader by
- String resolverName = config.getStringProperty(PropertyNames.PROPERTY_CLASSLOADER_RESOLVER_NAME);
- String key = resolverName;
- if (primaryLoader != null)
- {
- key += ":[" + StringUtils.toJVMIDString(primaryLoader) + "]";
- }
-
- if (classLoaderResolverMap == null)
- {
- classLoaderResolverMap = new HashMap<String, ClassLoaderResolver>();
- }
-
- ClassLoaderResolver clr = classLoaderResolverMap.get(key);
- if (clr != null)
- {
- // Return the cached loader resolver
- return clr;
- }
-
- // Create the ClassLoaderResolver of this type with this primary loader
- try
- {
- clr = (ClassLoaderResolver)pluginManager.createExecutableExtension(
- "org.datanucleus.classloader_resolver", "name", resolverName,
- "class-name", new Class[] {ClassLoader.class}, new Object[] {primaryLoader});
- clr.registerUserClassLoader((ClassLoader)config.getProperty(PropertyNames.PROPERTY_CLASSLOADER_PRIMARY));
- }
- catch (ClassNotFoundException cnfe)
- {
- throw new NucleusUserException(LOCALISER.msg("001002", classLoaderResolverClassName), cnfe).setFatal();
- }
- catch (Exception e)
- {
- throw new NucleusUserException(LOCALISER.msg("001003", classLoaderResolverClassName), e).setFatal();
- }
- classLoaderResolverMap.put(key, clr);
-
- return clr;
- }
-
public synchronized ImplementationCreator getImplementationCreator()
{
if (implCreator == null)
@@ -884,34 +914,6 @@
}
/**
- * Accessor for the Meta-Data Manager.
- * @return Returns the MetaDataManager.
- */
- public synchronized MetaDataManager getMetaDataManager()
- {
- if (metaDataManager == null)
- {
- String apiName = apiAdapter.getName();
- try
- {
- metaDataManager = (MetaDataManager) getPluginManager().createExecutableExtension(
- "org.datanucleus.metadata_manager", new String[]{"name"}, new String[]{apiName},
- "class", new Class[] {ClassConstants.NUCLEUS_CONTEXT}, new Object[]{this});
- }
- catch (Exception e)
- {
- throw new NucleusException(LOCALISER.msg("008010", apiName, e.getMessage()), e);
- }
- if (metaDataManager == null)
- {
- throw new NucleusException(LOCALISER.msg("008009", apiName));
- }
- }
-
- return metaDataManager;
- }
-
- /**
* Accessor for the transaction manager.
* @return The transaction manager.
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|