当前位置: 首页>>代码示例>>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;未经允许,请勿转载。