• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package javax.sql;
19 
20 import java.io.Serializable;
21 import java.sql.SQLException;
22 import java.util.EventObject;
23 
24 /**
25  * Sent when specific events happen on a {@link PooledConnection} object. These
26  * events are a facility to report when an application closes the pooled
27  * connection or when an error occurs in the pooled connection.
28  */
29 public class ConnectionEvent extends EventObject implements Serializable {
30 
31     private static final long serialVersionUID = -4843217645290030002L;
32 
33     private SQLException ex;
34 
35     /**
36      * Creates a connection event initialized with the supplied {@code
37      * PooledConnection} reporting that the application has closed the
38      * connection.
39      *
40      * @param theConnection
41      *            the connection for which this event is created.
42      */
ConnectionEvent(PooledConnection theConnection)43     public ConnectionEvent(PooledConnection theConnection) {
44         super(theConnection);
45     }
46 
47     /**
48      * Creates a {@code ConnectionEvent} initialized with the supplied {@code
49      * PooledConnection} and with the supplied {@code SQLException} indicating
50      * that an error has occurred within the {@code PooledConnection}.
51      *
52      * @param theConnection
53      *            the connection for which this event is created.
54      * @param theException
55      *            information about the state of error that has occurred on the
56      *            application side.
57      */
ConnectionEvent(PooledConnection theConnection, SQLException theException)58     public ConnectionEvent(PooledConnection theConnection,
59             SQLException theException) {
60         super(theConnection);
61         ex = theException;
62     }
63 
64     /**
65      * Gets the {@code SQLException} which holds information about the error
66      * which occurred in the {@code PooledConnection}.
67      *
68      * @return a {@code SQLException} containing information about the error.
69      *         May be {@code null} if no error has occurred.
70      */
getSQLException()71     public SQLException getSQLException() {
72         return ex;
73     }
74 }
75