Return-Path: Mailing-List: contact cocoon-cvs-help@xml.apache.org; run by ezmlm Delivered-To: mailing list cocoon-cvs@xml.apache.org Received: (qmail 99687 invoked by uid 1152); 8 Jan 2001 20:20:50 -0000 Date: 8 Jan 2001 20:20:50 -0000 Message-ID: <20010108202050.99685.qmail@apache.org> From: bloritsch@apache.org To: xml-cocoon-cvs@apache.org Subject: cvs commit: xml-cocoon/src/org/apache/cocoon/components/datasource DataSourceComponent.java JdbcDataSource.java bloritsch 01/01/08 12:20:49 Modified: lib Tag: xml-cocoon2 avalonapi.jar src/org/apache/cocoon Tag: xml-cocoon2 CocoonComponentSelector.java src/org/apache/cocoon/components/datasource Tag: xml-cocoon2 DataSourceComponent.java JdbcDataSource.java Log: Made the JdbcDataSource Much more robust with a closed end pool. Next, I need to look at merging all background pool management and file monitoring in one Thread and use an event model to do the actual pool management. Revision Changes Path No revision No revision 1.1.2.12 +257 -243 xml-cocoon/lib/Attic/avalonapi.jar <> No revision No revision 1.1.2.10 +3 -2 xml-cocoon/src/org/apache/cocoon/Attic/CocoonComponentSelector.java Index: CocoonComponentSelector.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/CocoonComponentSelector.java,v retrieving revision 1.1.2.9 retrieving revision 1.1.2.10 diff -u -r1.1.2.9 -r1.1.2.10 --- CocoonComponentSelector.java 2001/01/05 16:20:58 1.1.2.9 +++ CocoonComponentSelector.java 2001/01/08 20:20:44 1.1.2.10 @@ -26,6 +26,7 @@ import org.apache.avalon.Composer; import org.apache.avalon.ConfigurationException; +import org.apache.cocoon.util.ClassUtils; import org.apache.cocoon.util.ComponentPool; import org.apache.cocoon.util.ComponentPoolController; @@ -35,7 +36,7 @@ /** Default component manager for Cocoon's non sitemap components. * @author Berin Loritsch * @author Paul Russell - * @version CVS $Revision: 1.1.2.9 $ $Date: 2001/01/05 16:20:58 $ + * @version CVS $Revision: 1.1.2.10 $ $Date: 2001/01/08 20:20:44 $ */ public class CocoonComponentSelector implements ComponentSelector, Composer, ThreadSafe { protected Logger log = LogKit.getLoggerFor("cocoon"); @@ -117,7 +118,7 @@ } // Work out what class of component we're dealing with. - if ( ThreadSafe.class.isAssignableFrom(componentClass) ) { + if ( ThreadSafe.class.isAssignableFrom(componentClass)) { component = getThreadsafeComponent(componentClass); } else if ( Poolable.class.isAssignableFrom(componentClass) ) { component = getPooledComponent(componentClass); No revision No revision 1.1.2.2 +5 -4 xml-cocoon/src/org/apache/cocoon/components/datasource/Attic/DataSourceComponent.java Index: DataSourceComponent.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/datasource/Attic/DataSourceComponent.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- DataSourceComponent.java 2001/01/05 23:08:34 1.1.2.1 +++ DataSourceComponent.java 2001/01/08 20:20:46 1.1.2.2 @@ -9,18 +9,19 @@ import org.apache.avalon.Component; import org.apache.avalon.Configurable; -import org.apache.avalon.Poolable; + import java.sql.Connection; +import java.sql.SQLException; /** * The standard interface for DataSources in Cocoon. * * @author Berin Loritsch - * @version CVS $Revision: 1.1.2.1 $ $Date: 2001/01/05 23:08:34 $ + * @version CVS $Revision: 1.1.2.2 $ $Date: 2001/01/08 20:20:46 $ */ -public interface DataSourceComponent extends Component, Configurable, Poolable { +public interface DataSourceComponent extends Component, Configurable { /** * Gets the Connection to the database */ - Connection getConnection(); + Connection getConnection() throws SQLException; } 1.1.2.4 +44 -24 xml-cocoon/src/org/apache/cocoon/components/datasource/Attic/JdbcDataSource.java Index: JdbcDataSource.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/datasource/Attic/JdbcDataSource.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- JdbcDataSource.java 2001/01/08 15:29:32 1.1.2.3 +++ JdbcDataSource.java 2001/01/08 20:20:47 1.1.2.4 @@ -9,46 +9,66 @@ import org.apache.avalon.Configuration; import org.apache.avalon.ConfigurationException; -import org.apache.cocoon.util.ClassUtils; +import org.apache.avalon.ThreadSafe; import org.apache.log.LogKit; import org.apache.log.Logger; + import java.sql.Connection; -import java.sql.DriverManager; +import java.sql.SQLException; /** - * The Default implementation for DataSources in Cocoon. + * The Default implementation for DataSources in Cocoon. This uses the + * normal java.sql.Connection object and + * java.sql.DriverManager. + * + * TODO: Implement a configurable closed end Pool, where the Connection + * acts like JDBC PooledConnections work. That means we can limit the + * total number of Connection objects that are created. * * @author Berin Loritsch - * @version CVS $Revision: 1.1.2.3 $ $Date: 2001/01/08 15:29:32 $ + * @version CVS $Revision: 1.1.2.4 $ $Date: 2001/01/08 20:20:47 $ */ -public class JdbcDataSource implements DataSourceComponent { - String dburl; - String user; - String passwd; +public class JdbcDataSource implements DataSourceComponent, ThreadSafe { Logger log = LogKit.getLoggerFor("cocoon"); - Connection dbConnection = null; + JdbcConnectionPool pool = null; - /** Configure and set up DB connection */ + /** + * Configure and set up DB connection. Here we set the connection + * information needed to create the Connection objects. It must + * be called only once. + * + * @param conf The Configuration object needed to describe the + * connection. + * + * @throws ConfigurationException + */ public void configure(Configuration conf) throws ConfigurationException { - this.dburl = conf.getChild("dburl").getValue(); - this.user = conf.getChild("user").getValue(); - this.passwd = conf.getChild("password").getValue(); + if (this.pool == null) { + String dburl = conf.getChild("dburl").getValue(); + String user = conf.getChild("user").getValue(); + String passwd = conf.getChild("password").getValue(); - try { - if (user.equals("")) { - this.dbConnection = DriverManager.getConnection(dburl); - } else { - this.dbConnection = DriverManager.getConnection(dburl, user, passwd); - } - } catch (Exception e) { - log.error("Could not connect to Database", e); - throw new ConfigurationException("Could not connect to Database", e); + Configuration controler = conf.getChild("pool-controller"); + int min = controler.getAttributeAsInt("min", 0); + int max = controler.getAttributeAsInt("max", 1); + + this.pool = new JdbcConnectionPool(dburl, user, passwd, min, max); } } /** Get the database connection */ - public Connection getConnection() { - return this.dbConnection; + public Connection getConnection() + throws SQLException { + Connection conn = null; + + try { + conn = (Connection) this.pool.get(); + } catch (Exception e) { + log.error("Could not return Connection", e); + throw new SQLException(e.getMessage()); + } + + return conn; } }