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 IConnectionProvidercreateByComponent(java.lang.String componentName)static IConnectionProvidergetByComponent(java.lang.String componentName)java.sql.ConnectiongetConnection()Returns a JDBC connection by default.java.sql.ConnectiongetConnection(java.lang.String dataSourceName)Returns a JDBC connection from a identifier.javax.sql.DataSourcegetDataSource()DataSource to wrapjava.lang.StringgetDataSourceJNDI()JNDI of DataSource to wrap.java.lang.StringgetPassword()java.lang.StringgetUser()static booleanisUseHibernateConnection()Iftruethen all intances use hibernate connection for obtain connection, instead of data source connection pool.voidsetDataSourceJNDI(java.lang.String dataSourceJDNI)JNDI of DataSource to wrap.voidsetDefaultDataSource(java.lang.String dataSourceName)Sets the datasource name used when usingIConnectionProvider.getConnection().voidsetPassword(java.lang.String password)Sets password used to create connection.static voidsetUseHibernateConnection(boolean useHibernateConnection)Iftruethen all intances use hibernate connection for obtain connection, instead of data source connection pool.voidsetUser(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.NamingExceptionDataSource 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.SQLExceptionDescription copied from interface:IConnectionProviderReturns a JDBC connection by default.- Specified by:
getConnectionin 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.SQLExceptionDescription copied from interface:IConnectionProviderReturns a JDBC connection from a identifier.- Specified by:
getConnectionin 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:IConnectionProviderSets 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:
setPasswordin interfaceIConnectionProvider
-
setUser
public void setUser(java.lang.String user)
Description copied from interface:IConnectionProviderSets the user used to craete the connection.It is not mandatory to call this method.
- Specified by:
setUserin 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:IConnectionProviderSets the datasource name used when usingIConnectionProvider.getConnection().- Specified by:
setDefaultDataSourcein interfaceIConnectionProvider
-
isUseHibernateConnection
public static boolean isUseHibernateConnection()
Iftruethen 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)
Iftruethen 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.
-
-