我有一个realm
database
我希望如下query
。
示例:
所以我按如下方式进行查询:
protected <T extends RealmObject> List<T> getListNotContainIds(Class<T> model, List<Long> idList, String fieldName) {
checkValueOfPortalRealm();
RealmQuery<T> query = portalRealmInstance.where(model);
if (idList != null) {
query.not().beginGroup();
for (int i = 0; i < idList.size(); i++) {
if (i == 0) {
query.equalTo(fieldName, idList.get(i));
} else {
query.or().equalTo(fieldName, idList.get(i));
}
}
query.endGroup();
}
return query.findAll();
}
然后,我得到了例外:。
java.lang.UnsupportedOperationException:缺少Not的参数 at io.realm.internal.TableQuery.validateQuery(TableQuery.java:94) at io.realm.internal.TableQuery.findAll(TableQuery.java:449) 在io.realm.RealmQuery.findAll(RealmQuery.java:1434)
我是客人说我的query
有问题,有人可以帮忙纠正吗?
答案 0 :(得分:0)
你应该这样做:
protected <T extends RealmObject> List<T> getListNotContainIds(Class<T> model, List<Long> idList, String fieldName) {
checkValueOfPortalRealm();
RealmQuery<T> query = portalRealmInstance.where(model);
if(idList != null && idList.size() > 0) {
boolean isFirst = true;
query = query.beginGroup();
for (long id : idList) {
if(!isFirst) {
query = query.or();
}
query = query.notEqualTo(fieldName, id);
isFirst = false;
}
query = query.endGroup();
}
return query.findAll();
}