use of org.apache.ibatis.mapping.Environment in project mybatis-3 by mybatis.
the class ClobReaderTypeHandlerTest method setupSqlSessionFactory.
@BeforeClass
public static void setupSqlSessionFactory() throws Exception {
DataSource dataSource = BaseDataTest.createUnpooledDataSource("org/apache/ibatis/type/jdbc.properties");
BaseDataTest.runScript(dataSource, "org/apache/ibatis/type/ClobReaderTypeHandlerTest.sql");
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 XMLConfigBuilder method databaseIdProviderElement.
private void databaseIdProviderElement(XNode context) throws Exception {
DatabaseIdProvider databaseIdProvider = null;
if (context != null) {
String type = context.getStringAttribute("type");
// awful patch to keep backward compatibility
if ("VENDOR".equals(type)) {
type = "DB_VENDOR";
}
Properties properties = context.getChildrenAsProperties();
databaseIdProvider = (DatabaseIdProvider) resolveClass(type).newInstance();
databaseIdProvider.setProperties(properties);
}
Environment environment = configuration.getEnvironment();
if (environment != null && databaseIdProvider != null) {
String databaseId = databaseIdProvider.getDatabaseId(environment.getDataSource());
configuration.setDatabaseId(databaseId);
}
}
use of org.apache.ibatis.mapping.Environment in project mybatis-3 by mybatis.
the class XmlExternalRefTest 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(PersonMapper.class);
configuration.addMapper(PetMapper.class);
return new SqlSessionFactoryBuilder().build(configuration);
}
use of org.apache.ibatis.mapping.Environment in project mybatis-3 by mybatis.
the class EnumWithOgnlTest method testConfiguration.
@Test
public void testConfiguration() {
UnpooledDataSourceFactory dataSourceFactory = new UnpooledDataSourceFactory();
Properties dataSourceProperties = new Properties();
dataSourceProperties.put("driver", "org.hsqldb.jdbcDriver");
dataSourceProperties.put("url", "jdbc:hsqldb:mem:xml_references");
dataSourceProperties.put("username", "sa");
dataSourceFactory.setProperties(dataSourceProperties);
Environment environment = new Environment("test", new JdbcTransactionFactory(), dataSourceFactory.getDataSource());
Configuration configuration = new Configuration();
configuration.setEnvironment(environment);
configuration.getTypeAliasRegistry().registerAlias(Person.class);
configuration.addMapper(PersonMapper.class);
configuration.addMapper(PersonMapper2.class);
new DefaultSqlSessionFactory(configuration);
}
use of org.apache.ibatis.mapping.Environment in project mybatis-3 by mybatis.
the class ReverseIncludeTest 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(ReverseIncludePersonMapper.class);
return new SqlSessionFactoryBuilder().build(configuration);
}
Aggregations