Java Code Examples for com.j256.ormlite.stmt.Where#query()
The following examples show how to use
com.j256.ormlite.stmt.Where#query() .
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 testUseOfAndMany() throws Exception { Dao<Foo, Integer> dao = createDao(Foo.class, true); assertEquals(0, dao.countOf()); Foo foo1 = new Foo(); foo1.val = 1231231; assertEquals(1, dao.create(foo1)); Foo foo2 = new Foo(); foo2.val = foo1.val + 1; assertEquals(1, dao.create(foo2)); Where<Foo, Integer> where = dao.queryBuilder().where(); where.and(where.eq(Foo.VAL_COLUMN_NAME, foo1.val), where.eq(Foo.ID_COLUMN_NAME, foo1.id)); List<Foo> results = where.query(); assertEquals(1, results.size()); assertEquals(foo1.id, results.get(0).id); // this should match none where.reset(); where.and(where.eq(Foo.ID_COLUMN_NAME, foo1.id), where.eq(Foo.ID_COLUMN_NAME, foo2.id), where.eq(Foo.VAL_COLUMN_NAME, foo1.val), where.eq(Foo.VAL_COLUMN_NAME, foo2.val)); results = where.query(); assertEquals(0, results.size()); }
Example 3
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 4
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 5
Source File: OrgNodeRepository.java From mOrgAnd with GNU General Public License v2.0 | 5 votes |
public static List<OrgNode> getScheduledNodes(String filename, boolean showHabits) { try { Where<OrgNode, Integer> query = queryBuilder().where().eq(OrgNode.FILE_FIELD_NAME, filename); query.and().like(OrgNode.TITLE_FIELD_NAME, "%<%>%"); if (showHabits == false) query.and().not().like(OrgNode.TITLE_FIELD_NAME, "%:STYLE: habit%"); return query.query(); } catch (SQLException e) { e.printStackTrace(); } return new ArrayList<OrgNode>(); }
Example 6
Source File: JdbcBaseDaoImplTest.java From ormlite-jdbc with ISC License | 5 votes |
@SuppressWarnings("unchecked") @Test public void testUseOfAndMany() 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.and(where.eq(Foo.VAL_FIELD_NAME, val), where.eq(Foo.ID_FIELD_NAME, id)); List<Foo> results = where.query(); assertEquals(1, results.size()); assertEquals(id, results.get(0).id); // this should match none where.reset(); where.and(where.eq(Foo.VAL_FIELD_NAME, val), where.eq(Foo.ID_FIELD_NAME, id), where.eq(Foo.ID_FIELD_NAME, notId)); results = where.query(); assertEquals(0, results.size()); }
Example 7
Source File: JdbcBaseDaoImplTest.java From ormlite-jdbc with ISC License | 5 votes |
@Test @SuppressWarnings("unchecked") public void testUseOfAndInt() 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.and(where.eq(Foo.VAL_FIELD_NAME, val), where.eq(Foo.ID_FIELD_NAME, id)); List<Foo> results = where.query(); assertEquals(1, results.size()); assertEquals(id, results.get(0).id); // this should match none where.reset(); where.eq(Foo.VAL_FIELD_NAME, val); where.eq(Foo.ID_FIELD_NAME, id); where.eq(Foo.ID_FIELD_NAME, notId); where.and(3); results = where.query(); assertEquals(0, results.size()); }
Example 8
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); }
Example 9
Source File: BaseDaoImplTest.java From ormlite-core with ISC License | 5 votes |
@Test public void testUseOfAndInt() throws Exception { Dao<Foo, Integer> dao = createDao(Foo.class, true); assertEquals(0, dao.countOf()); Foo foo1 = new Foo(); foo1.val = 1231231; assertEquals(1, dao.create(foo1)); Foo foo2 = new Foo(); foo2.val = foo1.val + 1; assertEquals(1, dao.create(foo1)); Where<Foo, Integer> where = dao.queryBuilder().where(); where.eq(Foo.VAL_COLUMN_NAME, foo1.val); where.eq(Foo.ID_COLUMN_NAME, foo1.id); where.and(2); List<Foo> results = where.query(); assertEquals(1, results.size()); assertEquals(foo1.id, results.get(0).id); // this should match none where.reset(); where.eq(Foo.ID_COLUMN_NAME, foo1.id); where.eq(Foo.ID_COLUMN_NAME, foo2.id); where.eq(Foo.VAL_COLUMN_NAME, foo1.val); where.eq(Foo.VAL_COLUMN_NAME, foo2.val); where.and(4); results = where.query(); assertEquals(0, results.size()); }
Example 10
Source File: OrgNodeRepository.java From mOrgAnd with GNU General Public License v2.0 | 4 votes |
public static List<OrgNode> getDirtyNodes(OrgFile file) throws SQLException { Where<OrgNode, Integer> builder = queryBuilder().orderBy(OrgNode.LINENUMBER_FIELD_NAME, false).where(); builder.eq(OrgNode.FILE_FIELD_NAME, file); builder.and().ne(OrgNode.STATE_FIELD_NAME, OrgNode.State.Clean); return builder.query(); }