当前位置: 首页>>代码示例>>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;未经允许,请勿转载。