本文整理匯總了Java中com.j256.ormlite.stmt.Where.or方法的典型用法代碼示例。如果您正苦於以下問題:Java Where.or方法的具體用法?Java Where.or怎麽用?Java Where.or使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.j256.ormlite.stmt.Where
的用法示例。
在下文中一共展示了Where.or方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testUseOfOrMany
import com.j256.ormlite.stmt.Where; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void testUseOfOrMany() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
assertEquals(0, dao.countOf());
Foo foo = new Foo();
int id = 1;
foo.id = id;
int val = 1231231;
foo.val = val;
assertEquals(1, dao.create(foo));
int notId = id + 1;
foo.id = notId;
foo.val = val + 1;
assertEquals(1, dao.create(foo));
Where<Foo, Integer> where = dao.queryBuilder().where();
where.or(where.eq(Foo.ID_FIELD_NAME, id), where.eq(Foo.ID_FIELD_NAME, notId),
where.eq(Foo.VAL_FIELD_NAME, val + 1), where.eq(Foo.VAL_FIELD_NAME, val + 1));
List<Foo> results = where.query();
assertEquals(2, results.size());
assertEquals(id, results.get(0).id);
assertEquals(notId, results.get(1).id);
}
示例2: testUseOfOrMany
import com.j256.ormlite.stmt.Where; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void testUseOfOrMany() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
assertEquals(0, dao.countOf());
Foo foo = new Foo();
int id = 1;
foo.id = id;
int val = 1231231;
foo.val = val;
assertEquals(1, dao.create(foo));
int notId = id + 1;
foo.id = notId;
foo.val = val + 1;
assertEquals(1, dao.create(foo));
Where<Foo, Integer> where = dao.queryBuilder().where();
where.or(where.eq(Foo.ID_FIELD_NAME, id), where.eq(Foo.ID_FIELD_NAME, notId),
where.eq(Foo.VAL_FIELD_NAME, val + 1), where.eq(Foo.VAL_FIELD_NAME, val + 1));
List<Foo> results = where.query();
assertEquals(2, results.size());
assertEquals(id, results.get(0).id);
assertEquals(notId, results.get(1).id);
}
示例3: testUseOfOrInt
import com.j256.ormlite.stmt.Where; //導入方法依賴的package包/類
public void testUseOfOrInt() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
assertEquals(0, dao.countOf());
Foo foo = new Foo();
int id = 1;
foo.id = id;
int val = 1231231;
foo.val = val;
assertEquals(1, dao.create(foo));
int notId = id + 1;
foo.id = notId;
foo.val = val + 1;
assertEquals(1, dao.create(foo));
Where<Foo, Integer> where = dao.queryBuilder().where();
where.eq(Foo.ID_FIELD_NAME, id);
where.eq(Foo.ID_FIELD_NAME, notId);
where.eq(Foo.VAL_FIELD_NAME, val + 1);
where.eq(Foo.VAL_FIELD_NAME, val + 1);
where.or(4);
List<Foo> results = where.query();
assertEquals(2, results.size());
assertEquals(id, results.get(0).id);
assertEquals(notId, results.get(1).id);
}
示例4: testUseOfOrMany
import com.j256.ormlite.stmt.Where; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void testUseOfOrMany() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
assertEquals(0, dao.countOf());
Foo foo1 = new Foo();
int val = 1231231;
foo1.val = val;
assertEquals(1, dao.create(foo1));
Foo foo2 = new Foo();
foo2.val = val + 1;
assertEquals(1, dao.create(foo2));
Where<Foo, Integer> where = dao.queryBuilder().where();
where.or(where.eq(Foo.ID_COLUMN_NAME, foo1.id), where.eq(Foo.ID_COLUMN_NAME, foo2.id),
where.eq(Foo.VAL_COLUMN_NAME, val), where.eq(Foo.VAL_COLUMN_NAME, foo2.val));
List<Foo> results = where.query();
assertEquals(2, results.size());
assertEquals(foo1.id, results.get(0).id);
assertEquals(foo2.id, results.get(1).id);
}
示例5: testUseOfOrInt
import com.j256.ormlite.stmt.Where; //導入方法依賴的package包/類
@Test
public void testUseOfOrInt() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
assertEquals(0, dao.countOf());
Foo foo1 = new Foo();
int val = 1231231;
foo1.val = val;
assertEquals(1, dao.create(foo1));
Foo foo2 = new Foo();
foo2.val = val + 1;
assertEquals(1, dao.create(foo2));
Where<Foo, Integer> where = dao.queryBuilder().where();
where.eq(Foo.ID_COLUMN_NAME, foo1.id);
where.eq(Foo.ID_COLUMN_NAME, foo2.id);
where.eq(Foo.VAL_COLUMN_NAME, val);
where.eq(Foo.VAL_COLUMN_NAME, val + 1);
where.or(4);
List<Foo> results = where.query();
assertEquals(2, results.size());
assertEquals(foo1.id, results.get(0).id);
assertEquals(foo2.id, results.get(1).id);
}
示例6: queryNotEqualsByColumnName
import com.j256.ormlite.stmt.Where; //導入方法依賴的package包/類
/**
* 查詢列名不等於指定值的記錄
*
* @param columnName 列名
* @param value 指定值
*/
public List<T> queryNotEqualsByColumnName(String columnName, Object value) {
List<T> list = null;
QueryBuilder queryBuilder = ormLiteDao.queryBuilder();
Where where = queryBuilder.where();
try {
where.or(where.gt(columnName, value), where.lt(columnName, value));
list = queryBuilder.query();
} catch (SQLException e) {
LogUtils.e(e);
}
return list;
}
示例7: orWhereClauses
import com.j256.ormlite.stmt.Where; //導入方法依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void orWhereClauses(Where<DBProcessedAudit, Integer> where, List<Where<DBProcessedAudit, Integer>> clauses) {
// If list contains one clause, nothing needs to be done.
if (clauses.size() == 2) {
where.or(clauses.get(0), clauses.get(1));
} else if (clauses.size() > 2) {
where.or(clauses.get(0), clauses.get(1), clauses.subList(2, clauses.size()).toArray((Where<DBProcessedAudit, Integer>[]) new Where[clauses.size() - 2]));
}
}
示例8: testUseOfOrInt
import com.j256.ormlite.stmt.Where; //導入方法依賴的package包/類
@Test
public void testUseOfOrInt() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
assertEquals(0, dao.countOf());
Foo foo = new Foo();
int id = 1;
foo.id = id;
int val = 1231231;
foo.val = val;
assertEquals(1, dao.create(foo));
int notId = id + 1;
foo.id = notId;
foo.val = val + 1;
assertEquals(1, dao.create(foo));
Where<Foo, Integer> where = dao.queryBuilder().where();
where.eq(Foo.ID_FIELD_NAME, id);
where.eq(Foo.ID_FIELD_NAME, notId);
where.eq(Foo.VAL_FIELD_NAME, val + 1);
where.eq(Foo.VAL_FIELD_NAME, val + 1);
where.or(4);
List<Foo> results = where.query();
assertEquals(2, results.size());
assertEquals(id, results.get(0).id);
assertEquals(notId, results.get(1).id);
}
示例9: findByNameOrCn
import com.j256.ormlite.stmt.Where; //導入方法依賴的package包/類
/**
* Fin prescriptions by name or cn, ordering by the position of the match
*
* @param match String to search by
* @param limit maximum number of results
* @return The list of prescriptions that match
*/
public List<Prescription> findByNameOrCn(final String match, final int limit) {
try {
LogUtil.d(TAG, "Query by name: " + match);
QueryBuilder<Prescription, Long> qb = dao.queryBuilder();
Where w = qb.where();
w.or(w.like(Prescription.COLUMN_NAME, "%" + match + "%"), w.like(Prescription.COLUMN_CODE, match + "%"));
qb.orderByRaw(" (CASE WHEN " + Prescription.COLUMN_NAME + " LIKE \"" + match + "%\" THEN 1 ELSE 2 END),name");
qb.limit((long) limit);
qb.setWhere(w);
return qb.query();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
示例10: getItemsCursor
import com.j256.ormlite.stmt.Where; //導入方法依賴的package包/類
public static Cursor getItemsCursor(CharSequence nameConstraint, Collection<ItemType> itemTypes, String itemCategory) {
try {
RuntimeExceptionDao<Item, UUID> itemDao = DsaTabApplication.getInstance().getDBHelper().getItemDao();
PreparedQuery<Item> query = null;
QueryBuilder<Item, UUID> builder = itemDao.queryBuilder();
if (TextUtils.isEmpty(nameConstraint) && (itemTypes == null || itemTypes.isEmpty())
&& TextUtils.isEmpty(itemCategory)) {
query = builder.prepare();
} else {
Where<Item, UUID> where = builder.where();
int stmtCount=0;
if (!TextUtils.isEmpty(nameConstraint)) {
String name = nameConstraint.toString();
if (name.contains("%")) {
where.like("name", nameConstraint);
} else {
where.like("name", nameConstraint + "%");
}
stmtCount++;
}
if (!TextUtils.isEmpty(itemCategory)) {
where.eq("category", itemCategory);
stmtCount++;
}
if (itemTypes != null && !itemTypes.isEmpty()) {
for (ItemType type : itemTypes) {
where.like("itemTypes", "%;" + type.name() + ";%");
}
if (itemTypes.size() > 1) {
where.or(itemTypes.size());
}
stmtCount++;
}
if (stmtCount > 1) {
where.and(stmtCount);
}
query = where.prepare();
}
Cursor cursor = getCursor(query,itemDao.getTableName());
cursor.setNotificationUri(DsaTabApplication.getInstance().getContentResolver(), ITEMS_URI);
return cursor;
} catch (SQLException e) {
Debug.e(e);
}
return null;
}