To execute the sequence we created in the previous section, use
the
TableAPI.execute()
method:
package kvstore.basicExample; try { tableH.execute(opList, null); } 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 (IllegalArgumentException iae) { // An operation in the list was null or empty. // Or at least one operation operates on a row // with a shard key that is different // than the others. // Or more than one operation uses the same key. } catch (DurabilityException de) { // The durability guarantee could not be met. } 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.
TableAPI.execute()
can optionally take
a WriteOptions
class instance. This
class instance allows you to specify:
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.