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/components/language/markup/xsp EsqlConnection.java EsqlHelper.java EsqlQuery.java
Date Thu, 16 May 2002 16:01:17 GMT
haul        02/05/16 09:01:17

  Modified:    src/java/org/apache/cocoon/components/language/markup/xsp
                        EsqlConnection.java EsqlHelper.java EsqlQuery.java
  Log:
  Fixes bugs / patches
  7507 [PATCH] esql - support CLOB in get-xml
  9004 [PATCH] add failure-ok to eql:query and documentation
  7181 esql:group behaves erratically
  8737 esql.xsl: getUrl() for datatypes OTHER
  with modifications:
  
  failure-ok is _not_ added. Instead error-results are evaulated when an exception is caught.
  If error-results is absent, an exception is raised. If it is present but empty, the error
  is swallowed.
  
  grouping code is completely redone. that should fix most problems previously encountered
  but one: footers are still not supported as that would require to have scrollable cursors
  or cache one row. Will add scrollable cursors as option in another patch.
  
  PS: will commit to cocoon_2_0_3_branch with time lag since I would like to see if there
  are complaints first...
  
  Revision  Changes    Path
  1.8       +7 -2      xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlConnection.java
  
  Index: EsqlConnection.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlConnection.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- EsqlConnection.java	17 Apr 2002 13:09:02 -0000	1.7
  +++ EsqlConnection.java	16 May 2002 16:01:17 -0000	1.8
  @@ -60,7 +60,7 @@
    *
    * based on the orginal esql.xsl
    * @author <a href="mailto:tcurdt@dff.st">Torsten Curdt</a>
  - * @version CVS $Id: EsqlConnection.java,v 1.7 2002/04/17 13:09:02 cziegeler Exp $
  + * @version CVS $Id: EsqlConnection.java,v 1.8 2002/05/16 16:01:17 haul Exp $
    */
   
   public class EsqlConnection implements Connection {
  @@ -80,7 +80,12 @@
     }
   
     public String getUrl() {
  -    return(url);
  +    if (this.url == null) 
  +      try {
  +        this.url=this.connection.getMetaData().getURL();
  +      } catch (SQLException e) {
  +      };
  +    return this.url;
     }
   
     public void setUrl( String url ) {
  
  
  
  1.9       +70 -26    xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlHelper.java
  
  Index: EsqlHelper.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlHelper.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- EsqlHelper.java	14 May 2002 12:16:08 -0000	1.8
  +++ EsqlHelper.java	16 May 2002 16:01:17 -0000	1.9
  @@ -51,9 +51,12 @@
   package org.apache.cocoon.components.language.markup.xsp;
   
   import java.io.BufferedInputStream;
  +import java.io.BufferedReader;
  +import java.io.Reader;
   import java.sql.ResultSet;
   import java.io.InputStream;
   import java.sql.Clob;
  +import java.sql.Types;
   
   /**
    * This is a helper class to remove redundant code in
  @@ -61,46 +64,88 @@
    *
    * based on the orginal esql.xsl
    * @author <a href="mailto:tcurdt@dff.st">Torsten Curdt</a>
  - * @version CVS $Id: EsqlHelper.java,v 1.8 2002/05/14 12:16:08 tcurdt Exp $
  + * @version CVS $Id: EsqlHelper.java,v 1.9 2002/05/16 16:01:17 haul Exp $
    */
   
   public class EsqlHelper {
   
  -      public final static String getAscii(ResultSet set, String column) {
  -        InputStream asciiStream = null;
  -        byte[] buffer = null;
   
  +    /** returns Unicode encoded string from CLOB or String column 
  +     */
  +    public final static String getStringOrClob(ResultSet set, String column) throws RuntimeException
{
  +        
  +        String result = null;
           try {
  -            Clob dbClob = set.getClob(column);
  -            int length = (int) dbClob.length();
  -            asciiStream = new BufferedInputStream(dbClob.getAsciiStream());
  -            buffer = new byte[length];
  -            asciiStream.read(buffer);
  -            asciiStream.close();
  +            result = EsqlHelper.getStringOrClob(set,set.findColumn(column));
           } catch (Exception e) {
               throw new RuntimeException("Error getting clob data: " + e.getMessage());
  -        } finally {
  -            if (asciiStream != null) try {asciiStream.close();} catch (Exception ase) {
  -                throw new RuntimeException("Error closing clob stream: " + ase.getMessage());
  +        }
  +        return result;
  +    }
  +
  +
  +    /** returns Unicode encoded string from CLOB or String column 
  +     */
  +    public final static String getStringOrClob(ResultSet set, int column) throws java.lang.Exception
{
  +        
  +        Reader reader = null;
  +        char[] buffer = null;
  +    
  +        try {
  +            if (set.getMetaData().getColumnType(column)==java.sql.Types.CLOB) {
  +                Clob dbClob = set.getClob(column);
  +                int length = (int) dbClob.length();
  +                reader = new BufferedReader(dbClob.getCharacterStream());
  +                buffer = new char[length];
  +                reader.read(buffer);
  +                reader.close();
  +                if (reader != null)
  +                    reader.close();
  +                if (buffer == null)
  +                    return "";
  +                return new String(buffer);
  +            } else {           
  +                return set.getString(column);
               }
  +        } catch ( Exception e) {
  +            throw new RuntimeException("Error getting clob data: " + e.getMessage());
           }
  +    }
   
  -        if (buffer == null) return "";
   
  -        return new String(buffer);
  +    /** returns ascii string from CLOB or String column 
  +     */
  +      public final static String getAscii(ResultSet set, String column) throws RuntimeException
{
  +
  +          String result = null;
  +          try {
  +              result = EsqlHelper.getAscii(set,set.findColumn(column));
  +          } catch (Exception e) {
  +              throw new RuntimeException("Error getting clob data: " + e.getMessage());
  +          }
  +          return result;
         }
   
  +
  +    /** returns ascii string from CLOB or String column 
  +     */
         public final static String getAscii(ResultSet set, int column) {
           InputStream asciiStream = null;
  -        byte[] buffer = null;
  +        String result = null;
   
           try {
  -            Clob dbClob = set.getClob(column);
  -            int length = (int) dbClob.length();
  -            asciiStream = new BufferedInputStream(dbClob.getAsciiStream());
  -            buffer = new byte[length];
  -            asciiStream.read(buffer);
  -            asciiStream.close();
  +            if (set.getMetaData().getColumnType(column) == Types.CLOB) {
  +                byte[] buffer = null;
  +                Clob dbClob = set.getClob(column);
  +                int length = (int) dbClob.length();
  +                asciiStream = new BufferedInputStream(dbClob.getAsciiStream());
  +                buffer = new byte[length];
  +                asciiStream.read(buffer);
  +                asciiStream.close();
  +                result = (buffer!=null? new String(buffer) : null);
  +            } else {
  +                result = set.getString(column);
  +            }
           } catch (Exception e) {
               throw new RuntimeException("Error getting clob data: " + e.getMessage());
           } finally {
  @@ -108,10 +153,9 @@
                   throw new RuntimeException("Error closing clob stream: " + ase.getMessage());
               }
           }
  -
  -        if (buffer == null) return "";
  -
  -        return new String(buffer);
  +        
  +        
  +        return result;
         }
   
         public final static String getStringFromByteArray(byte[] bytes, String encoding)
{
  
  
  
  1.15      +44 -8     xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlQuery.java
  
  Index: EsqlQuery.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlQuery.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- EsqlQuery.java	19 Apr 2002 18:18:45 -0000	1.14
  +++ EsqlQuery.java	16 May 2002 16:01:17 -0000	1.15
  @@ -57,6 +57,7 @@
   import java.sql.ResultSet;
   import java.sql.ResultSetMetaData;
   import java.sql.SQLException;
  +import java.util.ArrayList;
   
   /**
    * This helper class takes care of contstructing queries
  @@ -65,7 +66,7 @@
    *
    * based on the orginal esql.xsl
    * @author <a href="mailto:tcurdt@dff.st">Torsten Curdt</a>
  - * @version CVS $Id: EsqlQuery.java,v 1.14 2002/04/19 18:18:45 froehlich Exp $
  + * @version CVS $Id: EsqlQuery.java,v 1.15 2002/05/16 16:01:17 haul Exp $
    */
   
   public class EsqlQuery {
  @@ -80,7 +81,9 @@
     private int maxRows = -1;
     private int skipRows = 0;
     private boolean keepgoing = true;
  -  private java.util.Hashtable groupingVars = new java.util.Hashtable();
  +
  +    private ArrayList groups = null;
  +    private int groupLevel = -1;
   
     private String query;
     private int limitMethod;
  @@ -100,6 +103,17 @@
       this.hasResultSet = (this.resultSet != null);
     }
   
  +
  +    class EsqlGroup {
  +        public String var = null;
  +        public Object value = null;
  +        
  +        EsqlGroup ( String var, Object value ) {
  +            this.var = var;
  +            this.value = value;
  +        }
  +    }
  +
     public int getSkipRows() {
       return(skipRows);
     }
  @@ -211,13 +225,35 @@
       keepgoing = still;
     }
   
  -  public Object setGroupingVar( String key, Object value) {
  -    return groupingVars.put(key,value);
  -  }
   
  -  public Object getGroupingVar( String key) {
  -    return groupingVars.get(key);
  -  }
  +    public void groupLevelPlusPlus() {
  +        this.groupLevel++;
  +    }
  +
  +    public void groupLevelMinusMinus() {
  +        this.groupLevel--;
  +    }
  +
  +    public boolean groupLevelExists() {
  +        return (this.groups != null && this.groups.get(this.groupLevel) != null);
  +    }
  +
  +    public void setGroupingVar( String key ) throws SQLException {
  +        if (this.groups == null)
  +            this.groups = new ArrayList(1);
  +        this.groups.ensureCapacity(this.groupLevel);
  +        this.groups.add(this.groupLevel, new EsqlGroup(key, this.getResultSet().getObject(key)));
  +    }
  +
  +    public boolean hasGroupingVarChanged() throws SQLException {
  +        Object tmp = this.getResultSet().getObject(((EsqlGroup)this.groups.get(this.groupLevel)).var);
  +        if (tmp.equals(((EsqlGroup)this.groups.get(groupLevel)).value)) {
  +            return false;
  +        } else {
  +            ((EsqlGroup)this.groups.get(groupLevel)).value = tmp;
  +            return true;
  +        }
  +    }
   
     public ResultSetMetaData getResultSetMetaData() {
       return(resultSetMetaData);
  
  
  

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