avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject cvs commit: jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/test Tester.java
Date Tue, 04 Dec 2001 06:35:43 GMT
hammant     01/12/03 22:35:43

  Modified:    apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql
                        BasicLXSQLAggregateHandler.java
                        BasicLXSQLCreateAggregateViewHandler.java
               apps/db/src/java/org/apache/avalon/db/data
                        AggregateFunctionColumn.java Queryable.java
               apps/db/src/java/org/apache/avalon/db/data/impl
                        AbstractDelegatedQueryable.java
                        DefaultAggregateAveColumn.java
                        DefaultAggregateCountColumn.java
                        DefaultAggregateMaxColumn.java
                        DefaultAggregateMinColumn.java
                        DefaultAggregateSumColumn.java
               apps/db/src/java/org/apache/avalon/db/test Tester.java
  Log:
  more functionality to aggregate function columns
  
  Revision  Changes    Path
  1.9       +16 -16    jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/BasicLXSQLAggregateHandler.java
  
  Index: BasicLXSQLAggregateHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/BasicLXSQLAggregateHandler.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- BasicLXSQLAggregateHandler.java	2001/12/03 11:18:35	1.8
  +++ BasicLXSQLAggregateHandler.java	2001/12/04 06:35:43	1.9
  @@ -35,7 +35,7 @@
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
    * @author Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">g-froehlich@gmx.de</a>
  - * @version $Revision: 1.8 $
  + * @version $Revision: 1.9 $
    */
   public abstract class BasicLXSQLAggregateHandler extends BasicLXSQLHandler {
   
  @@ -56,7 +56,7 @@
        *
        *
        */
  -    protected AggregateFunctionColumn[] getAggregateFunctionColumns(Element fnColumnsNode)
throws ActionException {
  +    protected AggregateFunctionColumn[] getAggregateFunctionColumns(Queryable onQueryable,
Element fnColumnsNode) throws ActionException {
   
           Vector columns = new Vector();
   
  @@ -64,15 +64,15 @@
           for (int x = 0 ; x < subFnColumnsNodes.getLength(); x++) {
               String nodeName = subFnColumnsNodes.item(x).getNodeName();
               if (nodeName.equals("count")) {
  -                columns.add(createCountColumn(subFnColumnsNodes.item(x), x));
  +                columns.add(createCountColumn(onQueryable, subFnColumnsNodes.item(x), x));
               } else if (nodeName.equals("sum")) {
  -                columns.add(createSumColumn(subFnColumnsNodes.item(x), x));
  +                columns.add(createSumColumn(onQueryable, subFnColumnsNodes.item(x), x));
               } else if (nodeName.equals("ave")) {
  -                columns.add(createAveColumn(subFnColumnsNodes.item(x), x));
  +                columns.add(createAveColumn(onQueryable, subFnColumnsNodes.item(x), x));
               } else if (nodeName.equals("min")) {
  -                columns.add(createMinColumn(subFnColumnsNodes.item(x), x));
  +                columns.add(createMinColumn(onQueryable, subFnColumnsNodes.item(x), x));
               } else if (nodeName.equals("max")) {
  -                columns.add(createMaxColumn(subFnColumnsNodes.item(x), x));
  +                columns.add(createMaxColumn(onQueryable, subFnColumnsNodes.item(x), x));
               } else if (nodeName.equals("#text")) {
                   // whitespace OK
               } else {
  @@ -87,53 +87,53 @@
   
       }
   
  -    protected AggregateFunctionColumn createCountColumn(Node columnNode, int ix) throws
ActionException {
  +    protected AggregateFunctionColumn createCountColumn(Queryable onQueryable, Node columnNode,
int ix) throws ActionException {
           Node nameNode = columnNode.getAttributes().getNamedItem("as");
           AggregateFunctionColumn column = new DefaultAggregateCountColumn(nameNode == null
? null : nameNode.getNodeValue());
           column.setIndex(ix);
           return column;
       }
   
  -    protected AggregateFunctionColumn createSumColumn(Node columnNode, int ix) throws ActionException
{
  +    protected AggregateFunctionColumn createSumColumn(Queryable onQueryable, Node columnNode,
int ix) throws ActionException {
           Node nameNode = columnNode.getAttributes().getNamedItem("as");
           Node onNode = columnNode.getAttributes().getNamedItem("on");
           if (onNode == null) {
               throw new ActionException("Sum column must have 'on' attribute");
           }
  -        AggregateFunctionColumn column = new DefaultAggregateSumColumn(nameNode == null
? null : nameNode.getNodeValue(), onNode.getNodeValue());
  +        AggregateFunctionColumn column = new DefaultAggregateSumColumn(onQueryable, nameNode
== null ? null : nameNode.getNodeValue(), onNode.getNodeValue());
           column.setIndex(ix);
           return column;
       }
   
  -    protected AggregateFunctionColumn createAveColumn(Node columnNode, int ix) throws ActionException
{
  +    protected AggregateFunctionColumn createAveColumn(Queryable onQueryable, Node columnNode,
int ix) throws ActionException {
           Node nameNode = columnNode.getAttributes().getNamedItem("as");
           Node onNode = columnNode.getAttributes().getNamedItem("on");
           if (onNode == null) {
               throw new ActionException("Ave column must have 'on' attribute");
           }
  -        AggregateFunctionColumn column = new DefaultAggregateAveColumn(nameNode == null
? null : nameNode.getNodeValue(), onNode.getNodeValue());
  +        AggregateFunctionColumn column = new DefaultAggregateAveColumn(onQueryable, nameNode
== null ? null : nameNode.getNodeValue(), onNode.getNodeValue());
           column.setIndex(ix);
           return column;
       }
   
  -    protected AggregateFunctionColumn createMinColumn(Node columnNode, int ix) throws ActionException
{
  +    protected AggregateFunctionColumn createMinColumn(Queryable onQueryable, Node columnNode,
int ix) throws ActionException {
           Node nameNode = columnNode.getAttributes().getNamedItem("as");
           Node onNode = columnNode.getAttributes().getNamedItem("on");
           if (onNode == null) {
               throw new ActionException("Min column must have 'on' attribute");
           }
  -        AggregateFunctionColumn column = new DefaultAggregateMinColumn(nameNode == null
? null : nameNode.getNodeValue(), onNode.getNodeValue());
  +        AggregateFunctionColumn column = new DefaultAggregateMinColumn(onQueryable, nameNode
== null ? null : nameNode.getNodeValue(), onNode.getNodeValue());
           column.setIndex(ix);
           return column;
       }
   
  -    protected AggregateFunctionColumn createMaxColumn(Node columnNode, int ix) throws ActionException
{
  +    protected AggregateFunctionColumn createMaxColumn(Queryable onQueryable, Node columnNode,
int ix) throws ActionException {
           Node nameNode = columnNode.getAttributes().getNamedItem("as");
           Node onNode = columnNode.getAttributes().getNamedItem("on");
           if (onNode == null) {
               throw new ActionException("Max column must have 'on' attribute");
           }
  -        AggregateFunctionColumn column = new DefaultAggregateMaxColumn(nameNode == null
? null : nameNode.getNodeValue(), onNode.getNodeValue());
  +        AggregateFunctionColumn column = new DefaultAggregateMaxColumn(onQueryable, nameNode
== null ? null : nameNode.getNodeValue(), onNode.getNodeValue());
           column.setIndex(ix);
           return column;
       }
  
  
  
  1.10      +2 -2      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/BasicLXSQLCreateAggregateViewHandler.java
  
  Index: BasicLXSQLCreateAggregateViewHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/BasicLXSQLCreateAggregateViewHandler.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- BasicLXSQLCreateAggregateViewHandler.java	2001/12/03 11:18:35	1.9
  +++ BasicLXSQLCreateAggregateViewHandler.java	2001/12/04 06:35:43	1.10
  @@ -36,7 +36,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.9 $
  + * @version $Revision: 1.10 $
    */
   public class BasicLXSQLCreateAggregateViewHandler extends BasicLXSQLAggregateHandler {
   
  @@ -86,7 +86,7 @@
                   if (subRootNodes.item(i).getNodeName().equals("grouped-columns")) {
                       keyColumns = this.getKeyColumns(onQueryable, (Element) subRootNodes.item(i));
                   } else if (subRootNodes.item(i).getNodeName().equals("group-function-columns"))
{
  -                    functColumns = this.getAggregateFunctionColumns((Element) subRootNodes.item(i));
  +                    functColumns = this.getAggregateFunctionColumns(onQueryable, (Element)
subRootNodes.item(i));
                   }
               }
   
  
  
  
  1.4       +3 -2      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/AggregateFunctionColumn.java
  
  Index: AggregateFunctionColumn.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/AggregateFunctionColumn.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AggregateFunctionColumn.java	2001/12/01 15:30:42	1.3
  +++ AggregateFunctionColumn.java	2001/12/04 06:35:43	1.4
  @@ -13,9 +13,10 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version * $Revision: 1.3 $
  + * @version * $Revision: 1.4 $
    */
   public interface AggregateFunctionColumn extends Column {
       Object getDefaultValue();
  -
  +    void reset();
  +    void processRow(Row srcRow);
   }
  
  
  
  1.5       +2 -1      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/Queryable.java
  
  Index: Queryable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/Queryable.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Queryable.java	2001/12/01 17:50:26	1.4
  +++ Queryable.java	2001/12/04 06:35:43	1.5
  @@ -16,10 +16,11 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version * $Revision: 1.4 $
  + * @version * $Revision: 1.5 $
    */
   public interface Queryable extends Nameable, Cataloged {
       Column[] getColumns();
  +    int getColumnIndex(String columnName);
   
       void addRow(Row row);
       void addRowListener(RowListener rowListener);
  
  
  
  1.5       +5 -1      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/AbstractDelegatedQueryable.java
  
  Index: AbstractDelegatedQueryable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/AbstractDelegatedQueryable.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractDelegatedQueryable.java	2001/12/01 17:50:27	1.4
  +++ AbstractDelegatedQueryable.java	2001/12/04 06:35:43	1.5
  @@ -27,7 +27,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public abstract class AbstractDelegatedQueryable extends AbstractNameable implements Queryable
{
   
  @@ -64,6 +64,10 @@
        */
       public Column[] getColumns() {
           return mAbstractQueryable.getColumns();
  +    }
  +
  +    public int getColumnIndex(String columnName) {
  +        return mAbstractQueryable.getColumnIndex(columnName);
       }
   
       /**
  
  
  
  1.4       +40 -16    jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/DefaultAggregateAveColumn.java
  
  Index: DefaultAggregateAveColumn.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/DefaultAggregateAveColumn.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultAggregateAveColumn.java	2001/12/01 15:30:42	1.3
  +++ DefaultAggregateAveColumn.java	2001/12/04 06:35:43	1.4
  @@ -11,6 +11,7 @@
   import org.apache.avalon.db.data.types.NumericColumn;
   import org.apache.avalon.db.data.Row;
   import org.apache.avalon.db.data.Column;
  +import org.apache.avalon.db.data.Queryable;
   import org.apache.avalon.db.actions.ActionException;
   
   import java.math.BigDecimal;
  @@ -21,14 +22,15 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
   public class DefaultAggregateAveColumn extends AbstractAggregateFunctionColumn implements
NumericColumn {
   
  -    private int mAve;
  -    private Integer mAve2;
  +    private int mCount;
  +    private int mTotal;
  +    private Integer mAve;
       private static Integer DEFAULT = new Integer(0);
  -    private String mOnColumn;
  +    private Column mOnColumn;
   
       /**
        * Constructor DefaultAggregateAveColumn
  @@ -37,20 +39,25 @@
        * @param name
        *
        */
  -    public DefaultAggregateAveColumn(String name, String on) throws ActionException {
  +    public DefaultAggregateAveColumn(Queryable onQueryable, String name, String on) throws
ActionException {
           super(getNameOfColumn(name),"integer",Integer.class);
  -        mOnColumn = on;
  +        mOnColumn = onQueryable.getColumns()[onQueryable.getColumnIndex(on)];
       }
   
  -    public Object getValue(Row row) {
  -        if (mAve2 == null) {
  -            mAve2 = new Integer(mAve);
  +    private void testAve() {
  +        if (mAve == null) {
  +            mAve = new Integer(mTotal / mCount);
           }
  -        return mAve2;
  +    }
  +
  +    public Object getValue(Row row) {
  +        testAve();
  +        return mAve;
       }
   
       public String toString(Row row) {
  -        return "" + mAve;
  +        testAve();
  +        return "" + mAve.toString();
       }
   
       public int getPrecesion() {
  @@ -58,26 +65,43 @@
       }
   
       public Integer toInteger(Row row) {
  -        return mAve2;
  +        testAve();
  +        return mAve;
       }
   
       public Long toLong(Row row) {
  -        return new Long((long) mAve);
  +        testAve();
  +        return new Long((long) mAve.intValue());
       }
   
       public BigDecimal toBigDecimal(Row row) {
  -        return new BigDecimal((double) mAve);
  +        testAve();
  +        return new BigDecimal((double) mAve.intValue());
       }
   
       public Float toFloat(Row row) {
  -        return new Float((float) mAve);
  +        testAve();
  +        return new Float((float) mAve.intValue());
       }
   
       public Short toShort(Row row) {
  -        return new Short((short) mAve);
  +        testAve();
  +        return new Short((short) mAve.intValue());
       }
   
       public Object getDefaultValue() {
           return DEFAULT;
  +    }
  +
  +    public void reset() {
  +        mAve = null;
  +        mCount = 0;
  +        mTotal = 0;
  +    }
  +
  +    public void processRow(Row srcRow) {
  +        mTotal += mOnColumn.toInteger(srcRow).intValue();
  +        mCount++;
  +        mAve = null;
       }
   }
  
  
  
  1.5       +11 -1     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/DefaultAggregateCountColumn.java
  
  Index: DefaultAggregateCountColumn.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/DefaultAggregateCountColumn.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultAggregateCountColumn.java	2001/12/01 15:30:42	1.4
  +++ DefaultAggregateCountColumn.java	2001/12/04 06:35:43	1.5
  @@ -21,7 +21,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public class DefaultAggregateCountColumn extends AbstractAggregateFunctionColumn {
   
  @@ -77,5 +77,15 @@
   
       public Object getDefaultValue() {
           return DEFAULT;
  +    }
  +
  +    public void reset() {
  +        mCount = 0;
  +        mCount2 = null;
  +    }
  +
  +    public void processRow(Row srcRow) {
  +        mCount++;
  +        mCount2 = null;
       }
   }
  
  
  
  1.4       +35 -5     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/DefaultAggregateMaxColumn.java
  
  Index: DefaultAggregateMaxColumn.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/DefaultAggregateMaxColumn.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultAggregateMaxColumn.java	2001/12/01 15:30:42	1.3
  +++ DefaultAggregateMaxColumn.java	2001/12/04 06:35:43	1.4
  @@ -11,6 +11,7 @@
   import org.apache.avalon.db.data.types.NumericColumn;
   import org.apache.avalon.db.data.Row;
   import org.apache.avalon.db.data.Column;
  +import org.apache.avalon.db.data.Queryable;
   import org.apache.avalon.db.actions.ActionException;
   
   import java.math.BigDecimal;
  @@ -21,14 +22,14 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
   public class DefaultAggregateMaxColumn extends AbstractAggregateFunctionColumn implements
NumericColumn {
   
       private int mMax;
       private Integer mMax2;
       private static Integer DEFAULT = new Integer(0);
  -    private String mOnColumn;
  +    private Column mOnColumn;
   
       /**
        * Constructor DefaultAggregateMaxColumn
  @@ -37,19 +38,25 @@
        * @param name
        *
        */
  -    public DefaultAggregateMaxColumn(String name, String on) throws ActionException {
  +    public DefaultAggregateMaxColumn(Queryable onQueryable, String name, String on) throws
ActionException {
           super(getNameOfColumn(name),"integer",Integer.class);
  -        mOnColumn = on;
  +        mOnColumn = onQueryable.getColumns()[onQueryable.getColumnIndex(on)];
       }
   
  -    public Object getValue(Row row) {
  +    private void testMax() {
           if (mMax2 == null) {
               mMax2 = new Integer(mMax);
           }
  +    }
  +
  +
  +    public Object getValue(Row row) {
  +        testMax();
           return mMax2;
       }
   
       public String toString(Row row) {
  +        testMax();
           return "" + mMax;
       }
   
  @@ -58,26 +65,49 @@
       }
   
       public Integer toInteger(Row row) {
  +        testMax();
           return mMax2;
       }
   
       public Long toLong(Row row) {
  +        testMax();
           return new Long((long) mMax);
       }
   
       public BigDecimal toBigDecimal(Row row) {
  +        testMax();
           return new BigDecimal((double) mMax);
       }
   
       public Float toFloat(Row row) {
  +        testMax();
           return new Float((float) mMax);
       }
   
       public Short toShort(Row row) {
  +        testMax();
           return new Short((short) mMax);
       }
   
       public Object getDefaultValue() {
           return DEFAULT;
       }
  +
  +    public void reset() {
  +        mMax2 = null;
  +        mMax = 0;
  +    }
  +
  +    public void processRow(Row srcRow) {
  +        int val = mOnColumn.toInteger(srcRow).intValue();
  +        if (mMax2 == null) {
  +            mMax = val;
  +        } else {
  +            if (val > mMax) {
  +                mMax = val;
  +                mMax2 = new Integer(mMax);
  +            }
  +        }
  +    }
  +
   }
  
  
  
  1.4       +33 -5     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/DefaultAggregateMinColumn.java
  
  Index: DefaultAggregateMinColumn.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/DefaultAggregateMinColumn.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultAggregateMinColumn.java	2001/12/01 15:30:42	1.3
  +++ DefaultAggregateMinColumn.java	2001/12/04 06:35:43	1.4
  @@ -11,6 +11,7 @@
   import org.apache.avalon.db.data.types.NumericColumn;
   import org.apache.avalon.db.data.Row;
   import org.apache.avalon.db.data.Column;
  +import org.apache.avalon.db.data.Queryable;
   import org.apache.avalon.db.actions.ActionException;
   
   import java.math.BigDecimal;
  @@ -21,14 +22,14 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
   public class DefaultAggregateMinColumn extends AbstractAggregateFunctionColumn implements
NumericColumn {
   
       private int mMin;
       private Integer mMin2;
       private static Integer DEFAULT = new Integer(0);
  -    private String mOnColumn;
  +    private Column mOnColumn;
   
       /**
        * Constructor DefaultAggregateMinColumn
  @@ -37,19 +38,24 @@
        * @param name
        *
        */
  -    public DefaultAggregateMinColumn(String name, String on) throws ActionException {
  +    public DefaultAggregateMinColumn(Queryable onQueryable, String name, String on) throws
ActionException {
           super(getNameOfColumn(name),"integer",Integer.class);
  -        mOnColumn = on;
  +        mOnColumn = onQueryable.getColumns()[onQueryable.getColumnIndex(on)];
       }
   
  -    public Object getValue(Row row) {
  +    private void testMax() {
           if (mMin2 == null) {
               mMin2 = new Integer(mMin);
           }
  +    }
  +
  +    public Object getValue(Row row) {
  +        testMax();
           return mMin2;
       }
   
       public String toString(Row row) {
  +        testMax();
           return "" + mMin;
       }
   
  @@ -58,27 +64,49 @@
       }
   
       public Integer toInteger(Row row) {
  +        testMax();
           return mMin2;
       }
   
       public Long toLong(Row row) {
  +        testMax();
           return new Long((long) mMin);
       }
   
       public BigDecimal toBigDecimal(Row row) {
  +        testMax();
           return new BigDecimal((double) mMin);
       }
   
       public Float toFloat(Row row) {
  +        testMax();
           return new Float((float) mMin);
       }
   
       public Short toShort(Row row) {
  +        testMax();
           return new Short((short) mMin);
       }
   
       public Object getDefaultValue() {
           return DEFAULT;
  +    }
  +
  +    public void reset() {
  +        mMin2 = null;
  +        mMin = 0;
  +    }
  +
  +    public void processRow(Row srcRow) {
  +        int val = mOnColumn.toInteger(srcRow).intValue();
  +        if (mMin2 == null) {
  +            mMin = val;
  +        } else {
  +            if (val < mMin) {
  +                mMin = val;
  +                mMin2 = new Integer(mMin);
  +            }
  +        }
       }
   
   }
  
  
  
  1.4       +26 -5     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/DefaultAggregateSumColumn.java
  
  Index: DefaultAggregateSumColumn.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/DefaultAggregateSumColumn.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultAggregateSumColumn.java	2001/12/01 15:30:42	1.3
  +++ DefaultAggregateSumColumn.java	2001/12/04 06:35:43	1.4
  @@ -11,6 +11,7 @@
   import org.apache.avalon.db.data.types.NumericColumn;
   import org.apache.avalon.db.data.Row;
   import org.apache.avalon.db.data.Column;
  +import org.apache.avalon.db.data.Queryable;
   import org.apache.avalon.db.actions.ActionException;
   
   import java.math.BigDecimal;
  @@ -21,14 +22,14 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
   public class DefaultAggregateSumColumn extends AbstractAggregateFunctionColumn implements
NumericColumn {
   
       private int mSum;
       private Integer mSum2;
       private static Integer DEFAULT = new Integer(0);
  -    private String mOnColumn;
  +    private Column mOnColumn;
   
       /**
        * Constructor DefaultAggregateSumColumn
  @@ -37,19 +38,24 @@
        * @param name
        *
        */
  -    public DefaultAggregateSumColumn(String name, String on) throws ActionException {
  +    public DefaultAggregateSumColumn(Queryable onQueryable, String name, String on) throws
ActionException {
           super(getNameOfColumn(name),"integer",Integer.class);
  -        mOnColumn = on;
  +        mOnColumn = onQueryable.getColumns()[onQueryable.getColumnIndex(on)];
       }
   
  -    public Object getValue(Row row) {
  +    private void testMax() {
           if (mSum2 == null) {
               mSum2 = new Integer(mSum);
           }
  +    }
  +
  +    public Object getValue(Row row) {
  +        testMax();
           return mSum2;
       }
   
       public String toString(Row row) {
  +        testMax();
           return "" + mSum;
       }
   
  @@ -58,22 +64,27 @@
       }
   
       public Integer toInteger(Row row) {
  +        testMax();
           return mSum2;
       }
   
       public Long toLong(Row row) {
  +        testMax();
           return new Long((long) mSum);
       }
   
       public BigDecimal toBigDecimal(Row row) {
  +        testMax();
           return new BigDecimal((double) mSum);
       }
   
       public Float toFloat(Row row) {
  +        testMax();
           return new Float((float) mSum);
       }
   
       public Short toShort(Row row) {
  +        testMax();
           return new Short((short) mSum);
       }
   
  @@ -81,4 +92,14 @@
           return DEFAULT;
       }
   
  +    public void reset() {
  +        mSum2 = null;
  +        mSum = 0;
  +    }
  +
  +    public void processRow(Row srcRow) {
  +        int val = mOnColumn.toInteger(srcRow).intValue();
  +        mSum += val;
  +        mSum2 = null;
  +    }
   }
  
  
  
  1.38      +2 -3      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/test/Tester.java
  
  Index: Tester.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/test/Tester.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- Tester.java	2001/12/03 18:23:18	1.37
  +++ Tester.java	2001/12/04 06:35:43	1.38
  @@ -60,9 +60,8 @@
               System.out.println(mSQL.substring(str+3, msgEnd));
               sql = mSQL.substring(msgEnd+3,end).trim();
               Statement st = mCon.createStatement();
  -
  -            System.out.println("[[[[" + sql);
  -            if (sql.indexOf("<simple-select") > 0 | sql.startsWith("SELECT")) {
  +            if (sql.indexOf("<simple-select") >= 0 | sql.startsWith("SELECT")) {
  +                System.out.println("<<SEL");
                   ResultSet rs = st.executeQuery(sql);
                   System.out.println("Results:");
                   while (rs.next()) {
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message