本文整理汇总了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);
}