Search in sources :

Example 51 with QueryBuilder

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);
    }
}
Also used : SQLException(java.sql.SQLException) QueryBuilder(com.j256.ormlite.stmt.QueryBuilder) Where(com.j256.ormlite.stmt.Where)

Example 52 with QueryBuilder

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);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) QueryBuilder(com.j256.ormlite.stmt.QueryBuilder) Where(com.j256.ormlite.stmt.Where)

Example 53 with QueryBuilder

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);
    }
}
Also used : SQLException(java.sql.SQLException) QueryBuilder(com.j256.ormlite.stmt.QueryBuilder) Where(com.j256.ormlite.stmt.Where)

Example 54 with QueryBuilder

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<>();
    }
}
Also used : SelectArg(com.j256.ormlite.stmt.SelectArg) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Food(com.faltenreich.diaguard.shared.data.database.entity.Food)

Aggregations

SQLException (java.sql.SQLException)44 QueryBuilder (com.j256.ormlite.stmt.QueryBuilder)43 Where (com.j256.ormlite.stmt.Where)38 SelectArg (com.j256.ormlite.stmt.SelectArg)9 ArrayList (java.util.ArrayList)6 List (java.util.List)4 DatabaseHelper (ca.etsmtl.applets.etsmobile.db.DatabaseHelper)3 ElementEvaluation (ca.etsmtl.applets.etsmobile.model.ElementEvaluation)2 NonNull (androidx.annotation.NonNull)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 FicheEmploye (ca.etsmtl.applets.etsmobile.model.FicheEmploye)1 ExpandableListAdapter (ca.etsmtl.applets.etsmobile.ui.adapter.ExpandableListAdapter)1 Entry (com.faltenreich.diaguard.shared.data.database.entity.Entry)1 EntryTag (com.faltenreich.diaguard.shared.data.database.entity.EntryTag)1 Food (com.faltenreich.diaguard.shared.data.database.entity.Food)1 Tag (com.faltenreich.diaguard.shared.data.database.entity.Tag)1 Disease (de.symeda.sormas.api.Disease)1 FeatureTypeProperty (de.symeda.sormas.api.feature.FeatureTypeProperty)1 UserRole (de.symeda.sormas.api.user.UserRole)1 Date (java.util.Date)1