Skip to content

Commit cdfc6e6

Browse files
TestEntity: add unsigned properties (short, int and long).
1 parent 408d78b commit cdfc6e6

File tree

4 files changed

+73
-7
lines changed

4 files changed

+73
-7
lines changed

tests/objectbox-java-test/src/main/java/io/objectbox/TestEntity.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public class TestEntity {
3232
private String simpleString;
3333
/** Not-null value. */
3434
private byte[] simpleByteArray;
35+
/** In "real" entity would be annotated with @Unsigned. */
36+
private short simpleShortU;
37+
/** In "real" entity would be annotated with @Unsigned. */
38+
private int simpleIntU;
39+
/** In "real" entity would be annotated with @Unsigned. */
40+
private long simpleLongU;
3541

3642
transient boolean noArgsConstructorCalled;
3743

@@ -43,7 +49,7 @@ public TestEntity(long id) {
4349
this.id = id;
4450
}
4551

46-
public TestEntity(long id, boolean simpleBoolean, byte simpleByte, short simpleShort, int simpleInt, long simpleLong, float simpleFloat, double simpleDouble, String simpleString, byte[] simpleByteArray) {
52+
public TestEntity(long id, boolean simpleBoolean, byte simpleByte, short simpleShort, int simpleInt, long simpleLong, float simpleFloat, double simpleDouble, String simpleString, byte[] simpleByteArray, short simpleShortU, int simpleIntU, long simpleLongU) {
4753
this.id = id;
4854
this.simpleBoolean = simpleBoolean;
4955
this.simpleByte = simpleByte;
@@ -54,6 +60,9 @@ public TestEntity(long id, boolean simpleBoolean, byte simpleByte, short simpleS
5460
this.simpleDouble = simpleDouble;
5561
this.simpleString = simpleString;
5662
this.simpleByteArray = simpleByteArray;
63+
this.simpleShortU = simpleShortU;
64+
this.simpleIntU = simpleIntU;
65+
this.simpleLongU = simpleLongU;
5766
}
5867

5968
public long getId() {
@@ -140,4 +149,30 @@ public void setSimpleByteArray(byte[] simpleByteArray) {
140149
this.simpleByteArray = simpleByteArray;
141150
}
142151

152+
public short getSimpleShortU() {
153+
return simpleShortU;
154+
}
155+
156+
public TestEntity setSimpleShortU(short simpleShortU) {
157+
this.simpleShortU = simpleShortU;
158+
return this;
159+
}
160+
161+
public int getSimpleIntU() {
162+
return simpleIntU;
163+
}
164+
165+
public TestEntity setSimpleIntU(int simpleIntU) {
166+
this.simpleIntU = simpleIntU;
167+
return this;
168+
}
169+
170+
public long getSimpleLongU() {
171+
return simpleLongU;
172+
}
173+
174+
public TestEntity setSimpleLongU(long simpleLongU) {
175+
this.simpleLongU = simpleLongU;
176+
return this;
177+
}
143178
}

tests/objectbox-java-test/src/main/java/io/objectbox/TestEntityCursor.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public Cursor<TestEntity> createCursor(io.objectbox.Transaction tx, long cursorH
5151
private final static int __ID_simpleDouble = TestEntity_.simpleDouble.id;
5252
private final static int __ID_simpleString = TestEntity_.simpleString.id;
5353
private final static int __ID_simpleByteArray = TestEntity_.simpleByteArray.id;
54+
private final static int __ID_simpleShortU = TestEntity_.simpleShortU.id;
55+
private final static int __ID_simpleIntU = TestEntity_.simpleIntU.id;
56+
private final static int __ID_simpleLongU = TestEntity_.simpleLongU.id;
5457

5558
public TestEntityCursor(io.objectbox.Transaction tx, long cursor, BoxStore boxStore) {
5659
super(tx, cursor, TestEntity_.__INSTANCE, boxStore);
@@ -73,14 +76,18 @@ public final long put(TestEntity entity) {
7376
byte[] simpleByteArray = entity.getSimpleByteArray();
7477
int __id9 = simpleByteArray != null ? __ID_simpleByteArray : 0;
7578

76-
long __assignedId = collect313311(cursor, entity.getId(), PUT_FLAG_FIRST | PUT_FLAG_COMPLETE,
79+
collect313311(cursor, 0, PUT_FLAG_FIRST,
7780
__id8, simpleString, 0, null,
7881
0, null, __id9, simpleByteArray,
79-
__ID_simpleLong, entity.getSimpleLong(), INT_NULL_HACK ? 0 : __ID_simpleInt, entity.getSimpleInt(),
80-
__ID_simpleShort, entity.getSimpleShort(), __ID_simpleByte, entity.getSimpleByte(),
81-
__ID_simpleBoolean, entity.getSimpleBoolean() ? 1 : 0, 0, 0,
82+
__ID_simpleLong, entity.getSimpleLong(), __ID_simpleLongU, entity.getSimpleLongU(),
83+
INT_NULL_HACK ? 0 : __ID_simpleInt, entity.getSimpleInt(), __ID_simpleIntU, entity.getSimpleIntU(),
84+
__ID_simpleShort, entity.getSimpleShort(), __ID_simpleShortU, entity.getSimpleShortU(),
8285
__ID_simpleFloat, entity.getSimpleFloat(), __ID_simpleDouble, entity.getSimpleDouble());
8386

87+
long __assignedId = collect004000(cursor, entity.getId(), PUT_FLAG_COMPLETE,
88+
__ID_simpleByte, entity.getSimpleByte(), __ID_simpleBoolean, entity.getSimpleBoolean() ? 1 : 0,
89+
0, 0, 0, 0);
90+
8491
entity.setId(__assignedId);
8592

8693
return __assignedId;

tests/objectbox-java-test/src/main/java/io/objectbox/TestEntity_.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ public final class TestEntity_ implements EntityInfo<TestEntity> {
7777
public final static io.objectbox.Property<TestEntity> simpleByteArray =
7878
new io.objectbox.Property<>(__INSTANCE, 9, 10, byte[].class, "simpleByteArray");
7979

80+
public final static io.objectbox.Property<TestEntity> simpleShortU =
81+
new io.objectbox.Property<>(__INSTANCE, 10, 11, short.class, "simpleShortU");
82+
83+
public final static io.objectbox.Property<TestEntity> simpleIntU =
84+
new io.objectbox.Property<>(__INSTANCE, 11, 12, int.class, "simpleIntU");
85+
86+
public final static io.objectbox.Property<TestEntity> simpleLongU =
87+
new io.objectbox.Property<>(__INSTANCE, 12, 13, long.class, "simpleLongU");
88+
8089
@SuppressWarnings("unchecked")
8190
public final static io.objectbox.Property<TestEntity>[] __ALL_PROPERTIES = new io.objectbox.Property[]{
8291
id,
@@ -88,7 +97,10 @@ public final class TestEntity_ implements EntityInfo<TestEntity> {
8897
simpleFloat,
8998
simpleDouble,
9099
simpleString,
91-
simpleByteArray
100+
simpleByteArray,
101+
simpleShortU,
102+
simpleIntU,
103+
simpleLongU
92104
};
93105

94106
public final static io.objectbox.Property<TestEntity> __ID_PROPERTY = id;

tests/objectbox-java-test/src/test/java/io/objectbox/AbstractObjectBoxTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,16 @@ private void addTestEntity(ModelBuilder modelBuilder, boolean withIndex) {
197197
pb.flags(PropertyFlags.INDEXED).indexId(++lastIndexId, lastIndexUid);
198198
}
199199
entityBuilder.property("simpleByteArray", PropertyType.ByteVector).id(TestEntity_.simpleByteArray.id, ++lastUid);
200-
int lastId = TestEntity_.simpleByteArray.id;
200+
201+
// Unsigned integers.
202+
entityBuilder.property("simpleShortU", PropertyType.Short).id(TestEntity_.simpleShortU.id, ++lastUid)
203+
.flags(PropertyFlags.UNSIGNED);
204+
entityBuilder.property("simpleIntU", PropertyType.Int).id(TestEntity_.simpleIntU.id, ++lastUid)
205+
.flags(PropertyFlags.UNSIGNED);
206+
entityBuilder.property("simpleLongU", PropertyType.Long).id(TestEntity_.simpleLongU.id, ++lastUid)
207+
.flags(PropertyFlags.UNSIGNED);
208+
209+
int lastId = TestEntity_.simpleLongU.id;
201210
entityBuilder.lastPropertyId(lastId, lastUid);
202211
addOptionalFlagsToTestEntity(entityBuilder);
203212
entityBuilder.entityDone();
@@ -232,6 +241,9 @@ protected TestEntity createTestEntity(@Nullable String simpleString, int nr) {
232241
entity.setSimpleFloat(200 + nr / 10f);
233242
entity.setSimpleDouble(2000 + nr / 100f);
234243
entity.setSimpleByteArray(new byte[]{1, 2, (byte) nr});
244+
entity.setSimpleShortU((short) (100 + nr));
245+
entity.setSimpleIntU(nr);
246+
entity.setSimpleLongU(1000 + nr);
235247
return entity;
236248
}
237249

0 commit comments

Comments
 (0)