public class FaunaClient
extends java.lang.Object
implements java.lang.AutoCloseable
The client is asynchronous. All methods that performs latent operations
return an instance of CompletableFuture
.
The close()
method must be called in order to
release the FaunaClient
I/O resources.
Queries are constructed by using the static methods in the
Language
class.
import static com.faunadb.client.query.Language.*;
FaunaClient client = FaunaClient.builder()
.withSecret("someAuthToken")
.build();
client.query(
Get(
Ref(Collection("some_collection"), "123")
)
);
Language
Modifier and Type | Class and Description |
---|---|
static class |
FaunaClient.Builder
A builder for creating an instance of
FaunaClient |
Modifier and Type | Method and Description |
---|---|
static FaunaClient.Builder |
builder()
Creates a new
FaunaClient.Builder |
void |
close()
Releases any resources being held by the
FaunaClient instance. |
long |
getLastTxnTime()
Get the freshest timestamp reported to this client.
|
FaunaClient |
newSessionClient(java.lang.String secret)
Creates a session client with the user secret provided.
|
java.util.concurrent.CompletableFuture<java.util.List<Value>> |
query(Expr... exprs)
Issues multiple queries to FaunaDB.
|
java.util.concurrent.CompletableFuture<Value> |
query(Expr expr)
Issues a Query to FaunaDB.
|
java.util.concurrent.CompletableFuture<Value> |
query(Expr expr,
java.time.Duration timeout)
Issues a Query to FaunaDB.
|
java.util.concurrent.CompletableFuture<Value> |
query(Expr expr,
java.util.Optional<java.time.Duration> timeout)
Issues a Query to FaunaDB.
|
java.util.concurrent.CompletableFuture<java.util.List<Value>> |
query(java.util.List<? extends Expr> exprs)
Issues multiple queries to FaunaDB.
|
java.util.concurrent.CompletableFuture<java.util.List<Value>> |
query(java.util.List<? extends Expr> exprs,
java.time.Duration timeout)
Issues multiple queries to FaunaDB.
|
java.util.concurrent.CompletableFuture<java.util.List<Value>> |
query(java.util.List<? extends Expr> exprs,
java.util.Optional<java.time.Duration> timeout)
Issues multiple queries to FaunaDB.
|
void |
syncLastTxnTime(long timestamp)
Sync the freshest timestamp seen by this client.
|
public static FaunaClient.Builder builder()
FaunaClient.Builder
FaunaClient.Builder
public FaunaClient newSessionClient(java.lang.String secret)
Connection
instance
and must be closed after used.secret
- user secret for the session clientFaunaClient
public void close()
FaunaClient
instance.close
in interface java.lang.AutoCloseable
public java.util.concurrent.CompletableFuture<Value> query(Expr expr, java.time.Duration timeout)
Queries are constructed by the helper methods in the Language
class.
Responses are represented as structured tree where each node is a Value
instance.
Value
instances can be converted to native types. See Value
class for details.
expr
- the query to be executed.timeout
- the timeout for the current query. It replaces the timeout value set for this
FaunaClient
(if any), for the scope of this query. The timeout value
has milliseconds precision.CompletableFuture
containing the root node of the response tree.Value
,
Language
public java.util.concurrent.CompletableFuture<Value> query(Expr expr, java.util.Optional<java.time.Duration> timeout)
Queries are constructed by the helper methods in the Language
class.
Responses are represented as structured tree where each node is a Value
instance.
Value
instances can be converted to native types. See Value
class for details.
expr
- the query to be executed.timeout
- the timeout for the current query. It replaces the timeout value set for this
FaunaClient
(if any), for the scope of this query. The timeout value
has milliseconds precision.CompletableFuture
containing the root node of the response tree.Value
,
Language
public java.util.concurrent.CompletableFuture<java.util.List<Value>> query(Expr... exprs)
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.
exprs
- the list of queries to be sent to FaunaDB.CompletableFuture
containing an ordered list of the query's responses.public java.util.concurrent.CompletableFuture<java.util.List<Value>> query(java.util.List<? extends Expr> exprs)
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.
exprs
- the list of queries to be sent to FaunaDB.CompletableFuture
containing an ordered list of the query's responses.public java.util.concurrent.CompletableFuture<java.util.List<Value>> query(java.util.List<? extends Expr> exprs, java.time.Duration timeout)
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.
exprs
- the list of queries to be sent to FaunaDB.timeout
- the timeout for the current query. It replaces the timeout value set for this
FaunaClient
(if any), for the scope of this query. The timeout value
has milliseconds precision.CompletableFuture
containing an ordered list of the query's responses.public java.util.concurrent.CompletableFuture<java.util.List<Value>> query(java.util.List<? extends Expr> exprs, java.util.Optional<java.time.Duration> timeout)
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.
exprs
- the list of queries to be sent to FaunaDB.timeout
- the timeout for the current query. It replaces the timeout value set for this
FaunaClient
(if any), for the scope of this query. The timeout value
has milliseconds precision.CompletableFuture
containing an ordered list of the query's responses.public void syncLastTxnTime(long timestamp)
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.
public long getLastTxnTime()