Skip to content

Commit e269526

Browse files
committed
Test for #135. Wast able to reproduce.
1 parent cdf7400 commit e269526

File tree

7 files changed

+261
-0
lines changed

7 files changed

+261
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--
2+
-- Copyright 2009-2012 the original author or authors.
3+
--
4+
-- Licensed under the Apache License, Version 2.0 (the "License");
5+
-- you may not use this file except in compliance with the License.
6+
-- You may obtain a copy of the License at
7+
--
8+
-- http://www.apache.org/licenses/LICENSE-2.0
9+
--
10+
-- Unless required by applicable law or agreed to in writing, software
11+
-- distributed under the License is distributed on an "AS IS" BASIS,
12+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
-- See the License for the specific language governing permissions and
14+
-- limitations under the License.
15+
--
16+
17+
drop table users if exists;
18+
19+
create table users (
20+
id int,
21+
name varchar(20)
22+
);
23+
24+
insert into users (id, name) values(1, 'User1');
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.apache.ibatis.submitted.maptypehandler;
2+
3+
import java.sql.CallableStatement;
4+
import java.sql.PreparedStatement;
5+
import java.sql.ResultSet;
6+
import java.sql.SQLException;
7+
import java.util.Map;
8+
9+
import org.apache.ibatis.type.JdbcType;
10+
import org.apache.ibatis.type.MappedTypes;
11+
import org.apache.ibatis.type.TypeHandler;
12+
13+
@MappedTypes(Map.class)
14+
public class LabelsTypeHandler implements TypeHandler<Map<String, Object>> {
15+
16+
@Override
17+
public void setParameter(PreparedStatement ps, int i, Map<String, Object> parameter, JdbcType jdbcType) throws SQLException {
18+
// TODO Auto-generated method stub
19+
20+
}
21+
22+
@Override
23+
public Map<String, Object> getResult(ResultSet rs, String columnName) throws SQLException {
24+
// TODO Auto-generated method stub
25+
return null;
26+
}
27+
28+
@Override
29+
public Map<String, Object> getResult(ResultSet rs, int columnIndex) throws SQLException {
30+
// TODO Auto-generated method stub
31+
return null;
32+
}
33+
34+
@Override
35+
public Map<String, Object> getResult(CallableStatement cs, int columnIndex) throws SQLException {
36+
// TODO Auto-generated method stub
37+
return null;
38+
}
39+
40+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2009-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.apache.ibatis.submitted.maptypehandler;
17+
18+
import java.io.Reader;
19+
import java.sql.Connection;
20+
21+
import org.apache.ibatis.io.Resources;
22+
import org.apache.ibatis.jdbc.ScriptRunner;
23+
import org.apache.ibatis.session.SqlSession;
24+
import org.apache.ibatis.session.SqlSessionFactory;
25+
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
26+
import org.junit.Assert;
27+
import org.junit.BeforeClass;
28+
import org.junit.Test;
29+
30+
public class MapTypeHandlerTest {
31+
32+
private static SqlSessionFactory sqlSessionFactory;
33+
34+
@BeforeClass
35+
public static void setUp() throws Exception {
36+
// create an SqlSessionFactory
37+
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/maptypehandler/mybatis-config.xml");
38+
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
39+
reader.close();
40+
41+
// populate in-memory database
42+
SqlSession session = sqlSessionFactory.openSession();
43+
Connection conn = session.getConnection();
44+
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/maptypehandler/CreateDB.sql");
45+
ScriptRunner runner = new ScriptRunner(conn);
46+
runner.setLogWriter(null);
47+
runner.runScript(reader);
48+
reader.close();
49+
session.close();
50+
}
51+
52+
@Test
53+
public void shouldGetAUser() {
54+
SqlSession sqlSession = sqlSessionFactory.openSession();
55+
try {
56+
Mapper mapper = sqlSession.getMapper(Mapper.class);
57+
User user = mapper.getUser(1, "User1");
58+
Assert.assertEquals("User1", user.getName());
59+
} finally {
60+
sqlSession.close();
61+
}
62+
}
63+
64+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2014 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.apache.ibatis.submitted.maptypehandler;
17+
18+
import org.apache.ibatis.annotations.Param;
19+
20+
public interface Mapper {
21+
22+
User getUser(@Param("id") Integer id, @Param("name") String name);
23+
24+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2009-2013 the original author or authors.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<!DOCTYPE mapper
18+
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
19+
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
20+
21+
<mapper namespace="org.apache.ibatis.submitted.maptypehandler.Mapper">
22+
23+
<select id="getUser" resultType="org.apache.ibatis.submitted.maptypehandler.User">
24+
select * from users where id = #{id} and name = #{name}
25+
</select>
26+
27+
</mapper>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2009-2012 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.apache.ibatis.submitted.maptypehandler;
17+
18+
public class User {
19+
20+
private Integer id;
21+
private String name;
22+
23+
public Integer getId() {
24+
return id;
25+
}
26+
27+
public void setId(Integer id) {
28+
this.id = id;
29+
}
30+
31+
public String getName() {
32+
return name;
33+
}
34+
35+
public void setName(String name) {
36+
this.name = name;
37+
}
38+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
Copyright 2009-2013 the original author or authors.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<!DOCTYPE configuration
18+
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
19+
"http://mybatis.org/dtd/mybatis-3-config.dtd">
20+
21+
<configuration>
22+
23+
<typeHandlers>
24+
<typeHandler handler="org.apache.ibatis.submitted.maptypehandler.LabelsTypeHandler" />
25+
</typeHandlers>
26+
27+
<environments default="development">
28+
<environment id="development">
29+
<transactionManager type="JDBC">
30+
<property name="" value="" />
31+
</transactionManager>
32+
<dataSource type="UNPOOLED">
33+
<property name="driver" value="org.hsqldb.jdbcDriver" />
34+
<property name="url" value="jdbc:hsqldb:mem:maptypehandler" />
35+
<property name="username" value="sa" />
36+
</dataSource>
37+
</environment>
38+
</environments>
39+
40+
<mappers>
41+
<mapper class="org.apache.ibatis.submitted.maptypehandler.Mapper" />
42+
</mappers>
43+
44+
</configuration>

0 commit comments

Comments
 (0)