hammant 01/10/29 05:24:12
Modified: apps/db/src/java/org/apache/avalon/db/driver
ApacheDBCallableStatement.java
ApacheDBConnection.java
ApacheDBPreparedStatement.java
ApacheDBStatement.java
apps/db/src/java/org/apache/avalon/db/transport
AutoCommitRequest.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
CloseRequest.java CommitRequest.java
ReadOnlyReply.java ReadOnlyRequest.java
RollbackRequest.java TransactionIsolationReply.java
TransactionIsolationRequest.java
Log:
Connection and Driver - more implemented methods
Revision Changes Path
1.2 +10 -1
jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/ApacheDBCallableStatement.java
Index: ApacheDBCallableStatement.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/ApacheDBCallableStatement.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ApacheDBCallableStatement.java 2001/10/28 14:09:20 1.1
+++ ApacheDBCallableStatement.java 2001/10/29 13:24:11 1.2
@@ -28,9 +28,18 @@
*
*
* @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class ApacheDBCallableStatement extends AbstractDriver implements
CallableStatement {
+
+ private ApacheDBConnection mApacheDBConnection;
+ private String mSQL;
+
+ public ApacheDBCallableStatement(ApacheDBConnection apacheDBConnection,
String sql) {
+ mApacheDBConnection = apacheDBConnection;
+ mSQL = sql;
+ }
+
/**
* Registers the OUT parameter in ordinal position
1.3 +27 -33
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ApacheDBConnection.java 2001/10/28 23:14:54 1.2
+++ ApacheDBConnection.java 2001/10/29 13:24:11 1.3
@@ -22,10 +22,12 @@
*
*
* @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public abstract class ApacheDBConnection extends AbstractDriver implements
Connection {
+ private boolean closed = false;
+
protected abstract Reply sendRequest(Request request) throws
SQLException;
private void handleSQLException(Reply reply) throws SQLException {
@@ -34,8 +36,7 @@
}
}
- protected void initialize(String host, int port, String url) throws
SQLException {
- }
+ protected abstract void initialize(String host, int port, String url)
throws SQLException;
/**
* Creates a <code>Statement</code> object for sending
@@ -53,10 +54,7 @@
* @exception SQLException if a database access error occurs
*/
public Statement createStatement() throws SQLException {
-
- debug();
-
- return null;
+ return new ApacheDBStatement(this);
}
/**
@@ -89,10 +87,7 @@
* @exception SQLException if a database access error occurs
*/
public PreparedStatement prepareStatement(String sql) throws
SQLException {
-
- debug();
-
- return null;
+ return new ApacheDBPreparedStatement(this, sql);
}
/**
@@ -123,10 +118,7 @@
* @exception SQLException if a database access error occurs
*/
public CallableStatement prepareCall(String sql) throws SQLException {
-
- debug();
-
- return null;
+ return new ApacheDBCallableStatement(this,sql);
}
/**
@@ -144,7 +136,7 @@
debug();
- return null;
+ return sql;
}
/**
@@ -198,7 +190,8 @@
* @see #setAutoCommit
*/
public void commit() throws SQLException {
- debug();
+ Reply reply = sendRequest(new CommitRequest());
+ handleSQLException(reply);
}
/**
@@ -211,7 +204,8 @@
* @see #setAutoCommit
*/
public void rollback() throws SQLException {
- debug();
+ Reply reply = sendRequest(new RollbackRequest());
+ handleSQLException(reply);
}
/**
@@ -226,9 +220,12 @@
* @exception SQLException if a database access error occurs
*/
public void close() throws SQLException {
- debug();
+ Reply reply = sendRequest(new CloseRequest());
+ handleSQLException(reply);
}
+ protected abstract void closeConnection() throws SQLException;
+
/**
* Tests to see if a Connection is closed.
*
@@ -236,10 +233,7 @@
* @exception SQLException if a database access error occurs
*/
public boolean isClosed() throws SQLException {
-
- debug();
-
- return false;
+ return closed;
}
/**
@@ -272,7 +266,8 @@
* @exception SQLException if a database access error occurs
*/
public void setReadOnly(boolean readOnly) throws SQLException {
- debug();
+ Reply reply = sendRequest(new ReadOnlyRequest(readOnly));
+ handleSQLException(reply);
}
/**
@@ -282,10 +277,9 @@
* @exception SQLException if a database access error occurs
*/
public boolean isReadOnly() throws SQLException {
-
- debug();
-
- return false;
+ Reply reply = sendRequest(new ReadOnlyRequest());
+ handleSQLException(reply);
+ return ((ReadOnlyReply) reply).getState();
}
/**
@@ -331,7 +325,8 @@
* @see DatabaseMetaData#supportsTransactionIsolationLevel
*/
public void setTransactionIsolation(int level) throws SQLException {
- debug();
+ Reply reply = sendRequest(new TransactionIsolationRequest(level));
+ handleSQLException(reply);
}
/**
@@ -341,10 +336,9 @@
* @exception SQLException if a database access error occurs
*/
public int getTransactionIsolation() throws SQLException {
-
- debug();
-
- return 0;
+ Reply reply = sendRequest(new TransactionIsolationRequest());
+ handleSQLException(reply);
+ return ((TransactionIsolationReply) reply).getState();
}
/**
1.2 +9 -1
jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/ApacheDBPreparedStatement.java
Index: ApacheDBPreparedStatement.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/ApacheDBPreparedStatement.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ApacheDBPreparedStatement.java 2001/10/28 14:09:20 1.1
+++ ApacheDBPreparedStatement.java 2001/10/29 13:24:11 1.2
@@ -27,9 +27,17 @@
*
*
* @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class ApacheDBPreparedStatement extends AbstractDriver implements
PreparedStatement {
+
+ private ApacheDBConnection mApacheDBConnection;
+ private String mSQL;
+
+ public ApacheDBPreparedStatement(ApacheDBConnection apacheDBConnection,
String sql) {
+ mApacheDBConnection = apacheDBConnection;
+ mSQL = sql;
+ }
/**
* Executes the SQL query in this <code>PreparedStatement</code> object
1.2 +7 -1
jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/ApacheDBStatement.java
Index: ApacheDBStatement.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/ApacheDBStatement.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ApacheDBStatement.java 2001/10/28 14:09:20 1.1
+++ ApacheDBStatement.java 2001/10/29 13:24:11 1.2
@@ -18,9 +18,15 @@
*
*
* @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class ApacheDBStatement extends AbstractDriver implements Statement {
+
+ private ApacheDBConnection m_ApacheDBConnection;
+
+ public ApacheDBStatement(ApacheDBConnection apacheDBConnection) {
+ m_ApacheDBConnection = apacheDBConnection;
+ }
/**
* Executes an SQL statement that returns a single
<code>ResultSet</code> object.
1.2 +1 -1
jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/AutoCommitRequest.java
Index: AutoCommitRequest.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/AutoCommitRequest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AutoCommitRequest.java 2001/10/28 23:14:54 1.1
+++ AutoCommitRequest.java 2001/10/29 13:24:11 1.2
@@ -15,7 +15,7 @@
*
*
* @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class AutoCommitRequest extends Request {
@@ -34,7 +34,7 @@
}
public AutoCommitRequest() {
- super(Request.AUTOCOMMITCHANGE);
+ super(Request.AUTOCOMMITQUERY);
}
}
1.3 +3 -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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Reply.java 2001/10/28 23:14:54 1.2
+++ Reply.java 2001/10/29 13:24:11 1.3
@@ -18,7 +18,7 @@
*
*
* @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public abstract class Reply implements Serializable {
@@ -26,6 +26,8 @@
public static final int EXCEPTIONREPLY = 11;
public static final int UNKNOWNREQUEST = 12;
public static final int AUTOCOMMITREPLY = 13;
+ public static final int READONLYREPLY = 14;
+ public static final int TRANSACTIONISOLATIONREPLY = 15;
private int mReplyCode;
protected Reply(int replyCode) {
1.3 +8 -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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Request.java 2001/10/28 23:14:54 1.2
+++ Request.java 2001/10/29 13:24:11 1.3
@@ -18,7 +18,7 @@
*
*
* @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public abstract class Request implements Serializable {
@@ -28,6 +28,13 @@
public static final int GENERALSQL = 113;
public static final int AUTOCOMMITCHANGE = 114;
public static final int AUTOCOMMITQUERY = 115;
+ public static final int COMMIT = 116;
+ public static final int ROLLBACK = 117;
+ public static final int CLOSE = 118;
+ public static final int READONLYCHANGE = 119;
+ public static final int READONLYQUERY = 120;
+ public static final int TRANSACTIONISOLATIONCHANGE = 121;
+ public static final int TRANSACTIONISOLATIONQUERY = 122;
private int mRequestCode;
protected Request(int requestCode) {
1.1
jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/CloseRequest.java
Index: CloseRequest.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 CloseRequest
*
*
* @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
* @version $Revision: 1.1 $
*/
public class CloseRequest extends Request {
public CloseRequest() {
super(Request.CLOSE);
}
}
1.1
jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/CommitRequest.java
Index: CommitRequest.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 CommitRequest
*
*
* @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
* @version $Revision: 1.1 $
*/
public class CommitRequest extends Request {
public CommitRequest() {
super(Request.COMMIT);
}
}
1.1
jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/ReadOnlyReply.java
Index: ReadOnlyReply.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 ReadOnlyReply
*
*
* @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
* @version $Revision: 1.1 $
*/
public class ReadOnlyReply extends Reply {
private boolean m_ReadOnlyState;
/**
* Constructor ReadOnlyReply
*
*
* @param state
*
*/
public ReadOnlyReply(boolean state) {
super(READONLYREPLY);
m_ReadOnlyState = state;
}
public boolean getState() {
return m_ReadOnlyState;
}
}
1.1
jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/ReadOnlyRequest.java
Index: ReadOnlyRequest.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 ReadOnlyRequest
*
*
* @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
* @version $Revision: 1.1 $
*/
public class ReadOnlyRequest extends Request {
private boolean mReadOnly;
/**
* Constructor ReadOnlyRequest
*
*
* @param newState
*
*/
public ReadOnlyRequest(boolean newState) {
super(Request.READONLYCHANGE);
mReadOnly = newState;
}
public ReadOnlyRequest() {
super(Request.READONLYQUERY);
}
}
1.1
jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/RollbackRequest.java
Index: RollbackRequest.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 RollbackRequest
*
*
* @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
* @version $Revision: 1.1 $
*/
public class RollbackRequest extends Request {
public RollbackRequest() {
super(Request.ROLLBACK);
}
}
1.1
jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/TransactionIsolationReply.java
Index: TransactionIsolationReply.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 TransactionIsolationReply
*
*
* @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
* @version $Revision: 1.1 $
*/
public class TransactionIsolationReply extends Reply {
private int m_TransactionIsolationState;
/**
* Constructor TransactionIsolationReply
*
*
* @param state
*
*/
public TransactionIsolationReply(int state) {
super(TRANSACTIONISOLATIONREPLY);
m_TransactionIsolationState = state;
}
public int getState() {
return m_TransactionIsolationState;
}
}
1.1
jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/transport/TransactionIsolationRequest.java
Index: TransactionIsolationRequest.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 TransactionIsolationRequest
*
*
* @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
* @version $Revision: 1.1 $
*/
public class TransactionIsolationRequest extends Request {
private int mTransactionIsolation;
/**
* Constructor TransactionIsolationRequest
*
*
* @param newState
*
*/
public TransactionIsolationRequest(int newState) {
super(Request.TRANSACTIONISOLATIONCHANGE);
mTransactionIsolation = newState;
}
public TransactionIsolationRequest() {
super(Request.TRANSACTIONISOLATIONQUERY);
}
}
1.3 +16 -1
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CommandConnection.java 2001/10/28 23:14:54 1.2
+++ CommandConnection.java 2001/10/29 13:24:12 1.3
@@ -32,7 +32,7 @@
*
*
* @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class CommandConnection extends ApacheDBConnection {
@@ -58,6 +58,21 @@
"Some IO Exception during connection creation to host/port"
+ mHost + "/" + mPort
+ " during connection creation", ioe);
}
+ }
+
+ protected void closeConnection() throws SQLException {
+ try {
+ mObjectInputStream.close();
+ mObjectOutputStream.close();
+ } catch (IOException ioe) {
+ throw new SQLException("Unable to close ObjectStrams used by
Driver");
+ } finally {
+ mObjectInputStream = null;
+ mObjectOutputStream = null;
+ mHost = null;
+ mPort = 0;
+ }
+
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>