Skip to content

Commit 3db7d00

Browse files
committed
Code improvements.
Signed-off-by: Franz Wilhelmstötter <franz.wilhelmstoetter@gmail.com>
1 parent 766e564 commit 3db7d00

File tree

6 files changed

+33
-14
lines changed

6 files changed

+33
-14
lines changed

facilejdbc/src/main/java/io/jenetics/facilejdbc/Lifecycle.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -257,25 +257,25 @@ public static final class Value<T, E extends Exception>
257257
implements Supplier<T>, ExtendedCloseable<E>
258258
{
259259

260-
private final T _value;
261-
private final ThrowingConsumer<? super T, ? extends E> _release;
260+
private final T value;
261+
private final ThrowingConsumer<? super T, ? extends E> release;
262262

263263
private Value(
264264
final T value,
265265
final ThrowingConsumer<? super T, ? extends E> release
266266
) {
267-
_value = value;
268-
_release = requireNonNull(release);
267+
this.value = value;
268+
this.release = requireNonNull(release);
269269
}
270270

271271
@Override
272272
public T get() {
273-
return _value;
273+
return value;
274274
}
275275

276276
@Override
277277
public void close() throws E {
278-
_release.accept(get());
278+
release.accept(get());
279279
}
280280

281281
@Override
@@ -430,7 +430,7 @@ public static final class Resources<E extends Exception>
430430
implements ExtendedCloseable<E>
431431
{
432432

433-
private final List<ThrowingRunnable<? extends E>> _resources = new ArrayList<>();
433+
private final List<ThrowingRunnable<? extends E>> resources = new ArrayList<>();
434434

435435
/**
436436
* Create a new {@code Resources} object, initialized with the given
@@ -441,7 +441,7 @@ public static final class Resources<E extends Exception>
441441
public Resources(
442442
final Collection<? extends ThrowingRunnable<? extends E>> releases
443443
) {
444-
_resources.addAll(releases);
444+
resources.addAll(releases);
445445
}
446446

447447
/**
@@ -480,14 +480,14 @@ public <C> C add(
480480
requireNonNull(resource);
481481
requireNonNull(release);
482482

483-
_resources.add(() -> release.accept(resource));
483+
resources.add(() -> release.accept(resource));
484484
return resource;
485485
}
486486

487487
@Override
488488
public void close() throws E {
489-
if (!_resources.isEmpty()) {
490-
ExtendedCloseable.of(_resources).close();
489+
if (!resources.isEmpty()) {
490+
ExtendedCloseable.of(resources).close();
491491
}
492492
}
493493

facilejdbc/src/main/java/io/jenetics/facilejdbc/Query.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,19 @@
5050

5151
/**
5252
* A {@code Query} represents an executable piece of SQL text.
53+
* <p>
54+
* <b>Select query</b>
5355
* {@snippet lang="java":
5456
* private static final Query SELECT = Query.of("""
5557
* SELECT * FROM person
5658
* WHERE forename like :forename
5759
* ORDER BY surname;
5860
* """
5961
* );
60-
*
62+
* }
63+
* <p>
64+
* <b>Insert query</b>
65+
* {@snippet lang="java":
6166
* private static final Query INSERT = Query.of("""
6267
* INSERT INTO person(forename, surname, birthday, email)
6368
* VALUES(:forename, :surname, :birthday, :email);
@@ -613,14 +618,19 @@ public String toString() {
613618

614619
/**
615620
* Create a new query object from the given SQL string.
621+
* <p>
622+
* <b>Select query</b>
616623
* {@snippet lang="java":
617624
* private static final Query SELECT = Query.of("""
618625
* SELECT * FROM person
619626
* WHERE forename like :forename
620627
* ORDER BY surname;
621628
* """
622629
* );
623-
*
630+
* }
631+
* <p>
632+
* <b>Insert query</b>
633+
* {@snippet lang="java":
624634
* private static final Query INSERT = Query.of("""
625635
* INSERT INTO person(forename, surname, birthday, email)
626636
* VALUES(:forename, :surname, :birthday, :email);

facilejdbc/src/main/java/io/jenetics/facilejdbc/RowParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,10 @@ default ResultSetParser<Set<T>> unmodifiableSet() {
358358
* While consuming the result {@link Stream}, possible {@link SQLException}s
359359
* are wrapped into {@link UncheckedSQLException}s.
360360
* {@snippet lang="java":
361+
* static final RowParser<Book> PARSER = RowParser.record(Book.class);
361362
* final var select = Query.of("SELECT * FROM book;");
363+
*
364+
* // Query result stream must be used within a try-with-resources block.
362365
* try (var stream = select.as(PARSER.stream(), conn)) {
363366
* stream.forEach(book -> null); // @replace substring='null' replacement="..."
364367
* }

facilejdbc/src/main/java/io/jenetics/facilejdbc/SingleParam.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* INSERT_QUERY.on(
3232
* Param.value("forename", "Werner"),
3333
* Param.value("birthday", LocalDate.now()),
34-
* Param.value("email", "some.email@gmail.com"))
34+
* Param.value("email", "some.email@gmail.com"));
3535
* }
3636
*
3737
* @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>

facilejdbc/src/main/java/io/jenetics/facilejdbc/Stored.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020
package io.jenetics.facilejdbc;
2121

22+
import static java.util.Objects.requireNonNull;
23+
2224
/**
2325
* This class combines a record, stored in the DB, with its primary key.
2426
*
@@ -32,4 +34,7 @@
3234
* @since 2.1
3335
*/
3436
public record Stored<K, T>(K id, T value) {
37+
public Stored {
38+
requireNonNull(id);
39+
}
3540
}

facilejdbc/src/main/java/io/jenetics/facilejdbc/Transaction.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
* @version 1.1
5252
* @since 1.1
5353
*/
54+
@FunctionalInterface
5455
public interface Transaction {
5556

5657
/**

0 commit comments

Comments
 (0)