use of org.springframework.transaction.support.TransactionCallback in project spring-framework by spring-projects.
the class WebSphereUowTransactionManagerTests method uowManagerAndUserTransactionFoundInJndi.
@Test
public void uowManagerAndUserTransactionFoundInJndi() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
MockUOWManager manager = new MockUOWManager();
ExpectedLookupTemplate jndiTemplate = new ExpectedLookupTemplate();
jndiTemplate.addObject(WebSphereUowTransactionManager.DEFAULT_USER_TRANSACTION_NAME, ut);
jndiTemplate.addObject(WebSphereUowTransactionManager.DEFAULT_UOW_MANAGER_NAME, manager);
WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager();
ptm.setJndiTemplate(jndiTemplate);
ptm.afterPropertiesSet();
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
TransactionStatus ts = ptm.getTransaction(definition);
ptm.commit(ts);
assertEquals("result", ptm.execute(definition, new TransactionCallback<String>() {
@Override
public String doInTransaction(TransactionStatus status) {
return "result";
}
}));
assertEquals(UOWManager.UOW_TYPE_GLOBAL_TRANSACTION, manager.getUOWType());
assertFalse(manager.getJoined());
assertFalse(manager.getRollbackOnly());
verify(ut).begin();
verify(ut).commit();
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method saveMaterialRevisions.
private Material saveMaterialRevisions(final MaterialRevisions revs) {
Material hg = revs.getMaterialRevision(0).getMaterial();
transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
for (MaterialRevision revision : revs) {
repo.saveMaterialRevision(revision);
}
return null;
}
});
return hg;
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method savePipelineAndCreate_DMRs.
private DependencyMaterial savePipelineAndCreate_DMRs(Date d, MaterialRevisions hgMaterialRevisions, PipelineConfig config, int... dmrStageCounters) {
Pipeline pipeline = savePipeline(instanceFactory.createPipelineInstance(config, BuildCause.createWithModifications(hgMaterialRevisions, "Loser"), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider()));
CaseInsensitiveString stageName = config.get(0).name();
DependencyMaterial material = new DependencyMaterial(config.name(), stageName);
String label = pipeline.getLabel();
ArrayList<Modification> mods = new ArrayList<>();
for (int i = 0; i < dmrStageCounters.length; i++) {
int dmrStageCounter = dmrStageCounters[i];
StageIdentifier stageIdentifier = new StageIdentifier(pipeline.getIdentifier(), CaseInsensitiveString.str(stageName), String.valueOf(dmrStageCounter));
mods.add(new Modification(d, stageIdentifier.getStageLocator(), label, pipeline.getId()));
}
final MaterialRevision materialRevision = new MaterialRevision(material, mods);
transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
repo.saveMaterialRevision(materialRevision);
return null;
}
});
return material;
}
use of org.springframework.transaction.support.TransactionCallback in project ranger by apache.
the class RangerTransactionService method executeAfterTransactionComplete.
public void executeAfterTransactionComplete(final Runnable task) {
try {
scheduler.schedule(new Runnable() {
@Override
public void run() {
if (task != null) {
try {
// Create new transaction
TransactionTemplate txTemplate = new TransactionTemplate(txManager);
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
txTemplate.execute(new TransactionCallback<Object>() {
public Object doInTransaction(TransactionStatus status) {
task.run();
return null;
}
});
} catch (Exception e) {
LOG.error("Failed to commit TransactionService transaction", e);
LOG.error("Ignoring...");
}
}
}
}, 1000L, MILLISECONDS);
} catch (Exception e) {
LOG.error("Failed to schedule TransactionService transaction:", e);
LOG.error("Ignroing...");
}
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class UserSqlMapDao method deleteUsers.
@Override
public boolean deleteUsers(List<String> userNames) {
return (Boolean) transactionTemplate.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
String queryString = "delete from User where name in (:userNames)";
Query query = sessionFactory.getCurrentSession().createQuery(queryString);
query.setParameterList("userNames", userNames);
query.executeUpdate();
return Boolean.TRUE;
}
});
}
Aggregations