Java Code Examples for com.google.firebase.database.DatabaseReference#getRoot()

The following examples show how to use com.google.firebase.database.DatabaseReference#getRoot() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SyncPointTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 2
Source File: DataTestIT.java    From firebase-admin-java with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 3
Source File: SyncPointTest.java    From firebase-admin-java with Apache License 2.0 5 votes vote down vote up
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);
}