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