Yuta HIGUCHI

DatabaseClient: check result status

Change-Id: I4f0ab20e42bf673b03035a1d9841af16eb67993f
...@@ -39,7 +39,12 @@ public class DatabaseClient { ...@@ -39,7 +39,12 @@ public class DatabaseClient {
39 Arrays.asList(tableName)); 39 Arrays.asList(tableName));
40 CompletableFuture<SubmitResponse> future = client.submit(request); 40 CompletableFuture<SubmitResponse> future = client.submit(request);
41 try { 41 try {
42 - return (boolean) future.get().result(); 42 + final SubmitResponse submitResponse = future.get();
43 + if (submitResponse.status() == Status.OK) {
44 + return (boolean) submitResponse.result();
45 + } else {
46 + throw new DatabaseException(submitResponse.error());
47 + }
43 } catch (InterruptedException | ExecutionException e) { 48 } catch (InterruptedException | ExecutionException e) {
44 throw new DatabaseException(e); 49 throw new DatabaseException(e);
45 } 50 }
...@@ -54,7 +59,7 @@ public class DatabaseClient { ...@@ -54,7 +59,7 @@ public class DatabaseClient {
54 Arrays.asList(tableName)); 59 Arrays.asList(tableName));
55 CompletableFuture<SubmitResponse> future = client.submit(request); 60 CompletableFuture<SubmitResponse> future = client.submit(request);
56 try { 61 try {
57 - if (future.get().status() == Status.OK) { 62 + if (future.get().status() != Status.OK) {
58 throw new DatabaseException(future.get().toString()); 63 throw new DatabaseException(future.get().toString());
59 } 64 }
60 65
...@@ -90,7 +95,12 @@ public class DatabaseClient { ...@@ -90,7 +95,12 @@ public class DatabaseClient {
90 Arrays.asList()); 95 Arrays.asList());
91 CompletableFuture<SubmitResponse> future = client.submit(request); 96 CompletableFuture<SubmitResponse> future = client.submit(request);
92 try { 97 try {
93 - return (List<String>) future.get().result(); 98 + final SubmitResponse submitResponse = future.get();
99 + if (submitResponse.status() == Status.OK) {
100 + return (List<String>) submitResponse.result();
101 + } else {
102 + throw new DatabaseException(submitResponse.error());
103 + }
94 } catch (InterruptedException | ExecutionException e) { 104 } catch (InterruptedException | ExecutionException e) {
95 throw new DatabaseException(e); 105 throw new DatabaseException(e);
96 } 106 }
...@@ -106,8 +116,12 @@ public class DatabaseClient { ...@@ -106,8 +116,12 @@ public class DatabaseClient {
106 116
107 CompletableFuture<SubmitResponse> future = client.submit(request); 117 CompletableFuture<SubmitResponse> future = client.submit(request);
108 try { 118 try {
109 - List<InternalReadResult> internalReadResults = (List<InternalReadResult>) future.get().result(); 119 + final SubmitResponse submitResponse = future.get();
110 - return internalReadResults; 120 + if (submitResponse.status() == Status.OK) {
121 + return (List<InternalReadResult>) submitResponse.result();
122 + } else {
123 + throw new DatabaseException(submitResponse.error());
124 + }
111 } catch (InterruptedException | ExecutionException e) { 125 } catch (InterruptedException | ExecutionException e) {
112 throw new DatabaseException(e); 126 throw new DatabaseException(e);
113 } 127 }
...@@ -123,8 +137,12 @@ public class DatabaseClient { ...@@ -123,8 +137,12 @@ public class DatabaseClient {
123 137
124 CompletableFuture<SubmitResponse> future = client.submit(request); 138 CompletableFuture<SubmitResponse> future = client.submit(request);
125 try { 139 try {
126 - List<InternalWriteResult> internalWriteResults = (List<InternalWriteResult>) future.get().result(); 140 + final SubmitResponse submitResponse = future.get();
127 - return internalWriteResults; 141 + if (submitResponse.status() == Status.OK) {
142 + return (List<InternalWriteResult>) submitResponse.result();
143 + } else {
144 + throw new DatabaseException(submitResponse.error());
145 + }
128 } catch (InterruptedException | ExecutionException e) { 146 } catch (InterruptedException | ExecutionException e) {
129 throw new DatabaseException(e); 147 throw new DatabaseException(e);
130 } 148 }
......