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/cmdstream/client CommandConnection.java
Date Sun, 28 Oct 2001 23:14:55 GMT
hammant     01/10/28 15:14:55

  Modified:    apps/db/src/java/org/apache/avalon/db/data RowHolder.java
                        Table.java
               apps/db/src/java/org/apache/avalon/db/driver
                        ApacheDBConnection.java ApacheDBDriver.java
               apps/db/src/java/org/apache/avalon/db/transport
                        ExceptionReply.java Reply.java Request.java
               apps/db/src/java/org/apache/avalon/db/transport/cmdstream/client
                        CommandConnection.java
  Added:       apps/db/src/java/org/apache/avalon/db/transport
                        AutoCommitReply.java AutoCommitRequest.java
  Log:
  Work on Connection and Driver
  
  Revision  Changes    Path
  1.2       +2 -1      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/RowHolder.java
  
  Index: RowHolder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/RowHolder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RowHolder.java	2001/10/28 20:57:39	1.1
  +++ RowHolder.java	2001/10/28 23:14:54	1.2
  @@ -15,7 +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 RowHolder extends RowHolder {
  +public interface RowHolder extends Nameable {
  +    Column[] getColumns();
   }
  
  
  
  1.3       +3 -3      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/Table.java
  
  Index: Table.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/Table.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Table.java	2001/10/28 20:57:39	1.2
  +++ Table.java	2001/10/28 23:14:54	1.3
  @@ -15,8 +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 Table extends Nameable {
  -    Column[] getColumns();
  +public interface Table extends RowHolder {
  +
   }
  
  
  
  1.2       +20 -7     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/ApacheDBConnection.java
  
  Index: ApacheDBConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/ApacheDBConnection.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ApacheDBConnection.java	2001/10/28 14:09:20	1.1
  +++ ApacheDBConnection.java	2001/10/28 23:14:54	1.2
  @@ -10,6 +10,8 @@
   
   
   
  +import org.apache.avalon.db.transport.*;
  +
   import java.sql.*;
   
   import java.util.Map;
  @@ -20,9 +22,20 @@
    *
    *
    * @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 ApacheDBConnection extends AbstractDriver implements Connection {
  +public abstract class ApacheDBConnection extends AbstractDriver implements Connection {
  +
  +    protected abstract Reply sendRequest(Request request) throws SQLException;
  +
  +    private void handleSQLException(Reply reply) throws SQLException {
  +        if (reply instanceof ExceptionReply) {
  +            throw new SQLException(((ExceptionReply) reply).getExceptionText());
  +        }
  +    }
  +
  +    protected void initialize(String host, int port, String url) throws SQLException {
  +    }
   
       /**
        * Creates a <code>Statement</code> object for sending
  @@ -158,7 +171,8 @@
        * @exception SQLException if a database access error occurs
        */
       public void setAutoCommit(boolean autoCommit) throws SQLException {
  -        debug();
  +        Reply reply = sendRequest(new AutoCommitRequest(autoCommit));
  +        handleSQLException(reply);
       }
   
       /**
  @@ -169,10 +183,9 @@
        * @see #setAutoCommit
        */
       public boolean getAutoCommit() throws SQLException {
  -
  -        debug();
  -
  -        return false;
  +        Reply reply = sendRequest(new AutoCommitRequest());
  +        handleSQLException(reply);
  +        return ((AutoCommitReply) reply).getState();
       }
   
       /**
  
  
  
  1.2       +24 -3     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/ApacheDBDriver.java
  
  Index: ApacheDBDriver.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/ApacheDBDriver.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ApacheDBDriver.java	2001/10/28 14:09:20	1.1
  +++ ApacheDBDriver.java	2001/10/28 23:14:54	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 ApacheDBDriver extends AbstractDriver implements Driver {
   
  @@ -45,9 +45,30 @@
        */
       public Connection connect(String url, Properties info) throws SQLException {
   
  -        debug();
  +        String driver = null;
  +        if (url.startsWith(":cmds",JDBCPREFIX.length())) {
  +            driver = "org.apache.avalon.db.transport.cmdstream.client.CommandConnection";
  +        }
  +        ApacheDBConnection connection = null;
  +        try {
  +            connection = (ApacheDBConnection) Class.forName(driver).newInstance();
  +        } catch (ClassNotFoundException cnfe) {
  +            throw new SQLException("JDBC Driver Class not found, check jars(s) in classpath");
  +        } catch (InstantiationException ie) {
  +            throw new SQLException("Some problem instantiating JDBC driver");
  +        } catch (IllegalAccessException iae) {
  +            throw new SQLException("Some problem accessing JDBC driver");
  +        }
  +        connection.initialize(getHost(url), getPort(url), url);
  +        return connection;
  +    }
   
  -        return null;
  +    private String getHost(String url) {
  +        return null; //TODO
  +    }
  +
  +    private int getPort(String url) {
  +        return 0; //TODO
       }
   
       /**
  
  
  
  1.2       +9 -4      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/ExceptionReply.java
  
  Index: ExceptionReply.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/ExceptionReply.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ExceptionReply.java	2001/10/28 14:09:21	1.1
  +++ ExceptionReply.java	2001/10/28 23:14:54	1.2
  @@ -18,11 +18,11 @@
    *
    *
    * @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 ExceptionReply extends Reply {
   
  -    private ActionException m_ActionException;
  +    private String m_ExceptionText;
   
       /**
        * Constructor ExceptionReply
  @@ -31,10 +31,15 @@
        * @param ae
        *
        */
  -    public ExceptionReply(ActionException ae) {
  +    public ExceptionReply(String text) {
   
           super(EXCEPTIONREPLY);
   
  -        m_ActionException = ae;
  +        m_ExceptionText = text;
       }
  +
  +    public String getExceptionText() {
  +        return m_ExceptionText;
  +    }
  +
   }
  
  
  
  1.2       +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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Reply.java	2001/10/28 14:09:21	1.1
  +++ Reply.java	2001/10/28 23:14:54	1.2
  @@ -18,13 +18,14 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public abstract class Reply implements Serializable {
   
       public static final int RESULTSET = 10;
       public static final int EXCEPTIONREPLY = 11;
       public static final int UNKNOWNREQUEST = 12;
  +    public static final int AUTOCOMMITREPLY = 13;
       private int mReplyCode;
   
       protected Reply(int replyCode) {
  
  
  
  1.2       +3 -1      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/Request.java
  
  Index: Request.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/Request.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Request.java	2001/10/28 14:09:21	1.1
  +++ Request.java	2001/10/28 23:14:54	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 abstract class Request implements Serializable {
   
  @@ -26,6 +26,8 @@
       public static final int CREATETABLE = 111;
       public static final int INSERTINTO = 112;
       public static final int GENERALSQL = 113;
  +    public static final int AUTOCOMMITCHANGE = 114;
  +    public static final int AUTOCOMMITQUERY = 115;
       private int mRequestCode;
   
       protected Request(int requestCode) {
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/AutoCommitReply.java
  
  Index: AutoCommitReply.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.transport;
  
  
  
  import org.apache.avalon.db.actions.ActionException;
  
  
  /**
   * Class AutoCommitReply
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class AutoCommitReply extends Reply {
  
      private boolean m_AutoCommitState;
  
      /**
       * Constructor AutoCommitReply
       *
       *
       * @param state
       *
       */
      public AutoCommitReply(boolean state) {
          super(AUTOCOMMITREPLY);
          m_AutoCommitState = state;
      }
  
      public boolean getState() {
          return m_AutoCommitState;
      }
  
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/AutoCommitRequest.java
  
  Index: AutoCommitRequest.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.transport;
  
  
  
  /**
   * Class AutoCommitRequest
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class AutoCommitRequest extends Request {
  
      private boolean mAutoCommit;
  
      /**
       * Constructor AutoCommitRequest
       *
       *
       * @param newState
       *
       */
      public AutoCommitRequest(boolean newState) {
          super(Request.AUTOCOMMITCHANGE);
          mAutoCommit = newState;
      }
  
      public AutoCommitRequest() {
          super(Request.AUTOCOMMITCHANGE);
      }
  
  }
  
  
  
  1.2       +4 -20     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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CommandConnection.java	2001/10/28 14:09:21	1.1
  +++ CommandConnection.java	2001/10/28 23:14:54	1.2
  @@ -13,6 +13,7 @@
   import org.apache.avalon.db.transport.Request;
   import org.apache.avalon.db.transport.Reply;
   import org.apache.avalon.db.common.ApacheDBSQLException;
  +import org.apache.avalon.db.driver.ApacheDBConnection;
   
   import java.net.URL;
   import java.net.Socket;
  @@ -31,33 +32,16 @@
    *
    *
    * @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 CommandConnection {
  +public class CommandConnection extends ApacheDBConnection {
   
       private String mHost;
       private int mPort;
       private ObjectOutputStream mObjectOutputStream;
       private ObjectInputStream mObjectInputStream;
   
  -    /**
  -     * Method createConnetion
  -     *
  -     *
  -     * @param host
  -     * @param port
  -     *
  -     * @return
  -     *
  -     * @throws SQLException
  -     *
  -     */
  -    public CommandConnection createConnetion(String host, int port) throws SQLException
{
  -        return new CommandConnection(host, port);
  -    }
  -
  -    private CommandConnection(String host, int port) throws SQLException {
  -
  +    protected void initialize(String host, int port, String url) throws SQLException {
           this.mHost = host;
           this.mPort = port;
   
  
  
  

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