Skip to content

Commit d9da41c

Browse files
committed
Add SHARED_GLOBAL_IDS entity flag, update ModelProperty docs
1 parent 38701ba commit d9da41c

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

objectbox-java/src/main/java/io/objectbox/model/EntityFlags.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,18 @@ private EntityFlags() { }
3232
* It's possible to have local-only (non-synced) types and synced types in the same store (schema/data model).
3333
*/
3434
public static final int SYNC_ENABLED = 2;
35+
/**
36+
* Makes object IDs for a synced types (SYNC_ENABLED is set) global.
37+
* By default (not using this flag), the 64 bit object IDs have a local scope and are not unique globally.
38+
* This flag tells ObjectBox to treat object IDs globally and thus no ID mapping (local <-> global) is performed.
39+
* Often this is used with assignable IDs (ID_SELF_ASSIGNABLE property flag is set) and some special ID scheme.
40+
* Note: typically you won't do this with automatically assigned IDs, set by the local ObjectBox store.
41+
* Two devices would likely overwrite each other's object during sync as object IDs are prone to collide.
42+
* It might be OK if you can somehow ensure that only a single device will create new IDs.
43+
*/
44+
public static final int SHARED_GLOBAL_IDS = 4;
3545

36-
public static final String[] names = { "USE_NO_ARG_CONSTRUCTOR", "SYNC_ENABLED", };
46+
public static final String[] names = { "USE_NO_ARG_CONSTRUCTOR", "SYNC_ENABLED", "", "SHARED_GLOBAL_IDS", };
3747

3848
public static String name(int e) { return names[e - USE_NO_ARG_CONSTRUCTOR]; }
3949
}

objectbox-java/src/main/java/io/objectbox/model/ModelProperty.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,20 @@ public final class ModelProperty extends Table {
4444
public io.objectbox.model.IdUid indexId() { return indexId(new io.objectbox.model.IdUid()); }
4545
public io.objectbox.model.IdUid indexId(io.objectbox.model.IdUid obj) { int o = __offset(12); return o != 0 ? obj.__assign(o + bb_pos, bb) : null; }
4646
/**
47-
* For relations only: name of the target entity
47+
* For relations only: name of the target entity (will be replaced by "target entity ID" at the schema level)
4848
*/
4949
public String targetEntity() { int o = __offset(14); return o != 0 ? __string(o + bb_pos) : null; }
5050
public ByteBuffer targetEntityAsByteBuffer() { return __vector_as_bytebuffer(14, 1); }
5151
public ByteBuffer targetEntityInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 14, 1); }
5252
/**
53-
* E.g. for virtual to-one target ID properties, this references the ToOne object
53+
* This will probably move out of the core model into something binding specific.
54+
* A virtual property's "target name" typically references an existing field in the entity at the language level
55+
* of the binding. In contrast to this, the virtual property (via model "name") does not exist in the entity at
56+
* the language level (thus virtual), but in ObjectBox's core DB.
57+
* Example: consider a Java entity which has a ToOne (a Java specific relation wrapper) member called "parent".
58+
* ObjectBox core is unaware of that ToOne, but works with the "parentId" relation property,
59+
* which in turn does not exist in the Java entity.
60+
* The mapping between "parentId" and "parent" is done by our JNI binding.
5461
*/
5562
public String virtualTarget() { int o = __offset(16); return o != 0 ? __string(o + bb_pos) : null; }
5663
public ByteBuffer virtualTargetAsByteBuffer() { return __vector_as_bytebuffer(16, 1); }

0 commit comments

Comments
 (0)