org.openxava.util
Class DataSourceConnectionProvider

java.lang.Object
  extended by 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
DataSourceConnectionProvider()
           
 
Method Summary
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 wrap
 java.lang.String getDataSourceJNDI()
          JNDI of DataSource to wrap.
 java.lang.String getPassword()
           
 java.lang.String getUser()
           
static boolean isUseHibernateConnection()
          If true 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 using IConnectionProvider.getConnection().
 void setPassword(java.lang.String password)
          Sets password used to create connection.
static void setUseHibernateConnection(boolean useHibernateConnection)
          If true 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataSourceConnectionProvider

public DataSourceConnectionProvider()
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 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

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 interface IConnectionProvider

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()

setDefaultDataSource

public void setDefaultDataSource(java.lang.String dataSourceName)
Description copied from interface: IConnectionProvider
Sets the datasource name used when using IConnectionProvider.getConnection().

Specified by:
setDefaultDataSource in interface IConnectionProvider

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.