本文整理了Java中com.google.firebase.database.Query
类的一些代码示例,展示了Query
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query
类的具体详情如下:
包路径:com.google.firebase.database.Query
类名称:Query
[英]The Query class (and its subclass, DatabaseReference) are used for reading data. Listeners are attached, and they will be triggered when the corresponding data changes.
Instances of Query are obtained by calling startAt(), endAt(), or limit() on a DatabaseReference.
[中]查询类(及其子类DatabaseReference)用于读取数据。侦听器已附加,当相应的数据更改时,它们将被触发。
查询实例是通过调用数据库引用上的startAt()、endAt()或limit()获得的。
代码示例来源:origin: chat-sdk/chat-sdk-android
query = query.startAt(startTimestamp, Keys.Date);
query = query.orderByChild(Keys.Date).limitToLast(ChatSDK.config().messageHistoryDownloadLimit);
ChildEventListener listener = query.addChildEventListener(new FirebaseEventListener().onChildAdded((snapshot, s, hasValue) -> {
if (hasValue) {
代码示例来源:origin: chat-sdk/chat-sdk-android
.endAt(endDate.getTime() - 1, Keys.Date)
.limitToLast(numberOfMessages + 1);
query.addListenerForSingleValueEvent(new FirebaseEventListener().onValue((snapshot, hasValue) -> {
if(hasValue) {
List<Message> messages = new ArrayList<Message>();
代码示例来源:origin: chat-sdk/chat-sdk-android
private void removeListener () {
if(cel != null) {
ref.removeEventListener(cel);
}
if(vel != null) {
ref.removeEventListener(vel);
}
}
代码示例来源:origin: chat-sdk/chat-sdk-android
public Observable<Message> messageRemovedOn() {
return Observable.create(e -> {
Query query = FirebasePaths.threadMessagesRef(model.getEntityID());
query = query.orderByChild(Keys.Date);
query = query.limitToLast(ChatSDK.config().messageDeletionListenerLimit);
ChildEventListener removedListener = query.addChildEventListener(new FirebaseEventListener().onChildRemoved((snapshot, hasValue) -> {
if(hasValue) {
MessageWrapper message = new MessageWrapper(snapshot);
this.model.removeMessage(message.getModel());
// updateLastMessage().subscribe(new CrashReportingCompletableObserver());
e.onNext(message.getModel());
}
}));
FirebaseReferenceManager.shared().addRef(query, removedListener);
});
}
代码示例来源:origin: chat-sdk/chat-sdk-android
.startAt(value)
.limitToFirst(limit);
query.keepSynced(true);
query.addListenerForSingleValueEvent(new FirebaseEventListener().onValue((snapshot, hasValue) -> {
if (hasValue) {
Object valueObject = snapshot.getValue();
代码示例来源:origin: FrangSierra/RxFirebase
@Override
public void subscribe(final FlowableEmitter<DataSnapshot> emitter) throws Exception {
final ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
emitter.onNext(dataSnapshot);
}
@Override
public void onCancelled(final DatabaseError error) {
if (!emitter.isCancelled())
emitter.onError(new RxFirebaseDataException(error));
}
};
emitter.setCancellable(new Cancellable() {
@Override
public void cancel() throws Exception {
query.removeEventListener(valueEventListener);
}
});
query.addValueEventListener(valueEventListener);
}
}, strategy);
代码示例来源:origin: FrangSierra/RxFirebase
query.addChildEventListener(childEventListener);
代码示例来源:origin: Stoick001/SnapchatClone
private void listenForData() {
DatabaseReference usersDB = FirebaseDatabase.getInstance().getReference().child("users");
Query query = usersDB.orderByChild("username").startAt(mInput.getText().toString()).endAt(mInput.getText().toString() + "\uf8ff");
query.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
代码示例来源:origin: firebase/firebase-admin-java
/**
* Create a query constrained to only return the child node with the given key and value. Note
* that there is at most one such child as keys are unique.
*
* @param value The value to query for
* @param key The name of the child
* @return A query with the new constraint
*/
public Query equalTo(boolean value, String key) {
validateEqualToCall();
return this.startAt(value, key).endAt(value, key);
}
代码示例来源:origin: thinkmobiles/Android-MVP-vs-MVVM-Samples
public final void getCheckInByEmail(final String _email, final OnLoadCallback<CheckIn> loadCallback) {
mDatabaseCheckIn.orderByChild("email").equalTo(_email).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
long count = dataSnapshot.getChildrenCount();
Log.d(TAG, TABLE_CHECK_IN + " | MyCheckIns | Count is: " + count);
final List<CheckIn> checkIns = new ArrayList<CheckIn>();
for (final DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) {
final CheckIn checkIn = dataSnapshot1.getValue(CheckIn.class);
checkIns.add(checkIn);
Log.d(TAG, TABLE_CHECK_IN + " | MyCheckIns | Value " + checkIn.checkInMessage);
}
loadCallback.onDataChange(checkIns);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.d(TAG, TABLE_CHECK_IN + " | MyCheckIns | Failed to read: ", databaseError.toException());
loadCallback.onCancelled();
}
});
}
代码示例来源:origin: akshayejh/Lapit---Android-Firebase-Chat-App
Query messageQuery = messageRef.orderByKey().endAt(mLastKey).limitToLast(10);
messageQuery.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
代码示例来源:origin: UdacityAndroidDevScholarship/quiz-app
@Override
public void fetchResources(int startFrom, int limit, Callback<List<Resource>> callback) {
ValueEventListener listener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
if (snapshot != null) {
List<Resource> resources = new ArrayList<>();
for (DataSnapshot childSnapshot : snapshot.getChildren()) {
Resource resource = childSnapshot.getValue(Resource.class);
resources.add(resource);
}
callback.onReponse(resources);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
callback.onError();
}
};
Query resourcesQuery = mResourcesRef.orderByChild(KEY_TIMESTAMP);
if (limit > 0) {
resourcesQuery.limitToFirst(limit);
}
resourcesQuery.addValueEventListener(listener);
mValueListeners.add(listener);
}
代码示例来源:origin: firebase/firebase-admin-java
/**
* Create a query constrained to only return child nodes with a value less than or equal to the
* given value, using the given orderBy directive or priority as default.
*
* @param value The value to end at, inclusive
* @return A Query with the new constraint
* @since 2.0
*/
public Query endAt(boolean value) {
return endAt(value, null);
}
代码示例来源:origin: TomGrill/gdx-firebase
@Override
public void addListenerForSingleValueEvent(final ValueEventListener listener) {
query.addListenerForSingleValueEvent(new com.google.firebase.database.ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
listener.onDataChange(new DesktopDataSnapshot(dataSnapshot));
}
@Override
public void onCancelled(DatabaseError databaseError) {
listener.onCancelled(new DesktopDatabaseError(databaseError));
}
});
}
代码示例来源:origin: firebase/snippets-android
private void queryRecentScores() {
scoresRef.orderByValue().limitToLast(4).addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot snapshot, String previousChild) {
scoresRef.orderByValue().limitToLast(2).addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot snapshot, String previousChild) {
代码示例来源:origin: hieuapp/android-firebase-chat
mapQuery.get(id).addChildEventListener(mapChildListener.get(id));
mapMark.put(id, true);
} else {
mapQuery.get(id).removeEventListener(mapChildListener.get(id));
mapQuery.get(id).addChildEventListener(mapChildListener.get(id));
mapMark.put(id, true);
代码示例来源:origin: firebase/firebase-admin-java
/**
* Create a query constrained to only return child nodes with a value greater than or equal to the
* given value, using the given orderBy directive or priority as default.
*
* @param value The value to start at, inclusive
* @return A Query with the new constraint
*/
public Query startAt(String value) {
return startAt(value, null);
}
代码示例来源:origin: firebase/quickstart-java
public void doRun() throws JobInterruptException {
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
// Top 5 Posts in the database, ordered by stars
// [START top_posts_query]
Query topPostsQuery = ref.child("posts").orderByChild("starCount").limitToLast(5);
// [END top_posts_query]
// All Users
final DatabaseReference allUsersRef = ref.child("users");
topPostsQuery.addListenerForSingleValueEvent(new ValueEventListener() {
public void onDataChange(final DataSnapshot topPostsSnapshot) {
allUsersRef.addListenerForSingleValueEvent(new ValueEventListener() {
public void onDataChange(DataSnapshot allUsersSnapshot) {
// Get users and posts as lists
Map<String,User> users = allUsersSnapshot.getValue(new GenericTypeIndicator<Map<String, User>>() {});
List<Post> posts = topPostsSnapshot.getValue(new GenericTypeIndicator<List<Post>>() {});
// Send email to all users about the top 5 posts
MyEmailer.sendWeeklyEmail(users, posts);
}
public void onCancelled(DatabaseError databaseError) {
System.out.println("WeeklyEmailJob: could not get all users");
System.out.println("WeeklyEmailJob: " + databaseError.getMessage());
}
});
}
public void onCancelled(DatabaseError databaseError) {
System.out.println("WeeklyEmailJob: could not get top posts");
System.out.println("WeeklyEmailJob: " + databaseError.getMessage());
}
});
}
代码示例来源:origin: dragosholban/AndroidMyInstagramApp
Query likesQuery = database.child("likes").orderByChild("imageId").equalTo(image.key);
likesQuery.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
代码示例来源:origin: dragosholban/AndroidMyInstagramApp
Query imagesQuery = database.child("images").orderByKey().limitToFirst(100);
imagesQuery.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
内容来源于网络,如有侵权,请联系作者删除!