@Override public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { if (!open) throw new SQLException(MSG_CONNECTION_CLOSED); CachedPreparedStatement x = new CachedPreparedStatement(sql, con.prepareStatement(sql, columnNames)); x.setCacheable(false); x.setStatementListener(this); synchronized(nonCacheable) { nonCacheable.add(x); } return x; }
@Override public int executeUpdate() throws SQLException { if (isClosed()) throw new SQLException(MSG_STATEMENT_CLOSED); return ((PreparedStatement)st).executeUpdate(); }
if (!cacheP) cps = new CachedPreparedStatement(sql, con.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability)); cps.setCacheable(false); cps.setStatementListener(this); cps.setOpen(); x.setChecking(true); if (x.getResultSetType() == resultSetType && x.getResultSetConcurrency() == resultSetConcurrency && x.getResultSetHoldability() == resultSetHoldability) break; x.setChecking(false); cps.setOpen(); psHit++; log_debug(pool.getName() + ": PreparedStatement cache hit [" + sql + "," + cps.getParametersString() + "] - " + showHitRate(psHit, psReq, "PS-")); cps = new CachedPreparedStatement(sql, con.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability)); cps.setCacheable(true); cps.setStatementListener(this); cps.setOpen(); log_debug(pool.getName() + ": PreparedStatement cache miss [" + sql + "," + cps.getParametersString() + "] - " + showHitRate(psHit, psReq, "PS-"));
String key = cps.getSQLString(); synchronized(psUsed) if (!cacheP || !cps.isCacheable()) cps.release(); else // else try to recycle it. cps.recycle(); cps.release();
String toTemplateString() { StringBuilder sb = new StringBuilder(); sb.append(super.toString()); sb.append(" ["); sb.append(sql); sb.append(','); sb.append(getParametersString()); sb.append("]"); return sb.toString(); }
(psUsed.remove(0)).close();
@Override public void setInt(int parameterIndex, int x) throws SQLException { if (isClosed()) throw new SQLException(MSG_STATEMENT_CLOSED); ((PreparedStatement)st).setInt(parameterIndex, x); }
@Override public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { if (!open) throw new SQLException(MSG_CONNECTION_CLOSED); CachedPreparedStatement x = new CachedPreparedStatement(sql, con.prepareStatement(sql, autoGeneratedKeys)); x.setCacheable(false); x.setStatementListener(this); synchronized(nonCacheable) { nonCacheable.add(x); } return x; }
@Override public void setBytes(int parameterIndex, byte[] x) throws SQLException { if (isClosed()) throw new SQLException(MSG_STATEMENT_CLOSED); ((PreparedStatement)st).setBytes(parameterIndex, x); }
@Override public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { if (!open) throw new SQLException(MSG_CONNECTION_CLOSED); CachedPreparedStatement x = new CachedPreparedStatement(sql, con.prepareStatement(sql, columnIndexes)); x.setCacheable(false); x.setStatementListener(this); synchronized(nonCacheable) { nonCacheable.add(x); } return x; }
@Override public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException { if (isClosed()) throw new SQLException(MSG_STATEMENT_CLOSED); ((PreparedStatement)st).setObject(parameterIndex, x, targetSqlType, scale); }
@Override public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { if (isClosed()) throw new SQLException(MSG_STATEMENT_CLOSED); ((PreparedStatement)st).setDate(parameterIndex, x, cal); }
@Override public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { if (isClosed()) throw new SQLException(MSG_STATEMENT_CLOSED); ((PreparedStatement)st).setTime(parameterIndex, x, cal); }
@Override public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { if (isClosed()) throw new SQLException(MSG_STATEMENT_CLOSED); ((PreparedStatement)st).setBinaryStream(parameterIndex, x, length); }
@Override public void setFloat(int parameterIndex, float x) throws SQLException { if (isClosed()) throw new SQLException(MSG_STATEMENT_CLOSED); ((PreparedStatement)st).setFloat(parameterIndex, x); }
@Override public void setString(int parameterIndex, String x) throws SQLException { if (isClosed()) throw new SQLException(MSG_STATEMENT_CLOSED); ((PreparedStatement)st).setString(parameterIndex, x); }
@Override public boolean execute() throws SQLException { if (isClosed()) throw new SQLException(MSG_STATEMENT_CLOSED); return ((PreparedStatement)st).execute(); }
@Override public ParameterMetaData getParameterMetaData() throws SQLException { if (isClosed()) throw new SQLException(MSG_STATEMENT_CLOSED); return ((PreparedStatement)st).getParameterMetaData(); }
@Override public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { if (isClosed()) throw new SQLException(MSG_STATEMENT_CLOSED); ((PreparedStatement)st).setBlob(parameterIndex, inputStream, length); }
@Override public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { if (isClosed()) throw new SQLException(MSG_STATEMENT_CLOSED); ((PreparedStatement)st).setCharacterStream(parameterIndex, reader, length); }