Skip to content

Commit c1afae1

Browse files
Document how to use case sensitive conditions for String.
Also recommend using case sensitive conditions for indexed strings.
1 parent 084aa0f commit c1afae1

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

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

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
import java.util.Date;
2323
import java.util.List;
2424

25+
import javax.annotation.Nullable;
26+
2527
import io.objectbox.Box;
2628
import io.objectbox.EntityInfo;
2729
import io.objectbox.Property;
2830
import io.objectbox.annotation.apihint.Experimental;
2931
import io.objectbox.annotation.apihint.Internal;
3032
import io.objectbox.relation.RelationInfo;
3133

32-
import javax.annotation.Nullable;
33-
3434
/**
3535
* With QueryBuilder you define custom queries returning matching entities. Using the methods of this class you can
3636
* select (filter) results for specific data (for example #{@link #equal(Property, String)} and
@@ -647,42 +647,96 @@ public QueryBuilder<T> notIn(Property<T> property, int[] values) {
647647
// String
648648
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
649649

650+
/**
651+
* Creates an "equal ('=')" condition for this property.
652+
* <p>
653+
* Ignores case when matching results, e.g. {@code equal(prop, "example")} matches both "Example" and "example".
654+
* <p>
655+
* Use {@link #equal(Property, String, StringOrder) equal(prop, value, StringOrder.CASE_SENSITIVE)} to only match
656+
* if case is equal.
657+
* <p>
658+
* Note: Use a case sensitive condition to utilize an {@link io.objectbox.annotation.Index @Index}
659+
* on {@code property}, dramatically speeding up look-up of results.
660+
*/
650661
public QueryBuilder<T> equal(Property<T> property, String value) {
651662
verifyHandle();
652663
checkCombineCondition(nativeEqual(handle, property.getId(), value, false));
653664
return this;
654665
}
655666

667+
/**
668+
* Creates an "equal ('=')" condition for this property.
669+
* <p>
670+
* Set {@code order} to {@link StringOrder#CASE_SENSITIVE StringOrder.CASE_SENSITIVE} to only match
671+
* if case is equal. E.g. {@code equal(prop, "example", StringOrder.CASE_SENSITIVE)} only matches "example",
672+
* but not "Example".
673+
* <p>
674+
* Note: Use a case sensitive condition to utilize an {@link io.objectbox.annotation.Index @Index}
675+
* on {@code property}, dramatically speeding up look-up of results.
676+
*/
656677
public QueryBuilder<T> equal(Property<T> property, String value, StringOrder order) {
657678
verifyHandle();
658679
checkCombineCondition(nativeEqual(handle, property.getId(), value, order == StringOrder.CASE_SENSITIVE));
659680
return this;
660681
}
661682

683+
/**
684+
* Creates a "not equal ('&lt;&gt;')" condition for this property.
685+
* <p>
686+
* Ignores case when matching results, e.g. {@code notEqual(prop, "example")} excludes both "Example" and "example".
687+
* <p>
688+
* Use {@link #notEqual(Property, String, StringOrder) notEqual(prop, value, StringOrder.CASE_SENSITIVE)} to only exclude
689+
* if case is equal.
690+
* <p>
691+
* Note: Use a case sensitive condition to utilize an {@link io.objectbox.annotation.Index @Index}
692+
* on {@code property}, dramatically speeding up look-up of results.
693+
*/
662694
public QueryBuilder<T> notEqual(Property<T> property, String value) {
663695
verifyHandle();
664696
checkCombineCondition(nativeNotEqual(handle, property.getId(), value, false));
665697
return this;
666698
}
667699

700+
/**
701+
* Creates a "not equal ('&lt;&gt;')" condition for this property.
702+
* <p>
703+
* Set {@code order} to {@link StringOrder#CASE_SENSITIVE StringOrder.CASE_SENSITIVE} to only exclude
704+
* if case is equal. E.g. {@code notEqual(prop, "example", StringOrder.CASE_SENSITIVE)} only excludes "example",
705+
* but not "Example".
706+
* <p>
707+
* Note: Use a case sensitive condition to utilize an {@link io.objectbox.annotation.Index @Index}
708+
* on {@code property}, dramatically speeding up look-up of results.
709+
*/
668710
public QueryBuilder<T> notEqual(Property<T> property, String value, StringOrder order) {
669711
verifyHandle();
670712
checkCombineCondition(nativeNotEqual(handle, property.getId(), value, order == StringOrder.CASE_SENSITIVE));
671713
return this;
672714
}
673715

716+
/**
717+
* Ignores case when matching results. Use the overload and pass
718+
* {@link StringOrder#CASE_SENSITIVE StringOrder.CASE_SENSITIVE} to specify that case should not be ignored.
719+
*/
674720
public QueryBuilder<T> contains(Property<T> property, String value) {
675721
verifyHandle();
676722
checkCombineCondition(nativeContains(handle, property.getId(), value, false));
677723
return this;
678724
}
679725

726+
/**
727+
* Ignores case when matching results. Use the overload and pass
728+
* {@link StringOrder#CASE_SENSITIVE StringOrder.CASE_SENSITIVE} to specify that case should not be ignored.
729+
*/
680730
public QueryBuilder<T> startsWith(Property<T> property, String value) {
681731
verifyHandle();
682732
checkCombineCondition(nativeStartsWith(handle, property.getId(), value, false));
683733
return this;
684734
}
685735

736+
/**
737+
* Ignores case when matching results. Use the overload and pass
738+
* {@link StringOrder#CASE_SENSITIVE StringOrder.CASE_SENSITIVE} to specify that case should not be ignored.
739+
*/
686740
public QueryBuilder<T> endsWith(Property<T> property, String value) {
687741
verifyHandle();
688742
checkCombineCondition(nativeEndsWith(handle, property.getId(), value, false));
@@ -707,6 +761,10 @@ public QueryBuilder<T> endsWith(Property<T> property, String value, StringOrder
707761
return this;
708762
}
709763

764+
/**
765+
* Ignores case when matching results. Use the overload and pass
766+
* {@link StringOrder#CASE_SENSITIVE StringOrder.CASE_SENSITIVE} to specify that case should not be ignored.
767+
*/
710768
public QueryBuilder<T> less(Property<T> property, String value) {
711769
return less(property, value, StringOrder.CASE_INSENSITIVE);
712770
}
@@ -717,6 +775,10 @@ public QueryBuilder<T> less(Property<T> property, String value, StringOrder orde
717775
return this;
718776
}
719777

778+
/**
779+
* Ignores case when matching results. Use the overload and pass
780+
* {@link StringOrder#CASE_SENSITIVE StringOrder.CASE_SENSITIVE} to specify that case should not be ignored.
781+
*/
720782
public QueryBuilder<T> greater(Property<T> property, String value) {
721783
return greater(property, value, StringOrder.CASE_INSENSITIVE);
722784
}
@@ -727,6 +789,10 @@ public QueryBuilder<T> greater(Property<T> property, String value, StringOrder o
727789
return this;
728790
}
729791

792+
/**
793+
* Ignores case when matching results. Use the overload and pass
794+
* {@link StringOrder#CASE_SENSITIVE StringOrder.CASE_SENSITIVE} to specify that case should not be ignored.
795+
*/
730796
public QueryBuilder<T> in(Property<T> property, String[] values) {
731797
return in(property, values, StringOrder.CASE_INSENSITIVE);
732798
}

0 commit comments

Comments
 (0)