froehlich    01/11/14 07:54:19

  Modified:    apps/db/src/java/org/apache/avalon/db/basic/actions
                        BasicSelect.java
  Log:
  working on where statement
  
  Revision  Changes    Path
  1.21      +36 -5     
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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- BasicSelect.java  2001/11/13 17:25:56     1.20
  +++ BasicSelect.java  2001/11/14 15:54:18     1.21
  @@ -18,6 +18,7 @@
   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.apache.avalon.db.utils.StringUtils;
   import org.apache.avalon.db.data.ValidationException;
   
   import org.apache.avalon.framework.logger.LogEnabled;
  @@ -27,6 +28,7 @@
   
   import java.util.Vector;
   import java.util.Iterator;
  +import java.util.StringTokenizer;
   
   
   /**
  @@ -48,6 +50,12 @@
       private String[] mCols;
       private String[] mTablenames;
   
  +    final static String OPERATORS[][] = {
  +                                            {"=","<",">","<>","like"},
  +                                            
{"mequals","smaller","greater","unequal","like"}
  +                                         };
  +
  +
       /**
        * The Constructor
        *
  @@ -113,7 +121,9 @@
               RhinoHelper rh = new RhinoHelper();
               Matched rc = new Matched();
               rh.addBean("row",row);
  +            rh.addBean("my",this);
               rh.addBean("rc",rc);
  +            getLogger().debug("mWhereBuffer.toString()" + 
mWhereBuffer.toString());
               rh.executeAction("if (" + mWhereBuffer.toString() + ") { 
rc.itDidMatch(); } ");
               return rc.didItMatch();
           } else {
  @@ -123,8 +133,8 @@
   
       public class Matched {
           private boolean boolval = false;
  -        public void itDidMatch() {
  -            boolval = true;
  +        public void itDidMatch(boolean b) {
  +            boolval = b;
           }
           boolean didItMatch() {
               return boolval;
  @@ -181,8 +191,6 @@
           }
           mWhereBuffer = whereBuffer;
           getLogger().debug("sb=[\n" + whereBuffer + "\n]");
  -
  -
       }
   
       private String[] parseSelect(Element rootElement) throws ActionException 
{
  @@ -280,7 +288,7 @@
           try {
               getLogger().debug("parseWhereConditionTerm(): found condition");
               //Node nextSibling = (Node)element.getNextSibling();
  -            sb.append(getIndent(indent) + element.getAttribute("expr") + 
"\n");
  +            sb.append(getIndent(indent) + 
composeExpr(element.getAttribute("expr")) + "\n");
               //parseWhereTerm((Element)nextSibling,sb);
           } catch(Exception e) {
               e.printStackTrace();
  @@ -295,9 +303,32 @@
           return rval;
       }
   
  +    private String composeExpr(String expr) {
  +        String[] strarr = null;
  +        String[] result = null;
  +        String method = null;
  +
  +        for (int i=0; i<OPERATORS.length; i++) {
  +            strarr = StringUtils.split(expr,OPERATORS[0][i]);
  +            if(strarr.length > 1) {
  +                method = OPERATORS[i+1][0];
  +                result = strarr;
  +            }
  +        }
  +        method = "my." + method + "(row.getValue(\"" + result[0] + "\"),\"" 
+ result[1] + "\")";
  +        getLogger().debug("method=" + method);
  +        return method;
  +    }
  +
   
       private NodeList getSubRootNodes(Element rootElement) {
           return rootElement.getChildNodes();
  +    }
  +
  +    public boolean mequals(String leftexpr,String rightexpr) {
  +        getLogger().debug("leftexpr=" + leftexpr);
  +        getLogger().debug("rightexpr=" + rightexpr);
  +        return leftexpr.equals(rightexpr);
       }
   
       public void execute(Object[] params) throws ActionException {
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to