当前位置: 首页>>代码示例>>Java>>正文


Java TransactionStatus类代码示例

本文整理汇总了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;
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-5.0,代码行数:25,代码来源:BookServiceImpl.java

示例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;
	    }
		
	}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:27,代码来源:MicroServiceTemplateSupport.java

示例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;
	    }
		
	}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:24,代码来源:MicroServiceTemplateSupport.java

示例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();
    }
}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:29,代码来源:StartCompensationHandler.java

示例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;
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:20,代码来源:AbstractReadWriteController.java

示例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);
        }
    });
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:9,代码来源:JpaTicketRegistryTests.java

示例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);
            }
        }
    });
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:18,代码来源:JpaLockingStrategyTests.java

示例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));
    }
}
 
开发者ID:uweschaefer,项目名称:factcast,代码行数:23,代码来源:PGSynchronizedQuery.java

示例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);
               }
           }
       });
   }
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:20,代码来源:JpaLockingStrategyTests.java

示例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;
}
 
开发者ID:alibaba,项目名称:bulbasaur,代码行数:19,代码来源:PersistHelper.java

示例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);
}
 
开发者ID:bendem,项目名称:sql-streams-spring,代码行数:23,代码来源:SqlStreamTransactionAwareProxy.java

示例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);
}
 
开发者ID:bendem,项目名称:sql-streams-spring,代码行数:17,代码来源:SqlStreamsTransactionManager.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:41,代码来源:AbstractPlatformTransactionManager.java

示例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);
            }
        }
    });

}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:22,代码来源:ChannelServiceImpl.java

示例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);
            }
        }
    });
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:28,代码来源:PipelineServiceImpl.java


注:本文中的org.springframework.transaction.TransactionStatus类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。