froehlich    01/12/02 06:45:57

  Modified:    apps/db/src/java/org/apache/avalon/db/basic/actions
                        TestHelper.java BasicCriteria.java
  Log:
  expressions like col1='Wilma', col2=12334 and col1=122.333
  are now processed correctly!
  
  Revision  Changes    Path
  1.5       +1 -0      
jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/TestHelper.java
  
  Index: TestHelper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/TestHelper.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestHelper.java   2001/12/01 10:49:43     1.4
  +++ TestHelper.java   2001/12/02 14:45:57     1.5
  @@ -18,6 +18,7 @@
   
   /**
    * Helper class for BSF
  + *
    * @author Gerhard Froehlich <a href="mailto:[EMAIL PROTECTED]">[EMAIL 
PROTECTED]</a>
    * @version $Revision: 1.19 $
    */
  
  
  
  1.3       +57 -14    
jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicCriteria.java
  
  Index: BasicCriteria.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicCriteria.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BasicCriteria.java        2001/12/01 17:50:26     1.2
  +++ BasicCriteria.java        2001/12/02 14:45:57     1.3
  @@ -15,15 +15,18 @@
   import org.apache.avalon.db.data.DataException;
   import org.apache.avalon.db.data.Row;
   import org.apache.avalon.db.data.impl.DefaultStringConstantColumn;
  +import org.apache.avalon.db.data.impl.DefaultNumericConstantColumn;
   
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   
  +import org.apache.regexp.RE;
  +import org.apache.regexp.RESyntaxException;
  +
   import java.util.Iterator;
   
   /**
    * Class BasicCriteria
    *
  - *
    * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL 
PROTECTED]</a>
    * @author Gerhard Froehlich <a href="mailto:[EMAIL PROTECTED]">[EMAIL 
PROTECTED]</a>
    * @version $Revision: 1.7 $
  @@ -46,7 +49,7 @@
               setupLogger(this);
               mWhereClause = Criteria;
           } catch (Exception e) {
  -            ////getLogger().error("SimpleWhereClause(..): Exception:",e);
  +            //getLogger().error("SimpleWhereClause(..): Exception:",e);
           }
       }
   
  @@ -73,11 +76,13 @@
       private void testRows(Iterator rowIterator, 
BasicCriteriaMatchingRowCallback callBack) throws RhinoException {
           RhinoHelper rh = new RhinoHelper();
           TestHelper testHelper = new TestHelper();
  -        ColumnCheck columnCheck = new ColumnCheck();
  +        ColumnCheckLeft columnCheckLeft = new ColumnCheckLeft();
  +        ColumnCheckRight columnCheckRight = new ColumnCheckRight();
   
           rh.addBean("iterator",rowIterator);
           rh.addBean("callBack",callBack);
  -        rh.addBean("columnCheck",columnCheck);
  +        rh.addBean("columnCheckLeft",columnCheckLeft);
  +        rh.addBean("columnCheckRight",columnCheckRight);
           rh.addBean("testHelper",testHelper);
           //getLogger().debug("mWhereClause" + mWhereClause.toString());
           String js =
  @@ -116,11 +121,13 @@
           if(!mWhereClause.toString().equals("")) {
               RhinoHelper rh = new RhinoHelper();
               MatchingHelper mh = new MatchingHelper();
  -            ColumnCheck columnCheck = new ColumnCheck();
  +            ColumnCheckRight columnCheckRight = new ColumnCheckRight();
  +            ColumnCheckLeft columnCheckLeft = new ColumnCheckLeft();
   
               rh.addBean("row",row);
               rh.addBean("callBack",mh);
  -            rh.addBean("columnCheck",columnCheck);
  +            rh.addBean("columnCheckRight",columnCheckRight);
  +            rh.addBean("columnCheckLeft",columnCheckLeft);
               TestHelper testHelper = new TestHelper();
               rh.addBean("testHelper",testHelper);
               //getLogger().debug("mWhereClause" + mWhereClause.toString());
  @@ -143,17 +150,53 @@
           }
       }
   
  -    public class ColumnCheck {
  -       public Column getColumn(BasicRow row, String name) {
  -            if(row.getValue(name) == null) {
  -                return getConstantColumn("constantcolumn",name);
  +    public class ColumnCheckRight {
  +        public Column getColumn(String value) throws ActionException {
  +            RE checkString = null;
  +            RE checkInteger = null;
  +            RE checkFloat = null;
  +        
  +            String strtype = "'*'";
  +            String integertype = "([0-9])+";
  +            String floattype = "([0-9])+ . ([0-9])+ | . ([0-9])+";
  +            
  +            try {
  +                checkString = new RE(strtype);
  +                checkInteger = new RE(integertype);
  +                checkFloat = new RE(floattype);
  +            } catch (RESyntaxException ree) {
  +                ree.printStackTrace();
  +            }
  +        
  +            if(checkString.match(value)) {
  +                value = value.substring(1,value.length()-1);
  +                System.out.println("value=" + value);
  +                return getStringConstantColumn("constantcolumn",value);
  +            } else if(checkInteger.match(value)) {
  +                return getNumericConstantColumn("constantcolumn",value);
  +            } else if(checkFloat.match(value)) {       
  +                 return getNumericConstantColumn("constantcolumn",value);
               } else {
  -                return (Column)row.getColumn(name,false);
  +                throw new ActionException("\"" + value + "\" is not valid in 
the context where it is used");
               }
  -       }
  +        }
   
  -       private Column getConstantColumn(String name, String value) {
  +        private Column getStringConstantColumn(String name, String value) {
               return new DefaultStringConstantColumn(name,value);
  -       }
  +        }
  +
  +        private Column getNumericConstantColumn(String name, String value) {
  +            return new DefaultNumericConstantColumn(name,value);
  +        }
  +    }
  +
  +    public class ColumnCheckLeft {
  +        public Column getColumn(BasicRow row, String name) throws 
ActionException {
  +            if(row.getValue(name) == null) {
  +                throw new ActionException("\"" + name + "\" is not valid in 
the context where it is used");
  +            } else {
  +                 return (Column)row.getColumn(name,false);                
  +            }
  +        }
       }
   }
  
  
  

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

Reply via email to