Skip to content

Commit eabbbd8

Browse files
committed
Fix for issue
1 parent d47a200 commit eabbbd8

File tree

6 files changed

+164
-0
lines changed

6 files changed

+164
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
create table person (
2+
id int,
3+
firstName varchar(100),
4+
lastName varchar(100),
5+
order_type varchar(100)
6+
);
7+
8+
INSERT INTO person (id, firstName, lastName, order_type)
9+
VALUES (1, 'John', 'Smith', 'fast');
10+
11+
INSERT INTO person (id, firstName, lastName, order_type)
12+
VALUES (2, 'Christian', 'Poitras', 'fast');
13+
14+
INSERT INTO person (id, firstName, lastName, order_type)
15+
VALUES (3, 'Clinton', 'Begin', 'slow');
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package org.apache.ibatis.submitted.order_prefix_removed;
2+
3+
import org.apache.ibatis.annotations.Param;
4+
import org.apache.ibatis.io.Resources;
5+
import org.apache.ibatis.jdbc.ScriptRunner;
6+
import org.apache.ibatis.session.ExecutorType;
7+
import org.apache.ibatis.session.SqlSession;
8+
import org.apache.ibatis.session.SqlSessionFactory;
9+
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
10+
import org.junit.BeforeClass;
11+
import org.junit.Test;
12+
13+
import java.io.Reader;
14+
import java.sql.Connection;
15+
import java.sql.DriverManager;
16+
import java.util.HashMap;
17+
import java.util.List;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNotNull;
21+
22+
public class OrderPrefixRemoved {
23+
24+
private static SqlSessionFactory sqlSessionFactory;
25+
26+
@BeforeClass
27+
public static void initDatabase() throws Exception {
28+
Connection conn = null;
29+
30+
try {
31+
Class.forName("org.hsqldb.jdbcDriver");
32+
conn = DriverManager.getConnection("jdbc:hsqldb:mem:order_prefix_removed", "sa", "");
33+
34+
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/order_prefix_removed/CreateDB.sql");
35+
36+
ScriptRunner runner = new ScriptRunner(conn);
37+
runner.setLogWriter(null);
38+
runner.setErrorLogWriter(null);
39+
runner.runScript(reader);
40+
conn.commit();
41+
reader.close();
42+
43+
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/order_prefix_removed/ibatisConfig.xml");
44+
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
45+
reader.close();
46+
} finally {
47+
if (conn != null) {
48+
conn.close();
49+
}
50+
}
51+
}
52+
53+
@Test
54+
public void testOrderPrefixNotRemoved() {
55+
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.SIMPLE);
56+
try {
57+
PersonMapper personMapper = sqlSession.getMapper(PersonMapper.class);
58+
59+
Person person = personMapper.select(new String("slow"));
60+
61+
assertNotNull(person);
62+
63+
sqlSession.commit();
64+
} finally {
65+
sqlSession.close();
66+
}
67+
}
68+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.apache.ibatis.submitted.order_prefix_removed;
2+
3+
import java.io.Serializable;
4+
5+
public class Person implements Serializable {
6+
private Integer id;
7+
private String firstName;
8+
private String lastName;
9+
public String getFirstName() {
10+
return firstName;
11+
}
12+
public void setFirstName(String firstName) {
13+
this.firstName = firstName;
14+
}
15+
public String getLastName() {
16+
return lastName;
17+
}
18+
public void setLastName(String lastName) {
19+
this.lastName = lastName;
20+
}
21+
public Integer getId() {
22+
return id;
23+
}
24+
public void setId(Integer id) {
25+
this.id = id;
26+
}
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<!DOCTYPE mapper
3+
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
4+
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
5+
6+
<mapper namespace="org.apache.ibatis.submitted.order_prefix_removed.PersonMapper">
7+
8+
<resultMap id="personMap" type="Person">
9+
<id property="id" column="id"/>
10+
<result property="firstName" column="firstName"/>
11+
<result property="lastName" column="lastName"/>
12+
</resultMap>
13+
14+
15+
<select id="select" resultMap="personMap">
16+
SELECT id, firstName, lastName
17+
FROM person
18+
<where>
19+
<if test="true">
20+
ORDER_TYPE = #{value}
21+
</if>
22+
</where>
23+
</select>
24+
</mapper>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.apache.ibatis.submitted.order_prefix_removed;
2+
3+
public interface PersonMapper {
4+
public Person select(String orderType);
5+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<!DOCTYPE configuration
3+
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
4+
"http://mybatis.org/dtd/mybatis-3-config.dtd">
5+
6+
<configuration>
7+
<typeAliases>
8+
<typeAlias alias="Person" type="org.apache.ibatis.submitted.order_prefix_removed.Person"/>
9+
</typeAliases>
10+
11+
<environments default="test">
12+
<environment id="test">
13+
<transactionManager type="JDBC"></transactionManager>
14+
<dataSource type="UNPOOLED">
15+
<property name="driver" value="org.hsqldb.jdbcDriver"/>
16+
<property name="url" value="jdbc:hsqldb:mem:order_prefix_removed"/>
17+
<property name="username" value="sa"/>
18+
</dataSource>
19+
</environment>
20+
</environments>
21+
22+
<mappers>
23+
<mapper resource="org/apache/ibatis/submitted/order_prefix_removed/Person.xml"/>
24+
</mappers>
25+
</configuration>

0 commit comments

Comments
 (0)