Skip to content

Commit 9969a01

Browse files
Document how to use case sensitive conditions for String.
Also recommend using case sensitive conditions for indexed strings.
1 parent da6359d commit 9969a01

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
@@ -601,42 +601,96 @@ public QueryBuilder<T> notIn(Property<T> property, int[] values) {
601601
// String
602602
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
603603

604+
/**
605+
* Creates an "equal ('=')" condition for this property.
606+
* <p>
607+
* Ignores case when matching results, e.g. {@code equal(prop, "example")} matches both "Example" and "example".
608+
* <p>
609+
* Use {@link #equal(Property, String, StringOrder) equal(prop, value, StringOrder.CASE_SENSITIVE)} to only match
610+
* if case is equal.
611+
* <p>
612+
* Note: Use a case sensitive condition to utilize an {@link io.objectbox.annotation.Index @Index}
613+
* on {@code property}, dramatically speeding up look-up of results.
614+
*/
604615
public QueryBuilder<T> equal(Property<T> property, String value) {
605616
verifyHandle();
606617
checkCombineCondition(nativeEqual(handle, property.getId(), value, false));
607618
return this;
608619
}
609620

621+
/**
622+
* Creates an "equal ('=')" condition for this property.
623+
* <p>
624+
* Set {@code order} to {@link StringOrder#CASE_SENSITIVE StringOrder.CASE_SENSITIVE} to only match
625+
* if case is equal. E.g. {@code equal(prop, "example", StringOrder.CASE_SENSITIVE)} only matches "example",
626+
* but not "Example".
627+
* <p>
628+
* Note: Use a case sensitive condition to utilize an {@link io.objectbox.annotation.Index @Index}
629+
* on {@code property}, dramatically speeding up look-up of results.
630+
*/
610631
public QueryBuilder<T> equal(Property<T> property, String value, StringOrder order) {
611632
verifyHandle();
612633
checkCombineCondition(nativeEqual(handle, property.getId(), value, order == StringOrder.CASE_SENSITIVE));
613634
return this;
614635
}
615636

637+
/**
638+
* Creates a "not equal ('&lt;&gt;')" condition for this property.
639+
* <p>
640+
* Ignores case when matching results, e.g. {@code notEqual(prop, "example")} excludes both "Example" and "example".
641+
* <p>
642+
* Use {@link #notEqual(Property, String, StringOrder) notEqual(prop, value, StringOrder.CASE_SENSITIVE)} to only exclude
643+
* if case is equal.
644+
* <p>
645+
* Note: Use a case sensitive condition to utilize an {@link io.objectbox.annotation.Index @Index}
646+
* on {@code property}, dramatically speeding up look-up of results.
647+
*/
616648
public QueryBuilder<T> notEqual(Property<T> property, String value) {
617649
verifyHandle();
618650
checkCombineCondition(nativeNotEqual(handle, property.getId(), value, false));
619651
return this;
620652
}
621653

654+
/**
655+
* Creates a "not equal ('&lt;&gt;')" condition for this property.
656+
* <p>
657+
* Set {@code order} to {@link StringOrder#CASE_SENSITIVE StringOrder.CASE_SENSITIVE} to only exclude
658+
* if case is equal. E.g. {@code notEqual(prop, "example", StringOrder.CASE_SENSITIVE)} only excludes "example",
659+
* but not "Example".
660+
* <p>
661+
* Note: Use a case sensitive condition to utilize an {@link io.objectbox.annotation.Index @Index}
662+
* on {@code property}, dramatically speeding up look-up of results.
663+
*/
622664
public QueryBuilder<T> notEqual(Property<T> property, String value, StringOrder order) {
623665
verifyHandle();
624666
checkCombineCondition(nativeNotEqual(handle, property.getId(), value, order == StringOrder.CASE_SENSITIVE));
625667
return this;
626668
}
627669

670+
/**
671+
* Ignores case when matching results. Use the overload and pass
672+
* {@link StringOrder#CASE_SENSITIVE StringOrder.CASE_SENSITIVE} to specify that case should not be ignored.
673+
*/
628674
public QueryBuilder<T> contains(Property<T> property, String value) {
629675
verifyHandle();
630676
checkCombineCondition(nativeContains(handle, property.getId(), value, false));
631677
return this;
632678
}
633679

680+
/**
681+
* Ignores case when matching results. Use the overload and pass
682+
* {@link StringOrder#CASE_SENSITIVE StringOrder.CASE_SENSITIVE} to specify that case should not be ignored.
683+
*/
634684
public QueryBuilder<T> startsWith(Property<T> property, String value) {
635685
verifyHandle();
636686
checkCombineCondition(nativeStartsWith(handle, property.getId(), value, false));
637687
return this;
638688
}
639689

690+
/**
691+
* Ignores case when matching results. Use the overload and pass
692+
* {@link StringOrder#CASE_SENSITIVE StringOrder.CASE_SENSITIVE} to specify that case should not be ignored.
693+
*/
640694
public QueryBuilder<T> endsWith(Property<T> property, String value) {
641695
verifyHandle();
642696
checkCombineCondition(nativeEndsWith(handle, property.getId(), value, false));
@@ -661,6 +715,10 @@ public QueryBuilder<T> endsWith(Property<T> property, String value, StringOrder
661715
return this;
662716
}
663717

718+
/**
719+
* Ignores case when matching results. Use the overload and pass
720+
* {@link StringOrder#CASE_SENSITIVE StringOrder.CASE_SENSITIVE} to specify that case should not be ignored.
721+
*/
664722
public QueryBuilder<T> less(Property<T> property, String value) {
665723
return less(property, value, StringOrder.CASE_INSENSITIVE);
666724
}
@@ -671,6 +729,10 @@ public QueryBuilder<T> less(Property<T> property, String value, StringOrder orde
671729
return this;
672730
}
673731

732+
/**
733+
* Ignores case when matching results. Use the overload and pass
734+
* {@link StringOrder#CASE_SENSITIVE StringOrder.CASE_SENSITIVE} to specify that case should not be ignored.
735+
*/
674736
public QueryBuilder<T> greater(Property<T> property, String value) {
675737
return greater(property, value, StringOrder.CASE_INSENSITIVE);
676738
}
@@ -681,6 +743,10 @@ public QueryBuilder<T> greater(Property<T> property, String value, StringOrder o
681743
return this;
682744
}
683745

746+
/**
747+
* Ignores case when matching results. Use the overload and pass
748+
* {@link StringOrder#CASE_SENSITIVE StringOrder.CASE_SENSITIVE} to specify that case should not be ignored.
749+
*/
684750
public QueryBuilder<T> in(Property<T> property, String[] values) {
685751
return in(property, values, StringOrder.CASE_INSENSITIVE);
686752
}

0 commit comments

Comments
 (0)