本文整理汇总了Java中org.springframework.transaction.TransactionStatus类的典型用法代码示例。如果您正苦于以下问题:Java TransactionStatus类的具体用法?Java TransactionStatus怎么用?Java TransactionStatus使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TransactionStatus类属于org.springframework.transaction包,在下文中一共展示了TransactionStatus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteBook
import org.springframework.transaction.TransactionStatus; //导入依赖的package包/类
@Override
public boolean deleteBook(long ISBN) {
// TODO Auto-generated method stub
if (searchBook(ISBN).getISBN() == ISBN) {
transactionTemplate.setReadOnly(false);
return transactionTemplate.execute(new TransactionCallback<Boolean>() {
@Override
public Boolean doInTransaction(TransactionStatus status) {
// TODO Auto-generated method stub
try {
boolean result = bookDAO.deleteBook(ISBN);
return result;
} catch (Exception exception) {
status.setRollbackOnly();
}
return false;
}
});
}
return false;
}
示例2: execGroovyRetObjByDbTranNest
import org.springframework.transaction.TransactionStatus; //导入依赖的package包/类
public Object execGroovyRetObjByDbTranNest(String groovyName, String methodName, Integer nestDef,
Object... paramArray) throws Exception{
/* MicroMetaDao microDao=MicroMetaDao.getInstance(dbName,dbType);
DataSource dataSource=microDao.getMicroDataSource();
PlatformTransactionManager transactionManager=new DataSourceTransactionManager(dataSource);*/
PlatformTransactionManager transactionManager=MicroTranManagerHolder.getTransactionManager(dbName);
DefaultTransactionDefinition def =new DefaultTransactionDefinition();
def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);
if(nestDef==null){
nestDef=TransactionDefinition.PROPAGATION_REQUIRED;
}
def.setPropagationBehavior(nestDef);
TransactionStatus status=transactionManager.getTransaction(def);
try
{
Object retObj= GroovyExecUtil.execGroovyRetObj(groovyName, methodName, paramArray);
transactionManager.commit(status);
return retObj;
}
catch(Exception ex)
{
transactionManager.rollback(status);
throw ex;
}
}
示例3: execGroovyRetObjByDbTran
import org.springframework.transaction.TransactionStatus; //导入依赖的package包/类
public Object execGroovyRetObjByDbTran(String groovyName, String methodName,
Object... paramArray) throws Exception{
/* MicroMetaDao microDao=MicroMetaDao.getInstance(dbName,dbType);
DataSource dataSource=microDao.getMicroDataSource();
PlatformTransactionManager transactionManager=new DataSourceTransactionManager(dataSource);*/
PlatformTransactionManager transactionManager=MicroTranManagerHolder.getTransactionManager(dbName);
DefaultTransactionDefinition def =new DefaultTransactionDefinition();
def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
TransactionStatus status=transactionManager.getTransaction(def);
try
{
Object retObj= GroovyExecUtil.execGroovyRetObj(groovyName, methodName, paramArray);
transactionManager.commit(status);
return retObj;
}
catch(Exception ex)
{
transactionManager.rollback(status);
throw ex;
}
}
示例4: handler
import org.springframework.transaction.TransactionStatus; //导入依赖的package包/类
/**
* 补偿的时候,不走分布式事务处理
*
* @param point point 切点
* @param info 信息
* @return Object
* @throws Throwable
*/
@Override
public Object handler(ProceedingJoinPoint point, TxTransactionInfo info) throws Throwable {
TxTransactionLocal.getInstance().setTxGroupId(CommonConstant.COMPENSATE_ID);
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
TransactionStatus transactionStatus = platformTransactionManager.getTransaction(def);
try {
final Object proceed = point.proceed();
platformTransactionManager.commit(transactionStatus);
LogUtil.info(LOGGER, "补偿事务执行成功!事务组id为:{}", info::getTxGroupId);
return proceed;
} catch (Throwable e) {
LogUtil.info(LOGGER, "补偿事务执行失败!事务组id为:{}", info::getTxGroupId);
platformTransactionManager.rollback(transactionStatus);
throw e;
} finally {
TxTransactionLocal.getInstance().removeTxGroupId();
CompensationLocal.getInstance().removeCompensationId();
}
}
示例5: doInTransaction
import org.springframework.transaction.TransactionStatus; //导入依赖的package包/类
@Override
public SaveResult<T> doInTransaction(final TransactionStatus status) {
final SaveResult<T> result;
try {
wijzigObjectVoorOpslag(item);
if (historieVerwerkers.isEmpty()) {
result = new SaveResult<>(repository.save(item));
} else {
final T managedItem = repository.findOrPersist(item);
for (final HistorieVerwerker<T> historieVerwerker : historieVerwerkers) {
historieVerwerker.accept(item, managedItem);
}
result = new SaveResult<>(repository.save(managedItem));
}
} catch (final NotFoundException e) {
return new SaveResult<>(e);
}
return result;
}
示例6: getTicketInTransaction
import org.springframework.transaction.TransactionStatus; //导入依赖的package包/类
Ticket getTicketInTransaction(final String ticketId) {
return new TransactionTemplate(txManager).execute(new TransactionCallback<Ticket>() {
@Override
public Ticket doInTransaction(final TransactionStatus status) {
return jpaTicketRegistry.getTicket(ticketId);
}
});
}
示例7: invoke
import org.springframework.transaction.TransactionStatus; //导入依赖的package包/类
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
return new TransactionTemplate(txManager).execute(new TransactionCallback<Object>() {
@Override
public Object doInTransaction(final TransactionStatus status) {
try {
final Object result = method.invoke(jpaLock, args);
jpaLock.entityManager.flush();
logger.debug("Performed {} on {}", method.getName(), jpaLock);
return result;
// Force result of transaction to database
} catch (final Exception e) {
throw new RuntimeException("Transactional method invocation failed.", e);
}
}
});
}
示例8: run
import org.springframework.transaction.TransactionStatus; //导入依赖的package包/类
public synchronized void run(boolean useIndex) {
if (useIndex) {
jdbcTemplate.query(sql, setter, rowHandler);
} else {
long latest = latestFetcher.retrieveLatestSer();
transactionTemplate.execute(new TransactionCallback<Object>() {
@Override
public Object doInTransaction(TransactionStatus status) {
jdbcTemplate.execute("SET LOCAL enable_bitmapscan=0;");
jdbcTemplate.query(sql, setter, rowHandler);
return null;
}
});
// shift to max(retrievedLatestSer, and ser as updated in
// rowHandler)
serialToContinueFrom.set(Math.max(serialToContinueFrom.get(), latest));
}
}
示例9: invoke
import org.springframework.transaction.TransactionStatus; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
return new TransactionTemplate(txManager).execute(new TransactionCallback<Object>() {
public Object doInTransaction(final TransactionStatus status) {
try {
final Object result = method.invoke(jpaLock, args);
jpaLock.entityManager.flush();
logger.debug("Performed {} on {}", method.getName(), jpaLock);
return result;
// Force result of transaction to database
} catch (final Exception e) {
throw new RuntimeException("Transactional method invocation failed.", e);
}
}
});
}
示例10: tx
import org.springframework.transaction.TransactionStatus; //导入依赖的package包/类
public <T> T tx(TransactionRun<T> run) {
TransactionStatus txStatus = getTransactionStatus();
T result;
try {
result = run.run();
} catch (RuntimeException re) {
transactionManager.rollback(txStatus);
throw re;
} catch (Error err) {
transactionManager.rollback(txStatus);
throw err;
} catch (Exception e) {
transactionManager.rollback(txStatus);
throw new UndeclaredThrowableException(e, "undeclared error happened in transaction");
}
transactionManager.commit(txStatus);
return result;
}
示例11: invoke
import org.springframework.transaction.TransactionStatus; //导入依赖的package包/类
@Override
public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
Sql sql = this.sql;
if (method.getDeclaringClass() == SqlStreamHolder.class) {
return sql;
}
TransactionStatus transactionStatus = null;
try {
transactionStatus = TransactionAspectSupport.currentTransactionStatus();
} catch (NoTransactionException e) {
if (FAIL_WITHOUT_TRANSACTION) {
throw e;
}
}
if (transactionStatus instanceof SqlStreamTransactionStatus) {
sql = ((SqlStreamTransactionStatus) transactionStatus).transaction;
}
return method.invoke(sql, objects);
}
示例12: getTransaction
import org.springframework.transaction.TransactionStatus; //导入依赖的package包/类
@Override
public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException {
Transaction.IsolationLevel isolationLevel = translateIsolationLevel(definition.getIsolationLevel());
Transaction t;
if (isolationLevel == null) {
t = sql.transaction();
} else {
t = sql.transaction(isolationLevel);
}
if (definition.isReadOnly()) {
Wrap.execute(() -> t.getConnection().setReadOnly(true));
}
return new SqlStreamTransactionStatus(t);
}
示例13: commit
import org.springframework.transaction.TransactionStatus; //导入依赖的package包/类
/**
* This implementation of commit handles participating in existing
* transactions and programmatic rollback requests.
* Delegates to {@code isRollbackOnly}, {@code doCommit}
* and {@code rollback}.
* @see org.springframework.transaction.TransactionStatus#isRollbackOnly()
* @see #doCommit
* @see #rollback
*/
@Override
public final void commit(TransactionStatus status) throws TransactionException {
if (status.isCompleted()) {
throw new IllegalTransactionStateException(
"Transaction is already completed - do not call commit or rollback more than once per transaction");
}
DefaultTransactionStatus defStatus = (DefaultTransactionStatus) status;
if (defStatus.isLocalRollbackOnly()) {
if (defStatus.isDebug()) {
logger.debug("Transactional code has requested rollback");
}
processRollback(defStatus);
return;
}
if (!shouldCommitOnGlobalRollbackOnly() && defStatus.isGlobalRollbackOnly()) {
if (defStatus.isDebug()) {
logger.debug("Global transaction is marked as rollback-only but transactional code requested commit");
}
processRollback(defStatus);
// Throw UnexpectedRollbackException only at outermost transaction boundary
// or if explicitly asked to.
if (status.isNewTransaction() || isFailEarlyOnGlobalRollbackOnly()) {
throw new UnexpectedRollbackException(
"Transaction rolled back because it has been marked as rollback-only");
}
return;
}
processCommit(defStatus);
}
示例14: remove
import org.springframework.transaction.TransactionStatus; //导入依赖的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);
}
}
});
}
示例15: remove
import org.springframework.transaction.TransactionStatus; //导入依赖的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);
}
}
});
}