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/xdocs/lxsqlsamples select01.txt
Date Fri, 09 Nov 2001 11:16:59 GMT
hammant     01/11/09 03:16:59

  Modified:    apps/db/src/java/org/apache/avalon/db/actions/impl
                        AbstractAction.java
               apps/db/src/java/org/apache/avalon/db/basic/actions
                        BasicCreateTable.java
               apps/db/src/java/org/apache/avalon/db/basic/parser
                        BasicLXSQLParser.java
               apps/db/src/java/org/apache/avalon/db/data/impl
                        AbstractTable.java
  Added:       apps/db/src/java/org/apache/avalon/db/basic/actions
                        BasicCreateView.java
               apps/db/src/java/org/apache/avalon/db/basic/data
                        BasicView.java
               apps/db/src/java/org/apache/avalon/db/data/impl
                        AbstractView.java
               apps/db/src/xdocs/lxsqlsamples select01.txt
  Log:
  start of basic view
  
  Revision  Changes    Path
  1.2       +15 -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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractAction.java	2001/11/07 12:24:20	1.1
  +++ AbstractAction.java	2001/11/09 11:16:59	1.2
  @@ -8,6 +8,7 @@
   package org.apache.avalon.db.actions.impl;
   
   import org.apache.avalon.db.services.DatabasePersistor;
  +import org.apache.avalon.db.actions.ActionException;
   
   public class AbstractAction {
   
  @@ -16,5 +17,19 @@
       public void setDatabasePersistor(DatabasePersistor databasePersistor) {
           mDatabasePersistor = databasePersistor;
       }
  +
  +    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.2       +38 -4     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicCreateTable.java
  
  Index: BasicCreateTable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicCreateTable.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BasicCreateTable.java	2001/11/07 12:24:20	1.1
  +++ BasicCreateTable.java	2001/11/09 11:16:59	1.2
  @@ -13,7 +13,12 @@
   import org.apache.avalon.db.actions.impl.AbstractAction;
   import org.apache.avalon.db.data.Column;
   import org.apache.avalon.db.data.Table;
  +import org.apache.avalon.db.data.impl.DefaultColumn;
   import org.apache.avalon.db.basic.data.BasicTable;
  +import org.apache.avalon.db.services.DatabasePersistor;
  +import org.w3c.dom.Element;
  +import org.w3c.dom.NodeList;
  +import org.w3c.dom.Node;
   
   import java.util.Vector;
   
  @@ -30,6 +35,7 @@
       private String mTableName;
       private Column[] mColumns;
       private int mRecordCount;
  +    private Element mLxsql;
   
       /**
        * Constructor BCELCreateTable
  @@ -39,14 +45,12 @@
        * @param tableName
        *
        */
  -    public BasicCreateTable(String tableName, Vector columns) {
  +    public BasicCreateTable(String tableName, Element lxsql) {
           mTableName = tableName;
  -        mColumns = new Column[columns.size()];
  -        columns.toArray(mColumns);
  +        mLxsql = lxsql;
       }
   
   
  -
       /**
        * Method execute
        *
  @@ -55,6 +59,36 @@
       public void execute() throws ActionException {
   
           System.out.println("ct execute");
  +
  +        NodeList subRootNodes = mLxsql.getChildNodes();
  +
  +        Vector columns = new Vector();
  +
  +        for (int f = 0 ; f < subRootNodes.getLength(); f++) {
  +            if (subRootNodes.item(f).getNodeName().equals("columns")) {
  +                NodeList subColumnsNodes = subRootNodes.item(f).getChildNodes();
  +                for (int x = 0 ; x < subColumnsNodes.getLength(); x++) {
  +                    if (subColumnsNodes.item(x).getNodeName().equals("column")) {
  +                        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 = new DefaultColumn(fieldName, sqlFieldType, fieldType);
  +                        columns.add(column);
  +                    } else {
  +                        // TODO  There should be no other element types inside <columns>
  +                    }
  +
  +                }
  +
  +            } else {
  +                //TODO  Only <columns> is supported in <create-table> so far
  +            }
  +        }
  +
  +        //TODO need to create constrcutor suitable for superclass.
  +        columns.toArray(mColumns);
  +
   
           /*
           if (mDatabasePersistor.tableExists(mTableName)) {
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicCreateView.java
  
  Index: BasicCreateView.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.basic.actions;
  
  import org.apache.avalon.db.actions.CreateTable;
  import org.apache.avalon.db.actions.ActionException;
  import org.apache.avalon.db.actions.impl.AbstractAction;
  import org.apache.avalon.db.data.Column;
  import org.apache.avalon.db.data.Table;
  import org.apache.avalon.db.basic.data.BasicTable;
  import org.apache.avalon.db.services.DatabasePersistor;
  import org.w3c.dom.Document;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.Element;
  
  import java.util.Vector;
  
  
  /**
   * Class BCELCreateTable
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class BasicCreateView extends AbstractAction implements CreateTable {
  
      private String mViewName;
      private BasicCreateTable basicCreateTable;
      private BasicSelect basicSelect;
  
      /**
       * Constructor BCELCreateTable
       *
       *
       * @param pendingClass
       * @param tableName
       *
       */
      public BasicCreateView(String viewName, Document lxsql) {
          mViewName = viewName;
          NodeList subRootNodes = lxsql.getChildNodes();
          for (int i = 0; i < subRootNodes.getLength(); i++) {
              if (subRootNodes.item(i).getNodeName().equals("create-table")) {
                  basicCreateTable = new BasicCreateTable(viewName, (Element) subRootNodes.item(i));
              } else if (subRootNodes.item(i).getNodeName().equals("select-simple")) {
                  //basicSelect = new BasicSelect(tableName, (Element) subRootNodes.item(i));
                  // TODO
              }
          }
  
  
      }
  
  
  
      /**
       * Method execute
       *
       *
       */
      public void execute() throws ActionException {
  
          System.out.println("cv execute");
  
          if (basicCreateTable != null) {
              basicCreateTable.execute();
          }
          if (basicSelect != null) {
              basicSelect.execute();
          }
  
      }
  
      public void setDatabasePersistor(DatabasePersistor databasePersistor) {
          super.setDatabasePersistor(databasePersistor);
          if (basicCreateTable != null) {
              basicCreateTable.setDatabasePersistor(databasePersistor);
          }
          if (basicSelect != null) {
              basicSelect.setDatabasePersistor(databasePersistor);
          }
      }
  
      public int getRecordCount() {
          //return basicSelect.get..
          return 0; //TODO
      }
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/data/BasicView.java
  
  Index: BasicView.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.basic.data;
  
  import org.apache.avalon.db.data.impl.AbstractView;
  import org.apache.avalon.db.data.Column;
  
  /**
   * Class BasicView
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class BasicView extends AbstractView {
  
  
      public BasicView(String name, Column[] columns) {
          super(name, columns);
      }
  
      public int getColumnIndex(String columnName) {
          for (int x = 0; x < mColumns.length; x++) {
              if (mColumns[x].getColumnName().equals(columnName)) {
                  return x;
              }
          }
          return -1;
      }
  
  
  }
  
  
  
  1.2       +1 -31     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/parser/BasicLXSQLParser.java
  
  Index: BasicLXSQLParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/parser/BasicLXSQLParser.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BasicLXSQLParser.java	2001/11/07 13:28:35	1.1
  +++ BasicLXSQLParser.java	2001/11/09 11:16:59	1.2
  @@ -76,39 +76,9 @@
           Document doc = parseLXSQLString(request.getSql());
   
           Element rootElement = doc.getDocumentElement();
  -        getLogger().debug("rootElement=" + rootElement.getTagName());
  -
           String tableName = rootElement.getAttribute("name");
  -
  -        NodeList subRootNodes = rootElement.getChildNodes();
  -
  -        Vector columns = new Vector();
  -
  -        for (int f = 0 ; f < subRootNodes.getLength(); f++) {
  -            if (subRootNodes.item(f).getNodeName().equals("columns")) {
  -                NodeList subColumnsNodes = subRootNodes.item(f).getChildNodes();
  -                for (int x = 0 ; x < subColumnsNodes.getLength(); x++) {
  -                    if (subColumnsNodes.item(x).getNodeName().equals("column")) {
  -                        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 = new DefaultColumn(fieldName, sqlFieldType, fieldType);
  -                        columns.add(column);
  -                    } else {
  -                        // TODO  There should be no other element types inside <columns>
  -                    }
  -
  -                }
  -
  -            } else {
  -                //TODO  Only <columns> is supported in <create-table> so far
  -            }
  -        }
  -
  -        //TODO need to create constrcutor suitable for superclass.
   
  -        CreateTable action = new BasicCreateTable(tableName, columns);
  +        CreateTable action = new BasicCreateTable(tableName, rootElement);
           action.setDatabasePersistor(mDatabasePersistor);
           return action;
   
  
  
  
  1.4       +1 -2      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/AbstractTable.java
  
  Index: AbstractTable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/AbstractTable.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractTable.java	2001/11/05 18:49:49	1.3
  +++ AbstractTable.java	2001/11/09 11:16:59	1.4
  @@ -24,7 +24,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 AbstractTable extends AbstractRowHolder implements Table {
   
  @@ -37,7 +37,6 @@
        *
        * @param name
        * @param columns
  -     * @param rowClass
        *
        */
       public AbstractTable(String name, Column[] columns) {
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/AbstractView.java
  
  Index: AbstractView.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.Table;
  import org.apache.avalon.db.data.RowHolder;
  import org.apache.avalon.db.data.Column;
  
  import java.util.Vector;
  import java.util.Collections;
  import java.util.Collection;
  
  
  /**
   * Class AbstractView
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public abstract class AbstractView extends AbstractRowHolder implements Table {
  
  
      private Vector rows = new Vector();
  
      /**
       * Constructor AbstractView
       *
       *
       * @param name
       * @param columns
       *
       */
      public AbstractView(String name, Column[] columns) {
          super(name, columns);
      }
  
      public void addRow(AbstractTableRow atr) {
          rows.add(atr);
      }
  
      public void removeRow(AbstractTableRow atr) {
          rows.remove(atr);
      }
  
      public Collection getRows() {
          return Collections.unmodifiableCollection(rows);
      }
  
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/xdocs/lxsqlsamples/select01.txt
  
  Index: select01.txt
  ===================================================================
  <create-table name="Flintstones">
    <columns>
      <column name="forename" type="varchar" max="20"/>
      <column name="surname" type="varchar" max="20"/>
    </columns>
  </create-table>
  
  

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