openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r1045397 - in /openjpa/trunk: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/log/ openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/
Date Mon, 13 Dec 2010 22:32:20 GMT
Author: mikedd
Date: Mon Dec 13 22:32:20 2010
New Revision: 1045397

URL: http://svn.apache.org/viewvc?rev=1045397&view=rev
Log:
OPENNJPA-1906 adding warning when connection retain mode is used with container managed EMFs

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/log/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/log/TestConnectionRetainModeWarning.java
  (with props)
Modified:
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
    openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/log/TestConnectionRetainModeWarning.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/log/TestConnectionRetainModeWarning.java?rev=1045397&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/log/TestConnectionRetainModeWarning.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/log/TestConnectionRetainModeWarning.java
Mon Dec 13 22:32:20 2010
@@ -0,0 +1,112 @@
+/*
+ * 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.persistence.log;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.EntityManagerFactory;
+
+import org.apache.openjpa.lib.log.AbstractLog;
+import org.apache.openjpa.lib.log.Log;
+import org.apache.openjpa.lib.log.LogFactory;
+import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.persistence.PersistenceProviderImpl;
+import org.apache.openjpa.persistence.test.AbstractPersistenceTestCase;
+
+public class TestConnectionRetainModeWarning extends AbstractPersistenceTestCase implements
LogFactory {
+    private static List<String> messages = new ArrayList<String>();
+
+    Localizer _loc = Localizer.forPackage(PersistenceProviderImpl.class);
+
+    public void tearDown() throws Exception {
+        super.tearDown();
+        messages.clear();
+    }
+
+    // Start LogFactory implementation
+    public Log getLog(String channel) {
+        return new AbstractLog() {
+
+            protected boolean isEnabled(short logLevel) {
+                return true;
+            }
+
+            @Override
+            public void trace(Object message) {
+                messages.add(message.toString());
+            }
+
+            protected void log(short type, String message, Throwable t) {
+                messages.add(message);
+            }
+
+            @Override
+            public void error(Object message) {
+                messages.add(message.toString());
+            }
+
+            @Override
+            public void warn(Object message) {
+                super.warn(message.toString());
+            }
+
+            @Override
+            public void info(Object message) {
+                messages.add(message.toString());
+            }
+        };
+    }
+
+    public void assertMessageContains(String s) {
+        for (String message : messages) {
+            if (message.contains(s)) {
+                return;
+            }
+        }
+        fail("Did not find message " + s + " in " + messages);
+    }
+
+    public void assertMessageNotFound(String s) {
+        for (String message : messages) {
+            if (message.contains(s)) {
+                fail("Found unexpected messsage " + s);
+            }
+        }
+    }
+
+    public void testInfoMessage() {
+        EntityManagerFactory emf =
+            createEMF("openjpa.Log", this.getClass().getCanonicalName(), "openjpa.ConnectionRetainMode",
"always");
+
+        assertNotNull(emf);
+        assertMessageContains(_loc.get("retain-always", getPersistenceUnitName()).toString());
+        emf.close();
+    }
+
+    public void testInfoMessageNotFound() {
+        EntityManagerFactory emf =
+            createEMF("openjpa.Log", this.getClass().getCanonicalName(), "openjpa.ConnectionRetainMode",
"on-demand");
+
+        assertNotNull(emf);
+        assertMessageNotFound(_loc.get("retain-always", getPersistenceUnitName()).toString());
+        emf.close();
+    }
+
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/log/TestConnectionRetainModeWarning.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java?rev=1045397&r1=1045396&r2=1045397&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
Mon Dec 13 22:32:20 2010
@@ -40,6 +40,7 @@ import org.apache.openjpa.enhance.PCEnha
 import org.apache.openjpa.kernel.AbstractBrokerFactory;
 import org.apache.openjpa.kernel.Bootstrap;
 import org.apache.openjpa.kernel.BrokerFactory;
+import org.apache.openjpa.kernel.ConnectionRetainModes;
 import org.apache.openjpa.lib.conf.Configuration;
 import org.apache.openjpa.lib.conf.ConfigurationProvider;
 import org.apache.openjpa.lib.conf.Configurations;
@@ -102,6 +103,11 @@ public class PersistenceProviderImpl
             // Create appropriate LifecycleEventManager
             loadValidator(factory);
             
+            if (conf.getConnectionRetainModeConstant() == ConnectionRetainModes.CONN_RETAIN_ALWAYS)
{
+                // warn about EMs holding on to connections.
+                _log.warn(_loc.get("retain-always", conf.getId()));
+            }
+            
             OpenJPAEntityManagerFactory emf = JPAFacadeHelper.toEntityManagerFactory(factory);
             if (_log.isTraceEnabled()) {
                 _log.trace(this + " creating " + emf + " for PU " + name + ".");
@@ -196,6 +202,11 @@ public class PersistenceProviderImpl
                     _log.warn(_loc.get("transformer-registration-error", pui));
                 }
             }
+            
+            if (conf.getConnectionRetainModeConstant() == ConnectionRetainModes.CONN_RETAIN_ALWAYS)
{
+                // warn about container managed EMs holding on to connections.
+                _log.warn(_loc.get("cm-retain-always",conf.getId()));
+            }
 
             // Create appropriate LifecycleEventManager
             loadValidator(factory);

Modified: openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties?rev=1045397&r1=1045396&r2=1045397&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
Mon Dec 13 22:32:20 2010
@@ -244,3 +244,11 @@ invalid-cfname-prop: The "{0}" configura
 invalid-persistence-property: The property "{0}={1}" was detected while loading configuration.
However, it is invalid \
 and cannot be configured at the provider level, so it is ignored. Please consult the documentation
for the correct \
 usage of this property.
+retain-always: The persistence property 'openjpa.ConnectionRetainMode' is set to 'always'
for PersistenceUnit \
+'{0}'. Each EntityManager created for this PersistenceUnit will open a single connection.
The connection will not be \
+released until the EntityManager is closed. 
+cm-retain-always: The persistence property 'openjpa.ConnectionRetainMode' is set to 'always'
for the container \
+managed PersistenceUnit '{0}'. Each EntityManager created for this PersistenceUnit will open
a single connection. The \
+connection will not be released until the EntityManager is closed. If the application uses
container managed \
+EntityManagers this property should not be used because these EntityManagers may remain open
for extended periods of \
+time.



Mime
View raw message