Author: kwright
Date: Wed Sep 25 18:07:39 2013
New Revision: 1526249

URL: http://svn.apache.org/r1526249
Log:
Use shared parameters for database configuration

Modified:
    
manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java
    
manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
    
manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/DBInterfaceFactory.java
    
manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPoolManager.java

Modified: 
manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java?rev=1526249&r1=1526248&r2=1526249&view=diff
==============================================================================
--- 
manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java
 (original)
+++ 
manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java
 Wed Sep 25 18:07:39 2013
@@ -35,9 +35,6 @@ public class ConnectionFactory
 {
   public static final String _rcsid = "@(#)$Id: ConnectionFactory.java 988245 
2010-08-23 18:39:35Z kwright $";
 
-  // This default is designed to avoid strange errors with people using 
postgresql out of the box, where the maximum connection count is set to 100.
-  private static final int defaultMaxDBConnections = 50;
-  private static final int defaultTimeoutValue = 86400;
 
   private static HashMap checkedOutConnections = new HashMap();
 
@@ -47,7 +44,8 @@ public class ConnectionFactory
   {
   }
 
-  public static WrappedConnection getConnection(String jdbcUrl, String 
jdbcDriver, String database, String userName, String password)
+  public static WrappedConnection getConnection(String jdbcUrl, String 
jdbcDriver, String database, String userName, String password,
+    int maxDBConnections, boolean debug)
     throws ManifoldCFException
   {
     // Make sure database driver is registered
@@ -59,8 +57,8 @@ public class ConnectionFactory
     {
       throw new ManifoldCFException("Unable to load database driver: 
"+e.getMessage(),e,ManifoldCFException.SETUP_ERROR);
     }
-
-    ConnectionPoolManager cpm = poolManager.createPoolManager();
+    
+    ConnectionPoolManager cpm = poolManager.createPoolManager(debug);
     
     try
     {
@@ -76,18 +74,6 @@ public class ConnectionFactory
       }
       if (cp == null)
       {
-        String handleMax = 
ManifoldCF.getProperty(ManifoldCF.databaseHandleMaxcountProperty);
-        int maxDBConnections = defaultMaxDBConnections;
-        if (handleMax != null && handleMax.length() > 0)
-          maxDBConnections = Integer.parseInt(handleMax);
-        //String timeoutValueString = 
ManifoldCF.getProperty(ManifoldCF.databaseHandleTimeoutProperty);
-        //int timeoutValue = defaultTimeoutValue;
-        //if (timeoutValueString != null && timeoutValueString.length() > 0)
-        //  timeoutValue = Integer.parseInt(timeoutValueString);
-
-        // Logging.db.debug("adding pool alias [" + database + "]");
-        // I had to up the timeout from one hour to 3 due to the webconnector 
keeping some connections open a very long time...
-       //System.out.println("jdbcUrl = '"+jdbcUrl+"', userName='"+userName+"', 
password='"+password+"'");
         cpm.addAlias(database, jdbcDriver, jdbcUrl,
           userName, password,
           maxDBConnections, 300000L);
@@ -173,19 +159,19 @@ public class ConnectionFactory
   {
     private Integer poolExistenceLock = new Integer(0);
     private ConnectionPoolManager _pool = null;
-
+    
     private PoolManager()
     {
     }
 
-    public ConnectionPoolManager createPoolManager()
+    public ConnectionPoolManager createPoolManager(boolean debug)
       throws ManifoldCFException
     {
       synchronized (poolExistenceLock)
       {
         if (_pool != null)
           return _pool;
-        _pool = new ConnectionPoolManager(100);
+        _pool = new ConnectionPoolManager(100, debug);
         return _pool;
       }
     }

Modified: 
manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java?rev=1526249&r1=1526248&r2=1526249&view=diff
==============================================================================
--- 
manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
 (original)
+++ 
manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
 Wed Sep 25 18:07:39 2013
@@ -38,11 +38,11 @@ public abstract class Database
 {
   public static final String _rcsid = "@(#)$Id: Database.java 988245 
2010-08-23 18:39:35Z kwright $";
 
-  protected ICacheManager cacheManager;
-  protected IThreadContext context;
-  protected String jdbcUrl;
-  protected String jdbcDriverClass;
-  protected String databaseName;
+  protected final ICacheManager cacheManager;
+  protected final IThreadContext context;
+  protected final String jdbcUrl;
+  protected final String jdbcDriverClass;
+  protected final String databaseName;
   protected String userName;
   protected String password;
   protected TransactionHandle th = null;
@@ -52,7 +52,9 @@ public abstract class Database
   protected int delayedTransactionDepth = 0;
   protected Map<String,Modifications> modificationsSet = new 
HashMap<String,Modifications>();
 
-  protected long maxQueryTime;
+  protected final long maxQueryTime;
+  protected final boolean debug;
+  protected final int maxDBConnections;
   
   protected static Random random = new Random();
 
@@ -68,7 +70,10 @@ public abstract class Database
     this.userName = userName;
     this.password = password;
     
-    this.maxQueryTime = 
((long)ManifoldCF.getIntProperty(ManifoldCF.databaseQueryMaxTimeProperty,60)) * 
1000L;
+    this.maxQueryTime = ((long)LockManagerFactory.getIntProperty(context, 
ManifoldCF.databaseQueryMaxTimeProperty,60)) * 1000L;
+    this.debug = LockManagerFactory.getBooleanProperty(context, 
ManifoldCF.databaseConnectionTrackingProperty, false);
+    this.maxDBConnections = LockManagerFactory.getIntProperty(context, 
ManifoldCF.databaseHandleMaxcountProperty, 50);
+
     this.cacheManager = CacheManagerFactory.make(context);
   }
 
@@ -247,7 +252,8 @@ public abstract class Database
     // Get a semipermanent connection
     if (connection == null)
     {
-      connection = 
ConnectionFactory.getConnection(jdbcUrl,jdbcDriverClass,databaseName,userName,password);
+      connection = 
ConnectionFactory.getConnection(jdbcUrl,jdbcDriverClass,databaseName,userName,password,
+        maxDBConnections,debug);
       try
       {
         // Initialize the connection (for HSQLDB)
@@ -755,7 +761,8 @@ public abstract class Database
     else
     {
       // Grab a connection
-      WrappedConnection tempConnection = 
ConnectionFactory.getConnection(jdbcUrl,jdbcDriverClass,databaseName,userName,password);
+      WrappedConnection tempConnection = 
ConnectionFactory.getConnection(jdbcUrl,jdbcDriverClass,databaseName,userName,password,
+        maxDBConnections,debug);
       try
       {
         // Initialize the connection (for HSQLDB)

Modified: 
manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/DBInterfaceFactory.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/DBInterfaceFactory.java?rev=1526249&r1=1526248&r2=1526249&view=diff
==============================================================================
--- 
manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/DBInterfaceFactory.java
 (original)
+++ 
manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/DBInterfaceFactory.java
 Wed Sep 25 18:07:39 2013
@@ -40,9 +40,8 @@ public class DBInterfaceFactory
     Object x = context.get(dbName);
     if (x == null || !(x instanceof IDBInterface))
     {
-      String implementationClass = 
ManifoldCF.getProperty(ManifoldCF.databaseImplementation);
-      if (implementationClass == null)
-        implementationClass = 
"org.apache.manifoldcf.core.database.DBInterfacePostgreSQL";
+      String implementationClass = 
LockManagerFactory.getStringProperty(context, ManifoldCF.databaseImplementation,
+        "org.apache.manifoldcf.core.database.DBInterfacePostgreSQL");
       try
       {
         Class c = Class.forName(implementationClass);

Modified: 
manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPoolManager.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPoolManager.java?rev=1526249&r1=1526248&r2=1526249&view=diff
==============================================================================
--- 
manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPoolManager.java
 (original)
+++ 
manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPoolManager.java
 Wed Sep 25 18:07:39 2013
@@ -24,6 +24,7 @@ import java.util.*;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.manifoldcf.core.interfaces.ManifoldCFException;
+import org.apache.manifoldcf.core.interfaces.LockManagerFactory;
 import org.apache.manifoldcf.core.system.ManifoldCF;
 
 /** An instance of this class manages a number of (independent) connection 
pools.
@@ -37,10 +38,10 @@ public class ConnectionPoolManager
   protected volatile AtomicBoolean shuttingDown = new AtomicBoolean(false);
   protected final boolean debug;
   
-  public ConnectionPoolManager(int count)
+  public ConnectionPoolManager(int count, boolean debug)
     throws ManifoldCFException
   {
-    debug = 
ManifoldCF.getBooleanProperty(ManifoldCF.databaseConnectionTrackingProperty, 
false);
+    this.debug = debug;
     poolMap = new HashMap<String,ConnectionPool>(count);
     connectionCloserThread = new ConnectionCloserThread();
     connectionCloserThread.start();


Reply via email to