The following snipped creates your expected query:
TaskQuery orConditions = TaskQuery.create()
.where().state().isEqual(TaskState.SUSPENDED)
.or().state().isEqual(TaskState.RESUMED)
.or().state().isEqual(TaskState.PARKED);
TaskQuery query = TaskQuery.create()
.where().and(orConditions)
.orderBy().priority();
query.where().applicationId().isEqual(1);
Resulting Query:
SELECT *
FROM IWA_Task
WHERE ((Column(IWA_TaskQuery.State) WHERE
(
( Column(IWA_TaskQuery.State) = 4
|| Column(IWA_TaskQuery.State) = 5
|| Column(IWA_TaskQuery.State) = 8)
8
)
&&
Column(IWA_TaskQuery.ApplicationId) = 1) 1
)
ORDER BY Column(CurrentPriority) ASCENDING
Way 1: The first 'operator' is a OR-operator. As a result, the root-operator is a or-operator and therefore any further operators are attached to this root-(or-)operator, which results in your written condition.
Way 2: The method `and(TaskQuery q)` doesn only take the filter (the where-condition) from the passed query.
I would say: the TaskQuery API is a perfect fluent API. When using it to combine multiple condition is is a bit tricky...