Java Doc for ConnectionPoolManager.java in  » Database-JDBC-Connection-Pool » DBPool » snaq » db » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database JDBC Connection Pool » DBPool » snaq.db 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   snaq.util.LogUtil
      snaq.db.ConnectionPoolManager

ConnectionPoolManager
final public class ConnectionPoolManager extends LogUtil implements Comparable(Code)

Class to provide access and management for multiple connection pools defined in a properties file or object. Clients get access to each defined instance through one of the static getInstance() methods and can then check-out and check-in database connections from the pools defined by that manager.

Each successful call to a getInstance() method also increments an internal counter which keeps a record of the number of clients which hold a reference to that particular pool manager. When each client has finished using a pool manager it should call the release() method to let the manager know that it is no longer needed by that client, so it can clean up it's resources as necessary. The resources will not be released until the clients counter has reached zero. It is therefore necessary to allocate and release your pool manager references carefully.

Properties for a manager can be specified in three different ways.

  1. Properties file located in CLASSPATH
  2. Properties file referenced explicitly (with a File object)
  3. Properties object
  1. A CLASSPATH located properties file can simply be accessed using the method getInstance(name) where name is the name of the properties file specified as a string.
  2. To specify a properties file which is not in the CLASSPATH use the method getInstance(File). This same file handle must be used each time you want to obtain the instance in this way.
  3. To specify the pools using a Properties object a call must be made to the createInstance(Properties) method. This method creates the ConnectionPoolManager instance and makes it available via the getInstance() method.

Note: The getInstance() method can return one of two possible instances depending on the previous calls made to the pool manager. If the createInstance(Properties) method has previously been called successfully then it will return this manually created instance. Otherwise it will attempt to return an instance relating to the default properties file (dbpool.properties) within the CLASSPATH, if it exists.

The properties given to the manager specify which JDBC drivers to use to access the relevant databases, and also defines the characteristics of each connection pool. The properties required/allowed are as follows (those marked with * are mandatory):

 drivers*               Class names of required JDBC Drivers (comma/space delimited)
 logfile*               Filename of logfile
 <poolname>.url*        The JDBC URL for the database
 <poolname>.user        Database username for login
 <poolname>.password    Database password for login
 <poolname>.maxpool     The maximum number of pooled connections (0 if none)
 <poolname>.maxconn     The maximum number of possible connections (0 if no limit)
 <poolname>.expiry      The connection expiry time in seconds (0 if no expiry)
 <poolname>.init        The initial number of connections to create (default:0)
 <poolname>.validator   Class name of connection validator (optional)
 <poolname>.decoder     Class name of password decoder (optional)
 <poolname>.cache       Whether to cache Statements (optional, default:true)
 <poolname>.debug       Whether to log debug info (optional, default:false)
 <poolname>.prop.XXX    Passes property XXX and it's value to the JDBC driver
 <poolname>.async       Whether to use asynchronous connection destruction (optional, default:false)
 <poolname>.logfile     Filename of logfile for this pool (optional)
 <poolname>.dateformat  SimpleDateFormat formatting string for log entries (optional)
 

Multiple pools can be specified provided they each use a different pool name. The validator property optionally specifies the name of a class to be used for validating the database connections. The default connection validation simply performs a test using Connection.isClosed(). This test is not 100% reliable as the Java API documentation specifies that it only returns true if the connection has been explicitly closed. If more rigorous connection validation is required you can either use the provided class snaq.db.AutoCommitValidator or write your own validation class which should implement the ConnectionValidator interface.


See Also:   snaq.db.AutoCommitValidator
See Also:   snaq.db.ConnectionValidator
author:
   Giles Winstanley


Field Summary
protected  intclients
    


Method Summary
public  intcompareTo(Object o)
     Compares this instances to other instances by name.
public static synchronized  voidcreateInstance(Properties props)
     Creates a singleton instance of the ConnectionPoolManager for the specified Properties object.
public  ConnectiongetConnection(String name)
     Returns an open connection from the specified pool.
public  ConnectiongetConnection(String name, long time)
     Returns an open connection from the specified pool. If one is not available, and the max number of connections has not been reached, a new connection is created.
public static synchronized  ConnectionPoolManagergetInstance(String propsFile)
     Returns the singleton instance of the ConnectionPoolManager for the specified properties file.
public static synchronized  ConnectionPoolManagergetInstance(File propsFile)
     Returns the singleton instance of the ConnectionPoolManager for the specified properties file.
public static synchronized  ConnectionPoolManagergetInstance()
     Returns the standard singleton instance of the ConnectionPoolManager.
public static  SetgetInstances()
     Returns a Set containing all the current ConnectionPoolManager instances.
public  ConnectionPoolgetPool(String name)
     Returns a connection pool.
public  ConnectionPool[]getPools()
     Returns all the current connection pools maintained by this manager.
public static  Enumerationinstances()
     Returns an enumeration of all the available ConnectionPoolManager instances.
public synchronized  booleanisReleased()
     Returns whether this instance has been released (and therefore is unusable).
public synchronized  voidrelease()
     Releases all resources for this ConnectionPoolManager, and deregisters JDBC drivers if necessary.
public  voidsetLog(OutputStream out)
     Convenience method to override LogUtil method to set log for pools.
public  voidsetLog(PrintStream ps)
     Convenience method to override LogUtil method to set log for pools.
public synchronized  voidsetValidator(ConnectionValidator cv)
     Convenience method to set the validator class for all managed connection pools.
public  StringtoString()
     Returns a descriptive string for this instance.

Field Detail
clients
protected int clients(Code)





Method Detail
compareTo
public int compareTo(Object o)(Code)
Compares this instances to other instances by name.



createInstance
public static synchronized void createInstance(Properties props)(Code)
Creates a singleton instance of the ConnectionPoolManager for the specified Properties object. To subsequently use this instance user's should call the getInstance() method. This mechanism is used to provide the maximum separation between creation and use of this instance to avoid haphazard changes to any referenced Properties onject that may occur between calls. (This method can only be used successfully if no default properties instance exists and is in use at the time of calling.)
Parameters:
  props - Properties object to use
throws:
  RuntimeException - if default properties instance already exists and is in use



getConnection
public Connection getConnection(String name) throws SQLException(Code)
Returns an open connection from the specified pool. If one is not available, and the max number of connections has not been reached, a new connection is created.
Parameters:
  name - pool name as defined in the properties file a connection, or null if unable to obtain one



getConnection
public Connection getConnection(String name, long time) throws SQLException(Code)
Returns an open connection from the specified pool. If one is not available, and the max number of connections has not been reached, a new connection is created. If the max number has been reached, waits until one is available or the specified time has elapsed.
Parameters:
  name - pool name as defined in the properties file
Parameters:
  time - number of milliseconds to wait the connection or null



getInstance
public static synchronized ConnectionPoolManager getInstance(String propsFile) throws IOException(Code)
Returns the singleton instance of the ConnectionPoolManager for the specified properties file.
Parameters:
  propsFile - filename of the properties file to use (path info should not be specified; available CLASSPATH will be searched for the properties file) instance of ConnectionPoolManager relating to the specified properties file
throws:
  IOException - if there was an problem loading the properties



getInstance
public static synchronized ConnectionPoolManager getInstance(File propsFile) throws IOException(Code)
Returns the singleton instance of the ConnectionPoolManager for the specified properties file.
Parameters:
  propsFile - filename of the properties file to use (path info should not be specified; available CLASSPATH will be searched for the properties file) instance of ConnectionPoolManager relating to the specified properties file
throws:
  IOException - if there was an problem loading the properties



getInstance
public static synchronized ConnectionPoolManager getInstance() throws IOException(Code)
Returns the standard singleton instance of the ConnectionPoolManager. If an instance has been obtained with a user-specified Properties object then this instance is returned, otherwise an attempt is made to return an instance using the default properties file (dbpool.properties).
throws:
  IOException - if there was an problem loading the properties



getInstances
public static Set getInstances()(Code)
Returns a Set containing all the current ConnectionPoolManager instances. This method is included for convenience for external monitoring. Clients wanting to obtain an instance for using connections should NOT use this method. all current instances of ConnectionPoolManager.



getPool
public ConnectionPool getPool(String name)(Code)
Returns a connection pool. (This is only provided as a convenience method to allow fine-tuning in exceptional circumstances.)
Parameters:
  name - pool name as defined in the properties file the pool or null



getPools
public ConnectionPool[] getPools()(Code)
Returns all the current connection pools maintained by this manager. (This is only provided as a convenience method.) array of ConnectionPool objects



instances
public static Enumeration instances()(Code)
Returns an enumeration of all the available ConnectionPoolManager instances. This method is included for convenience for external monitoring. Clients wanting to obtain an instance for using connections should NOT use this method.



isReleased
public synchronized boolean isReleased()(Code)
Returns whether this instance has been released (and therefore is unusable).



release
public synchronized void release()(Code)
Releases all resources for this ConnectionPoolManager, and deregisters JDBC drivers if necessary. Any connections still in use are forcibly closed.



setLog
public void setLog(OutputStream out)(Code)
Convenience method to override LogUtil method to set log for pools.



setLog
public void setLog(PrintStream ps)(Code)
Convenience method to override LogUtil method to set log for pools.



setValidator
public synchronized void setValidator(ConnectionValidator cv)(Code)
Convenience method to set the validator class for all managed connection pools.



toString
public String toString()(Code)
Returns a descriptive string for this instance.



Fields inherited from snaq.util.LogUtil
protected DateFormat dateFormatddf(Code)(Java Doc)
protected boolean debug(Code)(Java Doc)
protected PrintStream log(Code)(Java Doc)
protected boolean logging(Code)(Java Doc)

Methods inherited from snaq.util.LogUtil
public synchronized void close()(Code)(Java Doc)
public PrintStream getLogStream()(Code)(Java Doc)
public boolean isDebug()(Code)(Java Doc)
public boolean isLogging()(Code)(Java Doc)
public synchronized void log(String prefix, String logEntry)(Code)(Java Doc)
public void log(String logEntry)(Code)(Java Doc)
public void log(Throwable e, String prefix, String logEntry)(Code)(Java Doc)
public void log(Throwable e, String logEntry)(Code)(Java Doc)
public void log(Throwable e)(Code)(Java Doc)
public synchronized void setDateFormat(DateFormat df)(Code)(Java Doc)
public void setDebug(boolean b)(Code)(Java Doc)
public synchronized void setLog(OutputStream out)(Code)(Java Doc)
public synchronized void setLog(PrintStream ps)(Code)(Java Doc)
public void setLogging(boolean b)(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.