james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject cvs commit: james-server/src/java/org/apache/james/util/dbcp JdbcDataSource.java
Date Thu, 24 Jul 2003 01:45:59 GMT
noel        2003/07/23 18:45:58

  Modified:    src/conf Tag: branch_2_1_fcs james-config.xml
               src/java/org/apache/james/util/dbcp Tag: branch_2_1_fcs
                        JdbcDataSource.java
  Log:
  Updated DBCP support to validate connections.  Made DBCP the default.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.40.2.15 +12 -2     james-server/src/conf/james-config.xml
  
  Index: james-config.xml
  ===================================================================
  RCS file: /home/cvs/james-server/src/conf/james-config.xml,v
  retrieving revision 1.40.2.14
  retrieving revision 1.40.2.15
  diff -u -r1.40.2.14 -r1.40.2.15
  --- james-config.xml	21 Jul 2003 02:56:08 -0000	1.40.2.14
  +++ james-config.xml	24 Jul 2003 01:45:58 -0000	1.40.2.15
  @@ -763,7 +763,17 @@
         <!-- If you are not using a database, you can leave this section unchanged. -->
         <!-- These connections are referred to by name in URLs elsewhere in the config
file. -->
         <data-sources>
  +         <!--
  +              James has previously used an in-house connection pool, Mordred.
  +              Mordred is being deprecated in favor of Jakarta Commons DBCP.
  +              To use DBCP:    org.apache.james.util.mordred.JdbcDataSource
  +              To use Mordred: org.apache.james.util.dbcp.JdbcDataSource
  +
  +              Change it back, of course, to use Mordred.
   
  +              NOTE: DBCP is configured to recover from a database server outage.
  +                    This, alone, may be reason for you to give it a try.
  +         -->
            <!-- James is distributed with a built in relevant copy of the mm.mysql JDBC
   -->
            <!-- driver.  No additional driver is needed for mysql. Read the mm.mysql LGPL
 -->
            <!-- license at apps\james\SAR-INF\lib\mm.mysql.LICENCE                   
   -->
  @@ -777,7 +787,7 @@
            <!-- If you see "SQLException: Giving up... no connections available." in your
-->
            <!-- log files or bounced mail you should increase this value -->
            <!--
  -         <data-source name="maildb" class="org.apache.james.util.mordred.JdbcDataSource">
  +         <data-source name="maildb" class="org.apache.james.util.dbcp.JdbcDataSource">
               <driver>org.gjt.mm.mysql.Driver</driver>
               <dburl>jdbc:mysql://127.0.0.1/mail?autoReconnect=true</dburl>
               <user>username</user>
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +34 -6     james-server/src/java/org/apache/james/util/dbcp/Attic/JdbcDataSource.java
  
  Index: JdbcDataSource.java
  ===================================================================
  RCS file: /home/cvs/james-server/src/java/org/apache/james/util/dbcp/Attic/JdbcDataSource.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- JdbcDataSource.java	21 Jul 2003 02:54:03 -0000	1.1.2.1
  +++ JdbcDataSource.java	24 Jul 2003 01:45:58 -0000	1.1.2.2
  @@ -98,11 +98,23 @@
               String user = configuration.getChild("user").getValue(null);
               String password = configuration.getChild("password").getValue(null);
   
  -            //First cut at this
  -            //This approach can't survive a database outage, so this is a sidewase upgrade
  -            //  from mordred feature-wise, although upgrade from potential upgrades and
  -            //  maintenance perspective.
  -            source = new BasicDataSource();
  +            // This inner class extends DBCP's BasicDataSource, and
  +            // turns on validation (using Connection.isClosed()), so
  +            // that the pool can recover from a server outage.
  +            source = new BasicDataSource() {
  +                protected synchronized javax.sql.DataSource createDataSource()
  +                        throws SQLException {
  +                    if (dataSource != null) {
  +                        return (dataSource);
  +                    } else {
  +                        javax.sql.DataSource ds = super.createDataSource();
  +                        connectionPool.setTestOnBorrow(true);
  +                        connectionPool.setTestOnReturn(true);
  +                        return ds;
  +                    }
  +                }
  +            };
  +
               source.setDriverClassName(driver);
               source.setUrl(dburl);
               source.setUsername(user);
  @@ -115,6 +127,22 @@
   
               //This is necessary, otherwise a connection could hang forever
               source.setMaxWait(configuration.getChild("max_wait").getValueAsInteger(5000));
  +
  +            // DBCP uses a PrintWriter approach to logging.  This
  +            // Writer class will bridge between DBCP and Avalon
  +            // Logging. Unfortunately, DBCP 1.0 is clueless about the
  +            // concept of a log level.
  +            final java.io.Writer writer = new java.io.CharArrayWriter() {
  +                public void flush() {
  +                    // flush the stream to the log
  +                    if (JdbcDataSource.this.getLogger().isErrorEnabled()) {
  +                        JdbcDataSource.this.getLogger().error(toString());
  +                    }
  +                    reset();    // reset the contents for the next message
  +                }
  +            };
  +
  +            source.setLogWriter(new PrintWriter(writer, true));
   
               /*
               Extra debug for first cut
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message