implement writesReturnUpdateCount
[yosql.git] / yosql-codegen / src / test / java / wtf / metio / yosql / codegen / dao / DefaultReadMethodGeneratorTest.java
blob3eda87253eef58e6378b831c5fe221a868460b26
1 /*
2 * This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level
3 * directory of this distribution and at https://creativecommons.org/publicdomain/zero/1.0/. No part of yosql,
4 * including this file, may be copied, modified, propagated, or distributed except according to the terms contained
5 * in the LICENSE file.
6 */
8 package wtf.metio.yosql.codegen.dao;
10 import org.junit.jupiter.api.DisplayName;
11 import org.junit.jupiter.api.Nested;
12 import wtf.metio.yosql.internals.testing.configs.JavaConfigurations;
14 @DisplayName("DefaultReadMethodGenerator")
15 class DefaultReadMethodGeneratorTest {
17 @Nested
18 @DisplayName("using default configuration")
19 class Defaults extends ReadMethodGeneratorTCK {
21 @Override
22 ReadMethodGenerator generator() {
23 return DaoObjectMother.readMethodGenerator(JavaConfigurations.defaults());
26 @Override
27 String readSingleMethodExpectation() {
28 return """
29 /**
30 * <p>Executes the following statement:</p>
31 * <pre>
32 * SELECT raw FROM table WHERE test = ? AND id = ?;</pre>
34 * <p>Generated based on the following file(s):</p>
35 * <ul>
36 * <li>data/queryData.sql</li>
37 * </ul>
38 * <p>Disable generating this method by setting <strong>generateStandardApi</strong> to <strong>false</strong></p>
40 @javax.annotation.processing.Generated(
41 value = "YoSQL",
42 comments = "DO NOT MODIFY - automatically generated by YoSQL"
44 public final java.util.Optional<java.util.Map<java.lang.String, java.lang.Object>> queryData(
45 final java.lang.Object test, final int id) {
46 LOG.entering("com.example.persistence.DataRepository", "queryData");
47 try (final var connection = dataSource.getConnection()) {
48 final var query = QUERY_DATA;
49 LOG.finer(() -> java.lang.String.format("Picked query [%s]", "QUERY_DATA"));
50 final var rawQuery = QUERY_DATA_RAW;
51 final var index = QUERY_DATA_INDEX;
52 LOG.finer(() -> java.lang.String.format("Picked index [%s]", "QUERY_DATA_INDEX"));
53 try (final var statement = connection.prepareStatement(query)) {
54 for (final int jdbcIndex : index.get("test")) {
55 statement.setObject(jdbcIndex, test);
57 for (final int jdbcIndex : index.get("id")) {
58 statement.setObject(jdbcIndex, id);
60 if (LOG.isLoggable(java.util.logging.Level.FINE)) {
61 final var executedQuery = rawQuery
62 .replace(":test", test == null ? "null" : test.toString())
63 .replace(":id", java.lang.String.valueOf(id));
64 LOG.fine(() -> java.lang.String.format("Executing query [%s]", executedQuery));
66 try (final var resultSet = statement.executeQuery()) {
67 final var list = new java.util.ArrayList<java.util.Map<java.lang.String, java.lang.Object>>();
68 while (resultSet.next()) {
69 list.add(toMap.apply(resultSet));
71 return list.size() > 0 ? java.util.Optional.of(list.get(0)) : java.util.Optional.empty();
75 catch (final java.sql.SQLException exception) {
76 throw new java.lang.RuntimeException(exception);
79 """;
82 @Override
83 String readMultipleMethodExpectation() {
84 return """
85 /**
86 * <p>Executes the following statement:</p>
87 * <pre>
88 * SELECT raw FROM table WHERE test = ? AND id = ?;</pre>
90 * <p>Generated based on the following file(s):</p>
91 * <ul>
92 * <li>data/queryData.sql</li>
93 * </ul>
94 * <p>Disable generating this method by setting <strong>generateStandardApi</strong> to <strong>false</strong></p>
96 @javax.annotation.processing.Generated(
97 value = "YoSQL",
98 comments = "DO NOT MODIFY - automatically generated by YoSQL"
100 public final java.util.List<java.util.Map<java.lang.String, java.lang.Object>> queryData(
101 final java.lang.Object test, final int id) {
102 LOG.entering("com.example.persistence.DataRepository", "queryData");
103 try (final var connection = dataSource.getConnection()) {
104 final var query = QUERY_DATA;
105 LOG.finer(() -> java.lang.String.format("Picked query [%s]", "QUERY_DATA"));
106 final var rawQuery = QUERY_DATA_RAW;
107 final var index = QUERY_DATA_INDEX;
108 LOG.finer(() -> java.lang.String.format("Picked index [%s]", "QUERY_DATA_INDEX"));
109 try (final var statement = connection.prepareStatement(query)) {
110 for (final int jdbcIndex : index.get("test")) {
111 statement.setObject(jdbcIndex, test);
113 for (final int jdbcIndex : index.get("id")) {
114 statement.setObject(jdbcIndex, id);
116 if (LOG.isLoggable(java.util.logging.Level.FINE)) {
117 final var executedQuery = rawQuery
118 .replace(":test", test == null ? "null" : test.toString())
119 .replace(":id", java.lang.String.valueOf(id));
120 LOG.fine(() -> java.lang.String.format("Executing query [%s]", executedQuery));
122 try (final var resultSet = statement.executeQuery()) {
123 final var list = new java.util.ArrayList<java.util.Map<java.lang.String, java.lang.Object>>();
124 while (resultSet.next()) {
125 list.add(toMap.apply(resultSet));
127 return list;
131 catch (final java.sql.SQLException exception) {
132 throw new java.lang.RuntimeException(exception);
135 """;
138 @Override
139 String readCursorMethodExpectation() {
140 return """
142 * <p>Executes the following statement:</p>
143 * <pre>
144 * SELECT raw FROM table WHERE test = ? AND id = ?;</pre>
146 * <p>Generated based on the following file(s):</p>
147 * <ul>
148 * <li>data/queryData.sql</li>
149 * </ul>
150 * <p>Disable generating this method by setting <strong>generateStandardApi</strong> to <strong>false</strong></p>
152 @javax.annotation.processing.Generated(
153 value = "YoSQL",
154 comments = "DO NOT MODIFY - automatically generated by YoSQL"
156 public final java.util.stream.Stream<java.util.Map<java.lang.String, java.lang.Object>> queryData(
157 final java.lang.Object test, final int id) {
158 LOG.entering("com.example.persistence.DataRepository", "queryData");
159 try {
160 final var connection = dataSource.getConnection();
161 final var query = QUERY_DATA;
162 LOG.finer(() -> java.lang.String.format("Picked query [%s]", "QUERY_DATA"));
163 final var rawQuery = QUERY_DATA_RAW;
164 final var index = QUERY_DATA_INDEX;
165 LOG.finer(() -> java.lang.String.format("Picked index [%s]", "QUERY_DATA_INDEX"));
166 final var statement = connection.prepareStatement(query);
167 for (final int jdbcIndex : index.get("test")) {
168 statement.setObject(jdbcIndex, test);
170 for (final int jdbcIndex : index.get("id")) {
171 statement.setObject(jdbcIndex, id);
173 if (LOG.isLoggable(java.util.logging.Level.FINE)) {
174 final var executedQuery = rawQuery
175 .replace(":test", test == null ? "null" : test.toString())
176 .replace(":id", java.lang.String.valueOf(id));
177 LOG.fine(() -> java.lang.String.format("Executing query [%s]", executedQuery));
179 final var resultSet = statement.executeQuery();
180 return java.util.stream.StreamSupport.stream(new java.util.Spliterators.AbstractSpliterator<java.util.Map<java.lang.String, java.lang.Object>>(java.lang.Long.MAX_VALUE, java.util.Spliterator.ORDERED) {
181 @java.lang.Override
182 @javax.annotation.processing.Generated(
183 value = "YoSQL",
184 comments = "DO NOT MODIFY - automatically generated by YoSQL"
186 public final boolean tryAdvance(
187 final java.util.function.Consumer<? super java.util.Map<java.lang.String, java.lang.Object>> action) {
188 try {
189 if (resultSet.next()) {
190 action.accept(toMap.apply(resultSet));
191 return true;
193 return false;
195 catch (final java.sql.SQLException exception) {
196 throw new java.lang.RuntimeException(exception);
199 }, false).onClose(new java.lang.Runnable() {
200 @java.lang.Override
201 @javax.annotation.processing.Generated(
202 value = "YoSQL",
203 comments = "DO NOT MODIFY - automatically generated by YoSQL"
205 public final void run() {
206 try {
207 resultSet.close();
208 statement.close();
209 connection.close();
211 catch (final java.sql.SQLException exception) {
212 throw new java.lang.RuntimeException(exception);
217 catch (final java.sql.SQLException exception) {
218 throw new java.lang.RuntimeException(exception);
221 """;
224 @Override
225 String readNoneMethodExpectation() {
226 return """
228 * <p>Executes the following statement:</p>
229 * <pre>
230 * SELECT raw FROM table WHERE test = ? AND id = ?;</pre>
232 * <p>Generated based on the following file(s):</p>
233 * <ul>
234 * <li>data/queryData.sql</li>
235 * </ul>
236 * <p>Disable generating this method by setting <strong>generateStandardApi</strong> to <strong>false</strong></p>
238 @javax.annotation.processing.Generated(
239 value = "YoSQL",
240 comments = "DO NOT MODIFY - automatically generated by YoSQL"
242 public final void queryData(final java.lang.Object test, final int id) {
243 LOG.entering("com.example.persistence.DataRepository", "queryData");
244 try {
245 final var connection = dataSource.getConnection();
246 final var query = QUERY_DATA;
247 LOG.finer(() -> java.lang.String.format("Picked query [%s]", "QUERY_DATA"));
248 final var rawQuery = QUERY_DATA_RAW;
249 final var index = QUERY_DATA_INDEX;
250 LOG.finer(() -> java.lang.String.format("Picked index [%s]", "QUERY_DATA_INDEX"));
251 final var statement = connection.prepareStatement(query);
252 for (final int jdbcIndex : index.get("test")) {
253 statement.setObject(jdbcIndex, test);
255 for (final int jdbcIndex : index.get("id")) {
256 statement.setObject(jdbcIndex, id);
258 if (LOG.isLoggable(java.util.logging.Level.FINE)) {
259 final var executedQuery = rawQuery
260 .replace(":test", test == null ? "null" : test.toString())
261 .replace(":id", java.lang.String.valueOf(id));
262 LOG.fine(() -> java.lang.String.format("Executing query [%s]", executedQuery));
264 try (final var resultSet = statement.executeQuery()) {
266 catch (final java.sql.SQLException exception) {
267 throw new java.lang.RuntimeException(exception);
270 """;
275 @Nested
276 @DisplayName("using Java 11 configuration")
277 class Java11 extends ReadMethodGeneratorTCK {
279 @Override
280 ReadMethodGenerator generator() {
281 return DaoObjectMother.readMethodGenerator(JavaConfigurations.java11());
284 @Override
285 String readSingleMethodExpectation() {
286 return """
288 * <p>Executes the following statement:</p>
289 * <pre>
290 * SELECT raw FROM table WHERE test = ? AND id = ?;</pre>
292 * <p>Generated based on the following file(s):</p>
293 * <ul>
294 * <li>data/queryData.sql</li>
295 * </ul>
296 * <p>Disable generating this method by setting <strong>generateStandardApi</strong> to <strong>false</strong></p>
298 @javax.annotation.processing.Generated(
299 value = "YoSQL",
300 comments = "DO NOT MODIFY - automatically generated by YoSQL"
302 public final java.util.Optional<java.util.Map<java.lang.String, java.lang.Object>> queryData(
303 final java.lang.Object test, final int id) {
304 LOG.entering("com.example.persistence.DataRepository", "queryData");
305 try (final var connection = dataSource.getConnection()) {
306 final var query = QUERY_DATA;
307 LOG.finer(() -> java.lang.String.format("Picked query [%s]", "QUERY_DATA"));
308 final var rawQuery = QUERY_DATA_RAW;
309 final var index = QUERY_DATA_INDEX;
310 LOG.finer(() -> java.lang.String.format("Picked index [%s]", "QUERY_DATA_INDEX"));
311 try (final var statement = connection.prepareStatement(query)) {
312 for (final int jdbcIndex : index.get("test")) {
313 statement.setObject(jdbcIndex, test);
315 for (final int jdbcIndex : index.get("id")) {
316 statement.setObject(jdbcIndex, id);
318 if (LOG.isLoggable(java.util.logging.Level.FINE)) {
319 final var executedQuery = rawQuery
320 .replace(":test", test == null ? "null" : test.toString())
321 .replace(":id", java.lang.String.valueOf(id));
322 LOG.fine(() -> java.lang.String.format("Executing query [%s]", executedQuery));
324 try (final var resultSet = statement.executeQuery()) {
325 final var list = new java.util.ArrayList<java.util.Map<java.lang.String, java.lang.Object>>();
326 while (resultSet.next()) {
327 list.add(toMap.apply(resultSet));
329 return list.size() > 0 ? java.util.Optional.of(list.get(0)) : java.util.Optional.empty();
333 catch (final java.sql.SQLException exception) {
334 throw new java.lang.RuntimeException(exception);
337 """;
340 @Override
341 String readMultipleMethodExpectation() {
342 return """
344 * <p>Executes the following statement:</p>
345 * <pre>
346 * SELECT raw FROM table WHERE test = ? AND id = ?;</pre>
348 * <p>Generated based on the following file(s):</p>
349 * <ul>
350 * <li>data/queryData.sql</li>
351 * </ul>
352 * <p>Disable generating this method by setting <strong>generateStandardApi</strong> to <strong>false</strong></p>
354 @javax.annotation.processing.Generated(
355 value = "YoSQL",
356 comments = "DO NOT MODIFY - automatically generated by YoSQL"
358 public final java.util.List<java.util.Map<java.lang.String, java.lang.Object>> queryData(
359 final java.lang.Object test, final int id) {
360 LOG.entering("com.example.persistence.DataRepository", "queryData");
361 try (final var connection = dataSource.getConnection()) {
362 final var query = QUERY_DATA;
363 LOG.finer(() -> java.lang.String.format("Picked query [%s]", "QUERY_DATA"));
364 final var rawQuery = QUERY_DATA_RAW;
365 final var index = QUERY_DATA_INDEX;
366 LOG.finer(() -> java.lang.String.format("Picked index [%s]", "QUERY_DATA_INDEX"));
367 try (final var statement = connection.prepareStatement(query)) {
368 for (final int jdbcIndex : index.get("test")) {
369 statement.setObject(jdbcIndex, test);
371 for (final int jdbcIndex : index.get("id")) {
372 statement.setObject(jdbcIndex, id);
374 if (LOG.isLoggable(java.util.logging.Level.FINE)) {
375 final var executedQuery = rawQuery
376 .replace(":test", test == null ? "null" : test.toString())
377 .replace(":id", java.lang.String.valueOf(id));
378 LOG.fine(() -> java.lang.String.format("Executing query [%s]", executedQuery));
380 try (final var resultSet = statement.executeQuery()) {
381 final var list = new java.util.ArrayList<java.util.Map<java.lang.String, java.lang.Object>>();
382 while (resultSet.next()) {
383 list.add(toMap.apply(resultSet));
385 return list;
389 catch (final java.sql.SQLException exception) {
390 throw new java.lang.RuntimeException(exception);
393 """;
396 @Override
397 String readCursorMethodExpectation() {
398 return """
400 * <p>Executes the following statement:</p>
401 * <pre>
402 * SELECT raw FROM table WHERE test = ? AND id = ?;</pre>
404 * <p>Generated based on the following file(s):</p>
405 * <ul>
406 * <li>data/queryData.sql</li>
407 * </ul>
408 * <p>Disable generating this method by setting <strong>generateStandardApi</strong> to <strong>false</strong></p>
410 @javax.annotation.processing.Generated(
411 value = "YoSQL",
412 comments = "DO NOT MODIFY - automatically generated by YoSQL"
414 public final java.util.stream.Stream<java.util.Map<java.lang.String, java.lang.Object>> queryData(
415 final java.lang.Object test, final int id) {
416 LOG.entering("com.example.persistence.DataRepository", "queryData");
417 try {
418 final var connection = dataSource.getConnection();
419 final var query = QUERY_DATA;
420 LOG.finer(() -> java.lang.String.format("Picked query [%s]", "QUERY_DATA"));
421 final var rawQuery = QUERY_DATA_RAW;
422 final var index = QUERY_DATA_INDEX;
423 LOG.finer(() -> java.lang.String.format("Picked index [%s]", "QUERY_DATA_INDEX"));
424 final var statement = connection.prepareStatement(query);
425 for (final int jdbcIndex : index.get("test")) {
426 statement.setObject(jdbcIndex, test);
428 for (final int jdbcIndex : index.get("id")) {
429 statement.setObject(jdbcIndex, id);
431 if (LOG.isLoggable(java.util.logging.Level.FINE)) {
432 final var executedQuery = rawQuery
433 .replace(":test", test == null ? "null" : test.toString())
434 .replace(":id", java.lang.String.valueOf(id));
435 LOG.fine(() -> java.lang.String.format("Executing query [%s]", executedQuery));
437 final var resultSet = statement.executeQuery();
438 return java.util.stream.StreamSupport.stream(new java.util.Spliterators.AbstractSpliterator<java.util.Map<java.lang.String, java.lang.Object>>(java.lang.Long.MAX_VALUE, java.util.Spliterator.ORDERED) {
439 @java.lang.Override
440 @javax.annotation.processing.Generated(
441 value = "YoSQL",
442 comments = "DO NOT MODIFY - automatically generated by YoSQL"
444 public final boolean tryAdvance(
445 final java.util.function.Consumer<? super java.util.Map<java.lang.String, java.lang.Object>> action) {
446 try {
447 if (resultSet.next()) {
448 action.accept(toMap.apply(resultSet));
449 return true;
451 return false;
453 catch (final java.sql.SQLException exception) {
454 throw new java.lang.RuntimeException(exception);
457 }, false).onClose(new java.lang.Runnable() {
458 @java.lang.Override
459 @javax.annotation.processing.Generated(
460 value = "YoSQL",
461 comments = "DO NOT MODIFY - automatically generated by YoSQL"
463 public final void run() {
464 try {
465 resultSet.close();
466 statement.close();
467 connection.close();
469 catch (final java.sql.SQLException exception) {
470 throw new java.lang.RuntimeException(exception);
475 catch (final java.sql.SQLException exception) {
476 throw new java.lang.RuntimeException(exception);
479 """;
482 @Override
483 String readNoneMethodExpectation() {
484 return """
486 * <p>Executes the following statement:</p>
487 * <pre>
488 * SELECT raw FROM table WHERE test = ? AND id = ?;</pre>
490 * <p>Generated based on the following file(s):</p>
491 * <ul>
492 * <li>data/queryData.sql</li>
493 * </ul>
494 * <p>Disable generating this method by setting <strong>generateStandardApi</strong> to <strong>false</strong></p>
496 @javax.annotation.processing.Generated(
497 value = "YoSQL",
498 comments = "DO NOT MODIFY - automatically generated by YoSQL"
500 public final void queryData(final java.lang.Object test, final int id) {
501 LOG.entering("com.example.persistence.DataRepository", "queryData");
502 try {
503 final var connection = dataSource.getConnection();
504 final var query = QUERY_DATA;
505 LOG.finer(() -> java.lang.String.format("Picked query [%s]", "QUERY_DATA"));
506 final var rawQuery = QUERY_DATA_RAW;
507 final var index = QUERY_DATA_INDEX;
508 LOG.finer(() -> java.lang.String.format("Picked index [%s]", "QUERY_DATA_INDEX"));
509 final var statement = connection.prepareStatement(query);
510 for (final int jdbcIndex : index.get("test")) {
511 statement.setObject(jdbcIndex, test);
513 for (final int jdbcIndex : index.get("id")) {
514 statement.setObject(jdbcIndex, id);
516 if (LOG.isLoggable(java.util.logging.Level.FINE)) {
517 final var executedQuery = rawQuery
518 .replace(":test", test == null ? "null" : test.toString())
519 .replace(":id", java.lang.String.valueOf(id));
520 LOG.fine(() -> java.lang.String.format("Executing query [%s]", executedQuery));
522 try (final var resultSet = statement.executeQuery()) {
524 catch (final java.sql.SQLException exception) {
525 throw new java.lang.RuntimeException(exception);
528 """;
533 @Nested
534 @DisplayName("using Java 14 configuration")
535 class Java14 extends ReadMethodGeneratorTCK {
537 @Override
538 ReadMethodGenerator generator() {
539 return DaoObjectMother.readMethodGenerator(JavaConfigurations.java14());
542 @Override
543 String readSingleMethodExpectation() {
544 return """
546 * <p>Executes the following statement:</p>
547 * <pre>
548 * SELECT raw FROM table WHERE test = ? AND id = ?;</pre>
550 * <p>Generated based on the following file(s):</p>
551 * <ul>
552 * <li>data/queryData.sql</li>
553 * </ul>
554 * <p>Disable generating this method by setting <strong>generateStandardApi</strong> to <strong>false</strong></p>
556 @javax.annotation.processing.Generated(
557 value = "YoSQL",
558 comments = "DO NOT MODIFY - automatically generated by YoSQL"
560 public final java.util.Optional<java.util.Map<java.lang.String, java.lang.Object>> queryData(
561 final java.lang.Object test, final int id) {
562 LOG.entering("com.example.persistence.DataRepository", "queryData");
563 try (final var connection = dataSource.getConnection()) {
564 final var query = QUERY_DATA;
565 LOG.finer(() -> java.lang.String.format("Picked query [%s]", "QUERY_DATA"));
566 final var rawQuery = QUERY_DATA_RAW;
567 final var index = QUERY_DATA_INDEX;
568 LOG.finer(() -> java.lang.String.format("Picked index [%s]", "QUERY_DATA_INDEX"));
569 try (final var statement = connection.prepareStatement(query)) {
570 for (final int jdbcIndex : index.get("test")) {
571 statement.setObject(jdbcIndex, test);
573 for (final int jdbcIndex : index.get("id")) {
574 statement.setObject(jdbcIndex, id);
576 if (LOG.isLoggable(java.util.logging.Level.FINE)) {
577 final var executedQuery = rawQuery
578 .replace(":test", test == null ? "null" : test.toString())
579 .replace(":id", java.lang.String.valueOf(id));
580 LOG.fine(() -> java.lang.String.format("Executing query [%s]", executedQuery));
582 try (final var resultSet = statement.executeQuery()) {
583 final var list = new java.util.ArrayList<java.util.Map<java.lang.String, java.lang.Object>>();
584 while (resultSet.next()) {
585 list.add(toMap.apply(resultSet));
587 return list.size() > 0 ? java.util.Optional.of(list.get(0)) : java.util.Optional.empty();
591 catch (final java.sql.SQLException exception) {
592 throw new java.lang.RuntimeException(exception);
595 """;
598 @Override
599 String readMultipleMethodExpectation() {
600 return """
602 * <p>Executes the following statement:</p>
603 * <pre>
604 * SELECT raw FROM table WHERE test = ? AND id = ?;</pre>
606 * <p>Generated based on the following file(s):</p>
607 * <ul>
608 * <li>data/queryData.sql</li>
609 * </ul>
610 * <p>Disable generating this method by setting <strong>generateStandardApi</strong> to <strong>false</strong></p>
612 @javax.annotation.processing.Generated(
613 value = "YoSQL",
614 comments = "DO NOT MODIFY - automatically generated by YoSQL"
616 public final java.util.List<java.util.Map<java.lang.String, java.lang.Object>> queryData(
617 final java.lang.Object test, final int id) {
618 LOG.entering("com.example.persistence.DataRepository", "queryData");
619 try (final var connection = dataSource.getConnection()) {
620 final var query = QUERY_DATA;
621 LOG.finer(() -> java.lang.String.format("Picked query [%s]", "QUERY_DATA"));
622 final var rawQuery = QUERY_DATA_RAW;
623 final var index = QUERY_DATA_INDEX;
624 LOG.finer(() -> java.lang.String.format("Picked index [%s]", "QUERY_DATA_INDEX"));
625 try (final var statement = connection.prepareStatement(query)) {
626 for (final int jdbcIndex : index.get("test")) {
627 statement.setObject(jdbcIndex, test);
629 for (final int jdbcIndex : index.get("id")) {
630 statement.setObject(jdbcIndex, id);
632 if (LOG.isLoggable(java.util.logging.Level.FINE)) {
633 final var executedQuery = rawQuery
634 .replace(":test", test == null ? "null" : test.toString())
635 .replace(":id", java.lang.String.valueOf(id));
636 LOG.fine(() -> java.lang.String.format("Executing query [%s]", executedQuery));
638 try (final var resultSet = statement.executeQuery()) {
639 final var list = new java.util.ArrayList<java.util.Map<java.lang.String, java.lang.Object>>();
640 while (resultSet.next()) {
641 list.add(toMap.apply(resultSet));
643 return list;
647 catch (final java.sql.SQLException exception) {
648 throw new java.lang.RuntimeException(exception);
651 """;
654 @Override
655 String readCursorMethodExpectation() {
656 return """
658 * <p>Executes the following statement:</p>
659 * <pre>
660 * SELECT raw FROM table WHERE test = ? AND id = ?;</pre>
662 * <p>Generated based on the following file(s):</p>
663 * <ul>
664 * <li>data/queryData.sql</li>
665 * </ul>
666 * <p>Disable generating this method by setting <strong>generateStandardApi</strong> to <strong>false</strong></p>
668 @javax.annotation.processing.Generated(
669 value = "YoSQL",
670 comments = "DO NOT MODIFY - automatically generated by YoSQL"
672 public final java.util.stream.Stream<java.util.Map<java.lang.String, java.lang.Object>> queryData(
673 final java.lang.Object test, final int id) {
674 LOG.entering("com.example.persistence.DataRepository", "queryData");
675 try {
676 final var connection = dataSource.getConnection();
677 final var query = QUERY_DATA;
678 LOG.finer(() -> java.lang.String.format("Picked query [%s]", "QUERY_DATA"));
679 final var rawQuery = QUERY_DATA_RAW;
680 final var index = QUERY_DATA_INDEX;
681 LOG.finer(() -> java.lang.String.format("Picked index [%s]", "QUERY_DATA_INDEX"));
682 final var statement = connection.prepareStatement(query);
683 for (final int jdbcIndex : index.get("test")) {
684 statement.setObject(jdbcIndex, test);
686 for (final int jdbcIndex : index.get("id")) {
687 statement.setObject(jdbcIndex, id);
689 if (LOG.isLoggable(java.util.logging.Level.FINE)) {
690 final var executedQuery = rawQuery
691 .replace(":test", test == null ? "null" : test.toString())
692 .replace(":id", java.lang.String.valueOf(id));
693 LOG.fine(() -> java.lang.String.format("Executing query [%s]", executedQuery));
695 final var resultSet = statement.executeQuery();
696 return java.util.stream.StreamSupport.stream(new java.util.Spliterators.AbstractSpliterator<java.util.Map<java.lang.String, java.lang.Object>>(java.lang.Long.MAX_VALUE, java.util.Spliterator.ORDERED) {
697 @java.lang.Override
698 @javax.annotation.processing.Generated(
699 value = "YoSQL",
700 comments = "DO NOT MODIFY - automatically generated by YoSQL"
702 public final boolean tryAdvance(
703 final java.util.function.Consumer<? super java.util.Map<java.lang.String, java.lang.Object>> action) {
704 try {
705 if (resultSet.next()) {
706 action.accept(toMap.apply(resultSet));
707 return true;
709 return false;
711 catch (final java.sql.SQLException exception) {
712 throw new java.lang.RuntimeException(exception);
715 }, false).onClose(new java.lang.Runnable() {
716 @java.lang.Override
717 @javax.annotation.processing.Generated(
718 value = "YoSQL",
719 comments = "DO NOT MODIFY - automatically generated by YoSQL"
721 public final void run() {
722 try {
723 resultSet.close();
724 statement.close();
725 connection.close();
727 catch (final java.sql.SQLException exception) {
728 throw new java.lang.RuntimeException(exception);
733 catch (final java.sql.SQLException exception) {
734 throw new java.lang.RuntimeException(exception);
737 """;
740 @Override
741 String readNoneMethodExpectation() {
742 return """
744 * <p>Executes the following statement:</p>
745 * <pre>
746 * SELECT raw FROM table WHERE test = ? AND id = ?;</pre>
748 * <p>Generated based on the following file(s):</p>
749 * <ul>
750 * <li>data/queryData.sql</li>
751 * </ul>
752 * <p>Disable generating this method by setting <strong>generateStandardApi</strong> to <strong>false</strong></p>
754 @javax.annotation.processing.Generated(
755 value = "YoSQL",
756 comments = "DO NOT MODIFY - automatically generated by YoSQL"
758 public final void queryData(final java.lang.Object test, final int id) {
759 LOG.entering("com.example.persistence.DataRepository", "queryData");
760 try {
761 final var connection = dataSource.getConnection();
762 final var query = QUERY_DATA;
763 LOG.finer(() -> java.lang.String.format("Picked query [%s]", "QUERY_DATA"));
764 final var rawQuery = QUERY_DATA_RAW;
765 final var index = QUERY_DATA_INDEX;
766 LOG.finer(() -> java.lang.String.format("Picked index [%s]", "QUERY_DATA_INDEX"));
767 final var statement = connection.prepareStatement(query);
768 for (final int jdbcIndex : index.get("test")) {
769 statement.setObject(jdbcIndex, test);
771 for (final int jdbcIndex : index.get("id")) {
772 statement.setObject(jdbcIndex, id);
774 if (LOG.isLoggable(java.util.logging.Level.FINE)) {
775 final var executedQuery = rawQuery
776 .replace(":test", test == null ? "null" : test.toString())
777 .replace(":id", java.lang.String.valueOf(id));
778 LOG.fine(() -> java.lang.String.format("Executing query [%s]", executedQuery));
780 try (final var resultSet = statement.executeQuery()) {
782 catch (final java.sql.SQLException exception) {
783 throw new java.lang.RuntimeException(exception);
786 """;
791 @Nested
792 @DisplayName("using Java 16 configuration")
793 class Java16 extends ReadMethodGeneratorTCK {
795 @Override
796 ReadMethodGenerator generator() {
797 return DaoObjectMother.readMethodGenerator(JavaConfigurations.java16());
800 @Override
801 String readSingleMethodExpectation() {
802 return """
804 * <p>Executes the following statement:</p>
805 * <pre>
806 * SELECT raw FROM table WHERE test = ? AND id = ?;</pre>
808 * <p>Generated based on the following file(s):</p>
809 * <ul>
810 * <li>data/queryData.sql</li>
811 * </ul>
812 * <p>Disable generating this method by setting <strong>generateStandardApi</strong> to <strong>false</strong></p>
814 @javax.annotation.processing.Generated(
815 value = "YoSQL",
816 comments = "DO NOT MODIFY - automatically generated by YoSQL"
818 public final java.util.Optional<java.util.Map<java.lang.String, java.lang.Object>> queryData(
819 final java.lang.Object test, final int id) {
820 LOG.entering("com.example.persistence.DataRepository", "queryData");
821 try (final var connection = dataSource.getConnection()) {
822 final var query = QUERY_DATA;
823 LOG.finer(() -> java.lang.String.format("Picked query [%s]", "QUERY_DATA"));
824 final var rawQuery = QUERY_DATA_RAW;
825 final var index = QUERY_DATA_INDEX;
826 LOG.finer(() -> java.lang.String.format("Picked index [%s]", "QUERY_DATA_INDEX"));
827 try (final var statement = connection.prepareStatement(query)) {
828 for (final int jdbcIndex : index.get("test")) {
829 statement.setObject(jdbcIndex, test);
831 for (final int jdbcIndex : index.get("id")) {
832 statement.setObject(jdbcIndex, id);
834 if (LOG.isLoggable(java.util.logging.Level.FINE)) {
835 final var executedQuery = rawQuery
836 .replace(":test", test == null ? "null" : test.toString())
837 .replace(":id", java.lang.String.valueOf(id));
838 LOG.fine(() -> java.lang.String.format("Executing query [%s]", executedQuery));
840 try (final var resultSet = statement.executeQuery()) {
841 final var list = new java.util.ArrayList<java.util.Map<java.lang.String, java.lang.Object>>();
842 while (resultSet.next()) {
843 list.add(toMap.apply(resultSet));
845 return list.size() > 0 ? java.util.Optional.of(list.get(0)) : java.util.Optional.empty();
849 catch (final java.sql.SQLException exception) {
850 throw new java.lang.RuntimeException(exception);
853 """;
856 @Override
857 String readMultipleMethodExpectation() {
858 return """
860 * <p>Executes the following statement:</p>
861 * <pre>
862 * SELECT raw FROM table WHERE test = ? AND id = ?;</pre>
864 * <p>Generated based on the following file(s):</p>
865 * <ul>
866 * <li>data/queryData.sql</li>
867 * </ul>
868 * <p>Disable generating this method by setting <strong>generateStandardApi</strong> to <strong>false</strong></p>
870 @javax.annotation.processing.Generated(
871 value = "YoSQL",
872 comments = "DO NOT MODIFY - automatically generated by YoSQL"
874 public final java.util.List<java.util.Map<java.lang.String, java.lang.Object>> queryData(
875 final java.lang.Object test, final int id) {
876 LOG.entering("com.example.persistence.DataRepository", "queryData");
877 try (final var connection = dataSource.getConnection()) {
878 final var query = QUERY_DATA;
879 LOG.finer(() -> java.lang.String.format("Picked query [%s]", "QUERY_DATA"));
880 final var rawQuery = QUERY_DATA_RAW;
881 final var index = QUERY_DATA_INDEX;
882 LOG.finer(() -> java.lang.String.format("Picked index [%s]", "QUERY_DATA_INDEX"));
883 try (final var statement = connection.prepareStatement(query)) {
884 for (final int jdbcIndex : index.get("test")) {
885 statement.setObject(jdbcIndex, test);
887 for (final int jdbcIndex : index.get("id")) {
888 statement.setObject(jdbcIndex, id);
890 if (LOG.isLoggable(java.util.logging.Level.FINE)) {
891 final var executedQuery = rawQuery
892 .replace(":test", test == null ? "null" : test.toString())
893 .replace(":id", java.lang.String.valueOf(id));
894 LOG.fine(() -> java.lang.String.format("Executing query [%s]", executedQuery));
896 try (final var resultSet = statement.executeQuery()) {
897 final var list = new java.util.ArrayList<java.util.Map<java.lang.String, java.lang.Object>>();
898 while (resultSet.next()) {
899 list.add(toMap.apply(resultSet));
901 return list;
905 catch (final java.sql.SQLException exception) {
906 throw new java.lang.RuntimeException(exception);
909 """;
912 @Override
913 String readCursorMethodExpectation() {
914 return """
916 * <p>Executes the following statement:</p>
917 * <pre>
918 * SELECT raw FROM table WHERE test = ? AND id = ?;</pre>
920 * <p>Generated based on the following file(s):</p>
921 * <ul>
922 * <li>data/queryData.sql</li>
923 * </ul>
924 * <p>Disable generating this method by setting <strong>generateStandardApi</strong> to <strong>false</strong></p>
926 @javax.annotation.processing.Generated(
927 value = "YoSQL",
928 comments = "DO NOT MODIFY - automatically generated by YoSQL"
930 public final java.util.stream.Stream<java.util.Map<java.lang.String, java.lang.Object>> queryData(
931 final java.lang.Object test, final int id) {
932 LOG.entering("com.example.persistence.DataRepository", "queryData");
933 try {
934 final var connection = dataSource.getConnection();
935 final var query = QUERY_DATA;
936 LOG.finer(() -> java.lang.String.format("Picked query [%s]", "QUERY_DATA"));
937 final var rawQuery = QUERY_DATA_RAW;
938 final var index = QUERY_DATA_INDEX;
939 LOG.finer(() -> java.lang.String.format("Picked index [%s]", "QUERY_DATA_INDEX"));
940 final var statement = connection.prepareStatement(query);
941 for (final int jdbcIndex : index.get("test")) {
942 statement.setObject(jdbcIndex, test);
944 for (final int jdbcIndex : index.get("id")) {
945 statement.setObject(jdbcIndex, id);
947 if (LOG.isLoggable(java.util.logging.Level.FINE)) {
948 final var executedQuery = rawQuery
949 .replace(":test", test == null ? "null" : test.toString())
950 .replace(":id", java.lang.String.valueOf(id));
951 LOG.fine(() -> java.lang.String.format("Executing query [%s]", executedQuery));
953 final var resultSet = statement.executeQuery();
954 return java.util.stream.StreamSupport.stream(new java.util.Spliterators.AbstractSpliterator<java.util.Map<java.lang.String, java.lang.Object>>(java.lang.Long.MAX_VALUE, java.util.Spliterator.ORDERED) {
955 @java.lang.Override
956 @javax.annotation.processing.Generated(
957 value = "YoSQL",
958 comments = "DO NOT MODIFY - automatically generated by YoSQL"
960 public final boolean tryAdvance(
961 final java.util.function.Consumer<? super java.util.Map<java.lang.String, java.lang.Object>> action) {
962 try {
963 if (resultSet.next()) {
964 action.accept(toMap.apply(resultSet));
965 return true;
967 return false;
969 catch (final java.sql.SQLException exception) {
970 throw new java.lang.RuntimeException(exception);
973 }, false).onClose(new java.lang.Runnable() {
974 @java.lang.Override
975 @javax.annotation.processing.Generated(
976 value = "YoSQL",
977 comments = "DO NOT MODIFY - automatically generated by YoSQL"
979 public final void run() {
980 try {
981 resultSet.close();
982 statement.close();
983 connection.close();
985 catch (final java.sql.SQLException exception) {
986 throw new java.lang.RuntimeException(exception);
991 catch (final java.sql.SQLException exception) {
992 throw new java.lang.RuntimeException(exception);
995 """;
998 @Override
999 String readNoneMethodExpectation() {
1000 return """
1002 * <p>Executes the following statement:</p>
1003 * <pre>
1004 * SELECT raw FROM table WHERE test = ? AND id = ?;</pre>
1006 * <p>Generated based on the following file(s):</p>
1007 * <ul>
1008 * <li>data/queryData.sql</li>
1009 * </ul>
1010 * <p>Disable generating this method by setting <strong>generateStandardApi</strong> to <strong>false</strong></p>
1012 @javax.annotation.processing.Generated(
1013 value = "YoSQL",
1014 comments = "DO NOT MODIFY - automatically generated by YoSQL"
1016 public final void queryData(final java.lang.Object test, final int id) {
1017 LOG.entering("com.example.persistence.DataRepository", "queryData");
1018 try {
1019 final var connection = dataSource.getConnection();
1020 final var query = QUERY_DATA;
1021 LOG.finer(() -> java.lang.String.format("Picked query [%s]", "QUERY_DATA"));
1022 final var rawQuery = QUERY_DATA_RAW;
1023 final var index = QUERY_DATA_INDEX;
1024 LOG.finer(() -> java.lang.String.format("Picked index [%s]", "QUERY_DATA_INDEX"));
1025 final var statement = connection.prepareStatement(query);
1026 for (final int jdbcIndex : index.get("test")) {
1027 statement.setObject(jdbcIndex, test);
1029 for (final int jdbcIndex : index.get("id")) {
1030 statement.setObject(jdbcIndex, id);
1032 if (LOG.isLoggable(java.util.logging.Level.FINE)) {
1033 final var executedQuery = rawQuery
1034 .replace(":test", test == null ? "null" : test.toString())
1035 .replace(":id", java.lang.String.valueOf(id));
1036 LOG.fine(() -> java.lang.String.format("Executing query [%s]", executedQuery));
1038 try (final var resultSet = statement.executeQuery()) {
1040 catch (final java.sql.SQLException exception) {
1041 throw new java.lang.RuntimeException(exception);
1044 """;