前の項で作成したシーケンスを実行するには、KVStore.execute()
メソッドを使用します。
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 a 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 }
前述の例外のいずれかがスローされると、シーケンス全体が中止され、データは、シーケンスを実行しなかった場合の状態になることに注意してください。
より詳細に指定できるKVStore.execute()
も使用できます。次のものを指定できます。
操作のリスト。
このシーケンスに使用する永続性保証。デフォルトの永続性保証を使用する場合、このパラメータにnull
を渡します。
シーケンス全体の処理に許される時間の上限を示すタイムアウト値。このパラメータに0
を指定すると、デフォルトのリクエスト・タイムアウト値が使用されます。
タイムアウト値で使用される単位を表すTimeUnit
。たとえば、TimeUnit.MILLISECONDS
です。
次に例を示します。
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 a 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 }