use of org.apache.ibatis.session.ExecutorType in project loc-framework by lord-of-code.
the class LocMybatisAutoConfiguration method createSqlSessionTemplate.
private void createSqlSessionTemplate(ConfigurableListableBeanFactory configurableListableBeanFactory, String prefixName, MybatisProperties mybatisProperties, SqlSessionFactory sqlSessionFactory) {
ExecutorType executorType = mybatisProperties.getExecutorType();
SqlSessionTemplate sqlSessionTemplate;
if (executorType != null) {
sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory, executorType);
} else {
sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
}
register(configurableListableBeanFactory, sqlSessionTemplate, prefixName + "SessionTemplate", prefixName + "St");
}
use of org.apache.ibatis.session.ExecutorType in project camel by apache.
the class MyBatisProducer method process.
public void process(Exchange exchange) throws Exception {
SqlSession session;
ExecutorType executorType = endpoint.getExecutorType();
if (executorType == null) {
session = endpoint.getSqlSessionFactory().openSession();
} else {
session = endpoint.getSqlSessionFactory().openSession(executorType);
}
try {
switch(endpoint.getStatementType()) {
case SelectOne:
doSelectOne(exchange, session);
break;
case SelectList:
doSelectList(exchange, session);
break;
case Insert:
doInsert(exchange, session);
break;
case InsertList:
doInsertList(exchange, session);
break;
case Update:
doUpdate(exchange, session);
break;
case UpdateList:
doUpdateList(exchange, session);
break;
case Delete:
doDelete(exchange, session);
break;
case DeleteList:
doDeleteList(exchange, session);
break;
default:
throw new IllegalArgumentException("Unsupported statementType: " + endpoint.getStatementType());
}
// flush the batch statements and commit the database connection
session.commit();
} catch (Exception e) {
// discard the pending batch statements and roll the database connection back
session.rollback();
throw e;
} finally {
// and finally close the session as we're done
session.close();
}
}
use of org.apache.ibatis.session.ExecutorType in project JessMA by ldcsaa.
the class MyBatisSessionMgr method changeSessionExecutorType.
/**
* 把当前 {@link SqlSession} 的 {@link ExecutorType} 设置为 {@literal type}
*/
public void changeSessionExecutorType(ExecutorType type) {
SqlSession session = localSession.get();
if (session == null)
localExecutorType.set(type);
else {
if (type == null)
type = getDefaultExecutorType();
ExecutorType currentType = localExecutorType.get();
if (type != currentType) {
SqlSession newSession = sessionFactory.openSession(type, session.getConnection());
session.clearCache();
localSession.set(newSession);
localExecutorType.set(type);
}
}
}
Aggregations