org.hibernate.connection
public class: DatasourceConnectionProvider [javadoc |
source]
java.lang.Object
org.hibernate.connection.DatasourceConnectionProvider
All Implemented Interfaces:
ConnectionProvider
A connection provider that uses a
DataSource registered with JNDI.
Hibernate will use this
ConnectionProvider by default if the
property
hibernate.connection.datasource is set.
| Method from org.hibernate.connection.DatasourceConnectionProvider Detail: |
public void close() {
}
|
public void closeConnection(Connection conn) throws SQLException {
conn.close();
}
|
public void configure(Properties props) throws HibernateException {
String jndiName = props.getProperty( Environment.DATASOURCE );
if ( jndiName == null ) {
String msg = "datasource JNDI name was not specified by property " + Environment.DATASOURCE;
log.error( msg );
throw new HibernateException( msg );
}
user = props.getProperty( Environment.USER );
pass = props.getProperty( Environment.PASS );
try {
ds = ( DataSource ) NamingHelper.getInitialContext( props ).lookup( jndiName );
}
catch ( Exception e ) {
log.error( "Could not find datasource: " + jndiName, e );
throw new HibernateException( "Could not find datasource", e );
}
if ( ds == null ) {
throw new HibernateException( "Could not find datasource: " + jndiName );
}
log.info( "Using datasource: " + jndiName );
}
|
public Connection getConnection() throws SQLException {
if (user != null || pass != null) {
return ds.getConnection(user, pass);
}
else {
return ds.getConnection();
}
}
|
public DataSource getDataSource() {
return ds;
}
|
public void setDataSource(DataSource ds) {
this.ds = ds;
}
|
public boolean supportsAggressiveRelease() {
return true;
}
|