Java Code Examples for org.apache.ibatis.session.Configuration#setEnvironment()

The following examples show how to use org.apache.ibatis.session.Configuration#setEnvironment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EnumWithOgnlTest.java    From mybatis with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: NpeExtendsTest.java    From mybaties with Apache License 2.0 6 votes vote down vote up
private SqlSessionFactory getSqlSessionFactoryWithConstructor() {
    UnpooledDataSourceFactory unpooledDataSourceFactory = new UnpooledDataSourceFactory();
    Properties properties = new Properties();
    properties.setProperty("driver", "org.hsqldb.jdbcDriver");
    properties.setProperty("url", "jdbc:hsqldb:mem:extends_with_constructor");
    properties.setProperty("username", "sa");
    unpooledDataSourceFactory.setProperties(properties);
    Environment environment = new Environment("extends_with_constructor", new JdbcTransactionFactory(), unpooledDataSourceFactory.getDataSource());
    
    Configuration configuration = new Configuration();
    configuration.setEnvironment(environment);
    configuration.addMapper(StudentConstructorMapper.class);
    configuration.addMapper(TeacherMapper.class);
    configuration.getMappedStatementNames();
    configuration.setAutoMappingBehavior(AutoMappingBehavior.NONE);
    
    return new DefaultSqlSessionFactory(configuration);
}
 
Example 3
Source File: SubstitutionInAnnotsTest.java    From mybatis with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  Class.forName("org.hsqldb.jdbcDriver");
  Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:annots", "sa", "");
  Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/substitution_in_annots/CreateDB.sql");
  ScriptRunner runner = new ScriptRunner(c);
  runner.setLogWriter(null);
  runner.setErrorLogWriter(null);
  runner.runScript(reader);
  c.commit();
  reader.close();

  Configuration configuration = new Configuration();
  Environment environment = new Environment("test", new JdbcTransactionFactory(), new UnpooledDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:annots", null));
  configuration.setEnvironment(environment);
  
  configuration.addMapper(SubstitutionInAnnotsMapper.class);
  
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
 
Example 4
Source File: SubstitutionInAnnotsTest.java    From mybaties with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  Class.forName("org.hsqldb.jdbcDriver");
  Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:annots", "sa", "");
  Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/substitution_in_annots/CreateDB.sql");
  ScriptRunner runner = new ScriptRunner(c);
  runner.setLogWriter(null);
  runner.setErrorLogWriter(null);
  runner.runScript(reader);
  c.commit();
  reader.close();

  Configuration configuration = new Configuration();
  Environment environment = new Environment("test", new JdbcTransactionFactory(), new UnpooledDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:annots", null));
  configuration.setEnvironment(environment);
  
  configuration.addMapper(SubstitutionInAnnotsMapper.class);
  
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
 
Example 5
Source File: AbstractEngineConfiguration.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public Configuration initMybatisConfiguration(Environment environment, Reader reader, Properties properties) {
    XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties);
    Configuration configuration = parser.getConfiguration();

    if (databaseType != null) {
        configuration.setDatabaseId(databaseType);
    }

    configuration.setEnvironment(environment);

    initCustomMybatisMappers(configuration);
    initMybatisTypeHandlers(configuration);
    initCustomMybatisInterceptors(configuration);
    if (isEnableLogSqlExecutionTime()) {
        initMyBatisLogSqlExecutionTimePlugin(configuration);
    }

    configuration = parseMybatisConfiguration(parser);
    return configuration;
}
 
Example 6
Source File: ProcessEngineConfigurationImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public Configuration initMybatisConfiguration(Environment environment, Reader reader, Properties properties) {
  XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties);
  Configuration configuration = parser.getConfiguration();

  if(databaseType != null) {
      configuration.setDatabaseId(databaseType);
  }

  configuration.setEnvironment(environment);

  initMybatisTypeHandlers(configuration);
  initCustomMybatisMappers(configuration);

  configuration = parseMybatisConfiguration(configuration, parser);
  return configuration;
}
 
Example 7
Source File: MultipleIncludeTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
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(MultipleIncludePersonMapper.class);

  return new SqlSessionFactoryBuilder().build(configuration);
}
 
Example 8
Source File: ReverseIncludeTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 9
Source File: ProcessEngineConfigurationImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected Configuration initMybatisConfiguration(Environment environment, Reader reader, Properties properties) {
    XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties);
    Configuration configuration = parser.getConfiguration();
    configuration.setEnvironment(environment);

    initMybatisTypeHandlers(configuration);
    initCustomMybatisMappers(configuration);

    configuration = parseMybatisConfiguration(configuration, parser);
    return configuration;
}
 
Example 10
Source File: ResultMapExtendsTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
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(ResultMapReferencePersonMapper.class);
  configuration.addMapper(ResultMapReferencePetMapper.class);

  return new SqlSessionFactoryBuilder().build(configuration);
}
 
Example 11
Source File: DmnEngineConfiguration.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Configuration initMybatisConfiguration(Environment environment, Reader reader, Properties properties) {
  XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties);
  Configuration configuration = parser.getConfiguration();

  if (databaseType != null) {
    configuration.setDatabaseId(databaseType);
  }

  configuration.setEnvironment(environment);

  initCustomMybatisMappers(configuration);

  configuration = parseMybatisConfiguration(configuration, parser);
  return configuration;
}
 
Example 12
Source File: FormEngineConfiguration.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Configuration initMybatisConfiguration(Environment environment, Reader reader, Properties properties) {
  XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties);
  Configuration configuration = parser.getConfiguration();

  if (databaseType != null) {
    configuration.setDatabaseId(databaseType);
  }

  configuration.setEnvironment(environment);

  initCustomMybatisMappers(configuration);

  configuration = parseMybatisConfiguration(configuration, parser);
  return configuration;
}
 
Example 13
Source File: SameIdTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 14
Source File: MultipleCrossIncludeTest.java    From mybaties with Apache License 2.0 5 votes vote down vote up
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(MultipleCrossIncludePersonMapper.class);
  configuration.addMapper(MultipleCrossIncludePetMapper.class);

  return new SqlSessionFactoryBuilder().build(configuration);
}
 
Example 15
Source File: XmlExternalRefTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 16
Source File: ParameterMapReferenceTest.java    From mybaties with Apache License 2.0 5 votes vote down vote up
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(ParameterMapReferencePersonMapper.class);
  configuration.addMapper(ParameterMapReferencePetMapper.class);

  return new SqlSessionFactoryBuilder().build(configuration);
}
 
Example 17
Source File: SameIdTest.java    From mybaties with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 18
Source File: ParameterMapReferenceTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
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(ParameterMapReferencePersonMapper.class);
  configuration.addMapper(ParameterMapReferencePetMapper.class);

  return new SqlSessionFactoryBuilder().build(configuration);
}
 
Example 19
Source File: MultipleIncludeTest.java    From mybaties with Apache License 2.0 5 votes vote down vote up
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(MultipleIncludePersonMapper.class);

  return new SqlSessionFactoryBuilder().build(configuration);
}
 
Example 20
Source File: MultipleReverseIncludeTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
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(MultipleReverseIncludePersonMapper.class);

  return new SqlSessionFactoryBuilder().build(configuration);
}