本文整理匯總了Java中com.google.firebase.database.DatabaseReference.getRoot方法的典型用法代碼示例。如果您正苦於以下問題:Java DatabaseReference.getRoot方法的具體用法?Java DatabaseReference.getRoot怎麽用?Java DatabaseReference.getRoot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.firebase.database.DatabaseReference
的用法示例。
在下文中一共展示了DatabaseReference.getRoot方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testRootForRootAndNonRootLocations
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testRootForRootAndNonRootLocations() throws DatabaseException {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
ref = ref.getRoot();
assertEquals(IntegrationTestUtils.getDatabaseUrl(), ref.toString());
ref = ref.getRoot(); // Should be a no-op
assertEquals(IntegrationTestUtils.getDatabaseUrl(), ref.toString());
}
示例2: parseEvent
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
private static TestEvent parseEvent(
DatabaseReference ref, Map<String, Object> eventSpec, String basePath) {
String path = (String) eventSpec.get("path");
Event.EventType type;
String eventTypeStr = (String) eventSpec.get("type");
if (eventTypeStr.equals("value")) {
type = Event.EventType.VALUE;
} else if (eventTypeStr.equals("child_added")) {
type = Event.EventType.CHILD_ADDED;
} else if (eventTypeStr.equals("child_moved")) {
type = Event.EventType.CHILD_MOVED;
} else if (eventTypeStr.equals("child_removed")) {
type = Event.EventType.CHILD_REMOVED;
} else if (eventTypeStr.equals("child_changed")) {
type = Event.EventType.CHILD_CHANGED;
} else {
throw new RuntimeException("Unknown event type: " + eventTypeStr);
}
String childName = (String) eventSpec.get("name");
String prevName = eventSpec.get("prevName") != null ? (String) eventSpec.get("prevName") : null;
Object data = eventSpec.get("data");
DatabaseReference rootRef = basePath != null ? ref.getRoot().child(basePath) : ref.getRoot();
DatabaseReference pathRef = rootRef.child(path);
if (childName != null) {
pathRef = pathRef.child(childName);
}
Node node = NodeUtilities.NodeFromJSON(data);
// TODO: don't use priority index by default
DataSnapshot snapshot = InternalHelpers.createDataSnapshot(pathRef, IndexedNode.from(node));
return new TestEvent(type, snapshot, prevName, null);
}