1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xalan.lib.sql;
  58. import java.util.Properties;
  59. import java.lang.String;
  60. import java.sql.Connection;
  61. import java.sql.SQLException;
  62. import java.sql.*;
  63. /**
  64. * An interface used to build wrapper classes around existing
  65. * Connection Pool libraries.
  66. * Title: ConnectionPool<p>
  67. * @author John Gentilin
  68. * @version 1.0
  69. */
  70. public interface ConnectionPool
  71. {
  72. /**
  73. * Determine if a Connection Pool has been disabled. If a Connection pool
  74. * is disabled, then it will only manage connections that are in use.
  75. * @return
  76. */
  77. public boolean isEnabled( );
  78. /**
  79. * The Driver and URL are the only required parmeters.
  80. * @param d
  81. * @return
  82. */
  83. public void setDriver( String d );
  84. /**
  85. * @param url
  86. * @return
  87. */
  88. public void setURL( String url );
  89. /**
  90. * Start downsizeing the pool, this usally happens right after the
  91. * pool has been marked as Inactive and we are removing connections
  92. * that are not currently inuse.
  93. * @return
  94. */
  95. public void freeUnused( );
  96. /**
  97. * Provide an indicator to the PoolManager when the Pool can be removed
  98. * from the Pool Table.
  99. * @return
  100. */
  101. public boolean hasActiveConnections( );
  102. /**
  103. * The rest of the protocol parameters can eiter be passed in as
  104. * just Username and Password or as a property collection. If the
  105. * property collection is used, then the sperate username and password
  106. * may be ignored, it is up to the wrapper implementation to handle
  107. * the situation. If the connection information changes while after the
  108. * pool has been established, the wrapper implementation should ignore
  109. * the change and throw an error.
  110. * @param p
  111. * @return
  112. */
  113. public void setPassword( String p );
  114. /**
  115. * @param u
  116. * @return
  117. */
  118. public void setUser( String u );
  119. /**
  120. * Set tne minimum number of connections that are to be maintained in the
  121. * pool.
  122. * @param n
  123. * @return
  124. */
  125. public void setMinConnections( int n );
  126. /**
  127. * Test to see if the connection info is valid to make a real connection
  128. * to the database. This method may cause the pool to be crated and filled
  129. * with min connections.
  130. * @return
  131. */
  132. public boolean testConnection( );
  133. /**
  134. * Retrive a database connection from the pool
  135. * @return
  136. * @throws SQLException
  137. */
  138. public Connection getConnection( )throws SQLException;
  139. /**
  140. * Return a connection to the pool, the connection may be closed if the
  141. * pool is inactive or has exceeded the max number of free connections
  142. * @param con
  143. * @return
  144. * @throws SQLException
  145. */
  146. public void releaseConnection( Connection con )throws SQLException;
  147. /**
  148. * Provide a mechinism to return a connection to the pool on Error.
  149. * A good default behaviour is to close this connection and build
  150. * a new one to replace it. Some JDBC impl's won't allow you to
  151. * reuse a connection after an error occurs.
  152. * @param con
  153. * @return
  154. * @throws SQLException
  155. */
  156. public void releaseConnectionOnError( Connection con )throws SQLException;
  157. /**
  158. * The Pool can be Enabled and Disabled. Disabling the pool
  159. * closes all the outstanding Unused connections and any new
  160. * connections will be closed upon release.
  161. * @param flag Control the Connection Pool. If it is enabled
  162. * then Connections will actuall be held around. If disabled
  163. * then all unused connections will be instantly closed and as
  164. * connections are released they are closed and removed from the pool.
  165. * @return
  166. */
  167. public void setPoolEnabled( final boolean flag );
  168. /**
  169. * Used to pass in extra configuration options during the
  170. * database connect phase.
  171. */
  172. public void setProtocol(Properties p);
  173. }