jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1039064 - in /jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca: JCAManagedConnection.java JCAManagedConnectionFactory.java JCARepositoryHandle.java
Date Thu, 25 Nov 2010 14:38:27 GMT
Author: jukka
Date: Thu Nov 25 14:38:27 2010
New Revision: 1039064

URL: http://svn.apache.org/viewvc?rev=1039064&view=rev
Log:
JCR-2523: StaleItemStateException during distributed transaction

Discard the old JCR session when reusing a JCAManagedConnection instance in a JCA connection
pool.
This prevents things like custom namespace mappings or uncleared cache data from persisting
between connections returned from the pool.

Modified:
    jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnection.java
    jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnectionFactory.java
    jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCARepositoryHandle.java

Modified: jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnection.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnection.java?rev=1039064&r1=1039063&r2=1039064&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnection.java
(original)
+++ jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnection.java
Thu Nov 25 14:38:27 2010
@@ -52,7 +52,7 @@ public final class JCAManagedConnection
     /**
      * Session instance.
      */
-    private final Session session;
+    private Session session;
 
     /**
      * XAResource instance.
@@ -78,11 +78,11 @@ public final class JCAManagedConnection
      * Construct the managed connection.
      */
     public JCAManagedConnection(
-            JCAManagedConnectionFactory mcf, JCAConnectionRequestInfo cri,
-            Session session) {
+            JCAManagedConnectionFactory mcf, JCAConnectionRequestInfo cri)
+            throws ResourceException {
         this.mcf = mcf;
         this.cri = cri;
-        this.session = session;
+        this.session = openSession();
         this.listeners = new LinkedList<ConnectionEventListener>();
         this.handles = new LinkedList<JCASessionHandle>();
         if (this.mcf.getBindSessionToTransaction().booleanValue()) {
@@ -93,10 +93,22 @@ public final class JCAManagedConnection
     }
 
     /**
-     * Return the repository.
+     * Create a new session.
      */
-    private Repository getRepository() {
-        return mcf.getRepository();
+    @SuppressWarnings("deprecation")
+    private Session openSession() throws ResourceException {
+        try {
+            Session session = mcf.getRepository().login(
+                    cri.getCredentials(), cri.getWorkspace());
+            log("Created session (" + session + ")");
+            return session;
+        } catch (RepositoryException e) {
+            log("Failed to create session", e);
+            ResourceException exception = new ResourceException(
+                    "Failed to create session: " + e.getMessage());
+            exception.setLinkedException(e);
+            throw exception;
+        }
     }
 
     /**
@@ -155,14 +167,8 @@ public final class JCAManagedConnection
     public void cleanup()
             throws ResourceException {
         synchronized (handles) {
-            try {
-                this.session.refresh(false);
-            } catch (RepositoryException e) {
-                ResourceException exception =
-                    new ResourceException("unable to cleanup connection");
-                exception.setLinkedException(e);
-                throw exception;
-            }
+            this.session.logout();
+            this.session = openSession();
             this.handles.clear();
         }
     }
@@ -229,20 +235,31 @@ public final class JCAManagedConnection
         }
     }
 
+    @SuppressWarnings("deprecation")
+    private String getDescriptor(String key) throws ResourceException {
+        try {
+            return mcf.getRepository().getDescriptor(key);
+        } catch (RepositoryException e) {
+            log("Failed to access the repository", e);
+            ResourceException exception = new ResourceException(
+                    "Failed to access the repository: " + e.getMessage());
+            exception.setLinkedException(e);
+            throw exception;
+        }
+    }
+
     /**
      * Return the product name.
      */
-    public String getEISProductName()
-            throws ResourceException {
-        return getRepository().getDescriptor(Repository.REP_NAME_DESC);
+    public String getEISProductName() throws ResourceException {
+        return getDescriptor(Repository.REP_NAME_DESC);
     }
 
     /**
      * Return the product version.
      */
-    public String getEISProductVersion()
-            throws ResourceException {
-        return getRepository().getDescriptor(Repository.REP_VERSION_DESC);
+    public String getEISProductVersion() throws ResourceException {
+        return getDescriptor(Repository.REP_VERSION_DESC);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnectionFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnectionFactory.java?rev=1039064&r1=1039063&r2=1039064&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnectionFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnectionFactory.java
Thu Nov 25 14:38:27 2010
@@ -21,10 +21,8 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
-import javax.jcr.Credentials;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
-import javax.jcr.Session;
 import javax.resource.ResourceException;
 import javax.resource.spi.ConnectionManager;
 import javax.resource.spi.ConnectionRequestInfo;
@@ -32,7 +30,6 @@ import javax.resource.spi.ManagedConnect
 import javax.resource.spi.ManagedConnectionFactory;
 import javax.security.auth.Subject;
 
-import org.apache.jackrabbit.api.XASession;
 import org.apache.jackrabbit.commons.JcrUtils;
 
 /**
@@ -134,35 +131,12 @@ public final class JCAManagedConnectionF
      */
     public Object createConnectionFactory(ConnectionManager cm)
             throws ResourceException {
-        createRepository();
         JCARepositoryHandle handle = new JCARepositoryHandle(this, cm);
         log("Created repository handle (" + handle + ")");
         return handle;
     }
 
     /**
-     * Create a new session.
-     */
-    private Session openSession(JCAConnectionRequestInfo cri)
-            throws ResourceException {
-        createRepository();
-        Credentials creds = cri.getCredentials();
-        String workspace = cri.getWorkspace();
-
-        try {
-            Session session = getRepository().login(creds, workspace);
-            log("Created session (" + session + ")");
-            return session;
-        } catch (RepositoryException e) {
-            log("Failed to create session", e);
-            ResourceException exception = new ResourceException(
-                    "Failed to create session: " + e.getMessage());
-            exception.setLinkedException(e);
-            throw exception;
-        }
-    }
-
-    /**
      * {@inheritDoc}
      * <p/>
      * Creates a new physical connection to the underlying EIS resource manager.
@@ -186,13 +160,12 @@ public final class JCAManagedConnectionF
      */
     private ManagedConnection createManagedConnection(JCAConnectionRequestInfo cri)
             throws ResourceException {
-        return new JCAManagedConnection(this, cri, openSession(cri));
+        return new JCAManagedConnection(this, cri);
     }
 
     /**
      * Returns a matched connection from the candidate set of connections.
      */
-    @SuppressWarnings("unchecked")
     public ManagedConnection matchManagedConnections(
             Set set, Subject subject, ConnectionRequestInfo cri)
             throws ResourceException {
@@ -212,9 +185,14 @@ public final class JCAManagedConnectionF
     }
 
     /**
-     * Return the repository.
+     * Return the repository, automatically creating it if needed.
      */
-    public Repository getRepository() {
+    public synchronized Repository getRepository() throws RepositoryException {
+        if (repository == null) {
+            JCARepositoryManager mgr = JCARepositoryManager.getInstance();
+            repository = mgr.createRepository(parameters);
+            log("Created repository (" + repository + ")");
+        }
         return repository;
     }
 
@@ -266,26 +244,6 @@ public final class JCAManagedConnectionF
     }
 
     /**
-     * Create repository.
-     */
-    private void createRepository()
-            throws ResourceException {
-        if (repository == null) {
-            try {
-                JCARepositoryManager mgr = JCARepositoryManager.getInstance();
-                repository = mgr.createRepository(parameters);
-                log("Created repository (" + repository + ")");
-            } catch (RepositoryException e) {
-                log("Failed to create repository", e);
-                ResourceException exception = new ResourceException(
-                        "Failed to create session: " + e.getMessage());
-                exception.setLinkedException(e);
-                throw exception;
-            }
-        }
-    }
-
-    /**
      * Shutdown the repository.
      */
     protected void finalize() {

Modified: jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCARepositoryHandle.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCARepositoryHandle.java?rev=1039064&r1=1039063&r2=1039064&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCARepositoryHandle.java
(original)
+++ jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCARepositoryHandle.java
Thu Nov 25 14:38:27 2010
@@ -66,6 +66,7 @@ public final class JCARepositoryHandle e
     /**
      * Creates a new session.
      */
+    @SuppressWarnings("deprecation")
     public Session login(Credentials creds, String workspace)
             throws RepositoryException {
         try {
@@ -113,7 +114,7 @@ public final class JCARepositoryHandle e
             this.mcf = mcf;
         }
 
-        public Repository getRepository() {
+        public Repository getRepository() throws RepositoryException {
             return mcf.getRepository();
         }
 



Mime
View raw message