Skip to content

Improve and add tests for XMLConfigBuilder #674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/test/java/org/apache/ibatis/builder/CachedAuthorMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright 2009-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ibatis.builder;

import org.apache.ibatis.domain.blog.Author;

public interface CachedAuthorMapper {
Author selectAllAuthors();
Author selectAuthorWithInlineParams(int id);
void insertAuthor(Author author);
boolean updateAuthor(Author author);
boolean deleteAuthor(int id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.domain.CachedAuthorMapper">
<mapper namespace="org.apache.ibatis.builder.CachedAuthorMapper">

<cache readOnly="true"/>

Expand Down
50 changes: 50 additions & 0 deletions src/test/java/org/apache/ibatis/builder/CustomLongTypeHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright 2009-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ibatis.builder;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedTypes;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@MappedTypes(Long.class)
public class CustomLongTypeHandler implements TypeHandler<Long> {

@Override
public void setParameter(PreparedStatement ps, int i, Long parameter, JdbcType jdbcType) throws SQLException {
ps.setLong(i, parameter);
}

@Override
public Long getResult(ResultSet rs, String columnName) throws SQLException {
return rs.getLong(columnName);
}

@Override
public Long getResult(ResultSet rs, int columnIndex) throws SQLException {
return rs.getLong(columnIndex);
}

@Override
public Long getResult(CallableStatement cs, int columnIndex) throws SQLException {
return cs.getLong(columnIndex);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright 2009-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ibatis.builder;

import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
import org.apache.ibatis.reflection.wrapper.ObjectWrapper;
import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;

import java.util.List;
import java.util.Properties;

public class CustomObjectWrapperFactory implements ObjectWrapperFactory {

private String option;

@Override
public boolean hasWrapperFor(Object object) {
return false;
}

@Override
public ObjectWrapper getWrapperFor(MetaObject metaObject, Object object) {
return null;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2015 the original author or authors.
* Copyright 2009-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;

public class ExampleTypeHandler implements TypeHandler<String> {
public class CustomStringTypeHandler implements TypeHandler<String> {

@Override
public void setParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

<configuration>

<properties resource="org/apache/ibatis/builder/jdbc.properties">
<property name="prop1" value="aaaa"/>
</properties>

<settings>
<setting name="autoMappingBehavior" value="NONE"/>
<setting name="autoMappingUnknownColumnBehavior" value="WARNING"/>
Expand Down Expand Up @@ -49,4 +53,55 @@
<setting name="configurationFactory" value="java.lang.String"/>
</settings>

<typeAliases>
<typeAlias alias="BlogAuthor" type="org.apache.ibatis.domain.blog.Author"/>
<typeAlias type="org.apache.ibatis.domain.blog.Blog"/>
<typeAlias type="org.apache.ibatis.domain.blog.Post"/>
<package name="org.apache.ibatis.domain.jpetstore"/>
</typeAliases>

<typeHandlers>
<typeHandler javaType="String" handler="org.apache.ibatis.builder.CustomStringTypeHandler"/>
<typeHandler javaType="String" jdbcType="VARCHAR" handler="org.apache.ibatis.builder.CustomStringTypeHandler"/>
<typeHandler handler="org.apache.ibatis.builder.CustomLongTypeHandler"/>
<package name="org.apache.ibatis.builder.typehandler"/>
</typeHandlers>

<objectFactory type="org.apache.ibatis.builder.ExampleObjectFactory">
<property name="objectFactoryProperty" value="100"/>
</objectFactory>

<objectWrapperFactory type="org.apache.ibatis.builder.CustomObjectWrapperFactory" />

<plugins>
<plugin interceptor="org.apache.ibatis.builder.ExamplePlugin">
<property name="pluginProperty" value="100"/>
</plugin>
</plugins>

<environments default="development">
<environment id="development">
<transactionManager type="JDBC">
<property name="" value=""/>
</transactionManager>
<dataSource type="UNPOOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
</environments>

<databaseIdProvider type="VENDOR">
<property name="Apache Derby" value="derby"/>
</databaseIdProvider>

<mappers>
<mapper resource="org/apache/ibatis/builder/BlogMapper.xml"/>
<mapper url="file:./src/test/java/org/apache/ibatis/builder/NestedBlogMapper.xml"/>
<mapper class="org.apache.ibatis.builder.CachedAuthorMapper"/>
<package name="org.apache.ibatis.builder.mapper"/>
</mappers>

</configuration>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2015 the original author or authors.
* Copyright 2009-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,7 @@
import java.util.Properties;

public class ExampleObjectFactory extends DefaultObjectFactory {

private Properties properties;
@Override
public <T> T create(Class<T> type) {
return super.<T>create(type);
Expand All @@ -35,6 +35,11 @@ public <T> T create(Class<T> type, List<Class<?>> constructorArgTypes, List<Obje
@Override
public void setProperties(Properties properties) {
super.setProperties(properties);
this.properties = properties;
}

public Properties getProperties() {
return properties;
}

}
8 changes: 6 additions & 2 deletions src/test/java/org/apache/ibatis/builder/ExamplePlugin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2015 the original author or authors.
* Copyright 2009-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,7 +24,7 @@

@Intercepts({})
public class ExamplePlugin implements Interceptor {

private Properties properties;
@Override
public Object intercept(Invocation invocation) throws Throwable {
return invocation.proceed();
Expand All @@ -37,7 +37,11 @@ public Object plugin(Object target) {

@Override
public void setProperties(Properties properties) {
this.properties = properties;
}

public Properties getProperties() {
return properties;
}

}
2 changes: 1 addition & 1 deletion src/test/java/org/apache/ibatis/builder/MapperConfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</typeAliases>

<typeHandlers>
<typeHandler javaType="String" jdbcType="VARCHAR" handler="org.apache.ibatis.builder.ExampleTypeHandler"/>
<typeHandler javaType="String" jdbcType="VARCHAR" handler="org.apache.ibatis.builder.CustomStringTypeHandler"/>
</typeHandlers>

<objectFactory type="org.apache.ibatis.builder.ExampleObjectFactory">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--

Copyright 2009-2016 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>

<properties url="file:./src/test/java/org/apache/ibatis/builder/jdbc.properties">
<property name="prop1" value="bbbb"/>
</properties>

</configuration>
Loading