changeset 265:e5379e129799

Fixed issue 34 geo-backend/trunk@215 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 13 Oct 2009 13:20:26 +0000
parents 5bbdbc0bbddc
children 1530890b28c9
files geo-backend/ChangeLog geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEConnectionPool.java geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEPoolableObjectFactory.java geo-backend/src/test/ressources/ArcSDEConnectionPoolTestCase.properties
diffstat 4 files changed, 131 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/geo-backend/ChangeLog	Tue Oct 13 09:00:30 2009 +0000
+++ b/geo-backend/ChangeLog	Tue Oct 13 13:20:26 2009 +0000
@@ -1,5 +1,17 @@
 2009-10-13  Tim Englich  <tim.englich@intevation.de>
 
+	* src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEPoolableObjectFactory.java (validateObject) Edited:
+	  Added Tests if the Object is Closed. And add propper instance Tests 
+	* src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEConnectionPool.java (initialize):
+	  Added further ConfigurationParameters that could be  set in the *.properties-File.
+	  maxWait, maxIdle, minIdle, testOnBorrow, testOnReturn, testWhileIdle, numTestsPerEvictionRun, 
+	  timeBetweenEvictionRunsMillis, testWhileIdle 
+	* src/test/ressources/ArcSDEConnectionPoolTestCase.properties: 
+	  Added som Configurationproperties for testing.
+	  
+	  Issue-34
+	  
+2009-10-13  Tim Englich  <tim.englich@intevation.de>
 	* src/test/java/de/intevation/gnv/geobackend/base/query/QueryExecutorTestCase.java (QueryExecutorTestCase):
 	  Changed expected Result of Spatial-Query-TestCase because of Changes to the used Query 
 	* src/test/ressources/QueryExecutorTestCase.properties: 
--- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEConnectionPool.java	Tue Oct 13 09:00:30 2009 +0000
+++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEConnectionPool.java	Tue Oct 13 13:20:26 2009 +0000
@@ -12,70 +12,115 @@
 
 /**
  *This is the ArcSDE specific implementation of the Interface ConnectionPool
+ * 
  * @author Tim Englich <tim.englich@intevation.de>
  */
 public class ArcSDEConnectionPool implements ConnectionPool {
 
-	/**
+    /**
      * the logger, used to log exceptions and additonaly information
      */
-    private static Logger log = Logger.getLogger(ArcSDEPoolableObjectFactory.class);
-    
-	/**
-	 * The Pool which stores the Connections to the ArcSDE Backend
-	 */
-	private GenericObjectPool pool = null;
-	
-	/**
-	 * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#closeConnection(java.lang.Object)
-	 */
-	public void closeConnection(Connection connection) throws ConnectionException {
-		
-		try {
-			//TODO: Muss Connection geschlossen werden?
-			this.pool.returnObject(connection);
-		} catch (Exception e) {
-			log.error(e,e);
-			throw new ConnectionException(e);
-		}
-
-	}
+    private static Logger log = Logger
+            .getLogger(ArcSDEPoolableObjectFactory.class);
 
-	/**
-	 * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#getConnection(java.lang.String)
-	 */
-	public synchronized Connection getConnection(String connectionID) throws ConnectionException{
-		try {
-			Object object = this.pool.borrowObject();
-			
-			if (object instanceof Connection){
-				return (Connection)object;
-			}else{
-				throw new ConnectionException("Created Object is not an java.sql.Connection");
-			}
-			
-		} catch (Exception e) {
-			log.error(e,e);
-			throw new ConnectionException(e);
-		}
+    /**
+     * The Pool which stores the Connections to the ArcSDE Backend
+     */
+    private GenericObjectPool pool = null;
+
+    /**
+     * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#closeConnection(java.lang.Object)
+     */
+    public void closeConnection(Connection connection)
+                                                      throws ConnectionException {
+
+        try {
+            // TODO: Muss Connection geschlossen werden?
+            this.pool.returnObject(connection);
+        } catch (Exception e) {
+            log.error(e, e);
+            throw new ConnectionException(e);
+        }
+
+    }
+
+    /**
+     * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#getConnection(java.lang.String)
+     */
+    public synchronized Connection getConnection(String connectionID)
+                                                                     throws ConnectionException {
+        try {
+            Object object = this.pool.borrowObject();
+
+            if (object instanceof Connection) {
+                return (Connection) object;
+            } else {
+                throw new ConnectionException(
+                        "Created Object is not an java.sql.Connection");
+            }
+
+        } catch (Exception e) {
+            log.error(e, e);
+            throw new ConnectionException(e);
+        }
+    }
+
+    /**
+     * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#initialize(java.util.Properties)
+     */
+    public void initialize(Properties properties) {
+        log.info("ArcSDEConnectionPool.initialize has been called");
+        log.info("ConnectionPool will be initialized");
+
+        PoolableObjectFactory poolableObjectFactory = new ArcSDEPoolableObjectFactory(
+                properties);
+
+        int maxActive = Integer.parseInt(properties.getProperty("maxActive",
+                "10"));
+        long maxWait = Long.parseLong(properties.getProperty("maxWait",
+                "" + GenericObjectPool.DEFAULT_MAX_WAIT));
+        int maxIdle = Integer.parseInt(properties.getProperty("maxIdle",
+                "" + GenericObjectPool.DEFAULT_MAX_IDLE));
+        int minIdle = Integer.parseInt(properties.getProperty("minIdle",
+                "" + GenericObjectPool.DEFAULT_MIN_IDLE));
+        boolean testOnBorrow = Boolean.parseBoolean(properties.getProperty(
+                "testOnBorrow", "" + GenericObjectPool.DEFAULT_TEST_ON_BORROW));
+        boolean testOnReturn = Boolean.parseBoolean(properties.getProperty(
+                "testOnReturn", "" + GenericObjectPool.DEFAULT_TEST_ON_RETURN));
+        long timeBetweenEvictionRunsMillis = Long
+                .parseLong(properties
+                        .getProperty(
+                                "timeBetweenEvictionRunsMillis",
+                                ""
+                                        + GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS));
+        int numTestsPerEvictionRun = Integer.parseInt(properties.getProperty(
+                "numTestsPerEvictionRun",
+                "" + GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN));
+        long minEvictableIdleTimeMillis = Long
+                .parseLong(properties
+                        .getProperty(
+                                "minEvictableIdleTimeMillis",
+                                ""
+                                        + GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS));
+        boolean testWhileIdle = Boolean.parseBoolean(properties
+                .getProperty("testWhileIdle",
+                        "" + GenericObjectPool.DEFAULT_TEST_WHILE_IDLE));
+        
+        log.info("Maximum Number of active Connections: " + maxActive);
+        log.info("Maximum Number of waiting: " + maxWait);
+        log.info("Maximum Number of idle: " + maxIdle);
+        log.info("Minimum Number of idle: " + minIdle);
+        log.info("TestOnBorrow: " + testOnBorrow);
+        log.info("TestOnReturn: " + testOnReturn);
+        log.info("TimeBetweenEvictionRunsMillis: " + timeBetweenEvictionRunsMillis);
+        log.info("NumTestsPerEvictionRun: " + numTestsPerEvictionRun);
+        log.info("MinEvictableIdleTimeMillis: " + minEvictableIdleTimeMillis);
+        log.info("TestWhileIdle: " + testWhileIdle);
+        
+        this.pool = new GenericObjectPool(poolableObjectFactory, maxActive,
+                                            GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION, maxWait,
+                                            maxIdle, minIdle, testOnBorrow, testOnReturn,
+                                            timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
+                                            minEvictableIdleTimeMillis, testWhileIdle);
 	}
-	
-	/**
-	 * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#initialize(java.util.Properties)
-	 */
-	public void initialize(Properties properties) {
-		log.info("ArcSDEConnectionPool.initialize has been called");
-		log.info("ConnectionPool will be initialized");
-		
-		PoolableObjectFactory poolableObjectFactory = new ArcSDEPoolableObjectFactory(properties);
-		
-		int maxActive = Integer.parseInt(properties.getProperty("maxActive", "10"));
-		
-	    log.info("Maximum Number of active Connections: "+maxActive);
-		// TODO weitere Werte einparsen und setzen.
-		
-		this.pool = new GenericObjectPool(poolableObjectFactory,maxActive);
-		
-	}
-
 }
--- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEPoolableObjectFactory.java	Tue Oct 13 09:00:30 2009 +0000
+++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEPoolableObjectFactory.java	Tue Oct 13 13:20:26 2009 +0000
@@ -4,13 +4,12 @@
 package de.intevation.gnv.geobackend.sde.connectionpool;
 
 import java.sql.Connection;
+import java.sql.SQLException;
 import java.util.Properties;
 
 import org.apache.commons.pool.PoolableObjectFactory;
 import org.apache.log4j.Logger;
 
-import com.esri.sde.sdk.client.SeConnection;
-
 import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException;
 import de.intevation.gnv.geobackend.sde.datasources.ArcSDEConnection;
 
@@ -79,8 +78,8 @@
 	 */
 	public void destroyObject(Object arg0) throws Exception {
 		log.debug("ArcSDEPoolableObjectFactory.destroyObjectb");
-		if (arg0 instanceof SeConnection){
-			((SeConnection)arg0).close();
+		if (arg0 instanceof ArcSDEConnection) {
+			((ArcSDEConnection)arg0).close();
 		}else{
 			log.warn("Object cannot be handled");
 		}
@@ -115,6 +114,13 @@
 	public boolean validateObject(Object arg0) {
 		// TODO Was muss hier passieren?
 		log.debug("ArcSDEPoolableObjectFactory.validateObject");
-		return true;
+        boolean returnValue = false;
+		try {
+		    returnValue = arg0 instanceof ArcSDEConnection
+                ? !((ArcSDEConnection)arg0).isClosed()
+                : false;
+        }
+        catch (SQLException sqle) {}
+        return returnValue;
 	}
-}
\ No newline at end of file
+}
--- a/geo-backend/src/test/ressources/ArcSDEConnectionPoolTestCase.properties	Tue Oct 13 09:00:30 2009 +0000
+++ b/geo-backend/src/test/ressources/ArcSDEConnectionPoolTestCase.properties	Tue Oct 13 13:20:26 2009 +0000
@@ -1,4 +1,8 @@
 maxActive=2
+testOnBorrow=true
+testOnReturn=false
+testWhileIdle=false
+timeBetweenEvictionRunsMillis=360000
 server=localhost
 username=gast
 credentials=gast

http://dive4elements.wald.intevation.org