当前位置: 首页>>代码示例>>Java>>正文


Java RealmQuery类代码示例

本文整理汇总了Java中io.realm.RealmQuery的典型用法代码示例。如果您正苦于以下问题:Java RealmQuery类的具体用法?Java RealmQuery怎么用?Java RealmQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RealmQuery类属于io.realm包,在下文中一共展示了RealmQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAll

import io.realm.RealmQuery; //导入依赖的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));
}
 
开发者ID:playmoweb,项目名称:store2realm,代码行数:20,代码来源:RealmDao.java

示例2: 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

示例3: searchContacts

import io.realm.RealmQuery; //导入依赖的package包/类
private RealmResults<Contact> searchContacts() {
  Contact c = Parcels.unwrap(getIntent().getParcelableExtra(EXTRA_SEARCH_FILTERS));
  realm = Realm.getDefaultInstance();
  RealmQuery<Contact> query = realm.where(Contact.class);

  query.contains(LASTNAME, c.lastName, Case.INSENSITIVE)
      .or()
      .contains(FIRSTNAME, c.lastName, Case.INSENSITIVE);

  if (!c.owner) {
    query.equalTo(OWNER, false);
  }

  if (!c.cornac) {
    query.equalTo(CORNAC, false);
  }

  if (!c.vet) {
    query.equalTo(VET, false);
  }

  return query.findAll();
}
 
开发者ID:goutfeb,项目名称:ElephantAsia,代码行数:24,代码来源:SearchContactResultActivity.java

示例4: searchElephants

import io.realm.RealmQuery; //导入依赖的package包/类
private RealmResults<Elephant> searchElephants() {
  Elephant e = Parcels.unwrap(getIntent().getParcelableExtra(EXTRA_SEARCH_ELEPHANT));
  RealmQuery<Elephant> query = realm.where(Elephant.class);

  query.contains(NAME, e.name, Case.INSENSITIVE);

  if (e.chips1 != null) {
    query.contains(CHIPS1, e.chips1, Case.INSENSITIVE);
  }

  if (!e.male) {
    query.equalTo(MALE, false);
  }

  if (!e.female) {
    query.equalTo(FEMALE, false);
  }
  return query.findAll();
}
 
开发者ID:goutfeb,项目名称:ElephantAsia,代码行数:20,代码来源:SearchElephantResultActivity.java

示例5: getMissingConfirmTrips

import io.realm.RealmQuery; //导入依赖的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();
    }
}
 
开发者ID:gbl08ma,项目名称:underlx,代码行数:25,代码来源:Trip.java

示例6: selectData

import io.realm.RealmQuery; //导入依赖的package包/类
void selectData(String name, String phoneNum, String sex, String education, final MaterialDialog materialDialog) {

        Logger.t(TAG).i("name=" + name + "\nphoneNum=" + phoneNum + "\nsex=" + sex + "\neducation=" + education);

        Realm realm = RealmManager.getRealm();

        RealmResults<User> userRealmResults;

        RealmQuery<User> realmQuery = realm.where(User.class)
                .contains("name", name)
                .contains("phoneNum", phoneNum);

        if (!TextUtils.isEmpty(sex)) {
            realmQuery.equalTo("sex", sex);
        }

        if (!TextUtils.isEmpty(education)) {
            realmQuery.equalTo("mExtendBeanRealmList.value", education);
        }
        userRealmResults = realmQuery.findAll();
        loadLatestData(userRealmResults);

        materialDialog.dismiss();
    }
 
开发者ID:chenzj-king,项目名称:RealmSample,代码行数:25,代码来源:SelectFragment.java

示例7: getItems

import io.realm.RealmQuery; //导入依赖的package包/类
@Override
public List<Item> getItems(Realm realm, boolean onlyUnread) {
    // Get all feeds belonging to Folder treeItem
    List<Feed> feeds = getFeeds(realm, onlyUnread);
    RealmQuery<Item> query = null;
    if(feeds != null && feeds.size() > 0) {
        // Find all items belonging to any feed from this folder
        Iterator<Feed> feedIterator = feeds.iterator();
        query = realm.where(Item.class).beginGroup()
                .equalTo(Item.FEED_ID, feedIterator.next().getId());
        while (feedIterator.hasNext()) {
            query.or().equalTo(Item.FEED_ID, feedIterator.next().getId());
        }
        query.endGroup();
        if(onlyUnread)
            query.equalTo(Item.UNREAD, true);
    }
    return query != null ? query.distinct(Item.FINGERPRINT) : null;
}
 
开发者ID:schaal,项目名称:ocreader,代码行数:20,代码来源:Folder.java

示例8: getAll

import io.realm.RealmQuery; //导入依赖的package包/类
@NonNull
public static List<Folder> getAll(Realm realm, boolean onlyUnread) {
    RealmQuery<Folder> query = null;
    if(onlyUnread) {
        RealmResults<Feed> unreadFeeds = realm.where(Feed.class).greaterThan(Feed.UNREAD_COUNT, 0).notEqualTo(Feed.FOLDER_ID, 0).findAll();
        if(unreadFeeds.size() > 0) {
            Iterator<Feed> feedIterator = unreadFeeds.iterator();
            query = realm.where(Folder.class)
                    .equalTo(Folder.ID, feedIterator.next().getFolderId());
            while (feedIterator.hasNext()) {
                query.or().equalTo(Folder.ID, feedIterator.next().getFolderId());
            }
        }
    } else {
        query = realm.where(Folder.class);
    }

    return query != null ? query.findAllSorted(Folder.NAME, Sort.ASCENDING) : Collections.emptyList();
}
 
开发者ID:schaal,项目名称:ocreader,代码行数:20,代码来源:Folder.java

示例9: findOneSync

import io.realm.RealmQuery; //导入依赖的package包/类
@Nullable
@Override
public T findOneSync(ID id) {
    Realm realm = null;
    try {
        realm = repositoryConfiguration.getRealmProvider().provideRealm();
        RealmQuery<T> query = realm.where(entityClass);
        T entity = idSearch.searchId(query, idFieldName, id)
                .findFirst();
        return entity == null ? null : realm.copyFromRealm(entity);
    } finally {
        if (realm != null) {
            realm.close();
        }
    }
}
 
开发者ID:AleksanderMielczarek,项目名称:RealmRepository,代码行数:17,代码来源:RepositoryDelegate.java

示例10: deleteSync

import io.realm.RealmQuery; //导入依赖的package包/类
@Override
public void deleteSync(ID id) {
    Realm realm = null;
    try {
        realm = repositoryConfiguration.getRealmProvider().provideRealm();
        realm.beginTransaction();
        RealmQuery<T> query = realm.where(entityClass);
        T entity = idSearch.searchId(query, idFieldName, id)
                .findFirst();
        if (entity != null) {
            entity.deleteFromRealm();
        }
        realm.commitTransaction();
    } finally {
        if (realm != null) {
            realm.close();
        }
    }
}
 
开发者ID:AleksanderMielczarek,项目名称:RealmRepository,代码行数:20,代码来源:RepositoryDelegate.java

示例11: getUnsentMessages

import io.realm.RealmQuery; //导入依赖的package包/类
void getUnsentMessages(final Conversation conversation, final GetCallback<List<Message>> callback) {
    RealmStore.QueryBuilder<MessageCacheObject> queryBuilder = new RealmStore.QueryBuilder<MessageCacheObject>() {
        @Override
        public RealmQuery<MessageCacheObject> buildQueryFrom(RealmQuery<MessageCacheObject> baseQuery) {
            RealmQuery<MessageCacheObject> query = baseQuery
                    .equalTo(KEY_CONVERSATION_ID, conversation.getId())
                    .isNotNull(KEY_SEND_DATE)
                    .beginGroup()
                        .equalTo(KEY_ALREADY_SYNC_TO_SERVER, false)
                        .or()
                        .equalTo(KEY_FAIL, true)
                    .endGroup();

            return query;
        }
    };

    if (callback != null) {
        this.store.getMessages(queryBuilder, -1, "creationDate", new RealmStore.ResultCallback<Message[]>() {
            @Override
            public void onResultGet(Message[] messages) {
                callback.onSuccess(Arrays.asList(messages));
            }
        });
    }
}
 
开发者ID:SkygearIO,项目名称:chat-SDK-Android,代码行数:27,代码来源:CacheController.java

示例12: deleteAllExcluding

import io.realm.RealmQuery; //导入依赖的package包/类
public <E extends RealmObject> void deleteAllExcluding(Class<E> classType, String classField,
    List<String> fieldsIn) {
  Realm realm = get();
  try {
    realm.beginTransaction();
    RealmQuery<E> query = realm.where(classType);
    for (String field : fieldsIn) {
      query.notEqualTo(classField, field);
    }
    query.findAll()
        .deleteAllFromRealm();
    realm.commitTransaction();
  } finally {
    if (realm != null) {
      realm.close();
    }
  }
}
 
开发者ID:Aptoide,项目名称:aptoide-client-v8,代码行数:19,代码来源:Database.java

示例13: transform

import io.realm.RealmQuery; //导入依赖的package包/类
@Override
public <T extends RealmModel> RealmQuery<T> transform(RealmQuery<T> realmQuery, Condition condition) {
    // Checks.
    if (!condition.isValid()) throw new IllegalArgumentException("Condition isn't valid.");
    if (condition.getType() != Condition.Type.NORMAL)
        throw new IllegalArgumentException("Condition type is not NORMAL.");

    // Get data from Conditions.
    String field = condition.getField();
    FieldType fieldType = condition.getFieldType();
    Object[] args = condition.getArgs();

    // Use different methods based on field type.
    if (FieldType.DATE == fieldType) return realmQuery.lessThan(field, (Date) args[0]);
    else if (FieldType.DOUBLE == fieldType) return realmQuery.lessThan(field, (Double) args[0]);
    else if (FieldType.FLOAT == fieldType) return realmQuery.lessThan(field, (Float) args[0]);
    else if (FieldType.INTEGER == fieldType) return realmQuery.lessThan(field, (Integer) args[0]);
    else if (FieldType.LONG == fieldType) return realmQuery.lessThan(field, (Long) args[0]);
    else
        throw new IllegalArgumentException(String.format("Illegal argument type \"%s\".", fieldType.getTypeName()));
}
 
开发者ID:bkromhout,项目名称:Ruqus,代码行数:22,代码来源:LessThan.java

示例14: transform

import io.realm.RealmQuery; //导入依赖的package包/类
@Override
public <T extends RealmModel> RealmQuery<T> transform(RealmQuery<T> realmQuery, Condition condition) {
    // Checks.
    if (!condition.isValid()) throw new IllegalArgumentException("Condition isn't valid.");
    if (condition.getType() != Condition.Type.NORMAL)
        throw new IllegalArgumentException("Condition type is not NORMAL.");

    // Get data from Conditions.
    String field = condition.getField();
    FieldType fieldType = condition.getFieldType();
    Object[] args = condition.getArgs();

    // Use different methods based on field type.
    if (FieldType.STRING == fieldType) return realmQuery.contains(field, (String) args[0]);
    else
        throw new IllegalArgumentException(String.format("Illegal argument type \"%s\".", fieldType.getTypeName()));
}
 
开发者ID:bkromhout,项目名称:Ruqus,代码行数:18,代码来源:StringContains.java

示例15: transform

import io.realm.RealmQuery; //导入依赖的package包/类
@Override
public <T extends RealmModel> RealmQuery<T> transform(RealmQuery<T> realmQuery, Condition condition) {
    // Checks.
    if (!condition.isValid()) throw new IllegalArgumentException("Condition isn't valid.");
    if (condition.getType() != Condition.Type.NORMAL)
        throw new IllegalArgumentException("Condition type is not NORMAL.");

    // Get data from Conditions.
    String field = condition.getField();
    FieldType fieldType = condition.getFieldType();
    Object[] args = condition.getArgs();

    // Use different methods based on field type.
    if (FieldType.DATE == fieldType)
        return realmQuery.lessThanOrEqualTo(field, (Date) args[0]);
    else if (FieldType.DOUBLE == fieldType)
        return realmQuery.lessThanOrEqualTo(field, (Double) args[0]);
    else if (FieldType.FLOAT == fieldType)
        return realmQuery.lessThanOrEqualTo(field, (Float) args[0]);
    else if (FieldType.INTEGER == fieldType)
        return realmQuery.lessThanOrEqualTo(field, (Integer) args[0]);
    else if (FieldType.LONG == fieldType)
        return realmQuery.lessThanOrEqualTo(field, (Long) args[0]);
    else
        throw new IllegalArgumentException(String.format("Illegal argument type \"%s\".", fieldType.getTypeName()));
}
 
开发者ID:bkromhout,项目名称:Ruqus,代码行数:27,代码来源:LessThanOrEqualTo.java


注:本文中的io.realm.RealmQuery类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。