本文整理汇总了Java中org.apache.ibatis.session.TransactionIsolationLevel类的典型用法代码示例。如果您正苦于以下问题:Java TransactionIsolationLevel类的具体用法?Java TransactionIsolationLevel怎么用?Java TransactionIsolationLevel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TransactionIsolationLevel类属于org.apache.ibatis.session包,在下文中一共展示了TransactionIsolationLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openSessionFromDataSource
import org.apache.ibatis.session.TransactionIsolationLevel; //导入依赖的package包/类
/**
* 源码解析: 从数据源创建会话
*
* @param execType 执行类型
* @param level 数据库隔离级别
* @param autoCommit 是否自动提交
* @return
*/
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) {
Transaction tx = null;
try {
// 源码解析: 获取环境
final Environment environment = configuration.getEnvironment();
// 源码解析: 获取事务工厂
final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
// 源码解析: 创建一个新的事务
tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit);
// 源码解析: 创建执行器
final Executor executor = configuration.newExecutor(tx, execType);
// 源码解析: 创建一个新的sql会话
return new DefaultSqlSession(configuration, executor, autoCommit);
} catch (Exception e) {
// 源码解析: 关闭事务
closeTransaction(tx); // may have fetched a connection so lets call close()
throw ExceptionFactory.wrapException("Error opening session. Cause: " + e, e);
} finally {
// 源码解析: 错误上下文清空重置
ErrorContext.instance().reset();
}
}
示例2: openSessionFromDataSource
import org.apache.ibatis.session.TransactionIsolationLevel; //导入依赖的package包/类
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) {
Transaction tx = null;
try {
final Environment environment = configuration.getEnvironment();
final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
//通过事务工厂来产生一个事务
tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit);
//生成一个执行器(事务包含在执行器里)
final Executor executor = configuration.newExecutor(tx, execType);
//然后产生一个DefaultSqlSession
return new DefaultSqlSession(configuration, executor, autoCommit);
} catch (Exception e) {
//如果打开事务出错,则关闭它
closeTransaction(tx); // may have fetched a connection so lets call close()
throw ExceptionFactory.wrapException("Error opening session. Cause: " + e, e);
} finally {
//最后清空错误上下文
ErrorContext.instance().reset();
}
}
示例3: batchUpdate
import org.apache.ibatis.session.TransactionIsolationLevel; //导入依赖的package包/类
protected int batchUpdate(List<T> updateObjects , String statement , Integer batchSize){
SqlSession sqlSession = this.sqlSessionTemplate.getSqlSessionFactory().openSession(ExecutorType.BATCH , TransactionIsolationLevel.NONE);
if (batchSize == null || batchSize == 0){
batchSize = BATCH_SIZE ;
}
int execCount = 0;
for (int i = 0 , size = updateObjects.size(); i < size ; i++){
sqlSession.update(statement, updateObjects);
if ((i != 0 && i % batchSize == 0) || i == size -1){
List<BatchResult> batchResults = sqlSession.flushStatements();
execCount = batchResults.size() ;
sqlSession.commit();
sqlSession.clearCache();
LOGGER.debug("batch insert , current commit size : {} " , execCount );
}
}
sqlSession.close();
return execCount;
}
示例4: batchDelete
import org.apache.ibatis.session.TransactionIsolationLevel; //导入依赖的package包/类
protected int batchDelete(List<T> delObjects , String statement , Integer batchSize){
SqlSession sqlSession = this.sqlSessionTemplate.getSqlSessionFactory().openSession(ExecutorType.BATCH , TransactionIsolationLevel.NONE);
if (batchSize == null || batchSize == 0){
batchSize = BATCH_SIZE ;
}
int execCount = 0;
for (int i = 0 , size = delObjects.size(); i < size ; i++){
sqlSession.delete(statement, delObjects);
if ((i != 0 && i % batchSize == 0) || i == size -1){
List<BatchResult> batchResults = sqlSession.flushStatements();
execCount = batchResults.size() ;
sqlSession.commit();
sqlSession.clearCache();
LOGGER.debug("batch insert , current commit size : {} " , execCount );
}
}
sqlSession.close();
return execCount;
}
示例5: insertNubRelationBatch
import org.apache.ibatis.session.TransactionIsolationLevel; //导入依赖的package包/类
@Transactional(
executorType = ExecutorType.BATCH,
isolationLevel = TransactionIsolationLevel.READ_UNCOMMITTED,
exceptionMessage = "Something went wrong while inserting nub relations batch for dataset {0}"
)
private void insertNubRelationBatch(UUID datasetKey, Map<Integer, Integer> relations, Iterable<Integer> usageKeyBatch) {
for (Integer usageKey : usageKeyBatch) {
Set<NameUsageIssue> issues = nameUsageMapper.getIssues(usageKey).getIssues();
if (relations.get(usageKey) == null) {
// no match, add issue if not existing yet
if (!issues.contains(NameUsageIssue.BACKBONE_MATCH_NONE)) {
issues.add(NameUsageIssue.BACKBONE_MATCH_NONE);
nameUsageMapper.updateIssues(usageKey, issues);
}
} else {
if (issues.remove(NameUsageIssue.BACKBONE_MATCH_NONE) || issues.remove(NameUsageIssue.BACKBONE_MATCH_FUZZY)) {
nameUsageMapper.updateIssues(usageKey, issues);
}
nubRelMapper.insert(datasetKey, usageKey, relations.get(usageKey));
// for CoL with its instable ids update source key
if (Constants.COL_DATASET_KEY.equals(datasetKey)) {
usageMapper.updateSourceTaxonKey(relations.get(usageKey), usageKey);
}
}
}
}
示例6: verify
import org.apache.ibatis.session.TransactionIsolationLevel; //导入依赖的package包/类
@Override
public void verify() {
SqlSessionManager sqlSessionManager = getInjector().getInstance(SqlSessionManager.class);
if (sqlSessionManager != null) {
try (SqlSessionManager ssm = sqlSessionManager) {
if (!ssm.isManagedSessionStarted()) {
ssm.startManagedSession(ExecutorType.SIMPLE, (TransactionIsolationLevel) null);
}
Connection connection = ssm.getConnection();
if (connection != null) {
try (Connection conn = connection) {
DatabaseMetaData dmd = conn.getMetaData();
if (dmd != null) {
if (!compareBeanToTable(dmd, getBeanClasses(getConfig()))) {
throw new IllegalStateException("compareBeanToTable returns false.");
}
}
ssm.rollback(true);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
}
}
示例7: newTransaction
import org.apache.ibatis.session.TransactionIsolationLevel; //导入依赖的package包/类
@Override
public Transaction newTransaction(DataSource ds, TransactionIsolationLevel level, boolean autoCommit) {
// Silently ignores autocommit and isolation level, as managed transactions are entirely
// controlled by an external manager. It's silently ignored so that
// code remains portable between managed and unmanaged configurations.
return new ManagedTransaction(ds, level, closeConnection);
}
示例8: openSessionFromDataSource
import org.apache.ibatis.session.TransactionIsolationLevel; //导入依赖的package包/类
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) {
Transaction tx = null;
try {
final Environment environment = configuration.getEnvironment();
final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit);
final Executor executor = configuration.newExecutor(tx, execType);
return new DefaultSqlSession(configuration, executor, autoCommit);
} catch (Exception e) {
closeTransaction(tx); // may have fetched a connection so lets call close()
throw ExceptionFactory.wrapException("Error opening session. Cause: " + e, e);
} finally {
ErrorContext.instance().reset();
}
}
示例9: isolationLevel
import org.apache.ibatis.session.TransactionIsolationLevel; //导入依赖的package包/类
@Override
public TransactionIsolationLevel isolationLevel() {
TransactionIsolationLevel ret = null;
if (particular != null) {
ret = particular.isolationLevel();
}
if ((ret == null) && (setting != null)) {
ret = setting.isolationLevel();
}
if (ret == null) {
ret = def.isolationLevel();
}
return ret;
}
示例10: JdbcTransaction
import org.apache.ibatis.session.TransactionIsolationLevel; //导入依赖的package包/类
public JdbcTransaction(DataSource ds, TransactionIsolationLevel desiredLevel, boolean desiredAutoCommit) {
dataSource = ds;
level = desiredLevel;
autoCommmit = desiredAutoCommit;
}
示例11: newTransaction
import org.apache.ibatis.session.TransactionIsolationLevel; //导入依赖的package包/类
@Override
public Transaction newTransaction(DataSource ds, TransactionIsolationLevel level, boolean autoCommit) {
return new JdbcTransaction(ds, level, autoCommit);
}
示例12: ManagedTransaction
import org.apache.ibatis.session.TransactionIsolationLevel; //导入依赖的package包/类
public ManagedTransaction(DataSource ds, TransactionIsolationLevel level, boolean closeConnection) {
this.dataSource = ds;
this.level = level;
this.closeConnection = closeConnection;
}
示例13: openSession
import org.apache.ibatis.session.TransactionIsolationLevel; //导入依赖的package包/类
@Override
public SqlSession openSession(TransactionIsolationLevel level) {
return openSessionFromDataSource(configuration.getDefaultExecutorType(), level, false);
}
示例14: newTransaction
import org.apache.ibatis.session.TransactionIsolationLevel; //导入依赖的package包/类
@Override
public Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit) {
return new ReadWriteManagedTransaction(dataSource);
}
示例15: newTransaction
import org.apache.ibatis.session.TransactionIsolationLevel; //导入依赖的package包/类
@Override
public Transaction newTransaction(DataSource ds, TransactionIsolationLevel level, boolean autoCommit) {
// 源码解析: 返回JDBC事务
return new JdbcTransaction(ds, level, autoCommit);
}