List of usage examples for org.apache.ibatis.session SqlSessionFactoryBuilder build
public SqlSessionFactory build(InputStream inputStream, String environment, Properties properties)
From source file:com.aspectran.mybatis.SqlSessionFactoryBean.java
License:Apache License
protected SqlSessionFactory buildSqlSessionFactory(File configFile) { ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); try (Reader reader = new FileReader(configFile)) { Thread.currentThread().setContextClassLoader(context.getEnvironment().getClassLoader()); SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder(); return sqlSessionFactoryBuilder.build(reader, environment, properties); } catch (Exception ex) { throw new IllegalArgumentException("Failed to parse mybatis config resource: " + configLocation, ex); } finally {//from w ww . ja v a 2 s. com Thread.currentThread().setContextClassLoader(originalClassLoader); } }
From source file:com.github.hexsmith.spring.boot.mybatis.demo.MybatisXmlConfigurationDemo.java
License:Apache License
public static void main(String[] args) throws IOException { ResourceLoader resourceLoader = new DefaultResourceLoader(); Resource resource = resourceLoader.getResource("classpath:mybatis/mybatis-config.xml"); EncodedResource encodedResource = new EncodedResource(resource, "UTF-8"); Reader reader = encodedResource.getReader(); SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder(); SqlSessionFactory sqlSessionFactory = builder.build(reader, "development", new Properties()); SqlSession sqlSession = sqlSessionFactory.openSession(); User user = sqlSession.selectOne("com.github.hexsmith.spring.boot.mybatis.mapper.UserMapper.selectOneUser", 3);//from w w w . j a va2 s . c o m System.out.println(user); }
From source file:com.qwazr.connectors.MybatisConnector.java
License:Apache License
@Override public void load(File data_directory) throws IOException { final File configurationFile; if (configuration_file != null) { configurationFile = new File(configuration_file); if (!configurationFile.exists()) throw new RuntimeException("The configuration file " + configuration_file + " does not exist"); } else/*from w ww . ja v a 2s . co m*/ configurationFile = null; final Properties props; if (properties != null) { props = new Properties(); props.putAll(properties); } else props = null; final SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder(); final InputStream inputStream; if (configurationFile != null) inputStream = new FileInputStream(configurationFile); else inputStream = Resources.getResourceAsStream(ClassLoaderManager.classLoader, configuration_resource != null ? configuration_resource : default_configuration); try { if (environment != null) { if (props != null) sqlSessionFactory = builder.build(inputStream, environment, props); else sqlSessionFactory = builder.build(inputStream, environment); } else { if (props != null) sqlSessionFactory = builder.build(inputStream, props); else sqlSessionFactory = builder.build(inputStream); } } finally { IOUtils.close(inputStream); } }
From source file:com.qwazr.library.mybatis.MybatisConnector.java
License:Apache License
@Override public void load() throws IOException { final File configurationFile; if (configuration_file != null) { configurationFile = new File(SubstitutedVariables.propertyAndEnvironmentSubstitute(configuration_file)); if (!configurationFile.exists()) throw new RuntimeException( "The configuration file " + configurationFile.getPath() + " does not exist"); } else/*from w w w . ja v a 2s .c om*/ configurationFile = null; Properties props = null; if (!StringUtils.isEmpty(properties_file)) { File propFile = new File(SubstitutedVariables.propertyAndEnvironmentSubstitute(properties_file)); if (propFile.exists() && propFile.isFile()) { props = new Properties(); try (FileReader reader = new FileReader(propFile)) { props.load(reader); } } else { LOGGER.warning(() -> "The property file does not exit: " + properties_file); } } if (properties != null) { if (props == null) props = new Properties(); props.putAll(properties); } else props = null; final SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder(); try (final InputStream inputStream = configurationFile != null ? new FileInputStream(configurationFile) : Resources.getResourceAsStream( configuration_resource != null ? configuration_resource : default_configuration)) { if (environment != null) { if (props != null) sqlSessionFactory = builder.build(inputStream, environment, props); else sqlSessionFactory = builder.build(inputStream, environment); } else { if (props != null) sqlSessionFactory = builder.build(inputStream, props); else sqlSessionFactory = builder.build(inputStream); } } }