Skip to content

Commit e8ca7f3

Browse files
Merge branch '100-or-equal-conditions' into dev
2 parents 9690540 + e37ead7 commit e8ca7f3

File tree

3 files changed

+348
-55
lines changed

3 files changed

+348
-55
lines changed

objectbox-java/src/main/java/io/objectbox/query/QueryBuilder.java

Lines changed: 94 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,20 @@
1616

1717
package io.objectbox.query;
1818

19-
import java.io.Closeable;
20-
import java.util.ArrayList;
21-
import java.util.Comparator;
22-
import java.util.Date;
23-
import java.util.List;
24-
25-
import javax.annotation.Nullable;
26-
2719
import io.objectbox.Box;
2820
import io.objectbox.EntityInfo;
2921
import io.objectbox.Property;
3022
import io.objectbox.annotation.apihint.Internal;
3123
import io.objectbox.exception.DbException;
3224
import io.objectbox.relation.RelationInfo;
3325

26+
import javax.annotation.Nullable;
27+
import java.io.Closeable;
28+
import java.util.ArrayList;
29+
import java.util.Comparator;
30+
import java.util.Date;
31+
import java.util.List;
32+
3433
/**
3534
* Builds a {@link Query Query} using conditions which can then be used to return a list of matching Objects.
3635
* <p>
@@ -153,9 +152,9 @@ private native long nativeLink(long handle, long storeHandle, int relationOwnerE
153152

154153
private native long nativeNotEqual(long handle, int propertyId, long value);
155154

156-
private native long nativeLess(long handle, int propertyId, long value);
155+
private native long nativeLess(long handle, int propertyId, long value, boolean withEqual);
157156

158-
private native long nativeGreater(long handle, int propertyId, long value);
157+
private native long nativeGreater(long handle, int propertyId, long value, boolean withEqual);
159158

160159
private native long nativeBetween(long handle, int propertyId, long value1, long value2);
161160

@@ -175,27 +174,27 @@ private native long nativeLink(long handle, long storeHandle, int relationOwnerE
175174

176175
private native long nativeEndsWith(long handle, int propertyId, String value, boolean caseSensitive);
177176

178-
private native long nativeLess(long handle, int propertyId, String value, boolean caseSensitive);
177+
private native long nativeLess(long handle, int propertyId, String value, boolean caseSensitive, boolean withEqual);
179178

180-
private native long nativeGreater(long handle, int propertyId, String value, boolean caseSensitive);
179+
private native long nativeGreater(long handle, int propertyId, String value, boolean caseSensitive, boolean withEqual);
181180

182181
private native long nativeIn(long handle, int propertyId, String[] value, boolean caseSensitive);
183182

184183
// ------------------------------ FPs ------------------------------
185184

186-
private native long nativeLess(long handle, int propertyId, double value);
185+
private native long nativeLess(long handle, int propertyId, double value, boolean withEqual);
187186

188-
private native long nativeGreater(long handle, int propertyId, double value);
187+
private native long nativeGreater(long handle, int propertyId, double value, boolean withEqual);
189188

190189
private native long nativeBetween(long handle, int propertyId, double value1, double value2);
191190

192191
// ------------------------------ Bytes ------------------------------
193192

194193
private native long nativeEqual(long handle, int propertyId, byte[] value);
195194

196-
private native long nativeLess(long handle, int propertyId, byte[] value);
195+
private native long nativeLess(long handle, int propertyId, byte[] value, boolean withEqual);
197196

198-
private native long nativeGreater(long handle, int propertyId, byte[] value);
197+
private native long nativeGreater(long handle, int propertyId, byte[] value, boolean withEqual);
199198

200199
@Internal
201200
public QueryBuilder(Box<T> box, long storeHandle, String entityName) {
@@ -531,13 +530,25 @@ public QueryBuilder<T> notEqual(Property<T> property, long value) {
531530

532531
public QueryBuilder<T> less(Property<T> property, long value) {
533532
verifyHandle();
534-
checkCombineCondition(nativeLess(handle, property.getId(), value));
533+
checkCombineCondition(nativeLess(handle, property.getId(), value, false));
534+
return this;
535+
}
536+
537+
public QueryBuilder<T> lessOrEqual(Property<T> property, long value) {
538+
verifyHandle();
539+
checkCombineCondition(nativeLess(handle, property.getId(), value, true));
535540
return this;
536541
}
537542

538543
public QueryBuilder<T> greater(Property<T> property, long value) {
539544
verifyHandle();
540-
checkCombineCondition(nativeGreater(handle, property.getId(), value));
545+
checkCombineCondition(nativeGreater(handle, property.getId(), value, false));
546+
return this;
547+
}
548+
549+
public QueryBuilder<T> greaterOrEqual(Property<T> property, long value) {
550+
verifyHandle();
551+
checkCombineCondition(nativeGreater(handle, property.getId(), value, true));
541552
return this;
542553
}
543554

@@ -614,9 +625,21 @@ public QueryBuilder<T> notEqual(Property<T> property, Date value) {
614625
return this;
615626
}
616627

628+
/**
629+
* @throws NullPointerException if given value is null. Use {@link #isNull(Property)} instead.
630+
*/
617631
public QueryBuilder<T> less(Property<T> property, Date value) {
618632
verifyHandle();
619-
checkCombineCondition(nativeLess(handle, property.getId(), value.getTime()));
633+
checkCombineCondition(nativeLess(handle, property.getId(), value.getTime(), false));
634+
return this;
635+
}
636+
637+
/**
638+
* @throws NullPointerException if given value is null. Use {@link #isNull(Property)} instead.
639+
*/
640+
public QueryBuilder<T> lessOrEqual(Property<T> property, Date value) {
641+
verifyHandle();
642+
checkCombineCondition(nativeLess(handle, property.getId(), value.getTime(), true));
620643
return this;
621644
}
622645

@@ -625,7 +648,16 @@ public QueryBuilder<T> less(Property<T> property, Date value) {
625648
*/
626649
public QueryBuilder<T> greater(Property<T> property, Date value) {
627650
verifyHandle();
628-
checkCombineCondition(nativeGreater(handle, property.getId(), value.getTime()));
651+
checkCombineCondition(nativeGreater(handle, property.getId(), value.getTime(), false));
652+
return this;
653+
}
654+
655+
/**
656+
* @throws NullPointerException if given value is null. Use {@link #isNull(Property)} instead.
657+
*/
658+
public QueryBuilder<T> greaterOrEqual(Property<T> property, Date value) {
659+
verifyHandle();
660+
checkCombineCondition(nativeGreater(handle, property.getId(), value.getTime(), true));
629661
return this;
630662
}
631663

@@ -766,7 +798,13 @@ public QueryBuilder<T> less(Property<T> property, String value) {
766798

767799
public QueryBuilder<T> less(Property<T> property, String value, StringOrder order) {
768800
verifyHandle();
769-
checkCombineCondition(nativeLess(handle, property.getId(), value, order == StringOrder.CASE_SENSITIVE));
801+
checkCombineCondition(nativeLess(handle, property.getId(), value, order == StringOrder.CASE_SENSITIVE, false));
802+
return this;
803+
}
804+
805+
public QueryBuilder<T> lessOrEqual(Property<T> property, String value, StringOrder order) {
806+
verifyHandle();
807+
checkCombineCondition(nativeLess(handle, property.getId(), value, order == StringOrder.CASE_SENSITIVE, true));
770808
return this;
771809
}
772810

@@ -780,7 +818,13 @@ public QueryBuilder<T> greater(Property<T> property, String value) {
780818

781819
public QueryBuilder<T> greater(Property<T> property, String value, StringOrder order) {
782820
verifyHandle();
783-
checkCombineCondition(nativeGreater(handle, property.getId(), value, order == StringOrder.CASE_SENSITIVE));
821+
checkCombineCondition(nativeGreater(handle, property.getId(), value, order == StringOrder.CASE_SENSITIVE, false));
822+
return this;
823+
}
824+
825+
public QueryBuilder<T> greaterOrEqual(Property<T> property, String value, StringOrder order) {
826+
verifyHandle();
827+
checkCombineCondition(nativeGreater(handle, property.getId(), value, order == StringOrder.CASE_SENSITIVE, true));
784828
return this;
785829
}
786830

@@ -817,13 +861,25 @@ public QueryBuilder<T> equal(Property<T> property, double value, double toleranc
817861

818862
public QueryBuilder<T> less(Property<T> property, double value) {
819863
verifyHandle();
820-
checkCombineCondition(nativeLess(handle, property.getId(), value));
864+
checkCombineCondition(nativeLess(handle, property.getId(), value, false));
865+
return this;
866+
}
867+
868+
public QueryBuilder<T> lessOrEqual(Property<T> property, double value) {
869+
verifyHandle();
870+
checkCombineCondition(nativeLess(handle, property.getId(), value, true));
821871
return this;
822872
}
823873

824874
public QueryBuilder<T> greater(Property<T> property, double value) {
825875
verifyHandle();
826-
checkCombineCondition(nativeGreater(handle, property.getId(), value));
876+
checkCombineCondition(nativeGreater(handle, property.getId(), value, false));
877+
return this;
878+
}
879+
880+
public QueryBuilder<T> greaterOrEqual(Property<T> property, double value) {
881+
verifyHandle();
882+
checkCombineCondition(nativeGreater(handle, property.getId(), value, true));
827883
return this;
828884
}
829885

@@ -845,13 +901,25 @@ public QueryBuilder<T> equal(Property<T> property, byte[] value) {
845901

846902
public QueryBuilder<T> less(Property<T> property, byte[] value) {
847903
verifyHandle();
848-
checkCombineCondition(nativeLess(handle, property.getId(), value));
904+
checkCombineCondition(nativeLess(handle, property.getId(), value, false));
905+
return this;
906+
}
907+
908+
public QueryBuilder<T> lessOrEqual(Property<T> property, byte[] value) {
909+
verifyHandle();
910+
checkCombineCondition(nativeLess(handle, property.getId(), value, true));
849911
return this;
850912
}
851913

852914
public QueryBuilder<T> greater(Property<T> property, byte[] value) {
853915
verifyHandle();
854-
checkCombineCondition(nativeGreater(handle, property.getId(), value));
916+
checkCombineCondition(nativeGreater(handle, property.getId(), value, false));
917+
return this;
918+
}
919+
920+
public QueryBuilder<T> greaterOrEqual(Property<T> property, byte[] value) {
921+
verifyHandle();
922+
checkCombineCondition(nativeGreater(handle, property.getId(), value, true));
855923
return this;
856924
}
857925

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,21 @@ inline fun <reified T> QueryBuilder<T>.less(property: Property<T>, value: Short)
6767
return less(property, value.toLong())
6868
}
6969

70+
/** Shortcut for [lessOrEqual(property, value.toLong())][QueryBuilder.lessOrEqual] */
71+
inline fun <reified T> QueryBuilder<T>.lessOrEqual(property: Property<T>, value: Short): QueryBuilder<T> {
72+
return lessOrEqual(property, value.toLong())
73+
}
74+
7075
/** Shortcut for [greater(property, value.toLong())][QueryBuilder.greater] */
7176
inline fun <reified T> QueryBuilder<T>.greater(property: Property<T>, value: Short): QueryBuilder<T> {
7277
return greater(property, value.toLong())
7378
}
7479

80+
/** Shortcut for [greaterOrEqual(property, value.toLong())][QueryBuilder.greaterOrEqual] */
81+
inline fun <reified T> QueryBuilder<T>.greaterOrEqual(property: Property<T>, value: Short): QueryBuilder<T> {
82+
return greaterOrEqual(property, value.toLong())
83+
}
84+
7585
/** Shortcut for [between(property, value1.toLong(), value2.toLong())][QueryBuilder.between] */
7686
inline fun <reified T> QueryBuilder<T>.between(property: Property<T>, value1: Short, value2: Short): QueryBuilder<T> {
7787
return between(property, value1.toLong(), value2.toLong())
@@ -94,11 +104,21 @@ inline fun <reified T> QueryBuilder<T>.less(property: Property<T>, value: Int):
94104
return less(property, value.toLong())
95105
}
96106

107+
/** Shortcut for [lessOrEqual(property, value.toLong())][QueryBuilder.lessOrEqual] */
108+
inline fun <reified T> QueryBuilder<T>.lessOrEqual(property: Property<T>, value: Int): QueryBuilder<T> {
109+
return lessOrEqual(property, value.toLong())
110+
}
111+
97112
/** Shortcut for [greater(property, value.toLong())][QueryBuilder.greater] */
98113
inline fun <reified T> QueryBuilder<T>.greater(property: Property<T>, value: Int): QueryBuilder<T> {
99114
return greater(property, value.toLong())
100115
}
101116

117+
/** Shortcut for [greaterOrEqual(property, value.toLong())][QueryBuilder.greaterOrEqual] */
118+
inline fun <reified T> QueryBuilder<T>.greaterOrEqual(property: Property<T>, value: Int): QueryBuilder<T> {
119+
return greaterOrEqual(property, value.toLong())
120+
}
121+
102122
/** Shortcut for [between(property, value1.toLong(), value2.toLong())][QueryBuilder.between] */
103123
inline fun <reified T> QueryBuilder<T>.between(property: Property<T>, value1: Int, value2: Int): QueryBuilder<T> {
104124
return between(property, value1.toLong(), value2.toLong())
@@ -116,11 +136,21 @@ inline fun <reified T> QueryBuilder<T>.less(property: Property<T>, value: Float)
116136
return less(property, value.toDouble())
117137
}
118138

139+
/** Shortcut for [lessOrEqual(property, value.toDouble())][QueryBuilder.lessOrEqual] */
140+
inline fun <reified T> QueryBuilder<T>.lessOrEqual(property: Property<T>, value: Float): QueryBuilder<T> {
141+
return lessOrEqual(property, value.toDouble())
142+
}
143+
119144
/** Shortcut for [greater(property, value.toDouble())][QueryBuilder.greater] */
120145
inline fun <reified T> QueryBuilder<T>.greater(property: Property<T>, value: Float): QueryBuilder<T> {
121146
return greater(property, value.toDouble())
122147
}
123148

149+
/** Shortcut for [greaterOrEqual(property, value.toDouble())][QueryBuilder.greaterOrEqual] */
150+
inline fun <reified T> QueryBuilder<T>.greaterOrEqual(property: Property<T>, value: Float): QueryBuilder<T> {
151+
return greaterOrEqual(property, value.toDouble())
152+
}
153+
124154
/** Shortcut for [between(property, value1.toDouble(), value2.toDouble())][QueryBuilder.between] */
125155
inline fun <reified T> QueryBuilder<T>.between(property: Property<T>, value1: Float, value2: Float): QueryBuilder<T> {
126156
return between(property, value1.toDouble(), value2.toDouble())

0 commit comments

Comments
 (0)