Package org.openxava.util
Class DataSourceConnectionProvider
- java.lang.Object
-
- org.openxava.util.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 Summary
Constructors Constructor Description DataSourceConnectionProvider()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static IConnectionProvider
createByComponent(java.lang.String componentName)
static IConnectionProvider
getByComponent(java.lang.String componentName)
java.sql.Connection
getConnection()
Returns a JDBC connection by default.java.sql.Connection
getConnection(java.lang.String dataSourceName)
Returns a JDBC connection from a identifier.javax.sql.DataSource
getDataSource()
DataSource to wrapjava.lang.String
getDataSourceJNDI()
JNDI of DataSource to wrap.java.lang.String
getPassword()
java.lang.String
getUser()
static boolean
isUseHibernateConnection()
Iftrue
then all intances use hibernate connection for obtain connection, instead of data source connection pool.void
setDataSourceJNDI(java.lang.String dataSourceJDNI)
JNDI of DataSource to wrap.void
setDefaultDataSource(java.lang.String dataSourceName)
Sets the datasource name used when usingIConnectionProvider.getConnection()
.void
setPassword(java.lang.String password)
Sets password used to create connection.static void
setUseHibernateConnection(boolean useHibernateConnection)
Iftrue
then all intances use hibernate connection for obtain connection, instead of data source connection pool.void
setUser(java.lang.String user)
Sets the user used to craete the connection.
-
-
-
Method Detail
-
createByComponent
public static IConnectionProvider createByComponent(java.lang.String componentName) throws XavaException
- Throws:
XavaException
-
getByComponent
public static IConnectionProvider getByComponent(java.lang.String componentName) throws XavaException
- Throws:
XavaException
-
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 interfaceIConnectionProvider
- 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 interfaceIConnectionProvider
- Parameters:
dataSourceName
- Name of data source from what I obtain the connection- Throws:
java.sql.SQLException
- If there are problem obtaining the connetion
-
setPassword
public void setPassword(java.lang.String password)
Description copied from interface:IConnectionProvider
Sets password used to create connection.* Must to call to
IConnectionProvider.setUser(java.lang.String)
too. Although set user and password is not mandatory.- Specified by:
setPassword
in interfaceIConnectionProvider
-
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 interfaceIConnectionProvider
-
getPassword
public java.lang.String getPassword()
-
getUser
public java.lang.String getUser()
-
setDefaultDataSource
public void setDefaultDataSource(java.lang.String dataSourceName)
Description copied from interface:IConnectionProvider
Sets the datasource name used when usingIConnectionProvider.getConnection()
.- Specified by:
setDefaultDataSource
in interfaceIConnectionProvider
-
isUseHibernateConnection
public static boolean isUseHibernateConnection()
Iftrue
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)
Iftrue
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.
-
-