use of com.j256.ormlite.stmt.QueryBuilder in project SORMAS-Project by hzi-braunschweig.
the class FeatureConfigurationDao method deleteExpiredFeatureConfigurations.
public void deleteExpiredFeatureConfigurations() {
try {
QueryBuilder builder = queryBuilder();
Where where = builder.where();
where.isNotNull(FeatureConfiguration.END_DATE);
where.and().lt(FeatureConfiguration.END_DATE, new Date());
List<FeatureConfiguration> result = builder.query();
if (result != null) {
for (FeatureConfiguration config : result) {
delete(config);
}
}
} catch (SQLException e) {
Log.e(getTableName(), "Could not perform deleteExpiredFeatureConfigurations");
throw new RuntimeException(e);
}
}
use of com.j256.ormlite.stmt.QueryBuilder in project SORMAS-Project by hzi-braunschweig.
the class FeatureConfigurationDao method isPropertyValueTrue.
public boolean isPropertyValueTrue(FeatureType featureType, FeatureTypeProperty property) {
if (!featureType.getSupportedProperties().contains(property)) {
throw new IllegalArgumentException("Feature type " + featureType + " does not support property " + property + ".");
}
if (!Boolean.class.isAssignableFrom(property.getReturnType())) {
throw new IllegalArgumentException("Feature type property " + property + " does not have specified return type " + Boolean.class.getSimpleName() + ".");
}
Map<FeatureTypeProperty, Object> propertyObjectMap;
try {
QueryBuilder builder = queryBuilder();
Where where = builder.where();
where.eq(FeatureConfiguration.FEATURE_TYPE, featureType);
builder.selectColumns(FeatureConfiguration.PROPERTIES);
FeatureConfiguration featureConfiguration = (FeatureConfiguration) builder.queryForFirst();
if (featureConfiguration != null && featureConfiguration.getPropertiesJson() != null) {
propertyObjectMap = featureConfiguration.getPropertiesMap();
} else {
return featureType.getSupportedPropertyDefaults().get(property) == Boolean.TRUE;
}
} catch (SQLException e) {
Log.e(getTableName(), "Could not perform isPropertyValueTrue");
throw new RuntimeException(e);
}
boolean result;
if (propertyObjectMap != null && propertyObjectMap.containsKey(property)) {
result = propertyObjectMap.get(property) == Boolean.TRUE;
} else {
// Compare the expected property value with the default value
result = featureType.getSupportedPropertyDefaults().get(property) == Boolean.TRUE;
}
return result;
}
use of com.j256.ormlite.stmt.QueryBuilder in project SORMAS-Project by hzi-braunschweig.
the class SampleDao method getReferredFrom.
public Sample getReferredFrom(String sampleUuid) {
try {
QueryBuilder qb = queryBuilder();
qb.where().eq(Sample.REFERRED_TO_UUID, sampleUuid).and().eq(AbstractDomainObject.SNAPSHOT, false);
return (Sample) qb.queryForFirst();
} catch (SQLException e) {
Log.e(getTableName(), "Could not perform getReferredFrom on Sample");
throw new RuntimeException(e);
}
}
use of com.j256.ormlite.stmt.QueryBuilder in project SORMAS-Project by hzi-braunschweig.
the class WeeklyReportDao method queryByEpiWeekAndUser.
public WeeklyReport queryByEpiWeekAndUser(EpiWeek epiWeek, User user) {
if (!(ConfigProvider.hasUserRight(UserRight.WEEKLYREPORT_CREATE))) {
throw new IllegalArgumentException("queryByEpiWeekAndUser is only supported for users who can create weekly reports");
}
try {
QueryBuilder builder = queryBuilder();
Where where = builder.where();
where.and(where.eq(WeeklyReport.REPORTING_USER + "_id", user), where.eq(WeeklyReport.YEAR, epiWeek.getYear()), where.eq(WeeklyReport.EPI_WEEK, epiWeek.getWeek()));
WeeklyReport result = (WeeklyReport) builder.queryForFirst();
initLazyData(result);
return result;
} 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 OutbreakDao method hasOutbreak.
public boolean hasOutbreak(District district, Disease disease) {
try {
QueryBuilder builder = queryBuilder();
Where where = builder.where();
where.and(where.eq(Outbreak.DISTRICT, district), where.eq(Outbreak.DISEASE, disease));
int result = (int) builder.countOf();
return result > 0;
} catch (SQLException e) {
Log.e(getTableName(), "Could not perform getNumberOfCasesForEpiWeekAndDisease");
throw new RuntimeException(e);
}
}
Aggregations