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 (C) Exoffice Technologies Inc. All Rights Reserved. 42 */ 43 package org.exolab.jms.persistence; 44 45 46 import java.sql.Connection; 47 48 49 /*** 50 * This interface is used to support different connection pooling packages 51 * such as Tyrex, DBCP, Minerva, PoolMan and Proxool. The client must first set 52 * the properties of the connection manager before making a call to 53 * {link #getConnection} 54 * 55 * @version $Revision: 1.1 $ $Date: 2004/11/26 01:50:44 $ 56 * @author <a href="mailto:jima@intalio.com">Jim Alateras</a> 57 **/ 58 public interface DBConnectionManager { 59 60 /*** 61 * Sets the user name that is used to obtain the connection 62 * 63 * @param name the user name 64 */ 65 void setUser(String name); 66 67 /*** 68 * Sets the user's password that is used to access the database 69 * 70 * @param password the user's password 71 */ 72 void setPassword(String password); 73 74 /*** 75 * Sets the JDBC driver class name 76 * 77 * @param driver the JDBC driver class name 78 */ 79 void setDriver(String driver); 80 81 /*** 82 * Sets the URL to the database 83 * 84 * @param url the JDBC URL 85 */ 86 void setURL(String url); 87 88 /*** 89 * Sets the maximum number of active connections that can be allocated from 90 * this pool at the same time, or zero for no limit. 91 * 92 * @param active the maximum number of active connections 93 */ 94 void setMaxActive(int active); 95 96 /*** 97 * Sets the maximum number of connections that can sit idle in the 98 * connection pool, before connections are evicted. 99 * 100 * @param idle the maximum number of idle connections 101 */ 102 void setMaxIdle(int idle); 103 104 /*** 105 * Sets the minimum time that a connection may remain idle 106 * before it may be evicted, or zero for no eviction. 107 * 108 * @param time the idle time, in seconds 109 */ 110 void setMinIdleTime(long time); 111 112 /*** 113 * Sets the interval between checking idle connections for eviction. 114 * Idle connections are removed after {@link #setMinIdleTime} seconds, 115 * or if {@ link #testQuery} is specified, and the query fails. 116 * 117 * @param interval the eviction interval, in seconds 118 */ 119 void setEvictionInterval(long interval); 120 121 /*** 122 * Specifies an SQL query to validate connections. This query 123 * should return at least one row, and be fast to execute. 124 * 125 * @param query the test query 126 */ 127 void setTestQuery(String query); 128 129 /*** 130 * Determines if connections should be tested before use. 131 * If true, each connection is tested before being returned. 132 * If a connection fails, it is discarded, and another connection 133 * allocated. This ensures a higher reliability, at the cost of 134 * performance. 135 * 136 * @param test if <code>true</code>, each connection is tested use. 137 */ 138 void setTestBeforeUse(boolean test); 139 140 /*** 141 * Initialise the connection manager. This must be called before a call to 142 * {@link #getConnection} is made and after all the properties have been 143 * set. 144 * 145 * @throws PersistenceException - if there is a problem with the init 146 */ 147 void init() throws PersistenceException; 148 149 /*** 150 * Retrieve a connection to the underlying database for the pool of 151 * connections. 152 * This can only be called after the properties have been set and the 153 * manager has been initialized 154 * 155 * @throws PersistenceException - if there is a problem with the init 156 */ 157 Connection getConnection() throws PersistenceException; 158 }