hammant 01/11/14 13:18:44 Modified: apps/db/src/java/org/apache/avalon/db/basic/actions BasicCreateQueryable.java BasicCreateTable.java BasicCreateView.java apps/db/src/java/org/apache/avalon/db/test Tester.java Log: start of work on View Revision Changes Path 1.8 +9 -3 jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicCreateQueryable.java Index: BasicCreateQueryable.java =================================================================== RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicCreateQueryable.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- BasicCreateQueryable.java 2001/11/14 17:05:32 1.7 +++ BasicCreateQueryable.java 2001/11/14 21:18:43 1.8 @@ -37,11 +37,13 @@ * * * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> - * @version $Revision: 1.7 $ + * @version $Revision: 1.8 $ */ public abstract class BasicCreateQueryable extends AbstractAction implements CreateTable { + protected Column[] mColumns; + /** * Method getColumns * @@ -54,17 +56,19 @@ Vector columns = new Vector(); for (int f = 0 ; f < subRootNodes.getLength(); f++) { - if (subRootNodes.item(f).getNodeName().equals("columns")) { + String nodeName = subRootNodes.item(f).getNodeName(); + if (nodeName.equals("columns")) { NodeList subColumnsNodes = subRootNodes.item(f).getChildNodes(); for (int x = 0 ; x < subColumnsNodes.getLength(); x++) { if (subColumnsNodes.item(x).getNodeName().equals("column")) { columns.add(createColumn(subColumnsNodes.item(x), x)); } else { + throw new ActionException("Only 'column' allowed as a node under 'columns' node"); } } } else { - throw new ActionException("Only 'columns' allowed as a node under 'create-table' node"); + } } @@ -74,6 +78,8 @@ return columnsAry; } + + protected abstract void checkNodeType(String nodeName) throws ActionException; protected Column createColumn(Node columnNode, int ix) throws ActionException { String sqlFieldType = columnNode.getAttributes().getNamedItem("type").getNodeValue(); 1.10 +5 -1 jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicCreateTable.java Index: BasicCreateTable.java =================================================================== RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicCreateTable.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- BasicCreateTable.java 2001/11/13 14:16:23 1.9 +++ BasicCreateTable.java 2001/11/14 21:18:43 1.10 @@ -33,7 +33,7 @@ public class BasicCreateTable extends BasicCreateQueryable implements CreateTable { private String mTableName; - private Column[] mColumns; + private int mRecordCount; private Element mLxsql; @@ -43,6 +43,10 @@ } public void initialize() throws ActionException { + } + + protected void checkNodeType(String nodeName) throws ActionException { + throw new ActionException("Only 'columns' allowed as a node under 'create-table' node"); } /** 1.10 +16 -17 jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicCreateView.java Index: BasicCreateView.java =================================================================== RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicCreateView.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- BasicCreateView.java 2001/11/13 14:16:23 1.9 +++ BasicCreateView.java 2001/11/14 21:18:43 1.10 @@ -29,29 +29,38 @@ * * * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> - * @version $Revision: 1.9 $ + * @version $Revision: 1.10 $ */ public class BasicCreateView extends BasicCreateQueryable implements CreateView { private String mViewName; private BasicSelect mBasicSelect; - private Document mLxsql; + private Element mRootElement; - public BasicCreateView(String viewName, Document lxsql) { + public BasicCreateView(String viewName, Element rootElement) { mViewName = viewName; - mLxsql = lxsql; + mRootElement = rootElement; } public void initialize() throws ActionException { - NodeList subRootNodes = mLxsql.getChildNodes(); + NodeList subRootNodes = mRootElement.getChildNodes(); for (int i = 0; i < subRootNodes.getLength(); i++) { - if (subRootNodes.item(i).getNodeName().equals("select-simple")) { + System.out.println(">>>"+subRootNodes.item(i).getNodeName()); + if (subRootNodes.item(i).getNodeName().equals("simple-select")) { mBasicSelect = new BasicSelect((Element) subRootNodes.item(i)); + } else if (subRootNodes.item(i).getNodeName().equals("columns")) { } } + mColumns = getColumns(mRootElement); mBasicSelect.initialize(); } + protected void checkNodeType(String nodeName) throws ActionException { + if (!nodeName.equals("simple-select")) { + throw new ActionException("Only 'columns' & 'simple-select' allowed as a node under 'create-view' node"); + } + } + /** * Method execute * @@ -60,18 +69,8 @@ public void execute() throws ActionException { System.out.println("cv execute"); - - NodeList subRootNodes = mLxsql.getChildNodes(); - Column[] columns = null; - for (int i = 0; i < subRootNodes.getLength(); i++) { - if (subRootNodes.item(i).getNodeName().equals("create-table")) { - columns = getColumns((Element) subRootNodes.item(i)); - } - } - - - View view = new BasicView(mViewName, columns, mBasicSelect); + View view = new BasicView(mViewName, mColumns, mBasicSelect); mDatabasePersistor.addQueryable(mViewName, view); if (mBasicSelect != null) { 1.17 +27 -0 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.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- Tester.java 2001/11/14 15:54:29 1.16 +++ Tester.java 2001/11/14 21:18:44 1.17 @@ -86,6 +86,33 @@ System.out.println("Result col1 = " + rs.getString(1)); } + System.err.println("VIEW 1"); + st = mCon.createStatement(); + String view = "<create-view name=\"FlintstonesView\">" + + "<columns>" + + "<column name=\"forename\" type=\"varchar\" max=\"20\"/>" + + "<column name=\"surname\" type=\"varchar\" max=\"20\"/>" + + "<column name=\"age\" type=\"integer\"/>" + + "</columns>" + + "<simple-select>" + + "<columns>" + + "<column name=\"forename\"/>" + + "<column name=\"surname\"/>" + + "</columns>" + + "<from><table name=\"Flintstones\"/></from>" + + "<where>" + + "<and>" + + "<condition expr=\"forename=Wilma\"/>" + //TODO this is too Java + "<condition expr=\"surname=Flintstone\"/>" + //TODO this is too Java + "</and>" + + "</where>" + + "</simple-select>" + + "</create-view>"; + + st.execute(view); + st.close(); + + /* System.err.println("SELECT 2"); //TODO st = mCon.createStatement();
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>