vgritsenko    2002/06/18 20:21:59

  Modified:    src/java/org/apache/cocoon/transformation Tag:
                        cocoon_2_0_3_branch SQLTransformer.java
  Log:
  Fix bug 6934
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.10.2.1  +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.10
  retrieving revision 1.10.2.1
  diff -u -r1.10 -r1.10.2.1
  --- SQLTransformer.java       8 Apr 2002 12:47:50 -0000       1.10
  +++ SQLTransformer.java       19 Jun 2002 03:21:59 -0000      1.10.2.1
  @@ -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:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to