froehlich 01/11/14 11:04:51 Modified: apps/db/src/java/org/apache/avalon/db/basic/actions BasicSelect.java Log: equal is working now Revision Changes Path 1.24 +70 -38 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.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- BasicSelect.java 2001/11/14 17:05:32 1.23 +++ BasicSelect.java 2001/11/14 19:04:51 1.24 @@ -28,11 +28,8 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; -import java.util.Vector; -import java.util.Iterator; -import java.util.StringTokenizer; +import java.util.*; - /** * This class represents a the BasicSelect action impl. * @author Gerhard Froehlich <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> @@ -41,6 +38,7 @@ */ public class BasicSelect extends AbstractAction implements Select,ParameterAdaptable,LogEnabled { + private static Hashtable mOperators; private RowSet mRowSet; private Columns mColumns; private Element mRootElement; @@ -51,11 +49,16 @@ private BasicTable mTable = null; private Column[] mCols; private String[] mTablenames; - - final static String OPERATORS[][] = { - {"=","<",">","<>","like"}, - {"mequals","smaller","greater","unequal","like"} - }; + static { + mOperators = new Hashtable(); + addOperator("=","mequal"); + addOperator(">","greater"); + addOperator("<","smaller"); + addOperator("<>","unequal"); + } + private static void addOperator(String operator, String method) { + mOperators.put(operator,method); + } /** @@ -98,7 +101,7 @@ for (int j=0; j < mCols.length; j++) { getLogger().debug("mCols[" + j + "]=" + mCols[j]); Object o = mCols[j].getValue(row); - getLogger().debug("mCols[j].getValue(row) j=" + j + ", " + o ); + getLogger().debug("row.getValue(mCols[" + j + "]=" + o); selectedRow[j] = o; } selectedRows.add(selectedRow); @@ -276,7 +279,6 @@ sb.append(getIndent(indent) + ")\n"); } - private void parseWhereConditionTerm(Element element, StringBuffer sb, int indent) { try { getLogger().debug("parseWhereConditionTerm(): found condition"); @@ -300,30 +302,77 @@ 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; + String operator = null; + getLogger().debug("expr=" + expr); + try { + Enumeration enum = mOperators.keys(); + while(enum.hasMoreElements()) { + operator = (String)enum.nextElement(); + getLogger().debug("matching operator = " + operator); + getLogger().debug("matching function = " + mOperators.get(operator)); + StringTokenizer strtok = new StringTokenizer(expr,operator); + strarr = new String[strtok.countTokens()]; + int cnt = 0; + while(strtok.hasMoreElements()) { + String s = (String)strtok.nextElement(); + getLogger().debug("s=" + s); + strarr[cnt] = s; + cnt++; + } + if(strarr.length > 1) { + method = (String)mOperators.get(operator); + getLogger().debug("matched function = " + method); + result = strarr; + } } + method = "my." + method + "(row.getValue(\"" + result[0] + "\"),\"" + result[1] + "\")"; + getLogger().debug("method=" + method); + } catch (Exception e) { + getLogger().error("composeExpr(): Exception",e); } - 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) { + protected Column[] convertColumns(String[] columnNames) { + BasicTable table = (BasicTable)mDatabasePersistor.getQueryable(mTablenames[0]); + //TODO * could be with other contrived columns + if (columnNames[0].equals("*")) { + return table.getColumns(); + } + + Column[] columns = new Column[columnNames.length]; + for ( int i = 0; i < columnNames.length; i++ ) { + columns[i] = table.getColumn(columnNames[i], false); + } + return columns; + } + + public boolean mequal(String leftexpr,String rightexpr) throws ActionException { getLogger().debug("leftexpr=" + leftexpr); getLogger().debug("rightexpr=" + rightexpr); return leftexpr.equals(rightexpr); } + public boolean smaller(String leftexpr,String rightexpr) throws ActionException { + throw new ActionException("operation not supported "); + } + + public boolean greater(String leftexpr,String rightexpr) throws ActionException { + throw new ActionException("operation not supported "); + } + + public boolean unequal(String leftexpr,String rightexpr) throws ActionException { + return !leftexpr.equals(rightexpr); + } + + public boolean like(String leftexpr,String rightexpr) throws ActionException { + throw new ActionException("operation not supported "); + } + public void execute(Object[] params) throws ActionException { getLogger().debug("select execute prepared"); } @@ -355,21 +404,4 @@ public void setParamCount(int i) { this.mParamCount = i; } - - protected Column[] convertColumns(String[] columnNames) { - - BasicTable table = (BasicTable)mDatabasePersistor.getQueryable(mTablenames[0]); - - //TODO * could be with other contrived columns - if (columnNames[0].equals("*")) { - return table.getColumns(); - } - - Column[] columns = new Column[columnNames.length]; - for ( int i = 0; i < columnNames.length; i++ ) { - columns[i] = table.getColumn(columnNames[i], false); - } - return columns; - } - }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>