當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。