本文整理汇总了Java中io.realm.Realm.where方法的典型用法代码示例。如果您正苦于以下问题:Java Realm.where方法的具体用法?Java Realm.where怎么用?Java Realm.where使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.realm.Realm
的用法示例。
在下文中一共展示了Realm.where方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAll
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public Flowable<Optional<List<T>>> getAll(List<T> items) {
Realm realm = Realm.getDefaultInstance();
RealmQuery<T> query = realm.where(clazz);
if(items.size() > 0){
String paramName = items.get(0).getUniqueIdentifierName();
Integer[] keys = new Integer[items.size()];
for(int i = 0; i < items.size(); i++){
keys[i] = items.get(i).getUniqueIdentifier();
}
query.in(paramName, keys);
}
List<T> copies = realm.copyFromRealm(query.findAll());
realm.close();
return Flowable.just(Optional.wrap(copies));
}
示例2: getOne
import io.realm.Realm; //导入方法依赖的package包/类
/**
* Get one with a specific filter object
* @param filter
* @return
*/
@Override
public Flowable<Optional<T>> getOne(Filter filter, SortingMode sortingMode) {
Realm realm = Realm.getDefaultInstance();
RealmQuery<T> query = realm.where(clazz);
query = filterToQuery(filter, query);
T item = null;
if (sortingMode != null) {
RealmResults<T> items = applySortingMode(sortingMode, query);
if (!items.isEmpty()) {
item = items.first();
}
} else {
item = query.findFirst();
}
T copy = null;
if (item != null) {
copy = realm.copyFromRealm(item);
}
realm.close();
return Flowable.just(Optional.wrap(copy));
}
示例3: getMissingConfirmTrips
import io.realm.Realm; //导入方法依赖的package包/类
public static RealmResults<Trip> getMissingConfirmTrips(Realm realm) {
RealmResults<StationUse> uses = realm.where(StationUse.class)
.greaterThan("entryDate", new Date(new Date().getTime() - TimeUnit.DAYS.toMillis(7))).findAll().where()
.equalTo("type", "NETWORK_ENTRY").or().equalTo("type", "VISIT").findAll();
// now we have all station uses that **might** be part of editable trips
// get all trips that contain these uses and which are yet to be confirmed
RealmQuery<Trip> tripsQuery = realm.where(Trip.class);
if (uses.size() > 0) {
// first item detached from the others because otherwise "Missing left-hand side of OR" might happen
// https://github.com/realm/realm-java/issues/1014#issuecomment-107235374
tripsQuery = tripsQuery.equalTo("userConfirmed", false).equalTo("path.station.id", uses.get(0).getStation().getId()).equalTo("path.entryDate", uses.get(0).getEntryDate());
for (int i = 1; i < uses.size(); i++) {
tripsQuery = tripsQuery.or().equalTo("userConfirmed", false).equalTo("path.station.id", uses.get(i).getStation().getId()).equalTo("path.entryDate", uses.get(i).getEntryDate());
}
return tripsQuery.findAll();
} else {
// realm is just terrible. not only is it hard to do a proper WHERE ... IN ... query, it's also hard to generate an empty result set.
// https://github.com/realm/realm-java/issues/1862
// https://github.com/realm/realm-java/issues/1575
// https://github.com/realm/realm-java/issues/4011
return tripsQuery.equalTo("id", "NEVER_BE_TRUE").findAll();
}
}
示例4: deleteAll
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public Flowable<Integer> deleteAll() {
final Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
RealmQuery<T> query = realm.where(clazz);
long count = query.count();
realm.delete(clazz);
realm.commitTransaction();
realm.close();
return Flowable.just((int)count);
}
示例5: get
import io.realm.Realm; //导入方法依赖的package包/类
public static <O extends RealmObject> O get(Realm realmInstance, QueryFilters filters, Class<O> clazz) throws LocalDataNotFoundException{
Realm realm = realmInstance;
RealmQuery<O> query = realm.where(clazz);
query = filters.copyToRealmQuery(query);
O result = query.findFirst();
if(result != null){
O finalResult = realm.copyFromRealm(result);
realm.close();
return finalResult;
}
throw new SessionNotFoundException("queried data is not found");
}
示例6: delete
import io.realm.Realm; //导入方法依赖的package包/类
public static <O extends RealmObject> void delete(Realm realmInstance, QueryFilters filters, Class<O> clazz){
Realm realm = realmInstance;
realm.beginTransaction();
RealmQuery<O> query = realm.where(clazz);
query = filters.copyToRealmQuery(query);
final RealmResults<O> results = query.findAll();
results.deleteAllFromRealm();
realm.commitTransaction();
realm.close();
}
示例7: getList
import io.realm.Realm; //导入方法依赖的package包/类
public static <O extends RealmObject> List<O> getList(Realm realmInstance, QueryFilters filters, Class<O> clazz) throws LocalDataNotFoundException{
Realm realm = realmInstance;
RealmQuery<O> query = realm.where(clazz);
query = filters.copyToRealmQuery(query);
List<O> results = realm.copyFromRealm(query.findAll());
realm.close();
return results;
}
示例8: refreshData
import io.realm.Realm; //导入方法依赖的package包/类
private void refreshData(){
Realm realm = Realm.getDefaultInstance();
RealmQuery<NotesModel> notesModelRealmQuery = realm.where(NotesModel.class);
RealmResults<NotesModel> query = notesModelRealmQuery.findAll();
notesList.clear();
notesList.addAll(query);
notesAdapter.notifyDataSetChanged();
}