Mercurial > dive4elements > gnv-client
comparison geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEPoolableObjectFactory.java @ 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 | ff1b7967e6b9 |
children | 5b536542ef56 |
comparison
equal
deleted
inserted
replaced
550:84ba7cbff791 | 551:1f6e2b256247 |
---|---|
21 | 21 |
22 /** | 22 /** |
23 * the logger, used to log exceptions and additonaly information | 23 * the logger, used to log exceptions and additonaly information |
24 */ | 24 */ |
25 private static Logger log = Logger.getLogger(ArcSDEPoolableObjectFactory.class); | 25 private static Logger log = Logger.getLogger(ArcSDEPoolableObjectFactory.class); |
26 | |
27 private int serverRoundtripInterval = 1000 * 30;// 30 Sekunden | |
26 /** | 28 /** |
27 * The URL to the ArcSDE Server | 29 * The URL to the ArcSDE Server |
28 */ | 30 */ |
29 private String server = null; | 31 private String server = null; |
30 /** | 32 /** |
54 this.port = properties.getProperty("port"); | 56 this.port = properties.getProperty("port"); |
55 this.database = properties.getProperty("database"); | 57 this.database = properties.getProperty("database"); |
56 this.username = properties.getProperty("username"); | 58 this.username = properties.getProperty("username"); |
57 this.credentials = properties.getProperty("credentials"); | 59 this.credentials = properties.getProperty("credentials"); |
58 | 60 |
61 try { | |
62 String serverRoundtripIntervalValue = properties.getProperty("serverRoundtripInterval"); | |
63 if (serverRoundtripIntervalValue != null){ | |
64 this.serverRoundtripInterval = Integer.parseInt(serverRoundtripIntervalValue); | |
65 } | |
66 } catch (NumberFormatException e) { | |
67 log.error(e,e); | |
68 } | |
69 | |
59 log.info("ArcSDEPoolableObjectFactory initialized"); | 70 log.info("ArcSDEPoolableObjectFactory initialized"); |
60 log.info("Server: "+this.server); | 71 log.info("Server: "+this.server); |
61 log.info("Port: "+this.port); | 72 log.info("Port: "+this.port); |
62 log.info("Database: "+this.database); | 73 log.info("Database: "+this.database); |
63 log.info("User: "+this.username); | 74 log.info("User: "+this.username); |
75 log.info("Testtimeout: "+this.serverRoundtripInterval); | |
76 | |
64 } | 77 } |
65 | 78 |
66 /** | 79 /** |
67 * @see org.apache.commons.pool.PoolableObjectFactory#activateObject(java.lang.Object) | 80 * @see org.apache.commons.pool.PoolableObjectFactory#activateObject(java.lang.Object) |
68 */ | 81 */ |
87 */ | 100 */ |
88 public Object makeObject() throws Exception { | 101 public Object makeObject() throws Exception { |
89 log.debug("ArcSDEPoolableObjectFactory.makeObject"); | 102 log.debug("ArcSDEPoolableObjectFactory.makeObject"); |
90 Connection con; | 103 Connection con; |
91 try { | 104 try { |
92 con = new ArcSDEConnection(this.server, this.port, this.database, this.username, this.credentials); | 105 con = new ArcSDEConnection(this.server, this.port, this.database, this.username, this.credentials, this.serverRoundtripInterval); |
93 } | 106 } |
94 catch (ConnectionException e) { | 107 catch (ConnectionException e) { |
95 throw new ConnectionException("Establishing a connection to database failed: " + e.toString(), e); | 108 throw new ConnectionException("Establishing a connection to database failed: " + e.toString(), e); |
96 } | 109 } |
97 return con; | 110 return con; |
107 /** | 120 /** |
108 * @see org.apache.commons.pool.PoolableObjectFactory#validateObject(java.lang.Object) | 121 * @see org.apache.commons.pool.PoolableObjectFactory#validateObject(java.lang.Object) |
109 */ | 122 */ |
110 public boolean validateObject(Object arg0) { | 123 public boolean validateObject(Object arg0) { |
111 log.debug("ArcSDEPoolableObjectFactory.validateObject"); | 124 log.debug("ArcSDEPoolableObjectFactory.validateObject"); |
125 | |
112 boolean returnValue = false; | 126 boolean returnValue = false; |
113 try { | 127 try { |
114 returnValue = arg0 instanceof ArcSDEConnection | 128 returnValue = arg0 instanceof ArcSDEConnection |
115 ? !((ArcSDEConnection)arg0).isClosed() | 129 ? ((ArcSDEConnection)arg0).isValid(this.serverRoundtripInterval) |
116 : false; | 130 : false; |
117 } | 131 } |
118 catch (SQLException sqle) {} | 132 catch (SQLException sqle) {} |
119 return returnValue; | 133 return returnValue; |
120 } | 134 } |