jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r923206 - in /jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca: JCAManagedConnection.java JCAManagedConnectionFactory.java JCARepositoryManager.java JCASessionHandle.java
Date Mon, 15 Mar 2010 13:09:38 GMT
Author: jukka
Date: Mon Mar 15 13:09:38 2010
New Revision: 923206

URL: http://svn.apache.org/viewvc?rev=923206&view=rev
Log:
JCR-2555: Improved reusability of the JCA package

Replace direct jackrabbit-core references with the JCR 2.0 RepositoryFactory mechanism

Also did some Java 5 cleanups

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/JCARepositoryManager.java
    jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCASessionHandle.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=923206&r1=923205&r2=923206&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
Mon Mar 15 13:09:38 2010
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.jca;
 
 import org.apache.jackrabbit.api.XASession;
-import org.apache.jackrabbit.core.RepositoryImpl;
 
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
@@ -64,12 +63,12 @@ public final class JCAManagedConnection
     /**
      * Listeners.
      */
-    private final LinkedList listeners;
+    private final LinkedList<ConnectionEventListener> listeners;
 
     /**
      * Handles.
      */
-    private final LinkedList handles;
+    private final LinkedList<JCASessionHandle> handles;
 
     /**
      * Log writer.
@@ -83,8 +82,8 @@ public final class JCAManagedConnection
         this.mcf = mcf;
         this.cri = cri;
         this.session = session;
-        this.listeners = new LinkedList();
-        this.handles = new LinkedList();
+        this.listeners = new LinkedList<ConnectionEventListener>();
+        this.handles = new LinkedList<JCASessionHandle>();
         if (this.mcf.getBindSessionToTransaction().booleanValue()) {
             this.xaResource =  new TransactionBoundXAResource(this, session.getXAResource());
         } else {
@@ -95,7 +94,7 @@ public final class JCAManagedConnection
     /**
      * Return the repository.
      */
-    private RepositoryImpl getRepository() {
+    private Repository getRepository() {
         return mcf.getRepository();
     }
 
@@ -306,8 +305,8 @@ public final class JCAManagedConnection
      */
     private void sendEvent(ConnectionEvent event) {
         synchronized (listeners) {
-            for (Iterator i = listeners.iterator(); i.hasNext();) {
-                ConnectionEventListener listener = (ConnectionEventListener) i.next();
+            for (Iterator<ConnectionEventListener> i = listeners.iterator(); i.hasNext();)
{
+                ConnectionEventListener listener = i.next();
 
                 switch (event.getId()) {
                     case ConnectionEvent.CONNECTION_CLOSED:

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=923206&r1=923205&r2=923206&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
Mon Mar 15 13:09:38 2010
@@ -16,20 +16,21 @@
  */
 package org.apache.jackrabbit.jca;
 
-import org.apache.jackrabbit.api.XASession;
-import org.apache.jackrabbit.core.RepositoryImpl;
+import java.io.PrintWriter;
+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;
 import javax.resource.spi.ManagedConnection;
 import javax.resource.spi.ManagedConnectionFactory;
 import javax.security.auth.Subject;
-import java.io.PrintWriter;
-import java.util.Iterator;
-import java.util.Set;
+
+import org.apache.jackrabbit.api.XASession;
 
 /**
  * Implements the JCA ManagedConnectionFactory contract.
@@ -58,7 +59,7 @@ public final class JCAManagedConnectionF
     /**
      * Repository.
      */
-    private transient RepositoryImpl repository;
+    private transient Repository repository;
 
     /**
      * Log writer.
@@ -137,9 +138,9 @@ public final class JCAManagedConnectionF
         String workspace = cri.getWorkspace();
 
         try {
-            XASession session = (XASession) getRepository().login(creds, workspace);
+            Session session = getRepository().login(creds, workspace);
             log("Created session (" + session + ")");
-            return session;
+            return (XASession) session;
         } catch (RepositoryException e) {
             log("Failed to create session", e);
             ResourceException exception = new ResourceException(
@@ -179,13 +180,13 @@ public final class JCAManagedConnectionF
     /**
      * Returns a matched connection from the candidate set of connections.
      */
-    public ManagedConnection matchManagedConnections(Set set, Subject subject, ConnectionRequestInfo
cri)
+    @SuppressWarnings("unchecked")
+    public ManagedConnection matchManagedConnections(
+            Set set, Subject subject, ConnectionRequestInfo cri)
             throws ResourceException {
-        for (Iterator i = set.iterator(); i.hasNext();) {
-            Object next = i.next();
-
-            if (next instanceof JCAManagedConnection) {
-                JCAManagedConnection mc = (JCAManagedConnection) next;
+        for (Object connection : set) {
+            if (connection instanceof JCAManagedConnection) {
+                JCAManagedConnection mc = (JCAManagedConnection) connection;
                 if (equals(mc.getManagedConnectionFactory())) {
                     JCAConnectionRequestInfo otherCri = mc.getConnectionRequestInfo();
                     if (equals(cri, otherCri)) {
@@ -201,7 +202,7 @@ public final class JCAManagedConnectionF
     /**
      * Return the repository.
      */
-    public RepositoryImpl getRepository() {
+    public Repository getRepository() {
         return repository;
     }
 

Modified: jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCARepositoryManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCARepositoryManager.java?rev=923206&r1=923205&r2=923206&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCARepositoryManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCARepositoryManager.java
Mon Mar 15 13:09:38 2010
@@ -16,13 +16,18 @@
  */
 package org.apache.jackrabbit.jca;
 
-import org.apache.jackrabbit.core.RepositoryImpl;
-import org.apache.jackrabbit.core.config.RepositoryConfig;
-
+import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 
+import org.apache.commons.io.IOUtils;
+import org.apache.jackrabbit.api.JackrabbitRepository;
+import org.apache.jackrabbit.commons.JcrUtils;
+
+import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -45,7 +50,7 @@ public final class JCARepositoryManager 
     /**
      * References.
      */
-    private final Map references;
+    private final Map<Reference, Reference> references;
 
     /**
      * Flag indicating that the life cycle
@@ -58,7 +63,7 @@ public final class JCARepositoryManager 
      * Construct the manager.
      */
     private JCARepositoryManager() {
-        this.references = new HashMap();
+        this.references = new HashMap<Reference, Reference>();
     }
 
     /**
@@ -70,7 +75,7 @@ public final class JCARepositoryManager 
      *                   JCARepositoryManager.CLASSPATH_CONFIG_PREFIX.
      * @return repository instance
      */
-    public RepositoryImpl createRepository(String homeDir, String configFile)
+    public Repository createRepository(String homeDir, String configFile)
             throws RepositoryException {
         Reference ref = getReference(homeDir, configFile);
         return ref.create();
@@ -80,10 +85,10 @@ public final class JCARepositoryManager 
      * Shutdown all the repositories.
      */
     public void shutdown() {
-        Collection references = this.references.values();
-        Iterator iter = references.iterator();
+        Collection<Reference> references = this.references.values();
+        Iterator<Reference> iter = references.iterator();
         while (iter.hasNext()) {
-            Reference ref = (Reference) iter.next();
+            Reference ref = iter.next();
             ref.shutdown();
         }
         this.references.clear();
@@ -97,7 +102,7 @@ public final class JCARepositoryManager 
      */
     private synchronized Reference getReference(String homeDir, String configFile) {
         Reference ref = new Reference(homeDir, configFile);
-        Reference other = (Reference) references.get(ref);
+        Reference other = references.get(ref);
 
         if (other == null) {
             references.put(ref, ref);
@@ -134,7 +139,7 @@ public final class JCARepositoryManager 
         /**
          * Repository instance.
          */
-        private RepositoryImpl repository;
+        private Repository repository;
 
         /**
          * Construct the manager.
@@ -148,45 +153,68 @@ public final class JCARepositoryManager 
         /**
          * Return the repository.
          */
-        public RepositoryImpl create()
-                throws RepositoryException {
+        public Repository create() throws RepositoryException {
             if (repository == null) {
-                RepositoryConfig config = null;
+                Map<String, String> parameters = new HashMap<String, String>();
+
+                parameters.put("org.apache.jackrabbit.repository.home", homeDir);
 
                 if (configFile.startsWith(CLASSPATH_CONFIG_PREFIX)) {
-                    ClassLoader cl = Thread.currentThread().getContextClassLoader();
-                    if (cl == null) {
-                        cl = this.getClass().getClassLoader();
-                    }
+                    String source =
+                        configFile.substring(CLASSPATH_CONFIG_PREFIX.length());
+                    File target = new File(homeDir, "repository.xml");
+                    copyConfigFile(source, target);
+                    parameters.put(
+                            "org.apache.jackrabbit.repository.conf",
+                            target.getPath());
+                } else {
+                    parameters.put(
+                            "org.apache.jackrabbit.repository.conf",
+                            configFile);
+                }
+
+                repository = JcrUtils.getRepository(parameters);
+            }
+
+            return repository;
+        }
 
-                    InputStream configInputStream = cl.getResourceAsStream(
-                        configFile.substring(CLASSPATH_CONFIG_PREFIX.length()));
+        private void copyConfigFile(String source, File target)
+                throws RepositoryException {
+            ClassLoader cl = Thread.currentThread().getContextClassLoader();
+            if (cl == null) {
+                cl = this.getClass().getClassLoader();
+            }
+
+            InputStream input = cl.getResourceAsStream(source);
+            if (input != null) {
+                try {
                     try {
-                        config = RepositoryConfig.create(configInputStream, homeDir);
-                    } finally {
-                        if (configInputStream != null) {
-                            try {
-                                configInputStream.close();
-                            } catch (IOException e) {
-                                // ignore
-                            }
+                        OutputStream output = new FileOutputStream(target);
+                        try {
+                            IOUtils.copy(input, output);
+                        } finally {
+                            output.close();
                         }
+                    } finally {
+                        input.close();
                     }
-                } else {
-                    config = RepositoryConfig.create(configFile, homeDir);
+                } catch (IOException e) {
+                    throw new RepositoryException(
+                            "Failed to copy configuration to " + target, e);
                 }
-                repository = RepositoryImpl.create(config);
+            } else {
+                throw new RepositoryException(
+                        "Repository configuration not found: " + source);
             }
-
-            return repository;
         }
 
         /**
          * Shutdown the repository.
          */
         public void shutdown() {
-            if (repository != null) {
-                repository.shutdown();
+            if (repository instanceof JackrabbitRepository) {
+                ((JackrabbitRepository) repository).shutdown();
             }
         }
 
@@ -257,5 +285,3 @@ public final class JCARepositoryManager 
     }
 
 }
-
-

Modified: jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCASessionHandle.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCASessionHandle.java?rev=923206&r1=923205&r2=923206&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCASessionHandle.java
(original)
+++ jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCASessionHandle.java
Mon Mar 15 13:09:38 2010
@@ -16,9 +16,10 @@
  */
 package org.apache.jackrabbit.jca;
 
-import org.apache.jackrabbit.api.XASession;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.AccessControlException;
 
 import javax.jcr.AccessDeniedException;
 import javax.jcr.Credentials;
@@ -46,11 +47,9 @@ import javax.jcr.security.AccessControlM
 import javax.jcr.version.VersionException;
 import javax.transaction.xa.XAResource;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.security.AccessControlException;
-import java.util.Map;
+import org.apache.jackrabbit.api.XASession;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
 
 /**
  * This class implements the JCA implementation of session.
@@ -144,6 +143,7 @@ public final class JCASessionHandle impl
     /**
      * Return node by UUID.
      */
+    @SuppressWarnings("deprecation")
     public Node getNodeByUUID(String uuid)
             throws ItemNotFoundException, RepositoryException {
         return getSession().getNodeByUUID(uuid);
@@ -316,6 +316,7 @@ public final class JCASessionHandle impl
     /**
      * Add lock token.
      */
+    @SuppressWarnings("deprecation")
     public void addLockToken(String arg0) {
         getSession().addLockToken(arg0);
     }
@@ -323,6 +324,7 @@ public final class JCASessionHandle impl
     /**
      * Return the lock tokens.
      */
+    @SuppressWarnings("deprecation")
     public String[] getLockTokens() {
         return getSession().getLockTokens();
     }
@@ -330,6 +332,7 @@ public final class JCASessionHandle impl
     /**
      * Remove lock token.
      */
+    @SuppressWarnings("deprecation")
     public void removeLockToken(String arg0) {
         getSession().removeLockToken(arg0);
     }



Mime
View raw message