/** * Close the LobCreator, if any. */ @Override public void cleanup() { this.lobCreator.close(); }
@Override public final Integer doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { LobCreator lobCreator = this.lobHandler.getLobCreator(); try { setValues(ps, lobCreator); return ps.executeUpdate(); } finally { lobCreator.close(); } }
public Object doInTransaction(TransactionStatus status) { try { JdbcTemplate template = dbDialect.getJdbcTemplate(); int affect = template.update(sql, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { doPreparedStatement(ps, dbDialect, lobCreator, header, columns); } }); return affect; } finally { lobCreator.close(); } } });
@Test public void testCorrectCleanup() throws SQLException { SqlLobValue lob = new SqlLobValue("Bla", handler); lob.setTypeValue(preparedStatement, 1, Types.CLOB, "test"); lob.cleanup(); verify(creator).setClobAsString(preparedStatement, 1, "Bla"); verify(creator).close(); }
@Test public void testCreatingPreparedStatementCallback() throws SQLException { LobHandler handler = mock(LobHandler.class); LobCreator creator = mock(LobCreator.class); PreparedStatement ps = mock(PreparedStatement.class); given(handler.getLobCreator()).willReturn(creator); given(ps.executeUpdate()).willReturn(3); class SetValuesCalled { boolean b = false; } final SetValuesCalled svc = new SetValuesCalled(); AbstractLobCreatingPreparedStatementCallback psc = new AbstractLobCreatingPreparedStatementCallback( handler) { @Override protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException, DataAccessException { svc.b = true; } }; assertEquals(Integer.valueOf(3), psc.doInPreparedStatement(ps)); assertTrue(svc.b); verify(creator).close(); verify(handler).getLobCreator(); verify(ps).executeUpdate(); }
@Override public void beforeCompletion() { // Close the LobCreator early if possible, to avoid issues with strict JTA // implementations that issue warnings when doing JDBC operations after // transaction completion. this.beforeCompletionCalled = true; this.lobCreator.close(); }
@Override public void beforeCompletion() { // Close the LobCreator early if possible, to avoid issues with strict JTA // implementations that issue warnings when doing JDBC operations after // transaction completion. this.beforeCompletionCalled = true; this.lobCreator.close(); }
/** * Close the LobCreator, if any. */ public void cleanup() { this.lobCreator.close(); }
public void afterCompletion(int status) { if (!this.beforeCompletionCalled) { // beforeCompletion not called before (probably because of JTA rollback). // Close the LobCreator here. this.lobCreator.close(); } }
@Override public void afterCompletion(int status) { if (!this.beforeCompletionCalled) { // beforeCompletion not called before (probably because of flushing on commit // in the transaction manager, after the chain of beforeCompletion calls). // Close the LobCreator here. this.lobCreator.close(); } }
/** * Close the LobCreator, if any. */ @Override public void cleanup() { this.lobCreator.close(); }
@Override public void beforeCompletion() { // Close the LobCreator early if possible, to avoid issues with strict JTA // implementations that issue warnings when doing JDBC operations after // transaction completion. this.beforeCompletionCalled = true; this.lobCreator.close(); }
@Override public void afterCompletion(int status) { if (!this.beforeCompletionCalled) { // beforeCompletion not called before (probably because of JTA rollback). // Close the LobCreator here. this.lobCreator.close(); } }
@Override public void afterCompletion(int status) { if (!this.beforeCompletionCalled) { // beforeCompletion not called before (probably because of flushing on commit // in the transaction manager, after the chain of beforeCompletion calls). // Close the LobCreator here. this.lobCreator.close(); } }
public void beforeCompletion() { // Close the LobCreator early if possible, to avoid issues with strict JTA // implementations that issue warnings when doing JDBC operations after // transaction completion. this.beforeCompletionCalled = true; this.lobCreator.close(); }
public void beforeCompletion() { this.lobCreator.close(); } }
@Override public final Integer doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { LobCreator lobCreator = this.lobHandler.getLobCreator(); try { setValues(ps, lobCreator); return ps.executeUpdate(); } finally { lobCreator.close(); } }
public final Integer doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { LobCreator lobCreator = this.lobHandler.getLobCreator(); try { setValues(ps, lobCreator); return ps.executeUpdate(); } finally { lobCreator.close(); } }
public Object doInTransaction(TransactionStatus status) { try { failedDatas.clear(); // 先清理 processedDatas.clear(); interceptor.transactionBegin(context, Arrays.asList(data), dbDialect); JdbcTemplate template = dbDialect.getJdbcTemplate(); int affect = template.update(data.getSql(), new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { doPreparedStatement(ps, dbDialect, lobCreator, data); } }); interceptor.transactionEnd(context, Arrays.asList(data), dbDialect); return affect; } finally { lobCreator.close(); } } });
public Object doInTransaction(TransactionStatus status) { // 初始化一下内容 try { failedDatas.clear(); // 先清理 processedDatas.clear(); interceptor.transactionBegin(context, splitDatas, dbDialect); JdbcTemplate template = dbDialect.getJdbcTemplate(); int[] affects = template.batchUpdate(sql, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int idx) throws SQLException { doPreparedStatement(ps, dbDialect, lobCreator, splitDatas.get(idx)); } public int getBatchSize() { return splitDatas.size(); } }); interceptor.transactionEnd(context, splitDatas, dbDialect); return affects; } finally { lobCreator.close(); } }