Mercurial > dive4elements > gnv-client
annotate geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEConnectionPool.java @ 1127:ebeb56428409
Added license headers and license file.
geo-backend/trunk@1261 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 02 Nov 2010 17:52:22 +0000 |
parents | e5e30090c37c |
children |
rev | line source |
---|---|
1127
ebeb56428409
Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
889
diff
changeset
|
1 /* |
ebeb56428409
Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
889
diff
changeset
|
2 * Copyright (c) 2010 by Intevation GmbH |
ebeb56428409
Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
889
diff
changeset
|
3 * |
ebeb56428409
Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
889
diff
changeset
|
4 * This program is free software under the LGPL (>=v2.1) |
ebeb56428409
Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
889
diff
changeset
|
5 * Read the file LGPL.txt coming with the software for details |
ebeb56428409
Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
889
diff
changeset
|
6 * or visit http://www.gnu.org/licenses/ if it does not exist. |
ebeb56428409
Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
889
diff
changeset
|
7 */ |
ebeb56428409
Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
889
diff
changeset
|
8 |
130
e4eacd613356
Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
9 package de.intevation.gnv.geobackend.sde.connectionpool; |
e4eacd613356
Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
10 |
e4eacd613356
Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
11 import java.sql.Connection; |
e4eacd613356
Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
12 import java.util.Properties; |
e4eacd613356
Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
13 |
e4eacd613356
Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
14 import org.apache.commons.pool.PoolableObjectFactory; |
e4eacd613356
Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
15 import org.apache.commons.pool.impl.GenericObjectPool; |
889
e5e30090c37c
Modified some JavaDoc so that the Warnings that where caused by mistakes are removed.
Tim Englich <tim.englich@intevation.de>
parents:
887
diff
changeset
|
16 import org.apache.log4j.Logger; |
886
8b442223741c
Ordered imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
885
diff
changeset
|
17 |
889
e5e30090c37c
Modified some JavaDoc so that the Warnings that where caused by mistakes are removed.
Tim Englich <tim.englich@intevation.de>
parents:
887
diff
changeset
|
18 import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool; |
e5e30090c37c
Modified some JavaDoc so that the Warnings that where caused by mistakes are removed.
Tim Englich <tim.englich@intevation.de>
parents:
887
diff
changeset
|
19 import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException; |
130
e4eacd613356
Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
20 |
e4eacd613356
Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
21 /** |
e4eacd613356
Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
22 *This is the ArcSDE specific implementation of the Interface ConnectionPool |
885
1c3efbd2fc5a
Removes trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
274
diff
changeset
|
23 * |
887
b757def3ff55
Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
886
diff
changeset
|
24 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> |
130
e4eacd613356
Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
25 */ |
e4eacd613356
Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
26 public class ArcSDEConnectionPool implements ConnectionPool { |
e4eacd613356
Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
27 |
265 | 28 /** |
130
e4eacd613356
Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
29 * the logger, used to log exceptions and additonaly information |
e4eacd613356
Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
30 */ |
265 | 31 private static Logger log = Logger |
32 .getLogger(ArcSDEPoolableObjectFactory.class); | |
130
e4eacd613356
Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
33 |
265 | 34 /** |
35 * The Pool which stores the Connections to the ArcSDE Backend | |
36 */ | |
37 private GenericObjectPool pool = null; | |
38 | |
39 /** | |
889
e5e30090c37c
Modified some JavaDoc so that the Warnings that where caused by mistakes are removed.
Tim Englich <tim.englich@intevation.de>
parents:
887
diff
changeset
|
40 * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#closeConnection(java.sql.Connection) |
265 | 41 */ |
42 public void closeConnection(Connection connection) | |
43 throws ConnectionException { | |
44 try { | |
45 this.pool.returnObject(connection); | |
46 } catch (Exception e) { | |
47 log.error(e, e); | |
48 throw new ConnectionException(e); | |
49 } | |
50 | |
51 } | |
52 | |
53 /** | |
54 * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#getConnection(java.lang.String) | |
55 */ | |
56 public synchronized Connection getConnection(String connectionID) | |
57 throws ConnectionException { | |
58 try { | |
59 Object object = this.pool.borrowObject(); | |
60 | |
61 if (object instanceof Connection) { | |
62 return (Connection) object; | |
63 } else { | |
64 throw new ConnectionException( | |
65 "Created Object is not an java.sql.Connection"); | |
66 } | |
67 | |
68 } catch (Exception e) { | |
69 log.error(e, e); | |
70 throw new ConnectionException(e); | |
71 } | |
72 } | |
73 | |
74 /** | |
75 * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#initialize(java.util.Properties) | |
76 */ | |
77 public void initialize(Properties properties) { | |
78 log.info("ArcSDEConnectionPool.initialize has been called"); | |
79 log.info("ConnectionPool will be initialized"); | |
80 | |
81 PoolableObjectFactory poolableObjectFactory = new ArcSDEPoolableObjectFactory( | |
82 properties); | |
83 | |
84 int maxActive = Integer.parseInt(properties.getProperty("maxActive", | |
85 "10")); | |
86 long maxWait = Long.parseLong(properties.getProperty("maxWait", | |
87 "" + GenericObjectPool.DEFAULT_MAX_WAIT)); | |
88 int maxIdle = Integer.parseInt(properties.getProperty("maxIdle", | |
89 "" + GenericObjectPool.DEFAULT_MAX_IDLE)); | |
90 int minIdle = Integer.parseInt(properties.getProperty("minIdle", | |
91 "" + GenericObjectPool.DEFAULT_MIN_IDLE)); | |
92 boolean testOnBorrow = Boolean.parseBoolean(properties.getProperty( | |
93 "testOnBorrow", "" + GenericObjectPool.DEFAULT_TEST_ON_BORROW)); | |
94 boolean testOnReturn = Boolean.parseBoolean(properties.getProperty( | |
95 "testOnReturn", "" + GenericObjectPool.DEFAULT_TEST_ON_RETURN)); | |
96 long timeBetweenEvictionRunsMillis = Long | |
97 .parseLong(properties | |
98 .getProperty( | |
99 "timeBetweenEvictionRunsMillis", | |
100 "" | |
101 + GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS)); | |
102 int numTestsPerEvictionRun = Integer.parseInt(properties.getProperty( | |
103 "numTestsPerEvictionRun", | |
104 "" + GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN)); | |
105 long minEvictableIdleTimeMillis = Long | |
106 .parseLong(properties | |
107 .getProperty( | |
108 "minEvictableIdleTimeMillis", | |
109 "" | |
110 + GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS)); | |
111 boolean testWhileIdle = Boolean.parseBoolean(properties | |
112 .getProperty("testWhileIdle", | |
113 "" + GenericObjectPool.DEFAULT_TEST_WHILE_IDLE)); | |
885
1c3efbd2fc5a
Removes trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
274
diff
changeset
|
114 |
265 | 115 log.info("Maximum Number of active Connections: " + maxActive); |
116 log.info("Maximum Number of waiting: " + maxWait); | |
117 log.info("Maximum Number of idle: " + maxIdle); | |
118 log.info("Minimum Number of idle: " + minIdle); | |
119 log.info("TestOnBorrow: " + testOnBorrow); | |
120 log.info("TestOnReturn: " + testOnReturn); | |
121 log.info("TimeBetweenEvictionRunsMillis: " + timeBetweenEvictionRunsMillis); | |
122 log.info("NumTestsPerEvictionRun: " + numTestsPerEvictionRun); | |
123 log.info("MinEvictableIdleTimeMillis: " + minEvictableIdleTimeMillis); | |
124 log.info("TestWhileIdle: " + testWhileIdle); | |
885
1c3efbd2fc5a
Removes trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
274
diff
changeset
|
125 |
265 | 126 this.pool = new GenericObjectPool(poolableObjectFactory, maxActive, |
127 GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION, maxWait, | |
128 maxIdle, minIdle, testOnBorrow, testOnReturn, | |
129 timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, | |
130 minEvictableIdleTimeMillis, testWhileIdle); | |
130
e4eacd613356
Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
131 } |
e4eacd613356
Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
132 } |