[dna-commits] DNA SVN: r1503 - in trunk: dna-graph/src/main/java/org/jboss/dna/graph/connector and 3 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Thu Dec 31 09:08:13 EST 2009


Author: bcarothers
Date: 2009-12-31 09:08:13 -0500 (Thu, 31 Dec 2009)
New Revision: 1503

Modified:
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositoryConnectionPool.java
   trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties
   trunk/dna-graph/src/test/java/org/jboss/dna/graph/query/optimize/RuleBasedOptimizerTest.java
   trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/model/simple/SimpleJpaConnection.java
Log:
DNA-608 RepositoryConnectionPool.ConnectionWrapper.close Closes the Underlying Connection

A\
"
''['{\
]
.kvuio[u8-98ghn09nt changes the\
 ConnectionWrapper close behavior to not attempt to close the underlying connection. This allowed a graph message to be retired and forced compensating changes in SimpleJpaConnector.

Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java	2009-12-31 13:47:17 UTC (rev 1502)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java	2009-12-31 14:08:13 UTC (rev 1503)
@@ -33,7 +33,6 @@
  */
 public final class GraphI18n {
 
-    public static I18n closedConnectionMayNotBeUsed;
     public static I18n errorConvertingIo;
     public static I18n errorConvertingType;
     public static I18n errorReadingPropertyValueBytes;

Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositoryConnectionPool.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositoryConnectionPool.java	2009-12-31 13:47:17 UTC (rev 1502)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositoryConnectionPool.java	2009-12-31 14:08:13 UTC (rev 1503)
@@ -779,8 +779,10 @@
             mainLock.lock();
             // Remove the connection from the in-use set ...
             boolean removed = this.inUseConnections.remove(wrapper);
-            assert removed;
 
+            // This means that the wrapper was already closed at least once since the last time it was opened
+            if (!removed) return;
+
             // If we're shutting down the pool, then just close the connection ...
             if (this.runState != RUNNING) {
                 wrapperToClose = wrapper;
@@ -932,7 +934,6 @@
         private final RepositoryConnection original;
         private final long timeCreated;
         private long lastUsed;
-        private boolean closed = false;
 
         protected ConnectionWrapper( RepositoryConnection connection ) {
             assert connection != null;
@@ -972,7 +973,6 @@
          * {@inheritDoc}
          */
         public XAResource getXAResource() {
-            if (closed) throw new IllegalStateException(GraphI18n.closedConnectionMayNotBeUsed.text());
             return this.original.getXAResource();
         }
 
@@ -980,7 +980,6 @@
          * {@inheritDoc}
          */
         public CachePolicy getDefaultCachePolicy() {
-            if (closed) throw new IllegalStateException(GraphI18n.closedConnectionMayNotBeUsed.text());
             return this.original.getDefaultCachePolicy();
         }
 
@@ -992,7 +991,6 @@
          */
         public void execute( ExecutionContext context,
                              Request request ) throws RepositorySourceException {
-            if (closed) throw new IllegalStateException(GraphI18n.closedConnectionMayNotBeUsed.text());
             this.original.execute(context, request);
         }
 
@@ -1001,7 +999,6 @@
          */
         public boolean ping( long time,
                              TimeUnit unit ) throws InterruptedException {
-            if (closed) throw new IllegalStateException(GraphI18n.closedConnectionMayNotBeUsed.text());
             return this.original.ping(time, unit);
         }
 
@@ -1009,12 +1006,8 @@
          * {@inheritDoc}
          */
         public void close() {
-            if (!closed) {
-                this.lastUsed = System.currentTimeMillis();
-                this.original.close();
-                this.closed = true;
-                returnConnection(this);
-            }
+            this.lastUsed = System.currentTimeMillis();
+            returnConnection(this);
         }
     }
 

Modified: trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties
===================================================================
--- trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties	2009-12-31 13:47:17 UTC (rev 1502)
+++ trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties	2009-12-31 14:08:13 UTC (rev 1503)
@@ -21,7 +21,6 @@
 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 #
-closedConnectionMayNotBeUsed = The connection has been closed an may not be used
 errorConvertingIo = Error converting {0} to a {1}
 errorConvertingType = Error converting {0} to a {1}: {2}
 errorReadingPropertyValueBytes = Error reading bytes

Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/query/optimize/RuleBasedOptimizerTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/query/optimize/RuleBasedOptimizerTest.java	2009-12-31 13:47:17 UTC (rev 1502)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/query/optimize/RuleBasedOptimizerTest.java	2009-12-31 14:08:13 UTC (rev 1503)
@@ -68,7 +68,7 @@
     private List<Integer> ruleExecutionOrder;
     private QueryContext context;
     private PlanNode node;
-    private boolean print = false;
+    private final boolean print = false;
 
     @Before
     public void beforeEach() {
@@ -139,7 +139,7 @@
             public PlanNode execute( QueryContext context,
                                      PlanNode plan,
                                      LinkedList<OptimizerRule> ruleStack ) {
-                context.getProblems().addError(GraphI18n.closedConnectionMayNotBeUsed);
+                context.getProblems().addError(GraphI18n.errorReadingPropertyValueBytes);
                 return plan;
             }
         });

Modified: trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/model/simple/SimpleJpaConnection.java
===================================================================
--- trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/model/simple/SimpleJpaConnection.java	2009-12-31 13:47:17 UTC (rev 1502)
+++ trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/model/simple/SimpleJpaConnection.java	2009-12-31 14:08:13 UTC (rev 1503)
@@ -45,24 +45,20 @@
 @NotThreadSafe
 public class SimpleJpaConnection implements RepositoryConnection {
 
-    private final SimpleJpaRepository repository;
+    private SimpleJpaRepository repository;
     private final JpaSource source;
     private EntityManager entityManager;
 
     public SimpleJpaConnection( JpaSource source ) {
         this.source = source;
 
-        this.entityManager = source.getEntityManagers().checkout();
-        this.entityManager.getTransaction().begin();
-        this.repository = new SimpleJpaRepository(source.getName(), source.getRootUuid(), source.getDefaultWorkspaceName(),
-                                                  source.getPredefinedWorkspaceNames(), entityManager,
-                                                  source.getRepositoryContext().getExecutionContext(), source.isCompressData(),
-                                                  source.isCreatingWorkspacesAllowed(), source.getLargeValueSizeInBytes());
     }
 
     public boolean ping( long time,
                          TimeUnit unit ) {
-        return entityManager != null && entityManager.isOpen();
+        // Most pings will occur before or after an execute() call, when there is no entityManger
+        // If there is no entity manager, the connection is still valid!
+        return entityManager == null || entityManager.isOpen();
     }
 
     public CachePolicy getDefaultCachePolicy() {
@@ -77,7 +73,18 @@
         return null;
     }
 
-    public void close() {
+    private void acquireRepository() {
+        this.entityManager = source.getEntityManagers().checkout();
+        this.entityManager.getTransaction().begin();
+        this.repository = new SimpleJpaRepository(source.getName(), source.getRootUuid(), source.getDefaultWorkspaceName(),
+                                                  source.getPredefinedWorkspaceNames(), entityManager,
+                                                  source.getRepositoryContext().getExecutionContext(), source.isCompressData(),
+                                                  source.isCreatingWorkspacesAllowed(), source.getLargeValueSizeInBytes());
+
+    }
+
+    private void releaseRepository() {
+        this.repository = null;
         if (entityManager != null) {
             try {
                 source.getEntityManagers().checkin(entityManager);
@@ -85,8 +92,12 @@
                 entityManager = null;
             }
         }
+
     }
 
+    public void close() {
+    }
+
     /**
      * {@inheritDoc}
      * 
@@ -101,6 +112,9 @@
             sw = new Stopwatch();
             sw.start();
         }
+
+        acquireRepository();
+
         // Do any commands update/write?
         Observer observer = this.source.getRepositoryContext().getObserver();
         RequestProcessor processor = new SimpleRequestProcessor(context, this.repository, observer, source.areUpdatesAllowed());
@@ -139,6 +153,9 @@
                 }
             }
         }
+
+        releaseRepository();
+
         if (logger.isTraceEnabled()) {
             assert sw != null;
             sw.stop();



More information about the dna-commits mailing list