org.slim3.datasource
Class DataSourceImpl

java.lang.Object
  extended by org.slim3.datasource.DataSourceImpl
All Implemented Interfaces:
EventListener, ConnectionEventListener, DataSource

public class DataSourceImpl
extends Object
implements DataSource, ConnectionEventListener

An implementation class for XADataSource.

Since:
3.0
Author:
higa

Nested Class Summary
protected  class DataSourceImpl.PoolTask
          The task for connection timeout.
 
Field Summary
protected  Set<XAConnectionImpl> activeConnectionSet
          The set for active connection.
protected  Map<Transaction,XAConnectionImpl> activeTxConnectionMap
          The map for active transactional connection.
static int DEFAULT_TRANSACTION_ISOLATION_LEVEL
          The default transaction isolation level.
protected  String driverClassName
          The driver class name.
protected  LinkedList<DataSourceImpl.PoolTask> freePool
          The pool for free connection.
protected  long freePoolTimeout
          The free pool timeout(milliseconds).
protected static Log log
          The log.
protected  int loginTimeout
          The login timeout.
protected  int maxActiveSize
          The max number of active connections.
protected  String password
          The password.
protected  boolean readOnly
          Whether connection is read only.
protected static Timer timer
          The timer.
protected  int transactionIsolationLevel
          The transaction isolation level.
protected  TransactionManager transactionManager
          The transaction manager.
protected  String url
          JDBC driver url.
protected  String user
          The user.
protected  String validationQuery
          The query for connection validation.
 
Constructor Summary
DataSourceImpl()
          Constructor.
 
Method Summary
protected  void addFreePool(XAConnectionImpl pooledConnection)
          Adds the connection to free pool.
 void close()
          Closes pooled connections.
 void connectionClosed(ConnectionEvent event)
           
 void connectionErrorOccurred(ConnectionEvent event)
           
protected  void finalize()
           
 Connection getConnection()
           
 Connection getConnection(String user, String password)
           
 int getLoginTimeout()
           
 PrintWriter getLogWriter()
           
protected  Connection getPhysicalConnection(String user, String password)
          Returns a physical connection
protected  Transaction getTransaction()
          Returns the transaction.
protected  XAConnection getXAConnection()
          Returns the pooled connection.
 void setDriverClassName(String driverClassName)
          Sets the driver class name.
 void setFreePoolTimeout(long freePoolTimeout)
          Sets the free pool timeout(milliseconds)
 void setLoginTimeout(int loginTimeout)
           
 void setLogWriter(PrintWriter logWriter)
           
 void setMaxActiveSize(int maxActiveSize)
          Sets the max number of active connections.
 void setPassword(String password)
          Sets the password.
 void setReadOnly(boolean readOnly)
          Sets the read only flag.
 void setTransactionIsolationLevel(int transactionIsolationLevel)
          Sets transaction isolation level.
 void setTransactionManager(TransactionManager transactionManager)
          Sets the transaction manager.
 void setUrl(String url)
          Sets the JDBC driver url.
 void setUser(String user)
          Sets the user.
 void setValidationQuery(String validationQuery)
          Sets the query for connection validation.
protected  boolean validateConnection(Connection con)
          Validates the connection.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TRANSACTION_ISOLATION_LEVEL

public static final int DEFAULT_TRANSACTION_ISOLATION_LEVEL
The default transaction isolation level.

See Also:
Constant Field Values

log

protected static Log log
The log.


timer

protected static Timer timer
The timer.


transactionManager

protected TransactionManager transactionManager
The transaction manager.


freePoolTimeout

protected long freePoolTimeout
The free pool timeout(milliseconds).


maxActiveSize

protected int maxActiveSize
The max number of active connections.


validationQuery

protected String validationQuery
The query for connection validation.


activeTxConnectionMap

protected Map<Transaction,XAConnectionImpl> activeTxConnectionMap
The map for active transactional connection.


activeConnectionSet

protected Set<XAConnectionImpl> activeConnectionSet
The set for active connection.


freePool

protected LinkedList<DataSourceImpl.PoolTask> freePool
The pool for free connection.


driverClassName

protected String driverClassName
The driver class name.


url

protected String url
JDBC driver url.


user

protected String user
The user.


password

protected String password
The password.


loginTimeout

protected int loginTimeout
The login timeout.


readOnly

protected boolean readOnly
Whether connection is read only.


transactionIsolationLevel

protected int transactionIsolationLevel
The transaction isolation level.

Constructor Detail

DataSourceImpl

public DataSourceImpl()
Constructor.

Method Detail

setDriverClassName

public void setDriverClassName(String driverClassName)
Sets the driver class name.

Parameters:
driverClassName - the driver class name

setUrl

public void setUrl(String url)
Sets the JDBC driver url.

Parameters:
url - the JDBC driver url

setUser

public void setUser(String user)
Sets the user.

Parameters:
user - the user

setPassword

public void setPassword(String password)
Sets the password.

Parameters:
password - the password

setTransactionManager

public void setTransactionManager(TransactionManager transactionManager)
Sets the transaction manager.

Parameters:
transactionManager - the transaction manager to set

setFreePoolTimeout

public void setFreePoolTimeout(long freePoolTimeout)
Sets the free pool timeout(milliseconds)

Parameters:
freePoolTimeout - the free pool timeout

setMaxActiveSize

public void setMaxActiveSize(int maxActiveSize)
Sets the max number of active connections.

Parameters:
maxActiveSize - the max number of active connections

setValidationQuery

public void setValidationQuery(String validationQuery)
Sets the query for connection validation.

Parameters:
validationQuery - the query for connection validation

setReadOnly

public void setReadOnly(boolean readOnly)
Sets the read only flag.

Parameters:
readOnly - the read only flag

setTransactionIsolationLevel

public void setTransactionIsolationLevel(int transactionIsolationLevel)
Sets transaction isolation level.

Parameters:
transactionIsolationLevel - the transaction isolation level

getConnection

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

getConnection

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

getXAConnection

protected XAConnection getXAConnection()
                                throws SQLException
Returns the pooled connection.

Returns:
the pooled connection
Throws:
SQLException - if a SQL exception is encountered

getPhysicalConnection

protected Connection getPhysicalConnection(String user,
                                           String password)
                                    throws SQLException,
                                           NullPointerException
Returns a physical connection

Parameters:
user - the user
password - the password
Returns:
a physical connection
Throws:
SQLException - if SQLException is encountered
NullPointerException - if the driverClassName property is null

getLogWriter

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

setLogWriter

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

getLoginTimeout

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

setLoginTimeout

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

connectionClosed

public void connectionClosed(ConnectionEvent event)
Specified by:
connectionClosed in interface ConnectionEventListener

connectionErrorOccurred

public void connectionErrorOccurred(ConnectionEvent event)
Specified by:
connectionErrorOccurred in interface ConnectionEventListener

close

public void close()
Closes pooled connections.


getTransaction

protected Transaction getTransaction()
Returns the transaction.

Returns:
the transaction

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

addFreePool

protected void addFreePool(XAConnectionImpl pooledConnection)
Adds the connection to free pool.

Parameters:
pooledConnection - the connection

validateConnection

protected boolean validateConnection(Connection con)
Validates the connection.

Parameters:
con - the connection
Returns:
whether the connection is valid.


Copyright © 2008-2009 The Slim3 project. All Rights Reserved.