Interface NoSQLHandle
- All Superinterfaces:
AutoCloseable
NoSQLHandleFactory.createNoSQLHandle(oracle.nosql.driver.NoSQLHandleConfig)
and NoSQLHandleConfig
,
which allows an application to specify default values and other configuration
information to be used by the handle.
The same interface is available to both users of the Oracle NoSQL Database Cloud Service and the on-premises Oracle NoSQL Database; however, some methods and/or parameters are specific to each environment. The documentation has notes about whether a class, method, or parameter is environment-specific. Unless otherwise noted they are applicable to both environments.
A handle has memory and network resources associated with it.
Consequently, the close()
method must be invoked to free up
the resources when the application is done using the handle.
To minimize network activity as well as resource allocation and deallocation overheads, it's best to avoid repeated creation and closing of handles. For example, creating and closing a handle around each operation, would incur large resource allocation overheads resulting in poor application performance.
A handle permits concurrent operations, so a single handle is sufficient to access tables in a multi-threaded application. The creation of multiple handles incurs additional resource overheads without providing any performance benefit.
With the exception of close()
the operations on this interface follow
a similar pattern. They accept a Request
object containing
parameters, both required and optional. They return a Result
object
containing results. Operation failures throw exceptions. Unique subclasses
of Request
and Result
exist for most operations, containing
information specific to the operation. All of these operations result in
remote calls across a network.
All Request
instances support specification of parameters for the
operation as well as the ability to override default parameters which may
have been specified in NoSQLHandleConfig
, such as request timeouts,
Consistency
, etc.
Objects returned by methods of this interface can only be used safely by
one thread at a time unless synchronized externally. Request
objects
are not copied and must not be modified by the application while a method
on this interface is using them.
Error and Exception Handling
On success all methods in this interface return Result
objects.
Errors are thrown as exceptions. Some Java exceptions, such as IllegalArgumentException
and NullPointerException
are thrown
directly. All other exceptions are instances of NoSQLException
,
which serves as a base class for NoSQL Database exceptions.
NoSQLException
instances are split into 2 broad categories:
- Exceptions that may be retried with the expectation that they
may succeed on retry. These are instances of
RetryableException
- Exceptions that may not be retried and if retried, will fail again
Exceptions that may be retried return true for
NoSQLException.okToRetry()
while those that may not will return false.
Examples of retryable exceptions are those which indicate resource
consumption violations such as ThrottlingException
.
Examples of exceptions that should not be
retried are IllegalArgumentException
,
TableNotFoundException
, and any other exception indicating a
syntactic or semantic error.
Instances of NoSQLHandle are thread-safe and expected to be shared among threads.
-
Method Summary
Modifier and TypeMethodDescriptionaddReplica
(AddReplicaRequest request) Cloud service only.void
close()
Closes the handle, releasing its memory and network resources.delete
(DeleteRequest request) Deletes a row from a table.doSystemRequest
(String statement, int timeoutMs, int pollIntervalMs) On-premises only.doTableRequest
(TableRequest request, int timeoutMs, int pollIntervalMs) A convenience method that performs a TableRequest and waits for completion of the operation.dropReplica
(DropReplicaRequest request) Cloud service only.get
(GetRequest request) Gets the row associated with a primary key.getIndexes
(GetIndexesRequest request) Returns information about and index, or indexes on a table.getReplicaStats
(ReplicaStatsRequest request) Cloud service only.Returns an object that allows control over how SDK statistics are collected.getTable
(GetTableRequest request) Gets static information about the specified table including its state, provisioned throughput and capacity and schema.getTableUsage
(TableUsageRequest request) Cloud service only.String[]
On-premises only.String[]
On-premises only.listTables
(ListTablesRequest request) Lists tables, returning table names.UserInfo[]
On-premises only.multiDelete
(MultiDeleteRequest request) Deletes multiple rows from a table in an atomic operation.prepare
(PrepareRequest request) Prepares a query for execution and reuse.put
(PutRequest request) Puts a row into a table.query
(QueryRequest request) Queries a table based on the query statement specified in theQueryRequest
.queryIterable
(QueryRequest request) Queries a table based on the query statement specified in theQueryRequest
while returning an iterable result.systemRequest
(SystemRequest request) On-premises only.systemStatus
(SystemStatusRequest request) On-premises only.tableRequest
(TableRequest request) Performs an operation on a table.writeMultiple
(WriteMultipleRequest request) Executes a sequence of operations associated with a table that share the same shard key portion of their primary keys, all the specified operations are executed within the scope of a single transaction.
-
Method Details
-
delete
Deletes a row from a table. The row is identified using a primary key value supplied inDeleteRequest.setKey(oracle.nosql.driver.values.MapValue)
By default a delete operation is unconditional and will succeed if the specified row exists. Delete operations can be made conditional based on whether the
Version
of an existing row matches that supplied byDeleteRequest.setMatchVersion(oracle.nosql.driver.Version)
.It is also possible, on failure, to return information about the existing row. The row, including it's
Version
can be optionally returned if a delete operation fails because of a Version mismatch. The existing row information will only be returned ifDeleteRequest.setReturnRow(boolean)
is true and the operation fails becauseDeleteRequest.setMatchVersion(oracle.nosql.driver.Version)
is used and the operation fails because the row exists and its version does not match. Use ofDeleteRequest.setReturnRow(boolean)
may result in additional consumed read capacity. If the operation is successful there will be no information returned about the previous row.- Parameters:
request
- the input parameters for the operation- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingNoSQLException
- if the operation cannot be performed for any other reason
-
get
Gets the row associated with a primary key. On success the value of the row is available using theGetResult.getValue()
operation. If there are no matching rows that method will return null.The default
Consistency
used for the operation isConsistency.EVENTUAL
unless an explicit value is has been set usingNoSQLHandleConfig.setConsistency(oracle.nosql.driver.Consistency)
orGetRequest.setConsistency(oracle.nosql.driver.Consistency)
. Use ofConsistency.ABSOLUTE
may affect latency of the operation and may result in additional cost for the operation.- Parameters:
request
- the input parameters for the operation- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingNoSQLException
- if the operation cannot be performed for any other reason
-
put
Puts a row into a table. This method creates a new row or overwrites an existing row entirely. The value used for the put is in thePutRequest
object and must contain a complete primary key and all required fields.It is not possible to put part of a row. Any fields that are not provided will be defaulted, overwriting any existing value. Fields that are not nullable or defaulted must be provided or an exception will be thrown.
By default a put operation is unconditional, but put operations can be conditional based on existence, or not, of a previous value as well as conditional on the
Version
of the existing value.- Use
PutRequest.Option.IfAbsent
to do a put only if there is no existing row that matches the primary key - Use
PutRequest.Option.IfPresent
to do a put only if there is an existing row that matches the primary key - Use
PutRequest.Option.IfVersion
to do a put only if there is an existing row that matches the primary key and itsVersion
matches that provided
It is also possible, on failure, to return information about the existing row. The row, including it's
Version
can be optionally returned if a put operation fails because of a Version mismatch or if the operation fails because the row already exists. The existing row information will only be returned ifPutRequest.setReturnRow(boolean)
is true and one of the following occurs:- The
PutRequest.Option.IfAbsent
is used and the operation fails because the row already exists. - The
PutRequest.Option.IfVersion
is used and the operation fails because the row exists and its version does not match.
PutRequest.setReturnRow(boolean)
may result in additional consumed read capacity. If the operation is successful there will be no information returned about the previous row.- Parameters:
request
- the input parameters for the operation- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingNoSQLException
- if the operation cannot be performed for any other reason
- Use
-
writeMultiple
Executes a sequence of operations associated with a table that share the same shard key portion of their primary keys, all the specified operations are executed within the scope of a single transaction.WriteMultipleRequest
.There are some size-based limitations on this operation:
- The max number of individual operations (put, delete) in a single WriteMultiple request is 50.
- The total request size is limited to 25MB.
- Parameters:
request
- the input parameters for the operation- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingRowSizeLimitException
- if data size in an operation exceeds the limit.BatchOperationNumberLimitException
- if the number of operations exceeds this limit.NoSQLException
- if the operation cannot be performed for any other reason
-
multiDelete
Deletes multiple rows from a table in an atomic operation. The key used may be partial but must contain all of the fields that are in the shard key. A range may be specified to delete a range of keys.- Parameters:
request
- the input parameters for the operation- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingNoSQLException
- if the operation cannot be performed for any other reason
-
query
Queries a table based on the query statement specified in theQueryRequest
.Queries that include a full shard key will execute much more efficiently than more distributed queries that must go to multiple shards.
Table- and system-style queries such as "CREATE TABLE ..." or "DROP TABLE .." are not supported by this interface. Those operations must be performed using
tableRequest(oracle.nosql.driver.ops.TableRequest)
orsystemRequest(oracle.nosql.driver.ops.SystemRequest)
as appropriate.The amount of data read by a single query request is limited by a system default and can be further limited using
QueryRequest.setMaxReadKB(int)
. This limits the amount of data read and not the amount of data returned, which means that a query can return zero results but still have more data to read. This situation is detected by checking if theQueryResult
has a continuation key, usingQueryResult.getContinuationKey()
. For this reason queries should always operate in a loop, acquiring more results, until the continuation key is null, indicating that the query is done. Inside the loop the continuation key is applied to theQueryRequest
usingQueryRequest.setContinuationKey(byte[])
.- Parameters:
request
- the input parameters for the operation- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingNoSQLException
- if the operation cannot be performed for any other reason
-
queryIterable
Queries a table based on the query statement specified in theQueryRequest
while returning an iterable result.Queries that include a full shard key will execute much more efficiently than more distributed queries that must go to multiple shards.
Remote calls, including preparation of a query statement, will not occur until the iteration starts. This means that errors such as an invalid statement or network issue will be thrown from the iterator and not this method.
Table- and system-style queries such as "CREATE TABLE ..." or "DROP TABLE .." are not supported by this interface. Those operations must be performed using
tableRequest(oracle.nosql.driver.ops.TableRequest)
orsystemRequest(oracle.nosql.driver.ops.SystemRequest)
as appropriate.The results are returned through an iterator, if connected to the cloud, the SDK uses the read/write rate limits set in the NoSQLHandleConfig or they can be overwritten using the
Request.setReadRateLimiter(RateLimiter)
andRequest.setWriteRateLimiter(RateLimiter)
.Note: Since iterators might use resources until they reach the end, it is necessary to close the QueryIterableResult or use the try-with-resources statement:
try ( QueryRequest qreq = new QueryRequest() .setStatement("select * from MyTable"); QueryIterableResult qir = handle.queryIterable(qreq)) { for( MapValue row : qir) { // do something with row } }
- Parameters:
request
- the input parameters for the operation- Returns:
- the iterable result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingNoSQLException
- if the operation cannot be performed for any other reason
-
prepare
Prepares a query for execution and reuse. Seequery(oracle.nosql.driver.ops.QueryRequest)
for general information and restrictions. It is recommended that prepared queries are used when the same query will run multiple times as execution is much more efficient than starting with a query string every time. The query language and API support query variables to assist with re-use.- Parameters:
request
- the input parameters for the operation- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingNoSQLException
- if the operation cannot be performed for any other reason
-
tableRequest
Performs an operation on a table. This method is used for creating and dropping tables and indexes as well as altering tables. Only one operation is allowed on a table at any one time.This operation is implicitly asynchronous. The caller must poll using methods on
TableResult
to determine when it has completed.- Parameters:
request
- the input parameters for the operation- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingNoSQLException
- if the operation cannot be performed for any other reason
-
doTableRequest
A convenience method that performs a TableRequest and waits for completion of the operation. This is the same as callingtableRequest(oracle.nosql.driver.ops.TableRequest)
then callingTableResult.waitForCompletion(oracle.nosql.driver.NoSQLHandle, int, int)
. If the operation fails an exception is thrown. All parameters are required.- Parameters:
request
- theTableRequest
to perform.timeoutMs
- the amount of time to wait for completion, in milliseconds.pollIntervalMs
- the polling interval for the wait operation.- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingRequestTimeoutException
- if the operation times out.NoSQLException
- if the operation cannot be performed for any other reason
-
systemRequest
On-premises only.Performs a system operation on the system, such as administrative operations that don't affect a specific table. For table-specific operations use
tableRequest(oracle.nosql.driver.ops.TableRequest)
ordoTableRequest(oracle.nosql.driver.ops.TableRequest, int, int)
.Examples of statements in the
SystemRequest
passed to this method include:- CREATE NAMESPACE mynamespace
- CREATE USER some_user IDENTIFIED BY password
- CREATE ROLE some_role
- GRANT ROLE some_role TO USER some_user
This operation is implicitly asynchronous. The caller must poll using methods on
SystemResult
to determine when it has completed.- Parameters:
request
- the input parameters for the operation- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingNoSQLException
- if the operation cannot be performed for any other reason
-
systemStatus
On-premises only.Checks the status of an operation previously performed using
systemRequest(oracle.nosql.driver.ops.SystemRequest)
.- Parameters:
request
- the input parameters for the operation- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingNoSQLException
- if the operation cannot be performed for any other reason
-
getTable
Gets static information about the specified table including its state, provisioned throughput and capacity and schema. Dynamic information such as usage is obtained usinggetTableUsage(oracle.nosql.driver.ops.TableUsageRequest)
. Throughput, capacity and usage information is only available when using the Cloud Service and will be null or not defined on-premises.- Parameters:
request
- the input parameters for the operation- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingTableNotFoundException
- if the specified table does not existNoSQLException
- if the operation cannot be performed for any other reason
-
getTableUsage
Cloud service only.Gets dynamic information about the specified table such as the current throughput usage. Usage information is collected in time slices and returned in individual usage records. It is possible to specify a time-based range of usage records using input parameters.
- Parameters:
request
- the input parameters for the operation- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingTableNotFoundException
- if the specified table does not existNoSQLException
- if the operation cannot be performed for any other reason
-
listTables
Lists tables, returning table names. If further information about a specific table is desired thegetTable(oracle.nosql.driver.ops.GetTableRequest)
interface may be used. If a given identity has access to a large number of tables the list may be paged using input parameters.- Parameters:
request
- the input parameters for the operation- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingNoSQLException
- if the operation cannot be performed for any other reason
-
getIndexes
Returns information about and index, or indexes on a table. If no index name is specified in theGetIndexesRequest
, then information on all indexes is returned.- Parameters:
request
- the input parameters for the operation- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingNoSQLException
- if the operation cannot be performed for any other reason
-
listNamespaces
String[] listNamespaces()On-premises only.Returns the namespaces in a store as an array of String.
- Returns:
- the namespaces or null if none are found
-
listRoles
String[] listRoles()On-premises only.Returns the roles in a store as an array of String.
- Returns:
- the list of roles or null if none are found
-
listUsers
UserInfo[] listUsers()On-premises only.Returns the users in a store as an array of
UserInfo
.- Returns:
- the users or null if none are found
-
doSystemRequest
On-premises only.A convenience method that performs a SystemRequest and waits for completion of the operation. This is the same as calling
systemRequest(oracle.nosql.driver.ops.SystemRequest)
then callingSystemResult.waitForCompletion(oracle.nosql.driver.NoSQLHandle, int, int)
. If the operation fails an exception is thrown. All parameters are required.System requests are those related to namespaces and security and are generally independent of specific tables. Examples of statements include:
- CREATE NAMESPACE mynamespace
- CREATE USER some_user IDENTIFIED BY password
- CREATE ROLE some_role
- GRANT ROLE some_role TO USER some_user
- Parameters:
statement
- the system statement for the operation.timeoutMs
- the amount of time to wait for completion, in milliseconds.pollIntervalMs
- the polling interval for the wait operation.- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingRequestTimeoutException
- if the operation times out.NoSQLException
- if the operation cannot be performed for any other reason
-
addReplica
Cloud service only.Add replica to a table.
This operation is implicitly asynchronous. The caller must poll using methods on
TableResult
to determine when it has completed.- Parameters:
request
- the input parameters for the operation- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingNoSQLException
- if the operation cannot be performed for any other reason- Since:
- 5.4.13
-
dropReplica
Cloud service only.Drop replica from a table.
This operation is implicitly asynchronous. The caller must poll using methods on
TableResult
to determine when it has completed.- Parameters:
request
- the input parameters for the operation- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingNoSQLException
- if the operation cannot be performed for any other reason- Since:
- 5.4.13
-
getReplicaStats
Cloud service only.Gets replica statistics information
- Parameters:
request
- the input parameters for the operation- Returns:
- the result of the operation
- Throws:
IllegalArgumentException
- if any of the parameters are invalid or required parameters are missingTableNotFoundException
- if the specified table does not existNoSQLException
- if the operation cannot be performed for any other reason- Since:
- 5.4.13
-
getStatsControl
StatsControl getStatsControl()Returns an object that allows control over how SDK statistics are collected.- Returns:
- the StatsControl object
- Since:
- 5.2.30
-
close
void close()Closes the handle, releasing its memory and network resources. Once this method is closed the handle is no longer usable. Any attempt to use a closed handle will throwIllegalArgumentException
.- Specified by:
close
in interfaceAutoCloseable
-