Search in sources :

Example 1 with SelectArg

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

the class AuthorizedUserRepository method getByEmail.

public AuthorizedUser getByEmail(String userName) {
    try {
        QueryBuilder<AuthorizedUser, Object> qb = dao.queryBuilder();
        qb.where().eq("email", 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)

Example 2 with SelectArg

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

the class AuthorizedUserRepository method remove.

public void remove(final String userName) {
    try {
        DeleteBuilder<AuthorizedUser, Object> db = dao.deleteBuilder();
        db.where().eq("name", new SelectArg(userName));
        db.delete();
    } catch (SQLException ex) {
        Logger.getLogger(AuthorizedUserRepository.class).error("Error removing a user from DB - ", ex);
    }
}
Also used : SelectArg(com.j256.ormlite.stmt.SelectArg) SQLException(java.sql.SQLException)

Example 3 with SelectArg

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

the class RepositoryUtil method updateVersion.

public static void updateVersion(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));
    List<DatabaseVersion> dbVersions = dbVersionDao.query(queryBuilder.prepare());
    if (!dbVersions.isEmpty()) {
        DeleteBuilder<DatabaseVersion, Object> deleteBuilder = dbVersionDao.deleteBuilder();
        deleteBuilder.where().eq("entity", new SelectArg(entityName));
        deleteBuilder.delete();
    }
    DatabaseVersion databaseVersion = new DatabaseVersion();
    databaseVersion.setEntity(entityName);
    databaseVersion.setVersion(version);
    dbVersionDao.create(databaseVersion);
}
Also used : SelectArg(com.j256.ormlite.stmt.SelectArg)

Example 4 with SelectArg

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

the class RepositoryUtil method isNewBuildRun.

public static boolean isNewBuildRun(ConnectionSource connectionSource, String entityName, Class clazz) throws SQLException {
    // build time checks only for releases, not runtime (e.g. IDE debug)
    // that's check uses for cards db cleanup on new version/build
    String currentBuild = JarVersion.getBuildTime(clazz);
    if (!JarVersion.isBuildTimeOk(currentBuild)) {
        return false;
    }
    TableUtils.createTableIfNotExists(connectionSource, DatabaseBuild.class);
    Dao<DatabaseBuild, Object> dbBuildDao = DaoManager.createDao(connectionSource, DatabaseBuild.class);
    QueryBuilder<DatabaseBuild, Object> queryBuilder = dbBuildDao.queryBuilder();
    queryBuilder.where().eq("entity", new SelectArg(entityName)).and().eq("last_build", new SelectArg(currentBuild));
    List<DatabaseBuild> dbBuilds = dbBuildDao.query(queryBuilder.prepare());
    if (dbBuilds.isEmpty()) {
        DatabaseBuild dbBuild = new DatabaseBuild();
        dbBuild.setEntity(entityName);
        dbBuild.setLastBuild(currentBuild);
        dbBuildDao.create(dbBuild);
    }
    return dbBuilds.isEmpty();
}
Also used : SelectArg(com.j256.ormlite.stmt.SelectArg)

Example 5 with SelectArg

use of com.j256.ormlite.stmt.SelectArg 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)

Aggregations

SelectArg (com.j256.ormlite.stmt.SelectArg)8 SQLException (java.sql.SQLException)3 Where (com.j256.ormlite.stmt.Where)1 CardType (mage.constants.CardType)1 Rarity (mage.constants.Rarity)1 SubType (mage.constants.SubType)1 SuperType (mage.constants.SuperType)1