Package de.hybris.platform.jdbcwrapper
Class DataSourceImpl
- java.lang.Object
-
- de.hybris.platform.jdbcwrapper.DataSourceImpl
-
- All Implemented Interfaces:
HybrisDataSource,java.sql.Wrapper,javax.sql.CommonDataSource,javax.sql.DataSource
- Direct Known Subclasses:
SlaveTenantDataSource
public class DataSourceImpl extends java.lang.Object implements HybrisDataSource
DataSource connection factory for JDBC Connections. CAUTION: Please be aware that this file will be compiled by using jdk 1.6 and jdk 1.7,
for being successful in both cases we have to suppress the generation of the @override annotation. So please DONT OPEN/SAVE this file by using eclipse !!!!
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.IntegerOBJ_POOL_V1_WHEN_EXHAUSTED_BLOCKprotected static java.lang.IntegerOBJ_POOL_V1_WHEN_EXHAUSTED_FAILprotected static java.lang.IntegerOBJ_POOL_V1_WHEN_EXHAUSTED_GROW
-
Constructor Summary
Constructors Modifier Constructor Description DataSourceImpl(Tenant tenant, java.lang.String id, java.lang.String jndiName, boolean readOnly, DataSourceFactory factory)Creates a new data source using a existing JNDI data source.DataSourceImpl(Tenant tenant, java.lang.String id, java.util.Map<java.lang.String,java.lang.String> params, boolean readOnly, DataSourceFactory factory)Creates a new data source using connection parameters.protectedDataSourceImpl(Tenant tenant, java.lang.String id, java.util.Map<java.lang.String,java.lang.String> params, java.lang.String jndiName, boolean readOnly, DataSourceFactory factory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancannotConnect()protected org.apache.commons.pool2.impl.GenericObjectPoolConfigcreateNewPoolConfig()protected org.apache.commons.pool.impl.GenericObjectPool.ConfigcreatePoolConfig()Deprecated.since ages - Database connection pool now uses version 2 of Apache Commons Pool, so please usecreateNewPoolConfig()to create GenericObjectPoolConfig instead.voiddestroy()protected booleandetermineBlockingFromV1Property(int whenExhaustedAction)protected java.sql.ConnectiondoGetConnection(boolean transactionBound)java.sql.ConnectiongetConnection()Fetches a new connection from connection pool.java.sql.ConnectiongetConnection(boolean transactionBound)Fetches a new connection from connection pool.java.sql.ConnectiongetConnection(java.lang.String username, java.lang.String password)java.util.Map<java.lang.String,java.lang.String>getConnectionParameters()JDBCConnectionPoolgetConnectionPool()java.lang.StringgetCustomSessionSQL()java.lang.StringgetDatabaseName()java.lang.StringgetDatabaseURL()java.lang.StringgetDatabaseUser()java.lang.StringgetDatabaseVersion()DataSourceFactorygetDataSourceFactory()java.lang.StringgetDriverVersion()java.lang.StringgetID()JDBCInterceptorgetJDBCInterceptor()java.lang.StringgetJNDIName()intgetLoginTimeout()JDBCLogUtilsgetLogUtils()java.io.PrintWritergetLogWriter()intgetMaxAllowedPhysicalOpen()intgetMaxInUse()intgetMaxPhysicalOpen()intgetMaxPreparedParameterCount()longgetMillisWaitedForConnection()intgetNumInUse()intgetNumPhysicalOpen()java.util.logging.LoggergetParentLogger()java.lang.StringgetSchemaName()Tries to get the used schema name for a given SQLserver or oracle connection.java.lang.StringgetTablePrefix()TenantgetTenant()static java.lang.StringgetUserNameFromDatabaseMetaData(java.sql.DatabaseMetaData dmd, java.lang.String fallback)voidinvalidate(ConnectionImpl conn)booleanisDBLogActive()returns the value of the project.properties property 'db.log.active', which tells if the logging into the jdbc.log is activated or not.booleanisDBLogAppendStackTraceActive()returns the value of the project.properties setting 'db.log.appendStackTrace', which tells if the logging of stacktraces for each statement into the jdbc.log is activated or not.booleanisReadOnly()booleanisWrapperFor(java.lang.Class<?> arg0)protected java.lang.StringreadSchemaName()voidresetStats()Reset the statistics.voidreturnToPool(ConnectionImpl conn)voidsetDBLog(boolean active)set the value of the project.properties setting 'db.log.active'voidsetDBLogAppendStackTrace(boolean active)set the value of the project.properties setting 'db.log.appendStackTrace'voidsetLoginTimeout(int arg0)voidsetLogWriter(java.io.PrintWriter arg0)java.lang.StringtoString()longtotalGets()org.springframework.dao.DataAccessExceptiontranslateToDataAccessException(java.sql.SQLException e)Translates the given raw SQL exception into a SpringDataAccessExceptionexactly like it would have been done when using SpringJdbcTemplate.<T> Tunwrap(java.lang.Class<T> arg0)
-
-
-
Field Detail
-
OBJ_POOL_V1_WHEN_EXHAUSTED_FAIL
protected static final java.lang.Integer OBJ_POOL_V1_WHEN_EXHAUSTED_FAIL
-
OBJ_POOL_V1_WHEN_EXHAUSTED_BLOCK
protected static final java.lang.Integer OBJ_POOL_V1_WHEN_EXHAUSTED_BLOCK
-
OBJ_POOL_V1_WHEN_EXHAUSTED_GROW
protected static final java.lang.Integer OBJ_POOL_V1_WHEN_EXHAUSTED_GROW
-
-
Constructor Detail
-
DataSourceImpl
public DataSourceImpl(Tenant tenant, java.lang.String id, java.util.Map<java.lang.String,java.lang.String> params, boolean readOnly, DataSourceFactory factory)
Creates a new data source using connection parameters.- Parameters:
tenant- the owning tenantparams- the connection parameters
-
DataSourceImpl
public DataSourceImpl(Tenant tenant, java.lang.String id, java.lang.String jndiName, boolean readOnly, DataSourceFactory factory)
Creates a new data source using a existing JNDI data source.- Parameters:
tenant- the owning tenantjndiName- the JNDI name of the actual data source
-
DataSourceImpl
protected DataSourceImpl(Tenant tenant, java.lang.String id, java.util.Map<java.lang.String,java.lang.String> params, java.lang.String jndiName, boolean readOnly, DataSourceFactory factory)
-
-
Method Detail
-
getDriverVersion
public java.lang.String getDriverVersion()
- Specified by:
getDriverVersionin interfaceHybrisDataSource- Returns:
- the driverVersion
-
determineBlockingFromV1Property
protected boolean determineBlockingFromV1Property(int whenExhaustedAction)
-
createPoolConfig
@Deprecated protected org.apache.commons.pool.impl.GenericObjectPool.Config createPoolConfig()
Deprecated.since ages - Database connection pool now uses version 2 of Apache Commons Pool, so please usecreateNewPoolConfig()to create GenericObjectPoolConfig instead.
-
createNewPoolConfig
protected org.apache.commons.pool2.impl.GenericObjectPoolConfig createNewPoolConfig()
-
getConnectionParameters
public java.util.Map<java.lang.String,java.lang.String> getConnectionParameters()
- Specified by:
getConnectionParametersin interfaceHybrisDataSource
-
getJNDIName
public java.lang.String getJNDIName()
- Specified by:
getJNDINamein interfaceHybrisDataSource- Returns:
- the JNDI name
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getID
public java.lang.String getID()
- Specified by:
getIDin interfaceHybrisDataSource- Returns:
- the ID of the current data source
-
getConnectionPool
public JDBCConnectionPool getConnectionPool()
- Specified by:
getConnectionPoolin interfaceHybrisDataSource
-
getTenant
public Tenant getTenant()
- Specified by:
getTenantin interfaceHybrisDataSource
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLExceptionFetches a new connection from connection pool. If aTransactionis currently running the connection is transaction bound (the connection which BEGIN and COMMIT/ROLLBACK is called upon).- Specified by:
getConnectionin interfacejavax.sql.DataSource- Throws:
java.sql.SQLException
-
getConnection
public java.sql.Connection getConnection(boolean transactionBound) throws java.sql.SQLExceptionFetches a new connection from connection pool. If aTransactionis currently running the connection is either transaction bound (the connection which BEGIN and COMMIT/ROLLBACK is called upon) or a 'fresh' one.- Specified by:
getConnectionin interfaceHybrisDataSource- Parameters:
transactionBound- only valid if transaction is currently running: if true connection is transaction bound, if false a 'fresh' one is returned- Throws:
java.sql.SQLException
-
doGetConnection
protected java.sql.Connection doGetConnection(boolean transactionBound) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
getConnection
public java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException- Specified by:
getConnectionin interfacejavax.sql.DataSource- Throws:
java.sql.SQLException
-
returnToPool
public void returnToPool(ConnectionImpl conn)
- Specified by:
returnToPoolin interfaceHybrisDataSource
-
invalidate
public void invalidate(ConnectionImpl conn)
- Specified by:
invalidatein interfaceHybrisDataSource
-
destroy
public void destroy()
- Specified by:
destroyin interfaceHybrisDataSource
-
getNumInUse
public int getNumInUse()
- Specified by:
getNumInUsein interfaceHybrisDataSource- Returns:
- the number of instances currently borrowed from the pool.
-
getNumPhysicalOpen
public int getNumPhysicalOpen()
- Specified by:
getNumPhysicalOpenin interfaceHybrisDataSource- Returns:
- number of currently open JDBC connections.
-
getMaxInUse
public int getMaxInUse()
- Specified by:
getMaxInUsein interfaceHybrisDataSource- Returns:
- the maximum number of the 'in use' connection
-
getMaxPhysicalOpen
public int getMaxPhysicalOpen()
- Specified by:
getMaxPhysicalOpenin interfaceHybrisDataSource- Returns:
- the maximum number of physical SQL connections.
-
totalGets
public long totalGets()
- Specified by:
totalGetsin interfaceHybrisDataSource- Returns:
- Total number of connections so far. Reset with
HybrisDataSource.resetStats()
-
getMaxAllowedPhysicalOpen
public int getMaxAllowedPhysicalOpen()
- Specified by:
getMaxAllowedPhysicalOpenin interfaceHybrisDataSource- Returns:
- the maximum number of objects that can be allocated by the pool
-
getMillisWaitedForConnection
public long getMillisWaitedForConnection()
- Specified by:
getMillisWaitedForConnectionin interfaceHybrisDataSource- Returns:
- the time in milliseconds how long it took to get a connection from the pool
-
resetStats
public void resetStats()
Description copied from interface:HybrisDataSourceReset the statistics. Those areHybrisDataSource.getMillisWaitedForConnection(),HybrisDataSource.getMaxInUse()andHybrisDataSource.totalGets()- Specified by:
resetStatsin interfaceHybrisDataSource
-
getLogUtils
public JDBCLogUtils getLogUtils()
- Specified by:
getLogUtilsin interfaceHybrisDataSource
-
getDatabaseName
public java.lang.String getDatabaseName()
- Specified by:
getDatabaseNamein interfaceHybrisDataSource- Returns:
- the database name
-
getMaxPreparedParameterCount
public int getMaxPreparedParameterCount()
- Specified by:
getMaxPreparedParameterCountin interfaceHybrisDataSource- Returns:
- the maximum allowed number of parameters within one prepared statement; -1 if no limit exists
-
getUserNameFromDatabaseMetaData
public static java.lang.String getUserNameFromDatabaseMetaData(java.sql.DatabaseMetaData dmd, java.lang.String fallback)
-
getDatabaseVersion
public java.lang.String getDatabaseVersion()
- Specified by:
getDatabaseVersionin interfaceHybrisDataSource- Returns:
- the databaseVersion
-
getDatabaseURL
public java.lang.String getDatabaseURL()
- Specified by:
getDatabaseURLin interfaceHybrisDataSource- Returns:
- the URL of the database
-
getCustomSessionSQL
public java.lang.String getCustomSessionSQL()
- Specified by:
getCustomSessionSQLin interfaceHybrisDataSource
-
getDatabaseUser
public java.lang.String getDatabaseUser()
- Specified by:
getDatabaseUserin interfaceHybrisDataSource- Returns:
- the database user
-
getSchemaName
public java.lang.String getSchemaName()
Tries to get the used schema name for a given SQLserver or oracle connection.- Specified by:
getSchemaNamein interfaceHybrisDataSource- Returns:
- the schema name of the database
-
readSchemaName
protected java.lang.String readSchemaName()
-
cannotConnect
public boolean cannotConnect()
- Specified by:
cannotConnectin interfaceHybrisDataSource- Returns:
trueif a connection the pool is not possible.
-
getDataSourceFactory
public DataSourceFactory getDataSourceFactory()
- Specified by:
getDataSourceFactoryin interfaceHybrisDataSource
-
isDBLogActive
public boolean isDBLogActive()
returns the value of the project.properties property 'db.log.active', which tells if the logging into the jdbc.log is activated or not.- Specified by:
isDBLogActivein interfaceHybrisDataSource
-
isDBLogAppendStackTraceActive
public boolean isDBLogAppendStackTraceActive()
returns the value of the project.properties setting 'db.log.appendStackTrace', which tells if the logging of stacktraces for each statement into the jdbc.log is activated or not.- Specified by:
isDBLogAppendStackTraceActivein interfaceHybrisDataSource
-
setDBLog
public void setDBLog(boolean active)
set the value of the project.properties setting 'db.log.active'- Specified by:
setDBLogin interfaceHybrisDataSource
-
setDBLogAppendStackTrace
public void setDBLogAppendStackTrace(boolean active)
set the value of the project.properties setting 'db.log.appendStackTrace'- Specified by:
setDBLogAppendStackTracein interfaceHybrisDataSource
-
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnlyin interfaceHybrisDataSource- Returns:
trueif the datasoure is read-only
-
getTablePrefix
public java.lang.String getTablePrefix()
- Specified by:
getTablePrefixin interfaceHybrisDataSource- Returns:
- the table prefix for all tables
-
getLogWriter
public java.io.PrintWriter getLogWriter() throws java.sql.SQLException- Specified by:
getLogWriterin interfacejavax.sql.CommonDataSource- Specified by:
getLogWriterin interfacejavax.sql.DataSource- Throws:
java.sql.SQLException
-
setLogWriter
public void setLogWriter(java.io.PrintWriter arg0) throws java.sql.SQLException- Specified by:
setLogWriterin interfacejavax.sql.CommonDataSource- Specified by:
setLogWriterin interfacejavax.sql.DataSource- Throws:
java.sql.SQLException
-
getLoginTimeout
public int getLoginTimeout() throws java.sql.SQLException- Specified by:
getLoginTimeoutin interfacejavax.sql.CommonDataSource- Specified by:
getLoginTimeoutin interfacejavax.sql.DataSource- Throws:
java.sql.SQLException
-
setLoginTimeout
public void setLoginTimeout(int arg0) throws java.sql.SQLException- Specified by:
setLoginTimeoutin interfacejavax.sql.CommonDataSource- Specified by:
setLoginTimeoutin interfacejavax.sql.DataSource- Throws:
java.sql.SQLException
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> arg0) throws java.sql.SQLException- Specified by:
isWrapperForin interfacejava.sql.Wrapper- Throws:
java.sql.SQLException
-
unwrap
public <T> T unwrap(java.lang.Class<T> arg0) throws java.sql.SQLException- Specified by:
unwrapin interfacejava.sql.Wrapper- Throws:
java.sql.SQLException
-
getParentLogger
public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException- Specified by:
getParentLoggerin interfacejavax.sql.CommonDataSource- Throws:
java.sql.SQLFeatureNotSupportedException- Since:
- jdk 1.7
-
translateToDataAccessException
public org.springframework.dao.DataAccessException translateToDataAccessException(java.sql.SQLException e)
Description copied from interface:HybrisDataSourceTranslates the given raw SQL exception into a SpringDataAccessExceptionexactly like it would have been done when using SpringJdbcTemplate.- Specified by:
translateToDataAccessExceptionin interfaceHybrisDataSource
-
getJDBCInterceptor
public JDBCInterceptor getJDBCInterceptor()
- Specified by:
getJDBCInterceptorin interfaceHybrisDataSource
-
-