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


Java DatabaseReference.limitToLast方法代碼示例

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


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

示例1: testCreateBasicQueries

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testCreateBasicQueries() {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);

  // Just make sure they don't throw anything
  ref.limitToLast(10);
  ref.startAt("199").limitToLast(10);
  ref.startAt("199", "test").limitToLast(10);
  ref.endAt(199).limitToLast(1);
  ref.startAt(50, "test").endAt(100, "tree");
  ref.startAt(4).endAt(10);
  ref.startAt(null).endAt(10);
  ref.orderByChild("child");
  ref.orderByChild("child/deep/path");
  ref.orderByValue();
  ref.orderByPriority();
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:18,代碼來源:QueryTestIT.java

示例2: testCacheInvalidation

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testCacheInvalidation()
    throws InterruptedException, TestFailure, TimeoutException {
  List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 2);
  DatabaseReference reader = refs.get(0);
  DatabaseReference writer = refs.get(1);

  final AtomicBoolean startChecking = new AtomicBoolean(false);
  final Semaphore ready = new Semaphore(0);
  final ReadFuture future = new ReadFuture(reader.limitToLast(2), 
      new ReadFuture.CompletionCondition() {
        @Override
        public boolean isComplete(List<EventRecord> events) {
          DataSnapshot snap = events.get(events.size() - 1).getSnapshot();
          Object result = snap.getValue();
          if (startChecking.compareAndSet(false, true) && result == null) {
            ready.release(1);
            return false;
          }
          // We already initialized the location, and now the remove has
          // happened
          // so that
          // we have no more data
          return startChecking.get() && result == null;
        }
      });

  TestHelpers.waitFor(ready);
  for (int i = 0; i < 4; ++i) {
    writer.child("k" + i).setValueAsync(i);
  }

  writer.removeValueAsync();
  future.timedGet();
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:36,代碼來源:QueryTestIT.java

示例3: loadMessages

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
public Promise<List<BMessage>, Void, Void> loadMessages(Integer lastNMessages){
    final Deferred<List<BMessage>, Void, Void> deferred = new DeferredObject<>();

    DatabaseReference messageRef = FirebasePaths.threadRef(model.getEntityID())
            .child(BFirebaseDefines.Path.BMessagesPath);

    Query msgQuery;
    // If number of messages set to retrieve is -1, retrieve all messages
    if(lastNMessages == -1){
        msgQuery = messageRef;
    }else {
        msgQuery = messageRef.limitToLast(lastNMessages);
    }

    msgQuery.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {
            if (snapshot.getValue() != null)
            {
                if (DEBUG) Timber.d("MessagesSnapShot: %s", snapshot.getValue().toString());

                List<BMessage> msgs = new ArrayList<BMessage>();

                BMessageWrapper msg;
                for (String key : ((Map<String, Object>) snapshot.getValue()).keySet())
                {
                    msg = new BMessageWrapper(BThreadWrapper.this.getModel() ,snapshot.child(key));

                    DaoCore.updateEntity(msg.model);

                    msgs.add(msg.model);
                }
                deferred.resolve(msgs);
            }
            else
            {
                deferred.reject(null);
            }
        }

        @Override
        public void onCancelled(DatabaseError firebaseError) {
            deferred.reject(null);
        }
    });

    return deferred.promise();
}
 
開發者ID:MobileDev418,項目名稱:AndroidBackendlessChat,代碼行數:49,代碼來源:BThreadWrapper.java


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