You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2010/11/26 14:15:47 UTC

svn commit: r1039341 - in /jackrabbit/branches/2.0: ./ jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/

Author: jukka
Date: Fri Nov 26 13:15:47 2010
New Revision: 1039341

URL: http://svn.apache.org/viewvc?rev=1039341&view=rev
Log:
2.0: Merged revision 1039335 (JCR-2523)

Modified:
    jackrabbit/branches/2.0/   (props changed)
    jackrabbit/branches/2.0/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnection.java
    jackrabbit/branches/2.0/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnectionFactory.java
    jackrabbit/branches/2.0/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCARepositoryHandle.java

Propchange: jackrabbit/branches/2.0/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Nov 26 13:15:47 2010
@@ -1,6 +1,6 @@
 /jackrabbit/branches/1.5:794012,794100,794102
-/jackrabbit/branches/2.1:955309,955314,982266,982277,982505,998310,1025933,1025957,1025962,1025964,1025981,1025985,1025990,1025995,1025999,1026002,1038594,1038599
+/jackrabbit/branches/2.1:955309,955314,982266,982277,982505,998310,1025933,1025957,1025962,1025964,1025981,1025985,1025990,1025995,1025999,1026002,1038594,1038599,1039335
 /jackrabbit/sandbox/JCR-1456:774917-886178
 /jackrabbit/sandbox/JCR-2170:812417-816332
 /jackrabbit/sandbox/tripod-JCR-2209:795441-795863
-/jackrabbit/trunk:891595,891629,892253,892263,894150-894151,896408,896513,896532,896857,896870,896876,896908,896940,896942-896943,896969,896977,897071,897836,897842,897858,897935,897983,897992-897993,897996,898002,898042,898267,898325,898540,898677,898699,898701,898715,898872,899102,899181,899391,899393-899394,899583,899594,899643,900305,900310,900314,900453,900702,900736,900762-900763,900767,900782,901095,901122,901139,901144,901170,901176,901191,901193,901196,901216,901228,901285,902058,902062,926324,928888,936668,955222,955229,955307,955852,965539,995411-995412,996810,999298-999299,999965,1000947,1001707,1002065-1002066,1002084,1002101-1002102,1002168,1002170,1002589,1002608,1002657,1002729,1003423,1003470,1003542,1003773,1004182,1004184,1004223-1004224,1004652,1005057,1005112,1036117,1036336-1036337,1038201
+/jackrabbit/trunk:891595,891629,892253,892263,894150-894151,896408,896513,896532,896857,896870,896876,896908,896940,896942-896943,896969,896977,897071,897836,897842,897858,897935,897983,897992-897993,897996,898002,898042,898267,898325,898540,898677,898699,898701,898715,898872,899102,899181,899391,899393-899394,899583,899594,899643,900305,900310,900314,900453,900702,900736,900762-900763,900767,900782,901095,901122,901139,901144,901170,901176,901191,901193,901196,901216,901228,901285,902058,902062,926324,928888,936668,955222,955229,955307,955852,965539,995411-995412,996810,999298-999299,999965,1000947,1001707,1002065-1002066,1002084,1002101-1002102,1002168,1002170,1002589,1002608,1002657,1002729,1003423,1003470,1003542,1003773,1004182,1004184,1004223-1004224,1004652,1005057,1005112,1036117,1036336-1036337,1038201,1039064

Modified: jackrabbit/branches/2.0/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnection.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnection.java?rev=1039341&r1=1039340&r2=1039341&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnection.java (original)
+++ jackrabbit/branches/2.0/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnection.java Fri Nov 26 13:15:47 2010
@@ -54,7 +54,7 @@ public final class JCAManagedConnection
     /**
      * Session instance.
      */
-    private final XASession session;
+    private XASession session;
 
     /**
      * XAResource instance.
@@ -79,10 +79,12 @@ public final class JCAManagedConnection
     /**
      * Construct the managed connection.
      */
-    public JCAManagedConnection(JCAManagedConnectionFactory mcf, JCAConnectionRequestInfo cri, XASession session) {
+    public JCAManagedConnection(
+            JCAManagedConnectionFactory mcf, JCAConnectionRequestInfo cri)
+            throws ResourceException {
         this.mcf = mcf;
         this.cri = cri;
-        this.session = session;
+        this.session = openSession();
         this.listeners = new LinkedList();
         this.handles = new LinkedList();
         if (this.mcf.getBindSessionToTransaction().booleanValue()) {
@@ -93,10 +95,22 @@ public final class JCAManagedConnection
     }
 
     /**
-     * Return the repository.
+     * Create a new session.
      */
-    private RepositoryImpl getRepository() {
-        return mcf.getRepository();
+    @SuppressWarnings("deprecation")
+    private XASession openSession() throws ResourceException {
+        try {
+            XASession session = (XASession) 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 +169,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 +237,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/branches/2.0/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnectionFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnectionFactory.java?rev=1039341&r1=1039340&r2=1039341&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnectionFactory.java (original)
+++ jackrabbit/branches/2.0/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAManagedConnectionFactory.java Fri Nov 26 13:15:47 2010
@@ -17,9 +17,8 @@
 package org.apache.jackrabbit.jca;
 
 import org.apache.jackrabbit.api.XASession;
-import org.apache.jackrabbit.core.RepositoryImpl;
 
-import javax.jcr.Credentials;
+import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.resource.ResourceException;
 import javax.resource.spi.ConnectionManager;
@@ -31,6 +30,8 @@ import java.io.PrintWriter;
 import java.util.Iterator;
 import java.util.Set;
 
+import org.apache.jackrabbit.commons.JcrUtils;
+
 /**
  * Implements the JCA ManagedConnectionFactory contract.
  */
@@ -58,7 +59,7 @@ public final class JCAManagedConnectionF
     /**
      * Repository.
      */
-    private transient RepositoryImpl repository;
+    private transient Repository repository;
 
     /**
      * Log writer.
@@ -121,35 +122,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 XASession openSession(JCAConnectionRequestInfo cri)
-            throws ResourceException {
-        createRepository();
-        Credentials creds = cri.getCredentials();
-        String workspace = cri.getWorkspace();
-
-        try {
-            XASession session = (XASession) 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.
@@ -173,13 +151,14 @@ 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.
      */
-    public ManagedConnection matchManagedConnections(Set set, Subject subject, ConnectionRequestInfo cri)
+    public ManagedConnection matchManagedConnections(
+            Set set, Subject subject, ConnectionRequestInfo cri)
             throws ResourceException {
         for (Iterator i = set.iterator(); i.hasNext();) {
             Object next = i.next();
@@ -199,9 +178,24 @@ public final class JCAManagedConnectionF
     }
 
     /**
-     * Return the repository.
+     * Return the repository, automatically creating it if needed.
      */
-    public RepositoryImpl getRepository() {
+    public synchronized Repository getRepository() throws RepositoryException {
+        if (repository == null) {
+            // Check the home directory
+            if ((homeDir == null) || homeDir.equals("")) {
+                throw new RepositoryException("Property 'homeDir' not set");
+            }
+
+            // Check the config file
+            if ((configFile == null) || configFile.equals("")) {
+                throw new RepositoryException("Property 'configFile' not set");
+            }
+
+            JCARepositoryManager mgr = JCARepositoryManager.getInstance();
+            repository = mgr.createRepository(homeDir, configFile);
+            log("Created repository (" + repository + ")");
+        }
         return repository;
     }
 
@@ -269,36 +263,6 @@ public final class JCAManagedConnectionF
     }
 
     /**
-     * Create repository.
-     */
-    private void createRepository()
-            throws ResourceException {
-        if (repository == null) {
-            // Check the home directory
-            if ((homeDir == null) || homeDir.equals("")) {
-                throw new ResourceException("Property 'homeDir' not set");
-            }
-
-            // Check the config file
-            if ((configFile == null) || configFile.equals("")) {
-                throw new ResourceException("Property 'configFile' not set");
-            }
-
-            try {
-                JCARepositoryManager mgr = JCARepositoryManager.getInstance();
-                repository = mgr.createRepository(homeDir, configFile);
-                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/branches/2.0/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCARepositoryHandle.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCARepositoryHandle.java?rev=1039341&r1=1039340&r2=1039341&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCARepositoryHandle.java (original)
+++ jackrabbit/branches/2.0/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCARepositoryHandle.java Fri Nov 26 13:15:47 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();
         }