KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > client > ClientPooledConnection40


1 /*
2  
3    Derby - Class org.apache.derby.client.ClientPooledConnection40
4  
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11  
12       http://www.apache.org/licenses/LICENSE-2.0
13  
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19  
20  */

21
22 package org.apache.derby.client;
23
24 import java.sql.PreparedStatement JavaDoc;
25 import java.sql.SQLException JavaDoc;
26 import java.util.Enumeration JavaDoc;
27 import java.util.Vector JavaDoc;
28 import javax.sql.ConnectionEventListener JavaDoc;
29 import javax.sql.StatementEventListener JavaDoc;
30 import javax.sql.StatementEvent JavaDoc;
31 import org.apache.derby.client.am.SqlException;
32 import org.apache.derby.client.net.NetXAConnection;
33 import org.apache.derby.jdbc.ClientBaseDataSource;
34 import org.apache.derby.jdbc.ClientDataSource;
35 import org.apache.derby.client.am.SqlException;
36 import org.apache.derby.client.net.NetLogWriter;
37
38 /**
39  *
40  * The class extends from the ClientPooledConnection class
41  * and contains implementations for the JDBC 4.0 specific
42  * methods in the javax.sql.PooledConnection interface.
43  *
44  */

45
46 public class ClientPooledConnection40 extends ClientPooledConnection {
47     //using generics to avoid casting problems
48
protected final Vector JavaDoc<StatementEventListener JavaDoc> statementEventListeners =
49              new Vector JavaDoc<StatementEventListener JavaDoc>();
50
51     public ClientPooledConnection40(ClientBaseDataSource ds,
52         org.apache.derby.client.am.LogWriter logWriter,
53         String JavaDoc user,
54         String JavaDoc password) throws SQLException JavaDoc {
55         super(ds,logWriter,user,password);
56         
57     }
58     
59     
60     public ClientPooledConnection40(ClientBaseDataSource ds,
61         org.apache.derby.client.am.LogWriter logWriter,
62         String JavaDoc user,
63         String JavaDoc password,
64         int rmId) throws SQLException JavaDoc {
65         super(ds,logWriter,user,password,rmId);
66         
67     }
68     
69     public ClientPooledConnection40(ClientBaseDataSource ds,
70         org.apache.derby.client.am.LogWriter logWriter) throws SQLException JavaDoc {
71         super(ds,logWriter);
72     }
73     
74      /**
75      *
76      * Registers a StatementEventListener with this PooledConnection object.
77      * Components that wish to be informed of events associated with the
78      * PreparedStatement object created by this PooledConnection like the close
79      * or error occurred event can register a StatementEventListener with this
80      * PooledConnection object.
81      *
82      * @param listener A component that implements the StatementEventListener
83      * interface and wants to be notified of Statement closed or
84      * or Statement error occurred events
85      */

86     public void addStatementEventListener(StatementEventListener JavaDoc listener){
87         if (logWriter_ != null) {
88             logWriter_.traceEntry(this, "addStatementEventListener", listener);
89         }
90         statementEventListeners.addElement(listener);
91     }
92     
93     /**
94      *
95      * Removes the specified previously registered listener object from the list
96      * of components that would be informed of events with a PreparedStatement
97      * object.
98      *
99      * @param listener The previously registered event listener that needs to be
100      * removed from the list of components
101      */

102     public void removeStatementEventListener(StatementEventListener JavaDoc listener){
103         if (logWriter_ != null) {
104             logWriter_.traceEntry(this, "removeConnectionEventListener", listener);
105         }
106         statementEventListeners.removeElement(listener);
107     }
108     
109     /**
110      *
111      * Raise the statementClosed event for all the listeners when the
112      * corresponding events occurs.
113      *
114      * @param statement The PreparedStatement that was closed
115      *
116      */

117     public void onStatementClose(PreparedStatement JavaDoc statement) {
118         if (!statementEventListeners.isEmpty()) {
119             StatementEvent JavaDoc event = new StatementEvent JavaDoc(this,statement);
120             //synchronized block on statementEventListeners to make it thread
121
//safe
122
synchronized(statementEventListeners) {
123                 for (StatementEventListener JavaDoc l : statementEventListeners) {
124                     l.statementClosed(event);
125                 }
126             }
127         }
128     }
129     
130     /**
131      *
132      * Raise the statementErrorOccurred event for all the listeners when the
133      * corresponding events occurs.
134      *
135      * @param statement The PreparedStatement on which error occurred
136      * @param sqle The SQLException associated with the error that
137      * caused the invalidation of the PreparedStatements
138      *
139      */

140     public void onStatementErrorOccurred(PreparedStatement JavaDoc statement,
141                     SQLException JavaDoc sqle) {
142         if (!statementEventListeners.isEmpty()) {
143             StatementEvent JavaDoc event = new StatementEvent JavaDoc(this,statement,sqle);
144             //synchronized block on statementEventListeners to make it thread
145
//safe
146
synchronized(statementEventListeners) {
147                 for (StatementEventListener JavaDoc l : statementEventListeners) {
148                     l.statementErrorOccurred(event);
149                 }
150             }
151         }
152     }
153 }
154
Popular Tags