changeset 551:1f6e2b256247

Improved the Objectvalidation of the ArcSDE-Databaseconnections geo-backend/trunk@544 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 15 Jan 2010 10:09:41 +0000
parents 84ba7cbff791
children 7615ee5d1345
files geo-backend/ChangeLog geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEPoolableObjectFactory.java geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnection.java
diffstat 3 files changed, 43 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/geo-backend/ChangeLog	Tue Jan 12 00:27:53 2010 +0000
+++ b/geo-backend/ChangeLog	Fri Jan 15 10:09:41 2010 +0000
@@ -1,3 +1,16 @@
+2010-01-15  Tim Englich  <tim.englich@intevation.de>
+
+	* src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnection.java (isValid): 
+	  Implemented the isValid-method of the ArcSDEConnection for 
+	  getting a propper Validation of the used SEConnection.
+	  For the Validation the Method testServer of the SEConnection is used.
+	
+	* src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEPoolableObjectFactory.java (ArcSDEPoolableObjectFactory): 
+	  Added Member serverRoundtripInterval to represent the Time in 
+	  Milliseconds which is allowed to reused a returned Connection.
+	  Also used Connection.isValid Method instead of Connection.isClosed 
+	  to validate the Connection befor it could be borrowed from the Pool.
+
 2009-01-12	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/gnv/geobackend/sde/datasources/RasterObject.java:
--- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEPoolableObjectFactory.java	Tue Jan 12 00:27:53 2010 +0000
+++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEPoolableObjectFactory.java	Fri Jan 15 10:09:41 2010 +0000
@@ -23,6 +23,8 @@
      * the logger, used to log exceptions and additonaly information
      */
     private static Logger log = Logger.getLogger(ArcSDEPoolableObjectFactory.class);
+    
+    private int serverRoundtripInterval = 1000 * 30;// 30 Sekunden
     /**
      * The URL to the ArcSDE Server
      */
@@ -56,11 +58,22 @@
         this.username = properties.getProperty("username");
         this.credentials = properties.getProperty("credentials");
         
+        try {
+            String serverRoundtripIntervalValue = properties.getProperty("serverRoundtripInterval");
+            if (serverRoundtripIntervalValue != null){
+                this.serverRoundtripInterval = Integer.parseInt(serverRoundtripIntervalValue);
+            }
+        } catch (NumberFormatException e) {
+            log.error(e,e);
+        }
+        
         log.info("ArcSDEPoolableObjectFactory initialized");
         log.info("Server: "+this.server);
         log.info("Port: "+this.port);
         log.info("Database: "+this.database);
         log.info("User: "+this.username);
+        log.info("Testtimeout: "+this.serverRoundtripInterval);
+        
         }
 
     /**
@@ -89,7 +102,7 @@
         log.debug("ArcSDEPoolableObjectFactory.makeObject");
         Connection con;
         try {
-            con = new ArcSDEConnection(this.server, this.port, this.database, this.username, this.credentials);
+            con = new ArcSDEConnection(this.server, this.port, this.database, this.username, this.credentials, this.serverRoundtripInterval);
         }
         catch (ConnectionException e) {
             throw new ConnectionException("Establishing a connection to database failed: " + e.toString(), e);
@@ -109,10 +122,11 @@
      */
     public boolean validateObject(Object arg0) {
         log.debug("ArcSDEPoolableObjectFactory.validateObject");
+        
         boolean returnValue = false;
         try {
             returnValue = arg0 instanceof ArcSDEConnection
-                ? !((ArcSDEConnection)arg0).isClosed()
+                ? ((ArcSDEConnection)arg0).isValid(this.serverRoundtripInterval)
                 : false;
         }
         catch (SQLException sqle) {}
--- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnection.java	Tue Jan 12 00:27:53 2010 +0000
+++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnection.java	Fri Jan 15 10:09:41 2010 +0000
@@ -42,14 +42,17 @@
     
 	private SeConnection seConnection = null;
 	
+	private long serverRoundtripInterval;
+	
 
 
 	/**
 	 * Constructor
 	 */
-	public ArcSDEConnection(String server,String port,String database,String username,String credentials) throws ConnectionException {
+	public ArcSDEConnection(String server,String port,String database,String username,String credentials, long serverRoundtripInterval) throws ConnectionException {
 		try {
 	        seConnection = new SeConnection(server,port,database,username,credentials);
+	        this.serverRoundtripInterval = serverRoundtripInterval;
         } catch (SeException e) {
 	        log.error(e,e);
 	        throw new ConnectionException(e);
@@ -388,7 +391,16 @@
     }
 
     public boolean isValid(int arg0) throws SQLException {
-        return false;
+        
+        boolean valid = true;
+        try {
+            this.seConnection.testServer(serverRoundtripInterval);
+        } catch (SeException e) {
+            log.debug("The validation of the Connection has occured an Error. The connection is invalid.");
+            valid = false;
+        }
+        
+        return valid;
     }
 
     public void setClientInfo(Properties arg0) throws SQLClientInfoException {

http://dive4elements.wald.intevation.org