當前位置: 首頁>>代碼示例>>Java>>正文


Java RealmQuery.findFirst方法代碼示例

本文整理匯總了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));
}
 
開發者ID:playmoweb,項目名稱:store2realm,代碼行數:27,代碼來源:RealmDao.java

示例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");
}
 
開發者ID:rezkyatinnov,項目名稱:kyandroid,代碼行數:13,代碼來源:LocalData.java

示例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;
}
 
開發者ID:toshiapp,項目名稱:toshi-android-client,代碼行數:12,代碼來源:PendingTransactionStore.java

示例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();
        }
    }
}
 
開發者ID:LizaAlert-HotLine,項目名稱:AndroidMobileWorkplace,代碼行數:31,代碼來源:YellowPagesLoader.java

示例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();
}
 
開發者ID:olivierg13,項目名稱:GreenDao-vs-Realm,代碼行數:9,代碼來源:RealmDailyMealManager.java


注:本文中的io.realm.RealmQuery.findFirst方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。