/** * Shorthand for {@link QueryBuilder#build() build()}.{@link Query#uniqueOrThrow() uniqueOrThrow()}; see * {@link Query#uniqueOrThrow()} for details. To execute a query more than once, you should build the query and * keep * the {@link Query} object for efficiency reasons. */ public T uniqueOrThrow() { return build().uniqueOrThrow(); }
public void testBuildQueryAndDeleteQuery() { insert(3); int value = getSimpleInteger(1); QueryBuilder<TestEntity> builder = dao.queryBuilder().where(Properties.SimpleInteger.eq(value)); Query<TestEntity> query = builder.build(); DeleteQuery<TestEntity> deleteQuery = builder.buildDelete(); assertEquals(1, query.list().size()); deleteQuery.executeDeleteWithoutDetachingEntities(); assertEquals(0, query.list().size()); }
public void testBuildQueryAndCountQuery() { insert(3); int value = getSimpleInteger(1); QueryBuilder<TestEntity> builder = dao.queryBuilder().where(Properties.SimpleInteger.eq(value)); Query<TestEntity> query = builder.build(); CountQuery<TestEntity> countQuery = builder.buildCount(); assertEquals(1, query.list().size()); assertEquals(1, countQuery.count()); }
/** * Shorthand for {@link QueryBuilder#build() build()}.{@link Query#list() list()}; see {@link Query#list()} for * details. To execute a query more than once, you should build the query and keep the {@link Query} object for * efficiency reasons. */ public List<T> list() { return build().list(); }
/** * Shorthand for {@link QueryBuilder#build() build()}.{@link Query#listLazy() listLazy()}; see * {@link Query#listLazy()} for details. To execute a query more than once, you should build the query and keep the * {@link Query} object for efficiency reasons. */ public LazyList<T> listLazy() { return build().listLazy(); }
/** * Shorthand for {@link QueryBuilder#build() build()}.{@link Query#listLazyUncached() listLazyUncached()}; see * {@link Query#listLazyUncached()} for details. To execute a query more than once, you should build the query and * keep the {@link Query} object for efficiency reasons. */ public LazyList<T> listLazyUncached() { return build().listLazyUncached(); }
/** * Shorthand for {@link QueryBuilder#build() build()}.{@link Query#listIterator() listIterator()}; see * {@link Query#listIterator()} for details. To execute a query more than once, you should build the query and keep * the {@link Query} object for efficiency reasons. */ public CloseableListIterator<T> listIterator() { return build().listIterator(); }
/** * Shorthand for {@link QueryBuilder#build() build()}.{@link Query#unique() unique()}; see {@link Query#unique()} * for details. To execute a query more than once, you should build the query and keep the {@link Query} object for * efficiency reasons. */ public T unique() { return build().unique(); }
/** * Shorthand for {@link QueryBuilder#build() build()}.{@link Query#__InternalRx()}. */ @Experimental public RxQuery<T> rx() { return build().__InternalRx(); }
/** * Shorthand for {@link QueryBuilder#build() build()}.{@link Query#__internalRxPlain()}. */ @Experimental public RxQuery<T> rxPlain() { return build().__internalRxPlain(); }
/** Internal query to resolve the "children" to-many relationship of TreeEntity. */ public List<TreeEntity> _queryTreeEntity_Children(Long parentId) { synchronized (this) { if (treeEntity_ChildrenQuery == null) { QueryBuilder<TreeEntity> queryBuilder = queryBuilder(); queryBuilder.where(Properties.ParentId.eq(null)); treeEntity_ChildrenQuery = queryBuilder.build(); } } Query<TreeEntity> query = treeEntity_ChildrenQuery.forCurrentThread(); query.setParameter(0, parentId); return query.list(); }
/** Internal query to resolve the "toManyTarget2List" to-many relationship of RelationSource2. */ public List<ToManyTarget2> _queryRelationSource2_ToManyTarget2List(Long fkId) { synchronized (this) { if (relationSource2_ToManyTarget2ListQuery == null) { QueryBuilder<ToManyTarget2> queryBuilder = queryBuilder(); queryBuilder.where(Properties.FkId.eq(null)); relationSource2_ToManyTarget2ListQuery = queryBuilder.build(); } } Query<ToManyTarget2> query = relationSource2_ToManyTarget2ListQuery.forCurrentThread(); query.setParameter(0, fkId); return query.list(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setUpViews(); // get the note DAO DaoSession daoSession = ((App) getApplication()).getDaoSession(); noteDao = daoSession.getNoteDao(); // query all notes, sorted a-z by their text notesQuery = noteDao.queryBuilder().orderAsc(NoteDao.Properties.Text).build(); updateNotes(); }
/** Internal query to resolve the "toManyTargetEntityList" to-many relationship of ToManyEntity. */ public List<ToManyTargetEntity> _queryToManyEntity_ToManyTargetEntityList(Long toManyId) { synchronized (this) { if (toManyEntity_ToManyTargetEntityListQuery == null) { QueryBuilder<ToManyTargetEntity> queryBuilder = queryBuilder(); queryBuilder.where(Properties.ToManyId.eq(null)); queryBuilder.orderRaw("T.'_id' ASC"); toManyEntity_ToManyTargetEntityListQuery = queryBuilder.build(); } } Query<ToManyTargetEntity> query = toManyEntity_ToManyTargetEntityListQuery.forCurrentThread(); query.setParameter(0, toManyId); return query.list(); }
/** Internal query to resolve the "toManyByJoinProperty" to-many relationship of ToManyEntity. */ public List<ToManyTargetEntity> _queryToManyEntity_ToManyByJoinProperty(String targetJoinProperty) { synchronized (this) { if (toManyEntity_ToManyByJoinPropertyQuery == null) { QueryBuilder<ToManyTargetEntity> queryBuilder = queryBuilder(); queryBuilder.where(Properties.TargetJoinProperty.eq(null)); queryBuilder.orderRaw("T.'_id' ASC"); toManyEntity_ToManyByJoinPropertyQuery = queryBuilder.build(); } } Query<ToManyTargetEntity> query = toManyEntity_ToManyByJoinPropertyQuery.forCurrentThread(); query.setParameter(0, targetJoinProperty); return query.list(); }
/** Internal query to resolve the "toManyDescList" to-many relationship of ToManyEntity. */ public List<ToManyTargetEntity> _queryToManyEntity_ToManyDescList(Long toManyIdDesc) { synchronized (this) { if (toManyEntity_ToManyDescListQuery == null) { QueryBuilder<ToManyTargetEntity> queryBuilder = queryBuilder(); queryBuilder.where(Properties.ToManyIdDesc.eq(null)); queryBuilder.orderRaw("T.'_id' DESC"); toManyEntity_ToManyDescListQuery = queryBuilder.build(); } } Query<ToManyTargetEntity> query = toManyEntity_ToManyDescListQuery.forCurrentThread(); query.setParameter(0, toManyIdDesc); return query.list(); }
/** Internal query to resolve the "dateEntityList" to-many relationship of ToManyEntity. */ public List<DateEntity> _queryToManyEntity_DateEntityList(Long idToMany) { synchronized (this) { if (toManyEntity_DateEntityListQuery == null) { QueryBuilder<DateEntity> queryBuilder = queryBuilder(); queryBuilder.join(JoinManyToDateEntity.class, JoinManyToDateEntityDao.Properties.IdDate) .where(JoinManyToDateEntityDao.Properties.IdToMany.eq(idToMany)); toManyEntity_DateEntityListQuery = queryBuilder.build(); } } Query<DateEntity> query = toManyEntity_DateEntityListQuery.forCurrentThread(); query.setParameter(0, idToMany); return query.list(); }
public void testQueryUnsetLimit() { Query<TestEntity> query = dao.queryBuilder().build(); try{ query.setLimit(1); fail("Limit must be defined in builder first"); } catch(RuntimeException expected) { //OK } }
public void testBuildQueryDoesntLeak() { QueryBuilder<TestEntity> builder = dao.queryBuilder().where(Properties.SimpleInteger.eq("dummy")); for (int i = 0; i < LEAK_TEST_ITERATIONS; i++) { builder.build(); } }
public void testSublistUncached() { ArrayList<TestEntity> list = insert(10); LazyList<TestEntity> listLazy = dao.queryBuilder().orderAsc(Properties.SimpleInteger).build().listLazyUncached(); try { assertIds(list.subList(2,7), listLazy.subList(2,7)); } catch (DaoException e) { assertEquals("This operation only works with cached lazy lists", e.getMessage()); } }