1 package com.protomatter.jdbc.pool; 2 3 import java.io.*; 4 import java.sql.*; 5 import java.util.*; 6 7 import com.protomatter.syslog.Channel; 8 9 14 class StatementWrapper 15 extends JDBCWrapper 16 implements Statement 17 { 18 private ConnectionWrapper connection = null; 19 private Statement statement = null; 20 private boolean isClosed = false; 21 private Channel log = Channel.forPackage(StatementWrapper.class); 22 23 public StatementWrapper(ConnectionWrapper connection, Statement statement) 24 { 25 super(); 26 this.connection = connection; 27 this.statement = statement; 28 } 29 30 public Statement getStatement() 31 { 32 if (this.statement == null) 33 return null; 34 return this.statement; 35 } 36 37 private final void checkClosed() 38 throws SQLException 39 { 40 if (this.isClosed) 41 throw new SQLException("Statement is already closed."); 42 } 43 44 public ResultSet executeQuery(String sql) 45 throws SQLException 46 { 47 checkClosed(); 48 return (ResultSet)callMethod(statement, "executeQuery", new Class [] { String .class }, new Object [] { sql }); 49 } 50 51 public int executeUpdate(String sql) 52 throws SQLException 53 { 54 checkClosed(); 55 return callIntMethod(statement, "executeUpdate", new Class [] { String .class }, new Object [] { sql }); 56 } 57 58 public void close() 59 throws SQLException 60 { 61 if (this.isClosed) 62 return; 63 64 callMethod(statement, "close"); 65 66 this.isClosed = true; 67 this.connection = null; 68 this.statement = null; 69 } 70 71 public int getMaxFieldSize() 72 throws SQLException 73 { 74 checkClosed(); 75 return callIntMethod(statement, "getMaxFieldSize", new Class [0], new Object [0]); 76 } 77 78 public void setMaxFieldSize(int size) 79 throws SQLException 80 { 81 checkClosed(); 82 callMethod(statement, "setMaxFieldSize", new Class [] { Integer.TYPE }, new Object [] { new Integer (size) }); 83 } 84 85 public int getMaxRows() 86 throws SQLException 87 { 88 checkClosed(); 89 return callIntMethod(statement, "getMaxRows", new Class [0], new Object [0]); 90 } 91 92 public void setMaxRows(int rows) 93 throws SQLException 94 { 95 checkClosed(); 96 callMethod(statement, "setMaxRows", new Class [] { Integer.TYPE }, new Object [] { new Integer (rows) }); 97 } 98 99 public void setEscapeProcessing(boolean setting) 100 throws SQLException 101 { 102 checkClosed(); 103 callMethod(statement, "setEscapeProcessing", new Class [] { Boolean .class }, new Object [] { new Boolean (setting) }); 104 } 105 106 public int getQueryTimeout() 107 throws SQLException 108 { 109 checkClosed(); 110 return callIntMethod(statement, "getQueryTimeout", new Class [0], new Object [0]); 111 } 112 113 public void setQueryTimeout(int timeout) 114 throws SQLException 115 { 116 checkClosed(); 117 callMethod(statement, "setQueryTimeout", new Class [] { Integer.TYPE }, new Object [] { new Integer (timeout) }); 118 } 119 120 public void cancel() 121 throws SQLException 122 { 123 checkClosed(); 124 callMethod(statement, "cancel"); 125 } 126 127 public SQLWarning getWarnings() 128 throws SQLException 129 { 130 checkClosed(); 131 return (SQLWarning)callMethod(statement, "getWarnings"); 132 } 133 134 public void clearWarnings() 135 throws SQLException 136 { 137 checkClosed(); 138 callMethod(statement, "clearWarnings"); 139 } 140 141 public void setCursorName(String name) 142 throws SQLException 143 { 144 checkClosed(); 145 callMethod(statement, "setCursorName", new Class [] { String .class }, new Object [] { name }); 146 } 147 148 public boolean execute(String sql) 149 throws SQLException 150 { 151 checkClosed(); 152 return callBooleanMethod(statement, "execute", new Class [] { String .class }, new Object [] { sql }); 153 } 154 155 public ResultSet getResultSet() 156 throws SQLException 157 { 158 checkClosed(); 159 return (ResultSet)callMethod(statement, "getResultSet"); 160 } 161 162 public int getUpdateCount() 163 throws SQLException 164 { 165 checkClosed(); 166 return callIntMethod(statement, "getUpdateCount", new Class [0], new Object [0]); 167 } 168 169 public boolean getMoreResults() 170 throws SQLException 171 { 172 checkClosed(); 173 return callBooleanMethod(statement, "getMoreResults", new Class [0], new Object [0]); 174 } 175 176 public void setFetchDirection(int direction) 177 throws SQLException 178 { 179 checkClosed(); 180 callMethod(statement, "setFetchDirection", new Class [] { Integer.TYPE }, new Object [] { new Integer (direction) }); 181 } 182 183 public int getFetchDirection() 184 throws SQLException 185 { 186 checkClosed(); 187 return callIntMethod(statement, "getFetchDirection", new Class [0], new Object [0]); 188 } 189 190 public void setFetchSize(int size) 191 throws SQLException 192 { 193 checkClosed(); 194 callMethod(statement, "setFetchSize", new Class [] { Integer.TYPE }, new Object [] { new Integer (size) }); 195 } 196 197 public int getFetchSize() 198 throws SQLException 199 { 200 checkClosed(); 201 return callIntMethod(statement, "getFetchSize", new Class [0], new Object [0]); 202 } 203 204 public int getResultSetConcurrency() 205 throws SQLException 206 { 207 checkClosed(); 208 return callIntMethod(statement, "getResultSetConcurrency", new Class [0], new Object [0]); 209 } 210 211 public int getResultSetType() 212 throws SQLException 213 { 214 checkClosed(); 215 return callIntMethod(statement, "getResultSetType", new Class [0], new Object [0]); 216 } 217 218 public void addBatch(String sql) 219 throws SQLException 220 { 221 checkClosed(); 222 callMethod(statement, "addBatch", new Class [] { String .class }, new Object [] { sql }); 223 } 224 225 public void clearBatch() 226 throws SQLException 227 { 228 checkClosed(); 229 callMethod(statement, "clearBatch", new Class [0], new Object [0]); 230 } 231 232 public int[] executeBatch() 233 throws SQLException 234 { 235 checkClosed(); 236 return (int[])callMethod(statement, "executeBatch", new Class [0], new Object [0]); 238 } 239 240 public Connection getConnection() 241 throws SQLException 242 { 243 checkClosed(); 244 return (Connection)callMethod(statement, "getConnection", new Class [0], new Object [0]); 245 } 246 } 247 | Popular Tags |