/projects/openjms-0.7.7-beta-1/modules/jms/src/main/java/org/exolab/jms/persistence/AbstractConnectionManager.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus · Java · 303 lines · 74 code · 34 blank · 195 comment · 0 complexity · a991d6408d813ad685fefe813903387d MD5 · raw file

  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. * All concrete {@link DBConnectionManager} instances can extend this class.
  46. *
  47. * @version $Revision: 1.1 $ $Date: 2004/11/26 01:50:44 $
  48. * @author <a href="mailto:jima@intalio.com">Jim Alateras</a>
  49. * @see org.exolab.jms.persistence.DBConnectionManager
  50. */
  51. public abstract class AbstractConnectionManager
  52. implements DBConnectionManager {
  53. /**
  54. * The user name
  55. */
  56. private String _user;
  57. /**
  58. * The user's password
  59. */
  60. private String _password;
  61. /**
  62. * The JDBC driver class name
  63. */
  64. private String _driver;
  65. /**
  66. * The JDBC url
  67. */
  68. private String _url;
  69. /**
  70. * The maximum no. of active connections
  71. */
  72. private int _maxActive;
  73. /**
  74. * The maximum no. of idle connections
  75. */
  76. private int _maxIdle;
  77. /**
  78. * The minimum time that a connection may remain idle before it may be
  79. * evicted, in seconds
  80. */
  81. private long _minIdleTime;
  82. /**
  83. * The interval between checking idle connections for eviction, in seconds
  84. */
  85. private long _evictionInterval;
  86. /**
  87. * The SQL query to validate connections
  88. */
  89. private String _testQuery;
  90. /**
  91. * Determines if connections should be tested before use,
  92. * using {@link #_testQuery}
  93. */
  94. private boolean _testBeforeUse = false;
  95. /**
  96. * Sets the user name that is used to obtain the connection
  97. *
  98. * @param name the user name
  99. */
  100. public void setUser(String name) {
  101. _user = name;
  102. }
  103. /**
  104. * Returns the user's name
  105. *
  106. * @return the user's name
  107. */
  108. public String getUser() {
  109. return _user;
  110. }
  111. /**
  112. * Sets the user's password that is used to access the database
  113. *
  114. * @param password the user's password
  115. */
  116. public void setPassword(String password) {
  117. _password = password;
  118. }
  119. /**
  120. * Returns the user's password
  121. *
  122. * @return the user's password
  123. */
  124. public String getPassword() {
  125. return _password;
  126. }
  127. /**
  128. * Sets the JDBC driver class name
  129. *
  130. * @param driver the JDBC driver class name
  131. */
  132. public void setDriver(String driver) {
  133. _driver = driver;
  134. }
  135. /**
  136. * Returns the JDBC driver class name
  137. *
  138. * @return the JDBC driver class name
  139. */
  140. public String getDriver() {
  141. return _driver;
  142. }
  143. /**
  144. * Sets the URL to the database
  145. *
  146. * @param url the JDBC URL
  147. */
  148. public void setURL(String url) {
  149. _url = url;
  150. }
  151. /**
  152. * Returns the JDBC URL
  153. *
  154. * @return the JDBC URL
  155. */
  156. public String getURL() {
  157. return _url;
  158. }
  159. /**
  160. * Sets the maximum number of active connections that can be allocated from
  161. * this pool at the same time, or zero for no limit.
  162. *
  163. * @param active the maximum number of active connections
  164. */
  165. public void setMaxActive(int active) {
  166. _maxActive = active;
  167. }
  168. /**
  169. * Returns the maximum number of active connections that can be allocated
  170. * from this pool at the same time.
  171. *
  172. * @return the maximum number of active connections
  173. */
  174. public int getMaxActive() {
  175. return _maxActive;
  176. }
  177. /**
  178. * Sets the maximum number of connections that can sit idle in the
  179. * connection pool, before connections are evicted.
  180. *
  181. * @param idle the maximum number of idle connections
  182. */
  183. public void setMaxIdle(int idle) {
  184. _maxIdle = idle;
  185. }
  186. /**
  187. * Returns the maximum number of connections that can sit idle in the
  188. * connection pool, before connections are evicted.
  189. *
  190. * @return the maximum number of idle connections
  191. */
  192. public int getMaxIdle() {
  193. return _maxIdle;
  194. }
  195. /**
  196. * Sets the minimum time that a connection may remain idle
  197. * before it may be evicted, or zero for no eviction.
  198. *
  199. * @param time the idle time, in seconds
  200. */
  201. public void setMinIdleTime(long time) {
  202. _minIdleTime = time;
  203. }
  204. /**
  205. * Returns the minimum time that a connection may remain idle
  206. * before it may be evicted
  207. *
  208. * @return the minimum idle time, in seconds
  209. */
  210. public long getMinIdleTime() {
  211. return _minIdleTime;
  212. }
  213. /**
  214. * Sets the interval between checking idle connections for eviction.
  215. * Idle connections are removed after {@link #setMinIdleTime} seconds,
  216. * or if {@ link #testQuery} is specified, and the query fails.
  217. *
  218. * @param interval the eviction interval, in seconds
  219. */
  220. public void setEvictionInterval(long interval) {
  221. _evictionInterval = interval;
  222. }
  223. /**
  224. * Returns the interval between checking idle connections for eviction.
  225. *
  226. * @return the eviction interval, in seconds
  227. */
  228. public long getEvictionInterval() {
  229. return _evictionInterval;
  230. }
  231. /**
  232. * Specifies an SQL query to validate connections. This query
  233. * should return at least one row, and be fast to execute.
  234. *
  235. * @param query the test query
  236. */
  237. public void setTestQuery(String query) {
  238. _testQuery = query;
  239. }
  240. /**
  241. * Returns the SQL query to validate connections.
  242. *
  243. * @return the test query
  244. */
  245. public String getTestQuery() {
  246. return _testQuery;
  247. }
  248. /**
  249. * Determines if connections should be tested before use.
  250. * If true, each connection is tested before being returned.
  251. * If a connection fails, it is discarded, and another connection
  252. * allocated. This ensures a higher reliability, at the cost of
  253. * performance.
  254. *
  255. * @param test if <code>true</code>, each connection is tested use.
  256. */
  257. public void setTestBeforeUse(boolean test) {
  258. _testBeforeUse = test;
  259. }
  260. /**
  261. * Returns if connections should be tested before use.
  262. *
  263. * @return <code>true</code> if each connection should be tested before
  264. * being used.
  265. */
  266. public boolean getTestBeforeUse() {
  267. return _testBeforeUse;
  268. }
  269. } //-- AbstractConnectionManager