GeezerVison is showing github.com — Merge branch '100-or-equal-conditions' into dev · TinyAndNeo/objectbox-java@e8ca7f3
File treeExpand file treeCollapse file tree Open diff view settings objectbox-java/src/main/java/io/objectbox/query objectbox-kotlin/src/main/kotlin/io/objectbox/kotlin tests/objectbox-java-test/src/test/java/io/objectbox/query
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: objectbox-java/src/main/java/io/objectbox/query/QueryBuilder.java +94-26Lines changed: 94 additions & 26 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 16 | 16 |
| 17 | 17 | package io.objectbox.query; | 18 | 18 |
| 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 | | - | 27 | 19 | import io.objectbox.Box; | 28 | 20 | import io.objectbox.EntityInfo; | 29 | 21 | import io.objectbox.Property; | 30 | 22 | import io.objectbox.annotation.apihint.Internal; | 31 | 23 | import io.objectbox.exception.DbException; | 32 | 24 | import io.objectbox.relation.RelationInfo; | 33 | 25 |
| | 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 | + | 34 | 33 | /** | 35 | 34 | * Builds a {@link Query Query} using conditions which can then be used to return a list of matching Objects. | 36 | 35 | * <p> | @@ -153,9 +152,9 @@ private native long nativeLink(long handle, long storeHandle, int relationOwnerE | 153 | 152 |
| 154 | 153 | private native long nativeNotEqual(long handle, int propertyId, long value); | 155 | 154 |
| 156 | | - private native long nativeLess(long handle, int propertyId, long value); | | 155 | + private native long nativeLess(long handle, int propertyId, long value, boolean withEqual); | 157 | 156 |
| 158 | | - private native long nativeGreater(long handle, int propertyId, long value); | | 157 | + private native long nativeGreater(long handle, int propertyId, long value, boolean withEqual); | 159 | 158 |
| 160 | 159 | private native long nativeBetween(long handle, int propertyId, long value1, long value2); | 161 | 160 |
| @@ -175,27 +174,27 @@ private native long nativeLink(long handle, long storeHandle, int relationOwnerE | 175 | 174 |
| 176 | 175 | private native long nativeEndsWith(long handle, int propertyId, String value, boolean caseSensitive); | 177 | 176 |
| 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); | 179 | 178 |
| 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); | 181 | 180 |
| 182 | 181 | private native long nativeIn(long handle, int propertyId, String[] value, boolean caseSensitive); | 183 | 182 |
| 184 | 183 | // ------------------------------ FPs ------------------------------ | 185 | 184 |
| 186 | | - private native long nativeLess(long handle, int propertyId, double value); | | 185 | + private native long nativeLess(long handle, int propertyId, double value, boolean withEqual); | 187 | 186 |
| 188 | | - private native long nativeGreater(long handle, int propertyId, double value); | | 187 | + private native long nativeGreater(long handle, int propertyId, double value, boolean withEqual); | 189 | 188 |
| 190 | 189 | private native long nativeBetween(long handle, int propertyId, double value1, double value2); | 191 | 190 |
| 192 | 191 | // ------------------------------ Bytes ------------------------------ | 193 | 192 |
| 194 | 193 | private native long nativeEqual(long handle, int propertyId, byte[] value); | 195 | 194 |
| 196 | | - private native long nativeLess(long handle, int propertyId, byte[] value); | | 195 | + private native long nativeLess(long handle, int propertyId, byte[] value, boolean withEqual); | 197 | 196 |
| 198 | | - private native long nativeGreater(long handle, int propertyId, byte[] value); | | 197 | + private native long nativeGreater(long handle, int propertyId, byte[] value, boolean withEqual); | 199 | 198 |
| 200 | 199 | @Internal | 201 | 200 | public QueryBuilder(Box<T> box, long storeHandle, String entityName) { | @@ -531,13 +530,25 @@ public QueryBuilder<T> notEqual(Property<T> property, long value) { | 531 | 530 |
| 532 | 531 | public QueryBuilder<T> less(Property<T> property, long value) { | 533 | 532 | 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)); | 535 | 540 | return this; | 536 | 541 | } | 537 | 542 |
| 538 | 543 | public QueryBuilder<T> greater(Property<T> property, long value) { | 539 | 544 | 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)); | 541 | 552 | return this; | 542 | 553 | } | 543 | 554 |
| @@ -614,9 +625,21 @@ public QueryBuilder<T> notEqual(Property<T> property, Date value) { | 614 | 625 | return this; | 615 | 626 | } | 616 | 627 |
| | 628 | + /** | | 629 | + * @throws NullPointerException if given value is null. Use {@link #isNull(Property)} instead. | | 630 | + */ | 617 | 631 | public QueryBuilder<T> less(Property<T> property, Date value) { | 618 | 632 | 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)); | 620 | 643 | return this; | 621 | 644 | } | 622 | 645 |
| @@ -625,7 +648,16 @@ public QueryBuilder<T> less(Property<T> property, Date value) { | 625 | 648 | */ | 626 | 649 | public QueryBuilder<T> greater(Property<T> property, Date value) { | 627 | 650 | 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)); | 629 | 661 | return this; | 630 | 662 | } | 631 | 663 |
| @@ -766,7 +798,13 @@ public QueryBuilder<T> less(Property<T> property, String value) { | 766 | 798 |
| 767 | 799 | public QueryBuilder<T> less(Property<T> property, String value, StringOrder order) { | 768 | 800 | 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)); | 770 | 808 | return this; | 771 | 809 | } | 772 | 810 |
| @@ -780,7 +818,13 @@ public QueryBuilder<T> greater(Property<T> property, String value) { | 780 | 818 |
| 781 | 819 | public QueryBuilder<T> greater(Property<T> property, String value, StringOrder order) { | 782 | 820 | 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)); | 784 | 828 | return this; | 785 | 829 | } | 786 | 830 |
| @@ -817,13 +861,25 @@ public QueryBuilder<T> equal(Property<T> property, double value, double toleranc | 817 | 861 |
| 818 | 862 | public QueryBuilder<T> less(Property<T> property, double value) { | 819 | 863 | 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)); | 821 | 871 | return this; | 822 | 872 | } | 823 | 873 |
| 824 | 874 | public QueryBuilder<T> greater(Property<T> property, double value) { | 825 | 875 | 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)); | 827 | 883 | return this; | 828 | 884 | } | 829 | 885 |
| @@ -845,13 +901,25 @@ public QueryBuilder<T> equal(Property<T> property, byte[] value) { | 845 | 901 |
| 846 | 902 | public QueryBuilder<T> less(Property<T> property, byte[] value) { | 847 | 903 | 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)); | 849 | 911 | return this; | 850 | 912 | } | 851 | 913 |
| 852 | 914 | public QueryBuilder<T> greater(Property<T> property, byte[] value) { | 853 | 915 | 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)); | 855 | 923 | return this; | 856 | 924 | } | 857 | 925 |
| |
Collapse file Copy file name to clipboardExpand all lines: objectbox-kotlin/src/main/kotlin/io/objectbox/kotlin/Extensions.kt +30Lines changed: 30 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -67,11 +67,21 @@ inline fun <reified T> QueryBuilder<T>.less(property: Property<T>, value: Short) | 67 | 67 | return less(property, value.toLong()) | 68 | 68 | } | 69 | 69 |
| | 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 | + | 70 | 75 | /** Shortcut for [greater(property, value.toLong())][QueryBuilder.greater] */ | 71 | 76 | inline fun <reified T> QueryBuilder<T>.greater(property: Property<T>, value: Short): QueryBuilder<T> { | 72 | 77 | return greater(property, value.toLong()) | 73 | 78 | } | 74 | 79 |
| | 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 | + | 75 | 85 | /** Shortcut for [between(property, value1.toLong(), value2.toLong())][QueryBuilder.between] */ | 76 | 86 | inline fun <reified T> QueryBuilder<T>.between(property: Property<T>, value1: Short, value2: Short): QueryBuilder<T> { | 77 | 87 | return between(property, value1.toLong(), value2.toLong()) | @@ -94,11 +104,21 @@ inline fun <reified T> QueryBuilder<T>.less(property: Property<T>, value: Int): | 94 | 104 | return less(property, value.toLong()) | 95 | 105 | } | 96 | 106 |
| | 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 | + | 97 | 112 | /** Shortcut for [greater(property, value.toLong())][QueryBuilder.greater] */ | 98 | 113 | inline fun <reified T> QueryBuilder<T>.greater(property: Property<T>, value: Int): QueryBuilder<T> { | 99 | 114 | return greater(property, value.toLong()) | 100 | 115 | } | 101 | 116 |
| | 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 | + | 102 | 122 | /** Shortcut for [between(property, value1.toLong(), value2.toLong())][QueryBuilder.between] */ | 103 | 123 | inline fun <reified T> QueryBuilder<T>.between(property: Property<T>, value1: Int, value2: Int): QueryBuilder<T> { | 104 | 124 | return between(property, value1.toLong(), value2.toLong()) | @@ -116,11 +136,21 @@ inline fun <reified T> QueryBuilder<T>.less(property: Property<T>, value: Float) | 116 | 136 | return less(property, value.toDouble()) | 117 | 137 | } | 118 | 138 |
| | 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 | + | 119 | 144 | /** Shortcut for [greater(property, value.toDouble())][QueryBuilder.greater] */ | 120 | 145 | inline fun <reified T> QueryBuilder<T>.greater(property: Property<T>, value: Float): QueryBuilder<T> { | 121 | 146 | return greater(property, value.toDouble()) | 122 | 147 | } | 123 | 148 |
| | 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 | + | 124 | 154 | /** Shortcut for [between(property, value1.toDouble(), value2.toDouble())][QueryBuilder.between] */ | 125 | 155 | inline fun <reified T> QueryBuilder<T>.between(property: Property<T>, value1: Float, value2: Float): QueryBuilder<T> { | 126 | 156 | return between(property, value1.toDouble(), value2.toDouble()) | |
|