com.atomikos.jdbc
Class AbstractDataSourceBean

java.lang.Object
  extended by com.atomikos.jdbc.AbstractDataSourceBean
All Implemented Interfaces:
ConnectionPoolProperties, HeuristicDataSource, Serializable, Referenceable, DataSource
Direct Known Subclasses:
AtomikosDataSourceBean, AtomikosNonXADataSourceBean

public abstract class AbstractDataSourceBean
extends Object
implements HeuristicDataSource, ConnectionPoolProperties, Referenceable, Serializable

Abstract data source bean with generic functionality.

See Also:
Serialized Form

Constructor Summary
AbstractDataSourceBean()
           
 
Method Summary
 void close()
           
protected abstract  void doClose()
           
protected abstract  ConnectionFactory doInit()
           
 int getBorrowConnectionTimeout()
          Get the maximum amount of time in seconds the pool will block waiting for a connection to become available in the pool when it is empty.
 Connection getConnection()
           
 Connection getConnection(HeuristicMessage msg)
          Get a connection to the datasource for the given description of the work.
 Connection getConnection(String msg)
          Get a connection to the datasource for the given description of the work.
 Connection getConnection(String username, String password)
           
 Connection getConnection(String user, String passwd, HeuristicMessage msg)
          Get a connection to the datasource for the given description of the work.
 Connection getConnection(String user, String passwd, String msg)
          Get a connection to the datasource for the given description of the work.
 int getDefaultIsolationLevel()
          Gets the default isolation level for connections created by this datasource.
 boolean getLocalTransactionMode()
          Tests whether local transactions are allowed - defaults to true for JDBC.
 int getLoginTimeout()
           
 PrintWriter getLogWriter()
           
 int getMaintenanceInterval()
          Gets the maintenance interval as set.
 int getMaxIdleTime()
          Gets the maximum amount of time in seconds a connection can stay in the pool before being eligible for being closed during pool shrinking.
 int getMaxPoolSize()
          Get the maximum pool size.
 int getMinPoolSize()
          Gets the minimum size of the pool.
 int getReapTimeout()
          Get the amount of time in seconds the connection pool will allow a connection to be borrowed before claiming it back.
 Reference getReference()
           
 String getTestQuery()
          Gets the SQL query used to test a connection before returning it.
 String getUniqueResourceName()
          Get the resource name.
 void init()
           
 int poolAvailableSize()
           
 int poolTotalSize()
           
 void setBorrowConnectionTimeout(int borrowConnectionTimeout)
          Sets the maximum amount of time in seconds the pool will block waiting for a connection to become available in the pool when it is empty.
 void setDefaultIsolationLevel(int defaultIsolationLevel)
          Sets the default isolation level of connections returned by this datasource.
 void setLoginTimeout(int seconds)
           
 void setLogWriter(PrintWriter out)
           
 void setMaintenanceInterval(int maintenanceInterval)
          Sets the maintenance interval for the pool maintenance thread.
 void setMaxIdleTime(int maxIdleTime)
          Sets the maximum amount of seconds that unused excess connections should stay in the pool.
 void setMaxPoolSize(int maxPoolSize)
          Sets the maximum pool size.
 void setMinPoolSize(int minPoolSize)
          Sets the minimum pool size.
 void setPoolSize(int poolSize)
          Sets both the minimal and maximal pool size.
 void setReapTimeout(int reapTimeout)
          Sets the amount of time (in seconds) that the connection pool will allow a connection to be in use, before claiming it back.
 void setTestQuery(String testQuery)
          Sets the SQL query or statement used to validate a connection before returning it.
 void setUniqueResourceName(String resourceName)
          Sets the resource name.
protected  void throwAtomikosSQLException(String msg)
           
protected  void throwAtomikosSQLException(String msg, Throwable cause)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDataSourceBean

public AbstractDataSourceBean()
Method Detail

throwAtomikosSQLException

protected void throwAtomikosSQLException(String msg)
                                  throws AtomikosSQLException
Throws:
AtomikosSQLException

throwAtomikosSQLException

protected void throwAtomikosSQLException(String msg,
                                         Throwable cause)
                                  throws AtomikosSQLException
Throws:
AtomikosSQLException

getMinPoolSize

public int getMinPoolSize()
Gets the minimum size of the pool.

Specified by:
getMinPoolSize in interface ConnectionPoolProperties
Returns:

setMinPoolSize

public void setMinPoolSize(int minPoolSize)
Sets the minimum pool size. The amount of pooled connections won't go below that value. The pool will open this amount of connections during initialization. Optional, defaults to 1.

Parameters:
minPoolSize -

getMaxPoolSize

public int getMaxPoolSize()
Get the maximum pool size.

Specified by:
getMaxPoolSize in interface ConnectionPoolProperties
Returns:

setMaxPoolSize

public void setMaxPoolSize(int maxPoolSize)
Sets the maximum pool size. The amount of pooled connections won't go above this value. Optional, defaults to 1.

Parameters:
maxPoolSize -

setPoolSize

public void setPoolSize(int poolSize)
Sets both the minimal and maximal pool size. Required if the maxPoolSize is not set.


getBorrowConnectionTimeout

public int getBorrowConnectionTimeout()
Get the maximum amount of time in seconds the pool will block waiting for a connection to become available in the pool when it is empty.

Specified by:
getBorrowConnectionTimeout in interface ConnectionPoolProperties
Returns:

setBorrowConnectionTimeout

public void setBorrowConnectionTimeout(int borrowConnectionTimeout)
Sets the maximum amount of time in seconds the pool will block waiting for a connection to become available in the pool when it is empty. Optional.

Parameters:
borrowConnectionTimeout - The time in seconds. Zero or negative means no waiting at all. Defaults to 30 seconds.

getReapTimeout

public int getReapTimeout()
Get the amount of time in seconds the connection pool will allow a connection to be borrowed before claiming it back.

Specified by:
getReapTimeout in interface ConnectionPoolProperties
Returns:

setReapTimeout

public void setReapTimeout(int reapTimeout)
Sets the amount of time (in seconds) that the connection pool will allow a connection to be in use, before claiming it back. Optional.

Parameters:
reapTimeout - The timeout in seconds. Zero means unlimited. Note that this value is only an indication; the pool will check regularly as indicated by the maintenanceInteval property. Default is 0 (no timeout).

setMaintenanceInterval

public void setMaintenanceInterval(int maintenanceInterval)
Sets the maintenance interval for the pool maintenance thread. Optional.

Parameters:
maintenanceInterval - The interval in seconds. If not set or not positive then the pool's default (60 secs) will be used.

getMaintenanceInterval

public int getMaintenanceInterval()
Gets the maintenance interval as set.

Specified by:
getMaintenanceInterval in interface ConnectionPoolProperties
Returns:

getMaxIdleTime

public int getMaxIdleTime()
Gets the maximum amount of time in seconds a connection can stay in the pool before being eligible for being closed during pool shrinking.

Specified by:
getMaxIdleTime in interface ConnectionPoolProperties
Returns:

setMaxIdleTime

public void setMaxIdleTime(int maxIdleTime)
Sets the maximum amount of seconds that unused excess connections should stay in the pool. Optional. Note: excess connections are connections that are created above the minPoolSize limit.

Parameters:
maxIdleTime - The preferred idle time for unused excess connections. Note that this value is only an indication; the pool will check regularly as indicated by the maintenanceInteval property. The default is 60 seconds.

getTestQuery

public String getTestQuery()
Gets the SQL query used to test a connection before returning it.

Specified by:
getTestQuery in interface ConnectionPoolProperties
Returns:

setTestQuery

public void setTestQuery(String testQuery)
Sets the SQL query or statement used to validate a connection before returning it. Optional.

Parameters:
testQuery - - The SQL query or statement to validate the connection with. Note that although you can specify updates here, these will NOT be part of any JTA transaction!

poolAvailableSize

public int poolAvailableSize()

poolTotalSize

public int poolTotalSize()

getLogWriter

public PrintWriter getLogWriter()
                         throws SQLException
Specified by:
getLogWriter in interface DataSource
Throws:
SQLException

getLoginTimeout

public int getLoginTimeout()
                    throws SQLException
Specified by:
getLoginTimeout in interface DataSource
Throws:
SQLException

setLogWriter

public void setLogWriter(PrintWriter out)
                  throws SQLException
Specified by:
setLogWriter in interface DataSource
Throws:
SQLException

setLoginTimeout

public void setLoginTimeout(int seconds)
                     throws SQLException
Specified by:
setLoginTimeout in interface DataSource
Throws:
SQLException

init

public void init()
          throws AtomikosSQLException
Throws:
AtomikosSQLException

close

public void close()

doInit

protected abstract ConnectionFactory doInit()
                                     throws Exception
Throws:
Exception

doClose

protected abstract void doClose()

getConnection

public Connection getConnection(HeuristicMessage msg)
                         throws SQLException
Description copied from interface: HeuristicDataSource
Get a connection to the datasource for the given description of the work.

Specified by:
getConnection in interface HeuristicDataSource
Parameters:
msg - The heuristic message that best describes the work about to be done.
Returns:
Connection The connection.
Throws:
SQLException - On error.

getConnection

public Connection getConnection(String username,
                                String password)
                         throws SQLException
Specified by:
getConnection in interface DataSource
Throws:
SQLException

getUniqueResourceName

public String getUniqueResourceName()
Get the resource name.

Specified by:
getUniqueResourceName in interface ConnectionPoolProperties
Returns:

setUniqueResourceName

public void setUniqueResourceName(String resourceName)
Sets the resource name. Required.

Parameters:
resourceName - An arbitrary user-specified value that identifies this datasource. It must be unique for recovery purposes.

getLocalTransactionMode

public boolean getLocalTransactionMode()
Tests whether local transactions are allowed - defaults to true for JDBC. This property is used by the pooling mechanism.

Specified by:
getLocalTransactionMode in interface ConnectionPoolProperties
Returns:

getReference

public Reference getReference()
                       throws NamingException
Specified by:
getReference in interface Referenceable
Throws:
NamingException

getConnection

public Connection getConnection()
                         throws SQLException
Specified by:
getConnection in interface DataSource
Throws:
SQLException

getConnection

public Connection getConnection(String msg)
                         throws SQLException
Description copied from interface: HeuristicDataSource
Get a connection to the datasource for the given description of the work.

Specified by:
getConnection in interface HeuristicDataSource
Parameters:
msg - The heuristic message that best describes the work about to be done.
Returns:
Connection The connection.
Throws:
SQLException - On error.

getConnection

public Connection getConnection(String user,
                                String passwd,
                                String msg)
                         throws SQLException
Description copied from interface: HeuristicDataSource
Get a connection to the datasource for the given description of the work.

Specified by:
getConnection in interface HeuristicDataSource
Parameters:
user - The user name to use.
passwd - The password.
msg - The heuristic message that best describes the work about to be done.
Returns:
Connection The connection.
Throws:
SQLException - On error.

getConnection

public Connection getConnection(String user,
                                String passwd,
                                HeuristicMessage msg)
                         throws SQLException
Description copied from interface: HeuristicDataSource
Get a connection to the datasource for the given description of the work.

Specified by:
getConnection in interface HeuristicDataSource
Parameters:
user - The user name to use.
passwd - The password.
msg - The heuristic message that best describes the work about to be done.
Returns:
Connection The connection.
Throws:
SQLException - On error.

setDefaultIsolationLevel

public void setDefaultIsolationLevel(int defaultIsolationLevel)
Sets the default isolation level of connections returned by this datasource. Optional, defaults to the vendor-specific JDBC or DBMS settings.

Parameters:
defaultIsolationLevel - The default isolation level. Negative values are ignored and result in vendor-specific JDBC driver or DBMS internal defaults.

getDefaultIsolationLevel

public int getDefaultIsolationLevel()
Gets the default isolation level for connections created by this datasource.

Specified by:
getDefaultIsolationLevel in interface ConnectionPoolProperties
Returns:
The default isolation level, or -1 if no specific value was set.


Copyright © 2011. All Rights Reserved.