List of usage examples for org.springframework.transaction.support TransactionCallbackWithoutResult TransactionCallbackWithoutResult
TransactionCallbackWithoutResult
From source file:org.jspresso.hrsample.backend.BackTestStartup.java
/** * Destroys all data from DB./*w w w . j av a2 s .co m*/ * * @throws Exception * the exception */ @AfterClass public static void tearDownAfterClass() throws Exception { BackTestStartup startup = new BackTestStartup(); startup.start(); final HibernateBackendController bc = (HibernateBackendController) startup.getBackendController(); bc.getTransactionTemplate().execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { deleteAllInstances(bc, Company.class); deleteAllInstances(bc, City.class); deleteAllInstances(bc, Role.class); } }); }
From source file:org.springextensions.neodatis.NeoDatisTransactionManagerTest.java
@Test public void testTransactionCommit() throws Exception { final ODB odb = Mockito.mock(ODB.class); PlatformTransactionManager tm = new NeoDatisTransactionManager(odb); TransactionTemplate tmpl = new TransactionTemplate(tm); Assert.assertFalse("Should not have a resource", TransactionSynchronizationManager.hasResource(odb)); Assert.assertFalse("There should no active synchronizations", TransactionSynchronizationManager.isSynchronizationActive()); tmpl.execute(new TransactionCallbackWithoutResult() { @Override/*from w w w .j a va 2s. c om*/ protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) { Assert.assertTrue(TransactionSynchronizationManager.hasResource(odb)); NeoDatisTemplate neoDatisTemplate = new NeoDatisTemplate(odb); neoDatisTemplate.store(null); } }); Assert.assertFalse("Should not have a resource", TransactionSynchronizationManager.hasResource(odb)); Assert.assertFalse("There should no active synchronizations", TransactionSynchronizationManager.isSynchronizationActive()); Mockito.verify(odb, Mockito.times(1)).commit(); }
From source file:org.jamwiki.db.DatabaseUpgrades.java
/** * Perform the required database upgrade steps when upgrading from versions * older than JAMWiki 1.3./*from w ww . ja va2 s .c om*/ */ public static void upgrade130(final List<WikiMessage> messages) throws WikiException { try { DatabaseConnection.getTransactionTemplate().execute(new TransactionCallbackWithoutResult() { protected void doInTransactionWithoutResult(TransactionStatus status) { try { // New tables as of JAMWiki 1.3 DatabaseUpgrades.executeUpgradeUpdate("STATEMENT_CREATE_USER_PREFERENCES_DEFAULTS_TABLE"); messages.add( new WikiMessage("upgrade.message.db.table.added", "jam_user_preferences_defaults")); DatabaseUpgrades.executeUpgradeUpdate("STATEMENT_CREATE_USER_PREFERENCES_TABLE"); messages.add(new WikiMessage("upgrade.message.db.table.added", "jam_user_preferences")); WikiDatabase.setupUserPreferencesDefaults(); // Create default values for user preferences. messages.add(new WikiMessage("upgrade.message.db.data.updated", "jam_user_preferences_defaults")); // Migrate existing user preferences to new tables DatabaseUpgrades .executeUpgradeUpdate("UPGRADE_130_MIGRATE_USER_PREFERENCES_DEFAULT_LOCALE"); DatabaseUpgrades.executeUpgradeUpdate("UPGRADE_130_MIGRATE_USER_PREFERENCES_EDITOR"); DatabaseUpgrades.executeUpgradeUpdate("UPGRADE_130_MIGRATE_USER_PREFERENCES_SIGNATURE"); messages.add(new WikiMessage("upgrade.message.db.data.updated", "jam_user_preferences")); // Drop old user preference columns from jam_wiki_user DatabaseUpgrades .executeUpgradeUpdate("UPGRADE_130_REMOVE_WIKI_USER_TABLE_COLUMN_DEFAULT_LOCALE"); messages.add(new WikiMessage("upgrade.message.db.data.updated", "jam_wiki_user")); DatabaseUpgrades.executeUpgradeUpdate("UPGRADE_130_REMOVE_WIKI_USER_TABLE_COLUMN_EDITOR"); messages.add(new WikiMessage("upgrade.message.db.data.updated", "jam_wiki_user")); DatabaseUpgrades .executeUpgradeUpdate("UPGRADE_130_REMOVE_WIKI_USER_TABLE_COLUMN_SIGNATURE"); messages.add(new WikiMessage("upgrade.message.db.data.updated", "jam_wiki_user")); DatabaseUpgrades.executeUpgradeUpdate("UPGRADE_130_ADD_USER_TABLE_COLUMN_CHALLENGE_VALUE"); messages.add(new WikiMessage("upgrade.message.db.data.updated", "jam_users")); DatabaseUpgrades.executeUpgradeUpdate("UPGRADE_130_ADD_USER_TABLE_COLUMN_CHALLENGE_DATE"); messages.add(new WikiMessage("upgrade.message.db.data.updated", "jam_users")); DatabaseUpgrades.executeUpgradeUpdate("UPGRADE_130_ADD_USER_TABLE_COLUMN_CHALLENGE_IP"); messages.add(new WikiMessage("upgrade.message.db.data.updated", "jam_users")); DatabaseUpgrades.executeUpgradeUpdate("UPGRADE_130_ADD_USER_TABLE_COLUMN_CHALLENGE_TRIES"); messages.add(new WikiMessage("upgrade.message.db.data.updated", "jam_users")); } catch (WikiException e) { status.setRollbackOnly(); throw new TransactionRuntimeException(e); } } }); } catch (TransactionRuntimeException e) { throw new WikiException(new WikiMessage("upgrade.error.fatal", e.getMessage())); } }
From source file:ch.tatool.app.service.impl.DataServiceImpl.java
/** * Save the module instance./* www. j a va 2 s . c o m*/ * This will save all changed module properties */ public void saveModule(Module module) { final ModuleImpl moduleImpl = (ModuleImpl) module; // load the module data moduleImpl.getTransactionTemplate().execute(new TransactionCallbackWithoutResult() { public void doInTransactionWithoutResult(TransactionStatus status) { ModuleDAO moduleDAO = moduleImpl.getModuleDAO(); moduleDAO.saveModule(moduleImpl); } }); }
From source file:com.github.akiraly.db4j.uow.FooService.java
public void assertBar(long id, String expectedBar) { tx(new TransactionCallbackWithoutResult() { @Override/*from w w w . j a v a 2 s . c om*/ protected void doInTransactionWithoutResult(TransactionStatus status) { EntityWithLongId<Foo> entity = fooDao.lazyFind(id); assertEquals(expectedBar, entity.getEntity().getBar()); assertEquals(now, entity.getEntity().getDt()); assertEquals(now.toLocalDate(), entity.getEntity().getLocalDate()); } }); }
From source file:org.springextensions.db4o.Db4oTransactionManagerTest.java
@Test public void testTransactionCommit() throws Exception { final ExtObjectContainer container = mock(ExtObjectContainer.class); when(container.identity()).thenReturn(null); PlatformTransactionManager tm = new Db4oTransactionManager(container); TransactionTemplate tt = new TransactionTemplate(tm); Assert.assertTrue(!TransactionSynchronizationManager.hasResource(container), "Has no container"); Assert.assertTrue(!TransactionSynchronizationManager.isSynchronizationActive(), "JTA synchronizations not active"); tt.execute(new TransactionCallbackWithoutResult() { protected void doInTransactionWithoutResult(TransactionStatus status) { Assert.assertTrue(TransactionSynchronizationManager.hasResource(container), "Has thread session"); Db4oTemplate template = new Db4oTemplate(container); template.identity();/*from www .ja v a 2 s . c o m*/ } }); Assert.assertTrue(!TransactionSynchronizationManager.hasResource(container), "Has no container"); Assert.assertTrue(!TransactionSynchronizationManager.isSynchronizationActive(), "JTA synchronizations not active"); verify(container).commit(); }
From source file:org.web4thejob.security.UserDetailsExImpl.java
private void loadAuthorities() { if (userIdentity.isNewInstance()) { return;/* www . j a v a 2 s . com*/ } ContextUtil.getTransactionWrapper().execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { Query query = ContextUtil.getEntityFactory().buildQuery(RoleMembers.class); query.addCriterion(new Path(RoleMembers.FLD_USER), Condition.EQ, userIdentity); for (Entity roleMembers : ContextUtil.getDRS().findByQuery(query)) { RoleIdentity roleIdentity = ContextUtil.getMRS() .deproxyEntity(((RoleMembers) roleMembers).getRole()); authorities.add(new GrantedAuthorityImpl(roleIdentity)); } } }); }
From source file:es.upm.fiware.rss.dao.loader.BmCurrencyLoader.java
@PostConstruct public void init() { TransactionTemplate tmpl = new TransactionTemplate(txManager); tmpl.execute(new TransactionCallbackWithoutResult() { @Override/*from w w w . ja va2 s . co m*/ protected void doInTransactionWithoutResult(TransactionStatus ts) { // Check if currencies has been loaded List<BmCurrency> currs = currencyDao.getAll(); if (currs == null || currs.isEmpty()) { saveCurrency("EUR", "Euro", "", "978", 2); saveCurrency("GBP", "Esterlina", "", "826", 2); saveCurrency("BRL", "Verdadero brasileno", "R$", "986", 2); saveCurrency("ARS", "Peso argentino", "$a", "032", 2); saveCurrency("MXN", "Peso mexicano", "$", "484", 2); saveCurrency("CLP", "Peso chileno", "$", "152", 2); saveCurrency("PEN", "Nuevo sol", "S/.", "604", 2); saveCurrency("VEF", "Bolivar fuerte", "Bs.", "937", 2); saveCurrency("COP", "Peso colombiano", "$", "170", 2); saveCurrency("USD", "US Dolar", "$", "840", 2); saveCurrency("NIO", "Cordoba oro", "C$", "558", 2); saveCurrency("GTQ", "Quetzal", "Q", "320", 2); saveCurrency("SVC", "El Salvador Colon", "", "222", 2); saveCurrency("PAB", "Balboa", "B/.", "590", 2); saveCurrency("UYU", "Peso Uruguayo", "$", "858", 2); saveCurrency("MYR", "Malaysian ringgit", "RM", "458", 2); saveCurrency("NOK", "Norwegian krone", "kr", "578", 2); saveCurrency("HUF", "Hungarian forint", "Ft", "348", 2); } } }); }
From source file:pl.touk.top.dictionary.webapp.util.PrepareStartupData.java
public void initialize() { if (!initialized) { initialized = true;/*from ww w. ja v a 2s .c o m*/ log.info("PREPARE STARTUP DATA PROCESS WORKS IN DEMO MODE, INSERTING ROWS"); hibernateTransactionTemplate.execute(new TransactionCallbackWithoutResult() { protected void doInTransactionWithoutResult(TransactionStatus status) { DictionaryFixtureUtils.prepareCasesFixture(dictionaryDao); } }); } }
From source file:nl.ordina.bag.etl.processor.MutatiesProcessor.java
public void execute() { TransactionCallback<?> processMutaties = new TransactionCallbackWithoutResult() { @Override/*from ww w.ja va 2s . c o m*/ protected void doInTransactionWithoutResult(TransactionStatus status) { while (true) { List<BAGMutatie> mutaties = bagMutatiesDAO.getNextBAGMutaties(); if (mutaties.size() > 0) for (BAGMutatie mutatie : mutaties) { if (BAGObjectType.WOONPLAATS.equals(mutatie.getObjectType())) { MutatieProduct mutatieProduct = mutatie.getMutatieProduct(); if (mutatieProduct.getNieuw() != null) { Woonplaats woonplaats = bagObjectFactory .getWoonplaats(mutatieProduct.getNieuw().getWoonplaats()); logger.debug("Woonplaats " + woonplaats.getIdentificatie() + " inserting"); insert(woonplaats); mutationListener.onInsert(mutatie.getObjectType(), woonplaats); } else if (mutatieProduct.getOrigineel() != null && mutatieProduct.getWijziging() != null) { Woonplaats origineel = bagObjectFactory .getWoonplaats(mutatieProduct.getOrigineel().getWoonplaats()); Woonplaats wijziging = bagObjectFactory .getWoonplaats(mutatieProduct.getWijziging().getWoonplaats()); logger.debug("Woonplaats " + origineel.getIdentificatie() + " updating"); update(origineel, wijziging); mutationListener.onUpdate(mutatie.getObjectType(), origineel, wijziging); } else handleException(mutatieProduct); } else if (BAGObjectType.OPENBARE_RUIMTE.equals(mutatie.getObjectType())) { MutatieProduct mutatieProduct = mutatie.getMutatieProduct(); if (mutatieProduct.getNieuw() != null) { OpenbareRuimte openbareRuimte = bagObjectFactory .getOpenbareRuimte(mutatieProduct.getNieuw().getOpenbareRuimte()); logger.debug( "Openbare ruimte " + openbareRuimte.getIdentificatie() + " inserting"); insert(openbareRuimte); mutationListener.onInsert(mutatie.getObjectType(), openbareRuimte); } else if (mutatieProduct.getOrigineel() != null && mutatieProduct.getWijziging() != null) { OpenbareRuimte origineel = bagObjectFactory .getOpenbareRuimte(mutatieProduct.getOrigineel().getOpenbareRuimte()); OpenbareRuimte wijziging = bagObjectFactory .getOpenbareRuimte(mutatieProduct.getWijziging().getOpenbareRuimte()); logger.debug("Openbare ruimte " + origineel.getIdentificatie() + " updating"); update(origineel, wijziging); mutationListener.onUpdate(mutatie.getObjectType(), origineel, wijziging); } else handleException(mutatieProduct); } else if (BAGObjectType.NUMMERAANDUIDING.equals(mutatie.getObjectType())) { MutatieProduct mutatieProduct = mutatie.getMutatieProduct(); if (mutatieProduct.getNieuw() != null) { Nummeraanduiding nummeraanduiding = bagObjectFactory .getNummeraanduiding(mutatieProduct.getNieuw().getNummeraanduiding()); logger.debug("Nummeraanduiding " + nummeraanduiding.getIdentificatie() + " inserting"); insert(nummeraanduiding); mutationListener.onInsert(mutatie.getObjectType(), nummeraanduiding); } else if (mutatieProduct.getOrigineel() != null && mutatieProduct.getWijziging() != null) { Nummeraanduiding origineel = bagObjectFactory.getNummeraanduiding( mutatieProduct.getOrigineel().getNummeraanduiding()); Nummeraanduiding wijziging = bagObjectFactory.getNummeraanduiding( mutatieProduct.getWijziging().getNummeraanduiding()); logger.debug("Nummeraanduiding " + origineel.getIdentificatie() + " updating"); update(origineel, wijziging); mutationListener.onUpdate(mutatie.getObjectType(), origineel, wijziging); } else handleException(mutatieProduct); } else if (BAGObjectType.PAND.equals(mutatie.getObjectType())) { MutatieProduct mutatieProduct = mutatie.getMutatieProduct(); if (mutatieProduct.getNieuw() != null) { Pand pand = bagObjectFactory.getPand(mutatieProduct.getNieuw().getPand()); logger.debug("Pand " + pand.getIdentificatie() + " inserting"); insert(pand); mutationListener.onInsert(mutatie.getObjectType(), pand); } else if (mutatieProduct.getOrigineel() != null && mutatieProduct.getWijziging() != null) { Pand origineel = bagObjectFactory .getPand(mutatieProduct.getOrigineel().getPand()); Pand wijziging = bagObjectFactory .getPand(mutatieProduct.getWijziging().getPand()); logger.debug("Pand " + origineel.getIdentificatie() + " updating"); update(origineel, wijziging); mutationListener.onUpdate(mutatie.getObjectType(), origineel, wijziging); } else handleException(mutatieProduct); } else if (BAGObjectType.VERBLIJFSOBJECT.equals(mutatie.getObjectType())) { MutatieProduct mutatieProduct = mutatie.getMutatieProduct(); if (mutatieProduct.getNieuw() != null) { Verblijfsobject verblijfsobject = bagObjectFactory .getVerblijfsobject(mutatieProduct.getNieuw().getVerblijfsobject()); logger.debug( "Verblijfsobject " + verblijfsobject.getIdentificatie() + " inserting"); insert(verblijfsobject); mutationListener.onInsert(mutatie.getObjectType(), verblijfsobject); } else if (mutatieProduct.getOrigineel() != null && mutatieProduct.getWijziging() != null) { Verblijfsobject origineel = bagObjectFactory .getVerblijfsobject(mutatieProduct.getOrigineel().getVerblijfsobject()); Verblijfsobject wijziging = bagObjectFactory .getVerblijfsobject(mutatieProduct.getWijziging().getVerblijfsobject()); logger.debug("Verblijfsobject " + origineel.getIdentificatie() + " updating"); update(origineel, wijziging); mutationListener.onUpdate(mutatie.getObjectType(), origineel, wijziging); } else handleException(mutatieProduct); } else if (BAGObjectType.LIGPLAATS.equals(mutatie.getObjectType())) { MutatieProduct mutatieProduct = mutatie.getMutatieProduct(); if (mutatieProduct.getNieuw() != null) { Ligplaats ligplaats = bagObjectFactory .getLigplaats(mutatieProduct.getNieuw().getLigplaats()); logger.debug("Ligplaats " + ligplaats.getIdentificatie() + " inserting"); insert(ligplaats); mutationListener.onInsert(mutatie.getObjectType(), ligplaats); } else if (mutatieProduct.getOrigineel() != null && mutatieProduct.getWijziging() != null) { Ligplaats origineel = bagObjectFactory .getLigplaats(mutatieProduct.getOrigineel().getLigplaats()); Ligplaats wijziging = bagObjectFactory .getLigplaats(mutatieProduct.getWijziging().getLigplaats()); logger.debug("Ligplaats " + origineel.getIdentificatie() + " updating"); update(origineel, wijziging); mutationListener.onUpdate(mutatie.getObjectType(), origineel, wijziging); } else handleException(mutatieProduct); } else if (BAGObjectType.STANDPLAATS.equals(mutatie.getObjectType())) { MutatieProduct mutatieProduct = mutatie.getMutatieProduct(); if (mutatieProduct.getNieuw() != null) { Standplaats standplaats = bagObjectFactory .getStandplaats(mutatieProduct.getNieuw().getStandplaats()); logger.debug("Standplaats " + standplaats.getIdentificatie() + " inserting"); insert(standplaats); mutationListener.onInsert(mutatie.getObjectType(), standplaats); } else if (mutatieProduct.getOrigineel() != null && mutatieProduct.getWijziging() != null) { Standplaats origineel = bagObjectFactory .getStandplaats(mutatieProduct.getOrigineel().getStandplaats()); Standplaats wijziging = bagObjectFactory .getStandplaats(mutatieProduct.getWijziging().getStandplaats()); logger.debug("Standplaats " + origineel.getIdentificatie() + " updating"); update(origineel, wijziging); mutationListener.onUpdate(mutatie.getObjectType(), origineel, wijziging); } else handleException(mutatieProduct); } bagMutatiesDAO.delete(mutatie); } else break; } } }; bagMutatiesDAO.doInTransaction(processMutaties); }