1 61 62 package org.apache.commons.dbutils; 63 64 import java.lang.reflect.InvocationHandler ; 65 import java.lang.reflect.Proxy ; 66 import java.sql.CallableStatement ; 67 import java.sql.Connection ; 68 import java.sql.Driver ; 69 import java.sql.PreparedStatement ; 70 import java.sql.ResultSet ; 71 import java.sql.ResultSetMetaData ; 72 import java.sql.Statement ; 73 74 84 public class ProxyFactory { 85 86 89 private static final Class [] callableStatementClass = 90 new Class [] { CallableStatement .class }; 91 92 95 private static final Class [] connectionClass = 96 new Class [] { Connection .class }; 97 98 101 private static final Class [] driverClass = new Class [] { Driver .class }; 102 103 106 private static final ProxyFactory instance = new ProxyFactory(); 107 108 111 private static final Class [] metaClass = 112 new Class [] { ResultSetMetaData .class }; 113 114 117 private static final Class [] preparedStatementClass = 118 new Class [] { PreparedStatement .class }; 119 120 123 private static final Class [] resultSetClass = 124 new Class [] { ResultSet .class }; 125 126 129 private static final Class [] statementClass = 130 new Class [] { Statement .class }; 131 132 135 public static ProxyFactory instance() { 136 return instance; 137 } 138 139 142 protected ProxyFactory() { 143 super(); 144 } 145 146 150 public CallableStatement createCallableStatement(InvocationHandler handler) { 151 return (CallableStatement ) Proxy.newProxyInstance( 152 handler.getClass().getClassLoader(), 153 callableStatementClass, 154 handler); 155 } 156 157 161 public Connection createConnection(InvocationHandler handler) { 162 return (Connection ) Proxy.newProxyInstance( 163 handler.getClass().getClassLoader(), 164 connectionClass, 165 handler); 166 } 167 168 172 public Driver createDriver(InvocationHandler handler) { 173 return (Driver ) Proxy.newProxyInstance( 174 handler.getClass().getClassLoader(), 175 driverClass, 176 handler); 177 } 178 179 183 public PreparedStatement createPreparedStatement(InvocationHandler handler) { 184 return (PreparedStatement ) Proxy.newProxyInstance( 185 handler.getClass().getClassLoader(), 186 preparedStatementClass, 187 handler); 188 } 189 190 194 public ResultSet createResultSet(InvocationHandler handler) { 195 return (ResultSet ) Proxy.newProxyInstance( 196 handler.getClass().getClassLoader(), 197 resultSetClass, 198 handler); 199 } 200 201 205 public ResultSetMetaData createResultSetMetaData(InvocationHandler handler) { 206 return (ResultSetMetaData ) Proxy.newProxyInstance( 207 handler.getClass().getClassLoader(), 208 metaClass, 209 handler); 210 } 211 212 216 public Statement createStatement(InvocationHandler handler) { 217 return (Statement ) Proxy.newProxyInstance( 218 handler.getClass().getClassLoader(), 219 statementClass, 220 handler); 221 } 222 223 } 224 | Popular Tags |