com.im.commons.db 5.9.2

com.im.commons.db.datasource
Class BaseDataSource

java.lang.Object
  extended by org.springframework.jdbc.datasource.AbstractDataSource
      extended by org.springframework.jdbc.datasource.AbstractDriverBasedDataSource
          extended by org.springframework.jdbc.datasource.DriverManagerDataSource
              extended by com.im.commons.db.datasource.BaseDataSource
All Implemented Interfaces:
ClosableDataSource, Wrapper, CommonDataSource, DataSource

public abstract class BaseDataSource
extends DriverManagerDataSource
implements ClosableDataSource

This is a base class for data sources. Specific DB support modules may provide its own DataSources with DB-specific options. The DataSource implements a connection pool and returns connections allocated from that pool. The close() method of those connections will only return the connection to the pool for reuse. Excess connections are closed. When a connection is returned to a thread, it is always returned to the thread. Those connection maintains a reference counter, so the thread properly returns connection to the pool just by calling close() on it. Current DIF code expects that dataSource.getConnection() will return the same Connection during the whole process, e.g. with respect to an active/opened transaction. The DataSource can be close()d, which closes all managed connection and detaches the connection pool. The next call to getConnection will allocate a new connection pool. It is NOT PERMITTED to change credentials or connection URL while a connection is active. All connections must be closed first, preferably by BaseDataSource.close().


Field Summary
 
Fields inherited from class org.springframework.jdbc.datasource.AbstractDataSource
logger
 
Constructor Summary
BaseDataSource()
           
 
Method Summary
 void afterPropertiesSet()
           
 BaseDataSource clone()
          Clone is overridden to copy over all visible properties, but JDK clone() is not used because only definition of the datasource not connection pools etc should be copied.
 void close()
          Closes all connections and the object pool.
protected  ObjectPool createConnectionPool()
          Written as an initializer, as it will be executed no matter which constructor will create the object PENDING P3: make these values configurable
protected  DataSource createDelegate(String url, Properties props)
          Will return a pooling delegate, constructing it from the current properties, if necessary.
 String getCatalog()
           
protected  Connection getConnectionFromDriverManager(String url, Properties properties)
           
 DBType getDbType()
           
 String getDriverClassName()
           
 ObjectPoolFactory getObjectPoolFactory()
           
 Properties getProperties()
           
 String getSchema()
           
 boolean isPrepareConnectionForCartridge()
          Get the value of prepareConnectionForCartridge
 boolean isWrapperFor(Class iface)
           
protected  void prepareNewConnection(Connection con)
           
 void setCatalog(String catalog)
           
 void setDbType(DBType dbType)
           
 void setDriverClassName(String driverClassName)
           
 void setObjectPoolFactory(ObjectPoolFactory objectPoolFactory)
           
 void setPrepareConnectionForCartridge(boolean prepareConnectionForCartridge)
          Set the value of prepareConnectionForCartridge
 void setProperties(Properties props)
           
 void setSchema(String schema)
           
 String toString()
           
 Object unwrap(Class iface)
           
 
Methods inherited from class org.springframework.jdbc.datasource.DriverManagerDataSource
getConnectionFromDriver
 
Methods inherited from class org.springframework.jdbc.datasource.AbstractDriverBasedDataSource
getConnection, getConnection, getConnectionFromDriver, getConnectionProperties, getPassword, getUrl, getUsername, setConnectionProperties, setPassword, setUrl, setUsername
 
Methods inherited from class org.springframework.jdbc.datasource.AbstractDataSource
getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriter
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BaseDataSource

public BaseDataSource()
Method Detail

isPrepareConnectionForCartridge

public boolean isPrepareConnectionForCartridge()
Get the value of prepareConnectionForCartridge

Returns:
The value of prepareConnectionForCartridge

setPrepareConnectionForCartridge

public void setPrepareConnectionForCartridge(boolean prepareConnectionForCartridge)
Set the value of prepareConnectionForCartridge

Parameters:
prepareConnectionForCartridge - The new value of prepareConnectionForCartridge

createConnectionPool

protected ObjectPool createConnectionPool()
Written as an initializer, as it will be executed no matter which constructor will create the object PENDING P3: make these values configurable


afterPropertiesSet

public void afterPropertiesSet()

getObjectPoolFactory

public ObjectPoolFactory getObjectPoolFactory()

setObjectPoolFactory

public void setObjectPoolFactory(ObjectPoolFactory objectPoolFactory)

toString

public String toString()
Overrides:
toString in class Object

close

public void close()
           throws SQLException
Closes all connections and the object pool. May throw an SQLException, if a connection cannot be closed. Other exceptions, such as those from the object pool are only logged and ignored.

Specified by:
close in interface ClosableDataSource
Throws:
SQLException

setProperties

public void setProperties(Properties props)

getProperties

public Properties getProperties()

getSchema

public String getSchema()

setSchema

public void setSchema(String schema)

getCatalog

public String getCatalog()

setCatalog

public void setCatalog(String catalog)

createDelegate

protected DataSource createDelegate(String url,
                                    Properties props)
Will return a pooling delegate, constructing it from the current properties, if necessary. Note: the 'passthrough' approach to the DriverManager superclass is used to overcome DriverManager's checks whether the calling Class may access the particular driver. Spring module is already allowed to access any and all JDBC driver modules, so I tunnel the call through Spring instead of creating further module dependencies.


prepareNewConnection

protected void prepareNewConnection(Connection con)

getConnectionFromDriverManager

protected Connection getConnectionFromDriverManager(String url,
                                                    Properties properties)
                                             throws SQLException
Overrides:
getConnectionFromDriverManager in class DriverManagerDataSource
Throws:
SQLException

setDriverClassName

public void setDriverClassName(String driverClassName)
Overrides:
setDriverClassName in class DriverManagerDataSource

getDriverClassName

public String getDriverClassName()

clone

public BaseDataSource clone()
Clone is overridden to copy over all visible properties, but JDK clone() is not used because only definition of the datasource not connection pools etc should be copied. Properties are copied using setter methods on the clone, so subclasses may override the behaviour. Subclasses, which define more properties MUST override.

Overrides:
clone in class Object

isWrapperFor

public boolean isWrapperFor(Class iface)
                     throws SQLException
Specified by:
isWrapperFor in interface Wrapper
Overrides:
isWrapperFor in class AbstractDataSource
Throws:
SQLException

unwrap

public Object unwrap(Class iface)
              throws SQLException
Specified by:
unwrap in interface Wrapper
Overrides:
unwrap in class AbstractDataSource
Throws:
SQLException

getDbType

public DBType getDbType()

setDbType

public void setDbType(DBType dbType)

com.im.commons.db 5.9.2