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 Fri, 09 Nov 2001 17:42:28 GMT
hammant     01/11/09 09:42:28

  Modified:    apps/db  build.xml
               apps/db/src/java/org/apache/avalon/db/basic/actions
                        BasicInsert.java BasicSelect.java
               apps/db/src/java/org/apache/avalon/db/basic/data
                        BasicTable.java
               apps/db/src/java/org/apache/avalon/db/basic/parser
                        BasicLXSQLParser.java
               apps/db/src/java/org/apache/avalon/db/test Tester.java
  Log:
  Javascript select
  
  Revision  Changes    Path
  1.14      +2 -0      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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- build.xml	2001/11/05 12:46:54	1.13
  +++ build.xml	2001/11/09 17:42:27	1.14
  @@ -153,6 +153,8 @@
   
         <lib dir="lib">
           <include name="bcel.jar"/>
  +        <include name="bsf.jar"/>
  +        <include name="js.jar"/>
         </lib>
   
         <lib dir="../../build/lib/" >
  
  
  
  1.2       +25 -28    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BasicInsert.java	2001/11/07 13:28:35	1.1
  +++ BasicInsert.java	2001/11/09 17:42:27	1.2
  @@ -8,20 +8,15 @@
    */
   package org.apache.avalon.db.basic.actions;
   
  +import org.apache.avalon.db.actions.impl.AbstractAction;
   import org.apache.avalon.db.actions.Insert;
   import org.apache.avalon.db.actions.ActionException;
  -import org.apache.avalon.db.actions.impl.AbstractAction;
  -
  -import org.apache.avalon.db.data.impl.AbstractTableRow;
  -import org.apache.avalon.db.data.Column;
   import org.apache.avalon.db.basic.data.BasicTable;
   import org.apache.avalon.db.basic.data.BasicRow;
   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
   import org.w3c.dom.NodeList;
   
  -import java.lang.reflect.Method;
  -import java.lang.reflect.InvocationTargetException;
   import java.util.Vector;
   
   
  @@ -65,10 +60,6 @@
           System.out.println("mTable=" + mTable);
           System.out.println("mDocument=" + mDocument);
   
  -        Column[] columns = mTable.getColumns();
  -        int colCount = columns.length;
  -        Object[] values = new Object[colCount];
  -
           Element rootElement = mDocument.getDocumentElement();
   
           NodeList subRootNodes = rootElement.getChildNodes();
  @@ -76,22 +67,27 @@
           for (int f = 0 ; f < subRootNodes.getLength(); f++) {
               if (subRootNodes.item(f).getNodeName().equals("rows")) {
                   NodeList subRowsNodes = subRootNodes.item(f).getChildNodes();
  -                Vector row = new Vector();
  -                for (int x = 0 ; x < subRowsNodes.getLength(); x++) {
  -                    if (subRowsNodes.item(x).getNodeName().equals("row")) {
  -                        mRecordCount++;
  -                        NodeList subRowNodes = subRootNodes.item(f).getChildNodes();
  -                        for (int y = 0 ; y < subRowNodes.getLength(); y++) {
  -                            if (subRowNodes.item(y).getNodeName().equals("value")) {
  -                                Element rowNode = (Element) subRowNodes.item(y);
  -                                String colName = rowNode.getAttribute("column");
  -                                String valueStr = rowNode.getNodeValue();
  -                                int ix = mTable.getColumnIndex(colName);
  -                                values[x] = valueStr;
  -                            }
  -                        }
  -                    } else {
  -                        // TODO
  +                processSubRowsNodes(subRowsNodes);
  +            } else {
  +                //TODO
  +            }
  +        }
  +    }
  +
  +    private void processSubRowsNodes(NodeList subRowsNodes) {
  +        Object[] values = new Object[mTable.getColumns().length];
  +        for (int x = 0 ; x < subRowsNodes.getLength(); x++) {
  +            if (subRowsNodes.item(x).getNodeName().equals("row")) {
  +                mRecordCount++;
  +                NodeList subRowNodes = subRowsNodes.item(x).getChildNodes();
  +                for (int y = 0 ; y < subRowNodes.getLength(); y++) {
  +                    if (subRowNodes.item(y).getNodeName().equals("value")) {
  +                        Element rowNode = (Element) subRowNodes.item(y);
  +                        String colName = rowNode.getAttribute("col");
  +
  +                        String valueStr = rowNode.getNodeValue();
  +                        int ix = mTable.getColumnIndex(colName);
  +                        values[ix] = valueStr;
                       }
                   }
                   Vector pendingRow = new Vector();
  @@ -101,14 +97,15 @@
                       } else {
                           pendingRow.add(values[q]);
                       }
  -
                   }
                   mTable.addRow(new BasicRow(mTable,pendingRow));
               } else {
  -                //TODO
  +                // TODO
               }
           }
  +
       }
  +
   
       public int getRecordCount() {
           return mRecordCount;
  
  
  
  1.6       +20 -8     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicSelect.java
  
  Index: BasicSelect.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicSelect.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BasicSelect.java	2001/11/09 16:35:56	1.5
  +++ BasicSelect.java	2001/11/09 17:42:27	1.6
  @@ -7,29 +7,27 @@
    */
   package org.apache.avalon.db.basic.actions;
   
  +import org.apache.avalon.db.actions.impl.AbstractAction;
   import org.apache.avalon.db.actions.Select;
   import org.apache.avalon.db.actions.ParameterAdaptable;
   import org.apache.avalon.db.actions.ActionException;
  -import org.apache.avalon.db.actions.impl.AbstractAction;
  -import org.apache.avalon.db.data.impl.AbstractTableRow;
   import org.apache.avalon.db.results.RowSet;
   import org.apache.avalon.db.results.Columns;
   import org.apache.avalon.db.basic.data.BasicTable;
  -import org.apache.avalon.db.basic.results.BasicRowSet;
   import org.apache.avalon.db.basic.results.BasicColumns;
  +import org.apache.avalon.db.basic.results.BasicRowSet;
   import org.apache.avalon.db.utils.RhinoHelper;
   import org.w3c.dom.Element;
   import org.w3c.dom.NodeList;
   
  -import java.lang.reflect.Method;
  -import java.lang.reflect.InvocationTargetException;
   import java.util.Vector;
   import java.util.Iterator;
  -import java.sql.SQLException;
   
  +
   /**
    * This class represents a the BasicSelect action impl.
    * @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
    */
   public class BasicSelect extends AbstractAction implements Select,ParameterAdaptable {
  @@ -57,13 +55,14 @@
           StringBuffer strbuf = new StringBuffer();
           Vector selectedRows = new Vector();
           //Rhino makes problems...causes EOFException...
  -        //RhinoHelper = new RhinoHelper();
           BasicTable table = null;
           String tablename = "";
           try {
               NodeList subRootNodes = mRootElement.getChildNodes();
               /** traverse the dom tree */
               System.out.println("traverse the dom tree");
  +            boolean where = false;
  +            String whereExpr = "";
               for (int i = 0 ; i < subRootNodes.getLength(); i++) {
                   if (subRootNodes.item(i).getNodeName().equals("columns")) {
                       //TODO process colums and store them temporary for
  @@ -79,13 +78,26 @@
                               table = (BasicTable) mDatabasePersistor.getTable(tablename);
                           }
                       }
  +                } else if (subRootNodes.item(i).getNodeName().equals("where")) {
  +                    where = true;
                   } //implement where clause
               }
  +            if (!where) {
  +                whereExpr = "(true)";
  +            }
   
               Iterator it = table.getRows().iterator();
               while (it.hasNext()) {
  -                selectedRows.add(it.next());
  +                System.out.println("Row test");
  +                RhinoHelper rh = new RhinoHelper();
  +                rh.addBean("row", it.next());
  +                rh.addBean("selectedRows", selectedRows);
  +                String jsString = "if " + whereExpr + " { selectedRows.addElement(row);
}";
  +                System.out.println("jsString " + jsString);
  +                rh.executeAction(jsString);
               }
  +            System.out.println("selectedRows size " + selectedRows.size());
  +
               mColumns = new BasicColumns();
               mRowSet = new BasicRowSet(mColumns,selectedRows);
           } catch (Exception e) {
  
  
  
  1.4       +1 -0      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BasicTable.java	2001/11/07 13:28:35	1.3
  +++ BasicTable.java	2001/11/09 17:42:27	1.4
  @@ -23,6 +23,7 @@
                   return x;
               }
           }
  +        System.out.println("Whoa " + columnName + " not found");
           return -1;
       }
   
  
  
  
  1.8       +0 -4      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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- BasicLXSQLParser.java	2001/11/09 15:03:20	1.7
  +++ BasicLXSQLParser.java	2001/11/09 17:42:27	1.8
  @@ -106,11 +106,7 @@
           Document doc = parseLXSQLString(request.getSql());
           Element rootElement = doc.getDocumentElement();
           String tableName = rootElement.getAttribute("table-name");
  -
  -        System.out.println("mDatabasePersistor" + mDatabasePersistor);
  -        System.out.println("=tn=" + tableName);
           BasicTable table = (BasicTable) mDatabasePersistor.getTable(tableName);
  -        System.out.println("=table=" + table);
           Insert action = new BasicInsert(table, doc);
           action.setDatabasePersistor(mDatabasePersistor);
   
  
  
  
  1.9       +16 -4     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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Tester.java	2001/11/09 16:13:18	1.8
  +++ Tester.java	2001/11/09 17:42:28	1.9
  @@ -42,15 +42,15 @@
           String insertInto = "<insert-into table-name=\"Flintstones\">" +
                                  "<rows>" +
                                    "<row>" +
  -                                   "<value col=\"forname\">Fred</value>" +
  +                                   "<value col=\"forename\">Fred</value>" +
                                      "<value col=\"surname\">Flintsone</value>"
+
                                    "</row>" +
                                    "<row>" +
  -                                   "<value col=\"forname\">Wilma</value>" +
  +                                   "<value col=\"forename\">Wilma</value>"
+
                                      "<value col=\"surname\">Flintsone</value>"
+
                                    "</row>" +
                                    "<row>" +
  -                                   "<value col=\"forname\">Barney</value>"
+
  +                                   "<value col=\"forename\">Barney</value>"
+
                                      "<value col=\"surname\">Rubble</value>"
+
                                    "</row>" +
                                  "</rows>" +
  @@ -58,7 +58,7 @@
           st.executeUpdate(insertInto);
           st.close();
   
  -        System.err.println("SELECT");
  +        System.err.println("SELECT 1");
           st = mCon.createStatement();
           String select = "<simple-select>" +
                               "<columns>*</columns>" +
  @@ -67,6 +67,18 @@
   
           st.executeQuery(select);
           st.close();
  +
  +        System.err.println("SELECT 2"); //TODO
  +        st = mCon.createStatement();
  +        String select2 = "<simple-select>" +
  +                            "<columns>*</columns>" +
  +                            "<from><table name=\"Flintstones\"/></from>"
+
  +                            "<where><and-block/></where>" +
  +                        "</simple-select>";
  +
  +        st.executeQuery(select2);
  +        st.close();
  +
   
       }
   
  
  
  

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