From: <one...@us...> - 2003-01-04 11:16:00
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/connection In directory sc8-pr-cvs1:/tmp/cvs-serv14211/src/net/sf/hibernate/connection Modified Files: C3P0ConnectionProvider.java ConnectionProvider.java ConnectionProviderFactory.java DBCPConnectionProvider.java DatasourceConnectionProvider.java DriverManagerConnectionProvider.java UserSuppliedConnectionProvider.java Log Message: reformatted code with beautiful, shiny, happy TABS! improved an exception Index: C3P0ConnectionProvider.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/connection/C3P0ConnectionProvider.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** C3P0ConnectionProvider.java 1 Jan 2003 13:54:09 -0000 1.1.1.1 --- C3P0ConnectionProvider.java 4 Jan 2003 11:15:27 -0000 1.2 *************** *** 27,33 **** private DataSource ds; private Integer isolation; ! ! private static final Log log = LogFactory.getLog(C3P0ConnectionProvider.class); ! public Connection getConnection() throws SQLException { try { --- 27,33 ---- private DataSource ds; private Integer isolation; ! ! private static final Log log = LogFactory.getLog(C3P0ConnectionProvider.class); ! public Connection getConnection() throws SQLException { try { *************** *** 46,50 **** return true; } ! public void closeConnection(Connection conn) throws SQLException { try { --- 46,50 ---- return true; } ! public void closeConnection(Connection conn) throws SQLException { try { *************** *** 56,68 **** } } ! ! public void configure(Properties props) throws HibernateException { ! String jdbcDriverClass = props.getProperty(Environment.DRIVER); ! String jdbcUrl = props.getProperty(Environment.URL); ! Properties connectionProps = ConnectionProviderFactory.getJdbcConnectionProperties(props); ! ! log.info("C3P0 using driver: " + jdbcDriverClass + " at URL: " + jdbcUrl); ! log.info("Connection properties: " + connectionProps); ! if (jdbcDriverClass==null) { log.warn("No JDBC Driver class was specified by property " + Environment.DRIVER); --- 56,68 ---- } } ! ! public void configure(Properties props) throws HibernateException { ! String jdbcDriverClass = props.getProperty(Environment.DRIVER); ! String jdbcUrl = props.getProperty(Environment.URL); ! Properties connectionProps = ConnectionProviderFactory.getJdbcConnectionProperties(props); ! ! log.info("C3P0 using driver: " + jdbcDriverClass + " at URL: " + jdbcUrl); ! log.info("Connection properties: " + connectionProps); ! if (jdbcDriverClass==null) { log.warn("No JDBC Driver class was specified by property " + Environment.DRIVER); *************** *** 79,84 **** } ! try { ! int minPoolSize = PropertiesHelper.getInt(Environment.C3P0_MIN_SIZE, props, 1); int maxPoolSize = PropertiesHelper.getInt(Environment.C3P0_MAX_SIZE, props, 100); --- 79,84 ---- } ! try { ! int minPoolSize = PropertiesHelper.getInt(Environment.C3P0_MIN_SIZE, props, 1); int maxPoolSize = PropertiesHelper.getInt(Environment.C3P0_MAX_SIZE, props, 100); *************** *** 94,98 **** pcfg.setMaxStatements(maxStatements); pcfg.setTestConnectionOnCheckout(validateConnection); ! /*DataSource unpooled = DataSources.unpooledDataSource( jdbcUrl, props.getProperty(Environment.USER), props.getProperty(Environment.PASS) --- 94,98 ---- pcfg.setMaxStatements(maxStatements); pcfg.setTestConnectionOnCheckout(validateConnection); ! /*DataSource unpooled = DataSources.unpooledDataSource( jdbcUrl, props.getProperty(Environment.USER), props.getProperty(Environment.PASS) *************** *** 100,110 **** DataSource unpooled = DataSources.unpooledDataSource(jdbcUrl, connectionProps); ds = DataSources.pooledDataSource(unpooled, pcfg); ! ! } ! catch (Exception e) { ! log.fatal("could not instantiate C3P0 connection pool", e); ! throw new HibernateException( "Could not instantiate C3P0 connection pool", e ); ! } ! String i = props.getProperty(Environment.ISOLATION); if (i==null) { --- 100,110 ---- DataSource unpooled = DataSources.unpooledDataSource(jdbcUrl, connectionProps); ds = DataSources.pooledDataSource(unpooled, pcfg); ! ! } ! catch (Exception e) { ! log.fatal("could not instantiate C3P0 connection pool", e); ! throw new HibernateException( "Could not instantiate C3P0 connection pool", e ); ! } ! String i = props.getProperty(Environment.ISOLATION); if (i==null) { *************** *** 116,122 **** } ! } ! } ! \ No newline at end of file --- 116,124 ---- } ! } ! } ! ! ! Index: ConnectionProvider.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/connection/ConnectionProvider.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ConnectionProvider.java 1 Jan 2003 13:54:09 -0000 1.1.1.1 --- ConnectionProvider.java 4 Jan 2003 11:15:27 -0000 1.2 *************** *** 7,11 **** /** ! * A strategy for obtaining JDBC connections.Implementors might * also implement connection pooling.<br> * <br> --- 7,11 ---- /** ! * A strategy for obtaining JDBC connections.Implementors might * also implement connection pooling.<br> * <br> *************** *** 15,19 **** * <br> * Implementors should provide a public default constructor. ! * * @see ConnectionProviderFactory */ --- 15,19 ---- * <br> * Implementors should provide a public default constructor. ! * * @see ConnectionProviderFactory */ *************** *** 43,45 **** --- 43,48 ---- public boolean isStatementCache(); } + + + Index: ConnectionProviderFactory.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/connection/ConnectionProviderFactory.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ConnectionProviderFactory.java 1 Jan 2003 13:54:09 -0000 1.1.1.1 --- ConnectionProviderFactory.java 4 Jan 2003 11:15:27 -0000 1.2 *************** *** 17,21 **** * a <tt>java.util.Properties</tt> instance. The <tt>ConnectionProviderFactory</tt> * first attempts to find a name of a <tt>ConnectionProvider</tt> subclass in the ! * property <tt>hibernate.connection.provider_class</tt>. If missing, heuristics are used * to choose either <tt>DriverManagerConnectionProvider</tt>, * <tt>DatasourceConnectionProvider</tt>, <tt>C3P0ConnectionProvider</tt> or --- 17,21 ---- * a <tt>java.util.Properties</tt> instance. The <tt>ConnectionProviderFactory</tt> * first attempts to find a name of a <tt>ConnectionProvider</tt> subclass in the ! * property <tt>hibernate.connection.provider_class</tt>. If missing, heuristics are used * to choose either <tt>DriverManagerConnectionProvider</tt>, * <tt>DatasourceConnectionProvider</tt>, <tt>C3P0ConnectionProvider</tt> or *************** *** 25,29 **** public final class ConnectionProviderFactory { ! private static final Log log = LogFactory.getLog(ConnectionProviderFactory.class); --- 25,29 ---- public final class ConnectionProviderFactory { ! private static final Log log = LogFactory.getLog(ConnectionProviderFactory.class); *************** *** 36,40 **** return newConnectionProvider( Environment.getProperties() ); } ! /** * Instantiate a <tt>ConnectionProvider</tt> using given properties. --- 36,40 ---- return newConnectionProvider( Environment.getProperties() ); } ! /** * Instantiate a <tt>ConnectionProvider</tt> using given properties. *************** *** 55,59 **** log.fatal("Could not instantiate connection provider", e); throw new HibernateException("Could not instantiate connection provider: " + providerClass); ! } } else if ( properties.getProperty(Environment.DATASOURCE)!=null ) { --- 55,59 ---- log.fatal("Could not instantiate connection provider", e); throw new HibernateException("Could not instantiate connection provider: " + providerClass); ! } } else if ( properties.getProperty(Environment.DATASOURCE)!=null ) { *************** *** 78,82 **** // cannot be instantiated private ConnectionProviderFactory() { throw new UnsupportedOperationException(); } ! /** * Transform JDBC connection properties passed in the form <tt>hibernate.connection.*</tt> to the --- 78,82 ---- // cannot be instantiated private ConnectionProviderFactory() { throw new UnsupportedOperationException(); } ! /** * Transform JDBC connection properties passed in the form <tt>hibernate.connection.*</tt> to the *************** *** 108,111 **** return result; } ! } --- 108,114 ---- return result; } ! } + + + Index: DBCPConnectionProvider.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/connection/DBCPConnectionProvider.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** DBCPConnectionProvider.java 1 Jan 2003 13:54:10 -0000 1.1.1.1 --- DBCPConnectionProvider.java 4 Jan 2003 11:15:27 -0000 1.2 *************** *** 24,38 **** /** ! * A connection provider that uses an Apache commons DBCP connection pool. Hibernate will * use this by default if the <tt>hibernate.dbcp.*</tt> properties are set. * @see ConnectionProvider */ public class DBCPConnectionProvider implements ConnectionProvider { ! private DataSource ds; private Integer isolation; ! ! private static final Log log = LogFactory.getLog(DBCPConnectionProvider.class); ! public Connection getConnection() throws SQLException { try { --- 24,38 ---- /** ! * A connection provider that uses an Apache commons DBCP connection pool. Hibernate will * use this by default if the <tt>hibernate.dbcp.*</tt> properties are set. * @see ConnectionProvider */ public class DBCPConnectionProvider implements ConnectionProvider { ! private DataSource ds; private Integer isolation; ! ! private static final Log log = LogFactory.getLog(DBCPConnectionProvider.class); ! public Connection getConnection() throws SQLException { try { *************** *** 51,55 **** return true; } ! public void closeConnection(Connection conn) throws SQLException { try { --- 51,55 ---- return true; } ! public void closeConnection(Connection conn) throws SQLException { try { *************** *** 61,73 **** } } ! ! public void configure(Properties props) throws HibernateException { ! String jdbcDriverClass = props.getProperty(Environment.DRIVER); ! String jdbcUrl = props.getProperty(Environment.URL); ! Properties connectionProps = ConnectionProviderFactory.getJdbcConnectionProperties(props); ! ! log.info("DBCP using driver: " + jdbcDriverClass + " at URL: " + jdbcUrl); ! log.info("Connection properties: " + connectionProps); ! if (jdbcDriverClass==null) { log.warn("No JDBC Driver class was specified by property " + Environment.DRIVER); --- 61,73 ---- } } ! ! public void configure(Properties props) throws HibernateException { ! String jdbcDriverClass = props.getProperty(Environment.DRIVER); ! String jdbcUrl = props.getProperty(Environment.URL); ! Properties connectionProps = ConnectionProviderFactory.getJdbcConnectionProperties(props); ! ! log.info("DBCP using driver: " + jdbcDriverClass + " at URL: " + jdbcUrl); ! log.info("Connection properties: " + connectionProps); ! if (jdbcDriverClass==null) { log.warn("No JDBC Driver class was specified by property " + Environment.DRIVER); *************** *** 84,131 **** } ! try { ! ! // We'll need a ObjectPool that serves as the ! // actual pool of connections. ! ObjectPool connectionPool = new GenericObjectPool( ! null, ! Integer.parseInt( props.getProperty(Environment.DBCP_MAXACTIVE) ), ! Byte.parseByte( props.getProperty(Environment.DBCP_WHENEXHAUSTED) ), ! Long.parseLong( props.getProperty(Environment.DBCP_MAXWAIT) ), ! Integer.parseInt( props.getProperty(Environment.DBCP_MAXIDLE) ) ! ); ! ! // We'll need a KeyedObjectPoolFactory that serves as the ! // actual pool of prepared statements. ! KeyedObjectPoolFactory statementPool = new GenericKeyedObjectPoolFactory( ! null, ! Integer.parseInt( props.getProperty(Environment.DBCP_PS_MAXACTIVE) ), ! Byte.parseByte( props.getProperty(Environment.DBCP_PS_WHENEXHAUSTED) ), ! Long.parseLong( props.getProperty(Environment.DBCP_PS_MAXWAIT) ), ! Integer.parseInt( props.getProperty(Environment.DBCP_PS_MAXIDLE) ) ); ! ! // Next, we'll create a ConnectionFactory that the ! // pool will use to create Connections. ! // We'll use the DriverManagerConnectionFactory. ! ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(jdbcUrl, connectionProps); ! ! // Now we'll create the PoolableConnectionFactory, which wraps ! // the "real" Connections created by the ConnectionFactory with ! // the classes that implement the pooling functionality. ! String validationQuery = props.getProperty(Environment.DBCP_VALIDATION_QUERY); ! new PoolableConnectionFactory(connectionFactory, connectionPool, statementPool, validationQuery, false, false); ! ! // Finally, we create the PoolingDriver itself, ! // passing in the object pool we created. ! ds = new PoolingDataSource(connectionPool); ! ! ! } ! catch (Exception e) { ! log.fatal("could not instantiate DBCP connection pool", e); ! throw new HibernateException( "Could not instantiate DBCP connection pool", e ); ! } ! String i = props.getProperty(Environment.ISOLATION); if (i==null) { --- 84,131 ---- } ! try { ! ! // We'll need a ObjectPool that serves as the ! // actual pool of connections. ! ObjectPool connectionPool = new GenericObjectPool( ! null, ! Integer.parseInt( props.getProperty(Environment.DBCP_MAXACTIVE) ), ! Byte.parseByte( props.getProperty(Environment.DBCP_WHENEXHAUSTED) ), ! Long.parseLong( props.getProperty(Environment.DBCP_MAXWAIT) ), ! Integer.parseInt( props.getProperty(Environment.DBCP_MAXIDLE) ) ); ! ! // We'll need a KeyedObjectPoolFactory that serves as the ! // actual pool of prepared statements. ! KeyedObjectPoolFactory statementPool = new GenericKeyedObjectPoolFactory( ! null, ! Integer.parseInt( props.getProperty(Environment.DBCP_PS_MAXACTIVE) ), ! Byte.parseByte( props.getProperty(Environment.DBCP_PS_WHENEXHAUSTED) ), ! Long.parseLong( props.getProperty(Environment.DBCP_PS_MAXWAIT) ), ! Integer.parseInt( props.getProperty(Environment.DBCP_PS_MAXIDLE) ) ! ); ! ! // Next, we'll create a ConnectionFactory that the ! // pool will use to create Connections. ! // We'll use the DriverManagerConnectionFactory. ! ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(jdbcUrl, connectionProps); ! ! // Now we'll create the PoolableConnectionFactory, which wraps ! // the "real" Connections created by the ConnectionFactory with ! // the classes that implement the pooling functionality. ! String validationQuery = props.getProperty(Environment.DBCP_VALIDATION_QUERY); ! new PoolableConnectionFactory(connectionFactory, connectionPool, statementPool, validationQuery, false, false); ! ! // Finally, we create the PoolingDriver itself, ! // passing in the object pool we created. ! ds = new PoolingDataSource(connectionPool); ! ! ! } ! catch (Exception e) { ! log.fatal("could not instantiate DBCP connection pool", e); ! throw new HibernateException( "Could not instantiate DBCP connection pool", e ); ! } ! String i = props.getProperty(Environment.ISOLATION); if (i==null) { *************** *** 137,143 **** } ! } ! } ! \ No newline at end of file --- 137,145 ---- } ! } ! } ! ! ! Index: DatasourceConnectionProvider.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/connection/DatasourceConnectionProvider.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** DatasourceConnectionProvider.java 1 Jan 2003 13:54:10 -0000 1.1.1.1 --- DatasourceConnectionProvider.java 4 Jan 2003 11:15:27 -0000 1.2 *************** *** 20,53 **** */ 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 jndi_name = props.getProperty(Environment.DATASOURCE); ! if (jndi_name==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(jndi_name); ! } ! catch (Exception e) { ! log.fatal( "Could not find datasource: " + jndi_name, e ); ! throw new HibernateException( "Could not find datasource", e ); ! } ! log.info( "Using datasource: " + jndi_name ); ! } ! ! public Connection getConnection() throws SQLException { ! try { if (user != null || pass != null) { return ds.getConnection(user, pass); --- 20,53 ---- */ 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 jndi_name = props.getProperty(Environment.DATASOURCE); ! if (jndi_name==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(jndi_name); ! } ! catch (Exception e) { ! log.fatal( "Could not find datasource: " + jndi_name, e ); ! throw new HibernateException( "Could not find datasource", e ); ! } ! log.info( "Using datasource: " + jndi_name ); ! } ! ! public Connection getConnection() throws SQLException { ! try { if (user != null || pass != null) { return ds.getConnection(user, pass); *************** *** 56,80 **** return ds.getConnection(); } ! } ! catch (SQLException sqle) { ! JDBCExceptionReporter.logExceptions(sqle); ! throw sqle; ! } ! } ! ! public void closeConnection(Connection conn) throws SQLException { ! try { ! conn.close(); ! } ! catch (SQLException sqle) { ! JDBCExceptionReporter.logExceptions(sqle); ! throw sqle; ! } ! } ! public boolean isStatementCache() { return true; } ! } --- 56,83 ---- return ds.getConnection(); } ! } ! catch (SQLException sqle) { ! JDBCExceptionReporter.logExceptions(sqle); ! throw sqle; ! } ! } ! ! public void closeConnection(Connection conn) throws SQLException { ! try { ! conn.close(); ! } ! catch (SQLException sqle) { ! JDBCExceptionReporter.logExceptions(sqle); ! throw sqle; ! } ! } ! public boolean isStatementCache() { return true; } ! } + + + Index: DriverManagerConnectionProvider.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/connection/DriverManagerConnectionProvider.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DriverManagerConnectionProvider.java 3 Jan 2003 22:47:24 -0000 1.2 --- DriverManagerConnectionProvider.java 4 Jan 2003 11:15:27 -0000 1.3 *************** *** 36,47 **** String driverClass = props.getProperty(Environment.DRIVER); ! poolSize = PropertiesHelper.getInt(Environment.POOL_SIZE, props, 20); //default pool size 20 log.info("Hibernate connection pool size: " + poolSize); isolation = PropertiesHelper.getInteger(Environment.ISOLATION, props); ! if (isolation!=null) ! log.info( "JDBC isolation level: " + Environment.isolationLevelToString( isolation.intValue() ) ); ! if (driverClass==null) { log.warn("no JDBC Driver class was specified by property " + Environment.DRIVER); --- 36,47 ---- String driverClass = props.getProperty(Environment.DRIVER); ! poolSize = PropertiesHelper.getInt(Environment.POOL_SIZE, props, 20); //default pool size 20 log.info("Hibernate connection pool size: " + poolSize); isolation = PropertiesHelper.getInteger(Environment.ISOLATION, props); ! if (isolation!=null) ! log.info( "JDBC isolation level: " + Environment.isolationLevelToString( isolation.intValue() ) ); ! if (driverClass==null) { log.warn("no JDBC Driver class was specified by property " + Environment.DRIVER); *************** *** 59,70 **** url = props.getProperty(Environment.URL); ! if (url==null) { ! String msg = "JDBC URL was not specified by property " + Environment.URL; ! log.fatal(msg); ! throw new HibernateException(msg); ! } ! connectionProps = ConnectionProviderFactory.getJdbcConnectionProperties(props); ! log.info( "using driver: " + driverClass + " at URL: " + url ); log.info("connection properties: " + connectionProps); --- 59,70 ---- url = props.getProperty(Environment.URL); ! if (url==null) { ! String msg = "JDBC URL was not specified by property " + Environment.URL; ! log.fatal(msg); ! throw new HibernateException(msg); ! } ! connectionProps = ConnectionProviderFactory.getJdbcConnectionProperties(props); ! log.info( "using driver: " + driverClass + " at URL: " + url ); log.info("connection properties: " + connectionProps); *************** *** 128,132 **** JDBCExceptionReporter.logExceptions(sqle); throw sqle; ! } } --- 128,132 ---- JDBCExceptionReporter.logExceptions(sqle); throw sqle; ! } } *************** *** 149,153 **** } } ! } --- 149,156 ---- } } ! } + + + Index: UserSuppliedConnectionProvider.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/connection/UserSuppliedConnectionProvider.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** UserSuppliedConnectionProvider.java 1 Jan 2003 13:54:12 -0000 1.1.1.1 --- UserSuppliedConnectionProvider.java 4 Jan 2003 11:15:27 -0000 1.2 *************** *** 17,21 **** */ public class UserSuppliedConnectionProvider implements ConnectionProvider { ! /** * @see net.sf.hibernate.connection.ConnectionProvider#configure(Properties) --- 17,21 ---- */ public class UserSuppliedConnectionProvider implements ConnectionProvider { ! /** * @see net.sf.hibernate.connection.ConnectionProvider#configure(Properties) *************** *** 24,28 **** LogFactory.getLog(UserSuppliedConnectionProvider.class).warn("No connection properties specified - the user must supply JDBC connections"); } ! /** * @see net.sf.hibernate.connection.ConnectionProvider#getConnection() --- 24,28 ---- LogFactory.getLog(UserSuppliedConnectionProvider.class).warn("No connection properties specified - the user must supply JDBC connections"); } ! /** * @see net.sf.hibernate.connection.ConnectionProvider#getConnection() *************** *** 31,35 **** throw new UnsupportedOperationException("The user must supply a JDBC connection"); } ! /** * @see net.sf.hibernate.connection.ConnectionProvider#closeConnection(Connection) --- 31,35 ---- throw new UnsupportedOperationException("The user must supply a JDBC connection"); } ! /** * @see net.sf.hibernate.connection.ConnectionProvider#closeConnection(Connection) *************** *** 38,42 **** throw new UnsupportedOperationException("The user must supply a JDBC connection"); } ! /** * @see net.sf.hibernate.connection.ConnectionProvider#isStatementCache() --- 38,42 ---- throw new UnsupportedOperationException("The user must supply a JDBC connection"); } ! /** * @see net.sf.hibernate.connection.ConnectionProvider#isStatementCache() *************** *** 45,48 **** return false; } ! } --- 45,51 ---- return false; } ! } + + + |