KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > lib > sql > ConnectionPool


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: ConnectionPool.java,v 1.13 2004/02/11 17:56:36 minchau Exp $
18  */

19
20 package org.apache.xalan.lib.sql;
21
22 import java.sql.Connection JavaDoc;
23 import java.sql.SQLException JavaDoc;
24 import java.util.Properties JavaDoc;
25
26 /**
27  * An interface used to build wrapper classes around existing
28  * Connection Pool libraries.
29  * Title: ConnectionPool<p>
30  * @author John Gentilin
31  * @version 1.0
32  */

33 public interface ConnectionPool
34 {
35
36   /**
37    * Determine if a Connection Pool has been disabled. If a Connection pool
38    * is disabled, then it will only manage connections that are in use.
39    *
40    */

41   public boolean isEnabled( );
42
43   /**
44    * The Driver and URL are the only required parmeters.
45    * @param d
46    *
47    */

48   public void setDriver( String JavaDoc d );
49
50   /**
51    * @param url
52    *
53    */

54   public void setURL( String JavaDoc url );
55
56   /**
57    * Start downsizeing the pool, this usally happens right after the
58    * pool has been marked as Inactive and we are removing connections
59    * that are not currently inuse.
60    *
61    */

62   public void freeUnused( );
63
64
65   /**
66    * Provide an indicator to the PoolManager when the Pool can be removed
67    * from the Pool Table.
68    *
69    */

70   public boolean hasActiveConnections( );
71
72   /**
73    * The rest of the protocol parameters can eiter be passed in as
74    * just Username and Password or as a property collection. If the
75    * property collection is used, then the sperate username and password
76    * may be ignored, it is up to the wrapper implementation to handle
77    * the situation. If the connection information changes while after the
78    * pool has been established, the wrapper implementation should ignore
79    * the change and throw an error.
80    * @param p
81    *
82    */

83   public void setPassword( String JavaDoc p );
84
85   /**
86    * @param u
87    *
88    */

89   public void setUser( String JavaDoc u );
90
91
92   /**
93    * Set tne minimum number of connections that are to be maintained in the
94    * pool.
95    * @param n
96    *
97    */

98   public void setMinConnections( int n );
99
100   /**
101    * Test to see if the connection info is valid to make a real connection
102    * to the database. This method may cause the pool to be crated and filled
103    * with min connections.
104    *
105    */

106   public boolean testConnection( );
107
108   /**
109    * Retrive a database connection from the pool
110    *
111    * @throws SQLException
112    */

113   public Connection JavaDoc getConnection( )throws SQLException JavaDoc;
114
115    /**
116    * Return a connection to the pool, the connection may be closed if the
117    * pool is inactive or has exceeded the max number of free connections
118    * @param con
119    *
120    * @throws SQLException
121    */

122   public void releaseConnection( Connection JavaDoc con )throws SQLException JavaDoc;
123
124    /**
125    * Provide a mechinism to return a connection to the pool on Error.
126    * A good default behaviour is to close this connection and build
127    * a new one to replace it. Some JDBC impl's won't allow you to
128    * reuse a connection after an error occurs.
129    * @param con
130    *
131    * @throws SQLException
132    */

133   public void releaseConnectionOnError( Connection JavaDoc con )throws SQLException JavaDoc;
134
135
136   /**
137    * The Pool can be Enabled and Disabled. Disabling the pool
138    * closes all the outstanding Unused connections and any new
139    * connections will be closed upon release.
140    * @param flag Control the Connection Pool. If it is enabled
141    * then Connections will actuall be held around. If disabled
142    * then all unused connections will be instantly closed and as
143    * connections are released they are closed and removed from the pool.
144    *
145    */

146   public void setPoolEnabled( final boolean flag );
147
148   /**
149    * Used to pass in extra configuration options during the
150    * database connect phase.
151    */

152   public void setProtocol(Properties JavaDoc p);
153
154
155 }
156
Popular Tags