Skip to content

Commit 894f43d

Browse files
committed
make Property usage in QueryBuilder type safe
1 parent 020a034 commit 894f43d

File tree

2 files changed

+47
-48
lines changed

2 files changed

+47
-48
lines changed

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

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ private void verifyHandle() {
225225
* @see #order(Property, int)
226226
* @see #orderDesc(Property)
227227
*/
228-
public QueryBuilder<T> order(Property property) {
228+
public QueryBuilder<T> order(Property<T> property) {
229229
return order(property, 0);
230230
}
231231

@@ -236,7 +236,7 @@ public QueryBuilder<T> order(Property property) {
236236
* @see #order(Property, int)
237237
* @see #order(Property)
238238
*/
239-
public QueryBuilder<T> orderDesc(Property property) {
239+
public QueryBuilder<T> orderDesc(Property<T> property) {
240240
return order(property, DESCENDING);
241241
}
242242

@@ -259,7 +259,7 @@ public QueryBuilder<T> orderDesc(Property property) {
259259
* @see #order(Property)
260260
* @see #orderDesc(Property)
261261
*/
262-
public QueryBuilder<T> order(Property property, int flags) {
262+
public QueryBuilder<T> order(Property<T> property, int flags) {
263263
verifyNotSubQuery();
264264
verifyHandle();
265265
if (combineNextWith != Operator.NONE) {
@@ -441,120 +441,120 @@ private void checkCombineCondition(long currentCondition) {
441441
}
442442
}
443443

444-
public QueryBuilder<T> isNull(Property property) {
444+
public QueryBuilder<T> isNull(Property<T> property) {
445445
verifyHandle();
446446
checkCombineCondition(nativeNull(handle, property.getId()));
447447
return this;
448448
}
449449

450-
public QueryBuilder<T> notNull(Property property) {
450+
public QueryBuilder<T> notNull(Property<T> property) {
451451
verifyHandle();
452452
checkCombineCondition(nativeNotNull(handle, property.getId()));
453453
return this;
454454
}
455455

456-
public QueryBuilder<T> equal(Property property, long value) {
456+
public QueryBuilder<T> equal(Property<T> property, long value) {
457457
verifyHandle();
458458
checkCombineCondition(nativeEqual(handle, property.getId(), value));
459459
return this;
460460
}
461461

462-
public QueryBuilder<T> equal(Property property, boolean value) {
462+
public QueryBuilder<T> equal(Property<T> property, boolean value) {
463463
verifyHandle();
464464
checkCombineCondition(nativeEqual(handle, property.getId(), value ? 1 : 0));
465465
return this;
466466
}
467467

468468
/** @throws NullPointerException if given value is null. Use {@link #isNull(Property)} instead. */
469-
public QueryBuilder<T> equal(Property property, Date value) {
469+
public QueryBuilder<T> equal(Property<T> property, Date value) {
470470
verifyHandle();
471471
checkCombineCondition(nativeEqual(handle, property.getId(), value.getTime()));
472472
return this;
473473
}
474474

475-
public QueryBuilder<T> notEqual(Property property, long value) {
475+
public QueryBuilder<T> notEqual(Property<T> property, long value) {
476476
verifyHandle();
477477
checkCombineCondition(nativeNotEqual(handle, property.getId(), value));
478478
return this;
479479
}
480480

481-
public QueryBuilder<T> notEqual(Property property, boolean value) {
481+
public QueryBuilder<T> notEqual(Property<T> property, boolean value) {
482482
verifyHandle();
483483
checkCombineCondition(nativeNotEqual(handle, property.getId(), value ? 1 : 0));
484484
return this;
485485
}
486486

487487
/** @throws NullPointerException if given value is null. Use {@link #isNull(Property)} instead. */
488-
public QueryBuilder<T> notEqual(Property property, Date value) {
488+
public QueryBuilder<T> notEqual(Property<T> property, Date value) {
489489
verifyHandle();
490490
checkCombineCondition(nativeNotEqual(handle, property.getId(), value.getTime()));
491491
return this;
492492
}
493493

494-
public QueryBuilder<T> less(Property property, long value) {
494+
public QueryBuilder<T> less(Property<T> property, long value) {
495495
verifyHandle();
496496
checkCombineCondition(nativeLess(handle, property.getId(), value));
497497
return this;
498498
}
499499

500-
public QueryBuilder<T> greater(Property property, long value) {
500+
public QueryBuilder<T> greater(Property<T> property, long value) {
501501
verifyHandle();
502502
checkCombineCondition(nativeGreater(handle, property.getId(), value));
503503
return this;
504504
}
505505

506-
public QueryBuilder<T> less(Property property, Date value) {
506+
public QueryBuilder<T> less(Property<T> property, Date value) {
507507
verifyHandle();
508508
checkCombineCondition(nativeLess(handle, property.getId(), value.getTime()));
509509
return this;
510510
}
511511

512512
/** @throws NullPointerException if given value is null. Use {@link #isNull(Property)} instead. */
513-
public QueryBuilder<T> greater(Property property, Date value) {
513+
public QueryBuilder<T> greater(Property<T> property, Date value) {
514514
verifyHandle();
515515
checkCombineCondition(nativeGreater(handle, property.getId(), value.getTime()));
516516
return this;
517517
}
518518

519-
public QueryBuilder<T> between(Property property, long value1, long value2) {
519+
public QueryBuilder<T> between(Property<T> property, long value1, long value2) {
520520
verifyHandle();
521521
checkCombineCondition(nativeBetween(handle, property.getId(), value1, value2));
522522
return this;
523523
}
524524

525525
/** @throws NullPointerException if one of the given values is null. */
526-
public QueryBuilder<T> between(Property property, Date value1, Date value2) {
526+
public QueryBuilder<T> between(Property<T> property, Date value1, Date value2) {
527527
verifyHandle();
528528
checkCombineCondition(nativeBetween(handle, property.getId(), value1.getTime(), value2.getTime()));
529529
return this;
530530
}
531531

532532
// FIXME DbException: invalid unordered_map<K, T> key
533-
public QueryBuilder<T> in(Property property, long[] values) {
533+
public QueryBuilder<T> in(Property<T> property, long[] values) {
534534
verifyHandle();
535535
checkCombineCondition(nativeIn(handle, property.getId(), values, false));
536536
return this;
537537
}
538538

539-
public QueryBuilder<T> in(Property property, int[] values) {
539+
public QueryBuilder<T> in(Property<T> property, int[] values) {
540540
verifyHandle();
541541
checkCombineCondition(nativeIn(handle, property.getId(), values, false));
542542
return this;
543543
}
544544

545-
public QueryBuilder<T> notIn(Property property, long[] values) {
545+
public QueryBuilder<T> notIn(Property<T> property, long[] values) {
546546
verifyHandle();
547547
checkCombineCondition(nativeIn(handle, property.getId(), values, true));
548548
return this;
549549
}
550550

551-
public QueryBuilder<T> notIn(Property property, int[] values) {
551+
public QueryBuilder<T> notIn(Property<T> property, int[] values) {
552552
verifyHandle();
553553
checkCombineCondition(nativeIn(handle, property.getId(), values, true));
554554
return this;
555555
}
556556

557-
public QueryBuilder<T> equal(Property property, String value) {
557+
public QueryBuilder<T> equal(Property<T> property, String value) {
558558
verifyHandle();
559559
checkCombineCondition(nativeEqual(handle, property.getId(), value, false));
560560
return this;
@@ -568,77 +568,77 @@ public QueryBuilder<T> equal(Property property, String value) {
568568
* When using {@link Query#setParameters(Property, double, double)},
569569
* consider that the params are the lower and upper bounds.
570570
*/
571-
public QueryBuilder<T> equal(Property property, double value, double tolerance) {
571+
public QueryBuilder<T> equal(Property<T> property, double value, double tolerance) {
572572
return between(property, value - tolerance, value + tolerance);
573573
}
574574

575-
public QueryBuilder<T> notEqual(Property property, String value) {
575+
public QueryBuilder<T> notEqual(Property<T> property, String value) {
576576
verifyHandle();
577577
checkCombineCondition(nativeNotEqual(handle, property.getId(), value, false));
578578
return this;
579579
}
580580

581-
public QueryBuilder<T> contains(Property property, String value) {
581+
public QueryBuilder<T> contains(Property<T> property, String value) {
582582
verifyHandle();
583583
checkCombineCondition(nativeContains(handle, property.getId(), value, false));
584584
return this;
585585
}
586586

587-
public QueryBuilder<T> startsWith(Property property, String value) {
587+
public QueryBuilder<T> startsWith(Property<T> property, String value) {
588588
verifyHandle();
589589
checkCombineCondition(nativeStartsWith(handle, property.getId(), value, false));
590590
return this;
591591
}
592592

593-
public QueryBuilder<T> endsWith(Property property, String value) {
593+
public QueryBuilder<T> endsWith(Property<T> property, String value) {
594594
verifyHandle();
595595
checkCombineCondition(nativeEndsWith(handle, property.getId(), value, false));
596596
return this;
597597
}
598598

599-
public QueryBuilder<T> equal(Property property, String value, StringOrder order) {
599+
public QueryBuilder<T> equal(Property<T> property, String value, StringOrder order) {
600600
verifyHandle();
601601
checkCombineCondition(nativeEqual(handle, property.getId(), value, order == StringOrder.CASE_SENSITIVE));
602602
return this;
603603
}
604604

605-
public QueryBuilder<T> notEqual(Property property, String value, StringOrder order) {
605+
public QueryBuilder<T> notEqual(Property<T> property, String value, StringOrder order) {
606606
verifyHandle();
607607
checkCombineCondition(nativeNotEqual(handle, property.getId(), value, order == StringOrder.CASE_SENSITIVE));
608608
return this;
609609
}
610610

611-
public QueryBuilder<T> contains(Property property, String value, StringOrder order) {
611+
public QueryBuilder<T> contains(Property<T> property, String value, StringOrder order) {
612612
verifyHandle();
613613
checkCombineCondition(nativeContains(handle, property.getId(), value, order == StringOrder.CASE_SENSITIVE));
614614
return this;
615615
}
616616

617-
public QueryBuilder<T> startsWith(Property property, String value, StringOrder order) {
617+
public QueryBuilder<T> startsWith(Property<T> property, String value, StringOrder order) {
618618
verifyHandle();
619619
checkCombineCondition(nativeStartsWith(handle, property.getId(), value, order == StringOrder.CASE_SENSITIVE));
620620
return this;
621621
}
622622

623-
public QueryBuilder<T> endsWith(Property property, String value, StringOrder order) {
623+
public QueryBuilder<T> endsWith(Property<T> property, String value, StringOrder order) {
624624
verifyHandle();
625625
checkCombineCondition(nativeEndsWith(handle, property.getId(), value, order == StringOrder.CASE_SENSITIVE));
626626
return this;
627627
}
628628

629-
public QueryBuilder<T> less(Property property, double value) {
629+
public QueryBuilder<T> less(Property<T> property, double value) {
630630
verifyHandle();
631631
checkCombineCondition(nativeLess(handle, property.getId(), value));
632632
return this;
633633
}
634634

635-
public QueryBuilder<T> greater(Property property, double value) {
635+
public QueryBuilder<T> greater(Property<T> property, double value) {
636636
verifyHandle();
637637
checkCombineCondition(nativeGreater(handle, property.getId(), value));
638638
return this;
639639
}
640640

641-
public QueryBuilder<T> between(Property property, double value1, double value2) {
641+
public QueryBuilder<T> between(Property<T> property, double value1, double value2) {
642642
verifyHandle();
643643
checkCombineCondition(nativeBetween(handle, property.getId(), value1, value2));
644644
return this;

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
// Copied from generated tests (& removed some unused Properties)
2121

2222
import io.objectbox.TestEntityCursor.Factory;
23-
2423
import io.objectbox.annotation.apihint.Internal;
2524
import io.objectbox.internal.CursorFactory;
2625
import io.objectbox.internal.IdGetter;
@@ -47,18 +46,18 @@ public final class TestEntity_ implements EntityInfo<TestEntity> {
4746

4847
private static int ID;
4948

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");
60-
61-
public final static Property[] __ALL_PROPERTIES = {
49+
public final static Property<TestEntity> id = new Property(__INSTANCE, ID++, ID, long.class, "id", true, "id");
50+
public final static Property<TestEntity> simpleBoolean = new Property(__INSTANCE, ID++, ID, boolean.class, "simpleBoolean", false, "simpleBoolean");
51+
public final static Property<TestEntity> simpleByte = new Property(__INSTANCE, ID++, ID, byte.class, "simpleByte", false, "simpleByte");
52+
public final static Property<TestEntity> simpleShort = new Property(__INSTANCE, ID++, ID, short.class, "simpleShort", false, "simpleShort");
53+
public final static Property<TestEntity> simpleInt = new Property(__INSTANCE, ID++, ID, int.class, "simpleInt", false, "simpleInt");
54+
public final static Property<TestEntity> simpleLong = new Property(__INSTANCE, ID++, ID, long.class, "simpleLong", false, "simpleLong");
55+
public final static Property<TestEntity> simpleFloat = new Property(__INSTANCE, ID++, ID, float.class, "simpleFloat", false, "simpleFloat");
56+
public final static Property<TestEntity> simpleDouble = new Property(__INSTANCE, ID++, ID, double.class, "simpleDouble", false, "simpleDouble");
57+
public final static Property<TestEntity> simpleString = new Property(__INSTANCE, ID++, ID, String.class, "simpleString", false, "simpleString");
58+
public final static Property<TestEntity> simpleByteArray = new Property(__INSTANCE, ID++, ID, byte[].class, "simpleByteArray", false, "simpleByteArray");
59+
60+
public final static Property<TestEntity>[] __ALL_PROPERTIES = new Property[]{
6261
id,
6362
simpleInt,
6463
simpleShort,

0 commit comments

Comments
 (0)