--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.jdbc.EmbedPooledConnection40\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.sql.Connection;\r
+import java.sql.SQLException;\r
+import java.util.Enumeration;\r
+import java.util.Vector;\r
+import java.sql.PreparedStatement;\r
+import javax.sql.StatementEvent;\r
+import javax.sql.StatementEventListener;\r
+\r
+/** \r
+ A PooledConnection object is a connection object that provides hooks for\r
+ connection pool management.\r
+\r
+ <P>This is Derby's implementation of a PooledConnection for use in\r
+ the following environments:\r
+ <UL>\r
+ <LI> JDBC 4.0 - J2SE 6.0\r
+ </UL>\r
+\r
+ */\r
+class EmbedPooledConnection40 extends EmbedPooledConnection {\r
+ \r
+ //using generics to avoid casting problems\r
+ protected final Vector<StatementEventListener> statementEventListeners =\r
+ new Vector<StatementEventListener>();\r
+ \r
+\r
+ EmbedPooledConnection40 (ReferenceableDataSource ds, String user, \r
+ String password, boolean requestPassword) throws SQLException {\r
+ super (ds, 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