From 60a87262c1d30d7a2a245a9e2ab3e2cd7f936f1c Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Sun, 13 Oct 2024 18:42:39 +0200 Subject: [PATCH] Adapt api --- .../itsallcode/jdbc/BatchInsertBuilder.java | 18 +++++++++++++++--- .../jdbc/identifier/QualifiedIdentifier.java | 12 +++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/itsallcode/jdbc/BatchInsertBuilder.java b/src/main/java/org/itsallcode/jdbc/BatchInsertBuilder.java index d8985e4..945bac9 100644 --- a/src/main/java/org/itsallcode/jdbc/BatchInsertBuilder.java +++ b/src/main/java/org/itsallcode/jdbc/BatchInsertBuilder.java @@ -38,12 +38,24 @@ public class BatchInsertBuilder { * @return {@code this} for fluent programming */ @SuppressWarnings("java:S3242") // Using List instead of Collection to preserve column order - public BatchInsertBuilder into(final String tableName, final List columnNames) { - this.sql = createInsertStatement(Identifier.simple(tableName), - columnNames.stream().map(Identifier::simple).toList()); + public BatchInsertBuilder into(final Identifier tableName, final List columnNames) { + this.sql = createInsertStatement(tableName, columnNames); return this; } + /** + * Define table and column names used for generating the {@code INSERT} + * statement. + * + * @param tableName table name + * @param columnNames column names + * @return {@code this} for fluent programming + */ + @SuppressWarnings("java:S3242") // Using List instead of Collection to preserve column order + public BatchInsertBuilder into(final String tableName, final List columnNames) { + return into(Identifier.simple(tableName), columnNames.stream().map(Identifier::simple).toList()); + } + /** * Define {@link Stream} of rows to insert. * diff --git a/src/main/java/org/itsallcode/jdbc/identifier/QualifiedIdentifier.java b/src/main/java/org/itsallcode/jdbc/identifier/QualifiedIdentifier.java index 753c673..b5002ff 100644 --- a/src/main/java/org/itsallcode/jdbc/identifier/QualifiedIdentifier.java +++ b/src/main/java/org/itsallcode/jdbc/identifier/QualifiedIdentifier.java @@ -8,7 +8,7 @@ /** * A qualified identifier, e.g. table name and schema name. */ -record QualifiedIdentifier(List id) implements Identifier { +public record QualifiedIdentifier(List id) implements Identifier { /** * Create a new qualified identifier. @@ -21,6 +21,16 @@ public static Identifier of(final Identifier... ids) { return new QualifiedIdentifier(asList(ids)); } + /** + * Create a new qualified identifier. + * + * @param ids the simple IDs + * @return a new instance + */ + public static Identifier of(final String... ids) { + return of(asList(ids).stream().map(Identifier::simple).toArray(Identifier[]::new)); + } + @Override public String toString() { return quote();