use of org.apache.ibatis.mapping.Environment in project mybatis-3 by mybatis.
the class SameIdTest method getSqlSessionFactoryJavaConfig.
private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception {
Class.forName("org.hsqldb.jdbcDriver");
Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", "");
initDb(c);
Configuration configuration = new Configuration();
Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null));
configuration.setEnvironment(environment);
configuration.addMapper(SameIdPersonMapper.class);
configuration.addMapper(SameIdPetMapper.class);
return new SqlSessionFactoryBuilder().build(configuration);
}
use of org.apache.ibatis.mapping.Environment in project Activiti by Activiti.
the class ProcessEngineConfigurationImpl method initSqlSessionFactory.
protected void initSqlSessionFactory() {
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();
properties.put("prefix", databaseTablePrefix);
String wildcardEscapeClause = "";
if ((databaseWildcardEscapeCharacter != null) && (databaseWildcardEscapeCharacter.length() != 0)) {
wildcardEscapeClause = " escape '" + databaseWildcardEscapeCharacter + "'";
}
properties.put("wildcardEscapeClause", wildcardEscapeClause);
if (databaseType != null) {
properties.put("limitBefore", DbSqlSessionFactory.databaseSpecificLimitBeforeStatements.get(databaseType));
properties.put("limitAfter", DbSqlSessionFactory.databaseSpecificLimitAfterStatements.get(databaseType));
properties.put("limitBetween", DbSqlSessionFactory.databaseSpecificLimitBetweenStatements.get(databaseType));
properties.put("limitOuterJoinBetween", DbSqlSessionFactory.databaseOuterJoinLimitBetweenStatements.get(databaseType));
properties.put("orderBy", DbSqlSessionFactory.databaseSpecificOrderByStatements.get(databaseType));
properties.put("limitBeforeNativeQuery", ObjectUtils.toString(DbSqlSessionFactory.databaseSpecificLimitBeforeNativeQueryStatements.get(databaseType)));
}
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.mapping.Environment in project pinpoint by naver.
the class SqlSessionTemplateITBase method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
Configuration configuration = mock(Configuration.class);
TransactionFactory transactionFactory = mock(TransactionFactory.class);
DataSource dataSource = mock(DataSource.class);
Environment environment = new Environment("test", transactionFactory, dataSource);
when(configuration.getEnvironment()).thenReturn(environment);
when(this.sqlSessionFactory.getConfiguration()).thenReturn(configuration);
when(this.sqlSessionFactory.openSession(EXECUTOR_TYPE)).thenReturn(this.sqlSessionProxy);
this.sqlSessionTemplate = new SqlSessionTemplate(this.sqlSessionFactory, EXECUTOR_TYPE);
}
use of org.apache.ibatis.mapping.Environment in project mybatis-3 by mybatis.
the class AutoMappingUnknownColumnBehaviorTest method setup.
@BeforeClass
public static void setup() throws Exception {
DataSource dataSource = BaseDataTest.createBlogDataSource();
TransactionFactory transactionFactory = new JdbcTransactionFactory();
Environment environment = new Environment("Production", transactionFactory, dataSource);
Configuration configuration = new Configuration(environment);
configuration.addMapper(Mapper.class);
sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
use of org.apache.ibatis.mapping.Environment in project mybatis-3 by mybatis.
the class ManyAnnoTest method testGetMessageForEmptyDatabase.
@Test
public void testGetMessageForEmptyDatabase() throws Exception {
final Environment environment = new Environment("test", new JdbcTransactionFactory(), BaseDataTest.createBlogDataSource());
final Configuration config = new Configuration(environment);
config.addMapper(PostMapper.class);
final SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(config);
final SqlSession session = factory.openSession();
PostMapper mapper = session.getMapper(PostMapper.class);
List<AnnoPost> posts = mapper.getPosts(101);
assertEquals(3, posts.size());
assertEquals(3, posts.get(0).getTags().size());
assertEquals(1, posts.get(1).getTags().size());
assertEquals(0, posts.get(2).getTags().size());
session.close();
}
Aggregations