|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectfedora.server.storage.ConnectionPool
Title: ConnectionPool.java
Description: A class for preallocating, recycling, and managing JDBC connections.
Taken/adapted from Core Servlets and JavaServer Pages from Prentice Hall and Sun Microsystems Press, http://www.coreservlets.com/ © 2000 Marty Hall; may be freely used or adapted
-----------------------------------------------------------------------------License and Copyright: The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/.
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License.
The original code is Copyright © 2000 Marty Hall. All rights reserved. The current project homepage for the original code may be found at: http://www.coreservlets.com/.
Portions created for the Fedora Repository System are Copyright © 2002-2004 by The Rector and Visitors of the University of Virginia and Cornell University. All rights reserved."
-----------------------------------------------------------------------------
| Constructor Summary | |
ConnectionPool(java.lang.String driver,
java.lang.String url,
java.lang.String username,
java.lang.String password,
int initialConnections,
int maxConnections,
boolean waitIfBusy)
Constructs a ConnectionPool based on the calling arguments. |
|
ConnectionPool(java.lang.String driver,
java.lang.String url,
java.lang.String username,
java.lang.String password,
int initialConnections,
int maxConnections,
boolean waitIfBusy,
DDLConverter ddlConverter)
Constructs a ConnectionPool that can provide TableCreatingConnections. |
|
| Method Summary | |
void |
closeAllConnections()
Closes all the connections. |
void |
free(java.sql.Connection connection)
Releases the specified connection and returns it to the active pool. |
java.sql.Connection |
getConnection()
Gets the next available connection. |
TableCreatingConnection |
getTableCreatingConnection()
Gets a TableCreatingConnection. |
void |
run()
|
java.lang.String |
toString()
Converts this class object into a meaningful string. |
int |
totalConnections()
Provides the total number of connections present including those that are busy and those that are available. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public ConnectionPool(java.lang.String driver,
java.lang.String url,
java.lang.String username,
java.lang.String password,
int initialConnections,
int maxConnections,
boolean waitIfBusy)
throws java.sql.SQLException
Constructs a ConnectionPool based on the calling arguments.
driver - The JDBC driver class name.url - The JDBC connection URL.username - The database user name.password - The database password.initialConnections - The minimum number of connections possible.maxConnections - The maximum number of connections possible.waitIfBusy - Boolean flag that determines whether to wait if there
are no more available connections. If set to true, it will wait until a
connection becomes available. If set to false, it will throw
SQLException when a connection is requested and there are no
more available connections.
java.sql.SQLException - If the connection pool cannot be established for
any reason.
public ConnectionPool(java.lang.String driver,
java.lang.String url,
java.lang.String username,
java.lang.String password,
int initialConnections,
int maxConnections,
boolean waitIfBusy,
DDLConverter ddlConverter)
throws java.sql.SQLException
driver - The JDBC driver class name.url - The JDBC connection URL.username - The database user name.password - The he database password.initialConnections - The minimum number of connections possible.maxConnections - The maximum number of connections possible.waitIfBusy - Boolean flag that determines whether to wait if there
are no more available connections. If set to true, it will wait
until a connection becomes available. If set to false, it will throw
SQLException when a connection is requested and there
are no more available connections.ddlConverter - The DDLConverter that the TableCreatingConnections
should use when createTable(TableSpec) is called.
java.sql.SQLException - If the connection pool cannot be established for
any reason.| Method Detail |
public TableCreatingConnection getTableCreatingConnection()
throws java.sql.SQLException
java.sql.SQLException - If there is any propblem in getting the SQL
connection.
public java.sql.Connection getConnection()
throws java.sql.SQLException
Gets the next available connection.
java.sql.SQLException - If the maximum number of connections has been reached
or there is some other problem in obtaining the connection.public void run()
run in interface java.lang.Runnablepublic void free(java.sql.Connection connection)
Releases the specified connection and returns it to the active pool.
connection - A JDBC connection.public int totalConnections()
Provides the total number of connections present including those that are busy and those that are available.
public void closeAllConnections()
Closes all the connections. Use with caution: be sure no connections are in use before calling. Note that you are not required to call this when done with a ConnectionPool, since connections are guaranteed to be closed when garbage collected. But this method gives more control regarding when the connections are closed.
public java.lang.String toString()
Converts this class object into a meaningful string.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||