cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon/acting/modular DatabaseAction.java DatabaseQueryAction.java DatabaseSelectAction.java
Date Fri, 09 Aug 2002 08:25:29 GMT
haul        2002/08/09 01:25:29

  Modified:    src/java/org/apache/cocoon/acting/modular
                        DatabaseAction.java DatabaseQueryAction.java
                        DatabaseSelectAction.java
  Log:
    <action dev="CH" type="fix">
     (Modular) DatabaseActions: select produced wrong result if no rows were
     found, query action returned broken result.
    </action>
  
  Revision  Changes    Path
  1.7       +6 -5      xml-cocoon2/src/java/org/apache/cocoon/acting/modular/DatabaseAction.java
  
  Index: DatabaseAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/modular/DatabaseAction.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DatabaseAction.java	10 Jun 2002 08:34:45 -0000	1.6
  +++ DatabaseAction.java	9 Aug 2002 08:25:29 -0000	1.7
  @@ -489,11 +489,11 @@
   
                   if ( column.isSet ){
                       if (getLogger().isDebugEnabled())
  -                        getLogger().debug( "Trying to set column " + cname +" using getAttributeValues
method");
  +                        getLogger().debug( "Trying to set column " + cname +" from "+column.mode+"
using getAttributeValues method");
                       values = input.getAttributeValues( cname, column.modeConf, objectModel
);
                   } else {
                       if (getLogger().isDebugEnabled())
  -                        getLogger().debug( "Trying to set column " + cname +" using getAttribute
method");
  +                        getLogger().debug( "Trying to set column " + cname +" from "+column.mode+"
using getAttribute method");
                       values = new Object[1];
                       values[0] = input.getAttribute( cname, column.modeConf, objectModel
);
                   }
  @@ -603,7 +603,7 @@
                                  Configuration table, Configuration column, int rowIndex,

                                  Object value, PreparedStatement statement, int position
) throws Exception {
   
  -        this.setOutput( objectModel, outputMode, results, table, column, rowIndex, value
);
  +        if (results!=null) this.setOutput( objectModel, outputMode, results, table, column,
rowIndex, value );
           this.setColumn( statement, position, column, value );
       }
   
  @@ -753,8 +753,9 @@
           } catch (Exception e) {
               if ( conn != null ) {
                   try {
  -                    if (getLogger().isDebugEnabled())
  +                    if (getLogger().isDebugEnabled()) {
                           getLogger().debug( "Rolling back transaction. Caused by " + e.getMessage()
);
  +                    }
                       conn.rollback();
                       results = null;
   
  
  
  
  1.2       +24 -11    xml-cocoon2/src/java/org/apache/cocoon/acting/modular/DatabaseQueryAction.java
  
  Index: DatabaseQueryAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/modular/DatabaseQueryAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DatabaseQueryAction.java	2 Jul 2002 08:17:46 -0000	1.1
  +++ DatabaseQueryAction.java	9 Aug 2002 08:25:29 -0000	1.2
  @@ -56,6 +56,7 @@
   import java.sql.Clob;
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
  +import java.sql.ResultSetMetaData;
   import java.sql.SQLException;
   import java.sql.Struct;
   import java.sql.Types;
  @@ -134,16 +135,15 @@
                   Configuration[] keys = table.getChild("keys").getChildren("key");
                   Configuration[] values = table.getChild("values").getChildren("value");
   
  -                queryData = new CacheHelper( keys.length, keys.length + values.length );
  -                fillModes( keys  , true , defaultModeNames, modeTypes, queryData );
  -                fillModes( values, false, defaultModeNames, modeTypes, queryData );
  -                
                   boolean found = false;
                   String queryModeName = "";
  +                String query = "";
  +                boolean useValues = true;
                   for (int i=0; i<queries.length; i++) {
                       queryModeName = queries[i].getAttribute("mode",null);
                       if ( queryModeName.equals((String)modeTypes.get(MODE_OTHERS)) || "all".equals(queryModeName))
{
  -                        queryData.queryString = queries[i].getValue();
  +                        query = queries[i].getValue();
  +                        useValues = queries[i].getAttributeAsBoolean("use-values", useValues);
                           found = true;
                           break;
                       }
  @@ -155,6 +155,13 @@
                                                        " for table " + table.getAttribute("name",null));
                   }
   
  +                
  +
  +                queryData = new CacheHelper( keys.length, keys.length + (useValues ? values.length
: 0));
  +                queryData.queryString = query;
  +                fillModes( keys  , true , defaultModeNames, modeTypes, queryData );
  +                if (useValues) fillModes( values, false, defaultModeNames, modeTypes, queryData
);
  +                
                   this.cachedQueryData.put( lookUpKey, queryData );
               }
           }
  @@ -202,16 +209,22 @@
           } else {
               // retrieve values
               ResultSet resultset = statement.getResultSet();
  +            ResultSetMetaData metadata = resultset.getMetaData();
               rowIndex = 0;
               while ( resultset.next() ){
                   //if ( ! ( rowIndex == -1 && resultset.isLast() ) ) {
                   rowIndex++;
                   //}
  -                for (int i = 0; i < queryData.columns.length; i++) {
  -                    if ( !queryData.columns[i].isKey ) {
  -                        Object value = JDBCTypeConversions.getColumn( resultset, queryData.columns[i].columnConf
);
  -                        this.setOutput(objectModel, outputMode, results, table, queryData.columns[i].columnConf,
rowIndex, value);
  -                    }
  +                String tableName = "";
  +                String columnName = "";
  +                for (int i = 1; i <= metadata.getColumnCount(); i++) {
  +                    Object value = resultset.getObject(i);
  +                    tableName = metadata.getTableName(i);
  +                    columnName = metadata.getColumnLabel(i) + "["+rowIndex+"]";
  +                    if (tableName != "") columnName = tableName + "." + columnName;
  +                    if (this.getLogger().isDebugEnabled())
  +                        this.getLogger().debug("retrieving "+columnName+" as "+value);
  +                    results.put(metadata.getTableName(i)+"."+metadata.getColumnLabel(i),value);
                   }
               }
               return rowIndex;
  
  
  
  1.4       +3 -5      xml-cocoon2/src/java/org/apache/cocoon/acting/modular/DatabaseSelectAction.java
  
  Index: DatabaseSelectAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/modular/DatabaseSelectAction.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DatabaseSelectAction.java	28 May 2002 13:42:50 -0000	1.3
  +++ DatabaseSelectAction.java	9 Aug 2002 08:25:29 -0000	1.4
  @@ -194,7 +194,7 @@
           for (int i = 0; i < queryData.columns.length; i++) {
               Column col = queryData.columns[i];
               if ( col.isKey ) {
  -                this.setColumn(objectModel, outputMode, results, table, col.columnConf,
rowIndex,
  +                this.setColumn(objectModel, outputMode, null, table, col.columnConf, rowIndex,
                                  columnValues[ i ][ ( col.isSet ? rowIndex : 0 ) ], statement,
currentIndex );
                   currentIndex++;
               }
  @@ -204,15 +204,13 @@
           ResultSet resultset = statement.getResultSet();
           rowIndex = 0;
           while ( resultset.next() ){
  -            //if ( ! ( rowIndex == -1 && resultset.isLast() ) ) {
  -                rowIndex++;
  -            //}
               for (int i = 0; i < queryData.columns.length; i++) {
                   if ( !queryData.columns[i].isKey ) {
                       Object value = JDBCTypeConversions.getColumn( resultset, queryData.columns[i].columnConf
);
                       this.setOutput(objectModel, outputMode, results, table, queryData.columns[i].columnConf,
rowIndex, value);
                   }
               }
  +			rowIndex++;
           }
           return rowIndex;
       }
  
  
  

----------------------------------------------------------------------
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


Mime
View raw message