當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultTransactionDefinition.setIsolationLevel方法代碼示例

本文整理匯總了Java中org.springframework.transaction.support.DefaultTransactionDefinition.setIsolationLevel方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultTransactionDefinition.setIsolationLevel方法的具體用法?Java DefaultTransactionDefinition.setIsolationLevel怎麽用?Java DefaultTransactionDefinition.setIsolationLevel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.transaction.support.DefaultTransactionDefinition的用法示例。


在下文中一共展示了DefaultTransactionDefinition.setIsolationLevel方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execGroovyRetObjByDbTran

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的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

示例2: execGroovyRetObjByDbTranNest

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的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: testA

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
@Test
	@SuppressWarnings("deprecation")
	public void testA() throws InterruptedException {
		
		DefaultTransactionDefinition def = new DefaultTransactionDefinition();
		def.setIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ);
		TransactionStatus status = transactionManager.getTransaction(def);
		
		try {
			int num = jdbcTemplate.queryForInt("select num from test where id = 1");
//			Thread.sleep(10);
			
			System.out.println(jdbcTemplate.queryForInt("select count(*) from test"));
			
			jdbcTemplate.update("update test set num = " + (num + 1) + " where id = 1");
			transactionManager.commit(status);
		} catch (Exception e) {
			transactionManager.rollback(status);
			throw e;
		}
	}
 
開發者ID:Jakegogo,項目名稱:concurrent,代碼行數:22,代碼來源:SpringTransactionTest.java

示例4: testB

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
	public void testB(int id) throws InterruptedException {
		// 0s
		DefaultTransactionDefinition def = new DefaultTransactionDefinition();
		def.setIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ);
		TransactionStatus status = transactionManager.getTransaction(def);
		try {
			int num = jdbcTemplate.queryForInt("select num from test where id = 1");
//			Thread.sleep(10);
			
			jdbcTemplate.update("update test set num = " + (num + 1) + " where id = 1");
//			jdbcTemplate.update("insert into test values(" + id + ",'23',5)");
			transactionManager.commit(status);
		} catch (Exception e) {
			transactionManager.rollback(status);
			throw e;
		}
	}
 
開發者ID:Jakegogo,項目名稱:concurrent,代碼行數:19,代碼來源:SpringTransactionTest.java

示例5: execute

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
@Override
public <T> T execute(final Function<Session, T> callback) {
    try {
        DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
        definition.setIsolationLevel(getTransactionIsolation().getTransactionIsolation());
        int timeout = getTimeout();
        if (timeout  >= 0) {
            definition.setTimeout(timeout);
        }
        definition.setReadOnly(isReadOnly());
        return connectionProvider.connection(false, connection -> {
            Session session =  newSession(connection);
            TransactionTemplate tt = new TransactionTemplate(platformTransactionManager, definition);
            return tt.execute(transactionStatus -> callback.apply(session));
        });
    } catch (final Exception e) {
        throw JdbcTemplateExceptionTranslator.doTranslate(e);
    }
}
 
開發者ID:ufoscout,項目名稱:jporm,代碼行數:20,代碼來源:JdbcTemplateTransaction.java

示例6: dbTranNestRollback

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
public void dbTranNestRollback() throws Exception{
	PlatformTransactionManager  transactionManager=MicroTranManagerHolder.getTransactionManager(dbName);
    DefaultTransactionDefinition def =new DefaultTransactionDefinition();
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus status=transactionManager.getTransaction(def);
    transactionManager.rollback(status);

}
 
開發者ID:jeffreyning,項目名稱:nh-micro,代碼行數:10,代碼來源:MicroServiceTemplateSupport.java

示例7: dbTranNestRollbackAndThrow

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
public void dbTranNestRollbackAndThrow() throws Exception{
	PlatformTransactionManager  transactionManager=MicroTranManagerHolder.getTransactionManager(dbName);
    DefaultTransactionDefinition def =new DefaultTransactionDefinition();
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus status=transactionManager.getTransaction(def);
    transactionManager.rollback(status);
    throw new RuntimeException("dbTranNestRollbackAndThrow");

}
 
開發者ID:jeffreyning,項目名稱:nh-micro,代碼行數:11,代碼來源:MicroServiceTemplateSupport.java

示例8: updateTransactionOrderRefundStatus

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
private void updateTransactionOrderRefundStatus(PaymentStatusInfo statusInfo) throws Exception {
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setIsolationLevel(TransactionDefinition.ISOLATION_DEFAULT);
    TransactionStatus status = txManager.getTransaction(def);
    try {
        if (statusInfo.getServiceStatus().equals(PaymentServiceStatus.SUCCESS)) {
            Integer tradeId = Integer.valueOf(statusInfo.getTradeId());
            PaymentTransaction transactionPO = transactionMapper.selectByPrimaryKey(tradeId);
            if (null == transactionPO) {
                throw new KException("找不到對應交易號");
            }

            PaymentStatus localStatus = PaymentStatus.valueOf(transactionPO.getStatus());
            PaymentStatus remoteStatus = statusInfo.getStatus();

            if (!localStatus.equals(remoteStatus)) {
                boolean validState = (localStatus.equals(PaymentStatus.SUCCESS) &&
                        remoteStatus.equals(PaymentStatus.APPLIED_REFUND));
                validState |=  (localStatus.equals(PaymentStatus.APPLIED_REFUND) &&
                        (remoteStatus.equals(PaymentStatus.REFUNDED) ||
                                remoteStatus.equals(PaymentStatus.REFUND_FAILED)));

                if (validState) {
                    transactionPO.setStatus(remoteStatus.name());
                    transactionPO.setRefundTime(statusInfo.getPaymentTime());
                    getOrderCoordinator().updateRefundStatus(transactionPO.getOrderId(), transactionPO);
                    transactionMapper.updateByPrimaryKeySelective(transactionPO);
                } else {
                    logPaymentException(transactionPO.getOrderId(), tradeId, localStatus.name(), remoteStatus.name(), "交易狀態錯誤");
                }
            }
        }
    } catch (Exception e) {
        txManager.rollback(status);
        throw e;
    }
    txManager.commit(status);
}
 
開發者ID:superkoh,項目名稱:k-framework,代碼行數:40,代碼來源:PaymentServiceImpl.java

示例9: testDefaultTransactionDefinition

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
@Test
public void testDefaultTransactionDefinition() throws Exception {
	DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
	definition.setIsolationLevel(TransactionDefinition.ISOLATION_REPEATABLE_READ);

	try {
		dialect.beginTransaction(null, definition);
		fail("expected exception");
	}
	catch (TransactionException e) {
		// ok
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:14,代碼來源:DefaultJpaDialectTests.java

示例10: getCustomTransactionDefinition

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
private static DefaultTransactionDefinition getCustomTransactionDefinition(int IsolationLevel,int propagationBehavior){
	DefaultTransactionDefinition def = new DefaultTransactionDefinition();   
    def.setIsolationLevel(IsolationLevel);   
    def.setPropagationBehavior(propagationBehavior);   
    
    return def;
}
 
開發者ID:yinshipeng,項目名稱:sosoapi-base,代碼行數:8,代碼來源:TransactionUtils.java

示例11: createTransaction

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
public static TransactionStatus createTransaction(String name, int propagationBehavior, int isolationLevel, PlatformTransactionManager transactionManager, boolean isReadOnly) {
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName(name);
    def.setReadOnly(isReadOnly);
    def.setPropagationBehavior(propagationBehavior);
    def.setIsolationLevel(isolationLevel);
    return transactionManager.getTransaction(def);
}
 
開發者ID:passion1014,項目名稱:metaworks_framework,代碼行數:9,代碼來源:TransactionUtils.java

示例12: AutoAssignChecker

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
/**
 * Instantiates a new auto assign checker
 *
 * @param targetFilterQueryManagement
 *            to get all target filter queries
 * @param targetManagement
 *            to get targets
 * @param deploymentManagement
 *            to assign distribution sets to targets
 * @param transactionManager
 *            to run transactions
 */
public AutoAssignChecker(final TargetFilterQueryManagement targetFilterQueryManagement,
        final TargetManagement targetManagement, final DeploymentManagement deploymentManagement,
        final PlatformTransactionManager transactionManager) {
    this.targetFilterQueryManagement = targetFilterQueryManagement;
    this.targetManagement = targetManagement;
    this.deploymentManagement = deploymentManagement;

    final DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("autoAssignDSToTargets");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    def.setReadOnly(false);
    def.setIsolationLevel(Isolation.READ_COMMITTED.value());
    transactionTemplate = new TransactionTemplate(transactionManager, def);
}
 
開發者ID:eclipse,項目名稱:hawkbit,代碼行數:27,代碼來源:AutoAssignChecker.java

示例13: processFile

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
private void processFile() throws ImporterException {
try {
    hasConsumedFirstLine = false;
    readFileLine = 0;
    logger.info("will process " + getCurrentFileName());
    // Transaction Definition
    txDefinition = new DefaultTransactionDefinition();
    txDefinition
	    .setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    txDefinition.setIsolationLevel(Isolation.READ_UNCOMMITTED.value());
    txDefinition.setReadOnly(false);

    startTransaction();
    setCommitFlushMode();
    while (!isEndOfDocument()) {
	this.readLineAndProcessData();
	incrementReadedFileLine(1);
	if (needCommit()) {
	    logger
		    .info("We need to commit, flushing and clearing: "
			    + totalReadLine);
	    // and commit !
	    commit();
	    startTransaction();
	    setCommitFlushMode();

	}
    }
    commit();
    decrementReadedFileLine(1);// remove a processed line because it has been
    // incremented on time more
} catch (Exception e) {
    rollbackTransaction();
    throw new ImporterException(
	    "An error occurred when processing "
		    + getCurrentFileName() + " : " + e.getMessage(), e.getCause());
}
   }
 
開發者ID:gisgraphy,項目名稱:gisgraphy,代碼行數:39,代碼來源:AbstractSimpleImporterProcessor.java

示例14: startTransaction

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
protected void startTransaction() {
   txDefinition = new DefaultTransactionDefinition();
    txDefinition
	    .setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    txDefinition.setIsolationLevel(Isolation.READ_UNCOMMITTED.value());
    txDefinition.setReadOnly(false);
txStatus = transactionManager.getTransaction(txDefinition);

   }
 
開發者ID:gisgraphy,項目名稱:gisgraphy,代碼行數:10,代碼來源:AbstractSimpleImporterProcessor.java

示例15: getTxStatus

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
private TransactionStatus getTxStatus(String action, boolean readOnly, String isolation, String propagation){
	DefaultTransactionDefinition def = new DefaultTransactionDefinition();
	
	def.setName(action);
	
	//Set readOnly configuration
	def.setReadOnly(readOnly);
	
	//Set isolation configuration
	if(isolation.equals(Command.ISOLATION_DEFAULT)){
		def.setIsolationLevel(DefaultTransactionDefinition.ISOLATION_DEFAULT);
	}else if(isolation.equals(Command.ISOLATION_READ_COMMITED)){
		def.setIsolationLevel(DefaultTransactionDefinition.ISOLATION_READ_COMMITTED);
	}else if(isolation.equals(Command.ISOLATION_READ_UNCOMMITED)){
		def.setIsolationLevel(DefaultTransactionDefinition.ISOLATION_READ_UNCOMMITTED);
	}else if(isolation.equals(Command.ISOLATION_REPEATABLE_READ)){
		def.setIsolationLevel(DefaultTransactionDefinition.ISOLATION_REPEATABLE_READ);
	}else if(isolation.equals(Command.ISOLATION_SERIALIZABLE)){
		def.setIsolationLevel(DefaultTransactionDefinition.ISOLATION_SERIALIZABLE);
	}

	//Set propagation configuration
	if(propagation.equals(Command.PROPAGATION_REQUIRED)){
		def.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_REQUIRED);
	}else if(propagation.equals(Command.PROPAGATION_MANDATORY)){
		def.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_MANDATORY);
	}else if(propagation.equals(Command.PROPAGATION_NESTED)){
		def.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_NESTED);
	}else if(propagation.equals(Command.PROPAGATION_NEVER)){
		def.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_NEVER);
	}else if(propagation.equals(Command.PROPAGATION_NOT_SUPPORTED)){
		def.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_NOT_SUPPORTED);
	}else if(propagation.equals(Command.PROPAGATION_REQUIRES_NEW)){
		def.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_REQUIRES_NEW);
	}else if(propagation.equals(Command.PROPAGATION_SUPPORTS)){
		def.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_SUPPORTS);
	}
	
	return txManager.getTransaction(def);
}
 
開發者ID:malaguna,項目名稱:cmdit,代碼行數:41,代碼來源:ServiceDelegate.java


注:本文中的org.springframework.transaction.support.DefaultTransactionDefinition.setIsolationLevel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。