avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject cvs commit: jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/test Tester.java
Date Mon, 05 Nov 2001 01:01:28 GMT
hammant     01/11/04 17:01:28

  Modified:    apps/db/src/java/org/apache/avalon/db/actions Create.java
                        WriteAction.java
               apps/db/src/java/org/apache/avalon/db/bcel/actions
                        AbstractBCELAction.java BCELCreateTable.java
                        BCELInsert.java
               apps/db/src/java/org/apache/avalon/db/bcel/parser
                        BCELSQLParser.java BaseBCELParser.java
                        GeneratedObjectClassLoader.java LXSQLParser.java
               apps/db/src/java/org/apache/avalon/db/server
                        AbstractDatabaseManager.java
               apps/db/src/java/org/apache/avalon/db/test Tester.java
  Removed:     apps/db/src/java/org/apache/avalon/db/bcel/actions
                        BCELInsertSingleValue.java
  Log:
  InsertInto starting to connect to instantiated table
  
  Revision  Changes    Path
  1.4       +2 -2      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/actions/Create.java
  
  Index: Create.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/actions/Create.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Create.java	2001/10/30 23:15:47	1.3
  +++ Create.java	2001/11/05 01:01:27	1.4
  @@ -15,8 +15,8 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version * $Revision: 1.3 $
  + * @version * $Revision: 1.4 $
    */
   public interface Create extends WriteAction {
  -    int getRecordCount();
  +
   }
  
  
  
  1.2       +3 -1      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/actions/WriteAction.java
  
  Index: WriteAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/actions/WriteAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WriteAction.java	2001/10/28 20:57:39	1.1
  +++ WriteAction.java	2001/11/05 01:01:27	1.2
  @@ -15,6 +15,8 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version * $Revision: 1.1 $
  + * @version * $Revision: 1.2 $
    */
  -public interface WriteAction extends Action {}
  +public interface WriteAction extends Action {
  +    int getRecordCount();
  +}
  
  
  
  1.3       +0 -1      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcel/actions/AbstractBCELAction.java
  
  Index: AbstractBCELAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcel/actions/AbstractBCELAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractBCELAction.java	2001/11/04 19:00:19	1.2
  +++ AbstractBCELAction.java	2001/11/05 01:01:27	1.3
  @@ -8,7 +8,6 @@
   package org.apache.avalon.db.bcel.actions;
   
   import org.apache.avalon.db.services.DatabasePersistor;
  -import org.apache.avalon.db.bcel.parser.GeneratedObjectClassLoader;
   import org.apache.avalon.db.bcel.parser.BaseBCELParser;
   
   public class AbstractBCELAction {
  
  
  
  1.5       +15 -8     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcel/actions/BCELCreateTable.java
  
  Index: BCELCreateTable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcel/actions/BCELCreateTable.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BCELCreateTable.java	2001/11/04 21:49:42	1.4
  +++ BCELCreateTable.java	2001/11/05 01:01:27	1.5
  @@ -27,12 +27,12 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public class BCELCreateTable extends AbstractBCELAction implements CreateTable {
   
       private JavaClass mPendingRowClass;
  -    private String mTableName;
  +    private String mTableName, mTableRowName, mTableRowClassName;
       private Vector mColumns;
       private int mRecordCount;
   
  @@ -44,9 +44,12 @@
        * @param tableName
        *
        */
  -    public BCELCreateTable(JavaClass pendingRowClass, String tableName, Vector columns)
{
  +    public BCELCreateTable(JavaClass pendingRowClass, String tableName, String tableRowName,
  +                           String tableRowClassName, Vector columns) {
           mPendingRowClass = pendingRowClass;
           mTableName = tableName;
  +        mTableRowName = tableRowName;
  +        mTableRowClassName = tableRowClassName;
           mColumns = columns;
       }
   
  @@ -58,6 +61,9 @@
        *
        */
       public void execute() throws ActionException {
  +
  +        System.out.println("ct execute");
  +
           /*
           if (mDatabasePersistor.tableExists(mTableName)) {
               throw new ActionException("Table " + mTableName + " Already Exists");
  @@ -65,11 +71,12 @@
           */
   
           byte[] bytes = mPendingRowClass.getBytes();
  -        System.out.println("here 1");
  -        mBCELParser.addGeneratedClass(mTableName, bytes);
  -        //Class rowClass = mBCELParser.getGeneratedClass(mTableName);
  -        //Table table = new BCELTable(mTableName, (Column[]) mColumns.toArray(), rowClass);
  -        //mDatabasePersistor.addTable(mTableName, table);
  +        System.out.println("here 1a");
  +        System.out.println("get table, it's parent class and all referenced classes (crashes
here)");
  +        Class rowClass = mBCELParser.makeGeneratedClass(mTableRowClassName, bytes);
  +        System.out.println("here 1b");
  +        Table table = new BCELTable(mTableName, (Column[]) mColumns.toArray(), rowClass);
  +        mDatabasePersistor.addTable(mTableName, table);
       }
   
       public int getRecordCount() {
  
  
  
  1.2       +3 -1      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcel/actions/BCELInsert.java
  
  Index: BCELInsert.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcel/actions/BCELInsert.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BCELInsert.java	2001/11/04 23:34:40	1.1
  +++ BCELInsert.java	2001/11/05 01:01:27	1.2
  @@ -25,7 +25,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class BCELInsert extends AbstractBCELAction implements Insert {
   
  @@ -54,6 +54,8 @@
        *
        */
       public void execute() throws ActionException {
  +
  +        System.out.println("insert execute");
   
           Class rowClass = mTable.getRowClass();
   
  
  
  
  1.5       +5 -5      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcel/parser/BCELSQLParser.java
  
  Index: BCELSQLParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcel/parser/BCELSQLParser.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BCELSQLParser.java	2001/11/03 13:26:21	1.4
  +++ BCELSQLParser.java	2001/11/05 01:01:28	1.5
  @@ -22,7 +22,6 @@
   import org.apache.avalon.db.transport.CreateTableRequest;
   import org.apache.avalon.db.transport.InsertRequest;
   import org.apache.avalon.db.bcel.actions.BCELCreateTable;
  -import org.apache.avalon.db.bcel.actions.BCELInsertSingleValue;
   import org.apache.avalon.db.bcel.data.BCELTable;
   import org.apache.avalon.db.data.Table;
   import org.apache.avalon.db.data.Column;
  @@ -59,7 +58,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public class BCELSQLParser extends BaseBCELParser {
   
  @@ -88,10 +87,11 @@
       public CreateTable createCreateTableAction(CreateTableRequest request) throws ActionException
{
   
           String tableName = getWordThree(request.getSql());
  +        String tableRowName = tableName + "Row";
           String values = getBracketedExpr(request.getSql());
           StringTokenizer st = new StringTokenizer(values, ",");
  -        String newTableClassName = createUniqueClassName(tableName);
  -        ClassGen cg = new ClassGen(newTableClassName,
  +        String newTableRowClassName = createUniqueClassName(tableRowName);
  +        ClassGen cg = new ClassGen(newTableRowClassName,
                                      "org.apache.avalon.db.data.impl.AbstractTableRow",
                                      "<SQL Generated>", Constants.ACC_PUBLIC | Constants.ACC_SUPER,
                                      null);
  @@ -121,7 +121,7 @@
               System.err.println(e);
           }
   
  -        CreateTable action = new BCELCreateTable(cg.getJavaClass(), tableName, columns);
  +        CreateTable action = new BCELCreateTable(cg.getJavaClass(), tableName, tableRowName,
newTableRowClassName, columns);
           action.setDatabasePersistor(mDatabasePersistor);
           return action;
       }
  
  
  
  1.4       +6 -7      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcel/parser/BaseBCELParser.java
  
  Index: BaseBCELParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcel/parser/BaseBCELParser.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BaseBCELParser.java	2001/11/03 13:26:21	1.3
  +++ BaseBCELParser.java	2001/11/05 01:01:28	1.4
  @@ -21,7 +21,7 @@
   import org.apache.avalon.db.transport.CreateTableRequest;
   import org.apache.avalon.db.transport.InsertRequest;
   import org.apache.avalon.db.bcel.actions.BCELCreateTable;
  -import org.apache.avalon.db.bcel.actions.BCELInsertSingleValue;
  +import org.apache.avalon.db.bcel.actions.BCELInsert;
   import org.apache.avalon.db.bcel.data.BCELTable;
   import org.apache.avalon.db.data.Table;
   import org.apache.avalon.db.data.Column;
  @@ -59,18 +59,17 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
   public abstract class BaseBCELParser extends AbstractLoggable
           implements Block, SQLParser, Contextualizable, Composable, Configurable {
   
       protected DatabasePersistor mDatabasePersistor;
  -    protected GeneratedObjectClassLoader mGenClassLoader = new GeneratedObjectClassLoader();
  +    protected GeneratedObjectClassLoader mGenClassLoader = new GeneratedObjectClassLoader(BaseBCELParser.class.getClassLoader());
       protected static int mGenObjSeq;
       protected HashMap mGeneratedObjTranslation = new HashMap();
       protected BlockContext mBlockContext;
   
  -
       /**
        * Method contextualize
        *
  @@ -227,14 +226,14 @@
           }
   
           //TODO get columns from table.
  -        return new BCELInsertSingleValue(table, null, valuesVec);
  +        return null; //new BCELInsert(table, null, valuesVec);
       }
   
       //private Insert createSelectInsert(Table table, String sql) {
       //}
   
  -    public void addGeneratedClass(String name, byte[] bytes) {
  -        mGenClassLoader.addGeneratedClass(name, bytes);
  +    public Class makeGeneratedClass(String name, byte[] bytes) {
  +        return mGenClassLoader.makeGeneratedClass(name, bytes);
       }
   
       public Object getGeneratedInstance(String name) {
  
  
  
  1.3       +16 -1     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcel/parser/GeneratedObjectClassLoader.java
  
  Index: GeneratedObjectClassLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcel/parser/GeneratedObjectClassLoader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GeneratedObjectClassLoader.java	2001/10/31 13:45:36	1.2
  +++ GeneratedObjectClassLoader.java	2001/11/05 01:01:28	1.3
  @@ -13,9 +13,21 @@
   
   public class GeneratedObjectClassLoader extends ClassLoader {
   
  +    private ClassLoader mParent;
  +
  +    public GeneratedObjectClassLoader(ClassLoader parent) {
  +        mParent = parent;
  +    }
  +
  +    public ClassLoader getPatent() {
  +        return mParent;
  +    }
  +
  +
       private HashMap mGeneratedClasses = new HashMap();
   
       public Class findClass(String name) {
  +        System.out.println("Lookin for " + name);
           try {
               return super.findClass(name);
           } catch (ClassNotFoundException cnfe) {
  @@ -25,11 +37,14 @@
           }
       }
   
  -    void addGeneratedClass(String name, byte[] bytes) {
  +    Class makeGeneratedClass(String name, byte[] bytes) {
  +        System.out.println("Storin " + name);
           mGeneratedClasses.put(name, new Holder(bytes));
  +        return findClass(name);
       }
   
       Object getGeneratedInstance(String name) {
  +        System.out.println("Gennin" + name);
           Class clazz = findClass(name);
           try {
               return clazz.newInstance();
  
  
  
  1.8       +13 -8     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcel/parser/LXSQLParser.java
  
  Index: LXSQLParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcel/parser/LXSQLParser.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- LXSQLParser.java	2001/11/04 23:34:40	1.7
  +++ LXSQLParser.java	2001/11/05 01:01:28	1.8
  @@ -20,7 +20,6 @@
   import org.apache.avalon.db.transport.CreateTableRequest;
   import org.apache.avalon.db.transport.InsertRequest;
   import org.apache.avalon.db.bcel.actions.BCELCreateTable;
  -import org.apache.avalon.db.bcel.actions.BCELInsertSingleValue;
   import org.apache.avalon.db.bcel.actions.AbstractBCELAction;
   import org.apache.avalon.db.bcel.actions.BCELInsert;
   import org.apache.avalon.db.bcel.data.BCELTable;
  @@ -75,7 +74,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.7 $
  + * @version $Revision: 1.8 $
    */
   public class LXSQLParser extends BaseBCELParser {
   
  @@ -103,6 +102,7 @@
           {
               throw new ComponentException("ParserConfiguration Exception in compose()",pce);
           }
  +        super.compose(componentManager);
       }
   
       /**
  @@ -142,10 +142,11 @@
               getLogger().debug("rootElement=" + rootElement.getTagName());
   
               String tableName = rootElement.getAttribute("name");
  +            String tableRowName = tableName + "Row";
   
   
  -            String newTableClassName = createUniqueClassName(tableName);
  -            ClassGen cg = new ClassGen(newTableClassName,
  +            String newTableRowClassName = createUniqueClassName(tableRowName);
  +            ClassGen cg = new ClassGen(newTableRowClassName,
                                      "org.apache.avalon.db.data.impl.AbstractTableRow",
                                      "<SQL Generated>", Constants.ACC_PUBLIC | Constants.ACC_SUPER,
                                      null);
  @@ -183,12 +184,12 @@
               //TODO need to create constrcutor suitable for superclass.
   
               try {
  -                cg.getJavaClass().dump(newTableClassName + "_tableName.class");
  +                cg.getJavaClass().dump(newTableRowClassName + "_tableName.class");
               } catch (java.io.IOException e) {
                   System.err.println(e);
               }
   
  -            CreateTable action = new BCELCreateTable(cg.getJavaClass(), tableName, columns);
  +            CreateTable action = new BCELCreateTable(cg.getJavaClass(), tableName, tableRowName,
newTableRowClassName, columns);
               action.setDatabasePersistor(mDatabasePersistor);
               ((AbstractBCELAction) action).setBCELParser(this);
               return action;
  @@ -224,8 +225,12 @@
               Element rootElement = doc.getDocumentElement();
               String tableName = rootElement.getAttribute("table-name");
   
  -            BCELTable table = (BCELTable) mDatabasePersistor.getTable(tableName);
  -
  +            System.out.println("mDatabasePersistor" + mDatabasePersistor);
  +            System.out.println("=tn=" + tableName);
  +            String uniqueTableName = getGeneratedClassName(tableName);
  +            System.out.println("=utn=" + uniqueTableName);
  +            BCELTable table = (BCELTable) mDatabasePersistor.getTable(uniqueTableName);
  +            System.out.println("=table=" + table);
               Insert action = new BCELInsert(table, doc);
               action.setDatabasePersistor(mDatabasePersistor);
               ((AbstractBCELAction) action).setBCELParser(this);
  
  
  
  1.11      +17 -11    jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/server/AbstractDatabaseManager.java
  
  Index: AbstractDatabaseManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/server/AbstractDatabaseManager.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AbstractDatabaseManager.java	2001/11/04 19:00:19	1.10
  +++ AbstractDatabaseManager.java	2001/11/05 01:01:28	1.11
  @@ -18,6 +18,7 @@
   import org.apache.avalon.db.actions.Select;
   import org.apache.avalon.db.actions.ActionException;
   import org.apache.avalon.db.actions.CreateTable;
  +import org.apache.avalon.db.actions.Insert;
   import org.apache.avalon.db.transport.Request;
   import org.apache.avalon.db.transport.Reply;
   import org.apache.avalon.db.transport.SelectRequest;
  @@ -26,6 +27,7 @@
   import org.apache.avalon.db.transport.UnknownRequestReply;
   import org.apache.avalon.db.transport.UpdateReply;
   import org.apache.avalon.db.transport.ResultSetReply;
  +import org.apache.avalon.db.transport.InsertRequest;
   import org.apache.avalon.framework.logger.AbstractLoggable;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.ComponentException;
  @@ -37,7 +39,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.10 $
  + * @version $Revision: 1.11 $
    */
   public abstract class AbstractDatabaseManager extends AbstractLoggable implements Composable
{
   
  @@ -75,17 +77,14 @@
           try {
               switch (request.getRequestCode()) {
   
  -            case (Request.SELECT) :
  -                return processSelectRequest((SelectRequest) request);
  -
  -            case (Request.CREATETABLE) :
  -                return processCreateTableRequest((CreateTableRequest) request);
  -
  -            case (Request.INSERT) :
  -
  -                //TODO
  -                break;
  +                case (Request.SELECT) :
  +                    return processSelectRequest((SelectRequest) request);
  +                case (Request.CREATETABLE) :
  +                    return processCreateTableRequest((CreateTableRequest) request);
  +                case (Request.INSERT) :
  +                    return processInsertRequest((InsertRequest) request);
               }
  +
           } catch (ActionException ae) {
               getLogger().error("processRequest(): Exception",ae);
               return new ExceptionReply(ae.getMessage());
  @@ -110,5 +109,12 @@
           ct.execute();
           return new UpdateReply(ct.getRecordCount());
       }
  +
  +    public Reply processInsertRequest(InsertRequest insertRequest) throws ActionException
{
  +        Insert ins = mSQLParser.createInsertAction(insertRequest);
  +        ins.execute();
  +        return new UpdateReply(ins.getRecordCount());
  +    }
  +
   
   }
  
  
  
  1.7       +1 -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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Tester.java	2001/11/04 23:34:40	1.6
  +++ Tester.java	2001/11/05 01:01:28	1.7
  @@ -38,7 +38,6 @@
   
           st = mCon.createStatement();
           String insertInto = "<insert-into table-name=\"Flintstones\">" +
  -                               "<columns astable\"true\"/>" +
                                  "<rows>" +
                                    "<row>" +
                                      "<value col=\"forname\">Fred</value>" +
  @@ -52,7 +51,7 @@
                                      "<value col=\"forname\">Barney</value>"
+
                                      "<value col=\"surname\">Rubble</value>"
+
                                    "</row>" +
  -                               "<rows>" +
  +                               "</rows>" +
                                "</insert-into>";
           st.executeUpdate(insertInto);
           st.close();
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-dev-help@jakarta.apache.org>


Mime
View raw message