當前位置: 首頁>>代碼示例>>Java>>正文


Java Query類代碼示例

本文整理匯總了Java中com.google.firebase.database.Query的典型用法代碼示例。如果您正苦於以下問題:Java Query類的具體用法?Java Query怎麽用?Java Query使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Query類屬於com.google.firebase.database包,在下文中一共展示了Query類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testDifferentIndependentQueries

import com.google.firebase.database.Query; //導入依賴的package包/類
@Test
public void testDifferentIndependentQueries() throws Exception {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
  Query query1 = ref.limitToFirst(1);
  Query query2 = ref.limitToFirst(2);

  query1.keepSynced(true);
  assertIsKeptSynced(query1);
  assertNotKeptSynced(query2);

  query2.keepSynced(true);
  assertIsKeptSynced(query1);
  assertIsKeptSynced(query2);

  query1.keepSynced(false);
  assertIsKeptSynced(query2);
  assertNotKeptSynced(query1);

  query2.keepSynced(false);
  assertNotKeptSynced(query1);
  assertNotKeptSynced(query2);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:23,代碼來源:KeepSyncedTestIT.java

示例2: FirebaseItemAdapter

import com.google.firebase.database.Query; //導入依賴的package包/類
public FirebaseItemAdapter(Class<Item> modelClass, Query ref) {
    mModelClass = modelClass;
    mSnapshots = new FirebaseArray(ref);

    mSnapshots.setOnChangedListener(new FirebaseArray.OnChangedListener() {
        @Override
        public void onChanged(EventType type, int index, int oldIndex) {
            switch (type) {
                case Added:
                    notifyItemInserted(index);
                    break;
                case Changed:
                    notifyItemChanged(index);
                    break;
                case Removed:
                    notifyItemRemoved(index);
                    break;
                case Moved:
                    notifyItemMoved(oldIndex, index);
                    break;
                default:
                    throw new IllegalStateException("Incomplete case statement");
            }
        }
    });
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:FirebaseItemAdapter.java

示例3: searchWithoutFilter

import com.google.firebase.database.Query; //導入依賴的package包/類
protected void searchWithoutFilter() {
    final String keyword = etSearch.getText().toString().trim();
    Query query = mDatabase.orderByChild("category").equalTo(keyword);

    mDatabase.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for(DataSnapshot snap : dataSnapshot.getChildren()) {
                String itemName = snap.child("itemName").getValue(String.class);
                if(itemName.toLowerCase().contains(keyword.toLowerCase())) {
                    items.add(itemName);
                    itemKeys.add(snap.getKey());
                }
            }
            loadListView();
        }
        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}
 
開發者ID:ppdesai434,項目名稱:MavsSnapUp,代碼行數:23,代碼來源:SearchActivity.java

示例4: loaditems

import com.google.firebase.database.Query; //導入依賴的package包/類
private void loaditems() {
    Query query = mDatabase.orderByChild("createdBy").equalTo(mAuth.getCurrentUser().getUid());
    query.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            items.clear();
            itemKey.clear();
            for(DataSnapshot snap : dataSnapshot.getChildren()) {
                if(snap.child("isItemSold").getValue(String.class)==null){
                    items.add(snap.child("itemName").getValue(String.class));
                    itemKey.add(snap.getKey());
                }
            }
            loadListView();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}
 
開發者ID:ppdesai434,項目名稱:MavsSnapUp,代碼行數:23,代碼來源:MyItemsActivity.java

示例5: getFollowingList

import com.google.firebase.database.Query; //導入依賴的package包/類
public void getFollowingList(String userId, final OnCompleteGetUserFollowingListener listener)
{
    RemoteDatabaseManager rdm = new RemoteDatabaseManager();

    Query recentPostsQuery = rdm.getUsersReference().child(userId).child("following")
            .limitToFirst(3000);
    recentPostsQuery.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            ArrayList<String> arrayList = new ArrayList<String>();

            for (DataSnapshot messageSnapshot: dataSnapshot.getChildren()) {
                String name = (String) messageSnapshot.getKey();
                Log.e("UserManager", "Name : "+ name);
                arrayList.add(name);
            }

            listener.onComplete(arrayList);
            followingListCache = arrayList;
        }

        @Override
        public void onCancelled(DatabaseError databaseError) { }
    });
}
 
開發者ID:icaynia,項目名稱:pracler,代碼行數:26,代碼來源:UserManager.java

示例6: findBookSearch

import com.google.firebase.database.Query; //導入依賴的package包/類
public Query findBookSearch(String userId, String folderId) {
    if (folderId == null) {

        return mDatabaseReference.child(userId)
                .child(REF_FOLDERS)
                .child(REF_MY_BOOKS_FOLDER)
                .child(REF_BOOKS)
                .orderByChild("volumeInfo/searchField");

    } else {

        return mDatabaseReference.child(userId)
                .child(REF_FOLDERS)
                .child(folderId)
                .child(REF_BOOKS)
                .orderByChild("volumeInfo/searchField");

    }
}
 
開發者ID:victoraldir,項目名稱:BuddyBook,代碼行數:20,代碼來源:FirebaseDatabaseHelper.java

示例7: singleValue

import com.google.firebase.database.Query; //導入依賴的package包/類
@NonNull public static Observable<DataSnapshot> singleValue(final Query query) {
    return Observable.create(new Observable.OnSubscribe<DataSnapshot>() {
        @Override public void call(final Subscriber<? super DataSnapshot> subscriber) {
            final ValueEventListener valueEvent = query.addValueEventListener(new ValueEventListener() {
                @Override public void onDataChange(DataSnapshot dataSnapshot) {
                    if (!subscriber.isUnsubscribed()) {
                        subscriber.onNext(dataSnapshot);
                    }
                }
                @Override public void onCancelled(DatabaseError databaseError) {
                    subscriber.onError(databaseError.toException());
                }
            });
            subscriber.add(Subscriptions.create(new Action0() {
                @Override public void call() {
                    query.removeEventListener(valueEvent);
                }
            }));
        }
    });
}
 
開發者ID:isfaaghyth,項目名稱:RxFBase,代碼行數:22,代碼來源:RxFirebase.java

示例8: onResume

import com.google.firebase.database.Query; //導入依賴的package包/類
@Override
protected void onResume() {
    super.onResume();

    Query listenNewNotif = FirebaseDatabase
            .getInstance()
            .getReference(getString(R.string.firebase_key_last_notif))
            .child(getString(R.string.firebase_key_notif_id));
    listenNewNotif.keepSynced(true);
    final DatabaseHelper dbHelper = new DatabaseHelper(this);
    listenNewNotif.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            if(dbHelper.getUnreadCount()>0 && notifMenu!=null){
                notifMenu.setIcon(getResources().getDrawable(R.drawable.ic_notification_new));
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.d(TAG,databaseError.getMessage());
        }
    });
}
 
開發者ID:CSI-KJSCE,項目名稱:CSI-KJSCEOfficial,代碼行數:26,代碼來源:MainActivity.java

示例9: getObjects

import com.google.firebase.database.Query; //導入依賴的package包/類
public <T> Observable<T> getObjects(final Query query, final Class<T> objectClass, final boolean useRootElement) {
    return Observable.create(new Observable.OnSubscribe<T>() {
        @Override
        public void call(final Subscriber<? super T> subscriber) {
            query.addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    if(useRootElement) {
                        converter.convert(dataSnapshot, objectClass, subscriber);
                    } else {
                        for (DataSnapshot entry : dataSnapshot.getChildren()) {
                            converter.convert(entry, objectClass, subscriber);
                        }
                    }
                    subscriber.onCompleted();
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });
        }
    });
}
 
開發者ID:florent37,項目名稱:EasyFirebase,代碼行數:26,代碼來源:RxFirebaseHelper.java

示例10: observeSingleValueEvent

import com.google.firebase.database.Query; //導入依賴的package包/類
/**
 * Listener for a single change in te data at the given query location.
 *
 * @param query reference represents a particular location in your Database and can be used for reading or writing data to that Database location.
 * @return a {@link Maybe} which emits the actual state of the database for the given query.
 */
@NonNull
public static Maybe<DataSnapshot> observeSingleValueEvent(@NonNull final Query query) {
   return Maybe.create(new MaybeOnSubscribe<DataSnapshot>() {
      @Override
      public void subscribe(final MaybeEmitter<DataSnapshot> emitter) throws Exception {
         query.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
               emitter.onSuccess(dataSnapshot);
               emitter.onComplete();
            }

            @Override
            public void onCancelled(DatabaseError error) {
               emitter.onError(new RxFirebaseDataException(error));
            }
         });
      }
   });
}
 
開發者ID:DVT,項目名稱:showcase-android,代碼行數:27,代碼來源:RxFirebaseDatabase.java

示例11: populateProfile

import com.google.firebase.database.Query; //導入依賴的package包/類
public void populateProfile() {
    nameEt.setText(currentUser.getDisplayName());
    emailEt.setText(currentUser.getEmail());

    Query userQuery = databaseReference.child("users").child(currentUser.getUid());
    userQuery.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            try {
                User user = dataSnapshot.getValue(User.class);
                nameEt.setText(user.getName());
                emailEt.setText(user.getEmail());
                collegeEt.setText(user.getCollege());
                departmentEt.setText(user.getDepartment());
                yearEt.setText(String.valueOf(user.getYear()));
                mobileEt.setText(user.getMobile());
            } catch (Exception e) {
                Log.e("populateProfile", e.toString());
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}
 
開發者ID:adithya321,項目名稱:Instincts-2k17,代碼行數:27,代碼來源:RegisterActivity.java

示例12: open

import com.google.firebase.database.Query; //導入依賴的package包/類
/**
 * Creates a query for habit events from each user followed
 */
@Override
public void open() {
    recentEvents.clear();
    recentHabitEventMap.clear();

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -7);
    long millis = cal.getTimeInMillis();

    for (String id : idList) {
        Query eventsQuery = FirebaseDatabase.getInstance().getReference("events/" + id)
                .orderByChild("eventDate").startAt(millis).endAt(DateTime.now().getMillis());
        eventsQuery.addChildEventListener(this);
        activeQueries.add(eventsQuery);
    }
}
 
開發者ID:CMPUT301F17T13,項目名稱:cat-is-a-dog,代碼行數:20,代碼來源:RecentHabitEventHistoryDataSource.java

示例13: open

import com.google.firebase.database.Query; //導入依賴的package包/類
/**
 * Creates one query per week up to 4 weeks in the past
 */
@Override
public void open() {
    completionResultArray.clear();
    completionRates = new double[4];
    completionLatch = new CountDownLatch(4);

    if(habit.getSchedule().size() > 0) {
        for(Week week : DateUtil.GetNPastWeeks(DateTime.now(), 4)) {
            String startKey = HabitEventDataModel.habitStampKey(habit.getKey(), week.getStartOfWeek());
            String endKey = HabitEventDataModel.habitStampKey(habit.getKey(), week.getEndOfWeek());

            Query eventCountQuery = FirebaseDatabase.getInstance().getReference("events/" + habit.getUserId())
                    .orderByChild("habitStamp").startAt(startKey).endAt(endKey);

            eventCountQuery.addValueEventListener(this);
            queryRegister.add(eventCountQuery);
        }
    }
}
 
開發者ID:CMPUT301F17T13,項目名稱:cat-is-a-dog,代碼行數:23,代碼來源:CompletionMetricDataSource.java

示例14: getPostListByUser

import com.google.firebase.database.Query; //導入依賴的package包/類
public void getPostListByUser(final OnDataChangedListener<Post> onDataChangedListener, String userId) {
    DatabaseReference databaseReference = database.getReference("posts");
    Query postsQuery;
    postsQuery = databaseReference.orderByChild("authorId").equalTo(userId);

    postsQuery.keepSynced(true);
    postsQuery.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            PostListResult result = parsePostList((Map<String, Object>) dataSnapshot.getValue());
            onDataChangedListener.onListChanged(result.getPosts());
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            LogUtil.logError(TAG, "getPostListByUser(), onCancelled", new Exception(databaseError.getMessage()));
        }
    });
}
 
開發者ID:rozdoum,項目名稱:social-app-android,代碼行數:20,代碼來源:DatabaseHelper.java

示例15: observe

import com.google.firebase.database.Query; //導入依賴的package包/類
private Observable<DataSnapshot> observe(final Query ref) {
    return Observable.create(emitter -> {
        final ValueEventListener listener =
                ref.addValueEventListener(new ValueEventListener() {
                    @Override public void onDataChange(DataSnapshot dataSnapshot) {
                        emitter.onNext(dataSnapshot);
                    }

                    @Override public void onCancelled(DatabaseError databaseError) {
                        emitter.onError(new FirebaseException(databaseError.getMessage()));
                    }
                });

        emitter.setCancellable(() -> ref.removeEventListener(listener));
    });
}
 
開發者ID:riteshakya037,項目名稱:Wallpapers-Android-Clean-Architecture,代碼行數:17,代碼來源:Comments.java


注:本文中的com.google.firebase.database.Query類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。