Skip to content

Commit 80e939a

Browse files
committed
Convert to record
1 parent 57ebe03 commit 80e939a

File tree

5 files changed

+53
-41
lines changed

5 files changed

+53
-41
lines changed

src/test/java/examples/joins/JoinMapper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import java.util.List;
1919

20-
import org.apache.ibatis.annotations.Result;
20+
import org.apache.ibatis.annotations.Arg;
2121
import org.apache.ibatis.annotations.ResultMap;
2222
import org.apache.ibatis.annotations.SelectProvider;
2323
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
@@ -29,8 +29,8 @@ public interface JoinMapper {
2929
List<OrderMaster> selectMany(SelectStatementProvider selectStatement);
3030

3131
@SelectProvider(type=SqlProviderAdapter.class, method="select")
32-
@Result(column="user_id", property="userId")
33-
@Result(column="user_name", property="userName")
34-
@Result(column="parent_id", property="parentId")
32+
@Arg(column="user_id", javaType = Integer.class)
33+
@Arg(column="user_name", javaType = String.class)
34+
@Arg(column="parent_id", javaType = Integer.class)
3535
List<User> selectUsers(SelectStatementProvider selectStatement);
3636
}

src/test/java/examples/joins/JoinMapperTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -945,9 +945,9 @@ void testSelf() {
945945

946946
assertThat(rows).hasSize(1);
947947
User row = rows.get(0);
948-
assertThat(row.getUserId()).isEqualTo(2);
949-
assertThat(row.getUserName()).isEqualTo("Barney");
950-
assertThat(row.getParentId()).isNull();
948+
assertThat(row.userId()).isEqualTo(2);
949+
assertThat(row.userName()).isEqualTo("Barney");
950+
assertThat(row.parentId()).isNull();
951951
}
952952
}
953953

@@ -985,9 +985,9 @@ void testSelfWithNewAlias() {
985985

986986
assertThat(rows).hasSize(1);
987987
User row = rows.get(0);
988-
assertThat(row.getUserId()).isEqualTo(2);
989-
assertThat(row.getUserName()).isEqualTo("Barney");
990-
assertThat(row.getParentId()).isNull();
988+
assertThat(row.userId()).isEqualTo(2);
989+
assertThat(row.userName()).isEqualTo("Barney");
990+
assertThat(row.parentId()).isNull();
991991
}
992992
}
993993

@@ -1016,9 +1016,9 @@ void testSelfWithNewAliasAndOverride() {
10161016

10171017
assertThat(rows).hasSize(1);
10181018
User row = rows.get(0);
1019-
assertThat(row.getUserId()).isEqualTo(2);
1020-
assertThat(row.getUserName()).isEqualTo("Barney");
1021-
assertThat(row.getParentId()).isNull();
1019+
assertThat(row.userId()).isEqualTo(2);
1020+
assertThat(row.userName()).isEqualTo("Barney");
1021+
assertThat(row.parentId()).isNull();
10221022
}
10231023
}
10241024

src/test/java/examples/joins/User.java

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,6 @@
1515
*/
1616
package examples.joins;
1717

18-
public class User {
19-
private Integer userId;
20-
private String userName;
21-
private Integer parentId;
18+
import org.jspecify.annotations.Nullable;
2219

23-
public Integer getUserId() {
24-
return userId;
25-
}
26-
27-
public void setUserId(Integer userId) {
28-
this.userId = userId;
29-
}
30-
31-
public String getUserName() {
32-
return userName;
33-
}
34-
35-
public void setUserName(String userName) {
36-
this.userName = userName;
37-
}
38-
39-
public Integer getParentId() {
40-
return parentId;
41-
}
42-
43-
public void setParentId(Integer parentId) {
44-
this.parentId = parentId;
45-
}
46-
}
20+
public record User (Integer userId, String userName, @Nullable Integer parentId) {}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2016-2025 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+
@NullMarked
17+
package examples.joins;
18+
19+
import org.jspecify.annotations.NullMarked;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2016-2025 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+
@NullMarked
17+
package examples.type_conversion;
18+
19+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)