Class 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 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 tenant
        params - 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 tenant
        jndiName - 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

      • 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 use createNewPoolConfig() to create GenericObjectPoolConfig instead.
      • createNewPoolConfig

        protected org.apache.commons.pool2.impl.GenericObjectPoolConfig createNewPoolConfig()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getID

        public java.lang.String getID()
        Specified by:
        getID in interface HybrisDataSource
        Returns:
        the ID of the current data source
      • getConnection

        public java.sql.Connection getConnection()
                                          throws java.sql.SQLException
        Fetches a new connection from connection pool. If a Transaction is currently running the connection is transaction bound (the connection which BEGIN and COMMIT/ROLLBACK is called upon).
        Specified by:
        getConnection in interface javax.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 a Transaction 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 interface HybrisDataSource
        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 interface javax.sql.DataSource
        Throws:
        java.sql.SQLException
      • getNumInUse

        public int getNumInUse()
        Specified by:
        getNumInUse in interface HybrisDataSource
        Returns:
        the number of instances currently borrowed from the pool.
      • getNumPhysicalOpen

        public int getNumPhysicalOpen()
        Specified by:
        getNumPhysicalOpen in interface HybrisDataSource
        Returns:
        number of currently open JDBC connections.
      • getMaxInUse

        public int getMaxInUse()
        Specified by:
        getMaxInUse in interface HybrisDataSource
        Returns:
        the maximum number of the 'in use' connection
      • getMaxPhysicalOpen

        public int getMaxPhysicalOpen()
        Specified by:
        getMaxPhysicalOpen in interface HybrisDataSource
        Returns:
        the maximum number of physical SQL connections.
      • getMaxAllowedPhysicalOpen

        public int getMaxAllowedPhysicalOpen()
        Specified by:
        getMaxAllowedPhysicalOpen in interface HybrisDataSource
        Returns:
        the maximum number of objects that can be allocated by the pool
      • getMillisWaitedForConnection

        public long getMillisWaitedForConnection()
        Specified by:
        getMillisWaitedForConnection in interface HybrisDataSource
        Returns:
        the time in milliseconds how long it took to get a connection from the pool
      • getMaxPreparedParameterCount

        public int getMaxPreparedParameterCount()
        Specified by:
        getMaxPreparedParameterCount in interface HybrisDataSource
        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)
      • getDatabaseURL

        public java.lang.String getDatabaseURL()
        Specified by:
        getDatabaseURL in interface HybrisDataSource
        Returns:
        the URL of the database
      • getSchemaName

        public java.lang.String getSchemaName()
        Tries to get the used schema name for a given SQLserver or oracle connection.
        Specified by:
        getSchemaName in interface HybrisDataSource
        Returns:
        the schema name of the database
      • readSchemaName

        protected java.lang.String readSchemaName()
      • cannotConnect

        public boolean cannotConnect()
        Specified by:
        cannotConnect in interface HybrisDataSource
        Returns:
        true if a connection the pool is not possible.
      • 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 interface HybrisDataSource
      • 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 interface HybrisDataSource
      • setDBLog

        public void setDBLog​(boolean active)
        set the value of the project.properties setting 'db.log.active'
        Specified by:
        setDBLog in interface HybrisDataSource
      • setDBLogAppendStackTrace

        public void setDBLogAppendStackTrace​(boolean active)
        set the value of the project.properties setting 'db.log.appendStackTrace'
        Specified by:
        setDBLogAppendStackTrace in interface HybrisDataSource
      • isReadOnly

        public boolean isReadOnly()
        Specified by:
        isReadOnly in interface HybrisDataSource
        Returns:
        true if the datasoure is read-only
      • getTablePrefix

        public java.lang.String getTablePrefix()
        Specified by:
        getTablePrefix in interface HybrisDataSource
        Returns:
        the table prefix for all tables
      • getLogWriter

        public java.io.PrintWriter getLogWriter()
                                         throws java.sql.SQLException
        Specified by:
        getLogWriter in interface javax.sql.CommonDataSource
        Specified by:
        getLogWriter in interface javax.sql.DataSource
        Throws:
        java.sql.SQLException
      • setLogWriter

        public void setLogWriter​(java.io.PrintWriter arg0)
                          throws java.sql.SQLException
        Specified by:
        setLogWriter in interface javax.sql.CommonDataSource
        Specified by:
        setLogWriter in interface javax.sql.DataSource
        Throws:
        java.sql.SQLException
      • getLoginTimeout

        public int getLoginTimeout()
                            throws java.sql.SQLException
        Specified by:
        getLoginTimeout in interface javax.sql.CommonDataSource
        Specified by:
        getLoginTimeout in interface javax.sql.DataSource
        Throws:
        java.sql.SQLException
      • setLoginTimeout

        public void setLoginTimeout​(int arg0)
                             throws java.sql.SQLException
        Specified by:
        setLoginTimeout in interface javax.sql.CommonDataSource
        Specified by:
        setLoginTimeout in interface javax.sql.DataSource
        Throws:
        java.sql.SQLException
      • isWrapperFor

        public boolean isWrapperFor​(java.lang.Class<?> arg0)
                             throws java.sql.SQLException
        Specified by:
        isWrapperFor in interface java.sql.Wrapper
        Throws:
        java.sql.SQLException
      • unwrap

        public <T> T unwrap​(java.lang.Class<T> arg0)
                     throws java.sql.SQLException
        Specified by:
        unwrap in interface java.sql.Wrapper
        Throws:
        java.sql.SQLException
      • getParentLogger

        public java.util.logging.Logger getParentLogger()
                                                 throws java.sql.SQLFeatureNotSupportedException
        Specified by:
        getParentLogger in interface javax.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 Spring DataAccessException exactly like it would have been done when using Spring JdbcTemplate.
        Specified by:
        translateToDataAccessException in interface HybrisDataSource