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