openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1084349 - in /openjpa/trunk: openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestEagerInit.java openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
Date Tue, 22 Mar 2011 20:50:22 GMT
Author: curtisr7
Date: Tue Mar 22 20:50:21 2011
New Revision: 1084349

URL: http://svn.apache.org/viewvc?rev=1084349&view=rev
Log:
OPENJPA-1960: Allow openjpa.InitializeEagerly to be used with BV.

Added:
    openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestEagerInit.java
  (with props)
Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java

Added: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestEagerInit.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestEagerInit.java?rev=1084349&view=auto
==============================================================================
--- openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestEagerInit.java
(added)
+++ openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestEagerInit.java
Tue Mar 22 20:50:21 2011
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.integration.validation;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.test.AbstractPersistenceTestCase;
+
+public class TestEagerInit extends AbstractPersistenceTestCase {
+    OpenJPAEntityManagerFactorySPI _emf;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        Map<String, String> props = new HashMap<String, String>();
+        props.put("openjpa.InitializeEagerly", "true");
+        _emf =
+            (OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.createEntityManagerFactory("simple-callback-mode",
+                "org/apache/openjpa/integration/validation/persistence.xml", props);
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        // TODO Auto-generated method stub
+        super.tearDown();
+        _emf.close();
+    }
+
+    public void testNonNullEmf() {
+        assertNotNull(_emf);
+    }
+}

Propchange: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestEagerInit.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java?rev=1084349&r1=1084348&r2=1084349&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
Tue Mar 22 20:50:21 2011
@@ -183,7 +183,7 @@ public class OpenJPAConfigurationImpl
     private final StoreFacadeTypeRegistry _storeFacadeRegistry = new StoreFacadeTypeRegistry();
     private BrokerFactoryEventManager _brokerFactoryEventManager = new BrokerFactoryEventManager(this);
     private Map<String, Object> _peMap; //contains persistence environment-specific
info    
-
+    private boolean _allowSetLifeCycleEventManager = true;
     /**
      * Default constructor. Attempts to load global properties.
      */
@@ -1739,7 +1739,17 @@ public class OpenJPAConfigurationImpl
     }
 
     public void setLifecycleEventManager(String lem) {
-        lifecycleEventManager.setString(lem);
+        if (_allowSetLifeCycleEventManager) {
+            _allowSetLifeCycleEventManager = false;
+            // Only allow this to be called once even if the configuration is frozen. This
can happen if a configuration
+            // is eagerly initialized and validation is being used.
+            lifecycleEventManager.setDynamic(true);
+            lifecycleEventManager.setString(lem);
+            lifecycleEventManager.setDynamic(false);
+        } else {
+            // If the configuration is frozen this will result in a warning message and/or
an exception.
+            lifecycleEventManager.setString(lem);
+        }
     }
 
     public boolean getDynamicEnhancementAgent() {



Mime
View raw message