source: Ballon/out/artifacts/geisa_artifact/WEB-INF/lib/mysql-connector-java-5.1.21/src/com/mysql/jdbc/ReflectiveStatementInterceptorAdapter.java @ 766

Last change on this file since 766 was 766, checked in by npipsl, 11 years ago
File size: 3.5 KB
Line 
1/*
2 Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved., Inc. All rights reserved.
3 U.S. Government Rights - Commercial software. Government users are subject
4 to the Sun Microsystems, Inc. standard license agreement and applicable
5 provisions of the FAR and its supplements. Use is subject to license terms.
6 This distribution may include materials developed by third parties.Sun,
7 Sun Microsystems, the Sun logo and MySQL Enterprise Monitor are
8 trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S.
9 and other countries.
10
11 Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved., Inc. Tous droits réservés.
12 L'utilisation est soumise aux termes du contrat de licence.Cette
13 distribution peut comprendre des composants développés par des tierces
14 parties.Sun, Sun Microsystems,  le logo Sun et  MySQL Enterprise Monitor sont
15 des marques de fabrique ou des marques déposées de Sun Microsystems, Inc.
16 aux Etats-Unis et dans du'autres pays.
17
18 */
19
20package com.mysql.jdbc;
21
22import java.lang.reflect.InvocationTargetException;
23import java.lang.reflect.Method;
24import java.sql.SQLException;
25import java.util.Properties;
26
27public class ReflectiveStatementInterceptorAdapter implements
28                StatementInterceptorV2 {
29
30        private final StatementInterceptor toProxy;
31       
32        final Method v2PostProcessMethod;
33
34        public ReflectiveStatementInterceptorAdapter(StatementInterceptor toProxy) {
35                this.toProxy = toProxy;
36                this.v2PostProcessMethod = getV2PostProcessMethod(toProxy.getClass());
37        }
38       
39        public void destroy() {
40                toProxy.destroy();
41        }
42
43        public boolean executeTopLevelOnly() {
44                return toProxy.executeTopLevelOnly();
45        }
46
47        public void init(Connection conn, Properties props) throws SQLException {
48                toProxy.init(conn, props);
49        }
50
51        public ResultSetInternalMethods postProcess(String sql,
52                        Statement interceptedStatement,
53                        ResultSetInternalMethods originalResultSet, Connection connection,
54                        int warningCount, boolean noIndexUsed, boolean noGoodIndexUsed, 
55                        SQLException statementException) throws SQLException {
56                // TODO Auto-generated method stub
57                try {
58                        return (ResultSetInternalMethods) v2PostProcessMethod.invoke(toProxy, new Object[] {sql,
59                                interceptedStatement,
60                                originalResultSet, connection,
61                                Integer.valueOf(warningCount), noIndexUsed ? Boolean.TRUE : Boolean.FALSE, noGoodIndexUsed ? Boolean.TRUE: Boolean.FALSE,
62                                                statementException});
63                } catch (IllegalArgumentException e) {
64                        SQLException sqlEx = new SQLException("Unable to reflectively invoke interceptor");
65                        sqlEx.initCause(e);
66                       
67                        throw sqlEx;
68                } catch (IllegalAccessException e) {
69                        SQLException sqlEx = new SQLException("Unable to reflectively invoke interceptor");
70                        sqlEx.initCause(e);
71                       
72                        throw sqlEx;
73                } catch (InvocationTargetException e) {
74                        SQLException sqlEx = new SQLException("Unable to reflectively invoke interceptor");
75                        sqlEx.initCause(e);
76                       
77                        throw sqlEx;
78                }
79        }
80
81        public ResultSetInternalMethods preProcess(String sql,
82                        Statement interceptedStatement, Connection connection)
83                        throws SQLException {
84                return toProxy.preProcess(sql, interceptedStatement, connection);
85        }
86
87        public static final Method getV2PostProcessMethod(Class<?> toProxyClass) {
88                try {
89                        Method postProcessMethod = toProxyClass.getMethod("postProcess", new Class[] {
90                                        String.class, Statement.class, ResultSetInternalMethods.class, Connection.class, Integer.TYPE, 
91                                        Boolean.TYPE, Boolean.TYPE, SQLException.class});
92                       
93                        return postProcessMethod;
94                } catch (SecurityException e) {
95                        return null;
96                } catch (NoSuchMethodException e) {
97                        return null;
98                }
99        }
100}
Note: See TracBrowser for help on using the repository browser.