froehlich 01/11/13 08:05:06
Modified: apps/db/src/java/org/apache/avalon/db/basic/actions
BasicSelect.java
Log:
fixed some things to get a simple select without where working
Revision Changes Path
1.19 +43 -42
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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- BasicSelect.java 2001/11/13 15:28:02 1.18
+++ BasicSelect.java 2001/11/13 16:05:06 1.19
@@ -62,8 +62,8 @@
mCols = parseSelect(mRootElement);
mTablenames = parseFrom(mRootElement);
parseLXSQL(mRootElement);
- System.out.println("cols.length=" + mCols.length);
- System.out.println("tablenames.length=" + mTablenames.length);
+ getLogger().debug("cols.length=" + mCols.length);
+ getLogger().debug("tablenames.length=" + mTablenames.length);
}
/**
@@ -75,45 +75,46 @@
Object[] selectedRow = null;
selectedRows = new Vector();
- if(true) {
- /** without where all rows */
- for(int i=0; i < mTablenames.length; i++) {
- /** get the table, should be only one */
- mTable =
(BasicTable)mDatabasePersistor.getQueryable(mTablenames[i]);
- Iterator it = mTable.getRows().iterator();
- while(it.hasNext()) {
- /** iterate rows and select only the needed cols */
- BasicRow row = (BasicRow)it.next();
- if (testRow(row)) {
- if(((String)mCols[0]).equals("*")) {
- selectedRow = new Object[row.getColumsLength()];
- for (int j=0; j < row.getColumsLength(); j++) {
- selectedRow[j] = row.getValue(j);
- }
- } else {
- selectedRow = new Object[mCols.length];
- for (int j=0; j < mCols.length; j++) {
- selectedRow[j] = row.getValue(mCols[j]);
- }
+ for(int i=0; i < mTablenames.length; i++) {
+ /** get the table, should be only one */
+ mTable = (BasicTable)mDatabasePersistor.getQueryable(mTablenames[i]);
+ Iterator it = mTable.getRows().iterator();
+ while(it.hasNext()) {
+ /** iterate rows and select only the needed cols */
+ BasicRow row = (BasicRow)it.next();
+ if (testRow(row)) {
+ if(((String)mCols[0]).equals("*")) {
+ selectedRow = new Object[row.getColumsLength()];
+ for (int j=0; j < row.getColumsLength(); j++) {
+ selectedRow[j] = row.getValue(j);
}
- selectedRows.add(selectedRow);
+ } else {
+ selectedRow = new Object[mCols.length];
+ for (int j=0; j < mCols.length; j++) {
+ selectedRow[j] = row.getValue(mCols[j]);
+ }
}
+ selectedRows.add(selectedRow);
}
}
+ getLogger().debug("selectedRows.size()=" + selectedRows.size());
mColumns = new BasicColumns();
mRowSet = new BasicRowSet(mColumns,selectedRows);
- } else {
-
}
}
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();
+ //Just for debug
+ if(!mWhereBuffer.toString().equals("")) {
+ 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();
+ } else {
+ return true;
+ }
}
public class Matched {
@@ -175,7 +176,7 @@
throw new ActionException("Validation Exception: " + ve.getMessage());
}
mWhereBuffer = whereBuffer;
- System.out.println("sb=[\n" + whereBuffer + "\n]");
+ getLogger().debug("sb=[\n" + whereBuffer + "\n]");
}
@@ -226,32 +227,32 @@
private void parseWhereTerm(Element element, StringBuffer sb, int indent)
throws ValidationException {
if(element != null) {
- System.out.println("Element != null " + element);
+ getLogger().debug("Element != null " + element);
if(element.getTagName().equals("and")) {
- System.out.println("parseWhereTerm(): found and");
+ getLogger().debug("parseWhereTerm(): found and");
parseWhereAndOrTerm(element.getChildNodes(),sb, indent, "&");
} else if(element.getTagName().equals("or")) {
- System.out.println("parseWhereTerm(): found or");
+ getLogger().debug("parseWhereTerm(): found or");
parseWhereAndOrTerm(element.getChildNodes(),sb, indent, "|");
} else if(element.getTagName().equals("condition")) {
- System.out.println("parseWhereTerm(): found condition");
+ getLogger().debug("parseWhereTerm(): found condition");
parseWhereConditionTerm(element,sb,indent);
} else {
throw new ValidationException("Unknown where term " +
element.getTagName());
}
} else {
- System.out.println("Element == null " + element);
- System.out.println("parseWhereTerm after if");
+ getLogger().debug("Element == null " + element);
+ getLogger().debug("parseWhereTerm after if");
throw new ValidationException("Null where element");
}
- System.out.println("parseWhereTerm at the end");
+ getLogger().debug("parseWhereTerm at the end");
}
private void parseWhereAndOrTerm(NodeList nodes, StringBuffer sb, int indent,
String andOr) {
sb.append(getIndent(indent) + "(\n");
try {
for(int i=0; i<nodes.getLength(); i++) {
- System.out.println("Looping and/or");
+ getLogger().debug("Looping and/or");
parseWhereTerm((Element)nodes.item(i),sb, indent +1);
if (i+1 < nodes.getLength()) {
sb.append( getIndent(indent) + andOr + "\n");
@@ -266,7 +267,7 @@
private void parseWhereConditionTerm(Element element, StringBuffer sb, int
indent) {
try {
- System.out.println("parseWhereConditionTerm(): found condition");
+ getLogger().debug("parseWhereConditionTerm(): found condition");
//Node nextSibling = (Node)element.getNextSibling();
sb.append(getIndent(indent) + element.getAttribute("expr") + "\n");
//parseWhereTerm((Element)nextSibling,sb);
@@ -289,7 +290,7 @@
}
public void execute(Object[] params) throws ActionException {
- System.out.println("select execute prepared");
+ getLogger().debug("select execute prepared");
}
public void setPrepared(boolean b) {
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>