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/transport/cmdstream/client CommandConnection.java
Date Sun, 04 Nov 2001 10:22:13 GMT
hammant     01/11/04 02:22:13

  Modified:    apps/db  build.xml
               apps/db/src/java/org/apache/avalon/db/driver
                        AvalonDBConnection.java AvalonDBDriver.java
                        AvalonDBStatement.java
               apps/db/src/java/org/apache/avalon/db/test Tester.java
               apps/db/src/java/org/apache/avalon/db/transport/cmdstream/client
                        CommandConnection.java
  Added:       apps/db/src/java/org/apache/avalon/db/driver
                        AbstractParserHelper.java
               apps/db/src/java/org/apache/avalon/db/driver/lxsql
                        LXSQLParserHelper.java
               apps/db/src/java/org/apache/avalon/db/driver/sql
                        SQLParserHelper.java
  Log:
  Parser differences glued in on client side.
  
  Revision  Changes    Path
  1.11      +1 -2      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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- build.xml	2001/11/03 15:02:07	1.10
  +++ build.xml	2001/11/04 10:22:13	1.11
  @@ -134,8 +134,7 @@
       <jar file="${build.lib}/avalon-db-testgui.jar" manifest="${manifest.dir}/test-gui.mf">
         <fileset dir="${build.classes}">
           <include name="org/apache/avalon/db/**"/>
  -        <exclude name="org/apache/avalon/db/transport/cmdstream/client/**"/>
  -        <exclude name="org/apache/avalon/db/driver/**"/>
  +        <exclude name="org/apache/avalon/db/transport/cmdstream/server/**"/>    
  
         </fileset>
       </jar>
   
  
  
  
  1.5       +9 -1      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/AvalonDBConnection.java
  
  Index: AvalonDBConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/AvalonDBConnection.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AvalonDBConnection.java	2001/11/01 08:19:28	1.4
  +++ AvalonDBConnection.java	2001/11/04 10:22:13	1.5
  @@ -42,15 +42,23 @@
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
    * @author Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">g-froehlich@gmx.de</a>
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public abstract class AvalonDBConnection extends AbstractDriver implements Connection {
   
       private boolean closed = false;
  +    private AbstractParserHelper mAbstractParserHelper;
   
       protected abstract Reply sendRequest(Request request) throws SQLException;
   
       protected abstract void initialize(String host, int port, String url) throws SQLException;
  +
  +    protected void setParserHelper(AbstractParserHelper parserHelper) {
  +        mAbstractParserHelper = parserHelper;
  +    }
  +    protected AbstractParserHelper getParserHelper() {
  +        return mAbstractParserHelper;
  +    }
   
       /**
        * Creates a <code>Statement</code> object for sending
  
  
  
  1.8       +34 -13    jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/AvalonDBDriver.java
  
  Index: AvalonDBDriver.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/AvalonDBDriver.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AvalonDBDriver.java	2001/11/03 08:21:00	1.7
  +++ AvalonDBDriver.java	2001/11/04 10:22:13	1.8
  @@ -12,11 +12,14 @@
   
   import org.apache.avalon.db.common.Version;
   import org.apache.avalon.db.utils.StringUtils;
  +import org.apache.avalon.db.driver.sql.SQLParserHelper;
  +import org.apache.avalon.db.driver.lxsql.LXSQLParserHelper;
   
   import java.sql.Driver;
   import java.sql.Connection;
   import java.sql.SQLException;
   import java.sql.DriverPropertyInfo;
  +import java.sql.DriverManager;
   
   import java.util.Properties;
   
  @@ -26,13 +29,26 @@
    *
    *
    * @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
           AvalonDBDriver extends AbstractDriver implements Driver {
   
       private static final String JDBCPREFIX = "jdbc:avalondb";
   
  +    static {
  +	    try {
  +            DriverManager.registerDriver(new AvalonDBDriver());
  +	    } catch (SQLException sqle) {
  +            System.out.println("Some problem registering AvalonDB driver statically");
  +            sqle.printStackTrace();
  +	    }
  +    }
  +
  +
  +    public AvalonDBDriver() {
  +    }
  +
       /**
        * Method connect
        *
  @@ -47,10 +63,15 @@
        */
       public Connection connect(String url, Properties info) throws SQLException {
   
  +        // jdbc:avalondb:<transport>:<syntax>:<database>:<host>:<port>
  +        //  0       1         2          3         4       5      6
  +
  +        String[] words = StringUtils.split(url,":");
  +
           String driver = null;
  -        if (url.startsWith(":cmds",JDBCPREFIX.length())) {
  +        if (words[2].equals("cmds")) {
               driver = "org.apache.avalon.db.transport.cmdstream.client.CommandConnection";
  -        } else if (url.startsWith(":glue",JDBCPREFIX.length())) {
  +        } else if (words[2].equals("glue")) {
               driver = "org.apache.avalon.db.transport.cmdstream.client.GlueConnection";
           }
           AvalonDBConnection connection = null;
  @@ -63,19 +84,19 @@
           } catch (IllegalAccessException iae) {
               throw new SQLException("Some problem accessing JDBC driver");
           }
  -        connection.initialize(getHost(url), getPort(url), url);
  -        return connection;
  -    }
  +        connection.initialize(words[5], new Integer(words[6]).intValue(), url);
   
  -    private String getHost(String url) {
  -        String[] str = StringUtils.split(url,":");
  -        return str[4];
  -    }
  +        AbstractParserHelper aph = null;
  +        if (words[3].equals("sql")) {
  +            aph = new SQLParserHelper();
  +        } else if (words[3].equals("lxsql")) {
  +            aph = new LXSQLParserHelper();
  +        }
  +        connection.setParserHelper(aph);
   
  -    private int getPort(String url) {
  -        String[] str = StringUtils.split(url,":");
  -        return new Integer(str[5]).intValue();
  +        return connection;
       }
  +
   
       /**
        * Method acceptsURL
  
  
  
  1.4       +3 -15     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/AvalonDBStatement.java
  
  Index: AvalonDBStatement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/AvalonDBStatement.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AvalonDBStatement.java	2001/11/01 08:19:28	1.3
  +++ AvalonDBStatement.java	2001/11/04 10:22:13	1.4
  @@ -33,7 +33,7 @@
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
    * @author Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">g-froehlich@gmx.de</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
   public class AvalonDBStatement extends AbstractDriver implements Statement {
   
  @@ -639,20 +639,8 @@
       }
   
       private Request getRequest(String sql) throws SQLException {
  -        Request request = null;
  -        if (sql.startsWith("INSERT")) {
  -            request = new InsertRequest(sql);
  -        } else if (sql.startsWith("UPDATE")) {
  -            request = new UpdateRequest(sql);
  -        } else if (sql.startsWith("DELETE")) {
  -            request = new DeleteRequest(sql);
  -        } else if (sql.startsWith("SELECT")) {
  -            request = new SelectRequest(sql);
  -            //TODO
  -        } else {
  -            throw new SQLException("Unknown SQL instrction (first word)");
  -        }
  -        return request;
  +        // LXSQL or SQL syntax
  +        return mAvalonDBConnection.getParserHelper().getRequest(sql);
       }
   
   }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/AbstractParserHelper.java
  
  Index: AbstractParserHelper.java
  ===================================================================
  /*
   * Created by IntelliJ IDEA.
   * User: Administrator
   * Date: Nov 4, 2001
   * Time: 10:02:42 AM
   * To change template for new class use 
   * Code Style | Class Templates options (Tools | IDE Options).
   */
  package org.apache.avalon.db.driver;
  
  import org.apache.avalon.db.transport.Request;
  
  import java.sql.SQLException;
  
  public abstract class AbstractParserHelper {
  
      protected abstract Request getRequest(String sql) throws SQLException;
  
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/lxsql/LXSQLParserHelper.java
  
  Index: LXSQLParserHelper.java
  ===================================================================
  /*
   * Created by IntelliJ IDEA.
   * User: Administrator
   * Date: Nov 4, 2001
   * Time: 10:05:06 AM
   * To change template for new class use 
   * Code Style | Class Templates options (Tools | IDE Options).
   */
  package org.apache.avalon.db.driver.lxsql;
  
  import org.apache.avalon.db.driver.AbstractParserHelper;
  import org.apache.avalon.db.transport.Request;
  import org.apache.avalon.db.transport.InsertRequest;
  import org.apache.avalon.db.transport.UpdateRequest;
  import org.apache.avalon.db.transport.DeleteRequest;
  import org.apache.avalon.db.transport.SelectRequest;
  import org.apache.avalon.db.transport.CreateTableRequest;
  
  import java.sql.SQLException;
  
  public class LXSQLParserHelper extends AbstractParserHelper {
      protected Request getRequest(String sql) throws SQLException {
          Request request = null;
          if (sql.startsWith("<insert")) {
              request = new InsertRequest(sql);
          } else if (sql.startsWith("<update")) {
              request = new UpdateRequest(sql);
          } else if (sql.startsWith("<delete")) {
              request = new DeleteRequest(sql);
          } else if (sql.startsWith("<select")) {
              request = new SelectRequest(sql);
          } else if (sql.startsWith("<create-table")) {
              request = new CreateTableRequest(sql);
              //TODO
          } else {
              throw new SQLException("Unknown SQL instuction (first term)");
          }
          return request;
      }
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/sql/SQLParserHelper.java
  
  Index: SQLParserHelper.java
  ===================================================================
  /*
   * Created by IntelliJ IDEA.
   * User: Administrator
   * Date: Nov 4, 2001
   * Time: 10:05:06 AM
   * To change template for new class use 
   * Code Style | Class Templates options (Tools | IDE Options).
   */
  package org.apache.avalon.db.driver.sql;
  
  import org.apache.avalon.db.driver.AbstractParserHelper;
  import org.apache.avalon.db.transport.Request;
  import org.apache.avalon.db.transport.InsertRequest;
  import org.apache.avalon.db.transport.UpdateRequest;
  import org.apache.avalon.db.transport.DeleteRequest;
  import org.apache.avalon.db.transport.SelectRequest;
  import org.apache.avalon.db.transport.CreateTableRequest;
  
  import java.sql.SQLException;
  
  public class SQLParserHelper extends AbstractParserHelper {
      protected Request getRequest(String sql) throws SQLException {
          Request request = null;
          if (sql.startsWith("INSERT")) {
              request = new InsertRequest(sql);
          } else if (sql.startsWith("UPDATE")) {
              request = new UpdateRequest(sql);
          } else if (sql.startsWith("DELETE")) {
              request = new DeleteRequest(sql);
          } else if (sql.startsWith("SELECT")) {
              request = new SelectRequest(sql);
          } else if (sql.startsWith("CREATE TABLE")) {
              request = new CreateTableRequest(sql);
              //TODO
          } else {
              throw new SQLException("Unknown SQL instuction (first term)");
          }
          return request;
      }
  }
  
  
  
  1.2       +12 -11    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Tester.java	2001/10/31 09:39:53	1.1
  +++ Tester.java	2001/11/04 10:22:13	1.2
  @@ -10,6 +10,7 @@
   
   import java.sql.DriverManager;
   import java.sql.Connection;
  +import java.sql.Statement;
   import java.io.File;
   
   public class Tester {
  @@ -17,14 +18,14 @@
       Connection mCon;
   
       private Tester() throws Exception {
  -        Class.forName("org.apache.avalon.db.driver.AvalonDBDriver");
  -        String url = "jdbc:avalondb:cmds:blablblahtodo";
  +        Class.forName("org.apache.avalon.db.driver.AvalonDBDriver").newInstance();
  +        String url = "jdbc:avalondb:cmds:lxsql:BlahBlah:localhost:9001";
           mCon = DriverManager.getConnection(url, "todo", "todo");
       }
   
  -    private void test(String fileName) throws Exception {
  -        File file = new File(fileName);
  -
  +    private void test() throws Exception {
  +        Statement st = mCon.createStatement();
  +        st.executeUpdate("<create-table name=\"Fred\"><columns><column name=\"wilma\"
type=\"varchar\" max=\"20\"/><column name=\"barney\" type=\"varchar\" max=\"20\"/></columns></create-table>");
       }
   
       private void close() throws Exception {
  @@ -33,18 +34,18 @@
   
   
       public static void main(String[] args) {
  -        String fileName = args[0];
  -        if (fileName != null) {
  +        //String fileName = args[0];
  +        //if (fileName != null) {
               try {
                   Tester tester = new Tester();
  -                tester.test(fileName);
  +                tester.test();
                   tester.close();
               } catch (Exception e) {
                   System.out.println("Some problem during running of test " + e.getMessage());
                   e.printStackTrace();
               }
  -        } else {
  -            System.out.println("Simgle parameter of file name containing SQL statements");
  -        }
  +       // } else {
  +        //    System.out.println("Simgle parameter of file name containing SQL statements");
  +        //}
       }
   }
  
  
  
  1.7       +3 -2      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/cmdstream/client/CommandConnection.java
  
  Index: CommandConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/cmdstream/client/CommandConnection.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CommandConnection.java	2001/11/02 12:26:37	1.6
  +++ CommandConnection.java	2001/11/04 10:22:13	1.7
  @@ -32,7 +32,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.6 $
  + * @version $Revision: 1.7 $
    */
   public class CommandConnection extends AvalonDBConnection {
   
  @@ -96,8 +96,9 @@
               throw new AvalonDBSQLException("THIS should never happen - ClassNotFoundException",
                                              cnfe);
           } catch (IOException ioe) {
  +            ioe.printStackTrace();
               throw new AvalonDBSQLException(
  -                "Some IO Exception during request handling to host/port" + mHost + "/"
+ mPort
  +                "Some IO Exception during request handling to host/port " + mHost + "/"
+ mPort
                   + " during connection creation", ioe);
           }
       }
  
  
  

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