Java Code Examples for com.j256.ormlite.stmt.Where#or()
The following examples show how to use
com.j256.ormlite.stmt.Where#or() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JdbcBaseDaoImplTest.java From ormlite-jdbc with ISC License | 6 votes |
@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); }
Example 2
Source File: BaseDaoImplTest.java From ormlite-core with ISC License | 6 votes |
@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); }
Example 3
Source File: BaseDaoImplTest.java From ormlite-core with ISC License | 6 votes |
@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); }
Example 4
Source File: OrmLiteDao.java From AndroidBase with Apache License 2.0 | 5 votes |
/** * 查询列名不等于指定值的记录 * * @param columnName 列名 * @param value 指定值 */ public List<T> queryNotEqualsByColumnName(String columnName, Object value) throws SQLException { QueryBuilder queryBuilder = ormLiteDao.queryBuilder(); Where where = queryBuilder.where(); where.or(where.gt(columnName, value), where.lt(columnName, value)); return queryBuilder.query(); }
Example 5
Source File: GetAuditLog.java From passopolis-server with GNU General Public License v3.0 | 5 votes |
@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])); } }
Example 6
Source File: JdbcBaseDaoImplTest.java From ormlite-jdbc with ISC License | 5 votes |
@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); }