21
21
22
22
import javax .annotation .Nullable ;
23
23
24
+ import io .objectbox .annotation .ExternalName ;
25
+ import io .objectbox .annotation .ExternalType ;
24
26
import io .objectbox .annotation .HnswIndex ;
25
27
import io .objectbox .annotation .apihint .Internal ;
26
28
import io .objectbox .flatbuffers .FlatBufferBuilder ;
@@ -123,6 +125,7 @@ public static class PropertyBuilder extends PartBuilder {
123
125
private int indexId ;
124
126
private long indexUid ;
125
127
private int indexMaxValueLength ;
128
+ private int externalNameOffset ;
126
129
private int externalType ;
127
130
private int hnswParamsOffset ;
128
131
private int flags ;
@@ -166,9 +169,16 @@ public PropertyBuilder indexMaxValueLength(int indexMaxValueLength) {
166
169
}
167
170
168
171
/**
169
- * Sets the {@link ExternalPropertyType} constant for this.
170
- *
171
- * @return this builder.
172
+ * Sets the {@link ExternalName} of this property.
173
+ */
174
+ public PropertyBuilder externalName (String externalName ) {
175
+ checkNotFinished ();
176
+ externalNameOffset = getFbb ().createString (externalName );
177
+ return this ;
178
+ }
179
+
180
+ /**
181
+ * Sets the {@link ExternalType} of this property. Should be one of {@link ExternalPropertyType}.
172
182
*/
173
183
public PropertyBuilder externalType (int externalType ) {
174
184
checkNotFinished ();
@@ -247,6 +257,7 @@ public int createFlatBufferTable(FlatBufferBuilder fbb) {
247
257
ModelProperty .addIndexId (fbb , indexIdOffset );
248
258
}
249
259
if (indexMaxValueLength > 0 ) ModelProperty .addMaxIndexValueLength (fbb , indexMaxValueLength );
260
+ if (externalNameOffset != 0 ) ModelProperty .addExternalName (fbb , externalNameOffset );
250
261
if (externalType != 0 ) ModelProperty .addExternalType (fbb , externalType );
251
262
if (hnswParamsOffset != 0 ) ModelProperty .addHnswParams (fbb , hnswParamsOffset );
252
263
if (flags != 0 ) ModelProperty .addFlags (fbb , flags );
@@ -262,6 +273,7 @@ public static class RelationBuilder extends PartBuilder {
262
273
private final int targetEntityId ;
263
274
private final long targetEntityUid ;
264
275
276
+ private int externalNameOffset ;
265
277
private int externalType ;
266
278
267
279
private RelationBuilder (FlatBufferBuilder fbb , String name , int relationId , long relationUid ,
@@ -275,9 +287,16 @@ private RelationBuilder(FlatBufferBuilder fbb, String name, int relationId, long
275
287
}
276
288
277
289
/**
278
- * Sets the {@link ExternalPropertyType} constant for this.
279
- *
280
- * @return this builder.
290
+ * Sets the {@link ExternalName} of this relation.
291
+ */
292
+ public RelationBuilder externalName (String externalName ) {
293
+ checkNotFinished ();
294
+ externalNameOffset = getFbb ().createString (externalName );
295
+ return this ;
296
+ }
297
+
298
+ /**
299
+ * Sets the {@link ExternalType} of this relation. Should be one of {@link ExternalPropertyType}.
281
300
*/
282
301
public RelationBuilder externalType (int externalType ) {
283
302
checkNotFinished ();
@@ -295,6 +314,7 @@ public int createFlatBufferTable(FlatBufferBuilder fbb) {
295
314
ModelRelation .addId (fbb , relationIdOffset );
296
315
int targetEntityIdOffset = IdUid .createIdUid (fbb , targetEntityId , targetEntityUid );
297
316
ModelRelation .addTargetEntityId (fbb , targetEntityIdOffset );
317
+ if (externalNameOffset != 0 ) ModelRelation .addExternalName (fbb , externalNameOffset );
298
318
if (externalType != 0 ) ModelRelation .addExternalType (fbb , externalType );
299
319
return ModelRelation .endModelRelation (fbb );
300
320
}
@@ -311,6 +331,7 @@ public static class EntityBuilder extends PartBuilder {
311
331
private Long uid ;
312
332
private Integer lastPropertyId ;
313
333
private Long lastPropertyUid ;
334
+ @ Nullable private String externalName ;
314
335
private Integer flags ;
315
336
@ Nullable private PropertyBuilder propertyBuilder ;
316
337
@ Nullable private RelationBuilder relationBuilder ;
@@ -335,6 +356,15 @@ public EntityBuilder lastPropertyId(int lastPropertyId, long lastPropertyUid) {
335
356
return this ;
336
357
}
337
358
359
+ /**
360
+ * Sets the {@link ExternalName} of this entity.
361
+ */
362
+ public EntityBuilder externalName (String externalName ) {
363
+ checkNotFinished ();
364
+ this .externalName = externalName ;
365
+ return this ;
366
+ }
367
+
338
368
/**
339
369
* One or more of {@link io.objectbox.model.EntityFlags}.
340
370
*/
@@ -402,6 +432,7 @@ public ModelBuilder entityDone() {
402
432
@ Override
403
433
public int createFlatBufferTable (FlatBufferBuilder fbb ) {
404
434
int nameOffset = fbb .createString (name );
435
+ int externalNameOffset = externalName != null ? fbb .createString (externalName ) : 0 ;
405
436
int propertiesOffset = model .createVector (propertyOffsets );
406
437
int relationsOffset = relationOffsets .isEmpty () ? 0 : model .createVector (relationOffsets );
407
438
@@ -417,6 +448,7 @@ public int createFlatBufferTable(FlatBufferBuilder fbb) {
417
448
int idOffset = IdUid .createIdUid (fbb , lastPropertyId , lastPropertyUid );
418
449
ModelEntity .addLastPropertyId (fbb , idOffset );
419
450
}
451
+ if (externalNameOffset != 0 ) ModelEntity .addExternalName (fbb , externalNameOffset );
420
452
if (flags != null ) ModelEntity .addFlags (fbb , flags );
421
453
return ModelEntity .endModelEntity (fbb );
422
454
}
0 commit comments