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.Integer
OBJ_POOL_V1_WHEN_EXHAUSTED_BLOCK
protected static java.lang.Integer
OBJ_POOL_V1_WHEN_EXHAUSTED_FAIL
protected static java.lang.Integer
OBJ_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.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 Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
cannotConnect()
protected org.apache.commons.pool2.impl.GenericObjectPoolConfig
createNewPoolConfig()
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.void
destroy()
protected boolean
determineBlockingFromV1Property(int whenExhaustedAction)
protected java.sql.Connection
doGetConnection(boolean transactionBound)
java.sql.Connection
getConnection()
Fetches a new connection from connection pool.java.sql.Connection
getConnection(boolean transactionBound)
Fetches a new connection from connection pool.java.sql.Connection
getConnection(java.lang.String username, java.lang.String password)
java.util.Map<java.lang.String,java.lang.String>
getConnectionParameters()
JDBCConnectionPool
getConnectionPool()
java.lang.String
getCustomSessionSQL()
java.lang.String
getDatabaseName()
java.lang.String
getDatabaseURL()
java.lang.String
getDatabaseUser()
java.lang.String
getDatabaseVersion()
DataSourceFactory
getDataSourceFactory()
java.lang.String
getDriverVersion()
java.lang.String
getID()
JDBCInterceptor
getJDBCInterceptor()
java.lang.String
getJNDIName()
int
getLoginTimeout()
JDBCLogUtils
getLogUtils()
java.io.PrintWriter
getLogWriter()
int
getMaxAllowedPhysicalOpen()
int
getMaxInUse()
int
getMaxPhysicalOpen()
int
getMaxPreparedParameterCount()
long
getMillisWaitedForConnection()
int
getNumInUse()
int
getNumPhysicalOpen()
java.util.logging.Logger
getParentLogger()
java.lang.String
getSchemaName()
Tries to get the used schema name for a given SQLserver or oracle connection.java.lang.String
getTablePrefix()
Tenant
getTenant()
static java.lang.String
getUserNameFromDatabaseMetaData(java.sql.DatabaseMetaData dmd, java.lang.String fallback)
void
invalidate(ConnectionImpl conn)
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.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.boolean
isReadOnly()
boolean
isWrapperFor(java.lang.Class<?> arg0)
protected java.lang.String
readSchemaName()
void
resetStats()
Reset the statistics.void
returnToPool(ConnectionImpl conn)
void
setDBLog(boolean active)
set the value of the project.properties setting 'db.log.active'void
setDBLogAppendStackTrace(boolean active)
set the value of the project.properties setting 'db.log.appendStackTrace'void
setLoginTimeout(int arg0)
void
setLogWriter(java.io.PrintWriter arg0)
java.lang.String
toString()
long
totalGets()
org.springframework.dao.DataAccessException
translateToDataAccessException(java.sql.SQLException e)
Translates the given raw SQL exception into a SpringDataAccessException
exactly like it would have been done when using SpringJdbcTemplate
.<T> T
unwrap(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:
getDriverVersion
in 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:
getConnectionParameters
in interfaceHybrisDataSource
-
getJNDIName
public java.lang.String getJNDIName()
- Specified by:
getJNDIName
in interfaceHybrisDataSource
- Returns:
- the JNDI name
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getID
public java.lang.String getID()
- Specified by:
getID
in interfaceHybrisDataSource
- Returns:
- the ID of the current data source
-
getConnectionPool
public JDBCConnectionPool getConnectionPool()
- Specified by:
getConnectionPool
in interfaceHybrisDataSource
-
getTenant
public Tenant getTenant()
- Specified by:
getTenant
in interfaceHybrisDataSource
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLException
Fetches a new connection from connection pool. If aTransaction
is currently running the connection is transaction bound (the connection which BEGIN and COMMIT/ROLLBACK is called upon).- Specified by:
getConnection
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
getConnection
public java.sql.Connection getConnection(boolean transactionBound) throws java.sql.SQLException
Fetches a new connection from connection pool. If aTransaction
is currently running the connection is either transaction bound (the connection which BEGIN and COMMIT/ROLLBACK is called upon) or a 'fresh' one.- Specified by:
getConnection
in 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:
getConnection
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
returnToPool
public void returnToPool(ConnectionImpl conn)
- Specified by:
returnToPool
in interfaceHybrisDataSource
-
invalidate
public void invalidate(ConnectionImpl conn)
- Specified by:
invalidate
in interfaceHybrisDataSource
-
destroy
public void destroy()
- Specified by:
destroy
in interfaceHybrisDataSource
-
getNumInUse
public int getNumInUse()
- Specified by:
getNumInUse
in interfaceHybrisDataSource
- Returns:
- the number of instances currently borrowed from the pool.
-
getNumPhysicalOpen
public int getNumPhysicalOpen()
- Specified by:
getNumPhysicalOpen
in interfaceHybrisDataSource
- Returns:
- number of currently open JDBC connections.
-
getMaxInUse
public int getMaxInUse()
- Specified by:
getMaxInUse
in interfaceHybrisDataSource
- Returns:
- the maximum number of the 'in use' connection
-
getMaxPhysicalOpen
public int getMaxPhysicalOpen()
- Specified by:
getMaxPhysicalOpen
in interfaceHybrisDataSource
- Returns:
- the maximum number of physical SQL connections.
-
totalGets
public long totalGets()
- Specified by:
totalGets
in interfaceHybrisDataSource
- Returns:
- Total number of connections so far. Reset with
HybrisDataSource.resetStats()
-
getMaxAllowedPhysicalOpen
public int getMaxAllowedPhysicalOpen()
- Specified by:
getMaxAllowedPhysicalOpen
in interfaceHybrisDataSource
- Returns:
- the maximum number of objects that can be allocated by the pool
-
getMillisWaitedForConnection
public long getMillisWaitedForConnection()
- Specified by:
getMillisWaitedForConnection
in 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:HybrisDataSource
Reset the statistics. Those areHybrisDataSource.getMillisWaitedForConnection()
,HybrisDataSource.getMaxInUse()
andHybrisDataSource.totalGets()
- Specified by:
resetStats
in interfaceHybrisDataSource
-
getLogUtils
public JDBCLogUtils getLogUtils()
- Specified by:
getLogUtils
in interfaceHybrisDataSource
-
getDatabaseName
public java.lang.String getDatabaseName()
- Specified by:
getDatabaseName
in interfaceHybrisDataSource
- Returns:
- the database name
-
getMaxPreparedParameterCount
public int getMaxPreparedParameterCount()
- Specified by:
getMaxPreparedParameterCount
in 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:
getDatabaseVersion
in interfaceHybrisDataSource
- Returns:
- the databaseVersion
-
getDatabaseURL
public java.lang.String getDatabaseURL()
- Specified by:
getDatabaseURL
in interfaceHybrisDataSource
- Returns:
- the URL of the database
-
getCustomSessionSQL
public java.lang.String getCustomSessionSQL()
- Specified by:
getCustomSessionSQL
in interfaceHybrisDataSource
-
getDatabaseUser
public java.lang.String getDatabaseUser()
- Specified by:
getDatabaseUser
in 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:
getSchemaName
in interfaceHybrisDataSource
- Returns:
- the schema name of the database
-
readSchemaName
protected java.lang.String readSchemaName()
-
cannotConnect
public boolean cannotConnect()
- Specified by:
cannotConnect
in interfaceHybrisDataSource
- Returns:
true
if a connection the pool is not possible.
-
getDataSourceFactory
public DataSourceFactory getDataSourceFactory()
- Specified by:
getDataSourceFactory
in 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:
isDBLogActive
in 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:
isDBLogAppendStackTraceActive
in interfaceHybrisDataSource
-
setDBLog
public void setDBLog(boolean active)
set the value of the project.properties setting 'db.log.active'- Specified by:
setDBLog
in interfaceHybrisDataSource
-
setDBLogAppendStackTrace
public void setDBLogAppendStackTrace(boolean active)
set the value of the project.properties setting 'db.log.appendStackTrace'- Specified by:
setDBLogAppendStackTrace
in interfaceHybrisDataSource
-
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnly
in interfaceHybrisDataSource
- Returns:
true
if the datasoure is read-only
-
getTablePrefix
public java.lang.String getTablePrefix()
- Specified by:
getTablePrefix
in interfaceHybrisDataSource
- Returns:
- the table prefix for all tables
-
getLogWriter
public java.io.PrintWriter getLogWriter() throws java.sql.SQLException
- Specified by:
getLogWriter
in interfacejavax.sql.CommonDataSource
- Specified by:
getLogWriter
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
setLogWriter
public void setLogWriter(java.io.PrintWriter arg0) throws java.sql.SQLException
- Specified by:
setLogWriter
in interfacejavax.sql.CommonDataSource
- Specified by:
setLogWriter
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
getLoginTimeout
public int getLoginTimeout() throws java.sql.SQLException
- Specified by:
getLoginTimeout
in interfacejavax.sql.CommonDataSource
- Specified by:
getLoginTimeout
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
setLoginTimeout
public void setLoginTimeout(int arg0) throws java.sql.SQLException
- Specified by:
setLoginTimeout
in interfacejavax.sql.CommonDataSource
- Specified by:
setLoginTimeout
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> arg0) throws java.sql.SQLException
- Specified by:
isWrapperFor
in interfacejava.sql.Wrapper
- Throws:
java.sql.SQLException
-
unwrap
public <T> T unwrap(java.lang.Class<T> arg0) throws java.sql.SQLException
- Specified by:
unwrap
in interfacejava.sql.Wrapper
- Throws:
java.sql.SQLException
-
getParentLogger
public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException
- Specified by:
getParentLogger
in 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:HybrisDataSource
Translates the given raw SQL exception into a SpringDataAccessException
exactly like it would have been done when using SpringJdbcTemplate
.- Specified by:
translateToDataAccessException
in interfaceHybrisDataSource
-
getJDBCInterceptor
public JDBCInterceptor getJDBCInterceptor()
- Specified by:
getJDBCInterceptor
in interfaceHybrisDataSource
-
-