001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.db.driver; 020 021import java.lang.reflect.InvocationTargetException; 022import java.sql.Connection; 023import java.sql.ResultSet; 024import java.sql.SQLException; 025import java.sql.SQLWarning; 026import java.sql.Statement; 027 028import lucee.commons.lang.ExceptionUtil; 029import lucee.runtime.PageContext; 030import lucee.runtime.exp.PageRuntimeException; 031import lucee.runtime.op.Caster; 032 033public class StatementProxy implements StatementPro { 034 035 protected ConnectionProxy conn; 036 protected Statement stat; 037 038 public StatementProxy(ConnectionProxy conn,Statement stat){ 039 this.conn=conn; 040 this.stat=stat; 041 } 042 043 @Override 044 public boolean execute(PageContext pc,String sql) throws SQLException { 045 return stat.execute(sql); 046 } 047 048 @Override 049 public boolean execute(PageContext pc,String sql, int autoGeneratedKeys) throws SQLException { 050 return stat.execute(sql, autoGeneratedKeys); 051 } 052 053 @Override 054 public boolean execute(PageContext pc,String sql, int[] columnIndexes) throws SQLException { 055 return stat.execute(sql, columnIndexes); 056 } 057 058 @Override 059 public boolean execute(PageContext pc,String sql, String[] columnNames) throws SQLException { 060 return stat.execute(sql, columnNames); 061 } 062 063 @Override 064 public ResultSet executeQuery(PageContext pc,String sql) throws SQLException { 065 return stat.executeQuery(sql); 066 } 067 068 @Override 069 public int executeUpdate(PageContext pc,String sql) throws SQLException { 070 return stat.executeUpdate(sql); 071 } 072 073 @Override 074 public int executeUpdate(PageContext pc,String sql, int autoGeneratedKeys) throws SQLException { 075 return stat.executeUpdate(sql, autoGeneratedKeys); 076 } 077 078 @Override 079 public int executeUpdate(PageContext pc,String sql, int[] columnIndexes) throws SQLException { 080 return stat.executeUpdate(sql, columnIndexes); 081 } 082 083 @Override 084 public int executeUpdate(PageContext pc,String sql, String[] columnNames) throws SQLException { 085 return stat.executeUpdate(sql, columnNames); 086 } 087 088 089 @Override 090 public boolean execute(String sql) throws SQLException { 091 return stat.execute(sql); 092 } 093 094 @Override 095 public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { 096 return stat.execute(sql, autoGeneratedKeys); 097 } 098 099 @Override 100 public boolean execute(String sql, int[] columnIndexes) throws SQLException { 101 return stat.execute(sql, columnIndexes); 102 } 103 104 @Override 105 public boolean execute(String sql, String[] columnNames) throws SQLException { 106 return stat.execute(sql, columnNames); 107 } 108 109 @Override 110 public int[] executeBatch() throws SQLException { 111 return stat.executeBatch(); 112 } 113 114 @Override 115 public ResultSet executeQuery(String sql) throws SQLException { 116 return stat.executeQuery(sql); 117 } 118 119 @Override 120 public int executeUpdate(String sql) throws SQLException { 121 return stat.executeUpdate(sql); 122 } 123 124 @Override 125 public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { 126 return stat.executeUpdate(sql, autoGeneratedKeys); 127 } 128 129 @Override 130 public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { 131 return stat.executeUpdate(sql, columnIndexes); 132 } 133 134 @Override 135 public int executeUpdate(String sql, String[] columnNames) throws SQLException { 136 return stat.executeUpdate(sql, columnNames); 137 } 138 139 @Override 140 public Connection getConnection() throws SQLException { 141 return conn; 142 } 143 144 @Override 145 public ResultSet getGeneratedKeys() throws SQLException { 146 return stat.getGeneratedKeys(); 147 } 148 149 @Override 150 public ResultSet getResultSet() throws SQLException { 151 return stat.getResultSet(); 152 } 153 154 155 156 157 158 @Override 159 public boolean isWrapperFor(Class<?> iface) throws SQLException { 160 return stat.isWrapperFor(iface); 161 } 162 163 @Override 164 public <T> T unwrap(Class<T> iface) throws SQLException { 165 return stat.unwrap(iface); 166 } 167 168 @Override 169 public void addBatch(String sql) throws SQLException { 170 stat.addBatch(sql); 171 } 172 173 @Override 174 public void cancel() throws SQLException { 175 stat.cancel(); 176 } 177 178 @Override 179 public void clearBatch() throws SQLException { 180 stat.clearBatch(); 181 } 182 183 @Override 184 public void clearWarnings() throws SQLException { 185 stat.clearWarnings(); 186 } 187 188 @Override 189 public void close() throws SQLException { 190 stat.close(); 191 } 192 193 @Override 194 public int getFetchDirection() throws SQLException { 195 return stat.getFetchDirection(); 196 } 197 198 @Override 199 public int getFetchSize() throws SQLException { 200 return stat.getFetchSize(); 201 } 202 203 @Override 204 public int getMaxFieldSize() throws SQLException { 205 return stat.getMaxFieldSize(); 206 } 207 208 @Override 209 public int getMaxRows() throws SQLException { 210 return stat.getMaxRows(); 211 } 212 213 @Override 214 public boolean getMoreResults() throws SQLException { 215 return stat.getMoreResults(); 216 } 217 218 @Override 219 public boolean getMoreResults(int current) throws SQLException { 220 return stat.getMoreResults(current); 221 } 222 223 @Override 224 public int getQueryTimeout() throws SQLException { 225 return stat.getQueryTimeout(); 226 } 227 228 @Override 229 public int getResultSetConcurrency() throws SQLException { 230 return stat.getResultSetConcurrency(); 231 } 232 233 @Override 234 public int getResultSetHoldability() throws SQLException { 235 return stat.getResultSetHoldability(); 236 } 237 238 @Override 239 public int getResultSetType() throws SQLException { 240 return stat.getResultSetType(); 241 } 242 243 @Override 244 public int getUpdateCount() throws SQLException { 245 return stat.getUpdateCount(); 246 } 247 248 @Override 249 public SQLWarning getWarnings() throws SQLException { 250 return stat.getWarnings(); 251 } 252 253 @Override 254 public boolean isClosed() throws SQLException { 255 return stat.isClosed(); 256 } 257 258 @Override 259 public boolean isPoolable() throws SQLException { 260 return stat.isPoolable(); 261 } 262 263 @Override 264 public void setCursorName(String name) throws SQLException { 265 stat.setCursorName(name); 266 } 267 268 @Override 269 public void setEscapeProcessing(boolean enable) throws SQLException { 270 stat.setEscapeProcessing(enable); 271 } 272 273 @Override 274 public void setFetchDirection(int direction) throws SQLException { 275 stat.setFetchDirection(direction); 276 } 277 278 @Override 279 public void setFetchSize(int rows) throws SQLException { 280 stat.setFetchSize(rows); 281 } 282 283 @Override 284 public void setMaxFieldSize(int max) throws SQLException { 285 stat.setMaxFieldSize(max); 286 } 287 288 @Override 289 public void setMaxRows(int max) throws SQLException { 290 stat.setMaxRows(max); 291 } 292 293 @Override 294 public void setPoolable(boolean poolable) throws SQLException { 295 stat.setPoolable(poolable); 296 } 297 298 @Override 299 public void setQueryTimeout(int seconds) throws SQLException { 300 stat.setQueryTimeout(seconds); 301 } 302 303 public void closeOnCompletion() throws SQLException { 304 // used reflection to make sure this work with Java 5 and 6 305 try { 306 stat.getClass().getMethod("closeOnCompletion", new Class[0]).invoke(stat, new Object[0]); 307 } 308 catch (Throwable t) { 309 ExceptionUtil.rethrowIfNecessary(t); 310 if(t instanceof InvocationTargetException && ((InvocationTargetException)t).getTargetException() instanceof SQLException) 311 throw (SQLException)((InvocationTargetException)t).getTargetException(); 312 throw new PageRuntimeException(Caster.toPageException(t)); 313 } 314 } 315 316 public boolean isCloseOnCompletion() throws SQLException { 317 // used reflection to make sure this work with Java 5 and 6 318 try { 319 return Caster.toBooleanValue(stat.getClass().getMethod("isCloseOnCompletion", new Class[0]).invoke(stat, new Object[0])); 320 } 321 catch (Throwable t) { 322 ExceptionUtil.rethrowIfNecessary(t); 323 if(t instanceof InvocationTargetException && ((InvocationTargetException)t).getTargetException() instanceof SQLException) 324 throw (SQLException)((InvocationTargetException)t).getTargetException(); 325 throw new PageRuntimeException(Caster.toPageException(t)); 326 } 327 } 328}