FileDocCategorySizeDatePackage
DatasourceConnectionProvider.javaAPI DocHibernate 3.2.52300Sat Jul 01 07:50:34 BST 2006org.hibernate.connection

DatasourceConnectionProvider

public class DatasourceConnectionProvider extends Object implements 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.
see
ConnectionProvider
author
Gavin King

Fields Summary
private DataSource
ds
private String
user
private String
pass
private static final Log
log
Constructors Summary
Methods Summary
public voidclose()

public voidcloseConnection(java.sql.Connection conn)

		conn.close();
	
public voidconfigure(java.util.Properties props)


		String jndiName = props.getProperty(Environment.DATASOURCE);
		if (jndiName==null) {
			String msg = "datasource JNDI name was not specified by property " + Environment.DATASOURCE;
			log.fatal(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.fatal( "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 java.sql.ConnectiongetConnection()

		if (user != null || pass != null) {
			return ds.getConnection(user, pass);
		}
		else {
			return ds.getConnection();
		}
	
public javax.sql.DataSourcegetDataSource()


	   
		return ds;
	
public voidsetDataSource(javax.sql.DataSource ds)

		this.ds = ds;
	
public booleansupportsAggressiveRelease()

see
ConnectionProvider#supportsAggressiveRelease()

		return true;