本文整理匯總了Java中io.realm.RealmQuery.findFirst方法的典型用法代碼示例。如果您正苦於以下問題:Java RealmQuery.findFirst方法的具體用法?Java RealmQuery.findFirst怎麽用?Java RealmQuery.findFirst使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.realm.RealmQuery
的用法示例。
在下文中一共展示了RealmQuery.findFirst方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getOne
import io.realm.RealmQuery; //導入方法依賴的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));
}
示例2: get
import io.realm.RealmQuery; //導入方法依賴的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");
}
示例3: loadSingleWhere
import io.realm.RealmQuery; //導入方法依賴的package包/類
private PendingTransaction loadSingleWhere(final String fieldName, final String value) {
final Realm realm = BaseApplication.get().getRealm();
final RealmQuery<PendingTransaction> query = realm
.where(PendingTransaction.class)
.equalTo(fieldName, value);
final PendingTransaction pendingTransaction = query.findFirst();
final PendingTransaction queriedPendingTransaction = pendingTransaction == null ? null : realm.copyFromRealm(pendingTransaction);
realm.close();
return queriedPendingTransaction;
}
示例4: fetchDataAsyncPeriodicaly
import io.realm.RealmQuery; //導入方法依賴的package包/類
/**
* Fetchs yellow pages from server periodically (once per 3 days).
*/
public void fetchDataAsyncPeriodicaly() {
Realm myRealm = null;
YPDownload data;
try {
myRealm = Realm.getInstance(context);
RealmQuery<YPDownload> query = myRealm.where(YPDownload.class);
if (query.count() > 0) {
data = query.findFirst();
} else {
myRealm.beginTransaction();
data = myRealm.createObject(YPDownload.class);
data.setWhen(0);
myRealm.commitTransaction();
}
Log.d(TAG, "when: " + data.getWhen());
if (System.currentTimeMillis() - data.getWhen() > 1000L * 60 * 60 * 24 * 3) {
fetchDataAsync();
}
} finally {
if (myRealm != null) {
myRealm.close();
}
}
}
示例5: queryDailyMeal
import io.realm.RealmQuery; //導入方法依賴的package包/類
/**
* Returns a {@link DailyMealRealm} thanks to its primary key
*/
public DailyMealRealm queryDailyMeal(long date) {
RealmQuery<DailyMealRealm> query = DbApp.getRealm().where(DailyMealRealm.class);
query.equalTo("eatenOn", date);
return query.findFirst();
}