# HG changeset patch # User Tim Englich # Date 1255440026 0 # Node ID e5379e1297999f76123fd2ee344ab9ae3f3acb2f # Parent 5bbdbc0bbddc70c19eb9a947bd802f7ec7596576 Fixed issue 34 geo-backend/trunk@215 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 5bbdbc0bbddc -r e5379e129799 geo-backend/ChangeLog --- 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 + * 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 * 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: diff -r 5bbdbc0bbddc -r e5379e129799 geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEConnectionPool.java --- 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 */ 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); - - } - } diff -r 5bbdbc0bbddc -r e5379e129799 geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEPoolableObjectFactory.java --- 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 +} diff -r 5bbdbc0bbddc -r e5379e129799 geo-backend/src/test/ressources/ArcSDEConnectionPoolTestCase.properties --- 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