• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Query类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: detachListener

import com.google.firebase.firestore.Query; //导入依赖的package包/类
private void detachListener() {
    // [START detach_listener]
    Query query = db.collection("cities");
    ListenerRegistration registration = query.addSnapshotListener(
            new EventListener<QuerySnapshot>() {
                // [START_EXCLUDE]
                @Override
                public void onEvent(@Nullable QuerySnapshot snapshots,
                                    @Nullable FirebaseFirestoreException e) {
                    // ...
                }
                // [END_EXCLUDE]
            });

    // ...

    // Stop listening to changes
    registration.remove();
    // [END detach_listener]
}
 
开发者ID:firebase,项目名称:snippets-android,代码行数:21,代码来源:DocSnippets.java


示例2: simpleQueries

import com.google.firebase.firestore.Query; //导入依赖的package包/类
private void simpleQueries() {
    // [START simple_queries]
    // Create a reference to the cities collection
    CollectionReference citiesRef = db.collection("cities");

    // Create a query against the collection.
    Query query = citiesRef.whereEqualTo("state", "CA");
    // [END simple_queries]

    // [START simple_query_capital]
    Query capitalCities = db.collection("cities").whereEqualTo("capital", true);
    // [END simple_query_capital]

    // [START example_filters]
    citiesRef.whereEqualTo("state", "CA");
    citiesRef.whereLessThan("population", 100000);
    citiesRef.whereGreaterThanOrEqualTo("name", "San Francisco");
    // [END example_filters]
}
 
开发者ID:firebase,项目名称:snippets-android,代码行数:20,代码来源:DocSnippets.java


示例3: toQuery

import com.google.firebase.firestore.Query; //导入依赖的package包/类
private Query toQuery(final Filters filters) {
    // Construct query basic query
    Query query = firestore.collection("restaurants");

    if (filters == null) {
        query.orderBy("avgRating", Query.Direction.ASCENDING);
    } else {
        // Category (equality filter)
        if (filters.hasCategory()) {
            query = query.whereEqualTo(Restaurant.FIELD_CATEGORY, filters.getCategory());
        }

        // City (equality filter)
        if (filters.hasCity()) {
            query = query.whereEqualTo(Restaurant.FIELD_CITY, filters.getCity());
        }

        // Price (equality filter)
        if (filters.hasPrice()) {
            query = query.whereEqualTo(Restaurant.FIELD_PRICE, filters.getPrice());
        }

        // Sort by (orderBy with direction)
        if (filters.hasSortBy()) {
            query = query.orderBy(filters.getSortBy(), filters.getSortDirection());
        }
    }

    /* query could be limited like: query.limit(5) */
    return query;
}
 
开发者ID:amrro,项目名称:firestore-android-arch-components,代码行数:32,代码来源:MainRepository.java


示例4: getDefault

import com.google.firebase.firestore.Query; //导入依赖的package包/类
public static Filters getDefault() {
    Filters filters = new Filters();
    filters.setSortBy(Restaurant.FIELD_AVG_RATING);
    filters.setSortDirection(Query.Direction.DESCENDING);

    return filters;
}
 
开发者ID:amrro,项目名称:firestore-android-arch-components,代码行数:8,代码来源:Filters.java


示例5: getSortDirection

import com.google.firebase.firestore.Query; //导入依赖的package包/类
@Nullable
private Query.Direction getSortDirection() {
    String selected = (String) binding.spinnerSort.getSelectedItem();
    if (getString(R.string.sort_by_rating).equals(selected)) {
        return Query.Direction.DESCENDING;
    }
    if (getString(R.string.sort_by_price).equals(selected)) {
        return Query.Direction.ASCENDING;
    }
    if (getString(R.string.sort_by_popularity).equals(selected)) {
        return Query.Direction.DESCENDING;
    }

    return null;
}
 
开发者ID:amrro,项目名称:firestore-android-arch-components,代码行数:16,代码来源:FilterDialogFragment.java


示例6: deleteCollection

import com.google.firebase.firestore.Query; //导入依赖的package包/类
/**
 * Delete all documents in a collection. Uses an Executor to perform work on a background
 * thread. This does *not* automatically discover and delete subcollections.
 */
private static Task<Void> deleteCollection(final CollectionReference collection,
                                           final int batchSize,
                                           Executor executor) {

    // Perform the delete operation on the provided Executor, which allows us to use
    // simpler synchronous logic without blocking the main thread.
    return Tasks.call(executor, () -> {
        // Get the first batch of documents in the collection
        Query query = collection.orderBy("__name__").limit(batchSize);

        // Get a list of deleted documents
        List<DocumentSnapshot> deleted = deleteQueryBatch(query);

        // While the deleted documents in the last batch indicate that there
        // may still be more documents in the collection, page down to the
        // next batch and delete again
        while (deleted.size() >= batchSize) {
            // Move the query cursor to start after the last doc in the batch
            DocumentSnapshot last = deleted.get(deleted.size() - 1);
            query = collection.orderBy("__name__")
                    .startAfter(last.getId())
                    .limit(batchSize);

            deleted = deleteQueryBatch(query);
        }

        return null;
    });

}
 
开发者ID:amrro,项目名称:firestore-android-arch-components,代码行数:35,代码来源:RestaurantUtil.java


示例7: deleteQueryBatch

import com.google.firebase.firestore.Query; //导入依赖的package包/类
/**
 * Delete all results from a query in a single WriteBatch. Must be run on a worker thread
 * to avoid blocking/crashing the main thread.
 */
@WorkerThread
private static List<DocumentSnapshot> deleteQueryBatch(final Query query) throws Exception {
    QuerySnapshot querySnapshot = Tasks.await(query.get());

    WriteBatch batch = query.getFirestore().batch();
    for (DocumentSnapshot snapshot : querySnapshot) {
        batch.delete(snapshot.getReference());
    }
    Tasks.await(batch.commit());

    return querySnapshot.getDocuments();
}
 
开发者ID:amrro,项目名称:firestore-android-arch-components,代码行数:17,代码来源:RestaurantUtil.java


示例8: initFirestore

import com.google.firebase.firestore.Query; //导入依赖的package包/类
private void initFirestore() {
    mFirestore = FirebaseFirestore.getInstance();
    // Get the 50 highest rated restaurants
    mQuery = mFirestore.collection("restaurants")
            .orderBy("avgRating", Query.Direction.DESCENDING)
            .limit(LIMIT);

    /**
     * Now we want to listen to the query,
     * so that we get all matching documents and are notified of future updates in real time.
     * Because our eventual goal is to bind this data to a RecyclerView,
     * we need to create a RecyclerView.Adapter class to listen to the data.
     */

}
 
开发者ID:chauhan-abhi,项目名称:CloudFirestore,代码行数:16,代码来源:MainActivity.java


示例9: onFilter

import com.google.firebase.firestore.Query; //导入依赖的package包/类
@Override
public void onFilter(Filters filters) {
    // Construct query basic query
    Query query = mFirestore.collection("restaurants");

    // Category (equality filter)
    if (filters.hasCategory()) {
        query = query.whereEqualTo("category", filters.getCategory());
    }

    // City (equality filter)
    if (filters.hasCity()) {
        query = query.whereEqualTo("city", filters.getCity());
    }

    // Price (equality filter)
    if (filters.hasPrice()) {
        query = query.whereEqualTo("price", filters.getPrice());
    }

    // Sort by (orderBy with direction)
    if (filters.hasSortBy()) {
        query = query.orderBy(filters.getSortBy(), filters.getSortDirection());
    }

    // Limit items
    query = query.limit(LIMIT);

    // Update the query
    mQuery = query;
    mAdapter.setQuery(query);


    // Set header
    mCurrentSearchView.setText(Html.fromHtml(filters.getSearchDescription(this)));
    mCurrentSortByView.setText(filters.getOrderDescription(this));

    // Save filters
    mViewModel.setFilters(filters);
}
 
开发者ID:chauhan-abhi,项目名称:CloudFirestore,代码行数:41,代码来源:MainActivity.java


示例10: setQuery

import com.google.firebase.firestore.Query; //导入依赖的package包/类
public void setQuery(Query query) {
    // Stop listening
    stopListening();

    // Clear existinkodig data
    mSnapshots.clear();
    notifyDataSetChanged();

    // Listen to new query
    mQuery = query;
    startListening();
}
 
开发者ID:chauhan-abhi,项目名称:CloudFirestore,代码行数:13,代码来源:FirestoreAdapter.java


示例11: getSortDirection

import com.google.firebase.firestore.Query; //导入依赖的package包/类
@Nullable
private Query.Direction getSortDirection() {
    String selected = (String) mSortSpinner.getSelectedItem();
    if (getString(R.string.sort_by_rating).equals(selected)) {
        return Query.Direction.DESCENDING;
    } if (getString(R.string.sort_by_price).equals(selected)) {
        return Query.Direction.ASCENDING;
    } if (getString(R.string.sort_by_popularity).equals(selected)) {
        return Query.Direction.DESCENDING;
    }

    return null;
}
 
开发者ID:chauhan-abhi,项目名称:CloudFirestore,代码行数:14,代码来源:FilterDialogFragment.java


示例12: deleteQueryBatch

import com.google.firebase.firestore.Query; //导入依赖的package包/类
/**
 * Delete all results from a query in a single WriteBatch. Must be run on a worker thread
 * to avoid blocking/crashing the main thread.
 */
@WorkerThread
private List<DocumentSnapshot> deleteQueryBatch(final Query query) throws Exception {
    QuerySnapshot querySnapshot = Tasks.await(query.get());

    WriteBatch batch = query.getFirestore().batch();
    for (DocumentSnapshot snapshot : querySnapshot) {
        batch.delete(snapshot.getReference());
    }
    Tasks.await(batch.commit());

    return querySnapshot.getDocuments();
}
 
开发者ID:btrautmann,项目名称:RxFirestore,代码行数:17,代码来源:DeleteCollectionOnSubscribe.java


示例13: deleteCollection

import com.google.firebase.firestore.Query; //导入依赖的package包/类
/**
 * Delete all documents in a collection. Uses an Executor to perform work on a background
 * thread. This does *not* automatically discover and delete subcollections.
 */
private Task<Void> deleteCollection(final CollectionReference collection,
                                    final int batchSize,
                                    Executor executor) {

    // Perform the delete operation on the provided Executor, which allows us to use
    // simpler synchronous logic without blocking the main thread.
    return Tasks.call(executor, new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            // Get the first batch of documents in the collection
            Query query = collection.orderBy(FieldPath.documentId()).limit(batchSize);

            // Get a list of deleted documents
            List<DocumentSnapshot> deleted = deleteQueryBatch(query);

            // While the deleted documents in the last batch indicate that there
            // may still be more documents in the collection, page down to the
            // next batch and delete again
            while (deleted.size() >= batchSize) {
                // Move the query cursor to start after the last doc in the batch
                DocumentSnapshot last = deleted.get(deleted.size() - 1);
                query = collection.orderBy(FieldPath.documentId())
                        .startAfter(last.getId())
                        .limit(batchSize);

                deleted = deleteQueryBatch(query);
            }

            return null;
        }
    });

}
 
开发者ID:firebase,项目名称:snippets-android,代码行数:38,代码来源:DocSnippets.java


示例14: onFilter

import com.google.firebase.firestore.Query; //导入依赖的package包/类
@Override
public void onFilter(Filters filters) {
    // Construct query basic query
    Query query = mFirestore.collection("restaurants");

    // Category (equality filter)
    if (filters.hasCategory()) {
        query = query.whereEqualTo(Restaurant.FIELD_CATEGORY, filters.getCategory());
    }

    // City (equality filter)
    if (filters.hasCity()) {
        query = query.whereEqualTo(Restaurant.FIELD_CITY, filters.getCity());
    }

    // Price (equality filter)
    if (filters.hasPrice()) {
        query = query.whereEqualTo(Restaurant.FIELD_PRICE, filters.getPrice());
    }

    // Sort by (orderBy with direction)
    if (filters.hasSortBy()) {
        query = query.orderBy(filters.getSortBy(), filters.getSortDirection());
    }

    // Limit items
    query = query.limit(LIMIT);

    // Update the query
    mAdapter.setQuery(query);

    // Set header
    mCurrentSearchView.setText(Html.fromHtml(filters.getSearchDescription(this)));
    mCurrentSortByView.setText(filters.getOrderDescription(this));

    // Save filters
    mViewModel.setFilters(filters);
}
 
开发者ID:firebase,项目名称:quickstart-android,代码行数:39,代码来源:MainActivity.java


示例15: setQuery

import com.google.firebase.firestore.Query; //导入依赖的package包/类
public void setQuery(Query query) {
    // Stop listening
    stopListening();

    // Clear existing data
    mSnapshots.clear();
    notifyDataSetChanged();

    // Listen to new query
    mQuery = query;
    startListening();
}
 
开发者ID:firebase,项目名称:quickstart-android,代码行数:13,代码来源:FirestoreAdapter.java


示例16: deleteCollection

import com.google.firebase.firestore.Query; //导入依赖的package包/类
/**
 * Delete all documents in a collection. Uses an Executor to perform work on a background
 * thread. This does *not* automatically discover and delete subcollections.
 */
private static Task<Void> deleteCollection(final CollectionReference collection,
                                           final int batchSize,
                                           Executor executor) {

    // Perform the delete operation on the provided Executor, which allows us to use
    // simpler synchronous logic without blocking the main thread.
    return Tasks.call(executor, new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            // Get the first batch of documents in the collection
            Query query = collection.orderBy("__name__").limit(batchSize);

            // Get a list of deleted documents
            List<DocumentSnapshot> deleted = deleteQueryBatch(query);

            // While the deleted documents in the last batch indicate that there
            // may still be more documents in the collection, page down to the
            // next batch and delete again
            while (deleted.size() >= batchSize) {
                // Move the query cursor to start after the last doc in the batch
                DocumentSnapshot last = deleted.get(deleted.size() - 1);
                query = collection.orderBy("__name__")
                        .startAfter(last.getId())
                        .limit(batchSize);

                deleted = deleteQueryBatch(query);
            }

            return null;
        }
    });

}
 
开发者ID:firebase,项目名称:quickstart-android,代码行数:38,代码来源:RestaurantUtil.java


示例17: FirestoreSpinnerAdapter

import com.google.firebase.firestore.Query; //导入依赖的package包/类
/**
 * Creates a new FirebaseSpinnerAdapter with the given options and dropdown layout.
 *
 * @param query The location to monitor for data changes
 * @param layout The layout to inflate for the normally displayed view
 * @param dropdownLayout The layout to inflate for the spinner dropdown menu
 */
@SuppressWarnings("WeakerAccess")
public FirestoreSpinnerAdapter(@NonNull Query query, Class<T> modelClass, @LayoutRes int layout,
                               @LayoutRes int dropdownLayout) {
    super();
    mSnapshots = new FirestoreArray<>(query, new ClassSnapshotParser<>(modelClass));
    mLayout = layout;
    mDropdownLayout = dropdownLayout;
}
 
开发者ID:TheCraftKid,项目名称:FirebaseUI-Android-Addons,代码行数:16,代码来源:FirestoreSpinnerAdapter.java


示例18: FirestoreArray

import com.google.firebase.firestore.Query; //导入依赖的package包/类
/**
 * @param options options for the query listen.
 * @see #FirestoreArray(Query, SnapshotParser)
 */
public FirestoreArray(@NonNull Query query,
                      @NonNull QueryListenOptions options,
                      @NonNull SnapshotParser<T> parser) {
    super(parser);
    mQuery = query;
    mOptions = options;
}
 
开发者ID:firebase,项目名称:FirebaseUI-Android,代码行数:12,代码来源:FirestoreArray.java


示例19: setQuery

import com.google.firebase.firestore.Query; //导入依赖的package包/类
/**
 * Set the query to use (with options) and provide a custom {@link SnapshotParser}.
 * <p>
 * Do not call this method after calling {@link #setSnapshotArray(ObservableSnapshotArray)}.
 */
@NonNull
public Builder<T> setQuery(@NonNull Query query,
                           @NonNull QueryListenOptions options,
                           @NonNull SnapshotParser<T> parser) {
    assertNull(mSnapshots, ERR_SNAPSHOTS_SET);

    mSnapshots = new FirestoreArray<>(query, options, parser);
    return this;
}
 
开发者ID:firebase,项目名称:FirebaseUI-Android,代码行数:15,代码来源:FirestoreRecyclerOptions.java


示例20: query

import com.google.firebase.firestore.Query; //导入依赖的package包/类
private Query query(final String id) {
    return restaurants.document(id)
            .collection("ratings")
            .orderBy("timestamp", Query.Direction.DESCENDING)
            .limit(50);
}
 
开发者ID:amrro,项目名称:firestore-android-arch-components,代码行数:7,代码来源:RestaurantRepository.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Region类代码示例发布时间:2022-05-22
下一篇:
Java Parser类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap