當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。