Search in sources :

Example 46 with QueryBuilder

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

Example 47 with QueryBuilder

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

Example 48 with QueryBuilder

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

Example 49 with QueryBuilder

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

Example 50 with QueryBuilder

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

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