From 42372cf6094fa8e32ad9dd31d1bc79a839f45ba4 Mon Sep 17 00:00:00 2001 From: Albert Lee Date: Thu, 29 Mar 2012 17:50:19 +0000 Subject: [PATCH] OPENJPA-2163 Simplify configuration: move SingletonLifecycleEventManager from property to Compatibility option. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1307018 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/openjpa/conf/Compatibility.java | 19 ++++++- .../openjpa/conf/OpenJPAConfiguration.java | 10 ---- .../conf/OpenJPAConfigurationImpl.java | 51 ++----------------- .../callbacks/TestMultiEmEntityListeners.java | 2 +- .../validation/TestValidationMode.java | 3 +- .../doc/manual/migration_considerations.xml | 2 +- .../src/doc/manual/ref_guide_conf.xml | 26 ---------- 7 files changed, 27 insertions(+), 86 deletions(-) diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java index 495804cc3..1ad8ed8a4 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java @@ -74,7 +74,7 @@ public class Compatibility { private boolean _useListAttributeForArrays = false; private boolean _metaFactoriesAreStrict = false; private boolean _resetFlushFlagForCascadePersist = true;//OPENJPA-2051 - + private boolean _singletonLifecycleEventManager = false; /** * Whether to require exact identity value types when creating object @@ -696,4 +696,21 @@ public class Compatibility { public void setResetFlushFlagForCascadePersist(boolean b){ _resetFlushFlagForCascadePersist = b; } + + /** + * Returns true if life cycle event manager is a singleton configuration. + */ + public boolean isSingletonLifecycleEventManager() { + return _singletonLifecycleEventManager; + } + + /** + * This property set whether each EntityManager has its own life cycle event manager. + By default, each EntityManager only fires events to the registered listeners to the entities + it manages. If the life cycle event manager is a singleton, events will be fired to listeners + registered to all instances of EntityManager in the same persistence unit. + */ + public void setSingletonLifecycleEventManager(boolean singleton) { + _singletonLifecycleEventManager = singleton; + } } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java index 30768cce9..99f82478b 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java @@ -1737,16 +1737,6 @@ public interface OpenJPAConfiguration */ public void setLifecycleEventManager(String eventMgr); - /** - * Returns if lifecycle event manager is a singlton configuration. - */ - public boolean isSingletonLifecycleEventManager(); - - /** - * Sets the lifecycle event manager singleton state. - */ - public void setSingletonLifecycleEventManager(boolean singleton); - /** * Gets the validation groups for pre-persist * diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java index 19b010281..d3a186c8f 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java @@ -167,8 +167,7 @@ public class OpenJPAConfigurationImpl public StringValue validationMode; public ObjectValue validationFactory; public ObjectValue validator; - public LEMValue lifecycleEventManager; - public SingletonLEMValue singletonLifecycleEventManager; + public ObjectValue lifecycleEventManager; public StringValue validationGroupPrePersist; public StringValue validationGroupPreUpdate; public StringValue validationGroupPreRemove; @@ -574,7 +573,7 @@ public class OpenJPAConfigurationImpl queryTimeout.setDefault("-1"); queryTimeout.setDynamic(true); - lifecycleEventManager = addValue(new LEMValue("LifecycleEventManager", false)); + lifecycleEventManager = addPlugin("LifecycleEventManager", true); aliases = new String[] { "default", LifecycleEventManager.class.getName(), "validating", ValidatingLifecycleEventManager.class.getName(), @@ -584,11 +583,6 @@ public class OpenJPAConfigurationImpl lifecycleEventManager.setString(aliases[0]); lifecycleEventManager.setInstantiatingGetter("getLifecycleEventManagerInstance"); - singletonLifecycleEventManager = (SingletonLEMValue) addValue(new SingletonLEMValue( - "SingletonLifecycleEventManager")); - singletonLifecycleEventManager.setDefault("false"); - singletonLifecycleEventManager.set(false); - dynamicEnhancementAgent = addBoolean("DynamicEnhancementAgent"); dynamicEnhancementAgent.setDefault("true"); dynamicEnhancementAgent.set(true); @@ -1754,9 +1748,9 @@ public class OpenJPAConfigurationImpl } public LifecycleEventManager getLifecycleEventManagerInstance() { - LifecycleEventManager lem = (LifecycleEventManager) - lifecycleEventManager.get(); - if (lem == null) { + LifecycleEventManager lem = null; + if (!getCompatibilityInstance().isSingletonLifecycleEventManager() || + (lem = (LifecycleEventManager)lifecycleEventManager.get()) == null) { lem = (LifecycleEventManager)lifecycleEventManager .instantiate(LifecycleEventManager.class, this); } @@ -1777,41 +1771,6 @@ public class OpenJPAConfigurationImpl } } - class LEMValue extends PluginValue { - boolean singleton; - - public LEMValue(String prop, boolean singleton) { - super(prop, true); - this.singleton = singleton; - } - - public Object get() { - return this.singleton ? super.get() : null; - } - } - - public boolean isSingletonLifecycleEventManager() { - return singletonLifecycleEventManager.get(); - } - - public void setSingletonLifecycleEventManager(boolean singleton) { - singletonLifecycleEventManager.set(singleton); - } - - class SingletonLEMValue extends BooleanValue { - - public SingletonLEMValue(String prop) { - super(prop); - } - - public void set(boolean value) { - super.set(value); - if (value && !lifecycleEventManager.singleton) { - lifecycleEventManager.singleton = true; - } - } - } - public boolean getDynamicEnhancementAgent() { return dynamicEnhancementAgent.get(); } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestMultiEmEntityListeners.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestMultiEmEntityListeners.java index ee59209b8..29fc7eead 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestMultiEmEntityListeners.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestMultiEmEntityListeners.java @@ -26,7 +26,7 @@ public class TestMultiEmEntityListeners extends SingleEMFTestCase { public void setUp() { setUp(CLEAR_TABLES, ListenerInEntity.class, AddListenerEntity.class -// , "openjpa.SingletonLifecycleEventManager", "true" +// , "openjpa.Compatibility", "SingletonLifecycleEventManager=true" ); } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationMode.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationMode.java index b17e0e04c..783be5c83 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationMode.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationMode.java @@ -258,7 +258,8 @@ public class TestValidationMode extends SingleEMFTestCase { // create our EMF Map prop = new HashMap(); prop.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); -// prop.put("openjpa.SingletonLifecycleEventManager", "true"); +// prop.put("openjpa.Compatibility", "SingletonLifecycleEventManager=true"); + OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.createEntityManagerFactory( "simple", diff --git a/openjpa-project/src/doc/manual/migration_considerations.xml b/openjpa-project/src/doc/manual/migration_considerations.xml index a093772be..69f74a633 100644 --- a/openjpa-project/src/doc/manual/migration_considerations.xml +++ b/openjpa-project/src/doc/manual/migration_considerations.xml @@ -426,7 +426,7 @@ Regenerate the canonical metamodel classes - Set the Compatibility property UseListAttributeForArrays to truein persistence.xml + Set the Compatibility property UseListAttributeForArrays to true in persistence.xml <property name="openjpa.Compatibility" value="UseListAttributeForArrays=true"/> diff --git a/openjpa-project/src/doc/manual/ref_guide_conf.xml b/openjpa-project/src/doc/manual/ref_guide_conf.xml index 2db51d865..04dea67bb 100644 --- a/openjpa-project/src/doc/manual/ref_guide_conf.xml +++ b/openjpa-project/src/doc/manual/ref_guide_conf.xml @@ -3279,32 +3279,6 @@ system sequence. See for more information. -
- openjpa.SingletonLifecycleEventManager - - Property name: - openjpa.SingletonLifecycleEventManager - - - Configuration API: - org.apache.openjpa.conf.OpenJPAConfiguration.isSingletonLifecycleEventManager - - - Resource adaptor config property: - SingletonLifecycleEventManager - - - Default: - false - - - Description: - This property controls whether each EntityManager has its own life cycle event manager. - By default, each EntityManager only fires events to the registered listeners to the entities - it manages. If the life cycle event manager is a singleton, events will be fired to listeners - registered to all instances of EntityManager in the same persistence unit. - -
openjpa.Specification