You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by ha...@apache.org on 2001/11/01 09:48:42 UTC

cvs commit: jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcelparser BaseBCELParser.java BCELSQLParser.java

hammant     01/11/01 00:48:42

  Modified:    apps/db/src/java/org/apache/avalon/db/bcelparser
                        BCELSQLParser.java
  Added:       apps/db/src/java/org/apache/avalon/db/bcelparser
                        BaseBCELParser.java
  Log:
  Split of BCEL parser into parent class and SQL impl
  
  Revision  Changes    Path
  1.4       +3 -172    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BCELSQLParser.java	2001/10/31 12:38:01	1.3
  +++ BCELSQLParser.java	2001/11/01 08:48:42	1.4
  @@ -51,10 +51,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 class BCELSQLParser extends AbstractLoggable
  -        implements Block, SQLParser, Contextualizable, Composable, Configurable, Initializable {
  +public class BCELSQLParser extends BaseBCELParser {
   
       private DatabasePersistor mDatabasePersistor;
       private GeneratedObjectClassLoader mGenClassLoader = new GeneratedObjectClassLoader();
  @@ -75,50 +74,7 @@
           return null;
       }
   
  -    /**
  -     * Method contextualize
  -     *
  -     *
  -     * @param context
  -     *
  -     * @throws ContextException
  -     *
  -     */
  -    public void contextualize(Context context) throws ContextException {}
  -
  -    /**
  -     * Method compose
  -     *
  -     *
  -     * @param componentManager
  -     *
  -     * @throws ComponentException
  -     *
  -     */
  -    public void compose(ComponentManager componentManager) throws ComponentException {
  -        mDatabasePersistor =
  -            (DatabasePersistor) componentManager.lookup(DatabasePersistor.class.getName());
  -    }
  -
  -    /**
  -     * Method configure
  -     *
  -     *
  -     * @param configuration
  -     *
  -     * @throws ConfigurationException
  -     *
  -     */
  -    public void configure(Configuration configuration) throws ConfigurationException {}
   
  -    /**
  -     * Method initialize
  -     *
  -     *
  -     * @throws Exception
  -     *
  -     */
  -    public void initialize() throws Exception {}
   
       /**
        * Method createSelectAction
  @@ -133,68 +89,7 @@
           return null;
       }
   
  -    private String getWordOne(String str) {
  -
  -        int ix0 = str.indexOf(' ');
  -
  -        if (ix0 == -1) {
  -            ix0 = str.length();
  -        }
  -
  -        return str.substring(0, ix0);
  -    }
  -
  -    private String getWordTwo(String str) {
  -
  -        int ix0 = str.indexOf(' ');
  -        int ix1 = str.indexOf(' ', ix0 + 1);
  -
  -        if (ix1 == -1) {
  -            ix1 = str.length();
  -        }
  -
  -        return str.substring(ix0 + 1, ix1);
  -    }
  -
  -    private String getWordThree(String str) {
  -
  -        int ix0 = str.indexOf(' ');
  -        int ix1 = str.indexOf(' ', ix0 + 1);
  -        int ix2 = str.indexOf(' ', ix1 + 1);
  -
  -        if (ix2 == -1) {
  -            ix2 = str.length();
  -        }
  -
  -        return str.substring(ix1 + 1, ix2);
  -    }
  -
  -    private String getWordFour(String str) {
  -
  -        int ix0 = str.indexOf(' ');
  -        int ix1 = str.indexOf(' ', ix0 + 1);
  -        int ix2 = str.indexOf(' ', ix1 + 1);
  -        int ix3 = str.indexOf(' ', ix2 + 1);
  -
  -        if (ix3 == -1) {
  -            ix3 = str.length();
  -        }
  -
  -        return str.substring(ix2 + 1, ix3);
  -    }
  -
  -    private String getBracketedExpr(String str) {
   
  -        int ix0 = str.indexOf('(');
  -        int ix1 = str.lastIndexOf(')');
  -
  -        System.out.println("str=" + str);
  -        System.out.println("ix0=" + ix0);
  -        System.out.println("ix1=" + ix1);
  -
  -        return str.substring(ix0 + 1, ix1);
  -    }
  -
       /**
        * Method createCreateTableAction
        *
  @@ -244,45 +139,7 @@
           return action;
       }
   
  -    private Type getType(String type) {
  -
  -        System.out.println("Type=(" + type + ")");
  -
  -        if (type.equals("varchar")) {
  -            return Type.STRING;
  -        } else if (type.equals("char")) {
  -            return Type.STRING;
  -        }
  -
  -        return Type.VOID;
  -    }
  -
  -    private void createField(ConstantPoolGen cp, ClassGen cg, Type fieldType, String name) {
   
  -        System.out.println("fn=" + name);
  -        System.out.println("Type2=" + fieldType);
  -
  -        FieldGen fg = new FieldGen(Constants.ACC_PUBLIC, fieldType, name, cp);
  -
  -        cg.addField(fg.getField());
  -    }
  -
  -    private void createSetter(ConstantPoolGen cp, ClassGen cg, Type fieldType, String name,
  -                              String table) {
  -
  -        InstructionList il = new InstructionList();
  -        MethodGen mg = new MethodGen(Constants.ACC_PUBLIC,    // access flags
  -                                     Type.VOID,               // return type
  -                                     new Type[]{ fieldType }, new String[]{ "value" },    // arg names
  -                                     "set" + name, table,     // method, class
  -                                     il, cp);
  -
  -        mg.stripAttributes(true);
  -        mg.setMaxStack();
  -        mg.setMaxLocals();
  -        cg.addMethod(mg.getMethod());
  -    }
  -
       /**
        * Method createInsertAction
        *
  @@ -311,34 +168,8 @@
           return null;
       }
   
  -    //private Insert createNamedColumnsInsert(Table table, String sql ) {
  -    //}
  -    private Insert createAllValuesInsert(Table table, String sql) {
  -
  -        String values = getBracketedExpr(sql);
  -        StringTokenizer st = new StringTokenizer(values, ",");
  -        Vector valuesVec = new Vector();
  -
  -        while (st.hasMoreTokens()) {
  -            valuesVec.add(st.nextToken().trim());
  -        }
  -
  -        //TODO get columns from table.
  -        return new BCELInsertSingleValue(table, null, valuesVec);
  -    }
  -
  -    //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/BaseBCELParser.java
  
  Index: BaseBCELParser.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 org.apache.avalon.db.services.SQLParser;
  import org.apache.avalon.db.services.DatabasePersistor;
  import org.apache.avalon.db.actions.Action;
  import org.apache.avalon.db.actions.Select;
  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.SelectRequest;
  import org.apache.avalon.db.transport.CreateTableRequest;
  import org.apache.avalon.db.transport.InsertRequest;
  import org.apache.avalon.db.bcelactions.BCELCreateTable;
  import org.apache.avalon.db.bcelactions.BCELInsertSingleValue;
  import org.apache.avalon.db.data.Table;
  import org.apache.avalon.db.data.Column;
  import org.apache.avalon.db.data.impl.DefaultColumn;
  import org.apache.avalon.phoenix.Block;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.bcel.Constants;
  import org.apache.bcel.generic.*;
  import org.apache.bcel.classfile.Field;
  
  import java.util.StringTokenizer;
  import java.util.Vector;
  import java.util.HashMap;
  
  
  /**
   * Class BaseBCELParser
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public abstract class BaseBCELParser extends AbstractLoggable
          implements Block, SQLParser, Contextualizable, Composable, Configurable, Initializable {
  
      protected DatabasePersistor mDatabasePersistor;
      protected GeneratedObjectClassLoader mGenClassLoader = new GeneratedObjectClassLoader();
      protected static int mGenObjSeq;
      protected HashMap mGeneratedObjTranslation = new HashMap();
  
  
      /**
       * Method createAction
       *
       *
       * @param request
       *
       * @return
       *
       */
      public Action createAction(Request request) {
          return null;
      }
  
      /**
       * Method contextualize
       *
       *
       * @param context
       *
       * @throws ContextException
       *
       */
      public void contextualize(Context context) throws ContextException {}
  
      /**
       * Method compose
       *
       *
       * @param componentManager
       *
       * @throws ComponentException
       *
       */
      public void compose(ComponentManager componentManager) throws ComponentException {
          mDatabasePersistor =
              (DatabasePersistor) componentManager.lookup(DatabasePersistor.class.getName());
      }
  
      /**
       * Method configure
       *
       *
       * @param configuration
       *
       * @throws ConfigurationException
       *
       */
      public void configure(Configuration configuration) throws ConfigurationException {}
  
      /**
       * Method initialize
       *
       *
       * @throws Exception
       *
       */
      public void initialize() throws Exception {}
  
      /**
       * Method createSelectAction
       *
       *
       * @param request
       *
       * @return
       *
       */
      public Select createSelectAction(SelectRequest request) {
          return null;
      }
  
      protected String getWordOne(String str) {
  
          int ix0 = str.indexOf(' ');
  
          if (ix0 == -1) {
              ix0 = str.length();
          }
  
          return str.substring(0, ix0);
      }
  
      protected String getWordTwo(String str) {
  
          int ix0 = str.indexOf(' ');
          int ix1 = str.indexOf(' ', ix0 + 1);
  
          if (ix1 == -1) {
              ix1 = str.length();
          }
  
          return str.substring(ix0 + 1, ix1);
      }
  
      protected String getWordThree(String str) {
  
          int ix0 = str.indexOf(' ');
          int ix1 = str.indexOf(' ', ix0 + 1);
          int ix2 = str.indexOf(' ', ix1 + 1);
  
          if (ix2 == -1) {
              ix2 = str.length();
          }
  
          return str.substring(ix1 + 1, ix2);
      }
  
      protected String getWordFour(String str) {
  
          int ix0 = str.indexOf(' ');
          int ix1 = str.indexOf(' ', ix0 + 1);
          int ix2 = str.indexOf(' ', ix1 + 1);
          int ix3 = str.indexOf(' ', ix2 + 1);
  
          if (ix3 == -1) {
              ix3 = str.length();
          }
  
          return str.substring(ix2 + 1, ix3);
      }
  
      protected String getBracketedExpr(String str) {
  
          int ix0 = str.indexOf('(');
          int ix1 = str.lastIndexOf(')');
  
          System.out.println("str=" + str);
          System.out.println("ix0=" + ix0);
          System.out.println("ix1=" + ix1);
  
          return str.substring(ix0 + 1, ix1);
      }
  
       protected Type getType(String type) {
  
          System.out.println("Type=(" + type + ")");
  
          if (type.equals("varchar")) {
              return Type.STRING;
          } else if (type.equals("char")) {
              return Type.STRING;
          }
  
          return Type.VOID;
      }
  
      protected void createField(ConstantPoolGen cp, ClassGen cg, Type fieldType, String name) {
  
          System.out.println("fn=" + name);
          System.out.println("Type2=" + fieldType);
  
          FieldGen fg = new FieldGen(Constants.ACC_PUBLIC, fieldType, name, cp);
  
          cg.addField(fg.getField());
      }
  
      protected void createSetter(ConstantPoolGen cp, ClassGen cg, Type fieldType, String name,
                                String table) {
  
          InstructionList il = new InstructionList();
          MethodGen mg = new MethodGen(Constants.ACC_PUBLIC,    // access flags
                                       Type.VOID,               // return type
                                       new Type[]{ fieldType }, new String[]{ "value" },    // arg names
                                       "set" + name, table,     // method, class
                                       il, cp);
  
          mg.stripAttributes(true);
          mg.setMaxStack();
          mg.setMaxLocals();
          cg.addMethod(mg.getMethod());
      }
  
  
      //private Insert createNamedColumnsInsert(Table table, String sql ) {
      //}
      protected Insert createAllValuesInsert(Table table, String sql) {
  
          String values = getBracketedExpr(sql);
          StringTokenizer st = new StringTokenizer(values, ",");
          Vector valuesVec = new Vector();
  
          while (st.hasMoreTokens()) {
              valuesVec.add(st.nextToken().trim());
          }
  
          //TODO get columns from table.
          return new BCELInsertSingleValue(table, null, valuesVec);
      }
  
      //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);
      }
  
  
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>