use of org.apache.ibatis.session.SqlSessionFactoryBuilder 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.session.SqlSessionFactoryBuilder in project mybatis-3 by mybatis.
the class LogFactoryTest method shouldReadLogImplFromSettings.
@Test
public void shouldReadLogImplFromSettings() throws Exception {
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/logging/mybatis-config.xml");
new SqlSessionFactoryBuilder().build(reader);
reader.close();
Log log = LogFactory.getLog(Object.class);
log.debug("Debug message.");
assertEquals(log.getClass().getName(), NoLoggingImpl.class.getName());
}
use of org.apache.ibatis.session.SqlSessionFactoryBuilder in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method createDynamicSqlSource.
private DynamicSqlSource createDynamicSqlSource(SqlNode... contents) throws IOException, SQLException {
createBlogDataSource();
final String resource = "org/apache/ibatis/builder/MapperConfig.xml";
final Reader reader = Resources.getResourceAsReader(resource);
SqlSessionFactory sqlMapper = new SqlSessionFactoryBuilder().build(reader);
Configuration configuration = sqlMapper.getConfiguration();
MixedSqlNode sqlNode = mixedContents(contents);
return new DynamicSqlSource(configuration, sqlNode);
}
use of org.apache.ibatis.session.SqlSessionFactoryBuilder in project JessMA by ldcsaa.
the class MyBatisSessionMgr method buildSessionFactory.
/** 创建 {@link SqlSessionFactory} */
private void buildSessionFactory() {
synchronized (this) {
if (sessionFactory == null) {
try {
Reader reader = Resources.getResourceAsReader(configFile);
sessionFactory = new SqlSessionFactoryBuilder().build(reader, environment);
if (GeneralHelper.isStrNotEmpty(pattern)) {
Set<String> packages = PackageHelper.getPackages(pattern);
for (String pkg : packages) {
Set<Class<?>> entities = PackageHelper.getClasses(pkg, false, new ClassFilter() {
@Override
public boolean accept(Class<?> clazz) {
if (!BeanHelper.isPublicInterface(clazz))
return false;
return true;
}
});
Configuration cfg = sessionFactory.getConfiguration();
for (Class<?> clazz : entities) {
if (!cfg.hasMapper(clazz))
cfg.addMapper(clazz);
}
}
}
} catch (IOException e) {
throw new SqlSessionException(e);
}
}
}
}
use of org.apache.ibatis.session.SqlSessionFactoryBuilder in project generator by mybatis.
the class AbstractTest method setUp.
@Before
public void setUp() throws Exception {
createDatabase();
Reader reader = Resources.getResourceAsReader(getMyBatisConfigFile());
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
}
Aggregations