Class DataSourceConnectionProvider

  • All Implemented Interfaces:
    java.io.Serializable, IConnectionProvider

    public class DataSourceConnectionProvider
    extends java.lang.Object
    implements IConnectionProvider, java.io.Serializable
    Adapter from JNDI DataSource interface to IConnectionProvider interface.
    Author:
    Javier Paniza
    See Also:
    Serialized Form
    • Constructor Detail

      • DataSourceConnectionProvider

        public DataSourceConnectionProvider()
    • Method Detail

      • getDataSource

        public javax.sql.DataSource getDataSource()
                                           throws javax.naming.NamingException
        DataSource to wrap
        Throws:
        javax.naming.NamingException
      • getDataSourceJNDI

        public java.lang.String getDataSourceJNDI()
        JNDI of DataSource to wrap.

        Only works if datasource == null

      • setDataSourceJNDI

        public void setDataSourceJNDI​(java.lang.String dataSourceJDNI)
        JNDI of DataSource to wrap.

        Only works if datasource == null

      • getConnection

        public java.sql.Connection getConnection()
                                          throws java.sql.SQLException
        Description copied from interface: IConnectionProvider
        Returns a JDBC connection by default.

        Specified by:
        getConnection in interface IConnectionProvider
        Throws:
        java.sql.SQLException - If there are problem obtaining the connetion
      • getConnection

        public java.sql.Connection getConnection​(java.lang.String dataSourceName)
                                          throws java.sql.SQLException
        Description copied from interface: IConnectionProvider
        Returns a JDBC connection from a identifier.

        Specified by:
        getConnection in interface IConnectionProvider
        Parameters:
        dataSourceName - Name of data source from what I obtain the connection
        Throws:
        java.sql.SQLException - If there are problem obtaining the connetion
      • setUser

        public void setUser​(java.lang.String user)
        Description copied from interface: IConnectionProvider
        Sets the user used to craete the connection.

        It is not mandatory to call this method.

        Specified by:
        setUser in interface IConnectionProvider
      • getPassword

        public java.lang.String getPassword()
      • getUser

        public java.lang.String getUser()
      • isUseHibernateConnection

        public static boolean isUseHibernateConnection()
        If true then all intances use hibernate connection for obtain connection, instead of data source connection pool.

        Useful for using outside an application server, for example, in a junit test.

      • setUseHibernateConnection

        public static void setUseHibernateConnection​(boolean useHibernateConnection)
        If true then all intances use hibernate connection for obtain connection, instead of data source connection pool.

        Useful for using outside an application server, for example, in a junit test.