|
44 | 44 | */ |
45 | 45 | @Internal |
46 | 46 | 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; |
49 | 56 |
|
50 | 57 | private final FlatBufferBuilder fbb = new FlatBufferBuilder(); |
51 | 58 | private final List<Integer> entityOffsets = new ArrayList<>(); |
52 | 59 |
|
53 | | - private long version = DEFAULT_MODEL_VERSION; |
| 60 | + private long version = DEFAULT_VERSION; |
54 | 61 |
|
55 | 62 | private Integer lastEntityId; |
56 | 63 | private Long lastEntityUid; |
@@ -424,6 +431,11 @@ private int createVector(List<Integer> offsets) { |
424 | 431 | return fbb.createVectorOfTables(offsetArray); |
425 | 432 | } |
426 | 433 |
|
| 434 | + /** |
| 435 | + * Sets the user-defined version of the schema this represents. Defaults to 1. |
| 436 | + * <p> |
| 437 | + * Currently unused. |
| 438 | + */ |
427 | 439 | public ModelBuilder version(long version) { |
428 | 440 | this.version = version; |
429 | 441 | return this; |
@@ -452,12 +464,12 @@ public ModelBuilder lastRelationId(int lastRelationId, long lastRelationUid) { |
452 | 464 | } |
453 | 465 |
|
454 | 466 | public byte[] build() { |
455 | | - int nameOffset = fbb.createString(DEFAULT_MODEL_NAME); |
| 467 | + int nameOffset = fbb.createString(DEFAULT_NAME); |
456 | 468 | int entityVectorOffset = createVector(entityOffsets); |
457 | 469 | Model.startModel(fbb); |
458 | 470 | 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); |
461 | 473 | Model.addEntities(fbb, entityVectorOffset); |
462 | 474 | if (lastEntityId != null) { |
463 | 475 | int idOffset = IdUid.createIdUid(fbb, lastEntityId, lastEntityUid); |
|
0 commit comments