Class QueryBuilder
java.lang.Object
com.atlassian.crowd.search.builder.QueryBuilder
Recommended convenience class to build queries.
Examples are presented below.
- Find all users, return results indexed from 0 to 99
or less:
QueryBuilder.queryFor(User.class, EntityDescriptor.user()).returningAtMost(100);
This is the minimum required structure for a query. - Find all users with the username matching b*, return results
indexed from 100 to 109 or less:
QueryBuilder.queryFor(User.class, EntityDescriptor.user()).with( Restriction.on(UserTermKeys.USERNAME).startingWith("b") ).startingAt(100).returningAtMost(10);
- Find all users that have an attribute 'color' with a value
that matches red* OR scarlet OR crimson, returning results
indexed from 0 to 49 or less:
QueryBuilder.queryFor(User.class, EntityDescriptor.user()).with( Combine.anyOf( Restriction.on(PropertyUtils.ofTypeString("color")).startingWith("red"), Restriction.on(PropertyUtils.ofTypeString("color")).exactlyMatching("scarlet"), Restriction.on(PropertyUtils.ofTypeString("color")).exactlyMatching("crimson") ) ).returningAtMost(50);
- Find all users that like the color red AND blue, returning
results indexed from 0 to 49 (only return usernames):
QueryBuilder.queryFor(String.class, EntityDescriptor.user()).with( Combine.allOf( Restriction.on(PropertyUtils.ofTypeString("color")).exactlyMatching("red"), Restriction.on(PropertyUtils.ofTypeString("color")).exactlyMatching("blue") ) ).returningAtMost(50);
- Find all users that like the color red and have a name
starting "r" or like blue and have a name starting with "b",
returning results indexed from 0 to 9 or less:
QueryBuilder.queryFor(User.class, EntityDescriptor.user()).with( Combine.anyOf( Combine.allOf( Restriction.on(PropertyUtils.ofTypeString("color")).exactlyMatching("red"), Restriction.on(UserTermKeys.USERNAME).startingWith("r") ), Combine.allOf( Restriction.on(PropertyUtils.ofTypeString("color")).exactlyMatching("blue"), Restriction.on(UserTermKeys.USERNAME).startingWith("b") ) ) ).returningAtMost(10);
This is equivalent to verbosely constructing the same query as so:
TermRestriction colorRed = new TermRestriction<String>(PropertyUtils.ofTypeString("color"), MatchMode.EXACTLY_MATCHES, "red"); TermRestriction colorBlue = new TermRestriction<String>(PropertyUtils.ofTypeString("color"), MatchMode.EXACTLY_MATCHES, "blue"); TermRestriction userNameR = new TermRestriction<String>(UserTermKeys.USERNAME, MatchMode.STARTS_WITH, "r"); TermRestriction userNameB = new TermRestriction<String>(UserTermKeys.USERNAME, MatchMode.STARTS_WITH, "b"); BooleanRestriction conjuction1 = new BooleanRestrictionImpl(BooleanRestriction.BooleanLogic.AND, colorRed, userNameR); BooleanRestriction conjuction2 = new BooleanRestrictionImpl(BooleanRestriction.BooleanLogic.AND, colorBlue, userNameB); BooleanRestriction disjunction = new BooleanRestrictionImpl(BooleanRestriction.BooleanLogic.OR, conjuction1, conjuction2); UserQuery query = new UserQuery(User.class, disjunction, 0, 10);
- Find first 10 users of a group:
QueryBuilder.queryFor(User.class, EntityDescriptor.user()).childrenOf(EntityDescriptor.group()).withName("group-name").returningAtMost(10);
- Find first 10 users of a group (returning just the names):
QueryBuilder.queryFor(String.class, EntityDescriptor.user()).childrenOf(EntityDescriptor.group()).withName("group-name").returningAtMost(10);
- Find first 10 groups that are members (children) of a group:
QueryBuilder.queryFor(Group.class, EntityDescriptor.group()).childrenOf(EntityDescriptor.group()).withName("group-name").returningAtMost(10);
- Find first 10 groups that a user belongs to:
QueryBuilder.queryFor(Group.class, EntityDescriptor.group()).parentsOf(EntityDescriptor.user()).withName("user-name").returningAtMost(10);
- Find first 10 groups that a user belongs to (returning just the names):
QueryBuilder.queryFor(String.class, EntityDescriptor.group()).parentsOf(EntityDescriptor.user()).withName("user-name").returningAtMost(10);
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static class
static class
static class
static class
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> MembershipQuery<T>
createMembershipQuery
(int maxResults, int startIndex, boolean findMembers, EntityDescriptor entityToReturn, Class<T> returnType, EntityDescriptor entityToMatch, SearchRestriction searchRestriction, String... namesToMatch) static <T> MembershipQuery<T>
createMembershipQuery
(int maxResults, int startIndex, boolean findMembers, EntityDescriptor entityToReturn, Class<T> returnType, EntityDescriptor entityToMatch, String nameToMatch) Deprecated.static <T> MembershipQuery<T>
createMembershipQuery
(int maxResults, int startIndex, boolean findMembers, EntityDescriptor entityToReturn, Class<T> returnType, EntityDescriptor entityToMatch, String... namesToMatch) Deprecated.static <T> QueryBuilder.PartialEntityQuery<T>
queryFor
(Class<T> returnType, EntityDescriptor entity) static <T> EntityQuery<T>
queryFor
(Class<T> returnType, EntityDescriptor entity, SearchRestriction searchRestriction, int startIndex, int maxResults)
-
Field Details
-
NULL_RESTRICTION
-
-
Constructor Details
-
QueryBuilder
public QueryBuilder()
-
-
Method Details
-
queryFor
public static <T> QueryBuilder.PartialEntityQuery<T> queryFor(Class<T> returnType, EntityDescriptor entity) -
queryFor
public static <T> EntityQuery<T> queryFor(Class<T> returnType, EntityDescriptor entity, SearchRestriction searchRestriction, int startIndex, int maxResults) -
createMembershipQuery
@Deprecated public static <T> MembershipQuery<T> createMembershipQuery(int maxResults, int startIndex, boolean findMembers, EntityDescriptor entityToReturn, Class<T> returnType, EntityDescriptor entityToMatch, String nameToMatch) Deprecated.UsecreateMembershipQuery(int, int, boolean, EntityDescriptor, Class, EntityDescriptor, String...)
instead. Since v2.9. -
createMembershipQuery
@Deprecated public static <T> MembershipQuery<T> createMembershipQuery(int maxResults, int startIndex, boolean findMembers, EntityDescriptor entityToReturn, Class<T> returnType, EntityDescriptor entityToMatch, String... namesToMatch) Deprecated. -
createMembershipQuery
public static <T> MembershipQuery<T> createMembershipQuery(int maxResults, int startIndex, boolean findMembers, EntityDescriptor entityToReturn, Class<T> returnType, EntityDescriptor entityToMatch, SearchRestriction searchRestriction, String... namesToMatch)
-
createMembershipQuery(int, int, boolean, EntityDescriptor, Class, EntityDescriptor, String...)
instead.