Search in sources :

Example 6 with SelectArg

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

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

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

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