/** * Deletes all ACEs defined in the acl_entry table belonging to the presented * ObjectIdentity primary key. * * @param oidPrimaryKey the rows in acl_entry to delete */ protected void deleteEntries(Long oidPrimaryKey) { jdbcOperations.update(deleteEntryByObjectIdentityForeignKey, oidPrimaryKey); }
/** * Deletes a single row from acl_object_identity that is associated with the presented * ObjectIdentity primary key. * <p> * We do not delete any entries from acl_class, even if no classes are using that * class any longer. This is a deadlock avoidance approach. * * @param oidPrimaryKey to delete the acl_object_identity */ protected void deleteObjectIdentity(Long oidPrimaryKey) { // Delete the acl_object_identity row jdbcOperations.update(deleteObjectIdentityByPrimaryKey, oidPrimaryKey); }
@Override protected void doInTransactionWithoutResult(TransactionStatus status) { JdbcOperationsSessionRepository.this.jdbcOperations.update( JdbcOperationsSessionRepository.this.deleteSessionQuery, id); }
@Override public int update(String sql, SqlParameterSource paramSource) throws DataAccessException { return getJdbcOperations().update(getPreparedStatementCreator(sql, paramSource)); }
public void cleanUpExpiredSessions() { Integer deletedCount = this.transactionOperations.execute((status) -> JdbcOperationsSessionRepository.this.jdbcOperations.update( JdbcOperationsSessionRepository.this.deleteSessionsByExpiryTimeQuery, System.currentTimeMillis())); if (logger.isDebugEnabled()) { logger.debug("Cleaned up " + deletedCount + " expired sessions"); } }
@Override public void afterRead(Long id) { int count = jdbcTemplate.update("UPDATE BATCH_STAGING SET PROCESSED=? WHERE ID=? AND PROCESSED=?", StagingItemWriter.DONE, id, StagingItemWriter.NEW); if (count != 1) { throw new OptimisticLockingFailureException("The staging record with ID=" + id + " was updated concurrently when trying to mark as complete (updated " + count + " records."); } }
@Override public int update( String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, @Nullable String[] keyColumnNames) throws DataAccessException { PreparedStatementCreator psc = getPreparedStatementCreator(sql, paramSource, pscf -> { if (keyColumnNames != null) { pscf.setGeneratedKeysColumnNames(keyColumnNames); } else { pscf.setReturnGeneratedKeys(true); } }); return getJdbcOperations().update(psc, generatedKeyHolder); }
@Before public void onSetUp() throws Exception { jdbcTemplate.update("delete from TRADE"); jdbcTemplate.update("delete from CUSTOMER where ID > 4"); jdbcTemplate.update("update CUSTOMER set credit=100000"); List<Map<String, Object>> list = jdbcTemplate.queryForList("select name, CREDIT from CUSTOMER"); for (Map<String, Object> map : list) { credits.put((String) map.get("NAME"), ((Number) map.get("CREDIT")).doubleValue()); } }
/** * Creates an entry in the acl_object_identity table for the passed ObjectIdentity. * The Sid is also necessary, as acl_object_identity has defined the sid column as * non-null. * * @param object to represent an acl_object_identity for * @param owner for the SID column (will be created if there is no acl_sid entry for * this particular Sid already) */ protected void createObjectIdentity(ObjectIdentity object, Sid owner) { Long sidId = createOrRetrieveSidPrimaryKey(owner, true); Long classId = createOrRetrieveClassPrimaryKey(object.getType(), true, object.getIdentifier().getClass()); jdbcOperations.update(insertObjectIdentity, classId, object.getIdentifier().toString(), sidId, Boolean.TRUE); }
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { Assert.notNull(this.stepName, "Step name not set. Either this class was not registered as a listener " + "or the key 'stepName' was not found in the Job's ExecutionContext."); this.jdbcTemplate.update("insert into ERROR_LOG values (?, ?, '"+getSkipCount()+" records were skipped!')", jobName, stepName); return RepeatStatus.FINISHED; }
@Test public void testLaunchJob() throws Exception { jdbcTemplate.update("DELETE FROM PLAYERS"); jdbcTemplate.update("DELETE FROM GAMES"); jdbcTemplate.update("DELETE FROM PLAYER_SUMMARY"); jobLauncherTestUtils.launchJob(); int count = jdbcTemplate.queryForObject("SELECT COUNT(*) from PLAYER_SUMMARY", Integer.class); assertTrue(count > 0); } }
/** * @see TradeDao */ @Override public void writeTrade(Trade trade) { Long id = incrementer.nextLongValue(); log.debug("Processing: " + trade); jdbcTemplate.update(INSERT_TRADE_RECORD, id, trade.getIsin(), trade.getQuantity(), trade.getPrice(), trade.getCustomer()); }
@Test public void deleteByIdWithoutTransaction() { this.repository = new JdbcOperationsSessionRepository(this.jdbcOperations); this.repository.deleteById("testSessionId"); verify(this.jdbcOperations, times(1)).update( eq("DELETE FROM SPRING_SESSION WHERE SESSION_ID = ?"), anyString()); verifyZeroInteractions(this.jdbcOperations); verifyZeroInteractions(this.transactionManager); }
@Test public void cleanUpExpiredSessionsWithoutTransaction() { this.repository = new JdbcOperationsSessionRepository(this.jdbcOperations); this.repository.cleanUpExpiredSessions(); verify(this.jdbcOperations, times(1)).update( eq("DELETE FROM SPRING_SESSION WHERE EXPIRY_TIME < ?"), anyLong()); verifyZeroInteractions(this.jdbcOperations); verifyZeroInteractions(this.transactionManager); }
@Test public void delete() { String sessionId = "testSessionId"; this.repository.deleteById(sessionId); assertPropagationRequiresNew(); verify(this.jdbcOperations, times(1)).update(startsWith("DELETE"), eq(sessionId)); }
@Test public void saveNewWithoutTransaction() { this.repository = new JdbcOperationsSessionRepository(this.jdbcOperations); JdbcOperationsSessionRepository.JdbcSession session = this.repository .createSession(); this.repository.save(session); verify(this.jdbcOperations, times(1)).update( startsWith("INSERT INTO SPRING_SESSION"), isA(PreparedStatementSetter.class)); verifyZeroInteractions(this.jdbcOperations); verifyZeroInteractions(this.transactionManager); }
@Test public void saveNewWithoutAttributes() { JdbcOperationsSessionRepository.JdbcSession session = this.repository .createSession(); this.repository.save(session); assertThat(session.isNew()).isFalse(); assertPropagationRequiresNew(); verify(this.jdbcOperations, times(1)).update(startsWith("INSERT"), isA(PreparedStatementSetter.class)); verifyZeroInteractions(this.jdbcOperations); }
@Before public void before() { mailSender.clear(); errorHandler.clear(); jdbcTemplate.update("create table USERS (ID INTEGER, NAME VARCHAR(40), EMAIL VARCHAR(20))"); }
@Test public void cleanupExpiredSessions() { this.repository.cleanUpExpiredSessions(); assertPropagationRequiresNew(); verify(this.jdbcOperations, times(1)).update(startsWith("DELETE"), anyLong()); }
@Test public void saveUpdatedWithoutTransaction() { this.repository = new JdbcOperationsSessionRepository(this.jdbcOperations); JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession( "primaryKey", new MapSession()); session.setLastAccessedTime(Instant.now()); this.repository.save(session); verify(this.jdbcOperations, times(1)).update(startsWith("UPDATE SPRING_SESSION"), isA(PreparedStatementSetter.class)); verifyZeroInteractions(this.jdbcOperations); verifyZeroInteractions(this.transactionManager); }