use of com.j256.ormlite.stmt.QueryBuilder in project SORMAS-Project by hzi-braunschweig.
the class TaskDao method queryAllDoneOrRemoved.
/**
* Gets all done and discarded tasks.
* Ordered by due date - newest first
* TODO split - #942
*
* @return
*/
public List<Task> queryAllDoneOrRemoved() {
try {
QueryBuilder builder = queryBuilder();
Where where = builder.where();
where.and(where.eq(AbstractDomainObject.SNAPSHOT, false), where.or(where.eq(Task.ASSIGNEE_USER + "_id", ConfigProvider.getUser()), where.eq(Task.CREATOR_USER + "_id", ConfigProvider.getUser())), where.eq(Task.TASK_STATUS, TaskStatus.DONE).or().eq(Task.TASK_STATUS, TaskStatus.REMOVED));
return builder.orderBy(Task.PRIORITY, true).orderBy(Task.DUE_DATE, true).query();
} catch (SQLException e) {
android.util.Log.e(getTableName(), "Could not perform queryAllDoneOrRemoved on Task");
throw new RuntimeException(e);
}
}
use of com.j256.ormlite.stmt.QueryBuilder in project SORMAS-Project by hzi-braunschweig.
the class TaskDao method queryMyPendingForNotification.
/**
* query for the following PENDING tasks:
* 1. suggested start within range
* 2. due date within range
* 3. localChangeDate within range, not modified (-> has been updated on server) and suggested start before end of range
* Ordered by priority, then due date - oldes (most due) first
* Typically, the range is the interval between two notification polls (e.g. 2 minutes)
*
* @return
*/
public List<Task> queryMyPendingForNotification(Date rangeStart, Date rangeEnd) {
if (ConfigProvider.getUser() == null) {
return new ArrayList<Task>();
}
try {
QueryBuilder builder = queryBuilder();
Where where = builder.where();
where.and(where.eq(AbstractDomainObject.SNAPSHOT, false), where.eq(Task.ASSIGNEE_USER + "_id", ConfigProvider.getUser()), where.eq(Task.TASK_STATUS, TaskStatus.PENDING), where.or(where.between(Task.SUGGESTED_START, rangeStart, rangeEnd), where.between(Task.DUE_DATE, rangeStart, rangeEnd), where.and(where.between(Task.LOCAL_CHANGE_DATE, rangeStart, rangeEnd), where.eq(Task.MODIFIED, false), where.or(where.raw(Task.LAST_OPENED_DATE + " < " + Task.LOCAL_CHANGE_DATE), where.isNull(Task.LAST_OPENED_DATE)), where.le(Task.SUGGESTED_START, rangeEnd))));
builder.orderBy(Task.PRIORITY, true).orderBy(Task.DUE_DATE, true);
builder.prepareStatementString();
return builder.query();
} catch (SQLException e) {
android.util.Log.e(getTableName(), "Could not perform queryMyPendingForNotification on Task");
throw new RuntimeException(e);
}
}
use of com.j256.ormlite.stmt.QueryBuilder in project SORMAS-Project by hzi-braunschweig.
the class TaskDao method queryAllPending.
/**
* Gets all pending tasks.
* Ordered by priority, then due date - oldest (most due) first
* TODO split - #942
*
* @return
*/
public List<Task> queryAllPending() {
try {
QueryBuilder builder = queryBuilder();
Where where = builder.where();
where.and(where.eq(AbstractDomainObject.SNAPSHOT, false), where.or(where.eq(Task.ASSIGNEE_USER + "_id", ConfigProvider.getUser()), where.eq(Task.CREATOR_USER + "_id", ConfigProvider.getUser())), where.eq(Task.TASK_STATUS, TaskStatus.PENDING));
return builder.orderBy(Task.PRIORITY, true).orderBy(Task.DUE_DATE, true).query();
} catch (SQLException e) {
android.util.Log.e(getTableName(), "Could not perform queryAllPending on Task");
throw new RuntimeException(e);
}
}
use of com.j256.ormlite.stmt.QueryBuilder in project Diaguard by Faltenreich.
the class FoodDao method search.
public List<Food> search(String query, long page, boolean showCustomFood, boolean showCommonFood, boolean showBrandedFood) {
if (!showCustomFood && !showCommonFood && !showBrandedFood) {
return new ArrayList<>();
}
try {
QueryBuilder<Food, Long> queryBuilder = getQueryBuilder().orderByRaw(String.format("%s COLLATE NOCASE", Food.Column.NAME)).orderBy(Food.Column.UPDATED_AT, false).offset(page * BaseDao.PAGE_SIZE).limit(BaseDao.PAGE_SIZE);
Where<Food, Long> where = queryBuilder.where();
where.isNull(Food.Column.DELETED_AT);
if (query != null && query.length() > 0) {
where.and();
where.like(Food.Column.NAME, new SelectArg("%" + query + "%"));
}
int whereTypeCount = 0;
if (showCustomFood) {
where.isNull(Food.Column.LABELS);
where.isNull(Food.Column.SERVER_ID);
where.and(2);
whereTypeCount++;
}
if (showCommonFood) {
where.isNotNull(Food.Column.LABELS);
where.isNull(Food.Column.SERVER_ID);
where.and(2);
whereTypeCount++;
}
if (showBrandedFood) {
where.isNotNull(Food.Column.SERVER_ID);
whereTypeCount++;
}
where.or(whereTypeCount);
where.and(2);
return where.query();
} catch (SQLException exception) {
Log.e(TAG, exception.toString());
return new ArrayList<>();
}
}
Aggregations