avalon-cvs 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/transport Reply.java UpdateReply.java
Date Tue, 30 Oct 2001 23:15:47 GMT
hammant     01/10/30 15:15:47

  Modified:    apps/db  build.xml
               apps/db/src/java/org/apache/avalon/db/actions Action.java
                        ActionException.java Create.java
               apps/db/src/java/org/apache/avalon/db/bcelactions
                        BCELCreateTable.java BCELInsertSingleValue.java
               apps/db/src/java/org/apache/avalon/db/bcelparser
                        BCELSQLParser.java
               apps/db/src/java/org/apache/avalon/db/server
                        AbstractDatabaseManager.java
               apps/db/src/java/org/apache/avalon/db/transport Reply.java
                        UpdateReply.java
  Added:       apps/db/src/java/org/apache/avalon/db/bcelactions
                        AbstractBCELAction.java
               apps/db/src/java/org/apache/avalon/db/bcelparser
                        GeneratedObjectClassLoader.java
  Log:
  ClassLoader for generated object exists now
  
  Revision  Changes    Path
  1.4       +4 -0      jakarta-avalon-cornerstone/apps/db/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/build.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- build.xml	2001/10/30 20:25:55	1.3
  +++ build.xml	2001/10/30 23:15:47	1.4
  @@ -138,6 +138,10 @@
           <include name="avalon-db.jar"/>
         </lib>      
   
  +      <lib dir="lib">
  +        <include name="bcel.jar"/>
  +      </lib>
  +
         <zipfileset dir="${conf.dir}" fullpath="conf/keyStore">
           <include name="keystore"/>
         </zipfileset>   
  
  
  
  1.4       +3 -1      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/actions/Action.java
  
  Index: Action.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/actions/Action.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Action.java	2001/10/30 20:06:32	1.3
  +++ Action.java	2001/10/30 23:15:47	1.4
  @@ -8,6 +8,7 @@
    */
   package org.apache.avalon.db.actions;
   
  +import org.apache.avalon.db.services.DatabasePersistor;
   
   
   /**
  @@ -15,8 +16,9 @@
    *
    *
    * @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 Action {
       void execute() throws ActionException;
  +    void setDatabasePersistor(DatabasePersistor databasePersistor);
   }
  
  
  
  1.2       +6 -2      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/actions/ActionException.java
  
  Index: ActionException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/actions/ActionException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ActionException.java	2001/10/28 14:09:19	1.1
  +++ ActionException.java	2001/10/30 23:15:47	1.2
  @@ -15,6 +15,10 @@
    *
    *
    * @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 ActionException extends Exception {}
  +public class ActionException extends Exception {
  +    public ActionException(String reason) {
  +        super(reason);
  +    }
  +}
  
  
  
  1.3       +4 -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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Create.java	2001/10/28 20:57:39	1.2
  +++ Create.java	2001/10/30 23:15:47	1.3
  @@ -15,6 +15,8 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version * $Revision: 1.2 $
  + * @version * $Revision: 1.3 $
    */
  -public interface Create extends WriteAction {}
  +public interface Create extends WriteAction {
  +    int getRecordCount();
  +}
  
  
  
  1.2       +21 -3     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcelactions/BCELCreateTable.java
  
  Index: BCELCreateTable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcelactions/BCELCreateTable.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BCELCreateTable.java	2001/10/30 17:45:14	1.1
  +++ BCELCreateTable.java	2001/10/30 23:15:47	1.2
  @@ -11,6 +11,9 @@
   
   
   import org.apache.avalon.db.actions.CreateTable;
  +import org.apache.avalon.db.actions.ActionException;
  +import org.apache.avalon.db.services.DatabasePersistor;
  +import org.apache.avalon.db.data.Table;
   import org.apache.bcel.classfile.JavaClass;
   
   
  @@ -19,12 +22,13 @@
    *
    *
    * @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 BCELCreateTable implements CreateTable {
  +public class BCELCreateTable extends AbstractBCELAction implements CreateTable {
   
       private JavaClass mPendingClass;
       private String mTableName;
  +    private int mRecordCount;
   
       /**
        * Constructor BCELCreateTable
  @@ -39,10 +43,24 @@
           mTableName = tableName;
       }
   
  +
  +
       /**
        * Method execute
        *
        *
        */
  -    public void execute() {}
  +    public void execute() throws ActionException {
  +        if (mDatabasePersistor.tableExists(mTableName)) {
  +            throw new ActionException("Table " + mTableName + " Already Exists");
  +        }
  +        byte[] bytes = mPendingClass.getBytes();
  +        mBCELSQLParser.addGeneratedClass(mTableName, bytes);
  +        Table table = (Table) mBCELSQLParser.getGeneratedInstance(mTableName);
  +        mDatabasePersistor.addTable(mTableName, table);
  +    }
  +
  +    public int getRecordCount() {
  +        return mRecordCount;
  +    }
   }
  
  
  
  1.2       +7 -2      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcelactions/BCELInsertSingleValue.java
  
  Index: BCELInsertSingleValue.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcelactions/BCELInsertSingleValue.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BCELInsertSingleValue.java	2001/10/30 17:45:14	1.1
  +++ BCELInsertSingleValue.java	2001/10/30 23:15:47	1.2
  @@ -12,6 +12,7 @@
   
   import org.apache.avalon.db.actions.Insert;
   import org.apache.avalon.db.data.Table;
  +import org.apache.avalon.db.services.DatabasePersistor;
   import org.apache.bcel.classfile.JavaClass;
   
   import java.util.Vector;
  @@ -26,9 +27,9 @@
    *
    *
    * @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 BCELInsertSingleValue implements Insert {
  +public class BCELInsertSingleValue extends AbstractBCELAction implements Insert {
   
       private Vector mColumnNames;
       private Vector mColumnValues;
  @@ -48,6 +49,10 @@
           mTable = table;
           mColumnNames = columnNames;
           mColumnValues = columnValues;
  +    }
  +
  +    public void setDatabasePersistor(DatabasePersistor databasePersistor) {
  +        mDatabasePersistor = databasePersistor;
       }
   
       /**
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcelactions/AbstractBCELAction.java
  
  Index: AbstractBCELAction.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.db.bcelactions;
  
  import org.apache.avalon.db.services.DatabasePersistor;
  import org.apache.avalon.db.bcelparser.GeneratedObjectClassLoader;
  import org.apache.avalon.db.bcelparser.BCELSQLParser;
  
  public class AbstractBCELAction {
  
      protected DatabasePersistor mDatabasePersistor;
      protected BCELSQLParser mBCELSQLParser;
  
      public void setDatabasePersistor(DatabasePersistor databasePersistor) {
          mDatabasePersistor = databasePersistor;
      }
      public void setBCELSQLParser(BCELSQLParser bcelSQLParser) {
          mBCELSQLParser = bcelSQLParser;
      }
  
  }
  
  
  
  1.2       +14 -2     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcelparser/BCELSQLParser.java
  
  Index: BCELSQLParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcelparser/BCELSQLParser.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BCELSQLParser.java	2001/10/30 17:45:14	1.1
  +++ BCELSQLParser.java	2001/10/30 23:15:47	1.2
  @@ -50,13 +50,15 @@
    *
    *
    * @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 BCELSQLParser extends AbstractLoggable
           implements Block, SQLParser, Contextualizable, Composable, Configurable, Initializable
{
   
       private DatabasePersistor mDatabasePersistor;
  +    private GeneratedObjectClassLoader mGenClassLoader = new GeneratedObjectClassLoader();
   
  +
       /**
        * Method createAction
        *
  @@ -234,7 +236,9 @@
               System.err.println(e);
           }
   
  -        return new BCELCreateTable(cg.getJavaClass(), table);
  +        CreateTable action = new BCELCreateTable(cg.getJavaClass(), table);
  +        action.setDatabasePersistor(mDatabasePersistor);
  +        return action;
       }
   
       private Type getType(String type) {
  @@ -322,6 +326,14 @@
   
       //private Insert createSelectInsert(Table table, String sql) {
       //}
  +
  +    public void addGeneratedClass(String name, byte[] bytes) {
  +        mGenClassLoader.addGeneratedClass(name, bytes);
  +    }
  +    public Object getGeneratedInstance(String name) {
  +        return mGenClassLoader.getGeneratedInstance(name);
  +    }
  +
   
       /**
        * Method main
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcelparser/GeneratedObjectClassLoader.java
  
  Index: GeneratedObjectClassLoader.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  
  package org.apache.avalon.db.bcelparser;
  
  import java.net.URLClassLoader;
  import java.util.HashMap;
  
  public class GeneratedObjectClassLoader extends ClassLoader {
  
      private HashMap mGeneratedClasses = new HashMap();
  
      public Class findClass(String name) {
          Holder holder = (Holder) mGeneratedClasses.get(name);
          byte[] bytes = holder.getBytes();
          return defineClass(name, bytes, 0, bytes.length);
      }
  
      void addGeneratedClass(String name, byte[] bytes) {
          mGeneratedClasses.put(name, new Holder(bytes));
      }
  
      Object getGeneratedInstance(String name) {
          Class clazz = findClass(name);
          try {
              return clazz.newInstance();
          } catch (Throwable t) {
              return null;
          }
      }
  
      private class Holder {
          private byte[] ba;
          Holder(byte[] ba) {
              this.ba = ba;
          }
          byte[] getBytes() {
              return ba;
          }
      }
  }
  
  
  
  1.5       +10 -6     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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractDatabaseManager.java	2001/10/30 20:06:33	1.4
  +++ AbstractDatabaseManager.java	2001/10/30 23:15:47	1.5
  @@ -17,6 +17,7 @@
   import org.apache.avalon.db.transport.*;
   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.framework.logger.AbstractLoggable;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.ComponentException;
  @@ -27,7 +28,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 abstract class AbstractDatabaseManager extends AbstractLoggable {
   
  @@ -72,10 +73,8 @@
                   return processSelectRequest((SelectRequest) request);
   
               case (Request.CREATETABLE) :
  +                return processCreateTableRequest((CreateTableRequest) request);
   
  -                //TODO
  -                break;
  -
               case (Request.INSERT) :
   
                   //TODO
  @@ -89,12 +88,17 @@
       }
   
       protected Reply processSelectRequest(SelectRequest selectRequest) throws ActionException
{
  -
           SelectRequest optimizedSelectRequest =
               mSQLOptimizer.optimizeSelectRequest(selectRequest);
           Select select = mSQLParser.createSelectAction(optimizedSelectRequest);
  -
           select.execute();
           return new ResultSetReply(select.getRowSet());
       }
  +
  +    protected Reply processCreateTableRequest(CreateTableRequest createTableRequest) throws
ActionException {
  +        CreateTable ct = mSQLParser.createCreateTableAction(createTableRequest);
  +        ct.execute();
  +        return new UpdateReply(ct.getRecordCount());
  +    }
  +
   }
  
  
  
  1.5       +2 -1      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/Reply.java
  
  Index: Reply.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/Reply.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Reply.java	2001/10/29 15:18:16	1.4
  +++ Reply.java	2001/10/30 23:15:47	1.5
  @@ -18,7 +18,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 abstract class Reply implements Serializable {
   
  @@ -29,6 +29,7 @@
       public static final int READONLYREPLY = 14;
       public static final int TRANSACTIONISOLATIONREPLY = 15;
       public static final int CATALOGREPLY = 16;
  +    public static final int UPDATEREPLY = 17;
   
       private int mReplyCode;
   
  
  
  
  1.2       +1 -1      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/UpdateReply.java
  
  Index: UpdateReply.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/UpdateReply.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- UpdateReply.java	2001/10/29 15:18:16	1.1
  +++ UpdateReply.java	2001/10/30 23:15:47	1.2
  @@ -18,7 +18,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 UpdateReply extends Reply {
   
  @@ -32,7 +32,7 @@
        *
        */
       public UpdateReply(int rc) {
  -        super(TRANSACTIONISOLATIONREPLY);
  +        super(UPDATEREPLY);
           mRowCount = rc;
       }
   
  
  
  

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


Mime
View raw message