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 Test1.script
Date Thu, 29 Nov 2001 14:26:13 GMT
hammant     01/11/29 06:26:13

  Modified:    apps/db  build.xml
               apps/db/src/java/org/apache/avalon/db/basic/actions
                        BasicLXSQLCriteriaHelper.java
               apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql
                        BasicLXSQLCreateAggregateViewHandler.java
                        BasicLXSQLCreateTableHandler.java
                        BasicLXSQLInsertRowsHandler.java
                        BasicLXSQLQueryableHandler.java
                        BasicLXSQLSelectSimpleHandler.java
                        BasicLXSQLUpdateRowsHandler.java
               apps/db/src/java/org/apache/avalon/db/driver/lxsql
                        LXSQLParserHelper.java
               apps/db/src/java/org/apache/avalon/db/test Tester.java
  Added:       apps/db/src/scripts/lxsql Test1.script
  Log:
  Tester uses script file now
  
  Revision  Changes    Path
  1.22      +5 -1      jakarta-avalon-cornerstone/apps/db/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/build.xml,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- build.xml	2001/11/27 23:01:30	1.21
  +++ build.xml	2001/11/29 14:26:13	1.22
  @@ -336,7 +336,11 @@
     <target name="docs"/>
     
     <target name="test1" depends="main">
  -    <java classname="org.apache.avalon.db.test.Tester" fork="true">
  +  
  +    <property name="script" location="src/scripts/lxsql/Test1.script"/>
  +  
  +    <java classname="org.apache.avalon.db.test.Tester" fork="true">          
  +      <arg value="${script}"/>
         <classpath refid="test.path"/>
       </java>  
     </target>
  
  
  
  1.2       +15 -5     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicLXSQLCriteriaHelper.java
  
  Index: BasicLXSQLCriteriaHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicLXSQLCriteriaHelper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BasicLXSQLCriteriaHelper.java	2001/11/29 10:35:26	1.1
  +++ BasicLXSQLCriteriaHelper.java	2001/11/29 14:26:13	1.2
  @@ -20,6 +20,7 @@
   
   import java.util.Hashtable;
   import java.util.Enumeration;
  +import java.util.Vector;
   
   /**
    * Class BasicLXSQLCriteriaHelper
  @@ -74,8 +75,10 @@
                       Element whereElement = (Element)subRootNodes.item(i);
                       NodeList elements = whereElement.getChildNodes();
                       for (int j=0; j < elements.getLength(); j++) {
  -                        Element element = (Element)elements.item(j);
  -                        parseWhereTerm(element, whereBuffer, indent+1);
  +                        String nodeName = elements.item(j).getNodeName();
  +                        if (!nodeName.equals("#text")) {
  +                          parseWhereTerm((Element) elements.item(j), whereBuffer, indent+1);
  +                        }
                       }
                       whereDone = true;
                   }
  @@ -113,11 +116,18 @@
       private void parseWhereAndOrTerm(NodeList nodes, StringBuffer sb, int indent, String
andOr) {
           sb.append(getIndent(indent) + "(\n");
           try {
  +            Vector realNodes = new Vector();
               for(int i=0; i<nodes.getLength(); i++) {
  +                if (!nodes.item(i).getNodeName().equals("#text")) {
  +                    realNodes.add(nodes.item(i));
  +                }
  +            }
  +            for (int i = 0; i < realNodes.size(); i++) {
  +                Element elem = (Element) realNodes.elementAt(i);
                   //getLogger().debug("Looping and/or");
  -                parseWhereTerm((Element)nodes.item(i),sb, indent +1);
  -                if (i+1 < nodes.getLength()) {
  -                  sb.append( getIndent(indent) + andOr + "\n");
  +                parseWhereTerm(elem,sb, indent +1);
  +                if (i+1 < realNodes.size()) {
  +                    sb.append( getIndent(indent) + andOr + "\n");
                   }
               }
           } catch(Exception e) {
  
  
  
  1.5       +3 -4      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BasicLXSQLCreateAggregateViewHandler.java	2001/11/29 10:35:55	1.4
  +++ BasicLXSQLCreateAggregateViewHandler.java	2001/11/29 14:26:13	1.5
  @@ -33,7 +33,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 BasicLXSQLCreateAggregateViewHandler extends BasicLXSQLAggregateHandler {
   
  @@ -76,7 +76,6 @@
               Column[] columns = null;
               NodeList subRootNodes = rootElement.getChildNodes();
               for (int i = 0; i < subRootNodes.getLength(); i++) {
  -                System.out.println(">>>"+subRootNodes.item(i).getNodeName());
                   if (subRootNodes.item(i).getNodeName().equals("grouped-columns")) {
                       columns = this.getColumns((Element) subRootNodes.item(i));
                   } else if (subRootNodes.item(i).getNodeName().equals("group-function-columns"))
{
  @@ -88,8 +87,8 @@
               basicCriteriaHelper.enableLogging(super.getLogger());
   
               CreateAggregateView action = new BasicCreateAggregateView(
  -                                                viewName, 
  -                                                onName, 
  +                                                viewName,
  +                                                onName,
                                                   columns ,
                                                   new BasicCriteria(basicCriteriaHelper.getCriteria())
                                            );
  
  
  
  1.7       +1 -3      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/BasicLXSQLCreateTableHandler.java
  
  Index: BasicLXSQLCreateTableHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/BasicLXSQLCreateTableHandler.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- BasicLXSQLCreateTableHandler.java	2001/11/23 12:40:20	1.6
  +++ BasicLXSQLCreateTableHandler.java	2001/11/29 14:26:13	1.7
  @@ -32,7 +32,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.6 $
  + * @version $Revision: 1.7 $
    */
   public class BasicLXSQLCreateTableHandler extends BasicLXSQLQueryableHandler {
   
  @@ -74,12 +74,10 @@
               Column[] columns = null;
               NodeList subRootNodes = rootElement.getChildNodes();
               for (int i = 0; i < subRootNodes.getLength(); i++) {
  -                System.out.println(">>>"+subRootNodes.item(i).getNodeName());
                   if (subRootNodes.item(i).getNodeName().equals("columns")) {
                       columns = getColumns((Element) subRootNodes.item(i));
                   }
               }
  -            System.out.println(">>>-" + columns[0]);
               CreateTable action = new BasicCreateTable(tableName, columns);
   
               mParser.initializeAction(action);
  
  
  
  1.6       +6 -3      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/BasicLXSQLInsertRowsHandler.java
  
  Index: BasicLXSQLInsertRowsHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/BasicLXSQLInsertRowsHandler.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BasicLXSQLInsertRowsHandler.java	2001/11/23 12:40:20	1.5
  +++ BasicLXSQLInsertRowsHandler.java	2001/11/29 14:26:13	1.6
  @@ -40,7 +40,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.6 $
    */
   public class BasicLXSQLInsertRowsHandler extends BasicLXSQLHandler {
   
  @@ -81,11 +81,14 @@
           Collection rows = null;
           try {
               for (int f = 0 ; f < subRootNodes.getLength(); f++) {
  +                String nodeName = subRootNodes.item(f).getNodeName();
                   if (subRootNodes.item(f).getNodeName().equals("rows")) {
                       NodeList subRowsNodes = subRootNodes.item(f).getChildNodes();
                       rows = processSubRowsNodes((BasicTable) queryable, subRowsNodes);
  -               } else {
  -                   throw new ActionException("Only 'rows' allowed as a node under root
node");
  +                } else if (nodeName.equals("#text")) {
  +                    // do nothing, whitespace between elems
  +                } else {
  +                    throw new ActionException("Only 'rows' allowed as a node under root
node");
                   }
               }
           } catch (ValidationException ve) {
  
  
  
  1.3       +9 -4      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/BasicLXSQLQueryableHandler.java
  
  Index: BasicLXSQLQueryableHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/BasicLXSQLQueryableHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BasicLXSQLQueryableHandler.java	2001/11/29 00:50:02	1.2
  +++ BasicLXSQLQueryableHandler.java	2001/11/29 14:26:13	1.3
  @@ -34,7 +34,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 abstract class BasicLXSQLQueryableHandler extends BasicLXSQLHandler {
   
  @@ -61,16 +61,21 @@
   
           NodeList subColumnsNodes = columnsNode.getChildNodes();
           for (int x = 0 ; x < subColumnsNodes.getLength(); x++) {
  -            if (subColumnsNodes.item(x).getNodeName().equals("column")) {
  +            String nodeName = subColumnsNodes.item(x).getNodeName();
  +            if (nodeName.equals("column")) {
                   columns.add(createColumn(subColumnsNodes.item(x), x));
  +            } else if (nodeName.equals("#text")) {
  +                // do nothing, whitespace between elems
               } else {
  -
  -                throw new ActionException("Only 'column' allowed as a node under 'columns'
node");
  +                throw new ActionException("Only 'column' allowed as a node under 'columns'
node, "+subColumnsNodes.item(x).getNodeName()+" found");
               }
           }
   
           Column[] columnsAry = new Column[columns.size()];
           columns.toArray(columnsAry);
  +        for (int x = 0; x < columnsAry.length; x++ ) {
  +            columnsAry[x].setIndex(x);
  +        }
   
           return columnsAry;
   
  
  
  
  1.6       +42 -22    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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BasicLXSQLSelectSimpleHandler.java	2001/11/29 10:35:55	1.5
  +++ BasicLXSQLSelectSimpleHandler.java	2001/11/29 14:26:13	1.6
  @@ -27,13 +27,16 @@
   import org.w3c.dom.Element;
   import org.w3c.dom.NodeList;
   
  +import java.util.Vector;
   
  +
   /**
    * Class BasicLXSQLSelectSimpleHandler
    *
    *
  +* @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.5 $
  + * @version $Revision: 1.6 $
    */
   public class BasicLXSQLSelectSimpleHandler extends BasicLXSQLHandler {
   
  @@ -72,6 +75,16 @@
   
           AbstractQueryable queryable = (AbstractQueryable) mDatabasePersistor.getQueryable(tables[0]);
   
  +        String[] cols = getColumns(rootElement);
  +        Column[] columns = null;
  +
  +        // TODO - not perfect.
  +        if (cols.length != 0 && cols[0].equals("*")) {
  +            columns = queryable.getColumns();
  +        } else {
  +            columns = convertColumns(queryable, cols);
  +        }
  +
           Select action = new BasicSelectSimple(tables,
           convertColumns(queryable, getColumns(rootElement)),
           new BasicCriteria(criteriaHelper.getCriteria()));
  @@ -83,18 +96,28 @@
       }
   
   
  -    private String[] parseFrom(Element rootElement) {
  +    private String[] parseFrom(Element rootElement) throws ActionException {
           NodeList subRootNodes = rootElement.getChildNodes();
           String[] tablenames = null;
   
           for (int i=0; i < subRootNodes.getLength(); i++) {
               if(subRootNodes.item(i).getNodeName().equals("from")) {
                   NodeList subFromNodes = subRootNodes.item(i).getChildNodes();
  -                tablenames = new String[subFromNodes.getLength()];
  +                Vector tables = new Vector();
                   for(int j=0; j < subFromNodes.getLength(); j++) {
  -                    Element fromElement = (Element)subFromNodes.item(j);
  -                    tablenames[j] = fromElement.getAttribute("name");
  +                    String subFromNodeName = subFromNodes.item(j).getNodeName();
  +                    if (subFromNodeName.equals("table")) {
  +                       Element fromElement = (Element)subFromNodes.item(j);
  +                       tables.add(fromElement.getAttribute("name"));
  +                    } else if (subFromNodeName.equals("#text")) {
  +
  +                        // ignore.
  +                    } else {
  +                        throw new ActionException("Unexpected node '"+subFromNodeName+"'
under 'from'");
  +                    }
                   }
  +                tablenames = new String[tables.size()];
  +                tables.copyInto(tablenames);
               }
           }
           return tablenames;
  @@ -103,9 +126,6 @@
       protected Column[] convertColumns(AbstractQueryable queryable, String[] columnNames)
{
   
           //TODO * could be with other contrived columns
  -        if (columnNames[0].equals("*")) {
  -            return queryable.getColumns();
  -        }
   
           Column[] columns = new Column[columnNames.length];
           for ( int i = 0; i < columnNames.length; i++ ) {
  @@ -121,24 +141,24 @@
           for (int i=0; i < subRootNodes.getLength(); i++) {
               if(subRootNodes.item(i).getNodeName().equals("columns")) {
                   Element columnsElement = (Element)subRootNodes.item(i);
  -                getLogger().debug("columnsElement.getFirstChild()=" + columnsElement.getFirstChild().getNodeName());
                   //First test if *
  -                if(columnsElement.getFirstChild().getNodeName().equals("#text")) {
  -                   if(columnsElement.getFirstChild().getNodeValue().equals("*")) {
  -                       cols = new String[1];
  -                       cols[0] = "*";
  -                   } else {
  -                       throw new ActionException(columnsElement.getFirstChild().getNodeValue()
  -                                              + " is not valid LXSQL Syntax");
  -                   }
  -                } else if (subRootNodes.item(i).hasChildNodes()) {
  +                if (subRootNodes.item(i).hasChildNodes()) {
                       NodeList subColumnsNodes = subRootNodes.item(i).getChildNodes();
  -                    cols = new String[subColumnsNodes.getLength()];
  +                    Vector colVec = new Vector();
                       for (int j=0; j < subColumnsNodes.getLength(); j++) {
  -                        //TODO checking columns, function...maybe extern syntax checking!?
  -                        Element columnElement = (Element)subColumnsNodes.item(j);
  -                        cols[j] = columnElement.getAttribute("name");
  +                        String nodeName = subColumnsNodes.item(j).getNodeName();
  +                        if (nodeName.equals("column")) {
  +                            //TODO checking columns, function...maybe extern syntax checking!?
  +                            Element columnElement = (Element)subColumnsNodes.item(j);
  +                            colVec.add(columnElement.getAttribute("name"));
  +                        } else if (nodeName.equals("#text")) {
  +                            // do nothing, whitespace between elems
  +                        } else {
  +                            throw new ActionException("Unknow node type '"+nodeName+"'
under 'columns'");
  +                        }
                       }
  +                    cols = new String[colVec.size()];
  +                    colVec.copyInto(cols);
                   } else {
                       throw new ActionException(columnsElement.getFirstChild().getNodeValue()
                                                 + " is not valid LXSQL Syntax");
  
  
  
  1.8       +8 -5      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/BasicLXSQLUpdateRowsHandler.java
  
  Index: BasicLXSQLUpdateRowsHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/BasicLXSQLUpdateRowsHandler.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- BasicLXSQLUpdateRowsHandler.java	2001/11/29 10:35:55	1.7
  +++ BasicLXSQLUpdateRowsHandler.java	2001/11/29 14:26:13	1.8
  @@ -33,7 +33,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.7 $
  + * @version $Revision: 1.8 $
    */
   public class BasicLXSQLUpdateRowsHandler extends BasicLXSQLHandler {
   
  @@ -68,7 +68,7 @@
           Element rootElement = doc.getDocumentElement();
           String queryableStr = rootElement.getAttribute("from");
           Queryable queryable = (Queryable) mDatabasePersistor.getQueryable(queryableStr);
  -    
  +
           String matchingInstructions = null;
   
           NodeList subRootNodes = rootElement.getChildNodes();
  @@ -82,9 +82,9 @@
           basicCriteriaHelper.enableLogging(super.getLogger());
   
           UpdateRows action = new BasicUpdateRows(
  -                                    (AbstractQueryable) queryable, 
  +                                    (AbstractQueryable) queryable,
                                       new BasicCriteria(
  -                                            basicCriteriaHelper.getCriteria(), 
  +                                            basicCriteriaHelper.getCriteria(),
                                               matchingInstructions, "")
                                       );
   
  @@ -98,8 +98,11 @@
           NodeList subUpdatesNodes = updatesElement.getChildNodes();
           StringBuffer instructionBuffer = new StringBuffer();
           for (int i=0; i < subUpdatesNodes.getLength(); i++) {
  -            if(subUpdatesNodes.item(i).getNodeName().equals("set")) {
  +            String nodeName = subUpdatesNodes.item(i).getNodeName();
  +            if (nodeName.equals("set")) {
                   setSetInstruction((Element) subUpdatesNodes.item(i), instructionBuffer);
  +            } else if(nodeName.equals("#text")) {
  +                // ignore
               } else {
                   throw new ActionException("Element 'set' is the only element allowed beneath
'updates'");
               }
  
  
  
  1.10      +9 -10     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/lxsql/LXSQLParserHelper.java
  
  Index: LXSQLParserHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/lxsql/LXSQLParserHelper.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- LXSQLParserHelper.java	2001/11/27 21:18:22	1.9
  +++ LXSQLParserHelper.java	2001/11/29 14:26:13	1.10
  @@ -1,10 +1,9 @@
   /*
  - * Created by IntelliJ IDEA.
  - * User: Administrator
  - * Date: Nov 4, 2001
  - * Time: 10:05:06 AM
  - * To change template for new class use 
  - * Code Style | Class Templates options (Tools | IDE Options).
  + * 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.driver.lxsql;
   
  @@ -33,7 +32,7 @@
               request = new UpdateRowsRequest(sql);
           } else if (sql.startsWith("<delete")) {
               request = new DeleteRowsRequest(sql);
  -        } else if (sql.startsWith("<select")) {
  +        } else if (sql.startsWith("<simple-select")) {
               request = new SelectRequest(sql);
           } else if (sql.startsWith("<create-")) {
               request = getCreateRequest(sql);
  @@ -43,7 +42,7 @@
               request = new DeleteRowsRequest(sql);
               //TODO
           } else {
  -            throw new SQLException("Unknown SQL instruction (first term)");
  +            throw new SQLException("Unknown SQL instruction (first term) - '" + sql.substring(0,10)
+ "'");
           }
           return request;
       }
  @@ -58,7 +57,7 @@
           } else if (sql.startsWith("<create-index")) {
               return new CreateIndexRequest(sql);
           } else {
  -            throw new SQLException("Unknown SQL instruction (first term)");
  +            throw new SQLException("Unknown SQL instruction (first term) - '" + sql.substring(0,10)
+ "'");
           }
       }
   
  @@ -70,7 +69,7 @@
           } else if (sql.startsWith("<drop-index")) {
               return new DropIndexRequest(sql);
           } else {
  -            throw new SQLException("Unknown SQL instruction (first term)");
  +            throw new SQLException("Unknown SQL instruction (first term) - '" + sql.substring(0,10)
+ "'");
           }
       }
   }
  
  
  
  1.33      +77 -196   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.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- Tester.java	2001/11/28 23:09:58	1.32
  +++ Tester.java	2001/11/29 14:26:13	1.33
  @@ -11,208 +11,90 @@
   import java.sql.Connection;
   import java.sql.Statement;
   import java.sql.ResultSet;
  +import java.sql.SQLException;
   import java.io.File;
  +import java.io.StringReader;
  +import java.io.FileInputStream;
  +import java.io.InputStreamReader;
   
   public class Tester {
   
       Connection mCon;
  +    String mLxsql;
   
  -    private Tester() throws Exception {
  +    private Tester(String scriptFile) throws Exception {
           Class.forName("org.apache.avalon.db.driver.AvalonDBDriver").newInstance();
           String url = "jdbc:avalondb:cmds:lxsql:BlahBlah:localhost:9001";
           mCon = DriverManager.getConnection(url, "todo", "todo");
  -    }
   
  -    private void test() throws Exception {
  -        Statement st = mCon.createStatement();
  +        String D = File.separator;
   
  -        System.err.println("CREATE");
  -        String createTable = "<create-table name=\"Flintstones\">" +
  -                               "<columns>" +
  -                                 "<column name=\"forename\" type=\"varchar\" max=\"20\"/>"
+
  -                                 "<column name=\"surname\" type=\"varchar\" max=\"20\"/>"
+
  -                                 "<column name=\"age\" type=\"integer\"/>" +
  -                               "</columns>" +
  -                             "</create-table>";
  -
  -        st.executeUpdate(createTable);
  -        System.out.println("  Update Count : " + st.getUpdateCount());
  -        st.close();
  -
  -        System.err.println("INSERT");
  -        st = mCon.createStatement();
  -        String insertInto = "<insert-into table-name=\"Flintstones\">" +
  -                               "<rows>" +
  -                                 "<row>" +
  -                                   "<value col=\"forename\">Fred</value>" +
  -                                   "<value col=\"surname\">Flintstone</value>"
+
  -                                   "<value col=\"age\">40</value>" +
  -                                 "</row>" +
  -                                 "<row>" +
  -                                   "<value col=\"forename\">Wilma</value>"
+
  -                                   "<value col=\"surname\">Flintstone</value>"
+
  -                                   "<value col=\"age\">38</value>" +
  -                                 "</row>" +
  -                                 "<row>" +
  -                                   "<value col=\"forename\">Barney</value>"
+
  -                                   "<value col=\"surname\">Rubble</value>"
+
  -                                   "<value col=\"age\">66</value>" +
  -                                 "</row>" +
  -                                 "<row>" +
  -                                   "<value col=\"forename\">I am going</value>"
+
  -                                   "<value col=\"surname\">to be deleted</value>"
+
  -                                   "<value col=\"age\">999</value>" +
  -                                 "</row>" +
  -                               "</rows>" +
  -                             "</insert-into>";
  -        st.executeUpdate(insertInto);
  -        System.out.println("  Update Count : " + st.getUpdateCount());
  -        st.close();
  -
  -
  -        System.err.println("SELECT 0 (all rows)");
  -        st = mCon.createStatement();
  -        String select = "<simple-select>" +
  -                           "<columns>*</columns>" +
  -                           "<from><table name=\"Flintstones\"/></from>"
+
  -                        "</simple-select>";
  -
  -        ResultSet rs = st.executeQuery(select);
  -        st.close();
  -        while (rs.next()) {
  -            System.out.println("  Row:" + rs.getString(0) + ", " + rs.getString(1) + ",
" + rs.getString(2));
  -        }
  -        rs.close();
  +        FileInputStream fis = new FileInputStream(scriptFile);
  +        InputStreamReader isr = new InputStreamReader(fis, "UTF8");
   
  -        System.err.println("SELECT 1 (age>40)");
  -        st = mCon.createStatement();
  -        select = "<simple-select>" +
  -                          "<columns><column name=\"forename\"/>" +
  -                          "<column name=\"surname\"/></columns>" +
  -                           //"<columns>*</columns>" +
  -                           "<from><table name=\"Flintstones\"/></from>"
+
  -
  -                           "<where>" +
  -                               "<condition expr=\"age>=40\"/>" +
  -                           "</where>" +
  -
  -                        "</simple-select>";
  -
  -        rs = st.executeQuery(select);
  -        st.close();
  -        while (rs.next()) {
  -            System.out.println("  Row:" + rs.getString(0) + ", " + rs.getString(1));
  -        }
  -        rs.close();
  +        StringBuffer buffer = new StringBuffer();
   
  -        System.err.println("VIEW 1 (Wilma Flintstone)");
  -        st = mCon.createStatement();
  -        String view = "<create-view name=\"FlintstonesView\" on=\"Flintstones\">"
+
  -                         "<columns>" +
  -                             "<column name=\"forename\" type=\"varchar\" max=\"20\"/>"
+
  -                             "<column name=\"surname\" type=\"varchar\" max=\"20\"/>"
+
  -                             "<column name=\"age\" type=\"integer\"/>" +
  -                         "</columns>" +
  -                         "<where>" +
  -                             "<and>" +
  -                                 "<condition expr=\"forename=Wilma\"/>" +
  -                                 "<condition expr=\"surname=Flintstone\"/>" +
  -                             "</and>" +
  -                         "</where>" +
  -                      "</create-view>";
  -
  -        st.execute(view);
  -        System.out.println("  Update Count : " + st.getUpdateCount());
  -        st.close();
  -
  -        System.err.println("SELECT 2 (on view)");
  -        st = mCon.createStatement();
  -        select = "<simple-select>" +
  -                          "<columns><column name=\"forename\"/>" +
  -                          "<column name=\"surname\"/></columns>" +
  -                           //"<columns>*</columns>" +
  -                           "<from><table name=\"FlintstonesView\"/></from>"
+
  -                        "</simple-select>";
  -        rs = st.executeQuery(select);
  -        st.close();
  -        while (rs.next()) {
  -            System.out.println("  Row:" + rs.getString(0) + ", " + rs.getString(1));
  +        int ch;
  +        while ((ch = isr.read()) > -1) {
  +            buffer.append((char)ch);
           }
  -        rs.close();
  +        isr.close();
  +        fis.close();
   
  +        mLxsql = buffer.toString();
   
  -        System.err.println("INDEX 1");
  -        st = mCon.createStatement();
  -        String index = "<create-index name=\"FlintstonesIdx\" table=\"Flintstones\">"
+
  -                         "<columns>" +
  -                            "<column name=\"forename\"/>" +
  -                            "<column name=\"surname\"/>" +
  -                         "</columns>" +
  -                      "</create-index>";
  -        st.execute(index);
  -        System.out.println("  Update Count : " + st.getUpdateCount());
  -        st.close();
  -
  -        System.err.println("DELETE 1 (age>100)");
  -        st = mCon.createStatement();
  -        String delt = "<delete-rows from=\"Flintstones\">" +
  -                          "<where>" +
  -                              "<condition expr=\"age>100\"/>" +
  -                          "</where>" +
  -                      "</delete-rows>";
  -        st.execute(delt);
  -        System.out.println("  Update Count : " + st.getUpdateCount());
  -        st.close();
  -
  -        System.err.println("UPDATE 1");
  -        st = mCon.createStatement();
  -        String updt = "<update-rows from=\"Flintstones\">" +
  -                          "<updates>" +
  -                              "<set name=\"surname\" value=\"McRubble\"/>" +
  -                          "</updates>" +
  -                          "<where>" +
  -                              "<condition expr=\"age>60\"/>" +
  -                          "</where>" +
  -                      "</update-rows>";
  -        st.execute(updt);
  -        System.out.println("  Update Count : " + st.getUpdateCount());
  -        st.close();
  -
  -        System.err.println("SELECT 3 (all rows)");
  -        st = mCon.createStatement();
  -        select = "<simple-select>" +
  -                          "<columns><column name=\"forename\"/>" +
  -                          "<column name=\"surname\"/></columns>" +
  -                           //"<columns>*</columns>" +
  -                           "<from><table name=\"Flintstones\"/></from>"
+
  -                        "</simple-select>";
  -        rs = st.executeQuery(select);
  -        st.close();
  -        while (rs.next()) {
  -            System.out.println("  Row:" + rs.getString(0) + ", " + rs.getString(1));
  -        }
  -        rs.close();
  +    }
  +
  +    private void test() throws Exception {
  +
  +        String lxSQL = null;
   
  -        System.err.println("VIEW 2 (surname aggregate)");
  -        st = mCon.createStatement();
  -        view = "<create-aggregate-view name=\"FlintstonesAggView\" on=\"Flintstones\">"
+
  -                         "<grouped-columns>" +
  -                             "<column name=\"surname\" as=\"lastName\"/>" +
  -                         "</grouped-columns>" +
  -                         "<group-function-columns>" +
  -                             "<count as=\"surCount\"/>" +
  -                             "<max as=\"maxAge\" on=\"age\"/>" +
  -                             "<min as=\"minAge\" on=\"age\"/>" +
  -                             "<ave as=\"aveAge\" on=\"age\"/>" +
  -                             "<sum as=\"sumAge\" on=\"age\"/>" +
  -                         "</group-function-columns>" +
  -                      "</create-aggregate-view>";
  -
  -        st.execute(view);
  -        System.out.println("  Update Count : " + st.getUpdateCount());
  -        st.close();
  +        try {
   
  +        System.out.println("Testing.....");
   
  +        int str = mLxsql.indexOf("###",0);
  +        int end = mLxsql.indexOf("###",str+3);
  +        while (end > 0) {
  +            int msgEnd = mLxsql.indexOf("##!",str);
  +            System.out.println(mLxsql.substring(str+3, msgEnd));
  +            lxSQL = mLxsql.substring(msgEnd+3,end);
  +            Statement st = mCon.createStatement();
  +
  +            if (lxSQL.indexOf("<simple-select") > 0) {
  +                ResultSet rs = st.executeQuery(lxSQL.trim());
  +                System.out.println("Results:");
  +                while (rs.next()) {
  +                    System.out.print("  Row:" + rs.getString(0));
  +                    try {
  +                        String col1 = rs.getString(1);
  +                        System.out.print(", " + col1);
  +                    } catch (ArrayIndexOutOfBoundsException aiobe) {
  +                        System.out.println(", [no col 1]");
  +                    }
  +                    try {
  +                        String col2 = rs.getString(2);
  +                        System.out.print(", " + col2);
  +                    } catch (ArrayIndexOutOfBoundsException aiobe) {
  +                        System.out.println(", [no col 2]");
  +                    }
  +                    System.out.println("");
  +                }
  +                rs.close();
  +            } else {
  +                st.executeUpdate(lxSQL.trim());
  +            }
  +            st.close();
  +            str = end;
  +            end = mLxsql.indexOf("###",end+3);
  +        }
  +
  +        } catch (SQLException sqle) {
  +            System.err.println("-- Failing LXSQL --");
  +            System.err.println(lxSQL);
  +            System.err.println("-------------------");
  +        }
  +
       }
   
       private void close() throws Exception {
  @@ -221,18 +103,17 @@
   
   
       public static void main(String[] args) {
  -        //String fileName = args[0];
  -        //if (fileName != null) {
  -            try {
  -                Tester tester = new Tester();
  -                tester.test();
  -                tester.close();
  -            } catch (Exception e) {
  -                System.out.println("Some problem during running of test : " + e.getMessage());
  -                e.printStackTrace();
  -            }
  -       // } else {
  -        //    System.out.println("Simgle parameter of file name containing SQL statements");
  -        //}
  +        if (args.length == 0) {
  +            System.err.println("First argument should be a script file");
  +        }
  +        String scriptFile = args[0];
  +        try {
  +            Tester tester = new Tester(scriptFile);
  +            tester.test();
  +            tester.close();
  +        } catch (Exception e) {
  +            System.out.println("Some problem during running of test : " + e.getMessage());
  +            e.printStackTrace();
  +        }
       }
   }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/scripts/lxsql/Test1.script
  
  Index: Test1.script
  ===================================================================
  ### CREATE ##!
  
  <create-table name="Flintstones">
    <columns>
      <column name="forename" type="varchar" max="20"/>
      <column name="surname" type="varchar" max="20"/>
      <column name="age" type="integer"/>
    </columns>
  </create-table>
  
  ### INSERT ##!
  
  <insert-into table-name="Flintstones">
    <rows>
      <row>
        <value col="forename">Fred</value>
        <value col="surname">Flintstone</value>
        <value col="age">40</value>
      </row>
      <row>
        <value col="forename">Wilma</value>
        <value col="surname">Flintstone</value>
        <value col="age">38</value>
      </row>
      <row>
        <value col="forename">Barney</value>
        <value col="surname">Rubble</value>
        <value col="age">66</value>
      </row>
      <row>
        <value col="forename">I am going</value>
        <value col="surname">to be deleted</value>
        <value col="age">999</value>
      </row>
    </rows>
  </insert-into>
  
  ### SELECT 0 (all rows) ##!
  
  <simple-select>
     <columns>
      <column name="forename"/>
      <column name="surname"/>
      <column name="age"/>
     </columns>
     <from>
       <table name="Flintstones"/>
     </from>
  </simple-select>
  
  ### SELECT 1 (age>40) ##!
  
  <simple-select>
    <columns>
      <column name="forename"/>
      <column name="surname"/>
    </columns>
    <from>
      <table name="Flintstones"/>
    </from>
    <where>
      <condition expr="age>=40"/>
    </where>
  </simple-select>
  
  ### VIEW 1 (Wilma Flintstone) ##!
  
  <create-view name="FlintstonesView" on="Flintstones">
    <columns>
      <column name="forename" type="varchar" max="20"/>
      <column name="surname" type="varchar" max="20"/>
      <column name="age" type="integer"/>
    </columns>
    <where>
      <and>
        <condition expr="forename=Wilma"/>
        <condition expr="surname=Flintstone"/>
      </and>
    </where>
  </create-view>
  
  ### SELECT 2 (on view) ##!
  
  <simple-select>
    <columns>
      <column name="forename"/>
      <column name="surname"/>
    </columns>
    <from>
      <table name="FlintstonesView"/>
    </from>
  </simple-select>
  
  ### INDEX 1 ##!
  
  <create-index name="FlintstonesIdx" table="Flintstones">
    <columns>
      <column name="forename"/>
      <column name="surname"/>
    </columns>
  </create-index>
  
  ### DELETE 1 (age>100) ##!
  
  <delete-rows from="Flintstones">
    <where>
      <condition expr="age>100"/>
    </where>
  </delete-rows>
  
  ### UPDATE 1 ##!
  
  <update-rows from="Flintstones">
    <updates>
      <set name="surname" value="McRubble"/>
    </updates>
    <where>
      <condition expr="age>60"/>
    </where>
  </update-rows>
  
  ### SELECT 3 (all rows) ##!
  
  <simple-select>
    <columns><column name="forename"/>
    <column name="surname"/></columns>
    <from>
      <table name="Flintstones"/>
    </from>
  </simple-select>
  
  ### VIEW 2 (surname aggregate) ##!
  
  <create-aggregate-view name="FlintstonesAggView" on="Flintstones">
    <grouped-columns>
      <column name="surname" as="lastName"/>
    </grouped-columns>
    <group-function-columns>
      <count as="surCount"/>
      <max as="maxAge" on="age"/>
      <min as="minAge" on="age"/>
      <ave as="aveAge" on="age"/>
      <sum as="sumAge" on="age"/>
    </group-function-columns>
  </create-aggregate-view>
  
  ###
  
  
  

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