本文整理匯總了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;
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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);
}
}
示例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);
}
示例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");
}
示例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);
}
示例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
}
}
示例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;
}
示例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);
}
示例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);
}
示例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());
}
}
示例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);
}
示例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);
}