1 16 package web.struts; 17 18 import java.lang.reflect.*; 19 import java.sql.PreparedStatement ; 20 import java.sql.ResultSet ; 21 import java.sql.Statement ; 22 23 27 class _Statement implements InvocationHandler { 28 29 private final static Class [] infs = new Class []{Statement .class}; 30 private final static Class [] infs2 = new Class []{PreparedStatement .class}; 31 32 public _Statement(Statement stmt, boolean decode) { 33 statement = stmt; 34 this.decode = decode; 35 } 36 37 41 public Statement getStatement() { 42 if(statement instanceof PreparedStatement ) 43 return (Statement )Proxy.newProxyInstance( 44 statement.getClass().getClassLoader(),infs2, this); 45 return (Statement )Proxy.newProxyInstance( 46 statement.getClass().getClassLoader(),infs, this); 47 } 48 49 public Object invoke(Object proxy, Method m, Object args[]) throws Throwable { 50 String method = m.getName(); 51 if (decode && SETSTRING.equals(method)) 52 try { 53 String param = (String ) args[1]; 54 if (param != null) 55 param = new String (param.getBytes(), "8859_1"); 56 return m.invoke(statement, new Object [] { args[0], param }); 57 } catch (InvocationTargetException e) { 58 throw e.getTargetException(); 59 } 60 if (decode && EXECUTEQUERY.equals(method)) 61 try { 62 ResultSet rs = (ResultSet ) m.invoke(statement, args); 63 return (new _ResultSet(rs, decode)).getResultSet(); 64 } catch (InvocationTargetException e) { 65 throw e.getTargetException(); 66 } 67 try { 68 return m.invoke(statement, args); 69 } catch (InvocationTargetException e) { 70 if (GETQUERYTIMEOUT.equals(method)) 71 return new Integer (0); 72 else 73 throw e.getTargetException(); 74 } 75 } 76 77 private Statement statement; 78 79 private boolean decode; 80 81 private static final String GETQUERYTIMEOUT = "getQueryTimeout"; 82 83 private static final int gqt_return = 0; 84 85 private static final String SETSTRING = "setString"; 86 87 private static final String EXECUTEQUERY = "executeQuery"; 88 } | Popular Tags |