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);
}
}
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);
}
}
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);
}
}
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);
}
}
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();
}
}
Aggregations