Added:
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4MysqlPooledConnection.java
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4MysqlXAConnection.java
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4SuspendableXAConnection.java
Modified:
branches/branch_5_1/connector-j/CHANGES
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4PreparedStatementWrapper.java
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlConnectionPoolDataSource.java
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlPooledConnection.java
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlXAConnection.java
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlXADataSource.java
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/SuspendableXAConnection.java
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/WrapperBase.java
branches/branch_5_1/connector-j/src/testsuite/simple/ConnectionTest.java
branches/branch_5_1/connector-j/src/testsuite/simple/MetadataTest.java
branches/branch_5_1/connector-j/src/testsuite/simple/StatementsTest.java
branches/branch_5_1/connector-j/src/testsuite/simple/XATest.java
Log:
JDBC-4.0-ized XAConnections and datasources.
Modified: branches/branch_5_1/connector-j/CHANGES
===================================================================
--- branches/branch_5_1/connector-j/CHANGES 2007-10-09 16:46:46 UTC (rev 6630)
+++ branches/branch_5_1/connector-j/CHANGES 2007-10-11 20:01:16 UTC (rev 6631)
@@ -1,5 +1,9 @@
# Changelog
# $Id$
+nn-nn-08 - Version 5.1.6
+
+ - JDBC-4.0-ized XAConnections and datasources.
+
10-09-07 - Version 5.1.5
- Released instead of 5.1.4 to pickup patch for BUG#31053
Modified:
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java
===================================================================
---
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java 2007-10-09
16:46:46 UTC (rev 6630)
+++
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java 2007-10-11
20:01:16 UTC (rev 6631)
@@ -854,7 +854,7 @@
}
if (fireClosedEvent) {
- this.mpc.callListener(
+ this.mpc.callConnectionEventListeners(
MysqlPooledConnection.CONNECTION_CLOSED_EVENT, null);
}
Added:
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4MysqlPooledConnection.java
===================================================================
---
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4MysqlPooledConnection.java 2007-10-09
16:46:46 UTC (rev 6630)
+++
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4MysqlPooledConnection.java 2007-10-11
20:01:16 UTC (rev 6631)
@@ -0,0 +1,107 @@
+/*
+ Copyright (C) 2007 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ There are special exceptions to the terms and conditions of the GPL
+ as it is applied to this software. View the full text of the
+ exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
+ software distribution.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ */
+
+package com.mysql.jdbc.jdbc2.optional;
+
+import java.sql.SQLException;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.sql.StatementEvent;
+import javax.sql.StatementEventListener;
+
+
+/**
+ * This class is used to wrap and return a physical connection within a logical
+ * handle. It also registers and notifies ConnectionEventListeners of any
+ * ConnectionEvents
+ *
+ * @see javax.sql.PooledConnection
+ * @see org.gjt.mm.mysql.jdbc2.optional.LogicalHandle
+ * @author Todd Wolff <todd.wolff_at_prodigy.net>
+ */
+public class JDBC4MysqlPooledConnection extends MysqlPooledConnection {
+
+ private Map<StatementEventListener, StatementEventListener>
statementEventListeners;
+
+ public JDBC4MysqlPooledConnection(com.mysql.jdbc.Connection connection) {
+ super(connection);
+
+ this.statementEventListeners = new HashMap<StatementEventListener,
StatementEventListener>();
+ }
+
+ public synchronized void close() throws SQLException {
+ super.close();
+
+ if (this.statementEventListeners != null) {
+ this.statementEventListeners.clear();
+
+ this.statementEventListeners = null;
+ }
+ }
+
+
+ /**
+ * Registers a <code>StatementEventListener</code> with this
<code>PooledConnection</code> object. Components that
+ * wish to be notified when <code>PreparedStatement</code>s created by the
+ * connection are closed or are detected to be invalid may use this method
+ * to register a <code>StatementEventListener</code> with this
<code>PooledConnection</code> object.
+ * <p>
+ * @param listener an component which implements the
<code>StatementEventListener</code>
+ * interface that is to be registered with this
<code>PooledConnection</code> object
+ * <p>
+ * @since 1.6
+ */
+ public void addStatementEventListener(StatementEventListener listener) {
+ synchronized (this.statementEventListeners) {
+ this.statementEventListeners.put(listener, listener);
+ }
+ }
+
+ /**
+ * Removes the specified <code>StatementEventListener</code> from the list
of
+ * components that will be notified when the driver detects that a
+ * <code>PreparedStatement</code> has been closed or is invalid.
+ * <p>
+ * @param listener the component which implements the
+ * <code>StatementEventListener</code> interface that was previously
+ * registered with this <code>PooledConnection</code> object
+ * <p>
+ * @since 1.6
+ */
+ public void removeStatementEventListener(StatementEventListener listener) {
+ synchronized (this.statementEventListeners) {
+ this.statementEventListeners.remove(listener);
+ }
+ }
+
+ void fireStatementEvent(StatementEvent event) throws SQLException {
+ synchronized (this.statementEventListeners) {
+ for (StatementEventListener listener : this.statementEventListeners.keySet()) {
+ listener.statementClosed(event);
+ }
+ }
+ }
+}
\ No newline at end of file
Property changes on:
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4MysqlPooledConnection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4MysqlXAConnection.java
===================================================================
---
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4MysqlXAConnection.java 2007-10-09
16:46:46 UTC (rev 6630)
+++
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4MysqlXAConnection.java 2007-10-11
20:01:16 UTC (rev 6631)
@@ -0,0 +1,99 @@
+/*
+ Copyright (C) 2007 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ There are special exceptions to the terms and conditions of the GPL
+ as it is applied to this software. View the full text of the
+ exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
+ software distribution.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ */
+
+package com.mysql.jdbc.jdbc2.optional;
+
+import java.sql.SQLException;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.sql.StatementEvent;
+import javax.sql.StatementEventListener;
+
+import com.mysql.jdbc.ConnectionImpl;
+
+public class JDBC4MysqlXAConnection extends MysqlXAConnection {
+
+ private Map<StatementEventListener, StatementEventListener>
statementEventListeners;
+
+ public JDBC4MysqlXAConnection(ConnectionImpl connection, boolean logXaCommands) throws
SQLException {
+ super(connection, logXaCommands);
+
+ this.statementEventListeners = new HashMap<StatementEventListener,
StatementEventListener>();
+ }
+
+ public synchronized void close() throws SQLException {
+ super.close();
+
+ if (this.statementEventListeners != null) {
+ this.statementEventListeners.clear();
+
+ this.statementEventListeners = null;
+ }
+ }
+
+
+ /**
+ * Registers a <code>StatementEventListener</code> with this
<code>PooledConnection</code> object. Components that
+ * wish to be notified when <code>PreparedStatement</code>s created by the
+ * connection are closed or are detected to be invalid may use this method
+ * to register a <code>StatementEventListener</code> with this
<code>PooledConnection</code> object.
+ * <p>
+ * @param listener an component which implements the
<code>StatementEventListener</code>
+ * interface that is to be registered with this
<code>PooledConnection</code> object
+ * <p>
+ * @since 1.6
+ */
+ public void addStatementEventListener(StatementEventListener listener) {
+ synchronized (this.statementEventListeners) {
+ this.statementEventListeners.put(listener, listener);
+ }
+ }
+
+ /**
+ * Removes the specified <code>StatementEventListener</code> from the list
of
+ * components that will be notified when the driver detects that a
+ * <code>PreparedStatement</code> has been closed or is invalid.
+ * <p>
+ * @param listener the component which implements the
+ * <code>StatementEventListener</code> interface that was previously
+ * registered with this <code>PooledConnection</code> object
+ * <p>
+ * @since 1.6
+ */
+ public void removeStatementEventListener(StatementEventListener listener) {
+ synchronized (this.statementEventListeners) {
+ this.statementEventListeners.remove(listener);
+ }
+ }
+
+ void fireStatementEvent(StatementEvent event) throws SQLException {
+ synchronized (this.statementEventListeners) {
+ for (StatementEventListener listener : this.statementEventListeners.keySet()) {
+ listener.statementClosed(event);
+ }
+ }
+ }
+}
\ No newline at end of file
Property changes on:
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4MysqlXAConnection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4PreparedStatementWrapper.java
===================================================================
---
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4PreparedStatementWrapper.java 2007-10-09
16:46:46 UTC (rev 6630)
+++
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4PreparedStatementWrapper.java 2007-10-11
20:01:16 UTC (rev 6631)
@@ -46,6 +46,8 @@
import java.util.Map;
import java.util.Properties;
+import javax.sql.StatementEvent;
+
import com.mysql.jdbc.ConnectionImpl;
import com.mysql.jdbc.SQLError;
import com.mysql.jdbc.jdbc2.optional.ConnectionWrapper;
@@ -64,7 +66,12 @@
try {
super.close();
} finally {
- this.unwrappedInterfaces = null;
+ try {
+ ((JDBC4MysqlPooledConnection)this.pooledConnection).fireStatementEvent(
+ new StatementEvent(this.pooledConnection, this));
+ } finally {
+ this.unwrappedInterfaces = null;
+ }
}
}
Added:
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4SuspendableXAConnection.java
===================================================================
---
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4SuspendableXAConnection.java 2007-10-09
16:46:46 UTC (rev 6630)
+++
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4SuspendableXAConnection.java 2007-10-11
20:01:16 UTC (rev 6631)
@@ -0,0 +1,99 @@
+/*
+ Copyright (C) 2007 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ There are special exceptions to the terms and conditions of the GPL
+ as it is applied to this software. View the full text of the
+ exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
+ software distribution.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ */
+
+package com.mysql.jdbc.jdbc2.optional;
+
+import java.sql.SQLException;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.sql.StatementEvent;
+import javax.sql.StatementEventListener;
+
+import com.mysql.jdbc.ConnectionImpl;
+
+public class JDBC4SuspendableXAConnection extends SuspendableXAConnection {
+
+ private Map<StatementEventListener, StatementEventListener>
statementEventListeners;
+
+ public JDBC4SuspendableXAConnection(ConnectionImpl connection) throws SQLException {
+ super(connection);
+
+ this.statementEventListeners = new HashMap<StatementEventListener,
StatementEventListener>();
+ }
+
+ public synchronized void close() throws SQLException {
+ super.close();
+
+ if (this.statementEventListeners != null) {
+ this.statementEventListeners.clear();
+
+ this.statementEventListeners = null;
+ }
+ }
+
+
+ /**
+ * Registers a <code>StatementEventListener</code> with this
<code>PooledConnection</code> object. Components that
+ * wish to be notified when <code>PreparedStatement</code>s created by the
+ * connection are closed or are detected to be invalid may use this method
+ * to register a <code>StatementEventListener</code> with this
<code>PooledConnection</code> object.
+ * <p>
+ * @param listener an component which implements the
<code>StatementEventListener</code>
+ * interface that is to be registered with this
<code>PooledConnection</code> object
+ * <p>
+ * @since 1.6
+ */
+ public void addStatementEventListener(StatementEventListener listener) {
+ synchronized (this.statementEventListeners) {
+ this.statementEventListeners.put(listener, listener);
+ }
+ }
+
+ /**
+ * Removes the specified <code>StatementEventListener</code> from the list
of
+ * components that will be notified when the driver detects that a
+ * <code>PreparedStatement</code> has been closed or is invalid.
+ * <p>
+ * @param listener the component which implements the
+ * <code>StatementEventListener</code> interface that was previously
+ * registered with this <code>PooledConnection</code> object
+ * <p>
+ * @since 1.6
+ */
+ public void removeStatementEventListener(StatementEventListener listener) {
+ synchronized (this.statementEventListeners) {
+ this.statementEventListeners.remove(listener);
+ }
+ }
+
+ void fireStatementEvent(StatementEvent event) throws SQLException {
+ synchronized (this.statementEventListeners) {
+ for (StatementEventListener listener : this.statementEventListeners.keySet()) {
+ listener.statementClosed(event);
+ }
+ }
+ }
+}
\ No newline at end of file
Property changes on:
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/JDBC4SuspendableXAConnection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlConnectionPoolDataSource.java
===================================================================
---
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlConnectionPoolDataSource.java 2007-10-09
16:46:46 UTC (rev 6630)
+++
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlConnectionPoolDataSource.java 2007-10-11
20:01:16 UTC (rev 6631)
@@ -56,7 +56,7 @@
public synchronized PooledConnection getPooledConnection()
throws SQLException {
Connection connection = getConnection();
- MysqlPooledConnection mysqlPooledConnection = new MysqlPooledConnection(
+ MysqlPooledConnection mysqlPooledConnection = MysqlPooledConnection.getInstance(
(com.mysql.jdbc.Connection)connection);
return mysqlPooledConnection;
@@ -77,7 +77,7 @@
public synchronized PooledConnection getPooledConnection(String s, String s1)
throws SQLException {
Connection connection = getConnection(s, s1);
- MysqlPooledConnection mysqlPooledConnection = new MysqlPooledConnection(
+ MysqlPooledConnection mysqlPooledConnection = MysqlPooledConnection.getInstance(
(com.mysql.jdbc.Connection)connection);
return mysqlPooledConnection;
Modified:
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlPooledConnection.java
===================================================================
---
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlPooledConnection.java 2007-10-09
16:46:46 UTC (rev 6630)
+++
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlPooledConnection.java 2007-10-11
20:01:16 UTC (rev 6631)
@@ -23,11 +23,15 @@
package com.mysql.jdbc.jdbc2.optional;
+import java.lang.reflect.Constructor;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
import javax.sql.ConnectionEvent;
import javax.sql.ConnectionEventListener;
@@ -36,6 +40,7 @@
import com.mysql.jdbc.ConnectionImpl;
import com.mysql.jdbc.Constants;
import com.mysql.jdbc.SQLError;
+import com.mysql.jdbc.Util;
import com.mysql.jdbc.exceptions.NotYetImplementedException;
/**
@@ -49,6 +54,37 @@
*/
public class MysqlPooledConnection implements PooledConnection {
+ private static final Constructor JDBC_4_POOLED_CONNECTION_WRAPPER_CTOR;
+
+ static {
+ if (Util.isJdbc4()) {
+ try {
+ JDBC_4_POOLED_CONNECTION_WRAPPER_CTOR = Class.forName(
+ "com.mysql.jdbc.jdbc2.optional.JDBC4MysqlPooledConnection")
+ .getConstructor(
+ new Class[] { com.mysql.jdbc.Connection.class });
+ } catch (SecurityException e) {
+ throw new RuntimeException(e);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ JDBC_4_POOLED_CONNECTION_WRAPPER_CTOR = null;
+ }
+ }
+
+ protected static MysqlPooledConnection getInstance(com.mysql.jdbc.Connection connection)
throws SQLException {
+ if (!Util.isJdbc4()) {
+ return new MysqlPooledConnection(connection);
+ }
+
+ return (MysqlPooledConnection) Util.handleNewInstance(
+ JDBC_4_POOLED_CONNECTION_WRAPPER_CTOR, new Object[] {
+ connection});
+ }
+
/**
* The flag for an exception being thrown.
*/
@@ -61,7 +97,7 @@
// ~ Instance/static variables .............................................
- private Hashtable eventListeners;
+ private Map connectionEventListeners;
private Connection logicalHandle;
@@ -78,11 +114,9 @@
public MysqlPooledConnection(com.mysql.jdbc.Connection connection) {
this.logicalHandle = null;
this.physicalConn = connection;
- this.eventListeners = new Hashtable(10);
+ this.connectionEventListeners = new HashMap();
}
- // ~ Methods ...............................................................
-
/**
* Adds ConnectionEventListeners to a hash table to be used for notification
* of ConnectionEvents
@@ -93,8 +127,8 @@
public synchronized void addConnectionEventListener(
ConnectionEventListener connectioneventlistener) {
- if (this.eventListeners != null) {
- this.eventListeners.put(connectioneventlistener,
+ if (this.connectionEventListeners != null) {
+ this.connectionEventListeners.put(connectioneventlistener,
connectioneventlistener);
}
}
@@ -109,8 +143,8 @@
public synchronized void removeConnectionEventListener(
ConnectionEventListener connectioneventlistener) {
- if (this.eventListeners != null) {
- this.eventListeners.remove(connectioneventlistener);
+ if (this.connectionEventListeners != null) {
+ this.connectionEventListeners.remove(connectioneventlistener);
}
}
@@ -132,7 +166,7 @@
SQLException sqlException = SQLError.createSQLException(
"Physical Connection doesn't exist");
- callListener(CONNECTION_ERROR_EVENT, sqlException);
+ callConnectionEventListeners(CONNECTION_ERROR_EVENT, sqlException);
throw sqlException;
}
@@ -151,7 +185,7 @@
(ConnectionImpl)this.physicalConn,
forXa);
} catch (SQLException sqlException) {
- callListener(CONNECTION_ERROR_EVENT, sqlException);
+ callConnectionEventListeners(CONNECTION_ERROR_EVENT, sqlException);
throw sqlException;
}
@@ -169,9 +203,15 @@
public synchronized void close() throws SQLException {
if (this.physicalConn != null) {
this.physicalConn.close();
+
+ this.physicalConn = null;
}
-
- this.physicalConn = null;
+
+ if (this.connectionEventListeners != null) {
+ this.connectionEventListeners.clear();
+
+ this.connectionEventListeners = null;
+ }
}
/**
@@ -186,63 +226,30 @@
* @param sqlException
* the exception being thrown
*/
- protected synchronized void callListener(int eventType,
+ protected synchronized void callConnectionEventListeners(int eventType,
SQLException sqlException) {
- if (this.eventListeners == null) {
+ if (this.connectionEventListeners == null) {
return;
}
- Enumeration enumeration = this.eventListeners.keys();
+ Iterator iterator = this.connectionEventListeners.entrySet().iterator();
+
ConnectionEvent connectionevent = new ConnectionEvent(this,
sqlException);
- while (enumeration.hasMoreElements()) {
+ while (iterator.hasNext()) {
- ConnectionEventListener connectioneventlistener = (ConnectionEventListener)
enumeration
- .nextElement();
- ConnectionEventListener connectioneventlistener1 = (ConnectionEventListener)
this.eventListeners
- .get(connectioneventlistener);
+ ConnectionEventListener connectioneventlistener = (ConnectionEventListener)
((Map.Entry)iterator
+ .next()).getValue();
if (eventType == CONNECTION_CLOSED_EVENT) {
- connectioneventlistener1.connectionClosed(connectionevent);
+ connectioneventlistener.connectionClosed(connectionevent);
} else if (eventType == CONNECTION_ERROR_EVENT) {
- connectioneventlistener1
+ connectioneventlistener
.connectionErrorOccurred(connectionevent);
}
}
}
-
-// /**
-// * Registers a <code>StatementEventListener</code> with this
<code>PooledConnection</code> object. Components that
-// * wish to be notified when <code>PreparedStatement</code>s created by
the
-// * connection are closed or are detected to be invalid may use this method
-// * to register a <code>StatementEventListener</code> with this
<code>PooledConnection</code> object.
-// * <p>
-// * @param listener an component which implements the
<code>StatementEventListener</code>
-// * interface that is to be registered with this
<code>PooledConnection</code> object
-// * <p>
-// * @since 1.6
-// */
-// public void addStatementEventListener(StatementEventListener listener) {
-// throw new NotYetImplementedException();
-// }
-//
-// /**
-// * Removes the specified <code>StatementEventListener</code> from the list
of
-// * components that will be notified when the driver detects that a
-// * <code>PreparedStatement</code> has been closed or is invalid.
-// * <p>
-// * @param listener the component which implements the
-// * <code>StatementEventListener</code> interface that was previously
-// * registered with this <code>PooledConnection</code> object
-// * <p>
-// * @since 1.6
-// */
-// public void removeStatementEventListener(StatementEventListener listener) {
-// throw new NotYetImplementedException();
-// }
-
-
}
\ No newline at end of file
Modified:
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlXAConnection.java
===================================================================
---
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlXAConnection.java 2007-10-09
16:46:46 UTC (rev 6630)
+++
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlXAConnection.java 2007-10-11
20:01:16 UTC (rev 6631)
@@ -22,6 +22,7 @@
*/
package com.mysql.jdbc.jdbc2.optional;
+import java.lang.reflect.Constructor;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -39,6 +40,7 @@
import com.mysql.jdbc.ConnectionImpl;
import com.mysql.jdbc.Constants;
+import com.mysql.jdbc.Util;
import com.mysql.jdbc.log.Log;
/*
@@ -83,7 +85,40 @@
MYSQL_ERROR_CODES_TO_XA_ERROR_CODES = Collections.unmodifiableMap(temp);
}
+
+ private static final Constructor JDBC_4_XA_CONNECTION_WRAPPER_CTOR;
+ static {
+ if (Util.isJdbc4()) {
+ try {
+ JDBC_4_XA_CONNECTION_WRAPPER_CTOR = Class.forName(
+ "com.mysql.jdbc.jdbc2.optional.JDBC4MysqlXAConnection")
+ .getConstructor(
+ new Class[] { ConnectionImpl.class, Boolean.TYPE });
+ } catch (SecurityException e) {
+ throw new RuntimeException(e);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ JDBC_4_XA_CONNECTION_WRAPPER_CTOR = null;
+ }
+ }
+
+ protected static MysqlXAConnection getInstance(ConnectionImpl mysqlConnection,
+ boolean logXaCommands) throws SQLException {
+ if (!Util.isJdbc4()) {
+ return new MysqlXAConnection(mysqlConnection, logXaCommands);
+ }
+
+ return (MysqlXAConnection) Util.handleNewInstance(
+ JDBC_4_XA_CONNECTION_WRAPPER_CTOR, new Object[] {
+ mysqlConnection,
+ Boolean.valueOf(logXaCommands) });
+ }
+
/**
* @param connection
*/
Modified:
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlXADataSource.java
===================================================================
---
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlXADataSource.java 2007-10-09
16:46:46 UTC (rev 6630)
+++
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlXADataSource.java 2007-10-11
20:01:16 UTC (rev 6631)
@@ -67,9 +67,9 @@
private XAConnection wrapConnection(Connection conn) throws SQLException {
if (getPinGlobalTxToPhysicalConnection() ||
((com.mysql.jdbc.Connection)conn).getPinGlobalTxToPhysicalConnection()) {
- return new SuspendableXAConnection((com.mysql.jdbc.ConnectionImpl) conn);
+ return SuspendableXAConnection.getInstance((com.mysql.jdbc.ConnectionImpl) conn);
}
- return new MysqlXAConnection((com.mysql.jdbc.ConnectionImpl) conn, getLogXaCommands());
+ return MysqlXAConnection.getInstance((com.mysql.jdbc.ConnectionImpl) conn,
getLogXaCommands());
}
}
\ No newline at end of file
Modified:
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/SuspendableXAConnection.java
===================================================================
---
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/SuspendableXAConnection.java 2007-10-09
16:46:46 UTC (rev 6630)
+++
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/SuspendableXAConnection.java 2007-10-11
20:01:16 UTC (rev 6631)
@@ -1,6 +1,7 @@
package com.mysql.jdbc.jdbc2.optional;
+import java.lang.reflect.Constructor;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
@@ -12,10 +13,42 @@
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ConnectionImpl;
+import com.mysql.jdbc.Util;
public class SuspendableXAConnection extends MysqlPooledConnection implements
XAConnection, XAResource {
+ private static final Constructor JDBC_4_XA_CONNECTION_WRAPPER_CTOR;
+
+ static {
+ if (Util.isJdbc4()) {
+ try {
+ JDBC_4_XA_CONNECTION_WRAPPER_CTOR = Class.forName(
+ "com.mysql.jdbc.jdbc2.optional.JDBC4SuspendableXAConnection")
+ .getConstructor(
+ new Class[] { ConnectionImpl.class });
+ } catch (SecurityException e) {
+ throw new RuntimeException(e);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ JDBC_4_XA_CONNECTION_WRAPPER_CTOR = null;
+ }
+ }
+
+ protected static SuspendableXAConnection getInstance(ConnectionImpl mysqlConnection)
throws SQLException {
+ if (!Util.isJdbc4()) {
+ return new SuspendableXAConnection(mysqlConnection);
+ }
+
+ return (SuspendableXAConnection) Util.handleNewInstance(
+ JDBC_4_XA_CONNECTION_WRAPPER_CTOR, new Object[] {
+ mysqlConnection});
+ }
+
public SuspendableXAConnection(ConnectionImpl connection) {
super(connection);
this.underlyingConnection = connection;
Modified:
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/WrapperBase.java
===================================================================
---
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/WrapperBase.java 2007-10-09
16:46:46 UTC (rev 6630)
+++
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/WrapperBase.java 2007-10-11
20:01:16 UTC (rev 6631)
@@ -56,7 +56,7 @@
if (this.pooledConnection != null) {
if (SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE.equals(sqlEx
.getSQLState())) {
- this.pooledConnection.callListener(
+ this.pooledConnection.callConnectionEventListeners(
MysqlPooledConnection.CONNECTION_ERROR_EVENT, sqlEx);
}
}
Modified: branches/branch_5_1/connector-j/src/testsuite/simple/ConnectionTest.java
===================================================================
--- branches/branch_5_1/connector-j/src/testsuite/simple/ConnectionTest.java 2007-10-09
16:46:46 UTC (rev 6630)
+++ branches/branch_5_1/connector-j/src/testsuite/simple/ConnectionTest.java 2007-10-11
20:01:16 UTC (rev 6631)
@@ -57,6 +57,7 @@
import com.mysql.jdbc.NonRegisteringDriver;
import com.mysql.jdbc.SQLError;
import com.mysql.jdbc.StringUtils;
+import com.mysql.jdbc.Util;
import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;
import com.mysql.jdbc.log.StandardLogger;
@@ -1515,7 +1516,14 @@
props.setProperty("useServerPrepStmts", "false"); // force the issue
props.setProperty("useCursorFetch", "true");
fetchConn = getConnectionWithProps(props);
- assertEquals("com.mysql.jdbc.ServerPreparedStatement",
+
+ String classname = "com.mysql.jdbc.ServerPreparedStatement";
+
+ if (Util.isJdbc4()) {
+ classname = "com.mysql.jdbc.JDBC4ServerPreparedStatement";
+ }
+
+ assertEquals(classname,
fetchConn.prepareStatement("SELECT 1").getClass().getName());
} finally {
if (fetchConn != null) {
Modified: branches/branch_5_1/connector-j/src/testsuite/simple/MetadataTest.java
===================================================================
--- branches/branch_5_1/connector-j/src/testsuite/simple/MetadataTest.java 2007-10-09
16:46:46 UTC (rev 6630)
+++ branches/branch_5_1/connector-j/src/testsuite/simple/MetadataTest.java 2007-10-11
20:01:16 UTC (rev 6631)
@@ -592,7 +592,7 @@
this.rs.next();
assertEquals("t1", this.rs.getString("TABLE_NAME"));
assertEquals("c1", this.rs.getString("COLUMN_NAME"));
- assertEquals("char", this.rs.getString("TYPE_NAME"));
+ assertEquals("CHAR", this.rs.getString("TYPE_NAME"));
assertEquals("1", this.rs.getString("COLUMN_SIZE"));
} finally {
if (conn1 != null) {
Modified: branches/branch_5_1/connector-j/src/testsuite/simple/StatementsTest.java
===================================================================
--- branches/branch_5_1/connector-j/src/testsuite/simple/StatementsTest.java 2007-10-09
16:46:46 UTC (rev 6630)
+++ branches/branch_5_1/connector-j/src/testsuite/simple/StatementsTest.java 2007-10-11
20:01:16 UTC (rev 6631)
@@ -1907,7 +1907,11 @@
ParameterBindings bindings =
((com.mysql.jdbc.PreparedStatement)this.pstmt).getParameterBindings();
for (int i = 0; i < valuesToTest.length; i++) {
- assertEquals(bindings.getObject(i + 1), valuesToTest[i]);
+ if (bindings.getObject(i + 1) instanceof Number) {
+ assertEquals("For binding " + (i + 1), bindings.getObject(i + 1).toString(),
valuesToTest[i].toString());
+ } else {
+ assertEquals("For binding " + (i + 1), bindings.getObject(i + 1), valuesToTest[i]);
+ }
}
}
Modified: branches/branch_5_1/connector-j/src/testsuite/simple/XATest.java
===================================================================
--- branches/branch_5_1/connector-j/src/testsuite/simple/XATest.java 2007-10-09 16:46:46
UTC (rev 6630)
+++ branches/branch_5_1/connector-j/src/testsuite/simple/XATest.java 2007-10-11 20:01:16
UTC (rev 6631)
@@ -278,7 +278,7 @@
xaConn1 = getXAConnection();
XAResource xaRes1 = xaConn1.getXAResource();
conn1 = xaConn1.getConnection();
- assertEquals(false, conn1.getAutoCommit());
+ assertEquals(true, conn1.getAutoCommit());
conn1.setAutoCommit(true);
conn1.createStatement().executeUpdate(
"INSERT INTO testLocalTransaction VALUES (1)");
| Thread |
|---|
| • Connector/J commit: r6631 - in branches/branch_5_1/connector-j: . src/com/mysql/jdbc/jdbc2/optional src/testsuite/simple | mmatthews | 11 Oct |