List of usage examples for org.springframework.transaction.support TransactionCallbackWithoutResult TransactionCallbackWithoutResult
TransactionCallbackWithoutResult
From source file:com.github.akiraly.db4j.uow.UowTest.java
@Test(timeout = 5000) public void testPersistStandaloneUow() { final String uow1User = "u100"; final Uow uow1 = new Uow(uow1User); assertUowCount(0);//from ww w . j a va 2 s . c o m EntityWithLongId<Uow> uow1WithId1 = EntityWithLongId.of(uow1, () -> { return transactionTemplate.execute((TransactionStatus status) -> { return uowDaoFactory.newDao().persist(uow1); }); }); Assert.assertSame(uow1, uow1WithId1.getEntity()); assertUowCount(0); Assert.assertTrue(uow1WithId1.getId() > 0); assertUowCount(1); EntityWithLongId<Uow> uow1WithId2 = uowDaoFactory.newDao().lazyPersist(uow1); assertUowCount(1); Assert.assertSame(uow1, uow1WithId2.getEntity()); transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { Assert.assertTrue(uow1WithId2.getId() > 0); } }); assertUowCount(2); Assert.assertNotEquals(uow1WithId1.getId(), uow1WithId2.getId()); uowDaoFactory.newDao().lazyPersist(uow1).getId(); assertUowCount(2); EntityWithLongId<Uow> loadedUow1byId1 = EntityWithLongId.of(() -> { return transactionTemplate.execute((TransactionStatus status) -> { return uowDaoFactory.newDao().lazyFind(uow1WithId1.getId()).getEntity(); }); }, uow1WithId1.getId()); Assert.assertEquals(uow1WithId1.getId(), loadedUow1byId1.getId()); Assert.assertEquals(uow1User, loadedUow1byId1.getEntity().getUser()); EntityWithLongId<Uow> loadedUow1byId2 = uowDaoFactory.newDao().lazyFind(uow1WithId2.getId()); Assert.assertEquals(uow1WithId2.getId(), loadedUow1byId2.getId()); transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { Assert.assertEquals(uow1User, loadedUow1byId2.getEntity().getUser()); } }); }
From source file:com.example.test.HibernateBookRepositoryTest.java
@After public void tearDown() { System.out.println("##################################################"); transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override/* w w w .j a v a 2s . c o m*/ protected void doInTransactionWithoutResult(TransactionStatus ts) { Session session = getCurrentSession(); session.createQuery("delete from Book").executeUpdate(); session.createQuery("delete from BookFetchModeSelect").executeUpdate(); session.createQuery("delete from BookFetchModeSubselect").executeUpdate(); session.createQuery("delete from BookFetchModeJoin").executeUpdate(); session.createQuery("delete from BookBatchSize").executeUpdate(); session.createQuery("delete from Author").executeUpdate(); session.createQuery("delete from Category").executeUpdate(); } }); }
From source file:eu.databata.engine.util.DBHistoryLogger.java
public void logCached(final String moduleName) { if (simulationMode) { return;/*from ww w. j a v a 2 s . c om*/ } transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { HistoryLogEntry e; while ((e = queue.poll()) != null) { propagationDAO.insertHistoryLog(moduleName, e); } } }); isCaching = false; }
From source file:com.bitsofproof.supernode.core.GetDataHandler.java
@Override public void process(final GetDataMessage m, final BitcoinPeer peer) { log.trace("received getdata for " + m.getBlocks().size() + " blocks " + m.getTransactions().size() + " transactions from " + peer.getAddress()); boolean found = false; for (byte[] h : m.getTransactions()) { Tx t = txHandler.getTransaction(new Hash(h).toString()); if (t != null) { found = true;/*from ww w . j av a 2s.com*/ TxMessage tm = (TxMessage) peer.createMessage("tx"); tm.setTx(t); peer.send(tm); log.trace("sent transaction " + t.getHash() + " to " + peer.getAddress()); } } if (!found) { peer.send(peer.createMessage("notfound")); } if (m.getBlocks().size() > 0) { new TransactionTemplate(transactionManager).execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { status.setRollbackOnly(); for (final byte[] h : m.getBlocks()) { Blk b; try { b = store.getBlock(new Hash(h).toString()); if (b != null) { final BlockMessage bm = (BlockMessage) peer.createMessage("block"); bm.setBlock(b); peer.send(bm); log.trace("sent block " + b.getHash() + " to " + peer.getAddress()); } } catch (ValidationException e) { } } if (m.getBlocks().size() > 1) { log.debug("sent " + m.getBlocks().size() + " blocks to " + peer.getAddress()); } else { peer.send(peer.createMessage("notfound")); } InvMessage inv = (InvMessage) peer.createMessage("inv"); inv.getBlockHashes().add(new Hash(store.getHeadHash()).toByteArray()); peer.send(inv); } }); } if (m.getFilteredBlocks().size() > 0 && peer.getFilter() != null) { new TransactionTemplate(transactionManager).execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { status.setRollbackOnly(); for (final byte[] h : m.getBlocks()) { Blk b; try { b = store.getBlock(new Hash(h).toString()); if (b != null) { final MerkleBlockMessage bm = (MerkleBlockMessage) peer .createMessage("merkleblock"); bm.setBlock(b); bm.filter(peer.getFilter()); peer.send(bm); log.trace("sent block " + b.getHash() + " to " + peer.getAddress()); } } catch (ValidationException e) { } } if (m.getBlocks().size() > 1) { log.debug("sent " + m.getBlocks().size() + " merkleblocks to " + peer.getAddress()); } else { peer.send(peer.createMessage("notfound")); } InvMessage inv = (InvMessage) peer.createMessage("inv"); inv.getBlockHashes().add(new Hash(store.getHeadHash()).toByteArray()); peer.send(inv); } }); } }
From source file:org.cleverbus.core.common.asynch.confirm.ConfirmationPollExecutorTest.java
@Test public void testGetNextMessage_moreThreads() throws InterruptedException { // firstly commit messages to DB (we can commit because we have embedded DB for tests only) TransactionTemplate txTemplate = new TransactionTemplate(jpaTransactionManager); txTemplate.execute(new TransactionCallbackWithoutResult() { @Override/*from w w w .j a v a2s. co m*/ protected void doInTransactionWithoutResult(TransactionStatus status) { Message msg = insertNewMessage("1234_4567"); confirmationService.insertFailedConfirmation(msg); msg = insertNewMessage("1234_4567_8"); confirmationService.insertFailedConfirmation(msg); msg = insertNewMessage("1234_4567_9"); confirmationService.insertFailedConfirmation(msg); } }); // prepare threads int threads = 5; final CountDownLatch latch = new CountDownLatch(threads); Runnable task = new Runnable() { @Override public void run() { try { pollExecutor.run(); } finally { latch.countDown(); } } }; mock.expectedMessageCount(3); // start processing and waits for result for (int i = 0; i < threads; i++) { new Thread(task).start(); } latch.await(); mock.assertIsSatisfied(); // verify messages ExternalCall extCall1 = findConfirmation("1234_4567"); assertThat(extCall1, notNullValue()); assertThat(extCall1.getState(), is(ExternalCallStateEnum.PROCESSING)); ExternalCall extCall2 = findConfirmation("1234_4567_8"); assertThat(extCall2, notNullValue()); assertThat(extCall2.getState(), is(ExternalCallStateEnum.PROCESSING)); ExternalCall extCall3 = findConfirmation("1234_4567_9"); assertThat(extCall3, notNullValue()); assertThat(extCall3.getState(), is(ExternalCallStateEnum.PROCESSING)); // check confirmationService confirmationService.confirmationFailed(extCall1); extCall1 = findConfirmation("1234_4567"); assertThat(extCall1.getState(), is(ExternalCallStateEnum.FAILED)); confirmationService.confirmationComplete(extCall2); extCall2 = findConfirmation("1234_4567_8"); assertThat(extCall2.getState(), is(ExternalCallStateEnum.OK)); }
From source file:org.pentaho.custom.authentication.provider.userroledao.hibernate.UserRoleDaoTransactionDecorator.java
public void createUser(final IUser userToCreate) throws AlreadyExistsException, UncategorizedUserRoleDaoException { transactionTemplate.execute(new TransactionCallbackWithoutResult() { protected void doInTransactionWithoutResult(TransactionStatus status) { userRoleDao.createUser(userToCreate); }/* www . j a v a 2s . co m*/ }); }
From source file:com.thoughtworks.go.server.dao.UserSqlMapDao.java
public void saveOrUpdate(final User user) { assertUserNotAnonymous(user);/* w ww. j av a 2 s . c o m*/ transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() { @Override public void afterCommit() { clearEnabledUserCountFromCache(); } }); sessionFactory.getCurrentSession().saveOrUpdate(copyLoginToDisplayNameIfNotPresent(user)); } }); }
From source file:org.cleverbus.core.common.asynch.repair.RepairExternalCallDbImpl.java
private void updateExternalCallsInDB(final List<ExternalCall> externalCalls) { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override//from w w w .j av a2 s. co m protected void doInTransactionWithoutResult(TransactionStatus status) { for (ExternalCall extCall : externalCalls) { Log.warn("The extCall {} is in {} state and is being changed to {}.", extCall.toHumanString(), extCall.getState(), ExternalCallStateEnum.FAILED); extCall.setState(ExternalCallStateEnum.FAILED); externalCallDao.update(extCall); } } }); }
From source file:ca.uhn.fhir.jpa.search.StaleSearchDeletingSvcImpl.java
protected void deleteSearch(final Search next) { TransactionTemplate tt = new TransactionTemplate(myTransactionManager); tt.execute(new TransactionCallbackWithoutResult() { @Override//ww w . j av a 2 s . c o m protected void doInTransactionWithoutResult(TransactionStatus theArg0) { Search searchToDelete = mySearchDao.findOne(next.getId()); ourLog.info("Expiring stale search {} / {}", searchToDelete.getId(), searchToDelete.getUuid()); mySearchIncludeDao.deleteForSearch(searchToDelete.getId()); mySearchResultDao.deleteForSearch(searchToDelete.getId()); mySearchDao.delete(searchToDelete); } }); }
From source file:net.cpollet.jixture.tests.integration.ITestDatabaseTestSupport.java
@Test public void noCommitDatabaseTestSupportDoesNotCommit() { noCommitDatabaseTestSupport.addFixtures(new MappingFixture(createUser())); noCommitDatabaseTestSupport.loadFixtures(); assertDatabaseContainsUser();//ww w. j a va 2 s . co m executeInNewTransaction(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { assertDatabaseDoesNotContainUser(); } }); }