Java Doc for InstanceKeyDataSource.java in  » Database-JDBC-Connection-Pool » Connection-Pool-DBCP » org » apache » commons » dbcp » datasources » 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 » Connection Pool DBCP » org.apache.commons.dbcp.datasources 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.dbcp.datasources.InstanceKeyDataSource

All known Subclasses:   org.apache.commons.dbcp.datasources.PerUserPoolDataSource,  org.apache.commons.dbcp.datasources.SharedPoolDataSource,
InstanceKeyDataSource
abstract public class InstanceKeyDataSource implements DataSource,Referenceable,Serializable(Code)

The base class for SharedPoolDataSource and PerUserPoolDataSource. Many of the configuration properties are shared and defined here. This class is declared public in order to allow particular usage with commons-beanutils; do not make direct use of it outside of commons-dbcp.

A J2EE container will normally provide some method of initializing the DataSource whose attributes are presented as bean getters/setters and then deploying it via JNDI. It is then available to an application as a source of pooled logical connections to the database. The pool needs a source of physical connections. This source is in the form of a ConnectionPoolDataSource that can be specified via the InstanceKeyDataSource.setDataSourceName(String) used to lookup the source via JNDI.

Although normally used within a JNDI environment, A DataSource can be instantiated and initialized as any bean. In this case the ConnectionPoolDataSource will likely be instantiated in a similar manner. This class allows the physical source of connections to be attached directly to this pool using the InstanceKeyDataSource.setConnectionPoolDataSource(ConnectionPoolDataSource) method.

The dbcp package contains an adapter, org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS , that can be used to allow the use of DataSource's based on this class with jdbc driver implementations that do not supply a ConnectionPoolDataSource, but still provide a java.sql.Driver implementation.

The package documentation contains an example using catalina and JNDI and it also contains a non-JNDI example.


author:
   John D. McNally
version:
   $Revision: 500687 $ $Date: 2007-01-27 16:33:47 -0700 (Sat, 27 Jan 2007) $


Field Summary
final protected static  intUNKNOWN_TRANSACTIONISOLATION
     Internal constant to indicate the level is not set.
protected  StringinstanceKey
    
 PropertiesjndiEnvironment
     Environment that may be used to set up a jndi initial context.

Constructor Summary
public  InstanceKeyDataSource()
    

Method Summary
protected  voidassertInitializationAllowed()
     Throws an IllegalStateException, if a PooledConnection has already been requested.
abstract public  voidclose()
     Close pool being maintained by this datasource.
public  ConnectiongetConnection()
     Attempt to establish a database connection.
public  ConnectiongetConnection(String username, String password)
     Attempt to establish a database connection.
public  ConnectionPoolDataSourcegetConnectionPoolDataSource()
     Get the value of connectionPoolDataSource.
public  StringgetDataSourceName()
     Get the name of the ConnectionPoolDataSource which backs this pool.
public  intgetDefaultTransactionIsolation()
     Get the value of defaultTransactionIsolation, which defines the state of connections handed out from this pool.
public  StringgetDescription()
     Get the description.
public  StringgetJndiEnvironment(String key)
     Get the value of jndiEnvironment which is used when instantiating a jndi InitialContext.
public  PrintWritergetLogWriter()
     Get the value of logWriter.
public  intgetLoginTimeout()
     Get the value of loginTimeout.
public  intgetMinEvictableIdleTimeMillis()
     Returns the minimum amount of time an object may sit idle in the pool before it is eligable for eviction by the idle object evictor (if any).
public  intgetNumTestsPerEvictionRun()
     Returns the number of objects to examine during each run of the idle object evictor thread (if any).
abstract protected  PooledConnectionAndInfogetPooledConnectionAndInfo(String username, String password)
    
public  ReferencegetReference()
     Retrieves the Reference of this object. Note: InstanceKeyDataSource subclasses should override this method.
public  booleangetTestOnBorrow()
     When true, objects will be {*link PoolableObjectFactory#validateObject validated} before being returned by the {*link #borrowObject} method.
public  booleangetTestOnReturn()
     When true, objects will be {*link PoolableObjectFactory#validateObject validated} before being returned to the pool within the {*link #returnObject}.
public  booleangetTestWhileIdle()
     When true, objects will be {*link PoolableObjectFactory#validateObject validated} by the idle object evictor (if any).
public  intgetTimeBetweenEvictionRunsMillis()
     Returns the number of milliseconds to sleep between runs of the idle object evictor thread.
public  StringgetValidationQuery()
     The SQL query that will be used to validate connections from this pool before returning them to the caller.
public  booleanisDefaultAutoCommit()
     Get the value of defaultAutoCommit, which defines the state of connections handed out from this pool.
public  booleanisDefaultReadOnly()
     Get the value of defaultReadOnly, which defines the state of connections handed out from this pool.
public  booleanisRollbackAfterValidation()
     Whether a rollback will be issued after executing the SQL query that will be used to validate connections from this pool before returning them to the caller.
final public  booleanisTestOnBorrow()
    
final public  booleanisTestOnReturn()
    
final public  booleanisTestWhileIdle()
    
public  voidsetConnectionPoolDataSource(ConnectionPoolDataSource v)
     Set the backend ConnectionPoolDataSource.
public  voidsetDataSourceName(String v)
     Set the name of the ConnectionPoolDataSource which backs this pool.
public  voidsetDefaultAutoCommit(boolean v)
     Set the value of defaultAutoCommit, which defines the state of connections handed out from this pool.
public  voidsetDefaultReadOnly(boolean v)
     Set the value of defaultReadOnly, which defines the state of connections handed out from this pool.
public  voidsetDefaultTransactionIsolation(int v)
     Set the value of defaultTransactionIsolation, which defines the state of connections handed out from this pool.
public  voidsetDescription(String v)
     Set the description.
public  voidsetJndiEnvironment(String key, String value)
     Sets the value of the given JNDI environment property to be used when instantiating a JNDI InitialContext.
public  voidsetLogWriter(PrintWriter v)
     Set the value of logWriter.
public  voidsetLoginTimeout(int v)
     Set the value of loginTimeout.
public  voidsetMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis)
     Sets the minimum amount of time an object may sit idle in the pool before it is eligable for eviction by the idle object evictor (if any).
public  voidsetNumTestsPerEvictionRun(int numTestsPerEvictionRun)
     Sets the number of objects to examine during each run of the idle object evictor thread (if any).

When a negative value is supplied, ceil({*link #numIdle})/abs({*link #getNumTestsPerEvictionRun}) tests will be run.

public  voidsetRollbackAfterValidation(boolean rollbackAfterValidation)
     Whether a rollback will be issued after executing the SQL query that will be used to validate connections from this pool before returning them to the caller.
public  voidsetTestOnBorrow(boolean testOnBorrow)
     When true, objects will be {*link PoolableObjectFactory#validateObject validated} before being returned by the {*link #borrowObject} method.
public  voidsetTestOnReturn(boolean testOnReturn)
     When true, objects will be {*link PoolableObjectFactory#validateObject validated} before being returned to the pool within the {*link #returnObject}.
public  voidsetTestWhileIdle(boolean testWhileIdle)
     When true, objects will be {*link PoolableObjectFactory#validateObject validated} by the idle object evictor (if any).
public  voidsetTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis)
     Sets the number of milliseconds to sleep between runs of the idle object evictor thread.
public  voidsetValidationQuery(String validationQuery)
     The SQL query that will be used to validate connections from this pool before returning them to the caller.
abstract protected  voidsetupDefaults(Connection con, String username)
    
protected  ConnectionPoolDataSourcetestCPDS(String username, String password)
    
protected  bytewhenExhaustedAction(int maxActive, int maxWait)
    

Field Detail
UNKNOWN_TRANSACTIONISOLATION
final protected static int UNKNOWN_TRANSACTIONISOLATION(Code)
Internal constant to indicate the level is not set.



instanceKey
protected String instanceKey(Code)



jndiEnvironment
Properties jndiEnvironment(Code)
Environment that may be used to set up a jndi initial context.




Constructor Detail
InstanceKeyDataSource
public InstanceKeyDataSource()(Code)
Default no-arg constructor for Serialization




Method Detail
assertInitializationAllowed
protected void assertInitializationAllowed() throws IllegalStateException(Code)
Throws an IllegalStateException, if a PooledConnection has already been requested.



close
abstract public void close() throws Exception(Code)
Close pool being maintained by this datasource.



getConnection
public Connection getConnection() throws SQLException(Code)
Attempt to establish a database connection.



getConnection
public Connection getConnection(String username, String password) throws SQLException(Code)
Attempt to establish a database connection.



getConnectionPoolDataSource
public ConnectionPoolDataSource getConnectionPoolDataSource()(Code)
Get the value of connectionPoolDataSource. This method will return null, if the backing datasource is being accessed via jndi. value of connectionPoolDataSource.



getDataSourceName
public String getDataSourceName()(Code)
Get the name of the ConnectionPoolDataSource which backs this pool. This name is used to look up the datasource from a jndi service provider. value of dataSourceName.



getDefaultTransactionIsolation
public int getDefaultTransactionIsolation()(Code)
Get the value of defaultTransactionIsolation, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setTransactionIsolation(int). If this method returns -1, the default is JDBC driver dependent. value of defaultTransactionIsolation.



getDescription
public String getDescription()(Code)
Get the description. This property is defined by jdbc as for use with GUI (or other) tools that might deploy the datasource. It serves no internal purpose. value of description.



getJndiEnvironment
public String getJndiEnvironment(String key)(Code)
Get the value of jndiEnvironment which is used when instantiating a jndi InitialContext. This InitialContext is used to locate the backend ConnectionPoolDataSource. value of jndiEnvironment.



getLogWriter
public PrintWriter getLogWriter()(Code)
Get the value of logWriter. value of logWriter.



getLoginTimeout
public int getLoginTimeout()(Code)
Get the value of loginTimeout. value of loginTimeout.



getMinEvictableIdleTimeMillis
public int getMinEvictableIdleTimeMillis()(Code)
Returns the minimum amount of time an object may sit idle in the pool before it is eligable for eviction by the idle object evictor (if any).
See Also:   InstanceKeyDataSource.setMinEvictableIdleTimeMillis
See Also:   InstanceKeyDataSource.setTimeBetweenEvictionRunsMillis



getNumTestsPerEvictionRun
public int getNumTestsPerEvictionRun()(Code)
Returns the number of objects to examine during each run of the idle object evictor thread (if any).
See Also:   InstanceKeyDataSource.setNumTestsPerEvictionRun
See Also:   InstanceKeyDataSource.setTimeBetweenEvictionRunsMillis



getPooledConnectionAndInfo
abstract protected PooledConnectionAndInfo getPooledConnectionAndInfo(String username, String password) throws SQLException(Code)



getReference
public Reference getReference() throws NamingException(Code)
Retrieves the Reference of this object. Note: InstanceKeyDataSource subclasses should override this method. The implementaion included below is not robust and will be removed at the next major version DBCP release. The non-null Reference of this object.
exception:
  NamingException - If a naming exception was encounteredwhile retrieving the reference.



getTestOnBorrow
public boolean getTestOnBorrow()(Code)
When true, objects will be {*link PoolableObjectFactory#validateObject validated} before being returned by the {*link #borrowObject} method. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another.
See Also:   InstanceKeyDataSource.setTestOnBorrow



getTestOnReturn
public boolean getTestOnReturn()(Code)
When true, objects will be {*link PoolableObjectFactory#validateObject validated} before being returned to the pool within the {*link #returnObject}.
See Also:   InstanceKeyDataSource.setTestOnReturn



getTestWhileIdle
public boolean getTestWhileIdle()(Code)
When true, objects will be {*link PoolableObjectFactory#validateObject validated} by the idle object evictor (if any). If an object fails to validate, it will be dropped from the pool.
See Also:   InstanceKeyDataSource.setTestWhileIdle
See Also:   InstanceKeyDataSource.setTimeBetweenEvictionRunsMillis



getTimeBetweenEvictionRunsMillis
public int getTimeBetweenEvictionRunsMillis()(Code)
Returns the number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, no idle object evictor thread will be run.
See Also:   InstanceKeyDataSource.setTimeBetweenEvictionRunsMillis



getValidationQuery
public String getValidationQuery()(Code)
The SQL query that will be used to validate connections from this pool before returning them to the caller. If specified, this query MUST be an SQL SELECT statement that returns at least one row.



isDefaultAutoCommit
public boolean isDefaultAutoCommit()(Code)
Get the value of defaultAutoCommit, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setAutoCommit(boolean). The default is true. value of defaultAutoCommit.



isDefaultReadOnly
public boolean isDefaultReadOnly()(Code)
Get the value of defaultReadOnly, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setReadOnly(boolean). The default is false. value of defaultReadOnly.



isRollbackAfterValidation
public boolean isRollbackAfterValidation()(Code)
Whether a rollback will be issued after executing the SQL query that will be used to validate connections from this pool before returning them to the caller. true if a rollback will be issued after executing thevalidation query
since:
   1.2.2



isTestOnBorrow
final public boolean isTestOnBorrow()(Code)

See Also:   InstanceKeyDataSource.getTestOnBorrow



isTestOnReturn
final public boolean isTestOnReturn()(Code)

See Also:   InstanceKeyDataSource.getTestOnReturn



isTestWhileIdle
final public boolean isTestWhileIdle()(Code)

See Also:   InstanceKeyDataSource.getTestWhileIdle



setConnectionPoolDataSource
public void setConnectionPoolDataSource(ConnectionPoolDataSource v)(Code)
Set the backend ConnectionPoolDataSource. This property should not be set if using jndi to access the datasource.
Parameters:
  v - Value to assign to connectionPoolDataSource.



setDataSourceName
public void setDataSourceName(String v)(Code)
Set the name of the ConnectionPoolDataSource which backs this pool. This name is used to look up the datasource from a jndi service provider.
Parameters:
  v - Value to assign to dataSourceName.



setDefaultAutoCommit
public void setDefaultAutoCommit(boolean v)(Code)
Set the value of defaultAutoCommit, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setAutoCommit(boolean). The default is true.
Parameters:
  v - Value to assign to defaultAutoCommit.



setDefaultReadOnly
public void setDefaultReadOnly(boolean v)(Code)
Set the value of defaultReadOnly, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setReadOnly(boolean). The default is false.
Parameters:
  v - Value to assign to defaultReadOnly.



setDefaultTransactionIsolation
public void setDefaultTransactionIsolation(int v)(Code)
Set the value of defaultTransactionIsolation, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setTransactionIsolation(int). The default is JDBC driver dependent.
Parameters:
  v - Value to assign to defaultTransactionIsolation



setDescription
public void setDescription(String v)(Code)
Set the description. This property is defined by jdbc as for use with GUI (or other) tools that might deploy the datasource. It serves no internal purpose.
Parameters:
  v - Value to assign to description.



setJndiEnvironment
public void setJndiEnvironment(String key, String value)(Code)
Sets the value of the given JNDI environment property to be used when instantiating a JNDI InitialContext. This InitialContext is used to locate the backend ConnectionPoolDataSource.
Parameters:
  key - the JNDI environment property to set.
Parameters:
  value - the value assigned to specified JNDI environment property.



setLogWriter
public void setLogWriter(PrintWriter v)(Code)
Set the value of logWriter.
Parameters:
  v - Value to assign to logWriter.



setLoginTimeout
public void setLoginTimeout(int v)(Code)
Set the value of loginTimeout.
Parameters:
  v - Value to assign to loginTimeout.



setMinEvictableIdleTimeMillis
public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis)(Code)
Sets the minimum amount of time an object may sit idle in the pool before it is eligable for eviction by the idle object evictor (if any). When non-positive, no objects will be evicted from the pool due to idle time alone.
See Also:   InstanceKeyDataSource.getMinEvictableIdleTimeMillis
See Also:   InstanceKeyDataSource.setTimeBetweenEvictionRunsMillis



setNumTestsPerEvictionRun
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)(Code)
Sets the number of objects to examine during each run of the idle object evictor thread (if any).

When a negative value is supplied, ceil({*link #numIdle})/abs({*link #getNumTestsPerEvictionRun}) tests will be run. I.e., when the value is -n, roughly one nth of the idle objects will be tested per run.
See Also:   InstanceKeyDataSource.getNumTestsPerEvictionRun
See Also:   InstanceKeyDataSource.setTimeBetweenEvictionRunsMillis




setRollbackAfterValidation
public void setRollbackAfterValidation(boolean rollbackAfterValidation)(Code)
Whether a rollback will be issued after executing the SQL query that will be used to validate connections from this pool before returning them to the caller. Default behavior is NOT to issue a rollback. The setting will only have an effect if a validation query is set
Parameters:
  rollbackAfterValidation - new property value
since:
   1.2.2



setTestOnBorrow
public void setTestOnBorrow(boolean testOnBorrow)(Code)
When true, objects will be {*link PoolableObjectFactory#validateObject validated} before being returned by the {*link #borrowObject} method. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another. For a true value to have any effect, the validationQuery property must be set to a non-null string.
See Also:   InstanceKeyDataSource.getTestOnBorrow



setTestOnReturn
public void setTestOnReturn(boolean testOnReturn)(Code)
When true, objects will be {*link PoolableObjectFactory#validateObject validated} before being returned to the pool within the {*link #returnObject}. For a true value to have any effect, the validationQuery property must be set to a non-null string.
See Also:   InstanceKeyDataSource.getTestOnReturn



setTestWhileIdle
public void setTestWhileIdle(boolean testWhileIdle)(Code)
When true, objects will be {*link PoolableObjectFactory#validateObject validated} by the idle object evictor (if any). If an object fails to validate, it will be dropped from the pool. For a true value to have any effect, the validationQuery property must be set to a non-null string.
See Also:   InstanceKeyDataSource.getTestWhileIdle
See Also:   InstanceKeyDataSource.setTimeBetweenEvictionRunsMillis



setTimeBetweenEvictionRunsMillis
public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis)(Code)
Sets the number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, no idle object evictor thread will be run.
See Also:   InstanceKeyDataSource.getTimeBetweenEvictionRunsMillis



setValidationQuery
public void setValidationQuery(String validationQuery)(Code)
The SQL query that will be used to validate connections from this pool before returning them to the caller. If specified, this query MUST be an SQL SELECT statement that returns at least one row. Default behavior is to test the connection when it is borrowed.



setupDefaults
abstract protected void setupDefaults(Connection con, String username) throws SQLException(Code)



testCPDS
protected ConnectionPoolDataSource testCPDS(String username, String password) throws javax.naming.NamingException, SQLException(Code)



whenExhaustedAction
protected byte whenExhaustedAction(int maxActive, int maxWait)(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.