2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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.
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.
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
18 package com.mysql.clusterj.jdbc;
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;
25 import java.sql.SQLException;
26 import java.sql.Savepoint;
28 import java.util.Properties;
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.
36 public class ConnectionLifecycleInterceptor
37 implements com.mysql.jdbc.ConnectionLifecycleInterceptor {
39 /** My message translator */
40 static final I18NHelper local = I18NHelper.getInstance(ConnectionLifecycleInterceptor.class);
43 static final Logger logger = LoggerFactoryService.getFactory().getInstance(ConnectionLifecycleInterceptor.class);
45 /** The delegate for all methods. */
46 private InterceptorImpl interceptorImpl;
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
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);
60 public void destroy() {
61 interceptorImpl.destroy(this);
62 interceptorImpl = null;
65 public void close() throws SQLException {
66 interceptorImpl.close();
69 public boolean commit() throws SQLException {
70 return interceptorImpl.commit();
73 public boolean rollback() throws SQLException {
74 return interceptorImpl.rollback();
77 public boolean rollback(Savepoint savepoint) throws SQLException {
78 return interceptorImpl.rollback(savepoint);
81 public boolean setAutoCommit(boolean autocommit) throws SQLException {
82 return interceptorImpl.setAutoCommit(autocommit);
85 public boolean setCatalog(String catalog) throws SQLException {
86 return interceptorImpl.setCatalog(catalog);
89 public boolean transactionBegun() throws SQLException {
90 return interceptorImpl.transactionBegun();
93 public boolean transactionCompleted() throws SQLException {
94 return interceptorImpl.transactionCompleted();