本文整理了Java中org.greenrobot.greendao.query.Query
类的一些代码示例,展示了Query
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query
类的具体详情如下:
包路径:org.greenrobot.greendao.query.Query
类名称:Query
[英]A repeatable query returning entities.
[中]返回实体的可重复查询。
代码示例来源:origin: greenrobot/greenDAO
/** 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();
}
代码示例来源:origin: greenrobot/greenDAO
public void testGetForCurrentThread_TwoThreads() throws InterruptedException {
insert(3);
createQueryFromOtherThread();
Query<TestEntity> query = queryFromOtherThread.forCurrentThread();
assertNotSame(queryFromOtherThread, query);
query.setLimit(10);
query.setOffset(0);
assertEquals(getSimpleInteger(1), (int) query.uniqueOrThrow().getSimpleInteger());
int expected = getSimpleInteger(2);
query.setParameter(0, expected);
assertEquals(expected, (int) query.list().get(0).getSimpleInteger());
assertEquals(expected, (int) query.listLazy().get(0).getSimpleInteger());
assertEquals(expected, (int) query.listLazyUncached().get(0).getSimpleInteger());
assertEquals(expected, (int) query.unique().getSimpleInteger());
assertEquals(expected, (int) query.uniqueOrThrow().getSimpleInteger());
}
代码示例来源:origin: greenrobot/greenDAO
/**
* Shorthand for {@link QueryBuilder#build() build()}.{@link Query#__InternalRx()}.
*/
@Experimental
public RxQuery<T> rx() {
return build().__InternalRx();
}
代码示例来源:origin: greenrobot/greenDAO
@Override
public T call() throws Exception {
return query.forCurrentThread().unique();
}
});
代码示例来源:origin: greenrobot/greenDAO
@Override
public List<T> call() throws Exception {
return query.forCurrentThread().list();
}
});
代码示例来源:origin: greenrobot/greenDAO
/**
* 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();
}
代码示例来源:origin: greenrobot/greenDAO
public void testThrowOutsideOwnerThread() throws InterruptedException {
createQueryFromOtherThread();
try {
queryFromOtherThread.list();
fail("Did not throw");
} catch (DaoException expected) {
queryFromOtherThread.listIterator();
fail("Did not throw");
} catch (DaoException expected) {
queryFromOtherThread.listLazyUncached();
fail("Did not throw");
} catch (DaoException expected) {
queryFromOtherThread.setLimit(2);
fail("Did not throw");
} catch (DaoException expected) {
queryFromOtherThread.setOffset(2);
fail("Did not throw");
} catch (DaoException expected) {
queryFromOtherThread.setParameter(0, 42);
fail("Did not throw");
} catch (DaoException expected) {
queryFromOtherThread.unique();
fail("Did not throw");
} catch (DaoException expected) {
代码示例来源:origin: greenrobot/greenDAO
break;
case QueryList:
operation.result = ((Query) operation.parameter).forCurrentThread().list();
break;
case QueryUnique:
operation.result = ((Query) operation.parameter).forCurrentThread().unique();
break;
case DeleteByKey:
代码示例来源:origin: greenrobot/greenDAO
public void testRawQueryCreate_setParameterInQuery() {
insert(3);
String value = getSimpleString(2);
String sql = "WHERE " + Properties.SimpleString.columnName + "=?";
Query<TestEntity> query = dao.queryRawCreate(sql, getSimpleString(1));
query.list();
query.setParameter(0, value);
List<TestEntity> result = query.list();
assertEquals(1, result.size());
assertEquals(value, result.get(0).getSimpleString());
}
代码示例来源:origin: greenrobot/greenDAO
public void testJoinMixedParameterValues() {
prepareData();
QueryBuilder<RelationEntity> queryBuilder = relationEntityDao.queryBuilder();
queryBuilder.where(RelationEntityDao.Properties.SimpleString.like(""), RelationEntityDao.Properties.SimpleString.ge(""));
Join<RelationEntity, TestEntity> join = queryBuilder.join(RelationEntityDao.Properties.TestIdNotNull,
TestEntity.class);
join.where(Properties.SimpleInt.le(0));
queryBuilder.offset(0).limit(0);
Query<RelationEntity> query = queryBuilder.build();
query.setParameter(0, "entity-%");
query.setParameter(1, "entity-4");
query.setParameter(2, 6);
query.setOffset(1);
query.setLimit(99);
List<RelationEntity> entities = query.list();
assertEquals(2, entities.size());
assertEquals("entity-5", entities.get(0).getSimpleString());
assertEquals("entity-6", entities.get(1).getSimpleString());
}
代码示例来源:origin: greenrobot/greenDAO
public void testJoinOfJoin() {
prepareData();
List<RelationEntity> relationEntities = relationEntityDao.loadAll();
relationEntities.get(2).setParent(relationEntities.get(4));
relationEntities.get(3).setParent(relationEntities.get(5));
relationEntities.get(7).setParent(relationEntities.get(5));
relationEntityDao.updateInTx(relationEntities);
QueryBuilder<RelationEntity> queryBuilder = relationEntityDao.queryBuilder();
Join<RelationEntity, RelationEntity> join1 =
queryBuilder.join(RelationEntityDao.Properties.ParentId, RelationEntity.class);
queryBuilder.join(join1, RelationEntityDao.Properties.TestIdNotNull, TestEntity.class, Properties.Id)
.where(Properties.SimpleInt.lt(6));
Query<RelationEntity> query = queryBuilder.build();
RelationEntity entity = query.uniqueOrThrow();
assertEquals(relationEntities.get(2).getSimpleString(), entity.getSimpleString());
query.setParameter(0, 99);
assertEquals(3, query.list().size());
}
代码示例来源:origin: greenrobot/greenDAO
/**
* 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();
}
代码示例来源:origin: greenrobot/greenDAO
public void testGetForCurrentThread_ParametersAreReset() {
insert(3);
int value = getSimpleInteger(1);
Query<TestEntity> query = dao.queryBuilder().where(Properties.SimpleInteger.eq(value)).build();
query.setParameter(0, value + 1);
TestEntity entityFor2 = query.unique();
assertEquals(value + 1, (int) entityFor2.getSimpleInteger());
query = query.forCurrentThread();
assertNotNull(query.unique());
}
代码示例来源:origin: CooLoongWu/CoolChat
List<Conversation> conversations = conversationDao.queryBuilder().build().list();
.where(ContactDao.Properties.UserId.eq(conversations.get(i).getMultiId()))
.build()
.unique();
conversations.get(i).setName(TextUtils.isEmpty(contact.getRemarkName()) ? contact.getName() : contact.getRemarkName());
} else if ("group".equals(conversations.get(i).getType())) {
.where(GroupDao.Properties.GroupId.eq(conversations.get(i).getMultiId()))
.build()
.unique();
conversations.get(i).setName(group.getGroupName());
代码示例来源:origin: greenrobot/greenDAO
public void testLike() {
TestEntity entity = insert(3).get(1);
entity.setSimpleString("greenrobot");
dao.update(entity);
Query<TestEntity> query = dao.queryBuilder().where(Properties.SimpleString.like("%robot")).build();
TestEntity entity2 = query.uniqueOrThrow();
assertEquals(entity.getId(), entity2.getId());
query.setParameter(0, "green%");
entity2 = query.uniqueOrThrow();
assertEquals(entity.getId(), entity2.getId());
query.setParameter(0, "%enrob%");
entity2 = query.uniqueOrThrow();
assertEquals(entity.getId(), entity2.getId());
query.setParameter(0, "%nothere%");
entity2 = query.unique();
assertNull(entity2);
}
代码示例来源:origin: greenrobot/greenDAO
public void testJoinSimpleParameterValue() {
prepareData();
QueryBuilder<RelationEntity> queryBuilder = createQueryBuilder(-1);
Query<RelationEntity> query = queryBuilder.build();
for (int i = 0; i < 10; i++) {
query.setParameter(0, i + 1);
RelationEntity unique = query.uniqueOrThrow();
assertEquals("entity-" + (i + 1), unique.getSimpleString());
}
}
代码示例来源:origin: greenrobot/greenDAO
@Override
public void call(Subscriber<? super T> subscriber) {
try {
LazyList<T> lazyList = query.forCurrentThread().listLazyUncached();
try {
for (T entity : lazyList) {
if (subscriber.isUnsubscribed()) {
break;
}
subscriber.onNext(entity);
}
} finally {
lazyList.close();
}
if (!subscriber.isUnsubscribed()) {
subscriber.onCompleted();
}
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
subscriber.onError(e);
}
}
});
代码示例来源:origin: greenrobot/greenDAO
public void run() {
query.forCurrentThread();
}
};
代码示例来源:origin: greenrobot/greenDAO
public void _testListSetParameters() {
insertEntities(15);
// TODO how to pass those to rxQuery?
query.setParameter(0, 5);
TestSubscriber<List<TestEntity>> testSubscriber = RxTestHelper.awaitTestSubscriber(rxQuery.list());
assertEquals(1, testSubscriber.getValueCount());
List<TestEntity> entitiesRead = testSubscriber.getOnNextEvents().get(0);
assertEquals(5, entitiesRead.size());
}
代码示例来源:origin: greenrobot/greenDAO
/**
* 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();
}
内容来源于网络,如有侵权,请联系作者删除!