You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by cu...@apache.org on 2009/10/21 00:10:11 UTC
svn commit: r827819 - in /openjpa/sandboxes/perf:
openjpa-kernel/src/main/java/org/apache/openjpa/meta/
openjpa-kernel/src/main/resources/org/apache/openjpa/meta/
openjpa-persistence/src/main/java/org/apache/openjpa/persistence/
Author: curtisr7
Date: Tue Oct 20 22:10:10 2009
New Revision: 827819
URL: http://svn.apache.org/viewvc?rev=827819&view=rev
Log:
OPENJPA-250: updated configuration properties to line up with 1.0.x changes.
Modified:
openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
openjpa/sandboxes/perf/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
openjpa/sandboxes/perf/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
Modified: openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java?rev=827819&r1=827818&r2=827819&view=diff
==============================================================================
--- openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java (original)
+++ openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java Tue Oct 20 22:10:10 2009
@@ -49,6 +49,7 @@
import org.apache.openjpa.lib.util.J2DoPrivHelper;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.MultiClassLoader;
+import org.apache.openjpa.lib.util.Options;
import org.apache.openjpa.lib.util.StringDistance;
import org.apache.openjpa.util.ImplHelper;
import org.apache.openjpa.util.InternalException;
@@ -153,8 +154,13 @@
new LifecycleEventManager.ListenerList(3);
private ReentrantLock _lock = null;
- protected boolean _preload = false;
+ // If true, all configured persistent classes will be eagerly loaded.
+ protected boolean _eagerPersistentTypes = false;
+ protected boolean _eagerPersistentMetaData = false;
protected boolean _noLock = false;
+
+ private static final String EAGER_PERSISTENT_TYPES = "EagerPersistentTypes";
+ private static final String EAGER_PERSISTENT_META_DATA = "EagerPersistentMetaData";
/**
* Default constructor. Configure via {@link Configurable}.
@@ -282,18 +288,51 @@
_sourceMode &= ~mode;
}
- public void setPreload(boolean l) {
- _preload = l;
+ /**
+ * Sets whether this repository will load all known persistent classes at initialization.
+ * Defaults to false.
+ */
+ public void setEagerPersistentTypes(boolean b) {
+ _eagerPersistentTypes = b;
}
- public void setNoLock(boolean l) {
- _noLock = l;
+
+ /**
+ * Sets whether this repository will load all known persistent classes at initialization.
+ * Defaults to false.
+ */
+ public boolean getEagerPersistentTypes() {
+ return _eagerPersistentTypes;
}
+ /**
+ * Sets whether this repository will load all MetaData for all known persistent classes at initialization.
+ * Defaults to false.
+ */
+ public void setEagerPersistentMetaData(boolean b) {
+ _eagerPersistentMetaData = b;
+ }
+
+ /**
+ * Sets whether this repository will load all MetaData for all known persistent classes at initialization.
+ * Defaults to false.
+ */
+ public boolean getEagerPersistentMetaData() {
+ return _eagerPersistentMetaData;
+ }
+ public void setNoLock(boolean b){
+ _noLock = b;
+ }
+ public boolean getNoLock(){
+ return _noLock;
+ }
/**
- * If the openjpa.MetaDataRepository plugin value preload=false is set, this method will noop. If
- * preload=true this method gets the list of persistent classes and calls to the MetaDataFactory
- * to load ALL metadata.
+ * If the openjpa.MetaDataRepository plugin value EagerPersistentMetaData=false and
+ * EagerPersistentTypes=false , this method will noop. If EagerPersistentTypes=true this method
+ * gets the list of persistent classes and loads them (Class.forName(..)). If EagerPersistentMetaData=true, this
+ * method will load all persistent classes and ALL MetaData for those persistent classes.
+ * <p>
+ * EagerPersistentMetaData=true implies EagerPersistentTypes=true.
* <p>
*
* If noLock=true, calling this method will also remove ALL locking from this class.
@@ -302,15 +341,18 @@
* NOTE : This method is not thread safe and should ONLY be called by the AbstractBrokerFactory
* constructor.
*/
- public void preload() {
- if (_preload == false) {
+ public void initializeEager() {
+ if (_eagerPersistentMetaData == false && _eagerPersistentTypes == false) {
return;
}
+
if (_log.isTraceEnabled()) {
- _log.trace("MetaDataRepository preload="+_preload+",noLock="+_noLock);
+ _log.trace("MetaDataRepository NoLock=" + _noLock + ", EagerPersistentTypes=" + _eagerPersistentTypes
+ + ", EagerPersistentMetaData=" + _eagerPersistentMetaData);
}
- // Remove locking and use unsynchronized maps.
- if (_noLock == true) {
+
+ // Remove locking and use unsynchronized maps if we're loading all MetaData
+ if (_noLock == true && _eagerPersistentMetaData == true) {
_oids = new HashMap();
_impls = new HashMap();
_ifaces = new HashMap();
@@ -320,44 +362,37 @@
_subs = new HashMap();
_lock = null;
}
-
- MultiClassLoader multi =
- AccessController.doPrivileged(J2DoPrivHelper.newMultiClassLoaderAction());
- multi.addClassLoader(AccessController.doPrivileged(J2DoPrivHelper
- .getContextClassLoaderAction()));
+
+ MultiClassLoader multi = AccessController.doPrivileged(J2DoPrivHelper.newMultiClassLoaderAction());
+ multi.addClassLoader(AccessController.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction()));
multi.addClassLoader(AccessController.doPrivileged(J2DoPrivHelper
.getClassLoaderAction(MetaDataRepository.class)));
Set<String> classes = getPersistentTypeNames(false, multi);
if (classes == null || classes.size() == 0) {
- throw new RuntimeException(
- "No persistent classes listed when trying to preload the MetaDataRepository");
+ throw new MetaDataException(_loc.get("repos-initializeEager-none"));
}
if (_log.isTraceEnabled() == true) {
- _log.trace(MetaDataRepository.class.getName() + " preloading the following classes : "
- + classes.toString());
+ _log
+ .trace(MetaDataRepository.class.getName() + " found the following classes : " + classes.toString());
}
for (String c : classes) {
try {
- Class<?> cls =
- AccessController
- .doPrivileged((J2DoPrivHelper.getForNameAction(c, true, multi)));
- // TODO -- need to test this
-// resolveAll(multi);
-// // Load query metadata
-// _factory.load(cls, MODE_QUERY, multi);
- _factory.load(cls, MODE_ALL, multi);
- } catch (PrivilegedActionException pae) {
- // Unexpected!
- if (_log.isTraceEnabled() == true) {
- _log.trace(MetaDataRepository.class.getName()
- + " encountered an unexpected exception ", pae);
+ Class<?> cls = AccessController.doPrivileged((J2DoPrivHelper.getForNameAction(c, true, multi)));
+ if (_eagerPersistentMetaData == true) {
+ // TODO -- need to test this
+ // resolveAll(multi);
+ // // Load query metadata
+ // _factory.load(cls, MODE_QUERY, multi);
+ _factory.load(cls, MODE_ALL, multi);
}
+ } catch (PrivilegedActionException pae) {
+ throw new MetaDataException(_loc.get("repos-initializeEager-error"), pae);
}
}// end for
-
- // Hook this class in early so we can process registered classes and add them
+
+ // Hook this class in early so we can process registered classes and add them
// to _aliases list.
PCRegistry.addRegisterClassListener(this);
processRegisteredClasses(multi);
@@ -2259,4 +2294,16 @@
public XMLFieldMetaData newXMLFieldMetaData(Class type, String name) {
return new XMLFieldMetaData(type, name);
}
+
+ /**
+ * This helper method returns true if Options paramater has the property EagerPersistentTypes or
+ * EagerPersistentMetaData set to true.
+ */
+ public static boolean needsInitializeEager(Options o) {
+ if (o.getBooleanProperty(EAGER_PERSISTENT_TYPES) == true
+ || o.getBooleanProperty(EAGER_PERSISTENT_META_DATA) == true) {
+ return true;
+ }
+ return false;
+ }
}
Modified: openjpa/sandboxes/perf/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/perf/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties?rev=827819&r1=827818&r2=827819&view=diff
==============================================================================
--- openjpa/sandboxes/perf/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties (original)
+++ openjpa/sandboxes/perf/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties Tue Oct 20 22:10:10 2009
@@ -321,3 +321,8 @@
a jar file, this may be caused by one or more inherited class of the \
entity not being packaged in the same jar file. Please check all \
inherited class(es) are packaged in the same jar file.
+repos-initializeEager-none: No persistent metadata found for loading during initialization. \
+ The persistent classes must be enlisted in configuration to be loaded during initialization.
+repos-initializeEager-error: Unexpected error during early loading during initialization. \
+ See nested stacktrace for details.
+
Modified: openjpa/sandboxes/perf/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/perf/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java?rev=827819&r1=827818&r2=827819&view=diff
==============================================================================
--- openjpa/sandboxes/perf/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java (original)
+++ openjpa/sandboxes/perf/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java Tue Oct 20 22:10:10 2009
@@ -83,15 +83,15 @@
BrokerFactory factory = getBrokerFactory(cp, poolValue, null);
- // We need to wait to preload until after we get back a fully configured/instantiated
+ // We need to wait to initializeEager until after we get back a fully configured/instantiated
// BrokerFactory. This is because it is possible that someone has extended OpenJPA
// functions and they need to be allowed time to configure themselves before we go off and
// start instanting configurable objects (ie:openjpa.MetaDataRepository). Don't catch
// any exceptions here because we want to fail-fast.
OpenJPAConfiguration conf = factory.getConfiguration();
Options o = Configurations.parseProperties(Configurations.getProperties(conf.getMetaDataRepository()));
- if(o.getBooleanProperty("Preload")){
- conf.getMetaDataRepositoryInstance().preload();
+ if(MetaDataRepository.needsInitializeEager(o) == true){
+ conf.getMetaDataRepositoryInstance().initializeEager();
}
return JPAFacadeHelper.toEntityManagerFactory(factory);
@@ -168,15 +168,15 @@
_loc.get("transformer-registration-error", pui));
}
}
- // We need to wait to preload until after we get back a fully configured/instantiated
+ // We need to wait to initializeEager until after we get back a fully configured/instantiated
// BrokerFactory. This is because it is possible that someone has extended OpenJPA
// functions and they need to be allowed time to configure themselves before we go off and
// start instanting configurable objects (ie:openjpa.MetaDataRepository). Don't catch
// any exceptions here because we want to fail-fast.
OpenJPAConfiguration conf = factory.getConfiguration();
Options o = Configurations.parseProperties(Configurations.getProperties(conf.getMetaDataRepository()));
- if(o.getBooleanProperty("Preload")){
- conf.getMetaDataRepositoryInstance().preload();
+ if(MetaDataRepository.needsInitializeEager(o) == true){
+ conf.getMetaDataRepositoryInstance().initializeEager();
}
return JPAFacadeHelper.toEntityManagerFactory(factory);