19 package com.mysql.clusterj.bindings;
21 import com.mysql.cluster.ndbj.NdbApiException;
22 import com.mysql.cluster.ndbj.NdbOperation.AbortOption;
23 import com.mysql.cluster.ndbj.NdbOperation;
24 import com.mysql.cluster.ndbj.NdbScanOperation;
25 import com.mysql.cluster.ndbj.NdbTransaction;
26 import com.mysql.clusterj.ClusterJDatastoreException;
27 import com.mysql.clusterj.core.store.ClusterTransaction;
28 import com.mysql.clusterj.core.store.Index;
29 import com.mysql.clusterj.core.store.IndexOperation;
30 import com.mysql.clusterj.core.store.IndexScanOperation;
31 import com.mysql.clusterj.core.store.Operation;
32 import com.mysql.clusterj.core.store.ScanOperation;
33 import com.mysql.clusterj.core.store.Table;
34 import com.mysql.clusterj.core.util.I18NHelper;
35 import com.mysql.clusterj.core.util.Logger;
36 import com.mysql.clusterj.core.util.LoggerFactoryService;
37 import java.util.ArrayList;
38 import java.util.List;
43 class ClusterTransactionImpl
implements ClusterTransaction {
46 static final I18NHelper local = I18NHelper
47 .getInstance(ClusterTransactionImpl.class);
50 static final Logger logger = LoggerFactoryService.getFactory()
51 .getInstance(ClusterTransactionImpl.class);
54 private List<Runnable> postExecuteCallbacks =
new ArrayList<Runnable>();
57 this.ndbTransaction = ndbTransaction;
61 ndbTransaction.close();
64 public void executeCommit() {
65 handlePendingPostExecuteCallbacks();
67 ndbTransaction.executeCommit();
68 }
catch (NdbApiException ndbApiException) {
69 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
74 public void executeCommit(
boolean abort,
boolean force) {
75 handlePendingPostExecuteCallbacks();
76 AbortOption abortOption = abort?AbortOption.AbortOnError:AbortOption.AO_IgnoreError;
80 }
catch (NdbApiException ndbApiException) {
81 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
86 public void executeNoCommit(
boolean abort,
boolean force) {
87 AbortOption abortOption = abort?AbortOption.AbortOnError:AbortOption.AO_IgnoreError;
91 performPostExecuteCallbacks();
92 }
catch (NdbApiException ndbApiException) {
93 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
98 public void executeNoCommit() {
100 ndbTransaction.executeNoCommit();
101 performPostExecuteCallbacks();
102 }
catch (NdbApiException ndbApiException) {
103 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
108 public void executeRollback() {
110 clearPostExecuteCallbacks();
111 ndbTransaction.executeRollback();
112 }
catch (NdbApiException ndbApiException) {
113 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
118 public Operation getDeleteOperation(Table storeTable) {
120 return new OperationImpl(ndbTransaction.getDeleteOperation(storeTable.getName()),
this);
121 }
catch (NdbApiException ndbApiException) {
122 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
127 public Operation getInsertOperation(Table storeTable) {
129 return new OperationImpl(ndbTransaction.getInsertOperation(storeTable.getName()),
this);
130 }
catch (NdbApiException ndbApiException) {
131 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
136 public IndexScanOperation getSelectIndexScanOperation(Index storeIndex, Table storeTable) {
138 return new IndexScanOperationImpl(
139 ndbTransaction.getSelectIndexScanOperation(storeIndex.getName(), storeTable.getName()),
this);
140 }
catch (NdbApiException ndbApiException) {
141 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
146 public Operation getSelectOperation(Table storeTable) {
148 return new OperationImpl(ndbTransaction.getSelectOperation(storeTable.getName()),
this);
149 }
catch (NdbApiException ndbApiException) {
150 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
155 public ScanOperation getSelectScanOperation(Table storeTable) {
157 return new ScanOperationImpl(
158 ndbTransaction.getSelectScanOperation(storeTable.getName()),
this);
159 }
catch (NdbApiException ndbApiException) {
160 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
165 public ScanOperation getSelectScanOperationLockModeExclusiveScanFlagKeyInfo(Table storeTable) {
167 return new ScanOperationImpl(
168 ndbTransaction.getSelectScanOperation(storeTable.getName(),
171 }
catch (NdbApiException ndbApiException) {
172 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
177 public IndexOperation getSelectUniqueOperation(Index storeIndex, Table storeTable) {
179 return new IndexOperationImpl(
180 ndbTransaction.getSelectUniqueOperation(storeIndex.getName(), storeTable.getName()),
this);
181 }
catch (NdbApiException ndbApiException) {
182 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
187 public Operation getUpdateOperation(Table storeTable) {
189 return new OperationImpl(ndbTransaction.getUpdateOperation(storeTable.getName()),
this);
190 }
catch (NdbApiException ndbApiException) {
191 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
196 public Operation getWriteOperation(Table storeTable) {
198 return new OperationImpl(ndbTransaction.getWriteOperation(storeTable.getName()),
this);
199 }
catch (NdbApiException ndbApiException) {
200 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
205 public void postExecuteCallback(Runnable callback) {
206 postExecuteCallbacks.add(callback);
209 private void clearPostExecuteCallbacks() {
210 postExecuteCallbacks.clear();
213 private void handlePendingPostExecuteCallbacks() {
215 if (!postExecuteCallbacks.isEmpty()) {
220 private void performPostExecuteCallbacks() {
222 for (Runnable runnable: postExecuteCallbacks) {
225 }
catch (Throwable t) {
226 throw new ClusterJDatastoreException(
227 local.message(
"ERR_Datastore"), t);
231 clearPostExecuteCallbacks();