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/services SQLParser.java
Date Sat, 03 Nov 2001 13:26:22 GMT
hammant     01/11/03 05:26:22

  Modified:    apps/db/src/conf db-assembly.xml db-config.xml
               apps/db/src/java/org/apache/avalon/db/bcel/parser
                        BCELSQLParser.java BaseBCELParser.java
               apps/db/src/java/org/apache/avalon/db/parser
                        DefaultSQLParser.java
               apps/db/src/java/org/apache/avalon/db/services
                        SQLParser.java
  Added:       apps/db/src/java/org/apache/avalon/db/bcel/parser
                        BCELSQLParser.xinfo LXSQLParser.java
                        LXSQLParser.xinfo
  Log:
  New XML based parser
  
  Revision  Changes    Path
  1.5       +4 -1      jakarta-avalon-cornerstone/apps/db/src/conf/db-assembly.xml
  
  Index: db-assembly.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/conf/db-assembly.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- db-assembly.xml	2001/11/03 10:31:21	1.4
  +++ db-assembly.xml	2001/11/03 13:26:21	1.5
  @@ -16,8 +16,10 @@
         <block class="org.apache.avalon.cornerstone.blocks.sockets.DefaultSocketManager"
name="sockets"/>
         
         <block class="org.apache.avalon.db.persistence.inmemory.NoPersistence" name="db-persistor"
/>
  +
  +      <block class="org.apache.avalon.cornerstone.blocks.dom.DOMBuilderFactory" name="dom-builder-factory"
/>
         
  -      <block class="org.apache.avalon.db.parser.DefaultSQLParser" name="sql-parser"
/>
  +      <block class="org.apache.avalon.db.bcel.parser.LXSQLParser" name="sql-parser"
/>
    
         <block class="org.apache.avalon.db.optimizer.DefaultSQLOptimizer" name="sql-optimizer"
/>
    
  @@ -25,6 +27,7 @@
       	<provide name="sockets" role="org.apache.avalon.cornerstone.services.sockets.SocketManager"/>
           <provide name="connections" 
                    role="org.apache.avalon.cornerstone.services.connection.ConnectionManager"
/>
  +        <provide name="dom-builder-factory" role="org.apache.avalon.cornerstone.services.dom.DocumentBuilderFactory"
/>                 
           <provide name="sql-parser" role="org.apache.avalon.db.services.SQLParser" />
           <provide name="sql-optimizer" role="org.apache.avalon.db.services.SQLOptimizer"
/>  
           <provide name="db-persistor" role="org.apache.avalon.db.services.DatabasePersistor"
/>
  
  
  
  1.4       +5 -0      jakarta-avalon-cornerstone/apps/db/src/conf/db-config.xml
  
  Index: db-config.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/conf/db-config.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- db-config.xml	2001/11/03 08:21:00	1.3
  +++ db-config.xml	2001/11/03 13:26:21	1.4
  @@ -43,5 +43,10 @@
       <sql-parser>TODO</sql-parser>
       <sql-optimizer>TODO</sql-optimizer>
       <db-persistor>TODO</db-persistor>    
  +    
  +    <dom-builder-factory>
  +        <domClass>org.apache.xerces.jaxp.DocumentBuilderFactoryImpl</domClass>
  +    </dom-builder-factory>
  +    
   
   </config>
  
  
  
  1.4       +5 -33     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BCELSQLParser.java	2001/11/01 09:22:15	1.3
  +++ BCELSQLParser.java	2001/11/03 13:26:21	1.4
  @@ -16,6 +16,7 @@
   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.actions.ActionException;
   import org.apache.avalon.db.transport.Request;
   import org.apache.avalon.db.transport.SelectRequest;
   import org.apache.avalon.db.transport.CreateTableRequest;
  @@ -58,25 +59,11 @@
    *
    *
    * @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 BaseBCELParser {
   
       /**
  -     * Method createAction
  -     *
  -     *
  -     * @param request
  -     *
  -     * @return
  -     *
  -     */
  -    public Action createAction(Request request) {
  -        return null;
  -    }
  -
  -
  -    /**
        * Method createSelectAction
        *
        *
  @@ -85,7 +72,7 @@
        * @return
        *
        */
  -    public Select createSelectAction(SelectRequest request) {
  +    public Select createSelectAction(SelectRequest request) throws ActionException {
           return null;
       }
   
  @@ -98,7 +85,7 @@
        * @return
        *
        */
  -    public CreateTable createCreateTableAction(CreateTableRequest request) {
  +    public CreateTable createCreateTableAction(CreateTableRequest request) throws ActionException
{
   
           String tableName = getWordThree(request.getSql());
           String values = getBracketedExpr(request.getSql());
  @@ -149,7 +136,7 @@
        * @return
        *
        */
  -    public Insert createInsertAction(InsertRequest request) {
  +    public Insert createInsertAction(InsertRequest request) throws ActionException {
   
           String tableName = getWordThree(request.getSql());
           Table table = mDatabasePersistor.getTable(tableName);
  @@ -168,19 +155,4 @@
           return null;
       }
   
  -
  -    /**
  -     * Method main
  -     *
  -     *
  -     * @param args
  -     *
  -     */
  -    public static void main(String[] args) {
  -
  -        BCELSQLParser parser = new BCELSQLParser();
  -
  -        parser.createCreateTableAction(
  -            new CreateTableRequest("CREATE TABLE Fred (Wilma varchar, Barney varchar)"));
  -    }
   }
  
  
  
  1.3       +1 -26     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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BaseBCELParser.java	2001/11/01 09:31:11	1.2
  +++ BaseBCELParser.java	2001/11/03 13:26:21	1.3
  @@ -59,7 +59,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public abstract class BaseBCELParser extends AbstractLoggable
           implements Block, SQLParser, Contextualizable, Composable, Configurable {
  @@ -72,19 +72,6 @@
   
   
       /**
  -     * Method createAction
  -     *
  -     *
  -     * @param request
  -     *
  -     * @return
  -     *
  -     */
  -    public Action createAction(Request request) {
  -        return null;
  -    }
  -
  -    /**
        * Method contextualize
        *
        *
  @@ -124,18 +111,6 @@
   
       }
   
  -    /**
  -     * Method createSelectAction
  -     *
  -     *
  -     * @param request
  -     *
  -     * @return
  -     *
  -     */
  -    public Select createSelectAction(SelectRequest request) {
  -        return null;
  -    }
   
       protected String getWordOne(String str) {
   
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcel/parser/BCELSQLParser.xinfo
  
  Index: BCELSQLParser.xinfo
  ===================================================================
  <?xml version="1.0"?>
  
  <blockinfo>
  
    <!-- section to describe block -->
    <block>
      <version>1.0</version>
    </block>
  
    <!-- services that are offered by this block -->
    <services>
      <service name="org.apache.avalon.db.services.SQLParser" version="1.0" />
    </services>
    <dependencies>
      <dependency>
        <service name="org.apache.avalon.db.services.DatabasePersistor" version="1.0"/>
      </dependency>        
  </blockinfo>
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcel/parser/LXSQLParser.java
  
  Index: LXSQLParser.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.bcel.parser;
  
  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.actions.ActionException;
  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.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;
  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.avalon.cornerstone.services.dom.DocumentBuilderFactory;
  import org.apache.bcel.Constants;
  import org.apache.bcel.generic.ConstantPoolGen;
  import org.apache.bcel.generic.Type;
  import org.apache.bcel.generic.ClassGen;
  import org.apache.bcel.generic.FieldGen;
  import org.apache.bcel.generic.InstructionList;
  import org.apache.bcel.generic.MethodGen;
  
  import org.apache.bcel.classfile.Field;
  import org.w3c.dom.DOMImplementation;
  import org.w3c.dom.Document;
  import org.w3c.dom.DocumentType;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.Node;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.ParserConfigurationException;
  import java.util.StringTokenizer;
  import java.util.Vector;
  import java.util.HashMap;
  import java.io.Reader;
  import java.io.StringReader;
  import java.io.IOException;
  
  
  /**
   * Class BCELSQLParser
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class LXSQLParser extends BaseBCELParser {
  
      protected DocumentBuilderFactory mDocumentBuilderFactory;
      protected DocumentBuilder mDocumentBuilder;
      private final String XMLHDR = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  
      /**
       * Method compose
       *
       *
       * @param componentManager
       *
       * @throws ComponentException
       *
       */
      public void compose(ComponentManager componentManager) throws ComponentException {
          mDocumentBuilderFactory =
              (DocumentBuilderFactory) componentManager.lookup(DocumentBuilderFactory.class.getName());
          try
          {
              mDocumentBuilder = mDocumentBuilderFactory.newDocumentBuilder();
          }
          catch (ParserConfigurationException pce)
          {
              throw new ComponentException("ParserConfiguration Exception in compose()",pce);
          }
      }
  
      /**
       * Method createSelectAction
       *
       *
       * @param request
       *
       * @return
       *
       */
      public Select createSelectAction(SelectRequest request) throws ActionException {
          return null;
      }
  
      /**
       * Method createCreateTableAction
       *
       *
       * @param request
       *
       * @return
       *
       */
      public CreateTable createCreateTableAction(CreateTableRequest request) throws ActionException
{
  
  //<create-table name="Fred">
  //    <columns>
  //       <column name="wilma" type="varchar" max="20"/>
  //       <column name="barney" type="varchar" max="20"/>
  //    </columns>
  //</create-table>
  
  
  
          StringReader sr = new StringReader(XMLHDR + request.getSql());
          InputSource is = new InputSource(sr);
          try
          {
              Document doc = mDocumentBuilder.parse(is);
  
              String tableName = doc.getAttributes().getNamedItem("name").getNodeValue();
  
              NodeList columnNodes = doc.getElementsByTagName("columns/column");
  
              String newTableClassName = createUniqueClassName(tableName);
              ClassGen cg = new ClassGen(newTableClassName,
                                     "org.apache.avalon.db.data.impl.AbstractTableRow",
                                     "<SQL Generated>", Constants.ACC_PUBLIC | Constants.ACC_SUPER,
                                     null);
              ConstantPoolGen cp = cg.getConstantPool();
              Vector columns = new Vector();
  
              for ( int i= 0; i < columnNodes.getLength(); i ++ ) {
                  final Node columnNode = columnNodes.item(i);
  
                  String fieldName = columnNode.getAttributes().getNamedItem("name").getNodeValue();
                  String sqlFieldType = columnNode.getAttributes().getNamedItem("type").getNodeValue();
                  Type fieldType = getType(sqlFieldType);
                  Column column = new DefaultColumn(fieldName, sqlFieldType, fieldType.toString());
  
                  columns.add(column);
                  createField(cp, cg, fieldType, fieldName);
                  createSetter(cp, cg, fieldType, fieldName, tableName);
              }
  
              //TODO need to create constrcutor suitable for superclass.
              try {
                  cg.getJavaClass().dump(tableName + "Row.class");
              } catch (java.io.IOException e) {
                  System.err.println(e);
              }
  
              CreateTable action = new BCELCreateTable(cg.getJavaClass(), tableName, columns);
              action.setDatabasePersistor(mDatabasePersistor);
              return action;
          }
          catch (SAXException se)
          {
              throw new ActionException(se.getMessage());
          }
          catch (IOException ioe)
          {
              throw new ActionException(ioe.getMessage());
          }
  
      }
  
  
      /**
       * Method createInsertAction
       *
       *
       * @param request
       *
       * @return
       *
       */
      public Insert createInsertAction(InsertRequest request) throws ActionException {
  
          //TODO
  
          return null;
      }
  
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/bcel/parser/LXSQLParser.xinfo
  
  Index: LXSQLParser.xinfo
  ===================================================================
  <?xml version="1.0"?>
  
  <blockinfo>
  
    <!-- section to describe block -->
    <block>
      <version>1.0</version>
    </block>
  
    <!-- services that are offered by this block -->
    <services>
      <service name="org.apache.avalon.db.services.SQLParser" version="1.0" />
    </services>
    <dependencies>
      <dependency>
        <service name="org.w3c.dom.DOMImplementation" version="1.0"/>
      </dependency>
      <dependency>
        <service name="org.apache.avalon.db.services.DatabasePersistor" version="1.0"/>
      </dependency>        
  </blockinfo>
  
  
  
  1.4       +5 -17     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/parser/DefaultSQLParser.java
  
  Index: DefaultSQLParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/parser/DefaultSQLParser.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultSQLParser.java	2001/10/30 17:45:14	1.3
  +++ DefaultSQLParser.java	2001/11/03 13:26:21	1.4
  @@ -15,6 +15,7 @@
   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.actions.ActionException;
   import org.apache.avalon.db.transport.Request;
   import org.apache.avalon.db.transport.SelectRequest;
   import org.apache.avalon.db.transport.CreateTableRequest;
  @@ -38,25 +39,12 @@
    *
    *
    * @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 DefaultSQLParser extends AbstractLoggable
           implements Block, SQLParser, Contextualizable, Composable, Configurable, Initializable
{
   
       /**
  -     * Method createAction
  -     *
  -     *
  -     * @param request
  -     *
  -     * @return
  -     *
  -     */
  -    public Action createAction(Request request) {
  -        return null;
  -    }
  -
  -    /**
        * Method contextualize
        *
        *
  @@ -107,15 +95,15 @@
        * @return
        *
        */
  -    public Select createSelectAction(SelectRequest request) {
  +    public Select createSelectAction(SelectRequest request) throws ActionException {
           return null;
       }
   
  -    public CreateTable createCreateTableAction(CreateTableRequest request) {
  +    public CreateTable createCreateTableAction(CreateTableRequest request) throws ActionException
{
           return null;
       }
   
  -    public Insert createInsertAction(InsertRequest request) {
  +    public Insert createInsertAction(InsertRequest request) throws ActionException {
           return null;
       }
   }
  
  
  
  1.4       +5 -15     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/services/SQLParser.java
  
  Index: SQLParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/services/SQLParser.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SQLParser.java	2001/10/30 17:45:14	1.3
  +++ SQLParser.java	2001/11/03 13:26:22	1.4
  @@ -14,6 +14,7 @@
   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.actions.ActionException;
   import org.apache.avalon.db.transport.Request;
   import org.apache.avalon.db.transport.SelectRequest;
   import org.apache.avalon.db.transport.CreateTableRequest;
  @@ -25,24 +26,13 @@
    *
    *
    * @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 SQLParser {
   
       // Resulting block may depend on ActionCache, DatabasePersistor & IndexGenerator
   
       /**
  -     * Method createAction
  -     *
  -     *
  -     * @param request
  -     *
  -     * @return
  -     *
  -     */
  -    Action createAction(Request request);
  -
  -    /**
        * Method createSelectAction
        *
        *
  @@ -51,7 +41,7 @@
        * @return
        *
        */
  -    Select createSelectAction(SelectRequest request);
  +    Select createSelectAction(SelectRequest request) throws ActionException;
   
       /**
        * Method createCreateTableAction
  @@ -62,7 +52,7 @@
        * @return
        *
        */
  -    CreateTable createCreateTableAction(CreateTableRequest request);
  +    CreateTable createCreateTableAction(CreateTableRequest request) throws ActionException;
   
       /**
        * Method createInsertAction
  @@ -73,5 +63,5 @@
        * @return
        *
        */
  -    Insert createInsertAction(InsertRequest request);
  +    Insert createInsertAction(InsertRequest request) throws ActionException;
   }
  
  
  

--
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