通过系统把几乎所有与人力资源相关的数据统一管理

源代码在线查看: datasourceconnectionprovider.java

软件大小: 23949 K
上传用户: RR15133422795
关键词: 人力资源 数据
下载地址: 免注册下载 普通下载 VIP

相关代码

				//$Id: DatasourceConnectionProvider.java,v 1.8.2.2 2003/10/25 11:11:45 oneovthafew Exp $				package net.sf.hibernate.connection;								import java.sql.Connection;				import java.sql.SQLException;				import java.util.Properties;								import javax.sql.DataSource;								import net.sf.hibernate.HibernateException;				import net.sf.hibernate.cfg.Environment;				import net.sf.hibernate.util.NamingHelper;								import org.apache.commons.logging.Log;				import org.apache.commons.logging.LogFactory;								/**				 * 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				 */				public class DatasourceConnectionProvider implements ConnectionProvider {					private DataSource ds;					private String user;					private String pass;										private static final Log log = LogFactory.getLog(DatasourceConnectionProvider.class);										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.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 Connection getConnection() throws SQLException {						if (user != null || pass != null) {							return ds.getConnection(user, pass);						}						else {							return ds.getConnection();						}					}										public void closeConnection(Connection conn) throws SQLException {						conn.close();					}										public void close() {}								}																																			

相关资源