To execute the sequence we created in the previous section, use
the
KVStore.execute()
method:
package kvstore.basicExample; ... import oracle.kv.DurabilityException; import oracle.kv.FaultException; import oracle.kv.OperationExecutionException; import oracle.kv.RequestTimeoutException; ... try { kvstore.execute(opList); } catch (OperationExecutionException oee) { // Some error occurred that prevented the sequence // from executing successfully. Use // oee.getFailedOperationIndex() to determine which // operation failed. Use oee.getFailedOperationResult() // to obtain an OperationResult object, which you can // use to troubleshoot the cause of the execution // exception. } catch (DurabilityException de) { // The durability guarantee could not be met. } catch (IllegalArgumentException iae) { // An operation in the list was null or empty. // Or at least one operation operates on a key // with a major path component that is different // than the others. // Or more than one operation uses the same key. } catch (RequestTimeoutException rte) { // The operation was not completed inside of the // default request timeout limit. } catch (FaultException fe) { // A generic error occurred }
Note that if any of the above exceptions are thrown, then the entire sequence is aborted, and your data will be in the state it would have been in if you had never executed the sequence at all.
A richer form of KVStore.execute()
is
available. It allows you to specify:
The list of operations.
The durability guarantee that you want to use for this
sequence. If you want to use the default durability
guarantee, pass null
for this
parameter.
A timeout value that identifies the upper bound on the
time interval allowed for processing the entire
sequence. If you provide 0
to this
parameter, the default request timeout value is used.
A TimeUnit
that identifies the
units used by the timeout value. For example:
TimeUnit.MILLISECONDS
.
For an example of using WriteOptions
,
see Durability Guarantees.
For example:
package kvstore.basicExample; ... import oracle.kv.Durability; import oracle.kv.DurabilityException; import oracle.kv.FaultException; import oracle.kv.OperationExecutionException; import oracle.kv.RequestTimeoutException; import java.util.concurrent.TimeUnit; ... Durability durability = new Durability(Durability.SyncPolicy.NO_SYNC, // Master sync Durability.SyncPolicy.NO_SYNC, // Replica sync Durability.ReplicaAckPolicy.NONE); try { kvstore.execute(opList, durability, 2000, TimeUnit.MILLISECONDS); } catch (OperationExecutionException oee) { // Some error occurred that prevented the sequence // from executing successfully. Use // oee.getFailedOperationIndex() to determine which // operation failed. Use oee.getFailedOperationResult() // to obtain an OperationResult object, which you can // use to troubleshoot the cause of the execution // exception. } catch (DurabilityException de) { // The durability guarantee could not be met. } catch (IllegalArgumentException iae) { // An operation in the list was null or empty. // Or at least one operation operates on a key // with a major path component that is different // than the others. // Or more than one operation uses the same key. } catch (RequestTimeoutException rte) { // The operation was not completed inside of the // default request timeout limit. } catch (FaultException fe) { // A generic error occurred }