use of org.apache.ibatis.session.defaults.DefaultSqlSessionFactory in project camunda-bpm-platform by camunda.
the class ProcessEngineConfigurationImpl method initSqlSessionFactory.
protected void initSqlSessionFactory() {
// to protect access to cachedSqlSessionFactory see CAM-6682
synchronized (ProcessEngineConfigurationImpl.class) {
if (isUseSharedSqlSessionFactory) {
sqlSessionFactory = cachedSqlSessionFactory;
}
if (sqlSessionFactory == null) {
InputStream inputStream = null;
try {
inputStream = getMyBatisXmlConfigurationSteam();
// update the jdbc parameters to the configured ones...
Environment environment = new Environment("default", transactionFactory, dataSource);
Reader reader = new InputStreamReader(inputStream);
Properties properties = new Properties();
if (isUseSharedSqlSessionFactory) {
properties.put("prefix", "${@org.camunda.bpm.engine.impl.context.Context@getProcessEngineConfiguration().databaseTablePrefix}");
} else {
properties.put("prefix", databaseTablePrefix);
}
initSqlSessionFactoryProperties(properties, databaseTablePrefix, databaseType);
XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties);
Configuration configuration = parser.getConfiguration();
configuration.setEnvironment(environment);
configuration = parser.parse();
configuration.setDefaultStatementTimeout(jdbcStatementTimeout);
if (isJdbcBatchProcessing()) {
configuration.setDefaultExecutorType(ExecutorType.BATCH);
}
sqlSessionFactory = new DefaultSqlSessionFactory(configuration);
if (isUseSharedSqlSessionFactory) {
cachedSqlSessionFactory = sqlSessionFactory;
}
} catch (Exception e) {
throw new ProcessEngineException("Error while building ibatis SqlSessionFactory: " + e.getMessage(), e);
} finally {
IoUtil.closeSilently(inputStream);
}
}
}
}
use of org.apache.ibatis.session.defaults.DefaultSqlSessionFactory in project Activiti by Activiti.
the class ProcessEngineConfigurationImpl method initSqlSessionFactory.
public void initSqlSessionFactory() {
if (sqlSessionFactory == null) {
InputStream inputStream = null;
try {
inputStream = getMyBatisXmlConfigurationStream();
Environment environment = new Environment("default", transactionFactory, dataSource);
Reader reader = new InputStreamReader(inputStream);
Properties properties = new Properties();
properties.put("prefix", databaseTablePrefix);
String wildcardEscapeClause = "";
if ((databaseWildcardEscapeCharacter != null) && (databaseWildcardEscapeCharacter.length() != 0)) {
wildcardEscapeClause = " escape '" + databaseWildcardEscapeCharacter + "'";
}
properties.put("wildcardEscapeClause", wildcardEscapeClause);
// set default properties
properties.put("limitBefore", "");
properties.put("limitAfter", "");
properties.put("limitBetween", "");
properties.put("limitOuterJoinBetween", "");
properties.put("limitBeforeNativeQuery", "");
properties.put("orderBy", "order by ${orderByColumns}");
properties.put("blobType", "BLOB");
properties.put("boolValue", "TRUE");
if (databaseType != null) {
properties.load(getResourceAsStream("org/activiti/db/properties/" + databaseType + ".properties"));
}
Configuration configuration = initMybatisConfiguration(environment, reader, properties);
sqlSessionFactory = new DefaultSqlSessionFactory(configuration);
} catch (Exception e) {
throw new ActivitiException("Error while building ibatis SqlSessionFactory: " + e.getMessage(), e);
} finally {
IoUtil.closeSilently(inputStream);
}
}
}
use of org.apache.ibatis.session.defaults.DefaultSqlSessionFactory in project mybatis-3 by mybatis.
the class SqlSessionTest method shouldFailSelectOneAuthorUsingMapperClassWithTwoResultHandlers.
@Test
void shouldFailSelectOneAuthorUsingMapperClassWithTwoResultHandlers() {
Configuration configuration = new Configuration(sqlMapper.getConfiguration().getEnvironment());
configuration.addMapper(AuthorMapperWithMultipleHandlers.class);
SqlSessionFactory sqlMapperWithMultipleHandlers = new DefaultSqlSessionFactory(configuration);
try (SqlSession sqlSession = sqlMapperWithMultipleHandlers.openSession()) {
DefaultResultHandler handler1 = new DefaultResultHandler();
DefaultResultHandler handler2 = new DefaultResultHandler();
AuthorMapperWithMultipleHandlers mapper = sqlSession.getMapper(AuthorMapperWithMultipleHandlers.class);
Assertions.assertThrows(BindingException.class, () -> mapper.selectAuthor(101, handler1, handler2));
}
}
use of org.apache.ibatis.session.defaults.DefaultSqlSessionFactory in project mybatis-3 by mybatis.
the class SqlSessionTest method shouldFailSelectOneAuthorUsingMapperClassWithTwoRowBounds.
@Test
void shouldFailSelectOneAuthorUsingMapperClassWithTwoRowBounds() {
Configuration configuration = new Configuration(sqlMapper.getConfiguration().getEnvironment());
configuration.addMapper(AuthorMapperWithRowBounds.class);
SqlSessionFactory sqlMapperWithMultipleHandlers = new DefaultSqlSessionFactory(configuration);
try (SqlSession sqlSession = sqlMapperWithMultipleHandlers.openSession()) {
RowBounds bounds1 = new RowBounds(0, 1);
RowBounds bounds2 = new RowBounds(0, 1);
AuthorMapperWithRowBounds mapper = sqlSession.getMapper(AuthorMapperWithRowBounds.class);
Assertions.assertThrows(BindingException.class, () -> mapper.selectAuthor(101, bounds1, bounds2));
}
}
use of org.apache.ibatis.session.defaults.DefaultSqlSessionFactory in project mybatis-3 by mybatis.
the class ProviderTest method shouldUseProvider.
@Test
void shouldUseProvider() throws Exception {
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multidb/ProviderConfig.xml");
DefaultSqlSessionFactory sqlSessionFactory = (DefaultSqlSessionFactory) new SqlSessionFactoryBuilder().build(reader);
Configuration c = sqlSessionFactory.getConfiguration();
assertEquals("translated", c.getDatabaseId());
}
Aggregations