本文整理汇总了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();
}
示例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();
}
示例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();
}