本文整理匯總了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();
}