Search in sources :

Example 1 with XMLMapperBuilder

use of org.apache.ibatis.builder.xml.XMLMapperBuilder in project mybatis-3 by mybatis.

the class XmlMapperBuilderTest method shouldSuccessfullyLoadXMLMapperFile.

@Test
public void shouldSuccessfullyLoadXMLMapperFile() throws Exception {
    Configuration configuration = new Configuration();
    String resource = "org/apache/ibatis/builder/AuthorMapper.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    XMLMapperBuilder builder = new XMLMapperBuilder(inputStream, configuration, resource, configuration.getSqlFragments());
    builder.parse();
}
Also used : Configuration(org.apache.ibatis.session.Configuration) InputStream(java.io.InputStream) XMLMapperBuilder(org.apache.ibatis.builder.xml.XMLMapperBuilder) Test(org.junit.Test)

Example 2 with XMLMapperBuilder

use of org.apache.ibatis.builder.xml.XMLMapperBuilder in project mybatis-3 by mybatis.

the class MapperAnnotationBuilder method loadXmlResource.

private void loadXmlResource() {
    // this flag is set at XMLMapperBuilder#bindMapperForNamespace
    if (!configuration.isResourceLoaded("namespace:" + type.getName())) {
        String xmlResource = type.getName().replace('.', '/') + ".xml";
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(type.getClassLoader(), xmlResource);
        } catch (IOException e) {
        // ignore, resource is not required
        }
        if (inputStream != null) {
            XMLMapperBuilder xmlParser = new XMLMapperBuilder(inputStream, assistant.getConfiguration(), xmlResource, configuration.getSqlFragments(), type.getName());
            xmlParser.parse();
        }
    }
}
Also used : InputStream(java.io.InputStream) XMLMapperBuilder(org.apache.ibatis.builder.xml.XMLMapperBuilder) IOException(java.io.IOException)

Example 3 with XMLMapperBuilder

use of org.apache.ibatis.builder.xml.XMLMapperBuilder in project sonarqube by SonarSource.

the class MyBatisConfBuilder method loadMapper.

public void loadMapper(String mapperName) {
    String configFile = configFilePath(mapperName);
    InputStream input = null;
    try {
        input = getClass().getResourceAsStream(configFile);
        checkArgument(input != null, format("Can not find mapper XML file %s", configFile));
        new XMLMapperBuilder(input, conf, mapperName, conf.getSqlFragments()).parse();
        loadAndConfigureLogger(mapperName);
    } catch (Exception e) {
        throw new IllegalArgumentException("Unable to load mapper " + mapperName, e);
    } finally {
        Closeables.closeQuietly(input);
    }
}
Also used : InputStream(java.io.InputStream) XMLMapperBuilder(org.apache.ibatis.builder.xml.XMLMapperBuilder)

Example 4 with XMLMapperBuilder

use of org.apache.ibatis.builder.xml.XMLMapperBuilder in project mybatis-3 by mybatis.

the class XmlMapperBuilderTest method mappedStatementWithOptions.

@Test
public void mappedStatementWithOptions() throws Exception {
    Configuration configuration = new Configuration();
    String resource = "org/apache/ibatis/builder/AuthorMapper.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    XMLMapperBuilder builder = new XMLMapperBuilder(inputStream, configuration, resource, configuration.getSqlFragments());
    builder.parse();
    MappedStatement mappedStatement = configuration.getMappedStatement("selectWithOptions");
    assertThat(mappedStatement.getFetchSize(), is(200));
    assertThat(mappedStatement.getTimeout(), is(10));
    assertThat(mappedStatement.getStatementType(), is(StatementType.PREPARED));
    assertThat(mappedStatement.getResultSetType(), is(ResultSetType.SCROLL_SENSITIVE));
    assertThat(mappedStatement.isFlushCacheRequired(), is(false));
    assertThat(mappedStatement.isUseCache(), is(false));
}
Also used : Configuration(org.apache.ibatis.session.Configuration) InputStream(java.io.InputStream) XMLMapperBuilder(org.apache.ibatis.builder.xml.XMLMapperBuilder) MappedStatement(org.apache.ibatis.mapping.MappedStatement) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)4 XMLMapperBuilder (org.apache.ibatis.builder.xml.XMLMapperBuilder)4 Configuration (org.apache.ibatis.session.Configuration)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 MappedStatement (org.apache.ibatis.mapping.MappedStatement)1