Skip to content

Commit 020a034

Browse files
committed
add SOURCE type param to RelationInfo
1 parent 8f79c77 commit 020a034

File tree

7 files changed

+20
-20
lines changed

7 files changed

+20
-20
lines changed

objectbox-java/src/main/java/io/objectbox/query/QueryBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public QueryBuilder<T> sort(Comparator<T> comparator) {
285285
* @param <TARGET> The target entity. For parent/tree like relations, it can be the same type.
286286
* @return A builder to define query conditions at the target entity side.
287287
*/
288-
public <TARGET> QueryBuilder<TARGET> link(RelationInfo<TARGET> relationInfo) {
288+
public <TARGET> QueryBuilder<TARGET> link(RelationInfo<?, TARGET> relationInfo) {
289289
boolean backlink = relationInfo.isBacklink();
290290
EntityInfo relationOwner = backlink ? relationInfo.targetInfo : relationInfo.sourceInfo;
291291
return link(relationInfo, relationOwner, relationInfo.targetInfo, backlink);
@@ -312,7 +312,7 @@ private <TARGET> QueryBuilder<TARGET> link(RelationInfo relationInfo, EntityInfo
312312
* @param <TARGET> The target entity. For parent/tree like relations, it can be the same type.
313313
* @return A builder to define query conditions at the target entity side.
314314
*/
315-
public <TARGET> QueryBuilder<TARGET> backlink(RelationInfo relationInfo) {
315+
public <TARGET> QueryBuilder<TARGET> backlink(RelationInfo<TARGET, ?> relationInfo) {
316316
if (relationInfo.isBacklink()) {
317317
throw new IllegalArgumentException("Double backlink: The relation is already a backlink, please use a regular link on the original relation instead.");
318318
}

objectbox-java/src/main/java/io/objectbox/relation/RelationInfo.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
*/
3232
@Internal
3333
@Immutable
34-
public class RelationInfo<TARGET> implements Serializable {
34+
public class RelationInfo<SOURCE, TARGET> implements Serializable {
3535
private static final long serialVersionUID = 7412962174183812632L;
3636

37-
public final EntityInfo sourceInfo;
37+
public final EntityInfo<SOURCE> sourceInfo;
3838
public final EntityInfo<TARGET> targetInfo;
3939

4040
/** For relations based on a target ID property (null otherwise). */
@@ -44,24 +44,24 @@ public class RelationInfo<TARGET> implements Serializable {
4444
public final int targetRelationId;
4545

4646
/** Only set for ToOne relations */
47-
public final ToOneGetter toOneGetter;
47+
public final ToOneGetter<TARGET> toOneGetter;
4848

4949
/** Only set for ToMany relations */
50-
public final ToManyGetter toManyGetter;
50+
public final ToManyGetter<TARGET> toManyGetter;
5151

5252
/** For ToMany relations based on ToOne backlinks (null otherwise). */
53-
public final ToOneGetter backlinkToOneGetter;
53+
public final ToOneGetter<SOURCE> backlinkToOneGetter;
5454

5555
/** For ToMany relations based on ToMany backlinks (null otherwise). */
56-
public final ToManyGetter backlinkToManyGetter;
56+
public final ToManyGetter<SOURCE> backlinkToManyGetter;
5757

5858
/** For stand-alone to-many relations (0 otherwise). */
5959
public final int relationId;
6060

6161
/**
6262
* ToOne
6363
*/
64-
public RelationInfo(EntityInfo sourceInfo, EntityInfo<TARGET> targetInfo, Property targetIdProperty,
64+
public RelationInfo(EntityInfo<SOURCE> sourceInfo, EntityInfo<TARGET> targetInfo, Property targetIdProperty,
6565
ToOneGetter toOneGetter) {
6666
this.sourceInfo = sourceInfo;
6767
this.targetInfo = targetInfo;
@@ -77,7 +77,7 @@ public RelationInfo(EntityInfo sourceInfo, EntityInfo<TARGET> targetInfo, Proper
7777
/**
7878
* ToMany as a ToOne backlink
7979
*/
80-
public RelationInfo(EntityInfo sourceInfo, EntityInfo<TARGET> targetInfo, ToManyGetter toManyGetter,
80+
public RelationInfo(EntityInfo<SOURCE> sourceInfo, EntityInfo<TARGET> targetInfo, ToManyGetter toManyGetter,
8181
Property targetIdProperty, ToOneGetter backlinkToOneGetter) {
8282
this.sourceInfo = sourceInfo;
8383
this.targetInfo = targetInfo;
@@ -93,7 +93,7 @@ public RelationInfo(EntityInfo sourceInfo, EntityInfo<TARGET> targetInfo, ToMany
9393
/**
9494
* ToMany as a ToMany backlink
9595
*/
96-
public RelationInfo(EntityInfo sourceInfo, EntityInfo<TARGET> targetInfo, ToManyGetter toManyGetter,
96+
public RelationInfo(EntityInfo<SOURCE> sourceInfo, EntityInfo<TARGET> targetInfo, ToManyGetter toManyGetter,
9797
ToManyGetter backlinkToManyGetter, int targetRelationId) {
9898
this.sourceInfo = sourceInfo;
9999
this.targetInfo = targetInfo;
@@ -109,7 +109,7 @@ public RelationInfo(EntityInfo sourceInfo, EntityInfo<TARGET> targetInfo, ToMany
109109
/**
110110
* Stand-alone ToMany.
111111
*/
112-
public RelationInfo(EntityInfo sourceInfo, EntityInfo<TARGET> targetInfo, ToManyGetter toManyGetter,
112+
public RelationInfo(EntityInfo<SOURCE> sourceInfo, EntityInfo<TARGET> targetInfo, ToManyGetter toManyGetter,
113113
int relationId) {
114114
this.sourceInfo = sourceInfo;
115115
this.targetInfo = targetInfo;

objectbox-java/src/main/java/io/objectbox/relation/ToMany.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class ToMany<TARGET> implements List<TARGET>, Serializable {
6767
private final static Integer ONE = Integer.valueOf(1);
6868

6969
private final Object entity;
70-
private final RelationInfo<TARGET> relationInfo;
70+
private final RelationInfo<Object, TARGET> relationInfo;
7171

7272
private ListFactory listFactory;
7373
private List<TARGET> entities;
@@ -90,15 +90,15 @@ public class ToMany<TARGET> implements List<TARGET>, Serializable {
9090
transient private boolean removeFromTargetBox;
9191
transient private Comparator<TARGET> comparator;
9292

93-
public ToMany(Object sourceEntity, RelationInfo<TARGET> relationInfo) {
93+
public ToMany(Object sourceEntity, RelationInfo<? extends Object, TARGET> relationInfo) {
9494
if (sourceEntity == null) {
9595
throw new IllegalArgumentException("No source entity given (null)");
9696
}
9797
if (relationInfo == null) {
9898
throw new IllegalArgumentException("No relation info given (null)");
9999
}
100100
this.entity = sourceEntity;
101-
this.relationInfo = relationInfo;
101+
this.relationInfo = (RelationInfo<Object, TARGET>) relationInfo;
102102
}
103103

104104
/** Currently only used for non-persisted entities (id == 0). */

tests/objectbox-java-test/src/main/java/io/objectbox/relation/Customer_.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public long getId(Customer object) {
105105
}
106106
}
107107

108-
static final RelationInfo<Order> orders =
108+
static final RelationInfo<Customer, Order> orders =
109109
new RelationInfo<>(Customer_.__INSTANCE, Order_.__INSTANCE, new ToManyGetter<Customer>() {
110110
@Override
111111
public ToMany<Order> getToMany(Customer customer) {
@@ -118,7 +118,7 @@ public ToOne<Customer> getToOne(Order order) {
118118
}
119119
});
120120

121-
static final RelationInfo<Order> ordersStandalone =
121+
static final RelationInfo<Customer, Order> ordersStandalone =
122122
new RelationInfo<>(Customer_.__INSTANCE, Order_.__INSTANCE, new ToManyGetter<Customer>() {
123123
@Override
124124
public ToMany<Order> getToMany(Customer customer) {

tests/objectbox-java-test/src/main/java/io/objectbox/relation/Order_.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public long getId(Order object) {
114114
}
115115
}
116116

117-
static final RelationInfo<Customer> customer = new RelationInfo<>(Order_.__INSTANCE, Customer_.__INSTANCE, customerId, new ToOneGetter<Order>() {
117+
static final RelationInfo<Order, Customer> customer = new RelationInfo<>(Order_.__INSTANCE, Customer_.__INSTANCE, customerId, new ToOneGetter<Order>() {
118118
@Override
119119
public ToOne getToOne(Order object) {
120120
return object.customer__toOne;

tests/objectbox-java-test/src/test/java/io/objectbox/relation/ToManyStandaloneTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void testPutAndGetPrimitives() {
4242
Cursor<Customer> cursorSource = InternalAccess.getWriter(customerBox);
4343
long[] orderIds = {order1.getId(), order2.getId()};
4444
cursorSource.modifyRelations(1, customerId, orderIds, false);
45-
RelationInfo<Order> info = Customer_.ordersStandalone;
45+
RelationInfo<Customer, Order> info = Customer_.ordersStandalone;
4646
int sourceEntityId = info.sourceInfo.getEntityId();
4747
Cursor<Order> targetCursor = cursorSource.getTx().createCursor(Order.class);
4848
List<Order> related = targetCursor.getRelationEntities(sourceEntityId, info.relationId, customerId, false);

tests/objectbox-java-test/src/test/java/io/objectbox/relation/ToOneTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void testTargetId_withTargetIdProperty() {
4545
assertEquals(1977, entity.getCustomerId());
4646
}
4747

48-
private RelationInfo<Customer> getRelationInfo(Property targetIdProperty) {
48+
private RelationInfo<Order, Customer> getRelationInfo(Property targetIdProperty) {
4949
return new RelationInfo<>(new Order_(), new Customer_(), targetIdProperty, null);
5050
}
5151

0 commit comments

Comments
 (0)