View Javadoc
1   /*
2    *    Copyright 2009-2023 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    *       https://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.empty_row;
17  
18  import java.util.Map;
19  
20  import org.apache.ibatis.annotations.ResultMap;
21  import org.apache.ibatis.annotations.Select;
22  
23  public interface Mapper {
24  
25    @Select("select null from (values(0))")
26    String getString();
27  
28    @ResultMap("parentRM")
29    @Select("select col1, col2 from parent where id = #{id}")
30    Parent getBean(Integer id);
31  
32    @Select("select col1, col2 from parent where id = #{id}")
33    Map<String, String> getMap(Integer id);
34  
35    @ResultMap("associationRM")
36    @Select({ "select p.id, c.name child_name from parent p",
37        "left join child c on c.parent_id = p.id where p.id = #{id}" })
38    Parent getAssociation(Integer id);
39  
40    @ResultMap("associationWithNotNullColumnRM")
41    @Select({ "select p.id, c.id child_id, c.name child_name from parent p",
42        "left join child c on c.parent_id = p.id where p.id = #{id}" })
43    Parent getAssociationWithNotNullColumn(Integer id);
44  
45    @ResultMap("nestedAssociationRM")
46    @Select("select 1 id, null child_name, null grandchild_name from (values(0))")
47    Parent getNestedAssociation();
48  
49    @ResultMap("collectionRM")
50    @Select({ "select p.id, c.name child_name from parent p",
51        "left join child c on c.parent_id = p.id where p.id = #{id}" })
52    Parent getCollection(Integer id);
53  
54    @ResultMap("twoCollectionsRM")
55    // @formatter:off
56    @Select({"select p.id, c.name child_name, e.name pet_name from parent p",
57        "left join child c on c.parent_id = p.id",
58        "left join pet e on e.parent_id = p.id", "where p.id = #{id}"})
59    // @formatter:on
60    Parent getTwoCollections(Integer id);
61  
62    @Select("select col1, col2 from parent where id = #{id}")
63    ImmutableParent selectImmutable(Integer id);
64  }