jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marti...@apache.org
Subject svn commit: r801221 - /jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionFactory.java
Date Wed, 05 Aug 2009 13:22:47 GMT
Author: martijnh
Date: Wed Aug  5 13:22:47 2009
New Revision: 801221

URL: http://svn.apache.org/viewvc?rev=801221&view=rev
Log:
JCR-1456 Database connection pooling

* BasicDataSource does not support "getConnection(String username, String password)", using
setters instead.

Modified:
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionFactory.java

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionFactory.java?rev=801221&r1=801220&r2=801221&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionFactory.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionFactory.java
Wed Aug  5 13:22:47 2009
@@ -58,45 +58,37 @@
     public static Connection getConnection(
             String driver, String url, String user, String password)
             throws RepositoryException, SQLException {
-        DataSource database;
 
         Class<?> driverClass = getDriverClass(driver);
         if (driverClass != null
                 && Context.class.isAssignableFrom(driverClass)) {
-            database = getJndiDataSource((Class<Context>) driverClass, url);
-        } else {
-            database = getDriverDataSource(driverClass, url);
-        }
-
-        if (user == null && password == null) {
-            return database.getConnection();
+            DataSource database = getJndiDataSource((Class<Context>) driverClass, url);
+            if (user == null && password == null) {
+                return database.getConnection();
+            } else {
+                return database.getConnection(user, password);
+            }
         } else {
-            return database.getConnection(user, password);
+            return getDriverDataSource(driverClass, url, user, password).getConnection();
         }
     }
     
     @SuppressWarnings("unchecked")
-	public static DataSource getDataSource(String driver, String url, String user, String password)
-    throws RepositoryException, SQLException
-    {
-    	DataSource database;
+    public static DataSource getDataSource(String driver, String url, String user, String
password)
+            throws RepositoryException, SQLException    {
 
         Class<?> driverClass = getDriverClass(driver);
         if (driverClass != null
                 && Context.class.isAssignableFrom(driverClass)) {
-            database = getJndiDataSource((Class<Context>) driverClass, url);
+            DataSource database = getJndiDataSource((Class<Context>) driverClass, url);
+            if (user == null && password == null) {
+                return database;
+            } else {
+                return new DataSourceWrapper(database, user, password);
+            }
         } else {
-            database = getDriverDataSource(driverClass, url);
-        }
-        
-        if (user == null && password == null)
-        {
-        	return database;
-        }
-        else
-        {
-        	return new DataSourceWrapper(database, user, password);
-        }
+            return getDriverDataSource(driverClass, url, user, password);
+        }        
     }
 
     /**
@@ -166,7 +158,7 @@
      * @return pooling DataSource for accessing the specified database
      */
     private static DataSource getDriverDataSource(
-            Class<?> driverClass, String url) {
+            Class<?> driverClass, String url, String user, String password) {
         BasicDataSource database = new BasicDataSource();
 
         if (driverClass != null) {
@@ -185,6 +177,8 @@
         }
 
         database.setUrl(url);
+        database.setUsername(user);
+        database.setPassword(password);
 
         return database;
     }



Mime
View raw message