avalon-dev 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, 13 Nov 2001 09:25:43 GMT
hammant     01/11/13 01:25:43

  Modified:    apps/db/src/java/org/apache/avalon/db/actions/impl
                        AbstractAction.java
               apps/db/src/java/org/apache/avalon/db/basic/actions
                        BasicCreateQueryable.java BasicInsert.java
               apps/db/src/java/org/apache/avalon/db/basic/data
                        BasicTable.java
               apps/db/src/java/org/apache/avalon/db/data Column.java
               apps/db/src/java/org/apache/avalon/db/data/impl
                        IntegerColumn.java VarCharColumn.java
               apps/db/src/java/org/apache/avalon/db/test Tester.java
  Log:
  Integer in tests now
  
  Revision  Changes    Path
  1.4       +2 -0      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractAction.java	2001/11/11 13:32:40	1.3
  +++ AbstractAction.java	2001/11/13 09:25:42	1.4
  @@ -19,6 +19,7 @@
           mDatabasePersistor = databasePersistor;
       }
   
  +    /* TODO not needed ? - PH
       protected Class getJavaType(String sqlType) throws ActionException {
   
           System.out.println("Type=(" + sqlType + ")");
  @@ -31,6 +32,7 @@
   
           throw new ActionException("Type " + sqlType + " not supported yet");
       }
  +    */
   
   
   }
  
  
  
  1.4       +1 -2      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicCreateQueryable.java
  
  Index: BasicCreateQueryable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicCreateQueryable.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BasicCreateQueryable.java	2001/11/13 09:07:25	1.3
  +++ BasicCreateQueryable.java	2001/11/13 09:25:42	1.4
  @@ -30,7 +30,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 abstract class BasicCreateQueryable extends AbstractAction implements CreateTable
{
   
  @@ -54,7 +54,6 @@
                           Node columnNode = subColumnsNodes.item(x);
                           String fieldName = columnNode.getAttributes().getNamedItem("name").getNodeValue();
                           String sqlFieldType = columnNode.getAttributes().getNamedItem("type").getNodeValue();
  -                        String fieldType = getJavaType(sqlFieldType).toString();
                           Column column = null;
                           if (sqlFieldType.equals("varchar")) {
                               int maxLength = Integer.parseInt(columnNode.getAttributes().getNamedItem("max").getNodeValue());
  
  
  
  1.4       +17 -8     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicInsert.java
  
  Index: BasicInsert.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicInsert.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BasicInsert.java	2001/11/09 21:15:47	1.3
  +++ BasicInsert.java	2001/11/13 09:25:42	1.4
  @@ -13,6 +13,8 @@
   import org.apache.avalon.db.actions.ActionException;
   import org.apache.avalon.db.basic.data.BasicTable;
   import org.apache.avalon.db.basic.data.BasicRow;
  +import org.apache.avalon.db.data.Column;
  +import org.apache.avalon.db.data.ValidationException;
   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
   import org.w3c.dom.NodeList;
  @@ -63,17 +65,22 @@
   
           NodeList subRootNodes = rootElement.getChildNodes();
   
  -        for (int f = 0 ; f < subRootNodes.getLength(); f++) {
  -            if (subRootNodes.item(f).getNodeName().equals("rows")) {
  -                NodeList subRowsNodes = subRootNodes.item(f).getChildNodes();
  -                processSubRowsNodes(subRowsNodes);
  -            } else {
  -                //TODO
  +        try {
  +
  +            for (int f = 0 ; f < subRootNodes.getLength(); f++) {
  +                if (subRootNodes.item(f).getNodeName().equals("rows")) {
  +                    NodeList subRowsNodes = subRootNodes.item(f).getChildNodes();
  +                    processSubRowsNodes(subRowsNodes);
  +               } else {
  +                   throw new ActionException("Only 'rows' allowed as a node under root
node");
  +                }
               }
  +        } catch (ValidationException ve) {
  +            throw new ActionException(ve.getMessage());
           }
       }
   
  -    private void processSubRowsNodes(NodeList subRowsNodes) {
  +    private void processSubRowsNodes(NodeList subRowsNodes) throws ValidationException
{
           Object[] values = new Object[mTable.getColumns().length];
           for (int x = 0 ; x < subRowsNodes.getLength(); x++) {
               if (subRowsNodes.item(x).getNodeName().equals("row")) {
  @@ -85,7 +92,9 @@
                           String colName = rowNode.getAttribute("col");
                           String valueStr = rowNode.getFirstChild().getNodeValue();
                           int ix = mTable.getColumnIndex(colName);
  -                        values[ix] = valueStr;
  +                        // TODO perhaps coluns could know their own index?
  +                        Column col = mTable.getColumn(colName);
  +                        values[ix] = col.convertFromString(valueStr);
                       }
                   }
                   Vector pendingRow = new Vector();
  
  
  
  1.6       +10 -2     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/data/BasicTable.java
  
  Index: BasicTable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/data/BasicTable.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BasicTable.java	2001/11/12 20:03:22	1.5
  +++ BasicTable.java	2001/11/13 09:25:42	1.6
  @@ -24,9 +24,17 @@
               }
           }
           throw new RuntimeException("Column " + columnName + " not found");
  -        //System.out.println("Whoa " + columnName + " not found");
  -        //return -1;
       }
  +
  +    public Column getColumn(String columnName) {
  +        for (int x = 0; x < mColumns.length; x++) {
  +            if (mColumns[x].getColumnName().equals(columnName)) {
  +                return mColumns[x];
  +            }
  +        }
  +        throw new RuntimeException("Column " + columnName + " not found");
  +    }
  +
   
   
   }
  
  
  
  1.7       +2 -1      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/Column.java
  
  Index: Column.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/Column.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Column.java	2001/11/12 23:09:56	1.6
  +++ Column.java	2001/11/13 09:25:42	1.7
  @@ -14,11 +14,12 @@
    *
    * @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.6 $
  + * @version * $Revision: 1.7 $
    */
   public interface Column extends Nameable {
   
       void test(Object obj) throws ValidationException;
  +    Object convertFromString(String str) throws ValidationException;
   
       String getSQLType();
       String getJavaType();
  
  
  
  1.2       +9 -0      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/IntegerColumn.java
  
  Index: IntegerColumn.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/IntegerColumn.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IntegerColumn.java	2001/11/13 09:07:26	1.1
  +++ IntegerColumn.java	2001/11/13 09:25:42	1.2
  @@ -16,7 +16,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class IntegerColumn extends AbstractColumn {
   
  @@ -38,4 +38,13 @@
               throw new ValidationException("Integer " + mName + " is not a valid number
(" + obj + ")");
           }
       }
  +
  +    public Object convertFromString(String str) throws ValidationException {
  +        try {
  +            return new Integer(str);
  +        } catch (NumberFormatException nfe) {
  +            throw new ValidationException("Integer " + mName + " is not a valid number
(" + str + ")");
  +        }
  +    }
  +
   }
  
  
  
  1.3       +6 -1      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/VarCharColumn.java
  
  Index: VarCharColumn.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/VarCharColumn.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- VarCharColumn.java	2001/11/13 09:07:26	1.2
  +++ VarCharColumn.java	2001/11/13 09:25:42	1.3
  @@ -17,7 +17,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.2 $
  + * @version $Revision: 1.3 $
    */
   public class VarCharColumn extends AbstractColumn {
   
  @@ -41,5 +41,10 @@
           if (str.length() > mMaxLength) {
               throw new ValidationException("String " + mName + " is too long at " + str.length());
           }
  +    }
  +
  +    public Object convertFromString(String str) throws ValidationException {
  +        test(str);
  +        return str;
       }
   }
  
  
  
  1.13      +4 -0      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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Tester.java	2001/11/12 20:03:22	1.12
  +++ Tester.java	2001/11/13 09:25:43	1.13
  @@ -31,6 +31,7 @@
                                  "<columns>" +
                                    "<column name=\"forename\" type=\"varchar\" max=\"20\"/>"
+
                                    "<column name=\"surname\" type=\"varchar\" max=\"20\"/>"
+
  +                                 "<column name=\"age\" type=\"integer\"/>" +
                                  "</columns>" +
                                "</create-table>";
   
  @@ -44,14 +45,17 @@
                                    "<row>" +
                                      "<value col=\"forename\">Fred</value>" +
                                      "<value col=\"surname\">Flintsone</value>"
+
  +                                   "<value col=\"age\">40</value>" +
                                    "</row>" +
                                    "<row>" +
                                      "<value col=\"forename\">Wilma</value>"
+
                                      "<value col=\"surname\">Flintsone</value>"
+
  +                                   "<value col=\"age\">38</value>" +
                                    "</row>" +
                                    "<row>" +
                                      "<value col=\"forename\">Barney</value>"
+
                                      "<value col=\"surname\">Rubble</value>"
+
  +                                   "<value col=\"age\">39</value>" +
                                    "</row>" +
                                  "</rows>" +
                                "</insert-into>";
  
  
  

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


Mime
View raw message