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;
}
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);
}
}
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();
}
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();
}
}
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;
}
Aggregations