Class FaunaClient
- java.lang.Object
-
- com.faunadb.client.FaunaClient
-
public class FaunaClient extends Object
The Java native client for FaunaDB.The client is asynchronous. All methods that performs latent operations return an instance of
CompletableFuture.Queries are constructed by using the static methods in the
Example:Languageclass.import static com.faunadb.client.query.Language.*; FaunaClient client = FaunaClient.builder() .withSecret("someAuthToken") .build(); client.query( Get( Ref(Collection("some_collection"), "123") ) );- See Also:
Language
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFaunaClient.BuilderA builder for creating an instance ofFaunaClient
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FaunaClient.Builderbuilder()Creates a newFaunaClient.BuilderlonggetLastTxnTime()Get the freshest timestamp reported to this client.FaunaClientnewSessionClient(String secret)Creates a session client with the user secret provided.CompletableFuture<Value>query(Expr expr)Issues a Query to FaunaDB.CompletableFuture<List<Value>>query(Expr... exprs)Issues multiple queries to FaunaDB.CompletableFuture<Value>query(Expr expr, Duration timeout)Issues a Query to FaunaDB.CompletableFuture<Value>query(Expr expr, Optional<Duration> timeout)Issues a Query to FaunaDB.CompletableFuture<List<Value>>query(List<? extends Expr> exprs)Issues multiple queries to FaunaDB.CompletableFuture<List<Value>>query(List<? extends Expr> exprs, Duration timeout)Issues multiple queries to FaunaDB.CompletableFuture<List<Value>>query(List<? extends Expr> exprs, Optional<Duration> timeout)Issues multiple queries to FaunaDB.CompletableFuture<MetricsResponse>queryWithMetrics(Expr expr, Optional<Duration> timeout)Issues a Query to FaunaDB with extra informationCompletableFuture<Flow.Publisher<Value>>stream(Expr expr)Creates a subscription to the result of the given read-only expression.CompletableFuture<Flow.Publisher<Value>>stream(Expr expr, List<EventField> fields, boolean snapshot)Creates a subscription to the result of the given read-only expression.voidsyncLastTxnTime(long timestamp)Sync the freshest timestamp seen by this client.
-
-
-
Method Detail
-
builder
public static FaunaClient.Builder builder()
Creates a newFaunaClient.Builder- Returns:
FaunaClient.Builder
-
newSessionClient
public FaunaClient newSessionClient(String secret)
Creates a session client with the user secret provided. Queries submitted to a session client will be authenticated with the secret provided. A session client shares its parent'sConnectioninstance.- Parameters:
secret- user secret for the session client- Returns:
- a new
FaunaClient
-
query
public CompletableFuture<Value> query(Expr expr)
Issues a Query to FaunaDB.Queries are constructed by the helper methods in the
Languageclass.Responses are represented as structured tree where each node is a
Valueinstance.Valueinstances can be converted to native types. SeeValueclass for details.- Parameters:
expr- the query to be executed.- Returns:
- a
CompletableFuturecontaining the root node of the response tree. - See Also:
Value,Language
-
query
public CompletableFuture<Value> query(Expr expr, Duration timeout)
Issues a Query to FaunaDB.Queries are constructed by the helper methods in the
Languageclass.Responses are represented as structured tree where each node is a
Valueinstance.Valueinstances can be converted to native types. SeeValueclass for details.- Parameters:
expr- the query to be executed.timeout- the timeout for the current query. It replaces the timeout value set for thisFaunaClient(if any), for the scope of this query. The timeout value has milliseconds precision.- Returns:
- a
CompletableFuturecontaining the root node of the response tree. - See Also:
Value,Language
-
query
public CompletableFuture<Value> query(Expr expr, Optional<Duration> timeout)
Issues a Query to FaunaDB.Queries are constructed by the helper methods in the
Languageclass.Responses are represented as structured tree where each node is a
Valueinstance.Valueinstances can be converted to native types. SeeValueclass for details.- Parameters:
expr- the query to be executed.timeout- the timeout for the current query. It replaces the timeout value set for thisFaunaClient(if any), for the scope of this query. The timeout value has milliseconds precision.- Returns:
- a
CompletableFuturecontaining the root node of the response tree. - See Also:
Value,Language
-
queryWithMetrics
public CompletableFuture<MetricsResponse> queryWithMetrics(Expr expr, Optional<Duration> timeout)
Issues a Query to FaunaDB with extra informationQueries are constructed by the helper methods in the
Languageclass.Responses are represented as structured tree where each node is a
Valueinstance.Valueinstances can be converted to native types. SeeValueclass for details.- Parameters:
expr- the query to be executed.timeout- the timeout for the current query. It replaces the timeout value set for thisFaunaClient(if any), for the scope of this query. The timeout value has milliseconds precision.- Returns:
- a
CompletableFuturecontaining the root node of the response tree. - See Also:
MetricsResponse,Language
-
query
public CompletableFuture<List<Value>> query(Expr... exprs)
Issues multiple queries to FaunaDB.These queries are sent to FaunaDB in a single request. A list containing all responses is returned in the same order as the issued queries.
- Parameters:
exprs- the list of queries to be sent to FaunaDB.- Returns:
- a
CompletableFuturecontaining an ordered list of the query's responses.
-
query
public CompletableFuture<List<Value>> query(List<? extends Expr> exprs)
Issues multiple queries to FaunaDB.These queries are sent to FaunaDB in a single request. A list containing all responses is returned in the same order as the issued queries.
- Parameters:
exprs- the list of queries to be sent to FaunaDB.- Returns:
- a
CompletableFuturecontaining an ordered list of the query's responses.
-
query
public CompletableFuture<List<Value>> query(List<? extends Expr> exprs, Duration timeout)
Issues multiple queries to FaunaDB.These queries are sent to FaunaDB in a single request. A list containing all responses is returned in the same order as the issued queries.
- Parameters:
exprs- the list of queries to be sent to FaunaDB.timeout- the timeout for the current query. It replaces the timeout value set for thisFaunaClient(if any), for the scope of this query. The timeout value has milliseconds precision.- Returns:
- a
CompletableFuturecontaining an ordered list of the query's responses.
-
query
public CompletableFuture<List<Value>> query(List<? extends Expr> exprs, Optional<Duration> timeout)
Issues multiple queries to FaunaDB.These queries are sent to FaunaDB in a single request. A list containing all responses is returned in the same order as the issued queries.
- Parameters:
exprs- the list of queries to be sent to FaunaDB.timeout- the timeout for the current query. It replaces the timeout value set for thisFaunaClient(if any), for the scope of this query. The timeout value has milliseconds precision.- Returns:
- a
CompletableFuturecontaining an ordered list of the query's responses.
-
syncLastTxnTime
public void syncLastTxnTime(long timestamp)
Sync the freshest timestamp seen by this client.This has no effect if staler than currently stored timestamp.
WARNING: This should be used only when coordinating timestamps across multiple clients. Moving the timestamp arbitrarily forward into the future will cause transactions to stall.
-
getLastTxnTime
public long getLastTxnTime()
Get the freshest timestamp reported to this client.
-
stream
public CompletableFuture<Flow.Publisher<Value>> stream(Expr expr)
Creates a subscription to the result of the given read-only expression. When executed, the expression must only perform reads and produce a single streamable type, such as a reference or a version. Expressions that attempt to perform writes or produce non-streamable types will result in an error. Otherwise, any expression can be used to initiate a stream, including user-defined function calls.- Parameters:
expr- the query to subscribe to.- Returns:
- a
CompletableFuturecontaining aFlow.PublisherofValue. - See Also:
Value,Language
-
stream
public CompletableFuture<Flow.Publisher<Value>> stream(Expr expr, List<EventField> fields, boolean snapshot)
Creates a subscription to the result of the given read-only expression. When executed, the expression must only perform reads and produce a single streamable type, such as a reference or a version. Expressions that attempt to perform writes or produce non-streamable types will result in an error. Otherwise, any expression can be used to initiate a stream, including user-defined function calls.- Parameters:
expr- the query to subscribe to.fields- fields to opt-in on the events.snapshot- if true the second event will be a snapshot event of the target- Returns:
- a
CompletableFuturecontaining aFlow.PublisherofValue. - See Also:
Value,Language
-
-