1 /***
2 * Redistribution and use of this software and associated documentation
3 * ("Software"), with or without modification, are permitted provided
4 * that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain copyright
7 * statements and notices. Redistributions must also contain a
8 * copy of this document.
9 *
10 * 2. Redistributions in binary form must reproduce the
11 * above copyright notice, this list of conditions and the
12 * following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * 3. The name "Exolab" must not be used to endorse or promote
16 * products derived from this Software without prior written
17 * permission of Exoffice Technologies. For written permission,
18 * please contact info@exolab.org.
19 *
20 * 4. Products derived from this Software may not be called "Exolab"
21 * nor may "Exolab" appear in their names without prior written
22 * permission of Exoffice Technologies. Exolab is a registered
23 * trademark of Exoffice Technologies.
24 *
25 * 5. Due credit should be given to the Exolab Project
26 * (http://www.exolab.org/).
27 *
28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Copyright 2000-2003 (C) Exoffice Technologies Inc. All Rights Reserved.
42 */
43 package org.exolab.jms.persistence;
44
45
46 /***
47 * All concrete {@link DBConnectionManager} instances can extend this class.
48 *
49 * @version $Revision: 1.1 $ $Date: 2004/11/26 01:50:44 $
50 * @author <a href="mailto:jima@intalio.com">Jim Alateras</a>
51 * @see org.exolab.jms.persistence.DBConnectionManager
52 */
53 public abstract class AbstractConnectionManager
54 implements DBConnectionManager {
55
56 /***
57 * The user name
58 */
59 private String _user;
60
61 /***
62 * The user's password
63 */
64 private String _password;
65
66 /***
67 * The JDBC driver class name
68 */
69 private String _driver;
70
71 /***
72 * The JDBC url
73 */
74 private String _url;
75
76 /***
77 * The maximum no. of active connections
78 */
79 private int _maxActive;
80
81 /***
82 * The maximum no. of idle connections
83 */
84 private int _maxIdle;
85
86 /***
87 * The minimum time that a connection may remain idle before it may be
88 * evicted, in seconds
89 */
90 private long _minIdleTime;
91
92 /***
93 * The interval between checking idle connections for eviction, in seconds
94 */
95 private long _evictionInterval;
96
97 /***
98 * The SQL query to validate connections
99 */
100 private String _testQuery;
101
102 /***
103 * Determines if connections should be tested before use,
104 * using {@link #_testQuery}
105 */
106 private boolean _testBeforeUse = false;
107
108
109 /***
110 * Sets the user name that is used to obtain the connection
111 *
112 * @param name the user name
113 */
114 public void setUser(String name) {
115 _user = name;
116 }
117
118 /***
119 * Returns the user's name
120 *
121 * @return the user's name
122 */
123 public String getUser() {
124 return _user;
125 }
126
127 /***
128 * Sets the user's password that is used to access the database
129 *
130 * @param password the user's password
131 */
132 public void setPassword(String password) {
133 _password = password;
134 }
135
136 /***
137 * Returns the user's password
138 *
139 * @return the user's password
140 */
141 public String getPassword() {
142 return _password;
143 }
144
145 /***
146 * Sets the JDBC driver class name
147 *
148 * @param driver the JDBC driver class name
149 */
150 public void setDriver(String driver) {
151 _driver = driver;
152 }
153
154 /***
155 * Returns the JDBC driver class name
156 *
157 * @return the JDBC driver class name
158 */
159 public String getDriver() {
160 return _driver;
161 }
162
163 /***
164 * Sets the URL to the database
165 *
166 * @param url the JDBC URL
167 */
168 public void setURL(String url) {
169 _url = url;
170 }
171
172 /***
173 * Returns the JDBC URL
174 *
175 * @return the JDBC URL
176 */
177 public String getURL() {
178 return _url;
179 }
180
181 /***
182 * Sets the maximum number of active connections that can be allocated from
183 * this pool at the same time, or zero for no limit.
184 *
185 * @param active the maximum number of active connections
186 */
187 public void setMaxActive(int active) {
188 _maxActive = active;
189 }
190
191 /***
192 * Returns the maximum number of active connections that can be allocated
193 * from this pool at the same time.
194 *
195 * @return the maximum number of active connections
196 */
197 public int getMaxActive() {
198 return _maxActive;
199 }
200
201 /***
202 * Sets the maximum number of connections that can sit idle in the
203 * connection pool, before connections are evicted.
204 *
205 * @param idle the maximum number of idle connections
206 */
207 public void setMaxIdle(int idle) {
208 _maxIdle = idle;
209 }
210
211 /***
212 * Returns the maximum number of connections that can sit idle in the
213 * connection pool, before connections are evicted.
214 *
215 * @return the maximum number of idle connections
216 */
217 public int getMaxIdle() {
218 return _maxIdle;
219 }
220
221 /***
222 * Sets the minimum time that a connection may remain idle
223 * before it may be evicted, or zero for no eviction.
224 *
225 * @param time the idle time, in seconds
226 */
227 public void setMinIdleTime(long time) {
228 _minIdleTime = time;
229 }
230
231 /***
232 * Returns the minimum time that a connection may remain idle
233 * before it may be evicted
234 *
235 * @return the minimum idle time, in seconds
236 */
237 public long getMinIdleTime() {
238 return _minIdleTime;
239 }
240
241 /***
242 * Sets the interval between checking idle connections for eviction.
243 * Idle connections are removed after {@link #setMinIdleTime} seconds,
244 * or if {@ link #testQuery} is specified, and the query fails.
245 *
246 * @param interval the eviction interval, in seconds
247 */
248 public void setEvictionInterval(long interval) {
249 _evictionInterval = interval;
250 }
251
252 /***
253 * Returns the interval between checking idle connections for eviction.
254 *
255 * @return the eviction interval, in seconds
256 */
257 public long getEvictionInterval() {
258 return _evictionInterval;
259 }
260
261 /***
262 * Specifies an SQL query to validate connections. This query
263 * should return at least one row, and be fast to execute.
264 *
265 * @param query the test query
266 */
267 public void setTestQuery(String query) {
268 _testQuery = query;
269 }
270
271 /***
272 * Returns the SQL query to validate connections.
273 *
274 * @return the test query
275 */
276 public String getTestQuery() {
277 return _testQuery;
278 }
279
280 /***
281 * Determines if connections should be tested before use.
282 * If true, each connection is tested before being returned.
283 * If a connection fails, it is discarded, and another connection
284 * allocated. This ensures a higher reliability, at the cost of
285 * performance.
286 *
287 * @param test if <code>true</code>, each connection is tested use.
288 */
289 public void setTestBeforeUse(boolean test) {
290 _testBeforeUse = test;
291 }
292
293 /***
294 * Returns if connections should be tested before use.
295 *
296 * @return <code>true</code> if each connection should be tested before
297 * being used.
298 */
299 public boolean getTestBeforeUse() {
300 return _testBeforeUse;
301 }
302
303 }