Skip to content

Commit 12f0353

Browse files
committed
Test Case for OGNL Static Method Calls in mappers
1 parent 0ff64c8 commit 12f0353

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

src/test/java/org/apache/ibatis/submitted/dynsql/CreateDB.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ insert into ibtest.names (id, description) values(3, 'Pebbles');
2727
insert into ibtest.names (id, description) values(4, 'Barney');
2828
insert into ibtest.names (id, description) values(5, 'Betty');
2929
insert into ibtest.names (id, description) values(6, 'Bamm Bamm');
30+
insert into ibtest.names (id, description) values(7, 'Rock ''n Roll');
3031

3132
create table ibtest.numerics (
3233
id int,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2013 MyBatis.org.
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.dynsql;
17+
18+
public class CustomUtil {
19+
public static String esc(final String s) {
20+
return s.replace("'", "''");
21+
}
22+
}

src/test/java/org/apache/ibatis/submitted/dynsql/DynSql.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,13 @@
6262
WHERE description LIKE #{pattern}
6363
ORDER BY id
6464
</select>
65+
66+
<select id="ognlStaticMethodCall" resultType="map" parameterType="string">
67+
<bind name="escapedLiteral" value="@org.apache.ibatis.submitted.dynsql.CustomUtil@esc(_parameter)" />
68+
SELECT *
69+
FROM ibtest.names
70+
WHERE description LIKE '${escapedLiteral}'
71+
ORDER BY id
72+
</select>
73+
6574
</mapper>

src/test/java/org/apache/ibatis/submitted/dynsql/DynSqlTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,18 @@ public void testNumerics() {
144144
sqlSession.close();
145145
}
146146
}
147+
148+
@Test
149+
public void testOgnlStaticMethodCall() {
150+
SqlSession sqlSession = sqlSessionFactory.openSession();
151+
try {
152+
List<Map<String, Object>> answer = sqlSession.selectList("org.apache.ibatis.submitted.dynsql.ognlStaticMethodCall", "Rock 'n Roll");
153+
assertTrue(answer.size() == 1);
154+
assertEquals(new Integer(7), answer.get(0).get("ID"));
155+
156+
} finally {
157+
sqlSession.close();
158+
}
159+
}
160+
147161
}

0 commit comments

Comments
 (0)