Search in sources :

Example 16 with QueryBuilder

use of com.j256.ormlite.stmt.QueryBuilder in project SORMAS-Project by hzi-braunschweig.

the class UserDao method getByDistrictAndRole.

public List<User> getByDistrictAndRole(District district, UserRole role, String orderBy) {
    try {
        QueryBuilder builder = queryBuilder();
        Where where = builder.where();
        where.and(where.eq(User.DISTRICT + "_id", district.getId()), createRoleFilter(role, where));
        return (List<User>) builder.orderBy(orderBy, true).query();
    } catch (SQLException e) {
        Log.e(getTableName(), "Could not perform getByDistrictAndRole");
        throw new RuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) List(java.util.List) QueryBuilder(com.j256.ormlite.stmt.QueryBuilder) Where(com.j256.ormlite.stmt.Where)

Example 17 with QueryBuilder

use of com.j256.ormlite.stmt.QueryBuilder in project SORMAS-Project by hzi-braunschweig.

the class TaskDao method queryAllNotExecutable.

/**
 * Gets all not executable tasks.
 * Ordered by due date - newest first
 * TODO split - #942
 *
 * @return
 */
public List<Task> queryAllNotExecutable() {
    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.NOT_EXECUTABLE));
        return builder.orderBy(Task.PRIORITY, true).orderBy(Task.DUE_DATE, true).query();
    } catch (SQLException e) {
        android.util.Log.e(getTableName(), "Could not perform queryAllNotExecutable 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 18 with QueryBuilder

use of com.j256.ormlite.stmt.QueryBuilder in project SORMAS-Project by hzi-braunschweig.

the class AggregateReportDao method getReportsByEpiWeekAndUser.

public List<AggregateReport> getReportsByEpiWeekAndUser(EpiWeek epiWeek, User user) {
    try {
        QueryBuilder builder = queryBuilder();
        Where where = builder.where();
        where.and(where.eq(AbstractDomainObject.SNAPSHOT, false), where.eq(AggregateReport.REPORTING_USER + "_id", user), where.eq(AggregateReport.YEAR, epiWeek.getYear()), where.eq(AggregateReport.EPI_WEEK, epiWeek.getWeek()));
        List<AggregateReport> reports = builder.query();
        Set<Disease> diseasesWithReports = new HashSet<>();
        for (AggregateReport report : reports) {
            diseasesWithReports.add(report.getDisease());
        }
        List<Disease> aggregateDiseases = DiseaseConfigurationCache.getInstance().getAllDiseases(true, null, false);
        for (Disease disease : aggregateDiseases) {
            if (!diseasesWithReports.contains(disease)) {
                reports.add(build(disease, epiWeek));
            }
        }
        Collections.sort(reports, new Comparator<AggregateReport>() {

            @Override
            public int compare(AggregateReport o1, AggregateReport o2) {
                return o1.getDisease().toString().compareTo(o2.getDisease().toString());
            }
        });
        return reports;
    } catch (SQLException e) {
        Log.e(getTableName(), "Could not perform queryByEpiWeekAndUser");
        throw new RuntimeException(e);
    }
}
Also used : Disease(de.symeda.sormas.api.Disease) SQLException(java.sql.SQLException) QueryBuilder(com.j256.ormlite.stmt.QueryBuilder) Where(com.j256.ormlite.stmt.Where) HashSet(java.util.HashSet)

Example 19 with QueryBuilder

use of com.j256.ormlite.stmt.QueryBuilder in project SORMAS-Project by hzi-braunschweig.

the class PointOfEntryDao method hasActiveEntriesInDistrict.

/**
 * Checks whether the database contains at least one active point of entry within the user's district.
 */
public boolean hasActiveEntriesInDistrict() {
    try {
        QueryBuilder builder = queryBuilder();
        Where where = builder.where();
        where.and(where.eq(PointOfEntry.DISTRICT + "_id", ConfigProvider.getUser().getDistrict().getId()), where.eq(InfrastructureAdo.ARCHIVED, false), where.eq(AbstractDomainObject.SNAPSHOT, false), where.ne(PointOfEntry.ACTIVE, false));
        return builder.queryForFirst() != null;
    } catch (SQLException | IllegalArgumentException e) {
        Log.e(getTableName(), "Could not perform hasActiveEntriesInDistrict");
        throw new RuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) QueryBuilder(com.j256.ormlite.stmt.QueryBuilder) Where(com.j256.ormlite.stmt.Where)

Example 20 with QueryBuilder

use of com.j256.ormlite.stmt.QueryBuilder in project ETSMobile-Android2 by ApplETS.

the class NoteManager method deleteExpiredElementsEvaluation.

/**
 * Deletes marks in DB that doesn't exist on API
 *
 * @param
 */
public void deleteExpiredElementsEvaluation(ListeDesElementsEvaluation listeDesElementsEvaluation) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    HashMap<String, ElementEvaluation> elementEvaluationHashMap = new HashMap<String, ElementEvaluation>();
    for (ElementEvaluation elem : listeDesElementsEvaluation.liste) {
        String id = listeDesElementsEvaluation.id + elem.nom;
        elementEvaluationHashMap.put(id, elem);
    }
    List<ElementEvaluation> elementEvaluationList = null;
    try {
        Dao<ElementEvaluation, String> elementsEvaluationDao = dbHelper.getDao(ElementEvaluation.class);
        QueryBuilder<ElementEvaluation, String> builder = elementsEvaluationDao.queryBuilder();
        Where where = builder.where();
        where.eq("listeDesElementsEvaluation_id", listeDesElementsEvaluation);
        elementEvaluationList = builder.query();
        for (ElementEvaluation element : elementEvaluationList) {
            if (!elementEvaluationHashMap.containsKey(element.id))
                elementsEvaluationDao.deleteById(element.id);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Where(com.j256.ormlite.stmt.Where) ElementEvaluation(ca.etsmtl.applets.etsmobile.model.ElementEvaluation)

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