- All Implemented Interfaces:
Queryable,Closeable,AutoCloseable
newInstance(java.lang.String, com.couchbase.columnar.client.java.Credential).
To create an instance with default options:
Cluster cluster = Cluster.newInstance(
connectionString,
Credential.of(username, password)
);
To create an instance with custom options:
Cluster cluster = Cluster.newInstance(
connectionString,
Credential.of(username, password),
options -> options
.timeout(it -> it.queryTimeout(Duration.ofMinutes(5)))
.deserializer(new JacksonDeserializer(new ObjectMapper()))
);
For best efficiency, create a single `Cluster` instance
per Columnar cluster and share it throughout your application.
When you're done interacting with the cluster, it's important to call
close() to release resources used by the cluster.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Releases resources and prevents further use of this object.Returns the database in this cluster with the given name.executeQuery(String statement, Consumer<QueryOptions> optionsCustomizer) Executes a query statement using the specified options (query parameters, etc.), and buffers all result rows in memory.executeStreamingQuery(String statement, Consumer<Row> rowAction, Consumer<QueryOptions> optionsCustomizer) Executes a query statement using the specified options, (query parameters, etc.), and passes result rows to the givenrowActioncallback, one by one as they arrive from the server.static ClusternewInstance(String connectionString, Credential credential) Returns a new instance, with default options.static ClusternewInstance(String connectionString, Credential credential, Consumer<ClusterOptions> optionsCustomizer) Returns a new instance, with options customized by theoptionsCustomizercallback.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.couchbase.columnar.client.java.Queryable
executeQuery, executeStreamingQuery
-
Method Details
-
newInstance
Returns a new instance, with default options.Example usage:
Cluster cluster = Cluster.newInstance( "couchbases://example.com", Credentials.of(username, password) ); -
newInstance
public static Cluster newInstance(String connectionString, Credential credential, Consumer<ClusterOptions> optionsCustomizer) Returns a new instance, with options customized by theoptionsCustomizercallback.Example usage:
Cluster cluster = Cluster.newInstance( connectionString, Credential.of(username, password), options -> options .timeout(it -> it.queryTimeout(Duration.ofMinutes(5))) .deserializer(new JacksonDeserializer(new ObjectMapper())) ); -
close
public void close()Releases resources and prevents further use of this object.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
database
Returns the database in this cluster with the given name.A database is a container for
Scopes.If the database does not exist, this method still returns a non-null object, but operations using that object fail with an exception indicating the database does not exist.
-
executeQuery
Description copied from interface:QueryableExecutes a query statement using the specified options (query parameters, etc.), and buffers all result rows in memory.If the results are not known to fit in memory, consider using the streaming version that takes a row action callback:
Queryable.executeStreamingQuery(String, Consumer, Consumer).- Specified by:
executeQueryin interfaceQueryable- Parameters:
statement- The Columnar SQL++ statement to execute.optionsCustomizer- A callback for specifying custom query options.- Returns:
- A query result consisting of metadata and a list of rows.
-
executeStreamingQuery
public QueryMetadata executeStreamingQuery(String statement, Consumer<Row> rowAction, Consumer<QueryOptions> optionsCustomizer) Description copied from interface:QueryableExecutes a query statement using the specified options, (query parameters, etc.), and passes result rows to the givenrowActioncallback, one by one as they arrive from the server.The callback action is guaranteed to execute in the same thread (or virtual thread) that called this method. If the callback throws an exception, the query is cancelled and the exception is re-thrown by this method.
- Specified by:
executeStreamingQueryin interfaceQueryable- Parameters:
statement- The Columnar SQL++ statement to execute.optionsCustomizer- A callback for specifying custom query options.- Returns:
- Query metadata.
-