GeezerVison is showing github.com — prep standalone relation modifications · bobbisinaga/objectbox-java@96e3f43
File treeExpand file treeCollapse file tree Open diff view settings objectbox-java/src/main/java/io/objectbox
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: objectbox-java/src/main/java/io/objectbox/Cursor.java +22Lines changed: 22 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -91,6 +91,12 @@ protected static native long collect004000(long cursor, long keyIfComplete, int | 91 | 91 |
| 92 | 92 | static native List nativeGetBacklinkEntities(long cursor, int entityId, int propertyId, long key); | 93 | 93 |
| | 94 | + static native List nativeGetRelationEntities(long cursor, int relationId, long key); | | 95 | + | | 96 | + static native void nativeModifyRelations(long cursor, int relationId, long key, long[] targetKeys, boolean remove); | | 97 | + | | 98 | + static native void nativeModifyRelationsSingle(long cursor, int relationId, long key, long targetKey, boolean remove); | | 99 | + | 94 | 100 | static native void nativeSetBoxStoreForEntities(long cursor, Object boxStore); | 95 | 101 |
| 96 | 102 | protected Transaction tx; | @@ -251,6 +257,7 @@ long internalHandle() { | 251 | 257 | return cursor; | 252 | 258 | } | 253 | 259 |
| | 260 | + @Internal | 254 | 261 | List<T> getBacklinkEntities(int entityId, Property relationIdProperty, long key) { | 255 | 262 | try { | 256 | 263 | return nativeGetBacklinkEntities(cursor, entityId, relationIdProperty.getId(), key); | @@ -260,6 +267,21 @@ List<T> getBacklinkEntities(int entityId, Property relationIdProperty, long key) | 260 | 267 | } | 261 | 268 | } | 262 | 269 |
| | 270 | + @Internal | | 271 | + public List<T> getRelationEntities(int relationId, long key) { | | 272 | + return nativeGetRelationEntities(cursor, relationId, key); | | 273 | + } | | 274 | + | | 275 | + @Internal | | 276 | + public void modifyRelations(int relationId, long key, long[] targetKeys, boolean remove) { | | 277 | + nativeModifyRelations(cursor, relationId, key, targetKeys, remove); | | 278 | + } | | 279 | + | | 280 | + @Internal | | 281 | + public void modifyRelationsSingle(int relationId, long key, long targetKey, boolean remove) { | | 282 | + nativeModifyRelationsSingle(cursor, relationId, key, targetKey, remove); | | 283 | + } | | 284 | + | 263 | 285 | @Override | 264 | 286 | public String toString() { | 265 | 287 | return "Cursor " + Long.toString(cursor, 16) + (isClosed() ? "(closed)" : ""); | |
Collapse file Copy file name to clipboardExpand all lines: objectbox-java/src/main/java/io/objectbox/relation/ToMany.java +16-19Lines changed: 16 additions & 19 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -583,29 +583,26 @@ public void internalApplyToDb(Cursor sourceCursor, Cursor<TARGET> targetCursor) | 583 | 583 | throw new IllegalStateException("Source entity has no ID (should have been put before)"); | 584 | 584 | } | 585 | 585 |
| 586 | | - if (removedStandalone != null) { | 587 | | - for (TARGET target : removedStandalone) { | 588 | | - long id = targetIdGetter.getId(target); | 589 | | - if (id == 0) { | 590 | | - // Paranoia | 591 | | - throw new IllegalStateException("Target entity has no ID (should have been put before)"); | 592 | | - } | 593 | | -// TODO | 594 | | - } | 595 | | - } | 596 | | - if (addedStandalone != null) { | 597 | | - for (TARGET target : addedStandalone) { | 598 | | - long id = targetIdGetter.getId(target); | 599 | | - if (id == 0) { | 600 | | - // Paranoia | 601 | | - throw new IllegalStateException("Target entity has no ID (should have been put before)"); | 602 | | - } | | 586 | + checkModifyStandaloneRelation(sourceCursor, entityId, removedStandalone, targetIdGetter, true); | | 587 | + checkModifyStandaloneRelation(sourceCursor, entityId, addedStandalone, targetIdGetter, false); | | 588 | + } | | 589 | + } | 603 | 590 |
| 604 | | -// TODO | | 591 | + private void checkModifyStandaloneRelation(Cursor cursor, long sourceEntityId, TARGET[] targets, | | 592 | + IdGetter<TARGET> targetIdGetter, boolean remove) { | | 593 | + if (targets != null) { | | 594 | + int length = targets.length; | | 595 | + long[] targetIds = new long[length]; | | 596 | + for (int i = 0; i < length; i++) { | | 597 | + long targetId = targetIdGetter.getId(targets[i]); | | 598 | + if (targetId == 0) { | | 599 | + // Paranoia | | 600 | + throw new IllegalStateException("Target entity has no ID (should have been put before)"); | 605 | 601 | } | | 602 | + targetIds[i] = targetId; | 606 | 603 | } | | 604 | + cursor.modifyRelations(relationInfo.relationId, sourceEntityId, targetIds, remove); | 607 | 605 | } | 608 | | - | 609 | 606 | } | 610 | 607 |
| 611 | 608 | /** For tests */ | |
|