]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
ee059bbf59cf24eed4225a0774344e7b83f22ec5
[packages/trusty/mysql-wsrep-5.6.git] /
1 /*
2  *  Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; version 2 of the License.
7  *
8  *  This program is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *  GNU General Public License for more details.
12  *
13  *  You should have received a copy of the GNU General Public License
14  *  along with this program; if not, write to the Free Software
15  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
16  */
17
18 package com.mysql.clusterj.jdbc;
19
20 import com.mysql.clusterj.core.util.I18NHelper;
21 import com.mysql.clusterj.core.util.Logger;
22 import com.mysql.clusterj.core.util.LoggerFactoryService;
23 import com.mysql.jdbc.Connection;
24
25 import java.sql.SQLException;
26 import java.sql.Savepoint;
27
28 import java.util.Properties;
29
30 /** This interceptor is a plugin for the MySQL JDBC driver, Connector-J.
31  * It is called for each change of state of the associated connection.
32  * It is registered with the connection via the connection URL parameter
33  * connectionLifecycleInterceptors=com.mysql.clusterj.jdbc.ConnectionLifecycleInterceptor.
34  * It must be used in conjunction with the StatementInterceptor.
35  */
36 public class ConnectionLifecycleInterceptor
37             implements com.mysql.jdbc.ConnectionLifecycleInterceptor {
38
39     /** My message translator */
40     static final I18NHelper local = I18NHelper.getInstance(ConnectionLifecycleInterceptor.class);
41
42     /** My logger */
43     static final Logger logger = LoggerFactoryService.getFactory().getInstance(ConnectionLifecycleInterceptor.class);
44
45     /** The delegate for all methods. */
46     private InterceptorImpl interceptorImpl;
47
48     /** This method is called during connection setup with a new instance of ConnectionLifecycleInterceptor.
49      * An instance of InterceptorImpl is either created or found by lookup.
50      * Before the interceptor is useable, both the connection lifecycle interceptor and
51      * the statement interceptor must be registered.
52      * @param conn the associated connection
53      * @param properties the properties used to create the connection
54      */
55     public void init(Connection conn, Properties properties) throws SQLException {
56         // find the interceptor if it's already registered; otherwise create it
57         this.interceptorImpl = InterceptorImpl.getInterceptorImpl(this, conn, properties);
58     }
59
60     public void destroy() {
61         interceptorImpl.destroy(this);
62         interceptorImpl = null;
63     }
64
65     public void close() throws SQLException {
66         interceptorImpl.close();
67     }
68
69     public boolean commit() throws SQLException {
70         return interceptorImpl.commit();
71     }
72
73     public boolean rollback() throws SQLException {
74         return interceptorImpl.rollback();
75     }
76
77     public boolean rollback(Savepoint savepoint) throws SQLException {
78         return interceptorImpl.rollback(savepoint);
79     }
80
81     public boolean setAutoCommit(boolean autocommit) throws SQLException {
82         return interceptorImpl.setAutoCommit(autocommit);
83     }
84
85     public boolean setCatalog(String catalog) throws SQLException {
86         return interceptorImpl.setCatalog(catalog);
87     }
88
89     public boolean transactionBegun() throws SQLException {
90         return interceptorImpl.transactionBegun();
91     }
92
93     public boolean transactionCompleted() throws SQLException {
94         return interceptorImpl.transactionCompleted();
95     }
96
97 }