Skip to content

Commit e413637

Browse files
committed
Hide IdOnlyAggregateReference class.
IdOnlyAggregateReference is an implementation detail of AggregateReference. Closes #2106
1 parent 91352c0 commit e413637

File tree

3 files changed

+49
-53
lines changed

3 files changed

+49
-53
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/mapping/AggregateReference.java

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
*/
1616
package org.springframework.data.jdbc.core.mapping;
1717

18-
import java.util.Objects;
19-
20-
import org.springframework.lang.Nullable;
21-
import org.springframework.util.Assert;
22-
2318
/**
2419
* A reference to the aggregate root of a different aggregate.
2520
*
@@ -49,47 +44,4 @@ static <T, ID> AggregateReference<T, ID> to(ID id) {
4944
*/
5045
ID getId();
5146

52-
/**
53-
* An {@link AggregateReference} that only holds the id of the referenced aggregate root. Note that there is no check
54-
* that a matching aggregate for this id actually exists.
55-
*
56-
* @param <T>
57-
* @param <ID>
58-
*/
59-
class IdOnlyAggregateReference<T, ID> implements AggregateReference<T, ID> {
60-
61-
private final ID id;
62-
63-
public IdOnlyAggregateReference(ID id) {
64-
65-
Assert.notNull(id, "Id must not be null");
66-
this.id = id;
67-
}
68-
69-
@Override
70-
public ID getId() {
71-
return id;
72-
}
73-
74-
@Override
75-
public boolean equals(@Nullable Object o) {
76-
77-
if (this == o)
78-
return true;
79-
if (o == null || getClass() != o.getClass())
80-
return false;
81-
IdOnlyAggregateReference<?, ?> that = (IdOnlyAggregateReference<?, ?>) o;
82-
return id.equals(that.id);
83-
}
84-
85-
@Override
86-
public int hashCode() {
87-
return Objects.hash(id);
88-
}
89-
90-
@Override
91-
public String toString() {
92-
return "IdOnlyAggregateReference{" + "id=" + id + '}';
93-
}
94-
}
9547
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 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+
package org.springframework.data.jdbc.core.mapping;
17+
18+
import org.springframework.util.Assert;
19+
20+
/**
21+
* An {@link AggregateReference} that only holds the id of the referenced aggregate root. Note that there is no check
22+
* that a matching aggregate for this id actually exists.
23+
*
24+
* @author Jens Schauder
25+
* @author Mark Paluch
26+
* @since 4.0
27+
* @param <T>
28+
* @param <ID>
29+
*/
30+
record IdOnlyAggregateReference<T, ID>(ID id) implements AggregateReference<T, ID> {
31+
32+
IdOnlyAggregateReference {
33+
Assert.notNull(id, "Id must not be null");
34+
}
35+
36+
@Override
37+
public ID getId() {
38+
return id();
39+
}
40+
41+
@Override
42+
public String toString() {
43+
return "IdOnlyAggregateReference{" + "id=" + id + '}';
44+
}
45+
}

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/mapping/IdOnlyAggregateReferenceTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
import static org.assertj.core.api.Assertions.*;
44

55
import org.junit.jupiter.api.Test;
6-
import org.springframework.data.jdbc.core.mapping.AggregateReference.IdOnlyAggregateReference;
76

87
/**
98
* Unit tests for the {@link IdOnlyAggregateReference}.
109
*
1110
* @author Myeonghyeon Lee
1211
*/
13-
public class IdOnlyAggregateReferenceTest {
12+
class IdOnlyAggregateReferenceTest {
1413

1514
@Test // DATAJDBC-427
16-
public void equals() {
15+
void equals() {
1716

1817
AggregateReference<DummyEntity, String> reference1 = AggregateReference.to("1");
1918
AggregateReference<DummyEntity, String> reference2 = AggregateReference.to("1");
@@ -23,7 +22,7 @@ public void equals() {
2322
}
2423

2524
@Test // DATAJDBC-427
26-
public void equalsFalse() {
25+
void equalsFalse() {
2726

2827
AggregateReference<DummyEntity, String> reference1 = AggregateReference.to("1");
2928
AggregateReference<DummyEntity, String> reference2 = AggregateReference.to("2");
@@ -33,7 +32,7 @@ public void equalsFalse() {
3332
}
3433

3534
@Test // DATAJDBC-427
36-
public void hashCodeTest() {
35+
void hashCodeTest() {
3736

3837
AggregateReference<DummyEntity, String> reference1 = AggregateReference.to("1");
3938
AggregateReference<DummyEntity, String> reference2 = AggregateReference.to("1");

0 commit comments

Comments
 (0)