You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2002/06/19 05:21:59 UTC

cvs commit: xml-cocoon2/src/java/org/apache/cocoon/transformation SQLTransformer.java

vgritsenko    2002/06/18 20:21:59

  Modified:    .        changes.xml
               .        Tag: cocoon_2_0_3_branch changes.xml
               src/java/org/apache/cocoon/transformation
                        SQLTransformer.java
  Log:
  Fix bug 6934
  
  Revision  Changes    Path
  1.191     +6 -1      xml-cocoon2/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/changes.xml,v
  retrieving revision 1.190
  retrieving revision 1.191
  diff -u -r1.190 -r1.191
  --- changes.xml	16 Jun 2002 08:40:49 -0000	1.190
  +++ changes.xml	19 Jun 2002 03:21:59 -0000	1.191
  @@ -38,6 +38,11 @@
    </devs>
   
    <release version="@version@" date="@date@">
  +  <action dev="VG" type="fix" fixes-bug="6934">
  +   Add connect-attempts and connect-waittime parameters to the SQLTransformer.
  +   Transformer tries to get a connection to the DB several times before
  +   returning an error.
  +  </action>
     <action dev="DC" type="add">
      Encourage people to help with the refactoring of Cocoon samples.
      Provide a 
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.138.2.24 +6 -1      xml-cocoon2/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/changes.xml,v
  retrieving revision 1.138.2.23
  retrieving revision 1.138.2.24
  diff -u -r1.138.2.23 -r1.138.2.24
  --- changes.xml	17 Jun 2002 02:20:44 -0000	1.138.2.23
  +++ changes.xml	19 Jun 2002 03:21:59 -0000	1.138.2.24
  @@ -38,6 +38,11 @@
    </devs>
   
    <release version="@version@" date="@date@">
  +  <action dev="VG" type="fix" fixes-bug="6934">
  +   Add connect-attempts and connect-waittime parameters to the SQLTransformer.
  +   Transformer tries to get a connection to the DB several times before
  +   returning an error.
  +  </action>
     <action dev="VG" type="fix" fixes-bug="8658" due-to="Michael Melhem" due-to-email="michaelm@fztig938.bank.dresdner.net">
      Fix sitemap compilation error when matchers are used within view or resource.
     </action>
  
  
  
  1.13      +36 -10    xml-cocoon2/src/java/org/apache/cocoon/transformation/SQLTransformer.java
  
  Index: SQLTransformer.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/transformation/SQLTransformer.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- SQLTransformer.java	21 May 2002 09:41:54 -0000	1.12
  +++ SQLTransformer.java	19 Jun 2002 03:21:59 -0000	1.13
  @@ -139,6 +139,23 @@
       protected static final int STATE_INSIDE_OUT_PARAMETER_ELEMENT = 7;
       protected static final int STATE_INSIDE_ESCAPE_STRING = 8;
   
  +    //
  +    // Configuration
  +    //
  +
  +    /** Is the old-driver turned on? (default is off) */
  +    private boolean oldDriver = false;
  +
  +    /** How many connection attempts to do? (default is 5 times) */
  +    private int connectAttempts = 5;
  +
  +    /** How long wait between connection attempts? (default is 5000 ms) */
  +    private int connectWaittime = 5;
  +
  +    //
  +    // State
  +    //
  +
       /** The list of queries that we're currently working on **/
       protected Vector queries;
   
  @@ -151,9 +168,6 @@
       /** Check if nr of rows need to be written out. **/
       protected boolean showNrOfRows;
   
  -    /** Is the old-driver turned on? (default is off) */
  -    private boolean oldDriver = false;
  -
       /** Namespace prefix to output */
       protected String outPrefix;
   
  @@ -220,7 +234,9 @@
        * dispose
        */
       public void dispose() {
  -        if ( this.dbSelector != null ) this.manager.release( (Component) this.dbSelector );
  +        if ( this.dbSelector != null ) {
  +            this.manager.release( (Component) this.dbSelector );
  +        }
       }
   
       /**
  @@ -229,11 +245,13 @@
       public void configure( Configuration conf ) throws ConfigurationException {
           super.configure( conf );
           if ( conf != null ) {
  -            Configuration child = conf.getChild( "old-driver" );
  -            this.oldDriver = child.getValueAsBoolean( false );
  +            this.oldDriver = conf.getChild( "old-driver" ).getValueAsBoolean( false );
               if (this.getLogger().isDebugEnabled()) {
                   this.getLogger().debug( "old-driver is " + this.oldDriver + " for " + this );
               }
  +
  +            this.connectAttempts = conf.getChild("connect-attempts").getValueAsInteger(5);
  +            this.connectWaittime = conf.getChild("connect-waittime").getValueAsInteger(5000);
           }
       }
   
  @@ -994,12 +1012,14 @@
   
                           try {
                               datasource = (DataSourceComponent) this.transformer.dbSelector.select( connection );
  -                            while ( result == null ) {
  +                            for ( int i = 0; i < transformer.connectAttempts && result == null; i++) {
                                   try {
                                       result = datasource.getConnection();
                                   } catch ( Exception e ) {
  -                                    final long waittime = 5000;
  -                                    getTheLogger().debug( "SQLTransformer$Query: could not acquire a Connection -- waiting " + waittime + " ms to try again." );
  +                                    final long waittime = transformer.connectWaittime;
  +                                    transformer.getTheLogger().debug(
  +                                            "SQLTransformer$Query: could not acquire a Connection -- waiting "
  +                                            + waittime + " ms to try again." );
                                       try {
                                           Thread.sleep( waittime );
                                       } catch ( InterruptedException ie ) {
  @@ -1010,6 +1030,12 @@
                                transformer.getTheLogger().error( "Could not use connection: " + connection, cme );
                           } finally {
                               if ( datasource != null ) this.transformer.dbSelector.release( datasource );
  +                        }
  +
  +                        if (result == null) {
  +                            throw new SQLException("Failed to obtain connection. Made "
  +                                    + transformer.connectAttempts + " attempts with "
  +                                    + transformer.connectWaittime + "ms interval");
                           }
                       }
                   } else {
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org