GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — prep standalone relation modifications · bobbisinaga/objectbox-java@96e3f43

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • objectbox-java/src/main/java/io/objectbox
    • Cursor.java
    • relation
      • ToMany.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎objectbox-java/src/main/java/io/objectbox/Cursor.java‎

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 numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ protected static native long collect004000(long cursor, long keyIfComplete, int
9191

9292
static native List nativeGetBacklinkEntities(long cursor, int entityId, int propertyId, long key);
9393

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+
94100
static native void nativeSetBoxStoreForEntities(long cursor, Object boxStore);
95101

96102
protected Transaction tx;
@@ -251,6 +257,7 @@ long internalHandle() {
251257
return cursor;
252258
}
253259

260+
@Internal
254261
List<T> getBacklinkEntities(int entityId, Property relationIdProperty, long key) {
255262
try {
256263
return nativeGetBacklinkEntities(cursor, entityId, relationIdProperty.getId(), key);
@@ -260,6 +267,21 @@ List<T> getBacklinkEntities(int entityId, Property relationIdProperty, long key)
260267
}
261268
}
262269

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+
263285
@Override
264286
public String toString() {
265287
return "Cursor " + Long.toString(cursor, 16) + (isClosed() ? "(closed)" : "");
Collapse file

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

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 numberDiff line numberDiff line change
@@ -583,29 +583,26 @@ public void internalApplyToDb(Cursor sourceCursor, Cursor<TARGET> targetCursor)
583583
throw new IllegalStateException("Source entity has no ID (should have been put before)");
584584
}
585585

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+
}
603590

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)");
605601
}
602+
targetIds[i] = targetId;
606603
}
604+
cursor.modifyRelations(relationInfo.relationId, sourceEntityId, targetIds, remove);
607605
}
608-
609606
}
610607

611608
/** For tests */

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.