Skip to content

Commit 56469b5

Browse files
committed
added stand alone relation tests
1 parent 1716e22 commit 56469b5

6 files changed

Lines changed: 383 additions & 2 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public abstract class AbstractRelationTest extends AbstractObjectBoxTest {
1717

1818
@Override
1919
protected BoxStore createBoxStore() {
20-
return MyObjectBox.builder().baseDirectory(boxStoreDir).build();
20+
return MyObjectBox.builder().baseDirectory(boxStoreDir).debugTransactions().build();
2121
}
2222

2323
@After

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class Customer implements Serializable {
2626
@Relation(idProperty = "customerId")
2727
List<Order> orders = new ToMany<>(this, Customer_.orders);
2828

29+
ToMany<Order> ordersStandalone = new ToMany<>(this, Customer_.ordersStandalone);
30+
2931
/** Used to resolve relations */
3032
@Internal
3133
@Generated(1307364262)
@@ -61,4 +63,7 @@ public List<Order> getOrders() {
6163
return orders;
6264
}
6365

66+
public ToMany<Order> getOrdersStandalone() {
67+
return ordersStandalone;
68+
}
6469
}

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.objectbox.relation;
22

33

4+
import java.util.List;
5+
46
import io.objectbox.BoxStore;
57
import io.objectbox.Cursor;
68
import io.objectbox.EntityInfo;
@@ -59,9 +61,28 @@ public final long put(Customer entity) {
5961
if (entity.orders instanceof ToMany) {
6062
ToMany<Order> toMany = (ToMany<Order>) entity.orders;
6163
if (toMany.internalCheckApplyToDbRequired()) {
62-
toMany.internalApplyToDb(this, getRelationTargetCursor(Order.class));
64+
Cursor<Order> targetCursor = getRelationTargetCursor(Order.class);
65+
try {
66+
toMany.internalApplyToDb(this, targetCursor);
67+
} finally {
68+
targetCursor.close();
69+
}
70+
}
71+
}
72+
73+
List<Order> ordersStandalone = entity.getOrdersStandalone();
74+
if (ordersStandalone instanceof ToMany) {
75+
ToMany<Order> toMany = (ToMany<Order>) ordersStandalone;
76+
if (toMany.internalCheckApplyToDbRequired()) {
77+
Cursor<Order> targetCursor = getRelationTargetCursor(Order.class);
78+
try {
79+
toMany.internalApplyToDb(this, targetCursor);
80+
} finally {
81+
targetCursor.close();
82+
}
6383
}
6484
}
85+
6586
return __assignedId;
6687
}
6788

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,7 @@ public ToOne<Customer> getToOne(Order order) {
100100
}
101101
});
102102

103+
static final RelationInfo<Order> ordersStandalone =
104+
new RelationInfo<>(Customer_.__INSTANCE, Order_.__INSTANCE, 1);
105+
103106
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ private static byte[] getModel() {
2828
ModelBuilder modelBuilder = new ModelBuilder();
2929
modelBuilder.lastEntityId(4, 5318696586219463633L);
3030
modelBuilder.lastIndexId(2, 8919874872236271392L);
31+
modelBuilder.lastRelationId(1, 8943758920347589435L);
3132

3233
EntityBuilder entityBuilder;
3334

@@ -37,6 +38,7 @@ private static byte[] getModel() {
3738
.flags(PropertyFlags.ID | PropertyFlags.NOT_NULL | PropertyFlags.ID_SELF_ASSIGNABLE);
3839
entityBuilder.property("name", PropertyType.String).id(2, 7412962174183812632L)
3940
.flags(PropertyFlags.INDEXED).indexId(1, 5782921847050580892L);
41+
entityBuilder.relation("ordersStandalone", 1, 8943758920347589435L, 3, 6367118380491771428L);
4042
entityBuilder.entityDone();
4143

4244

0 commit comments

Comments
 (0)