Java Doc for DBPoolImpl.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.DBPoolImpl

DBPoolImpl
public class DBPoolImpl implements AlarmListener,EnvironmentListener(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 public static  StringPROPERTY_PASSWORD
     The key used to look into the properties passed to the connect method to find the password.
final public static  StringPROPERTY_USER
     The key used to look into the properties passed to the connect method to find the username.
final protected static  Loggerlog
    

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

Method Summary
public  voidclose()
     Close the pool, closing the connections.
public  voidcloseIdleConnections()
     Closes the idle connections in the pool.
public  DriverConfigcreateBackupDriver()
     Returns the driver config.
public  ConnectionConfigcreateConnection()
     Creates the connection config.
public  DriverConfigcreateDriver()
     Returns the driver config.
 intcreatePoolId()
    
public  voidenvironmentConfig(EnvironmentClassLoader loader)
     Callback when the environment configures.
public  voidenvironmentStart(EnvironmentClassLoader loader)
     Callback when the environment starts.
public  voidenvironmentStop(EnvironmentClassLoader loader)
     Callback when the class loader dies.
public  voidforceClose()
     Close all the connections in the pool.
public  ConnectionConfiggetConnectionConfig()
     Returns the connection config.
public  longgetConnectionWaitTime()
     Gets the time to wait for a connection when all are used.
public  PrintWritergetLogWriter()
     Sets the debugging log for the connection.
public  intgetLoginTimeout()
     Gets the timeout for a database login.
 ManagedConnectionFactorygetManagedConnectionFactory()
     Returns the managed connection factory.
public  longgetMaxActiveTime()
     Get the time in milliseconds a connection can remain active.
public  intgetMaxCloseStatements()
     Gets the max statement.
public  intgetMaxConnections()
     Get the maximum number of pooled connections.
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  StringgetPingQuery()
     Returns the ping query.
public  StringgetPingTable()
     Get the table to 'ping' to see if the connection is still live.
public  intgetPreparedStatementCacheSize()
     Returns the prepared statement cache size.
public  SpyDataSourcegetSpyDataSource()
     Returns the next spy id.
public  intgetTotalConnections()
    
public  longgetTransactionTimeout()
     Gets the transaction timeout.
public  StringgetURL()
    
public  StringgetUser()
     Returns the connection's user.
public  voidhandleAlarm(Alarm alarm)
     At the alarm, close all connections which have been sitting in the pool for too long.
public  voidinit()
     Initialize the pool.
synchronized  voidinitDataSource()
     Initialize the pool's data source
  • If data-source is set, look it up in JNDI.
public  booleanisClosed()
     Returns true if the pool is closed.
public  booleanisLocalTransaction()
     Returns true if there is a valid local transactino associated with the database.
public  booleanisPing()
     Returns true if pinging is enabled.
public  booleanisSpy()
     Return true for a spy.
public  booleanisTransactional()
     Returns true if the pool supports transactions.
public  booleanisWrapStatements()
     Sets true if statements should be wrapped.
public  booleanisXA()
     Returns true if this is transactional.
public  booleanisXAForbidSameRM()
     Returns true if transactions should force isSameRM to be false.
public  booleanisXATransaction()
     Returns true if there is a valid XAResource associated with the database.
public  StringnewSpyId()
     Returns the next spy id.
public  voidsetConnectionWaitTime(Period waitTime)
     Sets the time to wait for a connection when all are used.
public  voidsetInitParam(InitParam init)
     Sets a driver parameter.
public  voidsetJDBCDriver(Driver jdbcDriver)
     Sets the jdbc-driver config.
public  voidsetLogWriter(PrintWriter out)
     Sets the debugging log for the connection.
public  voidsetLoginTimeout(int seconds)
     Sets the timeout for a database login.
public  voidsetMaxActiveTime(Period maxActiveTime)
     Set the time in milliseconds a connection can remain active.
public  voidsetMaxCloseStatements(int max)
     Sets the max statement.
public  voidsetMaxConnections(int maxConnections)
     Sets the maximum number of pooled connections.
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 name.
public  voidsetPassword(String password)
    
public  voidsetPing(boolean ping)
     Set true if pinging is enabled.
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)
     Sets the ping query.
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  voidsetSpy(boolean isSpy)
     Set the output for spying.
public  voidsetTransactionManager(TransactionManager tm)
     Set the transaction manager for this pool.
public  voidsetTransactionTimeout(Period period)
     Sets the transaction timeout.
public  voidsetURL(String url)
     Sets the jdbc-driver config.
public  voidsetUser(String user)
     Sets the connection's user.
public  voidsetWrapStatements(boolean isWrap)
     Sets true if statements 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 transactions should force isSameRM to be false.
public  StringtoString()
     Returns a string description of the pool.

Field Detail
PROPERTY_PASSWORD
final public static String PROPERTY_PASSWORD(Code)
The key used to look into the properties passed to the connect method to find the password.



PROPERTY_USER
final public static String PROPERTY_USER(Code)
The key used to look into the properties passed to the connect method to find the username.



log
final protected static Logger log(Code)




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




Method Detail
close
public void close()(Code)
Close the pool, closing the connections.



closeIdleConnections
public void closeIdleConnections()(Code)
Closes the idle connections in the pool.



createBackupDriver
public DriverConfig createBackupDriver()(Code)
Returns the driver config.



createConnection
public ConnectionConfig createConnection()(Code)
Creates the connection config.



createDriver
public DriverConfig createDriver()(Code)
Returns the driver config.



createPoolId
int createPoolId()(Code)



environmentConfig
public void environmentConfig(EnvironmentClassLoader loader)(Code)
Callback when the environment configures.



environmentStart
public void environmentStart(EnvironmentClassLoader loader)(Code)
Callback when the environment starts.



environmentStop
public void environmentStop(EnvironmentClassLoader loader)(Code)
Callback when the class loader dies.



forceClose
public void forceClose()(Code)
Close all the connections in the pool.



getConnectionConfig
public ConnectionConfig getConnectionConfig()(Code)
Returns the connection config.



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



getLogWriter
public PrintWriter getLogWriter() throws SQLException(Code)
Sets the debugging log for the connection.



getLoginTimeout
public int getLoginTimeout() throws SQLException(Code)
Gets the timeout for a database login.



getManagedConnectionFactory
ManagedConnectionFactory getManagedConnectionFactory()(Code)
Returns the managed connection factory.



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



getMaxCloseStatements
public int getMaxCloseStatements()(Code)
Gets the max statement.



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



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.



getPingQuery
public String getPingQuery()(Code)
Returns the ping query.



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.



getSpyDataSource
public SpyDataSource getSpyDataSource()(Code)
Returns the next spy id.



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



getTransactionTimeout
public long getTransactionTimeout()(Code)
Gets the transaction timeout.



getURL
public String getURL()(Code)



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



handleAlarm
public void handleAlarm(Alarm alarm)(Code)
At the alarm, close all connections which have been sitting in the pool for too long.
Parameters:
  alarm - the alarm event.



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



initDataSource
synchronized void initDataSource() throws SQLException(Code)
Initialize the pool's data source
  • If data-source is set, look it up in JNDI.
  • Else if the driver is a pooled or xa data source, use it.
  • Else create wrappers.



isClosed
public boolean isClosed()(Code)
Returns true if the pool is closed.



isLocalTransaction
public boolean isLocalTransaction()(Code)
Returns true if there is a valid local transactino associated with the database.



isPing
public boolean isPing()(Code)
Returns true if pinging is enabled.



isSpy
public boolean isSpy()(Code)
Return true for a spy.



isTransactional
public boolean isTransactional()(Code)
Returns true if the pool supports transactions.



isWrapStatements
public boolean isWrapStatements()(Code)
Sets true if statements should be wrapped.



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



isXAForbidSameRM
public boolean isXAForbidSameRM()(Code)
Returns true if transactions should force isSameRM to be false.



isXATransaction
public boolean isXATransaction()(Code)
Returns true if there is a valid XAResource associated with the database.



newSpyId
public String newSpyId()(Code)
Returns the next spy id.



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.



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



setLogWriter
public void setLogWriter(PrintWriter out) throws SQLException(Code)
Sets the debugging log for the connection.



setLoginTimeout
public void setLoginTimeout(int seconds) throws SQLException(Code)
Sets the timeout for a database login.



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



setMaxCloseStatements
public void setMaxCloseStatements(int max)(Code)
Sets the max statement.



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



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 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 true if pinging is enabled.



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)
Sets the ping query.



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.



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



setTransactionManager
public void setTransactionManager(TransactionManager 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 config.



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



setWrapStatements
public void setWrapStatements(boolean isWrap)(Code)
Sets true if statements 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 transactions should force isSameRM to be false.



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



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.