hammant 01/11/13 05:01:24 Modified: apps/db/src/java/org/apache/avalon/db/basic/actions BasicSelect.java apps/db/src/java/org/apache/avalon/db/test Tester.java Log: where selection now reducing resultset Revision Changes Path 1.14 +32 -15 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.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- BasicSelect.java 2001/11/13 12:12:44 1.13 +++ BasicSelect.java 2001/11/13 13:01:24 1.14 @@ -17,14 +17,10 @@ import org.apache.avalon.db.basic.data.BasicRow; import org.apache.avalon.db.basic.results.BasicColumns; import org.apache.avalon.db.basic.results.BasicRowSet; -import org.apache.avalon.db.basic.parser.BasicLXSQLParser; import org.apache.avalon.db.utils.RhinoHelper; -import org.apache.avalon.db.transport.SelectRequest; import org.apache.avalon.db.data.ValidationException; -import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; -import org.w3c.dom.Node; import java.util.Vector; import java.util.Iterator; @@ -62,7 +58,6 @@ StringBuffer strbuf = new StringBuffer(); Vector selectedRows = new Vector(); BasicTable table = null; - RhinoHelper rh = new RhinoHelper(); String[] cols; String[] tablenames; Object[] selectedrow = null; @@ -88,18 +83,20 @@ while(it.hasNext()) { /** iterate rows and select only the needed cols */ BasicRow row = (BasicRow)it.next(); - if(((String)cols[0]).equals("*")) { - selectedrow = new Object[row.getColumsLength()]; - for (int j=0; j < cols.length; j++) { - selectedrow[j] = row.getValue(j); - } - } else { - selectedrow = new Object[cols.length]; - for (int j=0; j < cols.length; j++) { - selectedrow[j] = row.getValue(j); + if (testRow(row)) { + if(((String)cols[0]).equals("*")) { + selectedrow = new Object[row.getColumsLength()]; + for (int j=0; j < cols.length; j++) { + selectedrow[j] = row.getValue(j); + } + } else { + selectedrow = new Object[cols.length]; + for (int j=0; j < cols.length; j++) { + selectedrow[j] = row.getValue(j); + } } + selectedRows.add(selectedrow); } - selectedRows.add(selectedrow); } } mColumns = new BasicColumns(); @@ -108,6 +105,26 @@ } } + + public boolean testRow(BasicRow row) throws ActionException { + RhinoHelper rh = new RhinoHelper(); + Matched rc = new Matched(); + rh.addBean("row",row); + rh.addBean("rc",rc); + rh.executeAction("if (" + mWhereBuffer.toString() + ") { rc.itDidMatch(); } "); + return rc.didItMatch(); + } + + public class Matched { + private boolean boolval = false; + public void itDidMatch() { + boolval = true; + } + boolean didItMatch() { + return boolval; + } + } + private boolean checkSelectStructure(Element rootElement) { NodeList subRootNodes = mRootElement.getChildNodes(); 1.15 +2 -2 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.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- Tester.java 2001/11/13 12:12:45 1.14 +++ Tester.java 2001/11/13 13:01:24 1.15 @@ -69,8 +69,8 @@ "<from><table name=\"Flintstones\"/></from>" + "<where>" + "<and>" + - "<condition expr=\"row.getColumn('forename').startsWith('F')\"/>" + //TODO this is too Java - "<condition expr=\"row.getColumn('forename').length() > 3\"/>" + //TODO this is too Java + "<condition expr=\"row.getValue('forename').startsWith('F')\"/>" + //TODO this is too Java + "<condition expr=\"row.getValue('forename').length() > 3\"/>" + //TODO this is too Java "</and>" + "</where>" + "</simple-select>";
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>