1919
2020import java .util .concurrent .Callable ;
2121
22- import io .objectbox .InternalAccess ;
2322import io .objectbox .Property ;
2423
2524/**
@@ -33,6 +32,12 @@ public class PropertyQuery {
3332 final Property property ;
3433 boolean distinct ;
3534 boolean noCaseIfDistinct = true ;
35+ boolean enableNull ;
36+
37+ double nullValueDouble ;
38+ float nullValueFloat ;
39+ String nullValueString ;
40+ long nullValueLong ;
3641
3742 PropertyQuery (Query query , Property property ) {
3843 this .query = query ;
@@ -63,6 +68,33 @@ public PropertyQuery distinct(QueryBuilder.StringOrder stringOrder) {
6368 return this ;
6469 }
6570
71+ public PropertyQuery nullValue (long nullValue ) {
72+ enableNull = true ;
73+ this .nullValueLong = nullValue ;
74+ return this ;
75+ }
76+
77+ public PropertyQuery nullValue (float nullValue ) {
78+ enableNull = true ;
79+ this .nullValueFloat = nullValue ;
80+ return this ;
81+ }
82+
83+ public PropertyQuery nullValue (double nullValue ) {
84+ enableNull = true ;
85+ this .nullValueDouble = nullValue ;
86+ return this ;
87+ }
88+
89+ public PropertyQuery nullValue (String nullValue ) {
90+ if (nullValue == null ) {
91+ throw new IllegalArgumentException ("Null strings are not allowed (yet)" );
92+ }
93+ enableNull = true ;
94+ this .nullValueString = nullValue ;
95+ return this ;
96+ }
97+
6698 /**
6799 * Find the values for the given string property for objects matching the query.
68100 * <p>
@@ -80,7 +112,8 @@ public String[] findStrings() {
80112 public String [] call () {
81113 boolean distinctNoCase = distinct && noCaseIfDistinct ;
82114 long cursorHandle = query .cursorHandle ();
83- return query .nativeFindStrings (query .handle , cursorHandle , property .id , distinct ,distinctNoCase );
115+ return query .nativeFindStrings (query .handle , cursorHandle , property .id , distinct , distinctNoCase ,
116+ enableNull , nullValueString );
84117 }
85118 });
86119 }
@@ -100,7 +133,8 @@ public long[] findLongs() {
100133 return (long []) query .callInReadTx (new Callable <long []>() {
101134 @ Override
102135 public long [] call () {
103- return query .nativeFindLongs (query .handle , query .cursorHandle (), property .id , distinct );
136+ return query .nativeFindLongs (query .handle , query .cursorHandle (), property .id , distinct ,
137+ enableNull , nullValueLong );
104138 }
105139 });
106140 }
@@ -118,7 +152,8 @@ public int[] findInts() {
118152 return (int []) query .callInReadTx (new Callable <int []>() {
119153 @ Override
120154 public int [] call () {
121- return query .nativeFindInts (query .handle , query .cursorHandle (), property .id , distinct );
155+ return query .nativeFindInts (query .handle , query .cursorHandle (), property .id , distinct ,
156+ enableNull , (int )nullValueLong );
122157 }
123158 });
124159 }
@@ -136,7 +171,8 @@ public short[] findShorts() {
136171 return (short []) query .callInReadTx (new Callable <short []>() {
137172 @ Override
138173 public short [] call () {
139- return query .nativeFindShorts (query .handle , query .cursorHandle (), property .id , distinct );
174+ return query .nativeFindShorts (query .handle , query .cursorHandle (), property .id , distinct ,
175+ enableNull , (short ) nullValueLong );
140176 }
141177 });
142178 }
@@ -154,7 +190,8 @@ public char[] findChars() {
154190 return (char []) query .callInReadTx (new Callable <char []>() {
155191 @ Override
156192 public char [] call () {
157- return query .nativeFindChars (query .handle , query .cursorHandle (), property .id , distinct );
193+ return query .nativeFindChars (query .handle , query .cursorHandle (), property .id , distinct ,
194+ enableNull , (char ) nullValueLong );
158195 }
159196 });
160197 }
@@ -170,7 +207,8 @@ public byte[] findBytes() {
170207 return (byte []) query .callInReadTx (new Callable <byte []>() {
171208 @ Override
172209 public byte [] call () {
173- return query .nativeFindBytes (query .handle , query .cursorHandle (), property .id , distinct );
210+ return query .nativeFindBytes (query .handle , query .cursorHandle (), property .id , distinct ,
211+ enableNull , (byte ) nullValueLong );
174212 }
175213 });
176214 }
@@ -188,7 +226,8 @@ public float[] findFloats() {
188226 return (float []) query .callInReadTx (new Callable <float []>() {
189227 @ Override
190228 public float [] call () {
191- return query .nativeFindFloats (query .handle , query .cursorHandle (), property .id , distinct );
229+ return query .nativeFindFloats (query .handle , query .cursorHandle (), property .id , distinct ,
230+ enableNull , nullValueFloat );
192231 }
193232 });
194233 }
@@ -206,7 +245,8 @@ public double[] findDoubles() {
206245 return (double []) query .callInReadTx (new Callable <double []>() {
207246 @ Override
208247 public double [] call () {
209- return query .nativeFindDoubles (query .handle , query .cursorHandle (), property .id , distinct );
248+ return query .nativeFindDoubles (query .handle , query .cursorHandle (), property .id , distinct ,
249+ enableNull , nullValueDouble );
210250 }
211251 });
212252 }
0 commit comments