Skip to content

Commit 8f79c77

Browse files
committed
Make Property generic to its entity type and hold EntityInfo in it
1 parent 10cdcee commit 8f79c77

File tree

8 files changed

+54
-45
lines changed

8 files changed

+54
-45
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,18 @@
2929
/**
3030
* Meta data describing a property
3131
*/
32-
public class Property implements Serializable {
32+
public class Property<ENTITY> implements Serializable {
3333
private static final long serialVersionUID = 8613291105982758093L;
3434

35+
public final EntityInfo<ENTITY> entity;
3536
public final int ordinal;
3637
public final int id;
3738

3839
/** One of the supported types to be mapped to the DB. */
3940
public final Class<?> type;
4041

4142
public final String name;
42-
public final boolean primaryKey;
43+
public final boolean isId;
4344
public final String dbName;
4445
public final Class<? extends PropertyConverter> converterClass;
4546

@@ -50,21 +51,23 @@ public class Property implements Serializable {
5051
// Also, this should make the Property class truly @Immutable.
5152
private boolean idVerified;
5253

53-
public Property(int ordinal, int id, Class<?> type, String name, boolean primaryKey, String dbName) {
54-
this(ordinal, id, type, name, primaryKey, dbName, null, null);
54+
public Property(EntityInfo<ENTITY> entity, int ordinal, int id, Class<?> type, String name) {
55+
this(entity, ordinal, id, type, name, false, name, null, null);
5556
}
5657

57-
public Property(int ordinal, int id, Class<?> type, String name) {
58-
this(ordinal, id, type, name, false, name, null, null);
58+
public Property(EntityInfo<ENTITY> entity, int ordinal, int id, Class<?> type, String name, boolean isId,
59+
String dbName) {
60+
this(entity, ordinal, id, type, name, isId, dbName, null, null);
5961
}
6062

61-
public Property(int ordinal, int id, Class<?> type, String name, boolean primaryKey, String dbName,
62-
Class<? extends PropertyConverter> converterClass, Class customType) {
63+
public Property(EntityInfo<ENTITY> entity, int ordinal, int id, Class<?> type, String name, boolean isId,
64+
String dbName, Class<? extends PropertyConverter> converterClass, Class customType) {
65+
this.entity = entity;
6366
this.ordinal = ordinal;
6467
this.id = id;
6568
this.type = type;
6669
this.name = name;
67-
this.primaryKey = primaryKey;
70+
this.isId = isId;
6871
this.dbName = dbName;
6972
this.converterClass = converterClass;
7073
this.customType = customType;

objectbox-kotlin/src/main/kotlin/io/objectbox/kotlin/Extensions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ inline fun <reified T> BoxStore.boxFor(): Box<T> = boxFor(T::class.java)
3232
inline fun <T : Any> BoxStore.boxFor(clazz: KClass<T>): Box<T> = boxFor(clazz.java)
3333

3434
/** An alias for the "in" method, which is a reserved keyword in Kotlin. */
35-
inline fun <reified T> QueryBuilder<T>.inValues(property: Property, values: LongArray): QueryBuilder<T>
35+
inline fun <reified T> QueryBuilder<T>.inValues(property: Property<T>, values: LongArray): QueryBuilder<T>
3636
= `in`(property, values)
3737

3838
/** An alias for the "in" method, which is a reserved keyword in Kotlin. */
39-
inline fun <reified T> QueryBuilder<T>.inValues(property: Property, values: IntArray): QueryBuilder<T>
39+
inline fun <reified T> QueryBuilder<T>.inValues(property: Property<T>, values: IntArray): QueryBuilder<T>
4040
= `in`(property, values)
4141

4242
/**

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ public long getId(TestEntityMinimal object) {
4747
}
4848
};
4949

50+
public final static TestEntityMinimal_ __INSTANCE = new TestEntityMinimal_();
51+
5052
private static int ID;
5153

52-
public final static Property id = new Property(ID++, ID, long.class, "id", true, "id");
53-
public final static Property text = new Property(ID++, ID, String.class, "text", false, "text");
54+
public final static Property id = new Property(__INSTANCE, ID++, ID, long.class, "id", true, "id");
55+
public final static Property text = new Property(__INSTANCE, ID++, ID, String.class, "text", false, "text");
5456

5557
public final static Property[] __ALL_PROPERTIES = {
5658
id,

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,20 @@ public final class TestEntity_ implements EntityInfo<TestEntity> {
4343
@Internal
4444
static final TestEntityIdGetter __ID_GETTER = new TestEntityIdGetter();
4545

46+
public final static TestEntity_ __INSTANCE = new TestEntity_();
47+
4648
private static int ID;
4749

48-
public final static Property id = new Property(ID++, ID, long.class, "id", true, "id");
49-
public final static Property simpleBoolean = new Property(ID++, ID, boolean.class, "simpleBoolean", false, "simpleBoolean");
50-
public final static Property simpleByte = new Property(ID++, ID, byte.class, "simpleByte", false, "simpleByte");
51-
public final static Property simpleShort = new Property(ID++, ID, short.class, "simpleShort", false, "simpleShort");
52-
public final static Property simpleInt = new Property(ID++, ID, int.class, "simpleInt", false, "simpleInt");
53-
public final static Property simpleLong = new Property(ID++, ID, long.class, "simpleLong", false, "simpleLong");
54-
public final static Property simpleFloat = new Property(ID++, ID, float.class, "simpleFloat", false, "simpleFloat");
55-
public final static Property simpleDouble = new Property(ID++, ID, double.class, "simpleDouble", false, "simpleDouble");
56-
public final static Property simpleString = new Property(ID++, ID, String.class, "simpleString", false, "simpleString");
57-
public final static Property simpleByteArray = new Property(ID++, ID, byte[].class, "simpleByteArray", false, "simpleByteArray");
50+
public final static Property id = new Property(__INSTANCE, ID++, ID, long.class, "id", true, "id");
51+
public final static Property simpleBoolean = new Property(__INSTANCE, ID++, ID, boolean.class, "simpleBoolean", false, "simpleBoolean");
52+
public final static Property simpleByte = new Property(__INSTANCE, ID++, ID, byte.class, "simpleByte", false, "simpleByte");
53+
public final static Property simpleShort = new Property(__INSTANCE, ID++, ID, short.class, "simpleShort", false, "simpleShort");
54+
public final static Property simpleInt = new Property(__INSTANCE, ID++, ID, int.class, "simpleInt", false, "simpleInt");
55+
public final static Property simpleLong = new Property(__INSTANCE, ID++, ID, long.class, "simpleLong", false, "simpleLong");
56+
public final static Property simpleFloat = new Property(__INSTANCE, ID++, ID, float.class, "simpleFloat", false, "simpleFloat");
57+
public final static Property simpleDouble = new Property(__INSTANCE, ID++, ID, double.class, "simpleDouble", false, "simpleDouble");
58+
public final static Property simpleString = new Property(__INSTANCE, ID++, ID, String.class, "simpleString", false, "simpleString");
59+
public final static Property simpleByteArray = new Property(__INSTANCE, ID++, ID, byte[].class, "simpleByteArray", false, "simpleByteArray");
5860

5961
public final static Property[] __ALL_PROPERTIES = {
6062
id,

tests/objectbox-java-test/src/main/java/io/objectbox/index/model/EntityLongIndex_.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ public class EntityLongIndex_ implements EntityInfo<EntityLongIndex> {
3636

3737
public static final String __NAME_IN_DB = "EntityLongIndex";
3838

39-
public final static Property id = new Property(0, 7, long.class, "id", true, "_id");
40-
public final static Property indexedLong = new Property(1, 1, long.class, "indexedLong");
41-
public final static Property float1 = new Property(2, 2, Float.class, "float1");
42-
public final static Property float2 = new Property(3, 3, Float.class, "float2");
43-
public final static Property float3 = new Property(4, 4, Float.class, "float3");
44-
public final static Property float4 = new Property(5, 5, Float.class, "float4");
45-
public final static Property float5 = new Property(6, 6, Float.class, "float5");
39+
public final static EntityLongIndex_ __INSTANCE = new EntityLongIndex_();
40+
41+
public final static Property id = new Property(__INSTANCE, 0, 7, long.class, "id", true, "_id");
42+
public final static Property indexedLong = new Property(__INSTANCE, 1, 1, long.class, "indexedLong");
43+
public final static Property float1 = new Property(__INSTANCE, 2, 2, Float.class, "float1");
44+
public final static Property float2 = new Property(__INSTANCE, 3, 3, Float.class, "float2");
45+
public final static Property float3 = new Property(__INSTANCE, 4, 4, Float.class, "float3");
46+
public final static Property float4 = new Property(__INSTANCE, 5, 5, Float.class, "float4");
47+
public final static Property float5 = new Property(__INSTANCE, 6, 6, Float.class, "float5");
4648

4749
public final static Property[] __ALL_PROPERTIES = {
4850
id,

tests/objectbox-java-test/src/main/java/io/objectbox/relation/Customer_.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ public class Customer_ implements EntityInfo<Customer> {
4646
@Internal
4747
static final CustomerIdGetter __ID_GETTER = new CustomerIdGetter();
4848

49-
public final static Property id = new Property(0, 1, long.class, "id", true, "_id");
50-
public final static Property name = new Property(1, 2, String.class, "name");
49+
public final static Customer_ __INSTANCE = new Customer_();
50+
51+
public final static Property id = new Property(__INSTANCE, 0, 1, long.class, "id", true, "_id");
52+
public final static Property name = new Property(__INSTANCE, 1, 2, String.class, "name");
5153

5254
public final static Property[] __ALL_PROPERTIES = {
5355
id,
@@ -56,8 +58,6 @@ public class Customer_ implements EntityInfo<Customer> {
5658

5759
public final static Property __ID_PROPERTY = id;
5860

59-
public final static Customer_ __INSTANCE = new Customer_();
60-
6161
@Override
6262
public String getEntityName() {
6363
return __ENTITY_NAME;

tests/objectbox-java-test/src/main/java/io/objectbox/relation/Order_.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ public class Order_ implements EntityInfo<Order> {
5151
@Internal
5252
static final OrderIdGetter __ID_GETTER = new OrderIdGetter();
5353

54-
public final static Property id = new Property(0, 1, long.class, "id", true, "_id");
55-
public final static Property date = new Property(1, 2, java.util.Date.class, "date");
56-
public final static Property customerId = new Property(2, 3, long.class, "customerId");
57-
public final static Property text = new Property(3, 4, String.class, "text");
54+
public final static Order_ __INSTANCE = new Order_();
55+
56+
public final static Property id = new Property(__INSTANCE, 0, 1, long.class, "id", true, "_id");
57+
public final static Property date = new Property(__INSTANCE, 1, 2, java.util.Date.class, "date");
58+
public final static Property customerId = new Property(__INSTANCE, 2, 3, long.class, "customerId");
59+
public final static Property text = new Property(__INSTANCE, 3, 4, String.class, "text");
5860

5961
public final static Property[] __ALL_PROPERTIES = {
6062
id,
@@ -65,8 +67,6 @@ public class Order_ implements EntityInfo<Order> {
6567

6668
public final static Property __ID_PROPERTY = id;
6769

68-
public final static Order_ __INSTANCE = new Order_();
69-
7070
@Override
7171
public String getEntityName() {
7272
return __ENTITY_NAME;

tests/test-proguard/src/main/java/io/objectbox/test/proguard/ObfuscatedEntity_.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ public final class ObfuscatedEntity_ implements EntityInfo<ObfuscatedEntity> {
4848
@Internal
4949
static final ObfuscatedEntityIdGetter __ID_GETTER = new ObfuscatedEntityIdGetter();
5050

51-
public final static Property id = new Property(0, 1, long.class, "id", true, "id");
52-
public final static Property myInt = new Property(1, 2, int.class, "myInt");
53-
public final static Property myString = new Property(2, 3, String.class, "myString");
51+
public final static ObfuscatedEntity_ __INSTANCE = new ObfuscatedEntity_();
52+
53+
public final static Property id = new Property(__INSTANCE, 0, 1, long.class, "id", true, "id");
54+
public final static Property myInt = new Property(__INSTANCE, 1, 2, int.class, "myInt");
55+
public final static Property myString = new Property(__INSTANCE, 2, 3, String.class, "myString");
5456

5557
public final static Property[] __ALL_PROPERTIES = {
5658
id,
@@ -60,8 +62,6 @@ public final class ObfuscatedEntity_ implements EntityInfo<ObfuscatedEntity> {
6062

6163
public final static Property __ID_PROPERTY = id;
6264

63-
public final static ObfuscatedEntity_ __INSTANCE = new ObfuscatedEntity_();
64-
6565
@Override
6666
public String getEntityName() {
6767
return __ENTITY_NAME;

0 commit comments

Comments
 (0)