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/scripts/lxsql Test2.script
Date Tue, 18 Dec 2001 20:21:26 GMT
hammant     01/12/18 12:21:26

  Modified:    apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql
                        BasicLXSQLSelectSimpleHandler.java
               apps/db/src/scripts/lxsql Test2.script
  Added:       apps/db/src/java/org/apache/avalon/db/data/impl
                        DefaultIntegerConstantColumn.java
               apps/db/src/java/org/apache/avalon/db/functions/impl
                        IntegerAdditionFunction.java
                        IntegerDivisionFunction.java
                        IntegerMultiplicationFunction.java
                        IntegerSubtractionFunction.java
  Log:
  basic maths functions
  
  Revision  Changes    Path
  1.12      +21 -2     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/BasicLXSQLSelectSimpleHandler.java
  
  Index: BasicLXSQLSelectSimpleHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/BasicLXSQLSelectSimpleHandler.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- BasicLXSQLSelectSimpleHandler.java	2001/12/18 19:25:24	1.11
  +++ BasicLXSQLSelectSimpleHandler.java	2001/12/18 20:21:26	1.12
  @@ -24,11 +24,16 @@
   import org.apache.avalon.db.data.impl.DefaultContrivedStringFunctionColumn;
   import org.apache.avalon.db.data.impl.DefaultStringConstantColumn;
   import org.apache.avalon.db.data.impl.DefaultContrivedIntegerFunctionColumn;
  +import org.apache.avalon.db.data.impl.DefaultIntegerConstantColumn;
   import org.apache.avalon.db.functions.impl.ConcatFunction;
   import org.apache.avalon.db.functions.impl.TrimStringFunction;
   import org.apache.avalon.db.functions.impl.LowerCaseStringFunction;
   import org.apache.avalon.db.functions.impl.UpperCaseStringFunction;
   import org.apache.avalon.db.functions.impl.PositionFunction;
  +import org.apache.avalon.db.functions.impl.IntegerAdditionFunction;
  +import org.apache.avalon.db.functions.impl.IntegerSubtractionFunction;
  +import org.apache.avalon.db.functions.impl.IntegerMultiplicationFunction;
  +import org.apache.avalon.db.functions.impl.IntegerDivisionFunction;
   import org.apache.avalon.db.functions.Function;
   import org.apache.avalon.db.functions.StringFunction;
   import org.apache.avalon.db.functions.NumericFunction;
  @@ -47,7 +52,7 @@
    *
   * @author Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">g-froehlich@gmx.de</a>
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.11 $
  + * @version $Revision: 1.12 $
    */
   public class BasicLXSQLSelectSimpleHandler extends BasicLXSQLHandler {
   
  @@ -192,6 +197,14 @@
               return getStringColumnFromStringFunction(queryable, elem, new UpperCaseStringFunction());
           } else if (nodeName.equals("position")) {
               return getIntegerColumnFromIntegerFunction(queryable, elem, new PositionFunction());
  +        } else if (nodeName.equals("addition")) {
  +            return getIntegerColumnFromIntegerFunction(queryable, elem, new IntegerAdditionFunction());
  +        } else if (nodeName.equals("subtraction")) {
  +            return getIntegerColumnFromIntegerFunction(queryable, elem, new IntegerSubtractionFunction());
  +        } else if (nodeName.equals("multiplication")) {
  +            return getIntegerColumnFromIntegerFunction(queryable, elem, new IntegerMultiplicationFunction());
  +        } else if (nodeName.equals("division")) {
  +            return getIntegerColumnFromIntegerFunction(queryable, elem, new IntegerDivisionFunction());
           } else {
               throw new ActionException("Unknown node type '"+nodeName+"' under 'columns'");
           }
  @@ -232,7 +245,13 @@
   
       private Column getSelectColumnConst(AbstractQueryable queryable, Element elem) throws
ActionException {
           String value = elem.getAttribute("value");
  -        return new DefaultStringConstantColumn("TODO",value);
  +        // TODO more types
  +        try {
  +            return new DefaultIntegerConstantColumn("TODO",Integer.parseInt(value));
  +        } catch (java.lang.NumberFormatException nfe) {
  +            return new DefaultStringConstantColumn("TODO",value);
  +        }
  +
       }
   
       private Column getStringColumnFromStringFunction(AbstractQueryable queryable, Element
aElem, StringFunction function) throws ActionException {
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/DefaultIntegerConstantColumn.java
  
  Index: DefaultIntegerConstantColumn.java
  ===================================================================
  
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.db.data.impl;
  
  import org.apache.avalon.db.data.ValidationException;
  import org.apache.avalon.db.data.Row;
  import org.apache.avalon.db.data.Column;
  import org.apache.avalon.db.data.types.NumericConstantColumn;
  
  import java.math.BigDecimal;
  
  /**
   * Class DefaultIntegerConstantColumn
   *
   *
   * @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.1 $
   */
  public class DefaultIntegerConstantColumn extends AbstractColumn implements NumericConstantColumn
{
  
      private int mIntConstant;
      private Integer mIntegerConstant;
  
      /**
       * Constructor DefaultIntegerConstantColumn
       *
       *
       * @param name
       * @param strConstant
       *
       */
      public DefaultIntegerConstantColumn(String name, int intConstant) {
          super(name,"integer",Integer.class.getName());
          mIntConstant = intConstant;
          mIntegerConstant = new Integer(mIntConstant);
      }
  
      public Object getValue(Row row) {
          return mIntegerConstant;
      }
  
      public String toString(Row row) {
          return mIntegerConstant.toString();
      }
  
      public Integer toInteger(Row row) {
          return mIntegerConstant;
      }
  
      public Long toLong(Row row) {
          return new Long(mIntConstant);
      }
  
      public BigDecimal toBigDecimal(Row row) {
          return new BigDecimal(mIntConstant);
      }
  
      public Float toFloat(Row row) {
          return new Float(mIntConstant);
      }
      
      public Short toShort(Row row) {
          return new Short((short)mIntConstant);
      }
  
      public int getPrecesion() {
          return Column.PREC_INT;
      }
  
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/functions/impl/IntegerAdditionFunction.java
  
  Index: IntegerAdditionFunction.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.db.functions.impl;
  
  import org.apache.avalon.db.data.Row;
  import org.apache.avalon.db.data.types.StringColumn;
  import org.apache.avalon.db.data.types.NumericColumn;
  import org.apache.avalon.db.functions.StringFunction;
  
  
  /**
   * Class IntegerAdditionFunction
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class IntegerAdditionFunction extends AbstractIntegerFunction {
  
      protected Integer getIntegerValue(Row row) {
          int tot = 0;
          for (int i = 0; i < mColumns.length; i++) {
              tot+= ((NumericColumn) mColumns[i]).toInteger(row).intValue();
          }
          return new Integer(tot);
      }
  
      public int getMinCols() {
          return 2;
      }
      public int getMaxCols() {
          return 99;
      }
  
  
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/functions/impl/IntegerDivisionFunction.java
  
  Index: IntegerDivisionFunction.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.db.functions.impl;
  
  import org.apache.avalon.db.data.Row;
  import org.apache.avalon.db.data.types.StringColumn;
  import org.apache.avalon.db.data.types.NumericColumn;
  import org.apache.avalon.db.functions.StringFunction;
  
  
  /**
   * Class IntegerDivisionFunction
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class IntegerDivisionFunction extends AbstractIntegerFunction {
  
      protected Integer getIntegerValue(Row row) {
          int c0 = ((NumericColumn) mColumns[0]).toInteger(row).intValue();
          int c1 = ((NumericColumn) mColumns[1]).toInteger(row).intValue();
          int res = c0 / c1;
          return new Integer(res);
      }
  
      public int getMinCols() {
          return 2;
      }
      public int getMaxCols() {
          return 2;
      }
  
  
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/functions/impl/IntegerMultiplicationFunction.java
  
  Index: IntegerMultiplicationFunction.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.db.functions.impl;
  
  import org.apache.avalon.db.data.Row;
  import org.apache.avalon.db.data.types.StringColumn;
  import org.apache.avalon.db.data.types.NumericColumn;
  import org.apache.avalon.db.functions.StringFunction;
  
  
  /**
   * Class IntegerMultiplicationFunction
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class IntegerMultiplicationFunction extends AbstractIntegerFunction {
  
      protected Integer getIntegerValue(Row row) {
          int tot = 0;
          for (int i = 0; i < mColumns.length; i++) {
              tot*= ((NumericColumn) mColumns[i]).toInteger(row).intValue();
          }
          return new Integer(tot);
      }
  
      public int getMinCols() {
          return 2;
      }
      public int getMaxCols() {
          return 99;
      }
  
  
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/functions/impl/IntegerSubtractionFunction.java
  
  Index: IntegerSubtractionFunction.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.db.functions.impl;
  
  import org.apache.avalon.db.data.Row;
  import org.apache.avalon.db.data.types.StringColumn;
  import org.apache.avalon.db.data.types.NumericColumn;
  import org.apache.avalon.db.functions.StringFunction;
  
  
  /**
   * Class IntegerSubtractionFunction
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class IntegerSubtractionFunction extends AbstractIntegerFunction {
  
      protected Integer getIntegerValue(Row row) {
          int tot = 0;
          for (int i = 0; i < mColumns.length; i++) {
              tot-= ((NumericColumn) mColumns[i]).toInteger(row).intValue();
          }
          return new Integer(tot);
      }
  
      public int getMinCols() {
          return 2;
      }
      public int getMaxCols() {
          return 99;
      }
  
  
  }
  
  
  
  1.4       +38 -0     jakarta-avalon-cornerstone/apps/db/src/scripts/lxsql/Test2.script
  
  Index: Test2.script
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/scripts/lxsql/Test2.script,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Test2.script	2001/12/18 19:25:24	1.3
  +++ Test2.script	2001/12/18 20:21:26	1.4
  @@ -41,5 +41,43 @@
      </from>
   </simple-select>
   
  +### SELECT 2 (function additon n subtr 'Age +- 100') ##!
  +
  +<simple-select>
  +   <columns>
  +     <column name="age"/>
  +     <addition>
  +       <column name="age"/>
  +       <const value="100"/>
  +     </addition>
  +     <subtraction>
  +       <column name="age"/>
  +       <const value="100"/>
  +     </subtraction>
  +   </columns>
  +   <from>
  +     <table name="Flintstones"/>
  +   </from>
  +</simple-select>
  +
  +### SELECT 3 (function mult n div 'Age */ 2') ##!
  +
  +<simple-select>
  +   <columns>
  +     <column name="age"/>
  +     <multiplication>
  +       <column name="age"/>
  +       <const value="2"/>
  +     </multiplication>
  +     <division>
  +       <column name="age"/>
  +       <const value="2"/>
  +     </division>
  +   </columns>
  +   <from>
  +     <table name="Flintstones"/>
  +   </from>
  +</simple-select>
  +
   
   ###
  
  
  

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