You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2006/05/04 11:58:56 UTC
svn commit: r399644 - in /db/derby/code/trunk/java:
client/org/apache/derby/client/ client/org/apache/derby/client/am/
client/org/apache/derby/client/net/
testing/org/apache/derbyTesting/functionTests/suites/
testing/org/apache/derbyTesting/functionTes...
Author: kahatlen
Date: Thu May 4 02:58:54 2006
New Revision: 399644
URL: http://svn.apache.org/viewcvs?rev=399644&view=rev
Log:
DERBY-941: Add JDBC4 support for Statement Events
Implementation of statement events on the client side. Patch
contributed by V. Narayanan.
Modified:
db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java
db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java
db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection.java
db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection40.java
db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java
db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement40.java
db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java
db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement40.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCallableStatement.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPreparedStatement.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnection.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementEventsTest.java
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java?rev=399644&r1=399643&r2=399644&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java Thu May 4 02:58:54 2006
@@ -19,6 +19,7 @@
*/
package org.apache.derby.client;
+import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.apache.derby.client.net.NetXAConnection;
import org.apache.derby.jdbc.ClientBaseDataSource;
@@ -63,6 +64,13 @@
password_ = password;
listeners_ = new java.util.Vector();
+ //pass the client pooled connection instance to this
+ //instance of the NetConnection object
+ //this object is then used to pass the close and the error events
+ //that occur in the PreparedStatement object back to the
+ //PooledConnection which will then raise the events
+ //on the listeners
+
netPhysicalConnection_ = (org.apache.derby.client.net.NetConnection)
ClientDriver.getFactory().newNetConnection(
(NetLogWriter) logWriter_,
@@ -70,7 +78,8 @@
password,
ds,
-1,
- false);
+ false,
+ this);
physicalConnection_ = netPhysicalConnection_;
}
@@ -253,6 +262,43 @@
logicalConnection_ = null;
}
+ /*-----------------------------------------------------------------*/
+ /*
+ * These methods are needed to provide StatementEvent support for
+ * derby.
+ * They are actually implemented in EmbedPooledConnection40 but have
+ * a dummy implementation here
+ */
+
+ /**
+ *
+ * The onStatementClose contains the logic for raising the Statement Closed
+ * events. This method has a dummy implementation here to avoid error when
+ * this class is compiled with jdk1.4. The class the actual implementation
+ * in ClientPooledConnection40.
+ *
+ * @param statement The PreparedStatement that was closed
+ *
+ */
+ public void onStatementClose(PreparedStatement statement) {
+
+ }
+
+ /**
+ * The method contains the logic for raising the Statement error occurred
+ * events. This method has a dummy implementation here to avoid error when
+ * this class is compiled with jdk1.4. The class the actual implementation
+ * in ClientPooledConnection40.
+ *
+ * @param statement The PreparedStatement that was closed
+ * @param sqle The SQLException associated with the error that caused
+ * the invalidation of this PreparedStatement
+ */
+ public void onStatementErrorOccurred(PreparedStatement statement,
+ SQLException sqle) {
+
+ }
+
/**
* creates and returns NetXAConnection.
* Overwrite this method to create different version of NetXAConnection
@@ -273,7 +319,8 @@
password,
ds,
rmId,
- true);
+ true,
+ this);
}
}
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java?rev=399644&r1=399643&r2=399644&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java Thu May 4 02:58:54 2006
@@ -20,16 +20,33 @@
package org.apache.derby.client;
+import java.sql.PreparedStatement;
import java.sql.SQLException;
+import java.util.Enumeration;
+import java.util.Vector;
+import javax.sql.ConnectionEventListener;
+import javax.sql.StatementEventListener;
+import javax.sql.StatementEvent;
+import org.apache.derby.client.am.SqlException;
import org.apache.derby.client.net.NetXAConnection;
import org.apache.derby.jdbc.ClientBaseDataSource;
import org.apache.derby.jdbc.ClientDataSource;
-import javax.sql.StatementEventListener;
import org.apache.derby.client.am.SqlException;
import org.apache.derby.client.net.NetLogWriter;
+/**
+ *
+ * The class extends from the ClientPooledConnection class
+ * and contains implementations for the JDBC 4.0 specific
+ * methods in the javax.sql.PooledConnection interface.
+ *
+ */
+
public class ClientPooledConnection40 extends ClientPooledConnection {
-
+ //using generics to avoid casting problems
+ protected final Vector<StatementEventListener> statementEventListeners =
+ new Vector<StatementEventListener>();
+
public ClientPooledConnection40(ClientBaseDataSource ds,
org.apache.derby.client.am.LogWriter logWriter,
String user,
@@ -53,11 +70,83 @@
super(ds,logWriter);
}
+ /**
+ *
+ * Registers a StatementEventListener with this PooledConnection object.
+ * Components that wish to be informed of events associated with the
+ * PreparedStatement object created by this PooledConnection like the close
+ * or error occurred event can register a StatementEventListener with this
+ * PooledConnection object.
+ *
+ * @param listener A component that implements the StatementEventListener
+ * interface and wants to be notified of Statement closed or
+ * or Statement error occurred events
+ */
public void addStatementEventListener(StatementEventListener listener){
- throw new java.lang.UnsupportedOperationException();
+ if (logWriter_ != null) {
+ logWriter_.traceEntry(this, "addStatementEventListener", listener);
+ }
+ statementEventListeners.addElement(listener);
}
+ /**
+ *
+ * Removes the specified previously registered listener object from the list
+ * of components that would be informed of events with a PreparedStatement
+ * object.
+ *
+ * @param listener The previously registered event listener that needs to be
+ * removed from the list of components
+ */
public void removeStatementEventListener(StatementEventListener listener){
- throw new java.lang.UnsupportedOperationException();
+ if (logWriter_ != null) {
+ logWriter_.traceEntry(this, "removeConnectionEventListener", listener);
+ }
+ statementEventListeners.removeElement(listener);
+ }
+
+ /**
+ *
+ * Raise the statementClosed event for all the listeners when the
+ * corresponding events occurs.
+ *
+ * @param statement The PreparedStatement that was closed
+ *
+ */
+ public void onStatementClose(PreparedStatement statement) {
+ if (!statementEventListeners.isEmpty()) {
+ StatementEvent event = new StatementEvent(this,statement);
+ //synchronized block on statementEventListeners to make it thread
+ //safe
+ synchronized(statementEventListeners) {
+ for (StatementEventListener l : statementEventListeners) {
+ l.statementClosed(event);
+ }
+ }
+ }
}
+
+ /**
+ *
+ * Raise the statementErrorOccurred event for all the listeners when the
+ * corresponding events occurs.
+ *
+ * @param statement The PreparedStatement on which error occurred
+ * @param sqle The SQLException associated with the error that
+ * caused the invalidation of the PreparedStatements
+ *
+ */
+ public void onStatementErrorOccurred(PreparedStatement statement,
+ SQLException sqle) {
+ if (!statementEventListeners.isEmpty()) {
+ StatementEvent event = new StatementEvent(this,statement,sqle);
+ //synchronized block on statementEventListeners to make it thread
+ //safe
+ synchronized(statementEventListeners) {
+ for (StatementEventListener l : statementEventListeners) {
+ l.statementErrorOccurred(event);
+ }
+ }
+ }
+ }
}
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection.java?rev=399644&r1=399643&r2=399644&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection.java Thu May 4 02:58:54 2006
@@ -114,7 +114,8 @@
password,
dataSource,
rmId,
- isXAConn);
+ isXAConn,
+ this);
controlCon_.getNetConnection().setTransactionIsolation(
Connection.TRANSACTION_READ_UNCOMMITTED);
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection40.java?rev=399644&r1=399643&r2=399644&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection40.java Thu May 4 02:58:54 2006
@@ -20,7 +20,11 @@
package org.apache.derby.client;
+import java.sql.PreparedStatement;
import java.sql.SQLException;
+import java.util.Enumeration;
+import java.util.Vector;
+import javax.sql.StatementEvent;
import javax.sql.StatementEventListener;
import org.apache.derby.client.am.SqlException;
import org.apache.derby.client.net.NetLogWriter;
@@ -33,6 +37,11 @@
*/
public class ClientXAConnection40 extends ClientXAConnection {
+ //using generics to avoid casting problems
+ protected final Vector<StatementEventListener> statementEventListeners =
+ new Vector<StatementEventListener>();
+
+
/**
* Constructor for ClientXAConnection40.
* @param ds
@@ -60,7 +69,10 @@
* <p>
*/
public void removeStatementEventListener(StatementEventListener listener) {
- throw new UnsupportedOperationException();
+ if (logWriter_ != null) {
+ logWriter_.traceEntry(this, "removeConnectionEventListener", listener);
+ }
+ statementEventListeners.removeElement(listener);
}
/**
@@ -76,6 +88,51 @@
* <p>
*/
public void addStatementEventListener(StatementEventListener listener) {
- throw new UnsupportedOperationException();
+ if (logWriter_ != null) {
+ logWriter_.traceEntry(this, "addStatementEventListener", listener);
+ }
+ statementEventListeners.addElement(listener);
+ }
+
+ /**
+ * Raise the statementClosed event for all the listeners when the
+ * corresponding events occurs
+ * @param statement The PreparedStatement that was closed
+ */
+ public void onStatementClose(PreparedStatement statement) {
+ if (!statementEventListeners.isEmpty()) {
+ StatementEvent event = new StatementEvent(this,statement);
+ //synchronized block on statementEventListeners to make it thread
+ //safe
+ synchronized(statementEventListeners) {
+ for (StatementEventListener l : statementEventListeners) {
+ l.statementClosed(event);
+ }
+ }
+ }
}
+
+ /**
+ *
+ * Raise the statementErrorOccurred event for all the listeners when the
+ * corresponding events occurs.
+ *
+ * @param statement The PreparedStatement on which error occurred
+ * @param sqle The SQLException associated with the error that
+ * caused the invalidation of the PreparedStatements
+ *
+ */
+ public void onStatementErrorOccurred(PreparedStatement statement,
+ SQLException sqle) {
+ if (!statementEventListeners.isEmpty()) {
+ StatementEvent event = new StatementEvent(this,statement,sqle);
+ //synchronized block on statementEventListeners to make it thread
+ //safe
+ synchronized(statementEventListeners) {
+ for (StatementEventListener l : statementEventListeners) {
+ l.statementErrorOccurred(event);
+ }
+ }
+ }
+ }
}
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java?rev=399644&r1=399643&r2=399644&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java Thu May 4 02:58:54 2006
@@ -20,6 +20,7 @@
package org.apache.derby.client.am;
+import org.apache.derby.client.ClientPooledConnection;
import org.apache.derby.shared.common.reference.SQLState;
import java.io.Reader;
@@ -63,13 +64,30 @@
wasNull_ = WAS_NULL_UNSET;
}
- // Common constructor for jdbc 2 callable statements with scroll attributes.
- // Called by material statement constructor.
+ /**
+ * Common constructor for jdbc 2 callable statements with scroll attributes.
+ * Called by material statement constructor.
+ *
+ * @param agent The instance of NetAgent associated with this
+ * CallableStatement object.
+ * @param connection The connection object associated with this
+ * PreparedStatement Object.
+ * @param sql A String object that is the SQL statement to be sent
+ * to the database.
+ * @param type One of the ResultSet type constants
+ * @param concurrency One of the ResultSet concurrency constants
+ * @param holdability One of the ResultSet holdability constants
+ * @param cpc The PooledConnection object that will be used to
+ * notify the PooledConnection reference of the Error
+ * Occurred and the Close events.
+ * @throws SqlException
+ */
public CallableStatement(Agent agent,
Connection connection,
String sql,
- int type, int concurrency, int holdability) throws SqlException {
- super(agent, connection, sql, type, concurrency, holdability, java.sql.Statement.NO_GENERATED_KEYS, null);
+ int type, int concurrency, int holdability,
+ ClientPooledConnection cpc) throws SqlException {
+ super(agent, connection, sql, type, concurrency, holdability, java.sql.Statement.NO_GENERATED_KEYS, null,cpc);
initCallableStatement();
}
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement40.java?rev=399644&r1=399643&r2=399644&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement40.java Thu May 4 02:58:54 2006
@@ -28,6 +28,7 @@
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLXML;
+import org.apache.derby.client.ClientPooledConnection;
import org.apache.derby.client.am.SqlException;
import org.apache.derby.client.am.ClientMessageId;
import org.apache.derby.shared.common.reference.SQLState;
@@ -35,11 +36,29 @@
public class CallableStatement40 extends org.apache.derby.client.am.CallableStatement {
+ /**
+ * Calls the superclass constructor and passes the parameters
+ *
+ * @param agent The instance of NetAgent associated with this
+ * CallableStatement object.
+ * @param connection The connection object associated with this
+ * PreparedStatement Object.
+ * @param sql A String object that is the SQL statement to be sent
+ * to the database.
+ * @param type One of the ResultSet type constants
+ * @param concurrency One of the ResultSet concurrency constants
+ * @param holdability One of the ResultSet holdability constants
+ * @param cpc The PooledConnection object that will be used to
+ * notify the PooledConnection reference of the Error
+ * Occurred and the Close events.
+ * @throws SqlException
+ */
public CallableStatement40(Agent agent,
Connection connection,
String sql,
- int type, int concurrency, int holdability) throws SqlException {
- super(agent, connection, sql, type, concurrency, holdability);
+ int type, int concurrency, int holdability,
+ ClientPooledConnection cpc) throws SqlException {
+ super(agent, connection, sql, type, concurrency, holdability,cpc);
}
public Reader getCharacterStream(String parameterName)
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java?rev=399644&r1=399643&r2=399644&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java Thu May 4 02:58:54 2006
@@ -54,15 +54,31 @@
throws SQLException;
/**
- * This method returns an instance of CallableStatement
- * (or CallableStatement40) class which implements
- * java.sql.CallableStatement
+ * Returns an instance of org.apache.derby.client.am.CallableStatement.
+ * or CallableStatement40 which implements java.sql.CallableStatement
+ *
+ * @param agent The instance of NetAgent associated with this
+ * CallableStatement object.
+ * @param connection The connection object associated with this
+ * PreparedStatement Object.
+ * @param sql A String object that is the SQL statement to be sent
+ * to the database.
+ * @param type One of the ResultSet type constants
+ * @param concurrency One of the ResultSet concurrency constants
+ * @param holdability One of the ResultSet holdability constants
+ * @param cpc The PooledConnection object that will be used to
+ * notify the PooledConnection reference of the Error
+ * Occurred and the Close events.
+ * @return a CallableStatement object
+ * @throws SqlException
*/
CallableStatement newCallableStatement(Agent agent,
org.apache.derby.client.am.Connection connection, String sql,
- int type,int concurrency,int holdability) throws SqlException;
+ int type,int concurrency,int holdability,
+ ClientPooledConnection cpc) throws SqlException;
/**
+ * Returns an instance of PreparedStatement
* This method returns an instance of LogicalConnection
* (or LogicalConnection40) which implements java.sql.Connection.
*/
@@ -74,19 +90,64 @@
/**
* This method returns an instance of PreparedStatement
* (or PreparedStatement40) which implements java.sql.PreparedStatement
+ * It has the ClientPooledConnection as one of its parameters
+ * this is used to raise the Statement Events when the prepared
+ * statement is closed
+ *
+ * @param agent The instance of NetAgent associated with this
+ * CallableStatement object.
+ * @param connection The connection object associated with this
+ * PreparedStatement Object.
+ * @param sql A String object that is the SQL statement to be sent
+ * to the database.
+ * @param section Section
+ * @param cpc The ClientPooledConnection wraps the underlying physical
+ * connection associated with this prepared statement.
+ * It is used to pass the Statement closed and the Statement
+ * error occurred events that occur back to the
+ * ClientPooledConnection.
+ * @return a PreparedStatement object
+ * @throws SqlException
*/
PreparedStatement newPreparedStatement(Agent agent,
org.apache.derby.client.am.Connection connection,
- String sql,Section section) throws SqlException;
+ String sql,Section section,ClientPooledConnection cpc)
+ throws SqlException;
/**
- * This method returns an instance of PreparedStatement
+ * Returns an instance of PreparedStatement
* (or PreparedStatement40) which implements java.sql.PreparedStatement
+ * It has the ClientPooledConnection as one of its parameters
+ * this is used to raise the Statement Events when the prepared
+ * statement is closed
+ *
+ * @param agent The instance of NetAgent associated with this
+ * CallableStatement object.
+ * @param connection The connection object associated with this
+ * PreparedStatement Object.
+ * @param sql A String object that is the SQL statement
+ * to be sent to the database.
+ * @param type One of the ResultSet type constants.
+ * @param concurrency One of the ResultSet concurrency constants.
+ * @param holdability One of the ResultSet holdability constants.
+ * @param autoGeneratedKeys a flag indicating whether auto-generated
+ * keys should be returned.
+ * @param columnNames an array of column names indicating the columns that
+ * should be returned from the inserted row or rows.
+ * @param cpc The ClientPooledConnection wraps the underlying physical
+ * connection associated with this prepared statement
+ * it is used to pass the Statement closed and the Statement
+ * error occurred events that occur back to the
+ * ClientPooledConnection.
+ * @return a PreparedSatement object
+ * @throws SqlException
*/
PreparedStatement newPreparedStatement(Agent agent,
org.apache.derby.client.am.Connection connection,String sql,
int type,int concurrency,int holdability,int autoGeneratedKeys,
- String [] columnNames) throws SqlException;
+ String [] columnNames,ClientPooledConnection cpc)
+ throws SqlException;
+
/**
* This method returns an instance of NetConnection (or NetConnection40) class
@@ -140,6 +201,34 @@
LogWriter netLogWriter,String ipaddr,
int portNumber,org.apache.derby.jdbc.ClientBaseDataSource dataSource,
boolean isXAConn) throws SqlException;
+
+ /**
+ * This method returns an instance of NetConnection (or NetConnection40)
+ * class which extends from org.apache.derby.client.am.Connection
+ * this implements the java.sql.Connection interface
+ * This method is used to pass the ClientPooledConnection
+ * object to the NetConnection object which can then be used to pass the
+ * statement events back to the user
+ *
+ * @param netLogWriter placeholder for NetLogWriter object associated with this connection
+ * @param user user id for this connection
+ * @param password password for this connection
+ * @param dataSource The DataSource object passed from the PooledConnection
+ * object from which this constructor was called
+ * @param rmId The Resource Manager ID for XA Connections
+ * @param isXAConn true if this is a XA connection
+ * @param cpc The ClientPooledConnection object from which this
+ * NetConnection constructor was called. This is used
+ * to pass StatementEvents back to the pooledConnection
+ * object
+ * @return
+ * @throws SqlException
+ */
+ org.apache.derby.client.am.Connection newNetConnection(
+ LogWriter netLogWriter,
+ String user,String password,
+ org.apache.derby.jdbc.ClientBaseDataSource dataSource,int rmId,
+ boolean isXAConn,ClientPooledConnection cpc) throws SqlException;
/**
* This method returns an instance of NetResultSet(or NetResultSet40)
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java?rev=399644&r1=399643&r2=399644&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java Thu May 4 02:58:54 2006
@@ -25,6 +25,7 @@
import java.io.InputStream;
import java.io.Reader;
import java.sql.SQLException;
+import org.apache.derby.client.ClientPooledConnection;
import org.apache.derby.jdbc.ClientDriver;
public class PreparedStatement extends Statement
@@ -69,6 +70,10 @@
// So instead of caching the scrollableRS_, we will cache the cursorName. And re-retrieve the scrollable
// result set from the map using this cursorName every time the PreparedStatement excutes.
String positionedUpdateCursorName_ = null;
+
+ // the ClientPooledConnection object used to notify of the events that occur
+ // on this prepared statement object
+ protected final ClientPooledConnection pooledConnection_;
private void initPreparedStatement() {
@@ -109,18 +114,42 @@
}
}
- // For for JDBC 2 positioned update statements.
- // Called by material statement constructors.
+ /**
+ *
+ * The PreparedStatement constructor used for JDBC 2 positioned update
+ * statements. Called by material statement constructors.
+ * It has the ClientPooledConnection as one of its parameters
+ * this is used to raise the Statement Events when the prepared
+ * statement is closed
+ *
+ * @param agent The instance of NetAgent associated with this
+ * CallableStatement object.
+ * @param connection The connection object associated with this
+ * PreparedStatement Object.
+ * @param sql A String object that is the SQL statement to be sent
+ * to the database.
+ * @param section Section
+ * @param cpc The ClientPooledConnection wraps the underlying physical
+ * connection associated with this prepared statement.
+ * It is used to pass the Statement closed and the Statement
+ * error occurred events that occur back to the
+ * ClientPooledConnection.
+ * @throws SqlException
+ *
+ */
+
public PreparedStatement(Agent agent,
Connection connection,
String sql,
- Section section) throws SqlException {
+ Section section,ClientPooledConnection cpc)
+ throws SqlException {
super(agent, connection);
// PreparedStatement is poolable by default
isPoolable = true;
initPreparedStatement(sql, section);
+ pooledConnection_ = cpc;
}
-
+
public void resetPreparedStatement(Agent agent,
Connection connection,
String sql,
@@ -138,21 +167,49 @@
section_ = section;
}
- // Constructor for jdbc 2 prepared statements with scroll attributes.
- // Called by material statement constructors.
+ /**
+ * The PreparedStatementConstructor used for jdbc 2 prepared statements
+ * with scroll attributes. Called by material statement constructors.
+ * It has the ClientPooledConnection as one of its parameters
+ * this is used to raise the Statement Events when the prepared
+ * statement is closed
+ *
+ * @param agent The instance of NetAgent associated with this
+ * CallableStatement object.
+ * @param connection The connection object associated with this
+ * PreparedStatement Object.
+ * @param sql A String object that is the SQL statement
+ * to be sent to the database.
+ * @param type One of the ResultSet type constants.
+ * @param concurrency One of the ResultSet concurrency constants.
+ * @param holdability One of the ResultSet holdability constants.
+ * @param autoGeneratedKeys a flag indicating whether auto-generated
+ * keys should be returned.
+ * @param columnNames an array of column names indicating the columns that
+ * should be returned from the inserted row or rows.
+ * @param cpc The ClientPooledConnection wraps the underlying physical
+ * connection associated with this prepared statement
+ * it is used to pass the Statement closed and the Statement
+ * error occurred events that occur back to the
+ * ClientPooledConnection.
+ * @throws SqlException
+ */
public PreparedStatement(Agent agent,
Connection connection,
String sql,
int type, int concurrency, int holdability,
- int autoGeneratedKeys, String[] columnNames)
- throws SqlException {
+ int autoGeneratedKeys, String[] columnNames,
+ ClientPooledConnection cpc)
+ throws SqlException {
super(agent, connection, type, concurrency, holdability,
autoGeneratedKeys, columnNames);
// PreparedStatement is poolable by default
isPoolable = true;
initPreparedStatement(sql);
+ pooledConnection_ = cpc;
}
+
public void resetPreparedStatement(Agent agent,
Connection connection,
String sql,
@@ -294,8 +351,8 @@
return resultSet;
}
}
- catch ( SqlException se )
- {
+ catch ( SqlException se ) {
+ checkStatementValidity(se);
throw se.getSQLException();
}
}
@@ -323,8 +380,8 @@
return updateValue;
}
}
- catch ( SqlException se )
- {
+ catch ( SqlException se ) {
+ checkStatementValidity(se);
throw se.getSQLException();
}
}
@@ -1140,8 +1197,8 @@
return b;
}
}
- catch ( SqlException se )
- {
+ catch ( SqlException se ) {
+ checkStatementValidity(se);
throw se.getSQLException();
}
}
@@ -2029,6 +2086,8 @@
* @see org.apache.derby.client.am.Statement#markClosed(boolean)
*/
protected void markClosed(boolean removeListener){
+ if(pooledConnection_ != null)
+ pooledConnection_.onStatementClose(this);
super.markClosed(removeListener);
if (parameterMetaData_ != null) {
@@ -2113,4 +2172,27 @@
}
}
}
+
+ /*
+ * Method calls onStatementError occurred on the
+ * BrokeredConnectionControl class after checking the
+ * SQLState of the SQLException thrown.
+ * @param sqle SqlException
+ * @throws java.sql.SQLException
+ */
+
+ private void checkStatementValidity(SqlException sqle)
+ throws SQLException {
+ //check if the statement is already closed
+ //This might be caused because the connection associated
+ //with this prepared statement has been closed marking
+ //its associated prepared statements also as
+ //closed
+
+ if(pooledConnection_!=null && isClosed()){
+ pooledConnection_.onStatementErrorOccurred(this,
+ sqle.getSQLException());
+ }
+ }
+
}
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement40.java?rev=399644&r1=399643&r2=399644&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement40.java Thu May 4 02:58:54 2006
@@ -26,26 +26,74 @@
import java.sql.SQLXML;
import java.io.Reader;
import java.io.InputStream;
+import org.apache.derby.client.ClientPooledConnection;
import org.apache.derby.client.am.SqlException;
import org.apache.derby.client.am.ClientMessageId;
import org.apache.derby.shared.common.reference.SQLState;
public class PreparedStatement40 extends org.apache.derby.client.am.PreparedStatement{
+ /**
+ * The PreparedStatement used for JDBC 4 positioned update statements.
+ * Called by material statement constructors.
+ * It has the ClientPooledConnection as one of its parameters
+ * this is used to raise the Statement Events when the prepared
+ * statement is closed
+ *
+ * @param agent The instance of NetAgent associated with this
+ * CallableStatement object.
+ * @param connection The connection object associated with this
+ * PreparedStatement Object.
+ * @param sql A String object that is the SQL statement to be sent
+ * to the database.
+ * @param section Section
+ * @param cpc The ClientPooledConnection wraps the underlying physical
+ * connection associated with this prepared statement.
+ * It is used to pass the Statement closed and the Statement
+ * error occurred events that occur back to the
+ * ClientPooledConnection.
+ * @throws SqlException
+ */
public PreparedStatement40(Agent agent,
Connection connection,
String sql,
- Section section) throws SqlException {
- super(agent, connection,sql,section);
+ Section section,ClientPooledConnection cpc) throws SqlException {
+ super(agent, connection,sql,section,cpc);
}
+ /**
+ * The PreparedStatementConstructor used for jdbc 4 prepared statements
+ * with scroll attributes. Called by material statement constructors.
+ * It has the ClientPooledConnection as one of its parameters
+ * this is used to raise the Statement Events when the prepared
+ * statement is closed
+ *
+ * @param agent The instance of NetAgent associated with this
+ * CallableStatement object.
+ * @param connection The connection object associated with this
+ * PreparedStatement Object.
+ * @param sql A String object that is the SQL statement
+ * to be sent to the database.
+ * @param type One of the ResultSet type constants.
+ * @param concurrency One of the ResultSet concurrency constants.
+ * @param holdability One of the ResultSet holdability constants.
+ * @param autoGeneratedKeys a flag indicating whether auto-generated
+ * keys should be returned.
+ * @param columnNames an array of column names indicating the columns that
+ * should be returned from the inserted row or rows.
+ * @param cpc The ClientPooledConnection wraps the underlying physical
+ * connection associated with this prepared statement
+ * it is used to pass the Statement closed and the Statement
+ * error occurred events that occur back to the
+ * ClientPooledConnection.
+ * @throws SqlException
+ */
public PreparedStatement40(Agent agent,
Connection connection,
String sql,
- int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNames) throws SqlException {
- super(agent, connection, sql, type, concurrency, holdability, autoGeneratedKeys, columnNames);
+ int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNames,ClientPooledConnection cpc) throws SqlException {
+ super(agent, connection, sql, type, concurrency, holdability, autoGeneratedKeys, columnNames, cpc);
}
-
public void setRowId(int parameterIndex, RowId x) throws SQLException{
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java?rev=399644&r1=399643&r2=399644&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java Thu May 4 02:58:54 2006
@@ -64,14 +64,29 @@
return new ClientPooledConnection(ds,logWriter,user,password,rmId);
}
/**
- * Returns an instance of org.apache.derby.client.am.CallableStatement
+ * Returns an instance of org.apache.derby.client.am.CallableStatement.
+ *
+ * @param agent The instance of NetAgent associated with this
+ * CallableStatement object.
+ * @param connection The connection object associated with this
+ * PreparedStatement Object.
+ * @param sql A String object that is the SQL statement to be sent
+ * to the database.
+ * @param type One of the ResultSet type constants
+ * @param concurrency One of the ResultSet concurrency constants
+ * @param holdability One of the ResultSet holdability constants
+ * @param cpc The PooledConnection object that will be used to
+ * notify the PooledConnection reference of the Error
+ * Occurred and the Close events.
+ * @return a CallableStatement object
+ * @throws SqlException
*/
public CallableStatement newCallableStatement(Agent agent,
org.apache.derby.client.am.Connection connection,
String sql,int type,int concurrency,
- int holdability) throws SqlException {
+ int holdability,ClientPooledConnection cpc) throws SqlException {
return new CallableStatement(agent,connection,sql,type,
- concurrency,holdability);
+ concurrency,holdability,cpc);
}
/**
@@ -85,24 +100,74 @@
}
/**
- * returns an instance of org.apache.derby.client.am.PreparedStatement
+ * This method returns an instance of PreparedStatement
+ * which implements java.sql.PreparedStatement. It has the
+ * ClientPooledConnection as one of its parameters
+ * this is used to raise the Statement Events when the prepared
+ * statement is closed.
+ *
+ * @param agent The instance of NetAgent associated with this
+ * CallableStatement object.
+ * @param connection The connection object associated with this
+ * PreparedStatement Object.
+ * @param sql A String object that is the SQL statement to be sent
+ * to the database.
+ * @param section Section
+ * @param cpc The ClientPooledConnection wraps the underlying physical
+ * connection associated with this prepared statement.
+ * It is used to pass the Statement closed and the Statement
+ * error occurred events that occur back to the
+ * ClientPooledConnection.
+ * @returns a PreparedStatement object
+ * @throws SqlException
*/
public PreparedStatement newPreparedStatement(Agent agent,
org.apache.derby.client.am.Connection connection,
- String sql,Section section) throws SqlException {
- return new PreparedStatement(agent,connection,sql,section);
+ String sql,Section section,ClientPooledConnection cpc)
+ throws SqlException {
+ return new PreparedStatement(agent,connection,sql,section,cpc);
}
- /**
- * returns an instance of org.apache.derby.client.am.PreparedStatement
+
+ /**
+ *
+ * This method returns an instance of PreparedStatement
+ * which implements java.sql.PreparedStatement.
+ * It has the ClientPooledConnection as one of its parameters
+ * this is used to raise the Statement Events when the prepared
+ * statement is closed.
+ *
+ * @param agent The instance of NetAgent associated with this
+ * CallableStatement object.
+ * @param connection The connection object associated with this
+ * PreparedStatement Object.
+ * @param sql A String object that is the SQL statement
+ * to be sent to the database.
+ * @param type One of the ResultSet type constants.
+ * @param concurrency One of the ResultSet concurrency constants.
+ * @param holdability One of the ResultSet holdability constants.
+ * @param autoGeneratedKeys a flag indicating whether auto-generated
+ * keys should be returned.
+ * @param columnNames an array of column names indicating the columns that
+ * should be returned from the inserted row or rows.
+ * @param cpc The ClientPooledConnection wraps the underlying physical
+ * connection associated with this prepared statement
+ * it is used to pass the Statement closed and the Statement
+ * error occurred events that occur back to the
+ * ClientPooledConnection.
+ * @returns a PreparedStatement object
+ * @throws SqlException
+ *
*/
public PreparedStatement newPreparedStatement(Agent agent,
org.apache.derby.client.am.Connection connection,
String sql,int type,int concurrency,int holdability,
- int autoGeneratedKeys,String [] columnNames)
+ int autoGeneratedKeys,String [] columnNames,
+ ClientPooledConnection cpc)
throws SqlException {
return new PreparedStatement(agent,connection,sql,type,concurrency,
- holdability,autoGeneratedKeys,columnNames);
+ holdability,autoGeneratedKeys,columnNames,cpc);
}
+
/**
* returns an instance of org.apache.derby.client.net.NetConnection
*/
@@ -159,6 +224,33 @@
return (org.apache.derby.client.am.Connection)
new NetConnection((NetLogWriter)netLogWriter,ipaddr,portNumber,dataSource,
isXAConn);
+ }
+ /**
+ * Returns an instance of org.apache.derby.client.net.NetConnection.
+ * @param netLogWriter Placeholder for NetLogWriter object associated
+ * with this connection.
+ * @param user user id for this connection.
+ * @param password password for this connection.
+ * @param dataSource The DataSource object passed from the PooledConnection
+ * object from which this constructor was called.
+ * @param rmId The Resource Manager ID for XA Connections
+ * @param isXAConn true if this is a XA connection
+ * @param cpc The ClientPooledConnection object from which this
+ * NetConnection constructor was called. This is used to
+ * pass StatementEvents back to the pooledConnection
+ * object.
+ * @returns a org.apache.derby.client.am.Connection object
+ * @throws SqlException
+ */
+ public org.apache.derby.client.am.Connection newNetConnection(
+ org.apache.derby.client.am.LogWriter netLogWriter,String user,
+ String password,
+ org.apache.derby.jdbc.ClientBaseDataSource dataSource,
+ int rmId,boolean isXAConn,
+ ClientPooledConnection cpc) throws SqlException {
+ return (org.apache.derby.client.am.Connection)
+ (new NetConnection((NetLogWriter)netLogWriter,user,password,dataSource,rmId,
+ isXAConn,cpc));
}
/**
* returns an instance of org.apache.derby.client.net.NetResultSet
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java?rev=399644&r1=399643&r2=399644&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java Thu May 4 02:58:54 2006
@@ -75,17 +75,51 @@
return new ClientPooledConnection40(ds,logWriter,user,password,rmId);
}
/**
- * Returns an instance of org.apache.derby.client.am.CallableStatement40
+ * Returns an instance of org.apache.derby.client.am.CallableStatement.
+ *
+ * @param agent The instance of NetAgent associated with this
+ * CallableStatement object.
+ * @param connection The connection object associated with this
+ * PreparedStatement Object.
+ * @param sql A String object that is the SQL statement to be sent
+ * to the database.
+ * @param type One of the ResultSet type constants
+ * @param concurrency One of the ResultSet concurrency constants
+ * @param holdability One of the ResultSet holdability constants
+ * @param cpc The PooledConnection object that will be used to
+ * notify the PooledConnection reference of the Error
+ * Occurred and the Close events.
+ * @return a CallableStatement object
+ * @throws SqlException
*/
public CallableStatement newCallableStatement(Agent agent,
org.apache.derby.client.am.Connection connection,
String sql,int type,int concurrency,
- int holdability) throws SqlException {
+ int holdability,ClientPooledConnection cpc) throws SqlException {
return new CallableStatement40(agent,connection,sql,type,concurrency,
- holdability);
+ holdability,cpc);
}
-
/**
+ * This method returns an instance of PreparedStatement
+ * which implements java.sql.PreparedStatement. It has the
+ * ClientPooledConnection as one of its parameters
+ * this is used to raise the Statement Events when the prepared
+ * statement is closed.
+ *
+ * @param agent The instance of NetAgent associated with this
+ * CallableStatement object.
+ * @param connection The connection object associated with this
+ * PreparedStatement Object.
+ * @param sql A String object that is the SQL statement to be sent
+ * to the database.
+ * @param section Section
+ * @param cpc The ClientPooledConnection wraps the underlying physical
+ * connection associated with this prepared statement.
+ * It is used to pass the Statement closed and the Statement
+ * error occurred events that occur back to the
+ * ClientPooledConnection.
+ * @returns a PreparedStatement object
+ * @throws SqlException
* Returns an instance of org.apache.derby.client.am.LogicalConnection40
*/
public LogicalConnection newLogicalConnection(
@@ -100,20 +134,51 @@
*/
public PreparedStatement newPreparedStatement(Agent agent,
org.apache.derby.client.am.Connection connection,
- String sql,Section section) throws SqlException {
- return new PreparedStatement40(agent,connection,sql,section);
+ String sql,Section section,ClientPooledConnection cpc)
+ throws SqlException {
+ return new PreparedStatement40(agent,connection,sql,section,cpc);
}
+
/**
- * returns an instance of org.apache.derby.client.am.PreparedStatement40
+ *
+ * This method returns an instance of PreparedStatement
+ * which implements java.sql.PreparedStatement.
+ * It has the ClientPooledConnection as one of its parameters
+ * this is used to raise the Statement Events when the prepared
+ * statement is closed.
+ *
+ * @param agent The instance of NetAgent associated with this
+ * CallableStatement object.
+ * @param connection The connection object associated with this
+ * PreparedStatement Object.
+ * @param sql A String object that is the SQL statement
+ * to be sent to the database.
+ * @param type One of the ResultSet type constants.
+ * @param concurrency One of the ResultSet concurrency constants.
+ * @param holdability One of the ResultSet holdability constants.
+ * @param autoGeneratedKeys a flag indicating whether auto-generated
+ * keys should be returned.
+ * @param columnNames an array of column names indicating the columns that
+ * should be returned from the inserted row or rows.
+ * @param cpc The ClientPooledConnection wraps the underlying physical
+ * connection associated with this prepared statement
+ * it is used to pass the Statement closed and the Statement
+ * error occurred events that occur back to the
+ * ClientPooledConnection.
+ * @returns a PreparedStatement object
+ * @throws SqlException
+ *
*/
public PreparedStatement newPreparedStatement(Agent agent,
org.apache.derby.client.am.Connection connection,
String sql,int type,int concurrency,
int holdability,int autoGeneratedKeys,
- String [] columnNames) throws SqlException {
+ String [] columnNames,ClientPooledConnection cpc)
+ throws SqlException {
return new PreparedStatement40(agent,connection,sql,type,concurrency,
- holdability,autoGeneratedKeys,columnNames);
+ holdability,autoGeneratedKeys,columnNames,cpc);
}
+
/**
* returns an instance of org.apache.derby.client.net.NetConnection40
@@ -171,6 +236,33 @@
return (org.apache.derby.client.am.Connection)
(new NetConnection40((NetLogWriter)netLogWriter,ipaddr,portNumber,dataSource,
isXAConn));
+ }
+ /**
+ * Returns an instance of org.apache.derby.client.net.NetConnection.
+ * @param netLogWriter placeholder for NetLogWriter object associated with this connection
+ * @param user user id for this connection
+ * @param password password for this connection
+ * @param dataSource The DataSource object passed from the PooledConnection
+ * object from which this constructor was called
+ * @param rmId The Resource Manager ID for XA Connections
+ * @param isXAConn true if this is a XA connection
+ * @param cpc The ClientPooledConnection object from which this
+ * NetConnection constructor was called. This is used
+ * to pass StatementEvents back to the pooledConnection
+ * object
+ * @returns a org.apache.derby.client.am.Connection object
+ * @throws SqlException
+ */
+ public org.apache.derby.client.am.Connection newNetConnection(
+ org.apache.derby.client.am.LogWriter netLogWriter,String user,
+ String password,
+ org.apache.derby.jdbc.ClientBaseDataSource dataSource,
+ int rmId,boolean isXAConn,ClientPooledConnection cpc)
+ throws SqlException {
+ return (org.apache.derby.client.am.Connection)
+ (new NetConnection40((NetLogWriter)netLogWriter,user,password,dataSource,rmId,
+ isXAConn,cpc));
+
}
/**
* returns an instance of org.apache.derby.client.net.NetResultSet
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCallableStatement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCallableStatement.java?rev=399644&r1=399643&r2=399644&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCallableStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCallableStatement.java Thu May 4 02:58:54 2006
@@ -26,6 +26,7 @@
import org.apache.derby.client.am.SqlException;
import org.apache.derby.jdbc.ClientDriver;
import org.apache.derby.client.am.ClientJDBCObjectFactory;
+import org.apache.derby.client.ClientPooledConnection;
public class NetCallableStatement extends NetPreparedStatement
implements MaterialPreparedStatement {
@@ -71,9 +72,10 @@
String sql,
int type,
int concurrency,
- int holdability) throws SqlException {
+ int holdability,
+ ClientPooledConnection cpc) throws SqlException {
this(ClientDriver.getFactory().newCallableStatement(netAgent,
- netConnection, sql, type, concurrency, holdability),
+ netConnection, sql, type, concurrency, holdability,cpc),
netAgent,
netConnection);
}
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java?rev=399644&r1=399643&r2=399644&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java Thu May 4 02:58:54 2006
@@ -35,6 +35,7 @@
import org.apache.derby.jdbc.ClientBaseDataSource;
import org.apache.derby.jdbc.ClientDataSource;
import org.apache.derby.jdbc.ClientDriver;
+import org.apache.derby.client.ClientPooledConnection;
import org.apache.derby.shared.common.reference.SQLState;
@@ -45,6 +46,12 @@
new MessageUtil(SqlException.CLIENT_MESSAGE_RESOURCE_NAME);
protected NetAgent netAgent_;
+ //contains a reference to the PooledConnection from which this created
+ //It then passes this reference to the PreparedStatement created from it
+ //The PreparedStatement then uses this to pass the close and the error
+ //occurred conditions back to the PooledConnection which can then throw the
+ //appropriate events.
+ protected ClientPooledConnection pooledConnection_ = null;
// For XA Transaction
@@ -236,6 +243,39 @@
productID_ = targetSrvrlslv_;
super.completeConnect();
}
+
+ // For JDBC 2 Connections
+ /**
+ * This constructor is called from the ClientPooledConnection object
+ * to enable the NetConnection to pass <code>this</code> on to the associated
+ * prepared statement object thus enabling the prepared statement object
+ * to inturn raise the statement events to the ClientPooledConnection object
+ * @param netLogWriter NetLogWriter object associated with this connection
+ * @param user user id for this connection
+ * @param password password for this connection
+ * @param dataSource The DataSource object passed from the PooledConnection
+ * object from which this constructor was called
+ * @param rmId The Resource manager ID for XA Connections
+ * @param isXAConn true if this is a XA connection
+ * @param cpc The ClientPooledConnection object from which this
+ * NetConnection constructor was called. This is used
+ * to pass StatementEvents back to the pooledConnection
+ * object
+ * @throws SqlException
+ */
+
+ public NetConnection(NetLogWriter netLogWriter,
+ String user,
+ String password,
+ org.apache.derby.jdbc.ClientBaseDataSource dataSource,
+ int rmId,
+ boolean isXAConn,
+ ClientPooledConnection cpc) throws SqlException {
+ super(netLogWriter, user, password, isXAConn, dataSource);
+ netAgent_ = (NetAgent) super.agent_;
+ initialize(user, password, dataSource, rmId, isXAConn);
+ this.pooledConnection_=cpc;
+ }
private void initialize(String user,
String password,
@@ -952,11 +992,16 @@
protected PreparedStatement newPositionedUpdatePreparedStatement_(String sql,
org.apache.derby.client.am.Section section) throws SqlException {
- return new NetPreparedStatement(netAgent_, this, sql, section).preparedStatement_;
+ //passing the pooledConnection_ object which will be used to raise
+ //StatementEvents to the PooledConnection
+ return new NetPreparedStatement(netAgent_, this, sql, section,pooledConnection_).preparedStatement_;
}
protected PreparedStatement newPreparedStatement_(String sql, int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNames) throws SqlException {
- return new NetPreparedStatement(netAgent_, this, sql, type, concurrency, holdability, autoGeneratedKeys, columnNames).preparedStatement_;
+
+ //passing the pooledConnection_ object which will be used to raise
+ //StatementEvents to the PooledConnection
+ return new NetPreparedStatement(netAgent_, this, sql, type, concurrency, holdability, autoGeneratedKeys, columnNames,pooledConnection_).preparedStatement_;
}
protected void resetPreparedStatement_(PreparedStatement ps,
@@ -971,7 +1016,9 @@
protected CallableStatement newCallableStatement_(String sql, int type, int concurrency, int holdability) throws SqlException {
- return new NetCallableStatement(netAgent_, this, sql, type, concurrency, holdability).callableStatement_;
+ //passing the pooledConnection_ object which will be used to raise
+ //StatementEvents to the PooledConnection
+ return new NetCallableStatement(netAgent_, this, sql, type, concurrency, holdability,pooledConnection_).callableStatement_;
}
protected void resetCallableStatement_(CallableStatement cs,
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java?rev=399644&r1=399643&r2=399644&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java Thu May 4 02:58:54 2006
@@ -37,6 +37,7 @@
import java.util.Properties;
import org.apache.derby.impl.jdbc.Util;
import org.apache.derby.jdbc.InternalDriver;
+import org.apache.derby.client.ClientPooledConnection;
import org.apache.derby.client.am.ClientMessageId;
import org.apache.derby.shared.common.reference.SQLState;
@@ -87,6 +88,39 @@
org.apache.derby.jdbc.ClientBaseDataSource dataSource,
boolean isXAConn) throws SqlException{
super(netLogWriter,ipaddr,portNumber,dataSource,isXAConn);
+ }
+
+
+ /**
+ * The constructor for the NetConnection40 class which contains
+ * implementations of JDBC 4.0 specific methods in the java.sql.Connection
+ * interface. This constructor is called from the ClientPooledConnection object
+ * to enable the NetConnection to pass <code>this</code> on to the associated
+ * prepared statement object thus enabling the prepared statement object
+ * to inturn raise the statement events to the ClientPooledConnection object.
+ *
+ * @param netLogWriter NetLogWriter object associated with this connection.
+ * @param user user id for this connection.
+ * @param password password for this connection.
+ * @param dataSource The DataSource object passed from the PooledConnection
+ * object from which this constructor was called.
+ * @param rmId The Resource manager ID for XA Connections
+ * @param isXAConn true if this is a XA connection.
+ * @param cpc The ClientPooledConnection object from which this
+ * NetConnection constructor was called. This is used
+ * to pass StatementEvents back to the pooledConnection
+ * object.
+ * @throws SqlException
+ */
+
+ public NetConnection40(NetLogWriter netLogWriter,
+ String user,
+ String password,
+ org.apache.derby.jdbc.ClientBaseDataSource dataSource,
+ int rmId,
+ boolean isXAConn,
+ ClientPooledConnection cpc) throws SqlException{
+ super(netLogWriter,user,password,dataSource,rmId,isXAConn,cpc);
}
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPreparedStatement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPreparedStatement.java?rev=399644&r1=399643&r2=399644&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPreparedStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPreparedStatement.java Thu May 4 02:58:54 2006
@@ -25,6 +25,7 @@
import org.apache.derby.client.am.SqlException;
import org.apache.derby.jdbc.ClientDriver;
import org.apache.derby.client.am.ClientJDBCObjectFactory;
+import org.apache.derby.client.ClientPooledConnection;
public class NetPreparedStatement extends NetStatement
@@ -55,14 +56,45 @@
preparedStatement_.materialPreparedStatement_ = this;
}
- // Called by abstract Connection.prepareStatment().newPreparedStatement() for jdbc 2 prepared statements
- // with scroll attributes.
- NetPreparedStatement(NetAgent netAgent, NetConnection netConnection, String sql, int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNames) throws SqlException {
+ /**
+ *
+ * The constructor for the NetPreparedStatement class. Called by abstract
+ * Connection.prepareStatment().newPreparedStatement()
+ * for jdbc 2 prepared statements with scroll attributes.
+ * It has the ClientPooledConnection as one of its parameters
+ * this is used to raise the Statement Events when the prepared
+ * statement is closed.
+ *
+ * @param agent The instance of NetAgent associated with this
+ * CallableStatement object.
+ * @param netNonnection The connection object associated with this
+ * PreparedStatement Object.
+ * @param sql A String object that is the SQL statement
+ * to be sent to the database.
+ * @param type One of the ResultSet type constants.
+ * @param concurrency One of the ResultSet concurrency constants.
+ * @param holdability One of the ResultSet holdability constants.
+ * @param autoGeneratedKeys a flag indicating whether auto-generated
+ * keys should be returned.
+ * @param columnNames A String array of column names indicating
+ * the columns that should be returned
+ * from the inserted row or rows.
+ * @param cpc The ClientPooledConnection wraps the underlying physical
+ * connection associated with this prepared statement
+ * it is used to pass the Statement closed and the Statement
+ * error occurred events that occur back to the
+ * ClientPooledConnection.
+ * @returns a PreparedStatement object
+ * @throws SqlException
+ *
+ */
+ NetPreparedStatement(NetAgent netAgent, NetConnection netConnection, String sql, int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNames, ClientPooledConnection cpc) throws SqlException {
this(ClientDriver.getFactory().newPreparedStatement(netAgent,
netConnection, sql, type, concurrency, holdability,
- autoGeneratedKeys, columnNames),
+ autoGeneratedKeys, columnNames, cpc),
netAgent,
- netConnection);
+ netConnection
+ );
}
void resetNetPreparedStatement(NetAgent netAgent, NetConnection netConnection, String sql, int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNames) throws SqlException {
@@ -70,13 +102,35 @@
resetNetPreparedStatement(preparedStatement_, netAgent, netConnection);
}
- // For JDBC 3.0 positioned updates.
+ /**
+ *
+ * The constructor for the NetPreparedStatement class. For JDBC 3.0
+ * positioned updates.It has the ClientPooledConnection as one of
+ * its parameters this is used to raise the Statement Events when the
+ * prepared statement is closed.
+ *
+ * @param agent The instance of NetAgent associated with this
+ * CallableStatement object.
+ * @param netNonnection The connection object associated with this
+ * PreparedStatement Object.
+ * @param sql A String object that is the SQL statement to be
+ * sent to the database.
+ * @param section Section
+ * @param cpc The ClientPooledConnection wraps the underlying physical
+ * connection associated with this prepared statement
+ * it is used to pass the Statement closed and the Statement
+ * error occurred events that occur back to the
+ * ClientPooledConnection
+ * @throws SqlException
+ *
+ */
NetPreparedStatement(NetAgent netAgent,
NetConnection netConnection,
String sql,
- Section section) throws SqlException {
+ Section section,ClientPooledConnection cpc)
+ throws SqlException {
this(ClientDriver.getFactory().newPreparedStatement(netAgent,
- netConnection, sql, section),
+ netConnection, sql, section,cpc),
netAgent,
netConnection);
}
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnection.java?rev=399644&r1=399643&r2=399644&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnection.java Thu May 4 02:58:54 2006
@@ -30,20 +30,46 @@
import org.apache.derby.client.am.SqlException;
import org.apache.derby.client.am.Statement;
+import org.apache.derby.client.ClientPooledConnection;
+
import org.apache.derby.jdbc.ClientDriver;
public class NetXAConnection {
private NetConnection netCon;
//---------------------constructors/finalizer---------------------------------
// For XA Connections
+ /**
+ *
+ * The construcor for the NetXAConnection. The parameter
+ * is set to <code>this</code> from ClientXAConnection when
+ * it creates an instance of NetXAConnection. This is then
+ * passed on the underlying NetConnection constructor and is
+ * used to raise StatementEvents from any PreparedStatement that
+ * would be created from that NetConnection.
+ *
+ * @param netLogWriter NetLogWriter object associated with this connection
+ * @param user user id for this connection
+ * @param password password for this connection
+ * @param dataSource The DataSource object passed from the ClientXAConnection
+ * object from which this constructor was called
+ * @param rmId The Resource manager ID for XA Connections
+ * @param isXAConn true if this is a XA connection
+ * @param cpc The ClientPooledConnection object from which this
+ * NetConnection constructor was called. This is used
+ * to pass StatementEvents back to the pooledConnection
+ * object
+ * @throws SqlException
+ *
+ */
public NetXAConnection(NetLogWriter netLogWriter,
String user,
String password,
org.apache.derby.jdbc.ClientBaseDataSource dataSource,
int rmId,
- boolean isXAConn) throws SqlException {
+ boolean isXAConn,
+ ClientPooledConnection cpc) throws SqlException {
netCon = createNetConnection (netLogWriter, user, password,
- dataSource, rmId, isXAConn);
+ dataSource, rmId, isXAConn,cpc);
checkPlatformVersion();
}
@@ -213,24 +239,32 @@
}
/**
+ *
* Creates NetConnection for the supported version of jdbc.
* This method can be overwritten to return NetConnection
* of the supported jdbc version.
- * @param netLogWriter
- * @param user
- * @param password
- * @param dataSource
- * @param rmId
- * @param isXAConn
+ * @param netLogWriter NetLogWriter object associated with this connection
+ * @param user user id for this connection
+ * @param password password for this connection
+ * @param dataSource The DataSource object passed from the ClientXAConnection
+ * object from which this constructor was called
+ * @param rmId The Resource manager ID for XA Connections
+ * @param isXAConn true if this is a XA connection
+ * @param cpc The ClientPooledConnection object from which this
+ * NetConnection constructor was called. This is used
+ * to pass StatementEvents back to the pooledConnection
+ * object
* @return NetConnection
+ *
*/
protected NetConnection createNetConnection (NetLogWriter netLogWriter,
String user,
String password,
org.apache.derby.jdbc.ClientBaseDataSource dataSource,
int rmId,
- boolean isXAConn) throws SqlException {
+ boolean isXAConn,
+ ClientPooledConnection cpc) throws SqlException {
return (NetConnection)ClientDriver.getFactory().newNetConnection
- (netLogWriter, user, password,dataSource, rmId, isXAConn);
+ (netLogWriter, user, password,dataSource, rmId, isXAConn,cpc);
}
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude?rev=399644&r1=399643&r2=399644&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude Thu May 4 02:58:54 2006
@@ -29,6 +29,3 @@
#failing (hanging?) on jdk 1.5/jdk 1.6
jdbcapi/checkDataSource.java
jdbcapi/checkDataSource30.java
-#exclude the statement events test until the feature is added on the
-#client side
-jdbc4/StatementEventsTest.junit
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementEventsTest.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementEventsTest.java?rev=399644&r1=399643&r2=399644&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementEventsTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementEventsTest.java Thu May 4 02:58:54 2006
@@ -43,6 +43,14 @@
boolean statementCloseEventOccurred=false;
boolean statementErrorEventOccurred=false;
+ //In the case of the client driver when the connection is closed then
+ //the prepared statements associated with the connection are also closed
+ //this would raise closed events for corresponding prepared statements
+
+ //using a flag to identify the occurrence of the error event in the
+ //network client which can also cause the close event to be raised
+ boolean client_ErrorEvent=false;
+
/**
* Create a test with the given name.
@@ -100,6 +108,11 @@
*/
void raiseErrorEvent() {
try {
+ //mark the falg to indicate that we are raising a error event
+ //on the client framework
+ if(usingDerbyNetClient())
+ client_ErrorEvent = true;
+
ps_error = conn.prepareStatement("values 1");
//close the connection associated with this prepared statement
@@ -129,8 +142,28 @@
public void statementClosed(StatementEvent event) {
statementCloseEventOccurred = true;
- if(ps_close==null || !event.getStatement().equals(ps_close)) {
- System.out.println("The statement event has the wrong reference + of PreparedStatement");
+ //If the event was caused by ps_close and not
+ //by ps_error. In this case client_ErrorEvent
+ //will be false.
+ //In this case check if the StatementEvent
+ //has a proper reference to ps_close
+ //which is the actual prepared statement
+ //that caused the error event.
+ if(!client_ErrorEvent && (ps_close==null ||
+ !event.getStatement().equals(ps_close))) {
+ System.out.println("The statement event has the wrong reference " +
+ "of PreparedStatement");
+ }
+
+ //If it is caused by the error occurred event on the
+ //Network client side. upon doing a Connection.close()
+ //the Prepared Statements associated with the
+ //Connection are automatically marked closed
+ //check if the StatementEvent has a proper reference to ps_error
+ if(client_ErrorEvent && (ps_error==null ||
+ !event.getStatement().equals(ps_error))) {
+ System.out.println("The statement event has the wrong reference" +
+ " of PreparedStatement");
}
}