public final class RemoteDatabaseClient extends java.lang.Object implements FirebaseClient
FirebaseClient
which operates via the Firebase REST API and the Java Admin SDK.
The client uses the Java Firebase Admin SDK for subscribing to events of a given database
node. The API exposes the ChildEventListener
so that the caller may build more complex
"nested" subscriptions without a need to re-fetch database references.
For all the other operations, the client uses the Firebase REST API as described in the documentation.
Modifier and Type | Class and Description |
---|---|
static class |
RemoteDatabaseClient.Builder
A builder for the
RemoteDatabaseClient instances. |
Modifier and Type | Method and Description |
---|---|
void |
create(io.spine.web.firebase.NodePath nodePath,
NodeValue value)
Writes the specified value to the Firebase database node.
|
void |
delete(io.spine.web.firebase.NodePath nodePath)
Deletes the node under the given path.
|
java.util.Optional<NodeValue> |
fetchNode(io.spine.web.firebase.NodePath nodePath)
Retrieves the value of the specified Firebase database node.
|
static RemoteDatabaseClient.Builder |
newBuilder()
Creates a new instance of
Builder for RemoteDatabaseClient instances. |
void |
subscribeTo(io.spine.web.firebase.NodePath nodePath,
com.google.firebase.database.ChildEventListener listener)
Subscribes to the child events of the given node.
|
void |
update(io.spine.web.firebase.NodePath nodePath,
NodeValue value)
Merges the specified value to the Firebase database node.
|
public java.util.Optional<NodeValue> fetchNode(io.spine.web.firebase.NodePath nodePath)
FirebaseClient
The null
value (i.e. the node is not present in the database) is returned as
Optional.empty()
.
fetchNode
in interface FirebaseClient
nodePath
- the path to the requested node in the databaseOptional
if the node is not present in the databasepublic void subscribeTo(io.spine.web.firebase.NodePath nodePath, com.google.firebase.database.ChildEventListener listener)
FirebaseClient
subscribeTo
in interface FirebaseClient
nodePath
- the path to the node to subscribe tolistener
- the callbacks invoked on child eventspublic void create(io.spine.web.firebase.NodePath nodePath, NodeValue value)
FirebaseClient
If the node exists, the value is overridden.
create
in interface FirebaseClient
nodePath
- the path to the node in the Firebase databasevalue
- the value to writepublic void update(io.spine.web.firebase.NodePath nodePath, NodeValue value)
FirebaseClient
If the node doesn't exist, it is created with the given value.
If the node exists, the value entries are added to the node children overwriting common ones if present.
update
in interface FirebaseClient
nodePath
- the path to the node in the Firebase databasevalue
- the value to mergepublic void delete(io.spine.web.firebase.NodePath nodePath)
FirebaseClient
Does nothing if the node does not exist.
delete
in interface FirebaseClient
nodePath
- the path to the node to deletepublic static RemoteDatabaseClient.Builder newBuilder()
Builder
for RemoteDatabaseClient
instances.Builder