KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > ejb > InjectedDataSourceConnectionProvider


1 //$Id: InjectedDataSourceConnectionProvider.java,v 1.1 2005/07/15 00:07:03 epbernard Exp $
2
package org.hibernate.ejb;
3
4 import java.util.Properties JavaDoc;
5 import javax.sql.DataSource JavaDoc;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9 import org.hibernate.HibernateException;
10 import org.hibernate.cfg.Environment;
11 import org.hibernate.connection.DatasourceConnectionProvider;
12
13 /**
14  * A connection provider that uses an injected <tt>DataSource</tt>.
15  * Setters has to be called before configure()
16  * @see org.hibernate.connection.ConnectionProvider
17  * @author Emmanuel Bernard
18  */

19 public class InjectedDataSourceConnectionProvider extends DatasourceConnectionProvider {
20     private String JavaDoc user;
21     private String JavaDoc pass;
22
23     private static final Log log = LogFactory.getLog(InjectedDataSourceConnectionProvider.class);
24
25     public void setDataSource(DataSource JavaDoc ds) {
26         super.setDataSource( ds );
27     }
28
29     public void configure(Properties JavaDoc props) throws HibernateException {
30         user = props.getProperty(Environment.USER);
31         pass = props.getProperty(Environment.PASS);
32
33         if ( getDataSource() == null ) throw new HibernateException( "No datasource provided" );
34         log.info( "Using provided datasource" );
35     }
36
37 }
38
Popular Tags