Class DataSourceConnectionProvider
- All Implemented Interfaces:
Serializable,IConnectionProvider
- Author:
- Javier Paniza
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic IConnectionProvidercreateByComponent(String componentName) static IConnectionProvidergetByComponent(String componentName) static StringReturns the clean JNDI name of the default JPA data source (without 'java:comp/env/' prefix).Returns a database connection.getConnection(String dataSourceName) Returns a JDBC connection from a identifier.DataSource to wrapJNDI of DataSource to wrap.static StringReturns the clean JNDI name of the default JPA data source (without 'java:comp/env/' prefix), reading it directly from persistence.xml without triggering Hibernate initialization.getUser()static booleanIftruethen all intances use hibernate connection for obtain connection, instead of data source connection pool.voidsetDataSourceJNDI(String dataSourceJDNI) JNDI of DataSource to wrap.voidsetDefaultDataSource(String dataSourceName) Sets the datasource name used when usingIConnectionProvider.getConnection().voidsetPassword(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.voidSets the user used to craete the connection.
-
Constructor Details
-
DataSourceConnectionProvider
public DataSourceConnectionProvider()
-
-
Method Details
-
createByComponent
- Throws:
XavaException
-
getCleanJPADataSourceName
Returns the clean JNDI name of the default JPA data source (without 'java:comp/env/' prefix).- Since:
- 8.0
-
getDefaultCleanJPADataSourceName
Returns the clean JNDI name of the default JPA data source (without 'java:comp/env/' prefix), reading it directly from persistence.xml without triggering Hibernate initialization.- Since:
- 8.0
-
getByComponent
- Throws:
XavaException
-
getDataSource
DataSource to wrap- Throws:
NamingException
-
getDataSourceJNDI
JNDI of DataSource to wrap.Only works if datasource == null
-
setDataSourceJNDI
JNDI of DataSource to wrap.Only works if datasource == null
-
getConnection
Returns a database connection.By default the connection is obtained from the DataSource configured in JNDI. If
setUseHibernateConnection(boolean)is set to true, the connection is obtained directly from JPA/Hibernate.Since version 8.0: If there is an active manager in
XPersistence.getManager(), this method uses its connection instead of creating a new one. This avoids lock issues with Hibernate 7 when the connection is closed by legacy code that does not expect a Hibernate-managed connection. In this case, callingclose()on the returned connection has no effect because the connection will be closed automatically whenXPersistence.commit()is called at the end of OpenXava's action cycle.- Specified by:
getConnectionin interfaceIConnectionProvider- Throws:
SQLException- If there are problem obtaining the connetion
-
getConnection
Description 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:
SQLException- If there are problem obtaining the connetion
-
setPassword
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
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
-
getUser
-
setDefaultDataSource
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.
-