Java Doc for DBPool.java in  » EJB-Server-resin-3.1.5 » resin » com » caucho » sql » 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 » EJB Server resin 3.1.5 » resin » com.caucho.sql 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.caucho.sql.DBPool

DBPool
public class DBPool implements DataSource,java.io.Serializable,HandleAware(Code)
Manages a pool of database connections. In addition, DBPool configures the database connection from a configuration file.

Like JDBC 2.0 pooling, DBPool returns a wrapped Connection. Applications can use that connection just like an unpooled connection. It is more important than ever to close() the connection, because the close returns the connection to the connection pool.

Example using DataSource JNDI style (recommended)


 Context env = (Context) new InitialContext().lookup("java:comp/env");
 DataSource pool = (DataSource) env.lookup("jdbc/test");
 Connection conn = pool.getConnection();
 try {
 ... // normal connection stuff
 } finally {
 conn.close();
 }
 

Configuration


 <database name='jdbc/test'>
 <init>
 <driver>postgresql.Driver</driver>
 <url>jdbc:postgresql://localhost/test</url>
 <user>ferg</user>
 <password>foobar</password>
 </init>
 </database>
 

Pool limits and timeouts

The pool will only allow getMaxConnections() connections alive at a time. If getMaxConnection connections are already active, getPooledConnection will block waiting for an available connection. The wait is timed. If connection-wait-time passes and there is still no connection, getPooledConnection create a new connection anyway.

Connections will only stay in the pool for about 5 seconds. After that they will be removed and closed. This reduces the load on the DB and also protects against the database dropping old connections.



Field Summary
final protected static  Loggerlog
    

Constructor Summary
public  DBPool()
     Null constructor for the Driver interface; called by the JNDI configuration.

Method Summary
public  voidcloseIdleConnections()
     Clears the pool.
public  DriverConfigcreateBackupDriver()
    
public  ConnectionConfigcreateConnection()
    
public  DriverConfigcreateDriver()
    
public  intgetActiveConnections()
     Get the total number of connections in use by the program.
public  ConnectiongetConnection()
     Returns a new or pooled connection.
public  ConnectiongetConnection(String user, String password)
     Return a connection.
public  longgetConnectionWaitTime()
     Gets the time to wait for a connection when all are used.
public  StringgetJndiName()
    
public  PrintWritergetLogWriter()
    
public  intgetLoginTimeout()
    
public  longgetMaxActiveTime()
     Get the time in milliseconds a connection can remain active.
public  intgetMaxConnections()
     Get the maximum number of pooled connections.
public  intgetMaxIdleCount()
     Get the maximum number of connections in the idle pool.
public  longgetMaxIdleTime()
     Get the time in milliseconds a connection will remain in the pool before being closed.
public  intgetMaxOverflowConnections()
     The number of connections to overflow if the connection pool fills and there's a timeout.
public  longgetMaxPoolTime()
     Get the time in milliseconds a connection will remain in the pool before being closed.
public  StringgetName()
    
public  StringgetPassword()
    
public  longgetPingInterval()
    
public  booleangetPingOnIdle()
     If true, the pool will ping in the idle pool.
public  booleangetPingOnReuse()
     If true, the pool will ping when attempting to reuse a connection.
public  StringgetPingTable()
     Get the table to 'ping' to see if the connection is still live.
public  intgetPreparedStatementCacheSize()
     Returns the prepared statement cache size.
public  intgetTotalConnections()
    
public  StringgetURL()
    
public  StringgetUser()
     Returns the connection's user (compat).
public  voidinit()
     Initialize the pool.
public  booleanisWrapperFor(Class iface)
    
public  booleanisXA()
     Returns true if this is transactional.
public  voidmarkForPoolRemoval(ManagedConnectionImpl mConn)
    
public  voidsetCloseDanglingConnections(boolean isClose)
     Set true if dangling connections should be closed.
public  voidsetConnectionWaitTime(Period waitTime)
     Sets the time to wait for a connection when all are used.
public  voidsetInitParam(InitParam init)
     Sets a driver parameter (compat).
public  voidsetJDBCDriver(Driver jdbcDriver)
     Sets the jdbc-driver config.
public  voidsetJndiName(String name)
     Sets the Pool's JNDI name.
public  voidsetLogWriter(PrintWriter log)
    
public  voidsetLoginTimeout(int timeout)
    
public  voidsetMaxActiveTime(Period maxActiveTime)
     Set the time in milliseconds a connection can remain active.
public  voidsetMaxConnections(int maxConnections)
     Sets the maximum number of pooled connections.
public  voidsetMaxCreateConnections(int maxCreateConnections)
     The number of connections to create at any one time.
public  voidsetMaxIdleCount(int count)
     Set the maximum number of connections in the idle pool.
public  voidsetMaxIdleTime(Period idleTime)
     Set the time in milliseconds a connection will remain in the pool before being closed.
public  voidsetMaxOverflowConnections(int maxOverflowConnections)
     The number of connections to overflow if the connection pool fills and there's a timeout.
public  voidsetMaxPoolTime(Period maxPoolTime)
     Set the time in milliseconds a connection will remain in the pool before being closed.
public  voidsetName(String name)
     Sets the Pool's WebBeans name.
public  voidsetPassword(String password)
    
public  voidsetPing(boolean ping)
     Set the table to 'ping' to see if the connection is still live.
public  voidsetPingInterval(Period interval)
    
public  voidsetPingOnIdle(boolean pingOnIdle)
     Set the table to 'ping' to see if the connection is still live.
public  voidsetPingOnReuse(boolean pingOnReuse)
     Set the table to 'ping' to see if the connection is still live.
public  voidsetPingQuery(String pingQuery)
     Set the query to 'ping' to see if the connection is still live.
public  voidsetPingTable(String pingTable)
     Set the table to 'ping' to see if the connection is still live.
public  voidsetPoolDataSource(ConnectionPoolDataSource poolDataSource)
     Sets the jdbc-driver config.
public  voidsetPreparedStatementCacheSize(int size)
     Sets the prepared statement cache size.
public  voidsetSaveAllocationStackTrace(boolean save)
     Set true if the stack trace should be saved on allocation.
public  voidsetSerializationHandle(Object handle)
    
public  voidsetSpy(boolean isSpy)
     Set the output for spying.
public  voidsetTransactionManager(TransactionManagerImpl tm)
     Set the transaction manager for this pool.
public  voidsetTransactionTimeout(Period period)
     Sets the transaction timeout.
public  voidsetURL(String url)
    
public  voidsetUser(String user)
     Sets the connection's user.
public  voidsetVar(String var)
     Sets the Pool's var.
public  voidsetWrapStatements(boolean isWrap)
     Set true if statement should be wrapped.
public  voidsetXA(boolean isTransactional)
     Returns true if this is transactional.
public  voidsetXADataSource(XADataSource xaDataSource)
     Sets the jdbc-driver config.
public  voidsetXAForbidSameRM(boolean isXAForbidSameRM)
     Returns true if this is transactional.
public  StringtoString()
     Returns a string description of the pool.
public  Tunwrap(Class<T> iface)
    

Field Detail
log
final protected static Logger log(Code)




Constructor Detail
DBPool
public DBPool()(Code)
Null constructor for the Driver interface; called by the JNDI configuration. Applications should not call this directly.




Method Detail
closeIdleConnections
public void closeIdleConnections()(Code)
Clears the pool.



createBackupDriver
public DriverConfig createBackupDriver() throws ConfigException(Code)
Sets a custom driver (or data source)



createConnection
public ConnectionConfig createConnection() throws ConfigException(Code)
Configure the initial connection



createDriver
public DriverConfig createDriver() throws ConfigException(Code)
Sets a custom driver (or data source)



getActiveConnections
public int getActiveConnections()(Code)
Get the total number of connections in use by the program.



getConnection
public Connection getConnection() throws SQLException(Code)
Returns a new or pooled connection.



getConnection
public Connection getConnection(String user, String password) throws SQLException(Code)
Return a connection. The connection will only be pooled if user and password match the configuration. In general, applications should use the null-argument getConnection().
Parameters:
  user - database user
Parameters:
  password - database password a database connection



getConnectionWaitTime
public long getConnectionWaitTime()(Code)
Gets the time to wait for a connection when all are used.



getJndiName
public String getJndiName()(Code)
Returns the Pool's name



getLogWriter
public PrintWriter getLogWriter() throws SQLException(Code)
Gets the log writer



getLoginTimeout
public int getLoginTimeout() throws SQLException(Code)
Returns the login timeout



getMaxActiveTime
public long getMaxActiveTime()(Code)
Get the time in milliseconds a connection can remain active.



getMaxConnections
public int getMaxConnections()(Code)
Get the maximum number of pooled connections.



getMaxIdleCount
public int getMaxIdleCount()(Code)
Get the maximum number of connections in the idle pool.



getMaxIdleTime
public long getMaxIdleTime()(Code)
Get the time in milliseconds a connection will remain in the pool before being closed.



getMaxOverflowConnections
public int getMaxOverflowConnections()(Code)
The number of connections to overflow if the connection pool fills and there's a timeout.



getMaxPoolTime
public long getMaxPoolTime()(Code)
Get the time in milliseconds a connection will remain in the pool before being closed.



getName
public String getName()(Code)
Returns the Pool's name



getPassword
public String getPassword()(Code)
Returns the connection's password



getPingInterval
public long getPingInterval()(Code)
Gets how often the ping for ping-on-idle



getPingOnIdle
public boolean getPingOnIdle()(Code)
If true, the pool will ping in the idle pool.



getPingOnReuse
public boolean getPingOnReuse()(Code)
If true, the pool will ping when attempting to reuse a connection.



getPingTable
public String getPingTable()(Code)
Get the table to 'ping' to see if the connection is still live.



getPreparedStatementCacheSize
public int getPreparedStatementCacheSize()(Code)
Returns the prepared statement cache size.



getTotalConnections
public int getTotalConnections()(Code)
Get the total number of connections



getURL
public String getURL()(Code)
Return the url



getUser
public String getUser()(Code)
Returns the connection's user (compat).



init
public void init() throws Exception(Code)
Initialize the pool.



isWrapperFor
public boolean isWrapperFor(Class iface) throws SQLException(Code)



isXA
public boolean isXA()(Code)
Returns true if this is transactional.



markForPoolRemoval
public void markForPoolRemoval(ManagedConnectionImpl mConn)(Code)



setCloseDanglingConnections
public void setCloseDanglingConnections(boolean isClose)(Code)
Set true if dangling connections should be closed.



setConnectionWaitTime
public void setConnectionWaitTime(Period waitTime)(Code)
Sets the time to wait for a connection when all are used.



setInitParam
public void setInitParam(InitParam init)(Code)
Sets a driver parameter (compat).



setJDBCDriver
public void setJDBCDriver(Driver jdbcDriver) throws SQLException(Code)
Sets the jdbc-driver config.



setJndiName
public void setJndiName(String name)(Code)
Sets the Pool's JNDI name. Also puts the pool in the classloader's list of pools.



setLogWriter
public void setLogWriter(PrintWriter log) throws SQLException(Code)
Sets the log writer



setLoginTimeout
public void setLoginTimeout(int timeout) throws SQLException(Code)
Sets the login timeout



setMaxActiveTime
public void setMaxActiveTime(Period maxActiveTime)(Code)
Set the time in milliseconds a connection can remain active.



setMaxConnections
public void setMaxConnections(int maxConnections) throws ConfigException(Code)
Sets the maximum number of pooled connections.



setMaxCreateConnections
public void setMaxCreateConnections(int maxCreateConnections) throws ConfigException(Code)
The number of connections to create at any one time.



setMaxIdleCount
public void setMaxIdleCount(int count)(Code)
Set the maximum number of connections in the idle pool. being closed.



setMaxIdleTime
public void setMaxIdleTime(Period idleTime)(Code)
Set the time in milliseconds a connection will remain in the pool before being closed.



setMaxOverflowConnections
public void setMaxOverflowConnections(int maxOverflowConnections)(Code)
The number of connections to overflow if the connection pool fills and there's a timeout.



setMaxPoolTime
public void setMaxPoolTime(Period maxPoolTime)(Code)
Set the time in milliseconds a connection will remain in the pool before being closed.



setName
public void setName(String name)(Code)
Sets the Pool's WebBeans name. Also puts the pool in the classloader's list of pools.



setPassword
public void setPassword(String password)(Code)
Sets the connection's password



setPing
public void setPing(boolean ping)(Code)
Set the table to 'ping' to see if the connection is still live.



setPingInterval
public void setPingInterval(Period interval)(Code)
Sets the time to ping for ping-on-idle



setPingOnIdle
public void setPingOnIdle(boolean pingOnIdle)(Code)
Set the table to 'ping' to see if the connection is still live.



setPingOnReuse
public void setPingOnReuse(boolean pingOnReuse)(Code)
Set the table to 'ping' to see if the connection is still live.



setPingQuery
public void setPingQuery(String pingQuery)(Code)
Set the query to 'ping' to see if the connection is still live.
Parameters:
  pingQuery - SQL to use for ping.



setPingTable
public void setPingTable(String pingTable)(Code)
Set the table to 'ping' to see if the connection is still live.
Parameters:
  pingTable - name of the SQL table to ping.



setPoolDataSource
public void setPoolDataSource(ConnectionPoolDataSource poolDataSource) throws SQLException(Code)
Sets the jdbc-driver config.



setPreparedStatementCacheSize
public void setPreparedStatementCacheSize(int size)(Code)
Sets the prepared statement cache size.



setSaveAllocationStackTrace
public void setSaveAllocationStackTrace(boolean save)(Code)
Set true if the stack trace should be saved on allocation.



setSerializationHandle
public void setSerializationHandle(Object handle)(Code)
HandleAware callback to set the webbeans handle for serialization



setSpy
public void setSpy(boolean isSpy) throws IOException(Code)
Set the output for spying.



setTransactionManager
public void setTransactionManager(TransactionManagerImpl tm)(Code)
Set the transaction manager for this pool.



setTransactionTimeout
public void setTransactionTimeout(Period period)(Code)
Sets the transaction timeout.



setURL
public void setURL(String url) throws ConfigException(Code)
Sets the jdbc-driver URL



setUser
public void setUser(String user)(Code)
Sets the connection's user.



setVar
public void setVar(String var)(Code)
Sets the Pool's var.



setWrapStatements
public void setWrapStatements(boolean isWrap)(Code)
Set true if statement should be wrapped.



setXA
public void setXA(boolean isTransactional)(Code)
Returns true if this is transactional.



setXADataSource
public void setXADataSource(XADataSource xaDataSource) throws SQLException(Code)
Sets the jdbc-driver config.



setXAForbidSameRM
public void setXAForbidSameRM(boolean isXAForbidSameRM)(Code)
Returns true if this is transactional.



toString
public String toString()(Code)
Returns a string description of the pool.



unwrap
public T unwrap(Class<T> iface) throws SQLException(Code)



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.