|
1 | 1 | /**
|
2 |
| - * Copyright 2009-2020 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. |
| 2 | + * Copyright 2009-2020 the original author or authors. |
| 3 | + * <p> |
| 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 | + * <p> |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * <p> |
| 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 | 15 | */
|
16 | 16 | package org.apache.ibatis.binding;
|
17 | 17 |
|
18 |
| -import static org.assertj.core.api.Assertions.assertThat; |
19 |
| - |
20 |
| -import java.util.HashMap; |
21 |
| - |
22 |
| -import javax.sql.DataSource; |
23 |
| - |
24 | 18 | import org.apache.ibatis.BaseDataTest;
|
25 | 19 | import org.apache.ibatis.annotations.Insert;
|
26 | 20 | import org.apache.ibatis.annotations.Param;
|
27 | 21 | import org.apache.ibatis.annotations.Select;
|
28 | 22 | import org.apache.ibatis.mapping.Environment;
|
| 23 | +import org.apache.ibatis.reflection.property.PropertyTokenizer; |
29 | 24 | import org.apache.ibatis.session.Configuration;
|
30 | 25 | import org.apache.ibatis.session.SqlSession;
|
31 | 26 | import org.apache.ibatis.session.SqlSessionFactory;
|
|
35 | 30 | import org.junit.jupiter.api.BeforeAll;
|
36 | 31 | import org.junit.jupiter.api.Test;
|
37 | 32 |
|
| 33 | +import javax.sql.DataSource; |
| 34 | +import java.util.ArrayList; |
| 35 | +import java.util.HashMap; |
| 36 | +import java.util.List; |
| 37 | + |
| 38 | +import static org.assertj.core.api.Assertions.assertThat; |
| 39 | + |
38 | 40 | class MapperMethodParamTest {
|
39 | 41 |
|
40 | 42 | private static SqlSessionFactory sqlSessionFactory;
|
@@ -71,13 +73,38 @@ void parameterNameIsSizeUsingHashMap() {
|
71 | 73 | }
|
72 | 74 | }
|
73 | 75 |
|
| 76 | + /** |
| 77 | + * Using nested lists as parameters |
| 78 | + * <br/> |
| 79 | + * Test whether {@link PropertyTokenizer#PropertyTokenizer(java.lang.String)} be parsed correctly |
| 80 | + */ |
| 81 | + @Test |
| 82 | + void parameterNameIsSizeUsingNestedList() { |
| 83 | + try (SqlSession session = sqlSessionFactory.openSession()) { |
| 84 | + // Constructed parameters |
| 85 | + List<List<List<Long>>> listOuter = new ArrayList<>(); |
| 86 | + List<List<Long>> listMiddle = new ArrayList<>(); |
| 87 | + List<Long> listInner = new ArrayList<>(); |
| 88 | + listOuter.add(listMiddle); |
| 89 | + listMiddle.add(listInner); |
| 90 | + listInner.add(Long.MAX_VALUE); |
| 91 | + |
| 92 | + Mapper mapper = session.getMapper(Mapper.class); |
| 93 | + mapper.insertSizeUsingNestedList("foo", listOuter); |
| 94 | + assertThat(mapper.selectSize("foo")).isEqualTo(Long.MAX_VALUE); |
| 95 | + } |
| 96 | + } |
| 97 | + |
74 | 98 | interface Mapper {
|
75 | 99 | @Insert("insert into param_test (id, size) values(#{id}, #{size})")
|
76 | 100 | void insert(@Param("id") String id, @Param("size") long size);
|
77 | 101 |
|
78 | 102 | @Insert("insert into param_test (id, size) values(#{id}, #{size})")
|
79 | 103 | void insertUsingHashMap(HashMap<String, Object> params);
|
80 | 104 |
|
| 105 | + @Insert("insert into param_test (id, size) values(#{id}, #{list[0][0][0]})") |
| 106 | + long insertSizeUsingNestedList(@Param("id") String id, @Param("list") List<List<List<Long>>> list); |
| 107 | + |
81 | 108 | @Select("select size from param_test where id = #{id}")
|
82 | 109 | long selectSize(@Param("id") String id);
|
83 | 110 | }
|
|
0 commit comments