--- /dev/null
+/*\r
+ \r
+ Derby - class org.apache.derby.jdbc.EmbedXAConnection40\r
+ \r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+ \r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+ \r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+ */\r
+\r
+\r
+package org.apache.derby.jdbc;\r
+\r
+import java.util.Vector;\r
+import java.sql.PreparedStatement;\r
+import java.sql.SQLException;\r
+import javax.sql.StatementEvent;\r
+import javax.sql.StatementEventListener;\r
+import javax.sql.XAConnection;\r
+import org.apache.derby.iapi.jdbc.ResourceAdapter;\r
+\r
+/**\r
+ * This class implements jdbc4.0 methods of XAConnection\r
+ */\r
+final class EmbedXAConnection40 extends EmbedXAConnection\r
+ implements XAConnection {\r
+ \r
+ //using generics to avoid casting problems\r
+ protected final Vector<StatementEventListener> statementEventListeners =\r
+ new Vector<StatementEventListener>();\r
+ \r
+ /**\r
+ * Creates EmbedXAConnection40.\r
+ * @param ds \r
+ * @param ra \r
+ * @param user \r
+ * @param password \r
+ * @param requestPassword \r
+ */\r
+ EmbedXAConnection40 (EmbeddedDataSource ds, ResourceAdapter ra, \r
+ String user, String password, \r
+ boolean requestPassword) throws SQLException {\r
+ super(ds, ra, user, password, requestPassword);\r
+ }\r
+ /**\r
+ * Removes the specified <code>StatementEventListener</code> from the list of \r
+ * components that will be notified when the driver detects that a \r
+ * <code>PreparedStatement</code> has been closed or is invalid.\r
+ * <p> \r
+ * \r
+ * @param listener the component which implements the\r
+ * <code>StatementEventListener</code> interface that was previously \r
+ * registered with this <code>PooledConnection</code> object\r
+ * <p>\r
+ * @since 1.6\r
+ */\r
+ public void removeStatementEventListener(StatementEventListener listener) {\r
+ if (listener == null)\r
+ return;\r
+ statementEventListeners.removeElement(listener);\r
+ }\r
+\r
+ /**\r
+ * Registers a <code>StatementEventListener</code> with this \r
+ * <code>PooledConnection</code> object. Components that \r
+ * wish to be notified when <code>PreparedStatement</code>s created by the\r
+ * connection are closed or are detected to be invalid may use this method \r
+ * to register a <code>StatementEventListener</code> with this \r
+ * <code>PooledConnection</code> object.\r
+ * <p>\r
+ * \r
+ * @param listener an component which implements the \r
+ * <code>StatementEventListener</code> interface that is to be registered\r
+ * with this <code>PooledConnection</code> object\r
+ * <p>\r
+ * @since 1.6\r
+ */\r
+ public void addStatementEventListener(StatementEventListener listener) {\r
+ if (!isActive)\r
+ return;\r
+ if (listener == null)\r
+ return;\r
+ statementEventListeners.addElement(listener);\r
+ }\r
+ \r
+ /**\r
+ * Raise the statementClosed event for all the listeners when the\r
+ * corresponding events occurs\r
+ * @param statement PreparedStatement\r
+ */\r
+ public void onStatementClose(PreparedStatement statement) {\r
+ if (!statementEventListeners.isEmpty()){\r
+ StatementEvent event = new StatementEvent(this,statement);\r
+ //synchronized block on statementEventListeners to make it thread\r
+ //safe\r
+ synchronized(statementEventListeners) {\r
+ for (StatementEventListener l : statementEventListeners) {\r
+ l.statementClosed(event);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
+ /**\r
+ * Raise the statementErrorOccurred event for all the listeners when the\r
+ * corresponding events occurs\r
+ * @param statement PreparedStatement\r
+ * @param sqle SQLException\r
+ */\r
+ public void onStatementErrorOccurred(PreparedStatement statement,SQLException sqle) {\r
+ if (!statementEventListeners.isEmpty()){\r
+ StatementEvent event = new StatementEvent(this,statement,sqle);\r
+ //synchronized block on statementEventListeners to make it thread\r
+ //safe\r
+ synchronized(statementEventListeners) {\r
+ for (StatementEventListener l : statementEventListeners){\r
+ l.statementErrorOccurred(event);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
+}
\ No newline at end of file