jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cko...@apache.org
Subject svn commit: r1205295 - in /jackrabbit/trunk/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca: JCAManagedConnectionFactory.java JCARepositoryManager.java
Date Wed, 23 Nov 2011 06:21:01 GMT
Author: ckoell
Date: Wed Nov 23 06:21:00 2011
New Revision: 1205295

URL: http://svn.apache.org/viewvc?rev=1205295&view=rev
Log:
JCR-3129 It should be possible to create a non-transient Repository inside the JCARepositoryManager

Modified:
    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

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=1205295&r1=1205294&r2=1205295&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
Wed Nov 23 06:21:00 2011
@@ -46,6 +46,15 @@ public class JCAManagedConnectionFactory
     private final Map<String, String> parameters = new HashMap<String, String>();
 
     /**
+     * Key for the repository home
+     */
+    final static String HOMEDIR_KEY = "org.apache.jackrabbit.repository.home";
+    /**
+     * Key for the repository config file
+     */
+    final static String CONFIGFILE_KEY = "org.apache.jackrabbit.repository.conf";
+    
+    /**
      * Flag indicating whether the session should be bound to the
      * transaction lifecycle.
      * In other words, if this flag is true the handle
@@ -81,28 +90,28 @@ public class JCAManagedConnectionFactory
      * Return the repository home directory.
      */
     public String getHomeDir() {
-        return parameters.get("org.apache.jackrabbit.repository.home");
+        return parameters.get(HOMEDIR_KEY);
     }
 
     /**
      * Set the repository home directory.
      */
     public void setHomeDir(String home) {
-        parameters.put("org.apache.jackrabbit.repository.home", home);
+        parameters.put(HOMEDIR_KEY, home);
     }
 
     /**
      * Return the repository configuration file.
      */
     public String getConfigFile() {
-        return parameters.get("org.apache.jackrabbit.repository.conf");
+        return parameters.get(CONFIGFILE_KEY);
     }
 
     /**
      * Set the repository configuration file.
      */
     public void setConfigFile(String conf) {
-        parameters.put("org.apache.jackrabbit.repository.conf", conf);
+        parameters.put(CONFIGFILE_KEY, conf);
     }
 
     /**
@@ -168,7 +177,8 @@ public class JCAManagedConnectionFactory
     /**
      * Returns a matched connection from the candidate set of connections.
      */
-    public ManagedConnection matchManagedConnections(
+    @SuppressWarnings("rawtypes")
+	public ManagedConnection matchManagedConnections(
             Set set, Subject subject, ConnectionRequestInfo cri)
             throws ResourceException {
         for (Object connection : set) {

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=1205295&r1=1205294&r2=1205295&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
Wed Nov 23 06:21:00 2011
@@ -21,7 +21,10 @@ import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.api.JackrabbitRepository;
 import org.apache.jackrabbit.commons.JcrUtils;
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
 
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -68,13 +71,46 @@ public final class JCARepositoryManager 
             Map<String, String> parameters) throws RepositoryException {
         Repository repository = repositories.get(parameters);
         if (repository == null) {
-            repository =  JcrUtils.getRepository(parameters);
+        	if (parameters.containsKey(JcrUtils.REPOSITORY_URI)) {
+	            repository = JcrUtils.getRepository(parameters);
+        	} else {
+	            repository = createNonTransientRepository(parameters);
+        	}
             repositories.put(parameters, repository);
         }
         return repository;
     }
 
     /**
+     * Creates a non transient Repository
+     * 
+     * @param parameters
+     * @return Repository
+     * @throws RepositoryException
+     */
+    private Repository createNonTransientRepository(
+			Map<String, String> parameters) throws RepositoryException {
+        RepositoryConfig config = null;
+
+        String configFile = parameters.get(JCAManagedConnectionFactory.CONFIGFILE_KEY);
+        String homeDir = parameters.get(JCAManagedConnectionFactory.HOMEDIR_KEY);
+        
+        if (configFile != null && configFile.startsWith(CLASSPATH_CONFIG_PREFIX))
{
+            ClassLoader cl = Thread.currentThread().getContextClassLoader();
+            if (cl == null) {
+                cl = this.getClass().getClassLoader();
+            }
+
+            InputStream configInputStream = cl.getResourceAsStream(
+                configFile.substring(CLASSPATH_CONFIG_PREFIX.length()));
+            config = RepositoryConfig.create(configInputStream, homeDir);
+        } else {
+            config = RepositoryConfig.create(configFile, homeDir);
+        }
+        return RepositoryImpl.create(config);
+	}
+
+	/**
      * Shutdown all the repositories.
      */
     public synchronized void shutdown() {



Mime
View raw message