Search in sources :

Example 21 with QueryBuilder

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

the class NoteManager method getElementsEvaluation.

public List<ElementEvaluation> getElementsEvaluation(ListeDesElementsEvaluation listeDesElementsEvaluation) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    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();
    } catch (SQLException e) {
        Log.e("SQL Exception", e.getMessage());
    }
    return elementEvaluationList;
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) SQLException(java.sql.SQLException) Where(com.j256.ormlite.stmt.Where) ElementEvaluation(ca.etsmtl.applets.etsmobile.model.ElementEvaluation)

Example 22 with QueryBuilder

use of com.j256.ormlite.stmt.QueryBuilder in project mage by magefree.

the class CardCriteria method buildQuery.

public void buildQuery(QueryBuilder qb) throws SQLException {
    optimize();
    Where where = qb.where();
    where.eq("nightCard", false);
    where.eq("splitCardHalf", false);
    int clausesCount = 2;
    if (name != null) {
        where.like("name", new SelectArg('%' + name + '%'));
        clausesCount++;
    }
    if (nameExact != null) {
        where.like("name", new SelectArg(nameExact));
        clausesCount++;
    }
    if (rules != null) {
        where.like("rules", new SelectArg('%' + rules + '%'));
        clausesCount++;
    }
    if (doubleFaced != null) {
        where.eq("doubleFaced", doubleFaced);
        clausesCount++;
    }
    if (modalDoubleFaced != null) {
        where.eq("modalDoubleFacesCard", modalDoubleFaced);
        clausesCount++;
    }
    for (Rarity rarity : rarities) {
        where.eq("rarity", rarity);
    }
    if (!rarities.isEmpty()) {
        where.or(rarities.size());
        clausesCount++;
    }
    for (String setCode : setCodes) {
        where.eq("setCode", setCode);
    }
    if (!setCodes.isEmpty()) {
        where.or(setCodes.size());
        clausesCount++;
    }
    for (String ignoreSetCode : ignoreSetCodes) {
        where.ne("setCode", ignoreSetCode);
    }
    if (!ignoreSetCodes.isEmpty()) {
        where.or(ignoreSetCodes.size());
        clausesCount++;
    }
    if (types.size() != 7) {
        // if all types selected - no selection needed (Tribal and Conspiracy not selectable yet)
        for (CardType type : types) {
            where.like("types", new SelectArg('%' + type.name() + '%'));
        }
        if (!types.isEmpty()) {
            where.or(types.size());
            clausesCount++;
        }
    }
    for (CardType type : notTypes) {
        where.not().like("types", new SelectArg('%' + type.name() + '%'));
        clausesCount++;
    }
    for (SuperType superType : supertypes) {
        where.like("supertypes", new SelectArg('%' + superType.name() + '%'));
        clausesCount++;
    }
    for (SuperType superType : notSupertypes) {
        where.not().like("supertypes", new SelectArg('%' + superType.name() + '%'));
        clausesCount++;
    }
    for (SubType subType : subtypes) {
        where.like("subtypes", new SelectArg('%' + subType.toString() + '%'));
        clausesCount++;
    }
    if (manaValue != null) {
        where.eq("manaValue", manaValue);
        clausesCount++;
    }
    int colorClauses = 0;
    if (black) {
        where.eq("black", true);
        colorClauses++;
    }
    if (blue) {
        where.eq("blue", true);
        colorClauses++;
    }
    if (green) {
        where.eq("green", true);
        colorClauses++;
    }
    if (red) {
        where.eq("red", true);
        colorClauses++;
    }
    if (white) {
        where.eq("white", true);
        colorClauses++;
    }
    if (colorless) {
        where.eq("black", false).eq("blue", false).eq("green", false).eq("red", false).eq("white", false);
        where.and(5);
        colorClauses++;
    }
    if (colorClauses > 0) {
        where.or(colorClauses);
        clausesCount++;
    }
    if (minCardNumber != Integer.MIN_VALUE) {
        where.ge("cardNumberAsInt", minCardNumber);
        clausesCount++;
    }
    if (maxCardNumber != Integer.MAX_VALUE) {
        where.le("cardNumberAsInt", maxCardNumber);
        clausesCount++;
    }
    if (clausesCount > 0) {
        where.and(clausesCount);
    } else {
        where.eq("cardNumber", new SelectArg(0));
    }
    if (start != null) {
        qb.offset(start);
    }
    if (count != null) {
        qb.limit(count);
    }
    if (sortBy != null) {
        qb.orderBy(sortBy, true);
    }
}
Also used : Rarity(mage.constants.Rarity) SelectArg(com.j256.ormlite.stmt.SelectArg) SubType(mage.constants.SubType) CardType(mage.constants.CardType) Where(com.j256.ormlite.stmt.Where) SuperType(mage.constants.SuperType)

Example 23 with QueryBuilder

use of com.j256.ormlite.stmt.QueryBuilder in project mage by magefree.

the class RepositoryUtil method isDatabaseObsolete.

public static boolean isDatabaseObsolete(ConnectionSource connectionSource, String entityName, long version) throws SQLException {
    TableUtils.createTableIfNotExists(connectionSource, DatabaseVersion.class);
    Dao<DatabaseVersion, Object> dbVersionDao = DaoManager.createDao(connectionSource, DatabaseVersion.class);
    QueryBuilder<DatabaseVersion, Object> queryBuilder = dbVersionDao.queryBuilder();
    queryBuilder.where().eq("entity", new SelectArg(entityName)).and().eq("version", new SelectArg(version));
    List<DatabaseVersion> dbVersions = dbVersionDao.query(queryBuilder.prepare());
    if (dbVersions.isEmpty()) {
        DatabaseVersion dbVersion = new DatabaseVersion();
        dbVersion.setEntity(entityName);
        dbVersion.setVersion(version);
        dbVersionDao.create(dbVersion);
    }
    return dbVersions.isEmpty();
}
Also used : SelectArg(com.j256.ormlite.stmt.SelectArg)

Example 24 with QueryBuilder

use of com.j256.ormlite.stmt.QueryBuilder in project mage by magefree.

the class RepositoryUtil method getDatabaseVersion.

public static long getDatabaseVersion(ConnectionSource connectionSource, String entityName) throws SQLException {
    TableUtils.createTableIfNotExists(connectionSource, DatabaseVersion.class);
    Dao<DatabaseVersion, Object> dbVersionDao = DaoManager.createDao(connectionSource, DatabaseVersion.class);
    QueryBuilder<DatabaseVersion, Object> queryBuilder = dbVersionDao.queryBuilder();
    queryBuilder.where().eq("entity", new SelectArg(entityName));
    List<DatabaseVersion> dbVersions = dbVersionDao.query(queryBuilder.prepare());
    if (dbVersions.isEmpty()) {
        return 0;
    } else {
        return dbVersions.get(0).getVersion();
    }
}
Also used : SelectArg(com.j256.ormlite.stmt.SelectArg)

Example 25 with QueryBuilder

use of com.j256.ormlite.stmt.QueryBuilder in project mage by magefree.

the class AuthorizedUserRepository method getByName.

public AuthorizedUser getByName(String userName) {
    try {
        QueryBuilder<AuthorizedUser, Object> qb = dao.queryBuilder();
        qb.where().eq("name", new SelectArg(userName));
        List<AuthorizedUser> results = dao.query(qb.prepare());
        if (results.size() == 1) {
            return results.get(0);
        }
        return null;
    } catch (SQLException ex) {
        Logger.getLogger(AuthorizedUserRepository.class).error("Error getting a authorized_user - ", ex);
    }
    return null;
}
Also used : SelectArg(com.j256.ormlite.stmt.SelectArg) SQLException(java.sql.SQLException)

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