Java Code Examples for org.apache.ibatis.builder.xml.XMLConfigBuilder#parse()

The following examples show how to use org.apache.ibatis.builder.xml.XMLConfigBuilder#parse() . 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: AbstractEngineConfiguration.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public Configuration parseMybatisConfiguration(XMLConfigBuilder parser) {
    Configuration configuration = parser.parse();

    if (dependentEngineMybatisTypeAliasConfigs != null) {
        for (MybatisTypeAliasConfigurator typeAliasConfig : dependentEngineMybatisTypeAliasConfigs) {
            typeAliasConfig.configure(configuration.getTypeAliasRegistry());
        }
    }
    if (dependentEngineMybatisTypeHandlerConfigs != null) {
        for (MybatisTypeHandlerConfigurator typeHandlerConfig : dependentEngineMybatisTypeHandlerConfigs) {
            typeHandlerConfig.configure(configuration.getTypeHandlerRegistry());
        }
    }

    parseDependentEngineMybatisXMLMappers(configuration);
    parseCustomMybatisXMLMappers(configuration);
    return configuration;
}
 
Example 2
Source File: XmlConfigBuilderTest.java    From mybaties with Apache License 2.0 6 votes vote down vote up
@Test
public void registerJavaTypeInitializingTypeHandler() {
  final String MAPPER_CONFIG = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
      + "<!DOCTYPE configuration PUBLIC \"-//mybatis.org//DTD Config 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-config.dtd\">\n" 
      + "<configuration>\n" 
      + "  <typeHandlers>\n"
      + "    <typeHandler javaType=\"org.apache.ibatis.builder.XmlConfigBuilderTest$MyEnum\"\n"
      + "      handler=\"org.apache.ibatis.builder.XmlConfigBuilderTest$EnumOrderTypeHandler\"/>\n" 
      + "  </typeHandlers>\n" 
      + "</configuration>\n";

  XMLConfigBuilder builder = new XMLConfigBuilder(new StringReader(MAPPER_CONFIG));
  builder.parse();

  TypeHandlerRegistry typeHandlerRegistry = builder.getConfiguration().getTypeHandlerRegistry();
  TypeHandler<MyEnum> typeHandler = typeHandlerRegistry.getTypeHandler(MyEnum.class);

  assertTrue(typeHandler instanceof EnumOrderTypeHandler);
  assertArrayEquals(MyEnum.values(), ((EnumOrderTypeHandler) typeHandler).constants);
}
 
Example 3
Source File: XmlConfigBuilderTest.java    From mybatis with Apache License 2.0 6 votes vote down vote up
@Test
public void registerJavaTypeInitializingTypeHandler() {
  final String MAPPER_CONFIG = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
      + "<!DOCTYPE configuration PUBLIC \"-//mybatis.org//DTD Config 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-config.dtd\">\n" 
      + "<configuration>\n" 
      + "  <typeHandlers>\n"
      + "    <typeHandler javaType=\"org.apache.ibatis.builder.XmlConfigBuilderTest$MyEnum\"\n"
      + "      handler=\"org.apache.ibatis.builder.XmlConfigBuilderTest$EnumOrderTypeHandler\"/>\n" 
      + "  </typeHandlers>\n" 
      + "</configuration>\n";

  XMLConfigBuilder builder = new XMLConfigBuilder(new StringReader(MAPPER_CONFIG));
  builder.parse();

  TypeHandlerRegistry typeHandlerRegistry = builder.getConfiguration().getTypeHandlerRegistry();
  TypeHandler<MyEnum> typeHandler = typeHandlerRegistry.getTypeHandler(MyEnum.class);

  assertTrue(typeHandler instanceof EnumOrderTypeHandler);
  assertArrayEquals(MyEnum.values(), ((EnumOrderTypeHandler) typeHandler).constants);
}
 
Example 4
Source File: XmlConfigBuilderTest.java    From mybaties with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSuccessfullyLoadMinimalXMLConfigFile() throws Exception {
  String resource = "org/apache/ibatis/builder/MinimalMapperConfig.xml";
  InputStream inputStream = Resources.getResourceAsStream(resource);
  XMLConfigBuilder builder = new XMLConfigBuilder(inputStream);
  Configuration config = builder.parse();
  assertNotNull(config);
}
 
Example 5
Source File: XmlConfigBuilderTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSuccessfullyLoadMinimalXMLConfigFile() throws Exception {
  String resource = "org/apache/ibatis/builder/MinimalMapperConfig.xml";
  InputStream inputStream = Resources.getResourceAsStream(resource);
  XMLConfigBuilder builder = new XMLConfigBuilder(inputStream);
  Configuration config = builder.parse();
  assertNotNull(config);
}
 
Example 6
Source File: SqlSessionFactoryBean.java    From gocd with Apache License 2.0 5 votes vote down vote up
private SqlSessionFactory buildSqlSessionFactory() throws IOException {
    SqlSessionFactoryBuilder factoryBuilder = new SqlSessionFactoryBuilder();

    XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder(configLocation.getInputStream());
    Configuration configuration = xmlConfigBuilder.getConfiguration();
    configuration.setEnvironment(new Environment(getClass().getSimpleName(), new SpringManagedTransactionFactory(), this.dataSource));
    xmlConfigBuilder.parse();
    return factoryBuilder.build(configuration);
}