You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ha...@apache.org on 2001/12/29 01:33:10 UTC

cvs commit: jakarta-avalon-cornerstone/apps/db/src/scripts/lxsql Test1.script Test2.script

hammant     01/12/28 16:33:10

  Modified:    apps/db/src/java/org/apache/avalon/db/actions/impl
                        AbstractAction.java
               apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql
                        SelectColumnHelper.java
               apps/db/src/java/org/apache/avalon/db/data/impl
                        DefaultTimestampColumn.java
               apps/db/src/scripts/lxsql Test1.script Test2.script
  Added:       apps/db/src/java/org/apache/avalon/db/functions/impl
                        AbstractTemporalIntegerFunction.java
                        DayOfMonthIntegerFunction.java
                        HourOfDayIntegerFunction.java
                        MinuteIntegerFunction.java
                        MonthIntegerFunction.java
                        SecondIntegerFunction.java YearIntegerFunction.java
  Log:
  Temporal functions added, equiv to SQL99 functions, but not including the MySQL extensions.
  
  Revision  Changes    Path
  1.8       +0 -18     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/actions/impl/AbstractAction.java
  
  Index: AbstractAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/actions/impl/AbstractAction.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AbstractAction.java	19 Nov 2001 10:59:09 -0000	1.7
  +++ AbstractAction.java	29 Dec 2001 00:33:09 -0000	1.8
  @@ -20,22 +20,4 @@
       public void setDatabasePersistor(DatabasePersistor databasePersistor) {
           mDatabasePersistor = databasePersistor;
       }
  -
  -
  -    /* TODO not needed ? - PH
  -    protected Class getJavaType(String sqlType) throws ActionException {
  -
  -        System.out.println("Type=(" + sqlType + ")");
  -
  -        if (sqlType.equals("varchar")) {
  -            return String.class;
  -        } else if (sqlType.equals("char")) {
  -            return String.class;
  -        }
  -
  -        throw new ActionException("Type " + sqlType + " not supported yet");
  -    }
  -    */
  -
  -
   }
  
  
  
  1.4       +19 -4     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/SelectColumnHelper.java
  
  Index: SelectColumnHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/SelectColumnHelper.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SelectColumnHelper.java	20 Dec 2001 12:31:15 -0000	1.3
  +++ SelectColumnHelper.java	29 Dec 2001 00:33:09 -0000	1.4
  @@ -30,6 +30,12 @@
   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.HourOfDayIntegerFunction;
  +import org.apache.avalon.db.functions.impl.DayOfMonthIntegerFunction;
  +import org.apache.avalon.db.functions.impl.MinuteIntegerFunction;
  +import org.apache.avalon.db.functions.impl.MonthIntegerFunction;
  +import org.apache.avalon.db.functions.impl.SecondIntegerFunction;
  +import org.apache.avalon.db.functions.impl.YearIntegerFunction;
   import org.apache.avalon.db.functions.StringFunction;
   import org.apache.avalon.db.functions.NumericFunction;
   import org.w3c.dom.Element;
  @@ -44,7 +50,7 @@
    *
    *
    * @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 SelectColumnHelper {
   
  @@ -62,7 +68,6 @@
   
       protected Column getSelectColumn(AbstractQueryable queryable, Element elem, ContrivedColumnNameHolder colHldr) throws ActionException {
   
  -
           String nodeName = elem.getNodeName();
   
           if (nodeName.equals("column")) {
  @@ -87,11 +92,21 @@
               return getIntegerColumnFromIntegerFunction(queryable, elem, new IntegerMultiplicationFunction(), colHldr);
           } else if (nodeName.equals("division")) {
               return getIntegerColumnFromIntegerFunction(queryable, elem, new IntegerDivisionFunction(), colHldr);
  +        } else if (nodeName.equals("hourofday")) {
  +            return getIntegerColumnFromIntegerFunction(queryable, elem, new HourOfDayIntegerFunction(), colHldr);
  +        } else if (nodeName.equals("dayofmonth")) {
  +            return getIntegerColumnFromIntegerFunction(queryable, elem, new DayOfMonthIntegerFunction(), colHldr);
  +        } else if (nodeName.equals("minute")) {
  +            return getIntegerColumnFromIntegerFunction(queryable, elem, new MinuteIntegerFunction(), colHldr);
  +        } else if (nodeName.equals("month")) {
  +            return getIntegerColumnFromIntegerFunction(queryable, elem, new MonthIntegerFunction(), colHldr);
  +        } else if (nodeName.equals("second")) {
  +            return getIntegerColumnFromIntegerFunction(queryable, elem, new SecondIntegerFunction(), colHldr);
  +        } else if (nodeName.equals("year")) {
  +            return getIntegerColumnFromIntegerFunction(queryable, elem, new YearIntegerFunction(), colHldr);
           } else {
               throw new ActionException("Unknown node type '"+nodeName+"' under 'columns'");
           }
  -
  -
       }
   
       protected Column getSelectColumnColumn(AbstractQueryable queryable, Element elem) throws ActionException {
  
  
  
  1.5       +6 -2      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/DefaultTimestampColumn.java
  
  Index: DefaultTimestampColumn.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/DefaultTimestampColumn.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultTimestampColumn.java	19 Dec 2001 18:59:26 -0000	1.4
  +++ DefaultTimestampColumn.java	29 Dec 2001 00:33:09 -0000	1.5
  @@ -20,7 +20,7 @@
    * Class DefaultTimestampColumn
    *
    * @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 DefaultTimestampColumn extends AbstractWritableColumn implements TemporalColumn {
   
  @@ -35,7 +35,11 @@
       public Object convertFromObject(Object obj) throws ValidationException {
           try {
               if (obj instanceof String) {
  -                return Timestamp.valueOf(obj.toString());
  +                try {
  +                    return Timestamp.valueOf(obj.toString());
  +                } catch (IllegalArgumentException iae) {
  +                    return Timestamp.valueOf(obj.toString().trim() + " 00:00:00.000000001");
  +                }
               } else if (obj instanceof Timestamp) {
                   return obj;
               } else {
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/functions/impl/AbstractTemporalIntegerFunction.java
  
  Index: AbstractTemporalIntegerFunction.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.functions.TemporalFunction;
  import org.apache.avalon.db.functions.NumericFunction;
  import org.apache.avalon.db.data.Row;
  
  import java.util.GregorianCalendar;
  
  
  /**
   * Class AbstractTemporalIntegerFunction
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public abstract class AbstractTemporalIntegerFunction extends AbstractIntegerFunction implements NumericFunction {
  
      private final int mDesiredLength;
      protected final GregorianCalendar mGregorianCalendar = new GregorianCalendar();
  
      public AbstractTemporalIntegerFunction(int desiredLength) {
          mDesiredLength = desiredLength;
      }
  
      public String getStringValue(Row row) {
          Integer integer = getIntegerValue(row);
          String string = integer.toString();
          if (string.length() +1 == mDesiredLength) {
              return "0" + string;
          } else if (string.length() < mDesiredLength) {
              return new String("00" + string).substring(string.length()-mDesiredLength,string.length());
          } else if (string.length() == mDesiredLength) {
              return string;
          } else {
              return string.substring(string.length()-mDesiredLength,string.length());
          }
      }
  
      public int getMinCols() {
          return 1;
      }
  
      public int getMaxCols() {
          return 1;
      }
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/functions/impl/DayOfMonthIntegerFunction.java
  
  Index: DayOfMonthIntegerFunction.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.TemporalColumn;
  
  import java.util.Date;
  import java.util.Calendar;
  
  /**
   * Class DayOfMonthIntegerFunction
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class DayOfMonthIntegerFunction extends AbstractTemporalIntegerFunction {
  
      public DayOfMonthIntegerFunction() {
          super(2);
      }
  
      protected Integer getIntegerValue(Row row) {
          TemporalColumn tc = (TemporalColumn) mColumns[0];
          Date date = (Date) tc.getValue(row);
          mGregorianCalendar.setTimeInMillis(date.getTime());
          return new Integer(mGregorianCalendar.get(Calendar.DAY_OF_MONTH));
      }
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/functions/impl/HourOfDayIntegerFunction.java
  
  Index: HourOfDayIntegerFunction.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.TemporalColumn;
  
  import java.util.Date;
  import java.util.Calendar;
  
  /**
   * Class HourOfDayIntegerFunction
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class HourOfDayIntegerFunction extends AbstractTemporalIntegerFunction {
  
      public HourOfDayIntegerFunction() {
          super(2);
      }
  
      protected Integer getIntegerValue(Row row) {
          TemporalColumn tc = (TemporalColumn) mColumns[0];
          Date date = (Date) tc.getValue(row);
          mGregorianCalendar.setTimeInMillis(date.getTime());
          return new Integer(mGregorianCalendar.get(Calendar.HOUR_OF_DAY));
      }
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/functions/impl/MinuteIntegerFunction.java
  
  Index: MinuteIntegerFunction.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.TemporalColumn;
  
  import java.util.Date;
  import java.util.Calendar;
  
  /**
   * Class MinuteIntegerFunction
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class MinuteIntegerFunction extends AbstractTemporalIntegerFunction {
  
      public MinuteIntegerFunction() {
          super(2);
      }
  
      protected Integer getIntegerValue(Row row) {
          TemporalColumn tc = (TemporalColumn) mColumns[0];
          Date date = (Date) tc.getValue(row);
          mGregorianCalendar.setTimeInMillis(date.getTime());
          return new Integer(mGregorianCalendar.get(Calendar.MINUTE));
      }
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/functions/impl/MonthIntegerFunction.java
  
  Index: MonthIntegerFunction.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.TemporalColumn;
  
  import java.util.Date;
  import java.util.Calendar;
  
  /**
   * Class MonthIntegerFunction
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class MonthIntegerFunction extends AbstractTemporalIntegerFunction {
  
      public MonthIntegerFunction() {
          super(2);
      }
  
      protected Integer getIntegerValue(Row row) {
          TemporalColumn tc = (TemporalColumn) mColumns[0];
          Date date = (Date) tc.getValue(row);
          mGregorianCalendar.setTimeInMillis(date.getTime());
          return new Integer(mGregorianCalendar.get(Calendar.MONTH) +1 );
      }
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/functions/impl/SecondIntegerFunction.java
  
  Index: SecondIntegerFunction.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.TemporalColumn;
  
  import java.util.Date;
  import java.util.Calendar;
  
  
  /**
   * Class SecondIntegerFunction
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class SecondIntegerFunction extends AbstractTemporalIntegerFunction {
  
      public SecondIntegerFunction() {
          super(2);
      }
  
      protected Integer getIntegerValue(Row row) {
          TemporalColumn tc = (TemporalColumn) mColumns[0];
          Date date = (Date) tc.getValue(row);
          mGregorianCalendar.setTimeInMillis(date.getTime());
          return new Integer(mGregorianCalendar.get(Calendar.SECOND));
      }
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/functions/impl/YearIntegerFunction.java
  
  Index: YearIntegerFunction.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.TemporalColumn;
  
  import java.util.Date;
  import java.util.Calendar;
  
  
  /**
   * Class SecondIntegerFunction
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class YearIntegerFunction extends AbstractTemporalIntegerFunction {
  
      public YearIntegerFunction() {
          super(4);  // not used.
      }
  
      protected Integer getIntegerValue(Row row) {
          TemporalColumn tc = (TemporalColumn) mColumns[0];
          Date date = (Date) tc.getValue(row);
          mGregorianCalendar.setTimeInMillis(date.getTime());
          return new Integer(mGregorianCalendar.get(Calendar.SECOND));
      }
  
      public String getStringValue(Row row) {
          Integer integer = getIntegerValue(row);
          String string = integer.toString();
          return string;
      }
  
  }
  
  
  
  1.6       +5 -0      jakarta-avalon-cornerstone/apps/db/src/scripts/lxsql/Test1.script
  
  Index: Test1.script
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/scripts/lxsql/Test1.script,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Test1.script	6 Dec 2001 00:58:51 -0000	1.5
  +++ Test1.script	29 Dec 2001 00:33:09 -0000	1.6
  @@ -5,6 +5,7 @@
       <column name="forename" type="varchar" max="20"/>
       <column name="surname" type="varchar" max="20"/>
       <column name="age" type="integer"/>
  +    <column name="dob" type="timestamp"/>
     </columns>
   </create-table>
   
  @@ -16,21 +17,25 @@
         <value col="forename">Fred</value>
         <value col="surname">Flintstone</value>
         <value col="age">40</value>
  +      <value col="dob">2001-01-01</value>
       </row>
       <row>
         <value col="forename">Wilma</value>
         <value col="surname">Flintstone</value>
         <value col="age">38</value>
  +      <value col="dob">1950-02-03</value>
       </row>
       <row>
         <value col="forename">Barney</value>
         <value col="surname">Rubble</value>
         <value col="age">66</value>
  +      <value col="dob">1756-15-15</value>
       </row>
       <row>
         <value col="forename">I am going</value>
         <value col="surname">to be deleted</value>
         <value col="age">999</value>
  +      <value col="dob">1968-02-12</value>
       </row>
     </rows>
   </insert-into>
  
  
  
  1.7       +3 -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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Test2.script	19 Dec 2001 10:45:46 -0000	1.6
  +++ Test2.script	29 Dec 2001 00:33:09 -0000	1.7
  @@ -19,6 +19,9 @@
          </concat>
        </trim>
        <column name="surname"/>
  +     <month as="MonthOfBirth">
  +       <column name="dob"/>
  +     </month>
      </columns>
      <from>
        <table name="Flintstones"/>
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>