Skip to content

Commit bb45440

Browse files
ModelBuilder: explain difference between model version and version
1 parent dc47bef commit bb45440

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

objectbox-java/src/main/java/io/objectbox/ModelBuilder.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,20 @@
4444
*/
4545
@Internal
4646
public class ModelBuilder {
47-
private static final String DEFAULT_MODEL_NAME = "default";
48-
private static final int DEFAULT_MODEL_VERSION = 2;
47+
48+
/**
49+
* The version of the model (structure). The database verifies it supports this version of a model.
50+
* <p>
51+
* Note this is different from the "modelVersion" in the model JSON file, which only refers to the JSON schema.
52+
*/
53+
private static final int MODEL_VERSION = 2;
54+
private static final String DEFAULT_NAME = "default";
55+
private static final int DEFAULT_VERSION = 1;
4956

5057
private final FlatBufferBuilder fbb = new FlatBufferBuilder();
5158
private final List<Integer> entityOffsets = new ArrayList<>();
5259

53-
private long version = DEFAULT_MODEL_VERSION;
60+
private long version = DEFAULT_VERSION;
5461

5562
private Integer lastEntityId;
5663
private Long lastEntityUid;
@@ -424,6 +431,11 @@ private int createVector(List<Integer> offsets) {
424431
return fbb.createVectorOfTables(offsetArray);
425432
}
426433

434+
/**
435+
* Sets the user-defined version of the schema this represents. Defaults to 1.
436+
* <p>
437+
* Currently unused.
438+
*/
427439
public ModelBuilder version(long version) {
428440
this.version = version;
429441
return this;
@@ -452,12 +464,12 @@ public ModelBuilder lastRelationId(int lastRelationId, long lastRelationUid) {
452464
}
453465

454466
public byte[] build() {
455-
int nameOffset = fbb.createString(DEFAULT_MODEL_NAME);
467+
int nameOffset = fbb.createString(DEFAULT_NAME);
456468
int entityVectorOffset = createVector(entityOffsets);
457469
Model.startModel(fbb);
458470
Model.addName(fbb, nameOffset);
459-
Model.addModelVersion(fbb, version);
460-
Model.addVersion(fbb, 1);
471+
Model.addModelVersion(fbb, MODEL_VERSION);
472+
Model.addVersion(fbb, version);
461473
Model.addEntities(fbb, entityVectorOffset);
462474
if (lastEntityId != null) {
463475
int idOffset = IdUid.createIdUid(fbb, lastEntityId, lastEntityUid);

0 commit comments

Comments
 (0)