本文整理汇总了Java中org.springframework.transaction.support.TransactionCallbackWithoutResult类的典型用法代码示例。如果您正苦于以下问题:Java TransactionCallbackWithoutResult类的具体用法?Java TransactionCallbackWithoutResult怎么用?Java TransactionCallbackWithoutResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TransactionCallbackWithoutResult类属于org.springframework.transaction.support包,在下文中一共展示了TransactionCallbackWithoutResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: remove
import org.springframework.transaction.support.TransactionCallbackWithoutResult; //导入依赖的package包/类
/**
* 删除Channel
*/
public void remove(final Long channelId) {
Assert.assertNotNull(channelId);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
arbitrateManageService.channelEvent().destory(channelId);
channelDao.delete(channelId);
} catch (Exception e) {
logger.error("ERROR ## remove channel has an exception ", e);
throw new ManagerException(e);
}
}
});
}
示例2: remove
import org.springframework.transaction.support.TransactionCallbackWithoutResult; //导入依赖的package包/类
/**
* 删除
*/
public void remove(final Long pipelineId) {
Assert.assertNotNull(pipelineId);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
PipelineDO pipelineDO = pipelineDao.findById(pipelineId);
if (pipelineDO != null) {
pipelineDao.delete(pipelineId);
pipelineNodeRelationDao.deleteByPipelineId(pipelineId);
// 删除历史cursor
String destination = pipelineDO.getParameters().getDestinationName();
short clientId = pipelineDO.getId().shortValue();
arbitrateViewService.removeCanal(destination, clientId);
arbitrateManageService.pipelineEvent().destory(pipelineDO.getChannelId(), pipelineId);
}
} catch (Exception e) {
logger.error("ERROR ## remove the pipeline(" + pipelineId + ") has an exception!");
throw new ManagerException(e);
}
}
});
}
示例3: create
import org.springframework.transaction.support.TransactionCallbackWithoutResult; //导入依赖的package包/类
/**
* 添加
*/
public void create(final DataMatrix matrix) {
Assert.assertNotNull(matrix);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
DataMatrixDO matrixlDO = modelToDo(matrix);
matrixlDO.setId(0L);
matrixlDO.setGroupKey(matrixlDO.getGroupKey()+TimeUtil.getTime0());
if (!dataMatrixDao.checkUnique(matrixlDO)) {
String exceptionCause = "exist the same repeat canal in the database.";
logger.warn("WARN ## " + exceptionCause);
throw new RepeatConfigureException(exceptionCause);
}
dataMatrixDao.insert(matrixlDO);
} catch (RepeatConfigureException rce) {
throw rce;
} catch (Exception e) {
logger.error("ERROR ## create canal has an exception!");
throw new ManagerException(e);
}
}
});
}
示例4: remove
import org.springframework.transaction.support.TransactionCallbackWithoutResult; //导入依赖的package包/类
/**
* 删除
*/
public void remove(final Long matrixId) {
Assert.assertNotNull(matrixId);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
dataMatrixDao.delete(matrixId);
} catch (Exception e) {
logger.error("ERROR ## remove canal(" + matrixId + ") has an exception!");
throw new ManagerException(e);
}
}
});
}
示例5: modify
import org.springframework.transaction.support.TransactionCallbackWithoutResult; //导入依赖的package包/类
/**
* 修改
*/
public void modify(final DataMatrix matrix) {
Assert.assertNotNull(matrix);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
DataMatrixDO matrixDo = modelToDo(matrix);
if (dataMatrixDao.checkUnique(matrixDo)) {
dataMatrixDao.update(matrixDo);
} else {
String exceptionCause = "exist the same repeat matrix in the database.";
logger.warn("WARN ## " + exceptionCause);
throw new RepeatConfigureException(exceptionCause);
}
} catch (RepeatConfigureException rce) {
throw rce;
} catch (Exception e) {
logger.error("ERROR ## modify canal(" + matrix.getId() + ") has an exception!");
throw new ManagerException(e);
}
}
});
}
示例6: remove
import org.springframework.transaction.support.TransactionCallbackWithoutResult; //导入依赖的package包/类
/**
* 删除
*/
public void remove(final Long canalId) {
Assert.assertNotNull(canalId);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
Canal canal = findById(canalId);
canalDao.delete(canalId);
arbitrateViewService.removeCanal(canal.getName()); // 删除canal节点信息
} catch (Exception e) {
logger.error("ERROR ## remove canal(" + canalId + ") has an exception!");
throw new ManagerException(e);
}
}
});
}
示例7: modify
import org.springframework.transaction.support.TransactionCallbackWithoutResult; //导入依赖的package包/类
/**
* 修改
*/
public void modify(final Canal canal) {
Assert.assertNotNull(canal);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
CanalDO canalDo = modelToDo(canal);
if (canalDao.checkUnique(canalDo)) {
canalDao.update(canalDo);
} else {
String exceptionCause = "exist the same repeat canal in the database.";
logger.warn("WARN ## " + exceptionCause);
throw new RepeatConfigureException(exceptionCause);
}
} catch (RepeatConfigureException rce) {
throw rce;
} catch (Exception e) {
logger.error("ERROR ## modify canal(" + canal.getId() + ") has an exception!");
throw new ManagerException(e);
}
}
});
}
示例8: create
import org.springframework.transaction.support.TransactionCallbackWithoutResult; //导入依赖的package包/类
/**
* 添加
*/
public void create(final Node node) {
Assert.assertNotNull(node);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
NodeDO nodeDo = modelToDo(node);
nodeDo.setId(0L);
if (!nodeDao.checkUnique(nodeDo)) {
String exceptionCause = "exist the same repeat node in the database.";
logger.warn("WARN ## " + exceptionCause);
throw new RepeatConfigureException(exceptionCause);
}
nodeDao.insert(nodeDo);
} catch (RepeatConfigureException rce) {
throw rce;
} catch (Exception e) {
logger.error("ERROR ## create node has an exception!");
throw new ManagerException(e);
}
}
});
}
示例9: remove
import org.springframework.transaction.support.TransactionCallbackWithoutResult; //导入依赖的package包/类
/**
* 删除
*/
public void remove(final Long nodeId) {
Assert.assertNotNull(nodeId);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
nodeDao.delete(nodeId);
} catch (Exception e) {
logger.error("ERROR ## remove node(" + nodeId + ") has an exception!");
throw new ManagerException(e);
}
}
});
}
示例10: modify
import org.springframework.transaction.support.TransactionCallbackWithoutResult; //导入依赖的package包/类
/**
* 修改
*/
public void modify(final Node node) {
Assert.assertNotNull(node);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
NodeDO nodeDo = modelToDo(node);
if (nodeDao.checkUnique(nodeDo)) {
nodeDao.update(nodeDo);
} else {
String exceptionCause = "exist the same repeat node in the database.";
logger.warn("WARN ## " + exceptionCause);
throw new RepeatConfigureException(exceptionCause);
}
} catch (RepeatConfigureException rce) {
throw rce;
} catch (Exception e) {
logger.error("ERROR ## modify node(" + node.getId() + ") has an exception!");
throw new ManagerException(e);
}
}
});
}
示例11: testInvalidIsolation
import org.springframework.transaction.support.TransactionCallbackWithoutResult; //导入依赖的package包/类
@Test
public void testInvalidIsolation() {
tt.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
given(manager.isOpen()).willReturn(true);
try {
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
}
});
fail("Should have thrown InvalidIsolationLevelException");
}
catch (InvalidIsolationLevelException ex) {
// expected
}
verify(manager).close();
}
示例12: testTransactionFlush
import org.springframework.transaction.support.TransactionCallbackWithoutResult; //导入依赖的package包/类
@Test
public void testTransactionFlush() {
given(manager.getTransaction()).willReturn(tx);
assertTrue(!TransactionSynchronizationManager.hasResource(factory));
assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
tt.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
assertTrue(TransactionSynchronizationManager.hasResource(factory));
status.flush();
}
});
assertTrue(!TransactionSynchronizationManager.hasResource(factory));
assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
verify(tx).commit();
verify(manager).flush();
verify(manager).close();
}
示例13: testIsolationLevel
import org.springframework.transaction.support.TransactionCallbackWithoutResult; //导入依赖的package包/类
@Test
public void testIsolationLevel() {
given(pmf.getPersistenceManager()).willReturn(pm);
given(pm.currentTransaction()).willReturn(tx);
PlatformTransactionManager tm = new JdoTransactionManager(pmf);
TransactionTemplate tt = new TransactionTemplate(tm);
tt.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
}
});
verify(tx).setIsolationLevel(Constants.TX_SERIALIZABLE);
verify(pm).close();
}
示例14: testTransactionFlush
import org.springframework.transaction.support.TransactionCallbackWithoutResult; //导入依赖的package包/类
@Test
public void testTransactionFlush() {
given(pmf.getPersistenceManager()).willReturn(pm);
given(pm.currentTransaction()).willReturn(tx);
PlatformTransactionManager tm = new JdoTransactionManager(pmf);
TransactionTemplate tt = new TransactionTemplate(tm);
assertTrue("Hasn't thread pm", !TransactionSynchronizationManager.hasResource(pmf));
assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
tt.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
assertTrue("Has thread pm", TransactionSynchronizationManager.hasResource(pmf));
status.flush();
}
});
assertTrue("Hasn't thread pm", !TransactionSynchronizationManager.hasResource(pmf));
assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
verify(pm).flush();
verify(pm).close();
verify(tx).begin();
verify(tx).commit();
}
示例15: transactionTemplateWithException
import org.springframework.transaction.support.TransactionCallbackWithoutResult; //导入依赖的package包/类
@Test
public void transactionTemplateWithException() {
TestTransactionManager tm = new TestTransactionManager(false, true);
TransactionTemplate template = new TransactionTemplate(tm);
final RuntimeException ex = new RuntimeException("Some application exception");
try {
template.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
throw ex;
}
});
fail("Should have propagated RuntimeException");
}
catch (RuntimeException caught) {
// expected
assertTrue("Correct exception", caught == ex);
assertTrue("triggered begin", tm.begin);
assertTrue("no commit", !tm.commit);
assertTrue("triggered rollback", tm.rollback);
assertTrue("no rollbackOnly", !tm.rollbackOnly);
}
}