author | lancea |
Wed, 11 Jul 2018 19:36:23 -0400 | |
branch | JDK-8188051-branch |
changeset 56828 | 64304e37e9b1 |
parent 56824 | 62e92191354d |
child 56832 | 4f7713e6a308 |
permissions | -rw-r--r-- |
56797 | 1 |
/* |
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
56824 | 26 |
package jdk.incubator.sql2; |
27 |
||
56797 | 28 |
import java.io.DataInputStream; |
29 |
import java.io.IOException; |
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.List; |
|
32 |
import java.util.concurrent.CompletableFuture; |
|
33 |
import java.util.concurrent.CompletionStage; |
|
34 |
import java.util.concurrent.Flow; |
|
56828
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
35 |
import java.util.concurrent.ForkJoinPool; |
56797 | 36 |
import java.util.concurrent.Semaphore; |
37 |
import java.util.stream.Collector; |
|
38 |
import java.util.stream.Collectors; |
|
39 |
||
40 |
/** |
|
41 |
* Simple example code using various aspects of ADBA. These do not necessarily |
|
42 |
* demonstrate the best way to use each feature, just one way. |
|
43 |
*/ |
|
44 |
public class Examples { |
|
45 |
||
46 |
// DataSourceFactory |
|
47 |
||
56824 | 48 |
public DataSource getDataSource() { |
56797 | 49 |
return DataSourceFactory.newFactory("oracle.database.adba") |
50 |
.builder() |
|
51 |
.url("//host.oracle.com:5521/example") |
|
52 |
.username("scott") |
|
53 |
.password("tiger") |
|
54 |
.build(); |
|
55 |
} |
|
56 |
||
57 |
// RowCountOperation |
|
58 |
||
59 |
public void insertItem(DataSource ds, Item item) { |
|
56824 | 60 |
try (Session session = ds.getSession()) { |
61 |
session.rowCountOperation("insert into tab values (:id, :name, :answer)") |
|
56797 | 62 |
.set("id", item.id(), AdbaType.NUMERIC) |
63 |
.set("name", item.name(), AdbaType.VARCHAR) |
|
64 |
.set("answer", item.answer(), AdbaType.NUMERIC) |
|
65 |
.submit(); |
|
66 |
} |
|
67 |
} |
|
68 |
||
69 |
// RowOperation |
|
70 |
||
71 |
public void idsForAnswer(DataSource ds, List<Integer> result, int correctAnswer) { |
|
56824 | 72 |
try (Session session = ds.getSession()) { |
73 |
session.<List<Integer>>rowOperation("select id, name, answer from tab where answer = :target") |
|
56797 | 74 |
.set("target", correctAnswer, AdbaType.NUMERIC) |
75 |
.collect(() -> result, |
|
76 |
(list, row) -> list.add(row.at("id").get(Integer.class)) ) |
|
77 |
.submit(); |
|
78 |
} |
|
79 |
} |
|
80 |
||
81 |
// RowOperation |
|
82 |
||
83 |
public CompletionStage<List<Item>> itemsForAnswer(DataSource ds, int answer) { |
|
56824 | 84 |
try (Session session = ds.getSession()) { |
85 |
return session.<List<Item>>rowOperation("select id, name, answer from tab where answer = :target") |
|
56797 | 86 |
.set("target", 42, AdbaType.NUMERIC) |
87 |
.collect(Collectors.mapping( |
|
88 |
row -> new Item(row.at("id").get(Integer.class), |
|
89 |
row.at("name").get(String.class), |
|
90 |
row.at("answer").get(Integer.class) ), |
|
91 |
Collectors.toList() )) |
|
92 |
.submit() |
|
93 |
.getCompletionStage(); |
|
94 |
} |
|
95 |
} |
|
96 |
||
97 |
// Independent OperationGroup |
|
98 |
||
99 |
public void insertItemsIndependent(DataSource ds, List<Item> list) { |
|
100 |
String sql = "insert into tab values (:id, :name, :answer)"; |
|
56824 | 101 |
try (Session session = ds.getSession()) { |
102 |
OperationGroup group = session.operationGroup() |
|
56797 | 103 |
.independent(); |
104 |
for (Item elem : list) { |
|
105 |
group.rowCountOperation(sql) |
|
106 |
.set("id", elem.id) |
|
107 |
.set("name", elem.name) |
|
108 |
.set("answer", elem.answer) |
|
109 |
.submit() |
|
110 |
.getCompletionStage() |
|
111 |
.exceptionally( t -> { |
|
112 |
System.out.println(elem.id); |
|
113 |
return null; |
|
114 |
}); |
|
115 |
} |
|
116 |
group.submit(); |
|
56824 | 117 |
|
56797 | 118 |
} |
119 |
} |
|
120 |
||
121 |
// Held OperationGroup |
|
122 |
||
123 |
public void insertItemsHold(DataSource ds, List<Item> list) { |
|
124 |
String sql = "insert into tabone values (:id, :name, :answer)"; |
|
56824 | 125 |
try (Session session = ds.getSession()) { |
126 |
OperationGroup group = session.operationGroup() |
|
56797 | 127 |
.independent(); |
128 |
group.submitHoldingForMoreMembers(); |
|
129 |
for (Item elem : list) { |
|
130 |
group.rowCountOperation(sql) |
|
131 |
.set("elem_", elem) |
|
132 |
.submit() |
|
133 |
.getCompletionStage() |
|
134 |
.exceptionally( t -> { |
|
135 |
System.out.println(elem.id); |
|
136 |
return null; |
|
137 |
}); |
|
138 |
} |
|
139 |
group.releaseProhibitingMoreMembers(); |
|
140 |
} |
|
141 |
} |
|
142 |
||
143 |
// Parallel, Independent OperationGroup |
|
144 |
||
145 |
public void updateListParallel(List<Item> list, DataSource ds) { |
|
146 |
String query = "select id from tab where answer = :answer"; |
|
147 |
String update = "update tab set name = :name where id = :id"; |
|
56824 | 148 |
try (Session session = ds.getSession()) { |
149 |
OperationGroup<Object, Object> group = session.operationGroup() |
|
56797 | 150 |
.independent() |
151 |
.parallel(); |
|
152 |
group.submitHoldingForMoreMembers(); |
|
153 |
for (Item elem : list) { |
|
154 |
CompletionStage<Integer> idPromise = group.<List<Integer>>rowOperation(query) |
|
155 |
.set("answer", elem.answer, AdbaType.NUMERIC) |
|
156 |
.collect( Collector.of( |
|
157 |
() -> new ArrayList<>(), |
|
158 |
(l, row) -> l.add( row.at("id").get(Integer.class) ), |
|
159 |
(l, r) -> l )) |
|
160 |
.submit() |
|
161 |
.getCompletionStage() |
|
162 |
.thenApply( l -> l.get(0) ); |
|
163 |
group.rowCountOperation(update) |
|
164 |
.set("id", idPromise) |
|
165 |
.set("name", "the ultimate question") |
|
166 |
.submit() |
|
167 |
.getCompletionStage() |
|
168 |
.exceptionally( t -> { |
|
169 |
System.out.println(elem.id); |
|
170 |
return null; |
|
171 |
}); |
|
172 |
} |
|
173 |
group.releaseProhibitingMoreMembers(); |
|
174 |
} |
|
175 |
} |
|
176 |
||
56828
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
177 |
// TransactionCompletion |
56797 | 178 |
|
179 |
public void transaction(DataSource ds) { |
|
56824 | 180 |
try (Session session = ds.getSession(t -> System.out.println("ERROR: " + t.toString()))) { |
56828
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
181 |
TransactionCompletion trans = session.transactionCompletion(); |
56824 | 182 |
CompletionStage<Integer> idPromise = session.<Integer>rowOperation("select empno, ename from emp where ename = :1 for update") |
56797 | 183 |
.set("1", "CLARK", AdbaType.VARCHAR) |
184 |
.collect(Collectors.collectingAndThen( |
|
185 |
Collectors.mapping(r -> r.at("empno").get(Integer.class), |
|
186 |
Collectors.toList()), |
|
187 |
l -> l.get(0))) |
|
188 |
.onError( t -> trans.setRollbackOnly() ) |
|
189 |
.submit() |
|
190 |
.getCompletionStage(); |
|
56824 | 191 |
session.<Long>rowCountOperation("update emp set deptno = :1 where empno = :2") |
56797 | 192 |
.set("1", 50, AdbaType.INTEGER) |
193 |
.set("2", idPromise, AdbaType.INTEGER) |
|
194 |
.apply(c -> { |
|
195 |
if (c.getCount() != 1L) { |
|
196 |
trans.setRollbackOnly(); |
|
197 |
throw new RuntimeException("updated wrong number of rows"); |
|
198 |
} |
|
199 |
return c.getCount(); |
|
200 |
}) |
|
201 |
.onError(t -> trans.setRollbackOnly() ) |
|
202 |
.submit(); |
|
203 |
// .getCompletionStage() |
|
204 |
// .exceptionally( t -> { trans.setRollbackOnly(); return null; } ) // incorrect |
|
56824 | 205 |
session.catchErrors(); |
206 |
session.commitMaybeRollback(trans); |
|
56797 | 207 |
} |
208 |
} |
|
209 |
||
210 |
// RowPublisherOperation |
|
211 |
||
212 |
public CompletionStage<List<String>> rowSubscriber(DataSource ds) { |
|
213 |
||
214 |
String sql = "select empno, ename from emp"; |
|
215 |
CompletableFuture<List<String>> result = new CompletableFuture<>(); |
|
216 |
||
217 |
Flow.Subscriber<Result.RowColumn> subscriber = new Flow.Subscriber<>() { |
|
218 |
||
219 |
Flow.Subscription subscription; |
|
220 |
List<String> names = new ArrayList<>(); |
|
221 |
int demand = 0; |
|
222 |
||
223 |
@Override |
|
224 |
public void onSubscribe(Flow.Subscription subscription) { |
|
225 |
this.subscription = subscription; |
|
226 |
this.subscription.request(10); |
|
227 |
demand += 10; |
|
228 |
} |
|
229 |
||
230 |
@Override |
|
231 |
public void onNext(Result.RowColumn column) { |
|
232 |
names.add(column.at("ename").get(String.class)); |
|
233 |
if (--demand < 1) { |
|
234 |
subscription.request(10); |
|
235 |
demand += 10; |
|
236 |
} |
|
237 |
} |
|
238 |
||
239 |
@Override |
|
240 |
public void onError(Throwable throwable) { |
|
241 |
result.completeExceptionally(throwable); |
|
242 |
} |
|
243 |
||
244 |
@Override |
|
245 |
public void onComplete() { |
|
246 |
result.complete(names); |
|
247 |
} |
|
248 |
||
249 |
}; |
|
250 |
||
56824 | 251 |
try (Session session = ds.getSession()) { |
252 |
return session.<List<String>>rowPublisherOperation(sql) |
|
56797 | 253 |
.subscribe(subscriber, result) |
254 |
.submit() |
|
255 |
.getCompletionStage(); |
|
256 |
} |
|
257 |
} |
|
258 |
||
259 |
// Control Operation Submission Rate |
|
260 |
||
261 |
public CompletionStage<Long> insertRecords(DataSource ds, DataInputStream in) { |
|
262 |
String insert = "insert into tab values (@record)"; |
|
56824 | 263 |
try (Session session = ds.getSession()) { |
264 |
OperationGroup<Long, Long> group = session.<Long, Long>operationGroup() |
|
56797 | 265 |
.independent() |
266 |
.collect(Collectors.summingLong(c -> c)); |
|
267 |
group.submitHoldingForMoreMembers(); |
|
268 |
Semaphore demand = new Semaphore(0); |
|
56824 | 269 |
session.requestHook( n -> demand.release((int)n) ); |
56797 | 270 |
while (in.available() > 0) { |
271 |
demand.acquire(1); // user thread blocked by Semaphore, not by ADBA |
|
272 |
group.<Long>rowCountOperation(insert) |
|
273 |
.set("record", in.readUTF(), AdbaType.VARCHAR) |
|
274 |
.apply(c -> c.getCount()) |
|
275 |
.submit(); |
|
276 |
} |
|
277 |
return group.releaseProhibitingMoreMembers() |
|
278 |
.getCompletionStage(); |
|
279 |
} |
|
280 |
catch (IOException | InterruptedException ex) { |
|
281 |
throw new SqlException(ex); |
|
282 |
} |
|
283 |
} |
|
284 |
||
285 |
// ArrayRowCountOperation |
|
286 |
||
287 |
public CompletionStage<Long> arrayInsert(DataSource ds, |
|
288 |
List<Integer> ids, |
|
289 |
List<String> names, |
|
290 |
List<Integer> answers) { |
|
291 |
String sql = "insert into tab values (?, ?, ?)"; |
|
56824 | 292 |
try (Session session = ds.getSession()) { |
293 |
return session.<Long>arrayRowCountOperation(sql) |
|
56797 | 294 |
.collect(Collectors.summingLong( c -> c.getCount() )) |
295 |
.set("1",ids, AdbaType.INTEGER) |
|
296 |
.set("2", names, AdbaType.VARCHAR) |
|
297 |
.set("3", answers, AdbaType.INTEGER) |
|
298 |
.submit() |
|
299 |
.getCompletionStage(); |
|
300 |
} |
|
301 |
} |
|
302 |
||
303 |
// ArrayRowCountOperation -- transposed |
|
304 |
||
305 |
public CompletionStage<Long> transposedArrayInsert(DataSource ds, List<Item> items) { |
|
306 |
String sql = "insert into tab values (?, ?, ?)"; |
|
56824 | 307 |
try (Session session = ds.getSession()) { |
308 |
return session.<Long>arrayRowCountOperation(sql) |
|
56797 | 309 |
.collect(Collectors.summingLong( c -> c.getCount() )) |
310 |
.set("1", items.stream().map(Item::id).collect(Collectors.toList()), AdbaType.INTEGER) |
|
311 |
.set("2", items.stream().map(Item::name).collect(Collectors.toList()), AdbaType.VARCHAR) |
|
312 |
.set("3", items.stream().map(Item::answer).collect(Collectors.toList()), AdbaType.INTEGER) |
|
313 |
.submit() |
|
314 |
.getCompletionStage(); |
|
315 |
} |
|
316 |
} |
|
317 |
||
318 |
// OutOperation |
|
319 |
||
320 |
public CompletionStage<Item> getItem(DataSource ds, int id) { |
|
321 |
String sql = "call item_for_id(:id, :name, :answer)"; |
|
56824 | 322 |
try (Session session = ds.getSession()) { |
323 |
return session.<Item>outOperation(sql) |
|
56797 | 324 |
.set("id", id, AdbaType.INTEGER) |
325 |
.outParameter("name", AdbaType.VARCHAR) |
|
326 |
.outParameter("answer", AdbaType.INTEGER) |
|
327 |
.apply( out -> new Item(id, |
|
328 |
out.at("name").get(String.class), |
|
329 |
out.at("answer").get(Integer.class)) ) |
|
330 |
.submit() |
|
331 |
.getCompletionStage(); |
|
332 |
} |
|
333 |
} |
|
334 |
||
335 |
// MultiOperation |
|
336 |
||
337 |
// LocalOperation |
|
338 |
||
56824 | 339 |
// SessionProperty |
56828
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
340 |
public enum ExampleSessionProperty implements SessionProperty { |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
341 |
LANGUAGE; |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
342 |
|
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
343 |
private static final String DEFAULT_VALUE = "AMERICAN_AMERICA"; |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
344 |
|
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
345 |
@Override |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
346 |
public Class<?> range() { |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
347 |
return String.class; |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
348 |
} |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
349 |
|
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
350 |
@Override |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
351 |
public Object defaultValue() { |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
352 |
return DEFAULT_VALUE; |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
353 |
} |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
354 |
|
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
355 |
@Override |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
356 |
public boolean isSensitive() { |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
357 |
return false; |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
358 |
} |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
359 |
|
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
360 |
@Override |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
361 |
public boolean configureOperation(OperationGroup<?, ?> group, Object value) { |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
362 |
group.operation("ALTER SESSION SET NLS_LANG = " |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
363 |
+ group.enquoteIdentifier((String)value, false)) |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
364 |
.submit(); |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
365 |
return true; |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
366 |
} |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
367 |
|
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
368 |
} |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
369 |
|
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
370 |
public Session getSession(DataSource ds) { |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
371 |
return ds.builder() |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
372 |
.property(ExampleSessionProperty.LANGUAGE, "FRENCH_FRANCE") |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
373 |
.build() |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
374 |
.attach(); |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
375 |
} |
56797 | 376 |
|
377 |
// Sharding |
|
378 |
||
379 |
// TransactionOutcome |
|
380 |
||
381 |
// Column navigation |
|
382 |
||
56824 | 383 |
private class Name { Name(String ... args) {} } |
384 |
private class Address { Address(String ... args) {} } |
|
385 |
||
386 |
private Name getName(Result.Column col) { |
|
387 |
return new Name( |
|
388 |
col.get(String.class), // title |
|
389 |
col.next().get(String.class), // given name |
|
390 |
col.next().get(String.class), // middle initial |
|
391 |
col.next().get(String.class), // family name |
|
392 |
col.next().get(String.class)); // suffix |
|
393 |
} |
|
394 |
||
395 |
private Address getAddress(Result.Column col) { |
|
396 |
List<String> a = new ArrayList<>(); |
|
397 |
for (Result.Column c : col.slice(6)) { |
|
398 |
a.add(c.get(String.class)); |
|
399 |
} |
|
400 |
return new Address(a.toArray(new String[0])); |
|
401 |
} |
|
402 |
public void columNavigation(Result.RowColumn column) { |
|
403 |
Name fullName = getName(column.at("name_title")); |
|
404 |
Address streetAddress = getAddress(column.at("street_address_line1")); |
|
405 |
Address mailingAddress = getAddress(column.at("mailing_address_line1")); |
|
406 |
for (Result.Column c : column.at(-14)) { // dump the last 14 columns |
|
407 |
System.out.println("trailing column " + c.get(String.class)); |
|
408 |
} |
|
409 |
} |
|
410 |
||
56797 | 411 |
// Error handling |
56824 | 412 |
|
56797 | 413 |
|
414 |
static public class Item { |
|
415 |
public int id; |
|
416 |
public String name; |
|
417 |
public int answer; |
|
418 |
||
419 |
public Item(int i, String n, int a) { |
|
420 |
id =i; |
|
421 |
name = n; |
|
422 |
answer = a; |
|
423 |
} |
|
424 |
||
425 |
public int id() { |
|
426 |
return id; |
|
427 |
} |
|
428 |
||
429 |
public String name() { |
|
430 |
return name; |
|
431 |
} |
|
432 |
||
433 |
public int answer() { |
|
434 |
return answer; |
|
435 |
} |
|
436 |
} |
|
437 |
||
438 |
} |