static PreparedStatement create(PreparedStatement ps, Collection<BlobHandler> toCleanup) { return (PreparedStatement)Proxy.newProxyInstance(PreparedStatement.class.getClassLoader(), new Class<?>[] {PreparedStatement.class}, new BlobCleanupPreparedStatement(ps, toCleanup)); }
/** Encapsulates the logic for creating a prepared statement with the arguments set*/ private PreparedStatement createPreparedStatement(Connection c, String sql, Object[] vs) throws PalantirSqlException { PreparedStatement ps; ps = Connections.prepareStatement(c, sql); List<BlobHandler> toClean = Lists.newArrayList(); if (vs != null) { try { for (int i=0; i < vs.length; i++) { BlobHandler cleanup = setObject(c, ps, i+1, vs[i]); if (cleanup != null) { toClean.add(cleanup); } } } catch (Exception e) { // if we throw, we need to clean up any blobs we have already made for (BlobHandler cleanupBlob : toClean) { try { cleanupBlob.freeTemporary(); } catch (Exception e1) { SqlLoggers.LOGGER.error("failed to free temp blob", e1); //$NON-NLS-1$ } } BasicSQLUtils.throwUncheckedIfSQLException(e); throw Throwables.throwUncheckedException(e); } } return BlobCleanupPreparedStatement.create(ps, toClean); }
/** Encapsulates the logic for creating a prepared statement with the arguments set*/ private PreparedStatement createPreparedStatement(Connection c, String sql, Object[] vs) throws PalantirSqlException { PreparedStatement ps; ps = Connections.prepareStatement(c, sql); List<BlobHandler> toClean = Lists.newArrayList(); if (vs != null) { try { for (int i=0; i < vs.length; i++) { BlobHandler cleanup = setObject(c, ps, i+1, vs[i]); if (cleanup != null) { toClean.add(cleanup); } } } catch (Exception e) { // if we throw, we need to clean up any blobs we have already made for (BlobHandler cleanupBlob : toClean) { try { cleanupBlob.freeTemporary(); } catch (Exception e1) { SqlLoggers.LOGGER.error("failed to free temp blob", e1); //$NON-NLS-1$ } } BasicSQLUtils.throwUncheckedIfSQLException(e); throw Throwables.throwUncheckedException(e); } } return BlobCleanupPreparedStatement.create(ps, toClean); }
static PreparedStatement create(PreparedStatement ps, Collection<BlobHandler> toCleanup) { return (PreparedStatement)Proxy.newProxyInstance(PreparedStatement.class.getClassLoader(), new Class<?>[] {PreparedStatement.class}, new BlobCleanupPreparedStatement(ps, toCleanup)); }