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/java/org/apache/avalon/db/server AbstractRequestHandler.java
Date Sat, 17 Nov 2001 17:04:27 GMT
hammant     01/11/17 09:04:27

  Modified:    apps/db/src/java/org/apache/avalon/db/basic/actions
                        BasicDeleteRows.java BasicUpdateRows.java
               apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql
                        BasicLXSQLDeleteRowsHandler.java
                        BasicLXSQLUpdateRowsHandler.java
               apps/db/src/java/org/apache/avalon/db/basic/parser
                        BasicLXSQLParser.java
               apps/db/src/java/org/apache/avalon/db/data Queryable.java
               apps/db/src/java/org/apache/avalon/db/data/impl
                        AbstractQueryable.java
               apps/db/src/java/org/apache/avalon/db/server
                        AbstractRequestHandler.java
  Added:       apps/db/src/java/org/apache/avalon/db/basic/actions
                        SimpleWhereClause.java
                        SimpleWhereClauseMatchingRowCallback.java
  Log:
  refactor of whereClause processing (start of)
  
  Revision  Changes    Path
  1.2       +22 -9     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicDeleteRows.java
  
  Index: BasicDeleteRows.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicDeleteRows.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BasicDeleteRows.java	2001/11/15 12:40:29	1.1
  +++ BasicDeleteRows.java	2001/11/17 17:04:26	1.2
  @@ -11,22 +11,25 @@
   import org.apache.avalon.db.actions.impl.AbstractAction;
   import org.apache.avalon.db.actions.ActionException;
   import org.apache.avalon.db.actions.DeleteRows;
  -import org.apache.avalon.db.data.Queryable;
  +import org.apache.avalon.db.data.impl.AbstractQueryable;
  +import org.apache.avalon.db.basic.data.BasicRow;
   import org.apache.avalon.framework.logger.LogEnabled;
  -import org.w3c.dom.Document;
   
  +import java.util.Iterator;
   
  +
   /**
    * Class BasicDeleteRows
    *
    *
    * @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 BasicDeleteRows extends AbstractAction implements DeleteRows ,LogEnabled {
  +public class BasicDeleteRows extends AbstractAction
  +        implements DeleteRows, LogEnabled, SimpleWhereClauseMatchingRowCallback {
   
  -    private Document mDocument;
  -    private Queryable mQueryable;
  +    private SimpleWhereClause mWhereClause;
  +    private AbstractQueryable mQueryable;
       private int mRecordCount;
   
       /**
  @@ -37,9 +40,9 @@
        * @param document
        *
        */
  -    public BasicDeleteRows(Queryable queryable, Document document) {
  +    public BasicDeleteRows(AbstractQueryable queryable, SimpleWhereClause whereClause)
{
           mQueryable = queryable;
  -        mDocument = document;
  +        mWhereClause = whereClause;
       }
   
       public void initialize() throws ActionException {
  @@ -53,10 +56,20 @@
        */
       public void execute() throws ActionException {
   
  -        //TODO
  +        Iterator it = mQueryable.getRows().iterator();
  +        mWhereClause.testRows(it, this);
   
       }
   
  +    /**
  +     * Method rowMatches
  +     *
  +     * This is the callback from JavaScript
  +     */
  +    public void rowMatches(BasicRow row) {
  +        mQueryable.deleteRow(row);
  +        mRecordCount++;
  +    }
   
       public int getRecordCount() {
           return mRecordCount;
  
  
  
  1.2       +21 -8     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicUpdateRows.java
  
  Index: BasicUpdateRows.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicUpdateRows.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BasicUpdateRows.java	2001/11/16 06:14:59	1.1
  +++ BasicUpdateRows.java	2001/11/17 17:04:26	1.2
  @@ -11,22 +11,24 @@
   import org.apache.avalon.db.actions.impl.AbstractAction;
   import org.apache.avalon.db.actions.ActionException;
   import org.apache.avalon.db.actions.UpdateRows;
  -import org.apache.avalon.db.data.Queryable;
  +import org.apache.avalon.db.data.impl.AbstractQueryable;
  +import org.apache.avalon.db.basic.data.BasicRow;
   import org.apache.avalon.framework.logger.LogEnabled;
  -import org.w3c.dom.Document;
   
  +import java.util.Iterator;
   
   /**
    * Class BasicUpdateRows
    *
    *
    * @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 BasicUpdateRows extends AbstractAction implements UpdateRows ,LogEnabled {
  +public class BasicUpdateRows extends AbstractAction
  +        implements UpdateRows, LogEnabled, SimpleWhereClauseMatchingRowCallback {
   
  -    private Document mDocument;
  -    private Queryable mQueryable;
  +    private SimpleWhereClause mWhereClause;
  +    private AbstractQueryable mQueryable;
       private int mRecordCount;
   
       /**
  @@ -37,9 +39,9 @@
        * @param document
        *
        */
  -    public BasicUpdateRows(Queryable queryable, Document document) {
  +    public BasicUpdateRows(AbstractQueryable queryable, SimpleWhereClause whereClause)
{
           mQueryable = queryable;
  -        mDocument = document;
  +        mWhereClause = whereClause;
       }
   
       public void initialize() throws ActionException {
  @@ -53,10 +55,21 @@
        */
       public void execute() throws ActionException {
   
  -        //TODO
  +        Iterator it = mQueryable.getRows().iterator();
  +        mWhereClause.testRows(it, this);
   
       }
   
  +    /**
  +     * Method rowMatches
  +     *
  +     * This is the callback from JavaScript
  +     */
  +    public void rowMatches(BasicRow row) {
  +        // TODO all the setting of columns
  +        mQueryable.rowChanged(row);
  +        mRecordCount++;
  +    }
   
       public int getRecordCount() {
           return mRecordCount;
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/SimpleWhereClause.java
  
  Index: SimpleWhereClause.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.basic.data.BasicRow;
  import org.apache.avalon.db.actions.ActionException;
  import org.apache.avalon.db.utils.RhinoHelper;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  
  import java.util.Iterator;
  
  /**
   * Class SimpleWhereClause
   *
   *
   * @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.1 $
   */
  public class SimpleWhereClause extends AbstractLogEnabled {
      private String mWhereClause;
  
      public SimpleWhereClause(String whereClause) {
          this.mWhereClause = whereClause;
      }
  
      public String getWhereClause() {
          return mWhereClause;
      }
  
      public void testRows(Iterator rowIterator, SimpleWhereClauseMatchingRowCallback callBack)
throws ActionException {
          RhinoHelper rh = new RhinoHelper();
          rh.addBean("iterator",rowIterator);
          rh.addBean("callback",callBack);
          rh.addBean("my",this); // TODO replace "my" with pointer to helper bean.
          getLogger().debug("mWhereClause" + mWhereClause.toString());
          String js =
              "while(iterator.hasNext()) {" +
                 "var row = it.next();" +
                 "if ( " + mWhereClause + " ) {" +
                    "callBack.rowMatches(row);" +
                 "}" +
              "}";
          rh.executeAction(js);
      }
  
      public boolean testRow(BasicRow row) throws ActionException {
          if(!mWhereClause.toString().equals("")) {
              RhinoHelper rh = new RhinoHelper();
              MatchingHelper mh = new MatchingHelper();
              rh.addBean("row",row);
              rh.addBean("callback",mh);
              rh.addBean("my",this); // TODO replace "my" with pointer to helper bean.
              getLogger().debug("mWhereClause" + mWhereClause.toString());
              rh.executeAction("if (" + mWhereClause.toString() + ") { rc.itDidMatch(true);
} ");
              return mh.matched;
          } else {
              return true;
          }
      }
      public class MatchingHelper implements SimpleWhereClauseMatchingRowCallback {
          public boolean matched = false;
          public void rowMatches(BasicRow row) {
              matched = true;
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/SimpleWhereClauseMatchingRowCallback.java
  
  Index: SimpleWhereClauseMatchingRowCallback.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.basic.data.BasicRow;
  
  /**
   * Class SimpleWhereClauseMatchingRowCallback
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public interface SimpleWhereClauseMatchingRowCallback {
  
      void rowMatches(BasicRow row);
  }
  
  
  
  1.3       +9 -2      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/BasicLXSQLDeleteRowsHandler.java
  
  Index: BasicLXSQLDeleteRowsHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/BasicLXSQLDeleteRowsHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BasicLXSQLDeleteRowsHandler.java	2001/11/16 06:14:59	1.2
  +++ BasicLXSQLDeleteRowsHandler.java	2001/11/17 17:04:26	1.3
  @@ -12,6 +12,7 @@
   
   import org.apache.avalon.db.basic.parser.BasicLXSQLParser;
   import org.apache.avalon.db.basic.actions.BasicDeleteRows;
  +import org.apache.avalon.db.basic.actions.SimpleWhereClause;
   import org.apache.avalon.db.services.DatabasePersistor;
   import org.apache.avalon.db.transport.Reply;
   import org.apache.avalon.db.transport.Request;
  @@ -20,6 +21,7 @@
   import org.apache.avalon.db.actions.ActionException;
   import org.apache.avalon.db.actions.DeleteRows;
   import org.apache.avalon.db.data.Queryable;
  +import org.apache.avalon.db.data.impl.AbstractQueryable;
   
   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
  @@ -30,7 +32,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public class BasicLXSQLDeleteRowsHandler extends BasicLXSQLHandler {
   
  @@ -65,7 +67,12 @@
           Element rootElement = doc.getDocumentElement();
           String queryableStr = rootElement.getAttribute("from");
           Queryable queryable = (Queryable) mDatabasePersistor.getQueryable(queryableStr);
  -        DeleteRows action = new BasicDeleteRows(queryable, doc);
  +
  +        SimpleWhereClause swc = new SimpleWhereClause("TODO");
  +        swc.enableLogging(super.getLogger());
  +
  +
  +        DeleteRows action = new BasicDeleteRows((AbstractQueryable) queryable, swc);
   
           mParser.initializeAction(action);
           action.execute();
  
  
  
  1.2       +8 -2      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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BasicLXSQLUpdateRowsHandler.java	2001/11/16 06:14:59	1.1
  +++ BasicLXSQLUpdateRowsHandler.java	2001/11/17 17:04:27	1.2
  @@ -12,6 +12,7 @@
   
   import org.apache.avalon.db.basic.parser.BasicLXSQLParser;
   import org.apache.avalon.db.basic.actions.BasicUpdateRows;
  +import org.apache.avalon.db.basic.actions.SimpleWhereClause;
   import org.apache.avalon.db.services.DatabasePersistor;
   import org.apache.avalon.db.transport.Reply;
   import org.apache.avalon.db.transport.Request;
  @@ -20,6 +21,7 @@
   import org.apache.avalon.db.actions.ActionException;
   import org.apache.avalon.db.actions.UpdateRows;
   import org.apache.avalon.db.data.Queryable;
  +import org.apache.avalon.db.data.impl.AbstractQueryable;
   
   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
  @@ -30,7 +32,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 BasicLXSQLUpdateRowsHandler extends BasicLXSQLHandler {
   
  @@ -65,7 +67,11 @@
           Element rootElement = doc.getDocumentElement();
           String queryableStr = rootElement.getAttribute("from");
           Queryable queryable = (Queryable) mDatabasePersistor.getQueryable(queryableStr);
  -        UpdateRows action = new BasicUpdateRows(queryable, doc);
  +
  +        SimpleWhereClause swc = new SimpleWhereClause("TODO");
  +        swc.enableLogging(super.getLogger());
  +
  +        UpdateRows action = new BasicUpdateRows((AbstractQueryable) queryable, swc);
   
           mParser.initializeAction(action);
           action.execute();
  
  
  
  1.16      +8 -0      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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- BasicLXSQLParser.java	2001/11/16 06:14:59	1.15
  +++ BasicLXSQLParser.java	2001/11/17 17:04:27	1.16
  @@ -49,6 +49,14 @@
           handlers[Request.SELECTSIMPLE] = new BasicLXSQLSelectSimpleHandler(this,mDatabasePersistor);
           handlers[Request.UPDATEROWS] = new BasicLXSQLUpdateRowsHandler(this,mDatabasePersistor);
   
  +        // decorate them with logging capability.
  +        for (int i = 0; i < handlers.length; i++) {
  +            if (handlers[i] != null) {
  +                handlers[i].enableLogging(super.getLogger());
  +            }
  +        }
  +
  +
           //TODO more
           return handlers;
       }
  
  
  
  1.3       +2 -1      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/Queryable.java
  
  Index: Queryable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/Queryable.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Queryable.java	2001/11/12 15:09:04	1.2
  +++ Queryable.java	2001/11/17 17:04:27	1.3
  @@ -8,6 +8,7 @@
    */
   package org.apache.avalon.db.data;
   
  +import java.util.Collection;
   
   
   /**
  @@ -15,7 +16,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version * $Revision: 1.2 $
  + * @version * $Revision: 1.3 $
    */
   public interface Queryable extends Nameable, Cataloged {
       Column[] getColumns();
  
  
  
  1.5       +13 -1     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/AbstractQueryable.java
  
  Index: AbstractQueryable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/AbstractQueryable.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractQueryable.java	2001/11/12 22:14:29	1.4
  +++ AbstractQueryable.java	2001/11/17 17:04:27	1.5
  @@ -26,7 +26,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 abstract class AbstractQueryable extends AbstractNameable implements Queryable {
   
  @@ -84,8 +84,20 @@
           AbstractTableRow atr = (AbstractTableRow) row;
           mRows.add(atr);
           atr.setAbstractQueryable(this);
  +        this.notifyRowListenersAdded(new Row[] {row});
  +    }
   
  +    public void deleteRow(Row row) {
  +        AbstractTableRow atr = (AbstractTableRow) row;
  +        mRows.remove(atr);
  +        this.notifyRowListenersDeleted(new Row[] {row});
  +        atr.setAbstractQueryable(null);
       }
  +
  +    public void rowChanged(Row row) {
  +        this.notifyRowListenersChanged(new Row[] {row});
  +    }
  +
   
       public void addRowListener(RowListener rowListener) {
           mListeners.add(new WeakReference(rowListener));
  
  
  
  1.2       +2 -1      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/server/AbstractRequestHandler.java
  
  Index: AbstractRequestHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/server/AbstractRequestHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractRequestHandler.java	2001/11/15 14:29:57	1.1
  +++ AbstractRequestHandler.java	2001/11/17 17:04:27	1.2
  @@ -12,8 +12,9 @@
   import org.apache.avalon.db.transport.Reply;
   import org.apache.avalon.db.actions.Action;
   import org.apache.avalon.db.actions.ActionException;
  +import org.apache.avalon.framework.logger.AbstractLogEnabled;
   
  -public abstract class AbstractRequestHandler {
  +public abstract class AbstractRequestHandler extends AbstractLogEnabled  {
   
       public abstract Reply handleRequest(Request request) throws ActionException;
   
  
  
  

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