diff --git a/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonClient.java b/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonClient.java index d677c900c28..4eeec6f2965 100644 --- a/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonClient.java +++ b/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonClient.java @@ -17,14 +17,28 @@ import io.helidon.dbclient.DbClient; +/** + * Helidon database client. + *

Common {@link DbClient} implementations ancestor with {@link CommonClientContext}. + */ public abstract class CommonClient implements DbClient { private final CommonClientContext context; + /** + * Creates an instance of {@lik CommonClient}. + * + * @param context database client context. + */ public CommonClient(CommonClientContext context) { this.context = context; } + /** + * Get database client context. + * + * @return database client context. + */ public CommonClientContext context() { return context; } diff --git a/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonClientBuilder.java b/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonClientBuilder.java index 91445ca53a6..1e45576860d 100644 --- a/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonClientBuilder.java +++ b/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonClientBuilder.java @@ -26,6 +26,13 @@ import io.helidon.dbclient.spi.DbClientBuilder; import io.helidon.dbclient.spi.DbMapperProvider; +/** + * Provider specific {@link io.helidon.dbclient.DbClient} builder. + *

Common {@link DbClientBuilder} implementations ancestor with {@link DbMapperManager.Builder} + * and common attributes required to initialize target {@code DbClient} instance. + * + * @param type of the builder extending or implementing this interface. + */ public abstract class CommonClientBuilder> implements DbClientBuilder { @@ -37,6 +44,9 @@ public abstract class CommonClientBuilder> private MapperManager mapperManager; private DbMapperManager dbMapperManager; + /** + * Creates an instance of {@link CommonClientBuilder}. + */ protected CommonClientBuilder() { } @@ -117,18 +127,38 @@ public T addMapperProvider(DbMapperProvider provider) { return identity(); } + /** + * Get database URL. + * + * @return database URL + */ public String url() { return url; } + /** + * Get database user name. + * + * @return database user name + */ public String username() { return username; } + /** + * Get database user password. + * + * @return database user password. + */ public String password() { return password; } + /** + * Get configured statements to be used by database provider. + * + * @return statements to be used by database provider + */ public DbStatements statements() { return statements; } @@ -137,10 +167,20 @@ public DbStatements statements() { // return List.copyOf(clientServices); // } + /** + * Get {@link io.helidon.common.mapper.Mapper} manager. + * + * @return {@code Mapper} manager. + */ public MapperManager mapperManager() { return mapperManager; } + /** + * Get manager of all configured {@link DbMapper mappers}. + * + * @return manager of all configured {@link DbMapper mappers} + */ public DbMapperManager dbMapperManager() { return dbMapperManager; } diff --git a/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonClientContext.java b/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonClientContext.java index 65f1f4660eb..efc3dabbe8c 100644 --- a/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonClientContext.java +++ b/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonClientContext.java @@ -110,8 +110,6 @@ public static Builder builder() { /** * A common base for builders for classes that want to extend {@link CommonClientContext}. - * - * @param type of the builder extending this builder, to keep fluent API */ public static class Builder implements io.helidon.common.Builder { diff --git a/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonColumn.java b/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonColumn.java index fa19dca8d04..29299b27a2c 100644 --- a/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonColumn.java +++ b/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonColumn.java @@ -21,9 +21,13 @@ import io.helidon.dbclient.DbClient; import io.helidon.dbclient.DbColumn; +/** + * Column data and metadata. + *

Common {@link DbColumn} implementations ancestor with {@link MapperManager} and database column value. + */ public abstract class CommonColumn implements DbColumn { - protected final Object value; + private final Object value; private final MapperManager mapperManager; protected CommonColumn(Object value, MapperManager mapperManager) { @@ -31,6 +35,10 @@ protected CommonColumn(Object value, MapperManager mapperManager) { this.mapperManager = mapperManager; } + protected Object rawValue() { + return value; + } + @Override public T as(Class type) throws MapperException { if (null == value) { diff --git a/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonRow.java b/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonRow.java index ad4f3480e7b..33b0837a4d6 100644 --- a/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonRow.java +++ b/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonRow.java @@ -26,10 +26,14 @@ import io.helidon.dbclient.DbMapperManager; import io.helidon.dbclient.DbRow; +/** + * Representation of a single row in a database (in SQL this would be a row, in a Document DB, this would be a single document). + *

Common {@link DbRow} implementations ancestor with {@link DbMapperManager} and an array of {@link DbColumn}s. + */ public abstract class CommonRow implements DbRow { private final DbMapperManager dbMapperManager; - CommonColumn[] columns; + private final CommonColumn[] columns; private final Map namesIndex; protected CommonRow(CommonColumn[] columns, DbMapperManager dbMapperManager) { diff --git a/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonStatement.java b/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonStatement.java index 1f261f2921a..1e630a849e0 100644 --- a/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonStatement.java +++ b/dbclient/common/src/main/java/io/helidon/dbclient/common/CommonStatement.java @@ -23,10 +23,9 @@ /** * Common statement methods and fields. * - * @param type of a subclass - * @param the result type of the statement as returned by {@link #execute()} + * @param type of the descendant of this class */ -public abstract class CommonStatement , R> implements DbStatement { +public abstract class CommonStatement> implements DbStatement { private final CommonClientContext context; @@ -50,6 +49,7 @@ public S indexedParam(Object parameters) { return identity(); } + @Override public S params(List parameters) { parameters.forEach(this::addParam); return identity(); diff --git a/dbclient/common/src/main/java/io/helidon/dbclient/common/package-info.java b/dbclient/common/src/main/java/io/helidon/dbclient/common/package-info.java new file mode 100644 index 00000000000..586f6d01652 --- /dev/null +++ b/dbclient/common/src/main/java/io/helidon/dbclient/common/package-info.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Helper classes to use in various implementations. + */ +package io.helidon.dbclient.common; diff --git a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClient.java b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClient.java index f9475c0d8e8..94f85b537ed 100644 --- a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClient.java +++ b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClient.java @@ -16,8 +16,6 @@ package io.helidon.dbclient; import java.util.Arrays; -import java.util.Optional; -import java.util.stream.Stream; import io.helidon.common.mapper.MapperManager; import io.helidon.config.Config; diff --git a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClientInterceptor.java b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClientInterceptor.java index 67cfc3505a8..84a15b9d9e1 100644 --- a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClientInterceptor.java +++ b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClientInterceptor.java @@ -35,6 +35,6 @@ public interface DbClientInterceptor { * @return single that completes when this service is finished */ Void statement(Void context); - //TODO: replace with DbClientServiceContext statement(DbClientServiceContext context); + //FIXME: replace with DbClientServiceContext statement(DbClientServiceContext context); } diff --git a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbMapperManager.java b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbMapperManager.java index d54e1f02918..1a60e12d47a 100644 --- a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbMapperManager.java +++ b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbMapperManager.java @@ -29,14 +29,13 @@ */ public interface DbMapperManager { + /** Generic type for the {@link DbRow} class. */ GenericType TYPE_DB_ROW = GenericType.create(DbRow.class); - /** - * Generic type for the {@link java.util.Map} of String to value pairs for named parameters. - */ + + /** Generic type for the {@link java.util.Map} of String to value pairs for named parameters. */ GenericType> TYPE_NAMED_PARAMS = new GenericType>() { }; - /** - * Generic type for the {@link java.util.List} of indexed parameters. - */ + + /** Generic type for the {@link java.util.List} of indexed parameters. */ GenericType> TYPE_INDEXED_PARAMS = new GenericType>() { }; /** diff --git a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbStatement.java b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbStatement.java index 23145669f2e..0164845f7b5 100644 --- a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbStatement.java +++ b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbStatement.java @@ -23,10 +23,9 @@ /** * Database statement that can process parameters. - * Method {@link #execute()} processes the statement and returns appropriate response. + * Method {@code execute()} processes the statement and returns appropriate response. *

- * All methods are non-blocking. The {@link #execute()} method returns either a {@link java.util.concurrent.CompletionStage} - * or another object that provides similar API for eventual processing of the response. + * All methods are blocking. *

* Once parameters are set using one of the {@code params} methods, all other methods throw an * {@link IllegalStateException}. @@ -34,12 +33,11 @@ * Once a parameter is added using {@link #addParam(Object)} or {@link #addParam(String, Object)}, all other * {@code params} methods throw an {@link IllegalStateException}. *

- * Once {@link #execute()} is called, all methods would throw an {@link IllegalStateException}. + * Once {@code execute()} is called, all methods would throw an {@link IllegalStateException}. * - * @param Type of the result of this statement (e.g. a {@link java.util.concurrent.CompletionStage}) - * @param Type of the descendant of this class + * @param type of the descendant of this class */ -public interface DbStatement, R> { +public interface DbStatement> { /** * Configure parameters from a {@link java.util.List} by order. @@ -304,10 +302,4 @@ default D params(Object... parameters) { */ D addParam(String name, byte[] parameter); - /** - * Execute this statement using the parameters configured with {@code params} and {@code addParams} methods. - * - * @return The result of this statement, never blocking. - */ - R execute(); } diff --git a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbStatementDml.java b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbStatementDml.java index bfc42ba8bf5..840fa6ae64f 100644 --- a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbStatementDml.java +++ b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbStatementDml.java @@ -19,5 +19,13 @@ * DML Database statement. * A DML statement modifies records in the database and returns the number of modified records. */ -public interface DbStatementDml extends DbStatement { +public interface DbStatementDml extends DbStatement { + + /** + * Execute this statement using the parameters configured with {@code params} and {@code addParams} methods. + * + * @return The result of this statement, never blocking. + */ + long execute(); + } diff --git a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbStatementGet.java b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbStatementGet.java index e8567aff675..9588bdcb290 100644 --- a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbStatementGet.java +++ b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbStatementGet.java @@ -19,8 +19,14 @@ /** * Database statement that queries the database and returns a single row if present, or an empty optional. - * In case the statement returns more than one rows, the future returned by {@link #execute()} will end in - * {@link java.util.concurrent.CompletionStage#exceptionally(java.util.function.Function)}. */ -public interface DbStatementGet extends DbStatement> { +public interface DbStatementGet extends DbStatement { + + /** + * Execute this statement using the parameters configured with {@code params} and {@code addParams} methods. + * + * @return The result of this statement, never blocking. + */ + Optional execute(); + } diff --git a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbStatementQuery.java b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbStatementQuery.java index 452ceb29d77..1c8bd72d8f2 100644 --- a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbStatementQuery.java +++ b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbStatementQuery.java @@ -19,9 +19,18 @@ /** * Database query statement. - *

Important: Method {@link #execute()} returns {@link Stream} of {@link DbRow}. This {@link Stream} must - * always be closed because it holds database resources ({@code java.sql.Connection}, {@code java.sql.Statement} + *

Important: Method {@link #execute()} returns {@link Stream} of {@link DbRow}. This {@link Stream} + * must be always closed because it holds database resources ({@code java.sql.Connection}, {@code java.sql.Statement} * and {@code java.sql.ResultSet}). */ -public interface DbStatementQuery extends DbStatement> { +public interface DbStatementQuery extends DbStatement { + + /** + * Execute this statement using the parameters configured with {@code params} and {@code addParams} methods. + *

Returned {@link Stream} of {@link DbRow} must be always closed because it holds database resources. + * + * @return The result of this statement, never blocking. + */ + Stream execute(); + } diff --git a/dbclient/dbclient/src/main/java/io/helidon/dbclient/package-info.java b/dbclient/dbclient/src/main/java/io/helidon/dbclient/package-info.java new file mode 100644 index 00000000000..a3a9924684b --- /dev/null +++ b/dbclient/dbclient/src/main/java/io/helidon/dbclient/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Database client API for Helidon. + */ +package io.helidon.dbclient; diff --git a/dbclient/dbclient/src/main/java/io/helidon/dbclient/spi/package-info.java b/dbclient/dbclient/src/main/java/io/helidon/dbclient/spi/package-info.java new file mode 100644 index 00000000000..612b3e9259e --- /dev/null +++ b/dbclient/dbclient/src/main/java/io/helidon/dbclient/spi/package-info.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Service provider interface for Helidon DB. + * The main entry point for driver implementor is {@link io.helidon.dbclient.spi.DbClientProvider}. + * + * @see io.helidon.dbclient.spi.DbClientProvider + * @see io.helidon.dbclient.spi.DbClientBuilder + * @see io.helidon.dbclient.spi.DbMapperProvider + */ +package io.helidon.dbclient.spi; diff --git a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcColumn.java b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcColumn.java index 3239525f372..16f3976a167 100644 --- a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcColumn.java +++ b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcColumn.java @@ -15,6 +15,7 @@ */ package io.helidon.dbclient.jdbc; +import java.lang.System.Logger.Level; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; @@ -24,6 +25,9 @@ class JdbcColumn extends CommonColumn { + /** Local logger instance. */ + private static final System.Logger LOGGER = System.getLogger(JdbcColumn.class.getName()); + private final MetaData metaData; private JdbcColumn(Object value, MetaData metaData, MapperManager mapperManager) { @@ -34,10 +38,10 @@ private JdbcColumn(Object value, MetaData metaData, MapperManager mapperManager) @Override public Class javaType() { if (null == metaData.javaType()) { - if (null == value) { + if (null == rawValue()) { return null; } - return value.getClass(); + return rawValue().getClass(); } else { return metaData.javaType(); } @@ -115,7 +119,8 @@ private static Class classByName(String columnClassName) { try { return Class.forName(columnClassName); } catch (ClassNotFoundException e) { - // TODO: Log on DEBUG level + LOGGER.log(Level.DEBUG, + String.format("Class %s for column type was not found", columnClassName)); return null; } } diff --git a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcStatement.java b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcStatement.java index 05a6b036dcf..cdaa62a72c9 100644 --- a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcStatement.java +++ b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcStatement.java @@ -27,7 +27,7 @@ import io.helidon.dbclient.DbStatement; import io.helidon.dbclient.common.CommonStatement; -abstract class JdbcStatement, R> extends CommonStatement { +abstract class JdbcStatement> extends CommonStatement { // JDBC statement execution context private final StatementContext context; diff --git a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcStatementDml.java b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcStatementDml.java index 284fd6c223f..a3a0b0686e4 100644 --- a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcStatementDml.java +++ b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcStatementDml.java @@ -22,16 +22,14 @@ import io.helidon.dbclient.DbStatementDml; import io.helidon.dbclient.DbStatementException; -class JdbcStatementDml - extends JdbcStatement - implements DbStatementDml { +class JdbcStatementDml extends JdbcStatement implements DbStatementDml { private JdbcStatementDml(StatementContext context) { super(context); } @Override - public Long execute() { + public long execute() { try (Connection connection = context().connectionPool().connection(); Statement statement = prepare().createStatement(connection)) { return (long) prepare().executeUpdate(); diff --git a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcStatementGet.java b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcStatementGet.java index 648e55310d2..c4738b585cd 100644 --- a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcStatementGet.java +++ b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcStatementGet.java @@ -25,9 +25,7 @@ import io.helidon.dbclient.DbStatementException; import io.helidon.dbclient.DbStatementGet; -class JdbcStatementGet - extends JdbcStatement> - implements DbStatementGet { +class JdbcStatementGet extends JdbcStatement implements DbStatementGet { private JdbcStatementGet(StatementContext context) { super(context); diff --git a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcStatementQuery.java b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcStatementQuery.java index 77f7bc637d8..9113796090e 100644 --- a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcStatementQuery.java +++ b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/JdbcStatementQuery.java @@ -29,9 +29,7 @@ import io.helidon.dbclient.DbStatementException; import io.helidon.dbclient.DbStatementQuery; -class JdbcStatementQuery - extends JdbcStatement> - implements DbStatementQuery { +class JdbcStatementQuery extends JdbcStatement implements DbStatementQuery { private JdbcStatementQuery(StatementContext context) { super(context); diff --git a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/NamedStatementParser.java b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/NamedStatementParser.java index 089bc34089b..5ab0196aea9 100644 --- a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/NamedStatementParser.java +++ b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/NamedStatementParser.java @@ -85,7 +85,7 @@ private enum State { STRING, // SQL string processing after 1st APOSTROPHE was recieved COLON, // Symbolic name processing after opening COLON (colon) was recieved PARAMETER, // Symbolic name processing after 1st LETTER or later LETTER - // or NUMBER of parameter name was recieved + // or NUMBER of parameter name was recieved MULTILN_COMMENT_BG, // Multiline comment processing after opening slash was recieved from the "/*" sequence MULTILN_COMMENT_END, // Multiline comment processing after closing star was recieved from the "*/" sequence MULTILN_COMMENT, // Multiline comment processing of the comment itself @@ -104,9 +104,9 @@ private enum State { STRING, // APOSTROPHE: beginning of SQL string processing, switch to STRING state STATEMENT, // STAR: regular part of the statement, keep processing it SINGLELN_COMMENT_BG, // DASH: possible starting sequence of single line comment, - // switch to SINGLELN_COMMENT_BG state + // switch to SINGLELN_COMMENT_BG state MULTILN_COMMENT_BG, // SLASH: possible starting sequence of multi line comment, - // switch to MULTILN_COMMENT_BG state + // switch to MULTILN_COMMENT_BG state COLON, // COLON: possible beginning of named parameter, switch to COLON state STATEMENT // OTHER: regular part of the statement, keep processing it }, @@ -126,20 +126,20 @@ private enum State { // Transitions from COLON state { PARAMETER, // IDENTIFIER_START: first character of named parameter, - // switch to PARAMETER state + // switch to PARAMETER state STATEMENT, // IDENTIFIER_PART: can't be first character of named parameter, - // go back to STATEMENT state + // go back to STATEMENT state STATEMENT, // LF: can't be first character of named parameter, go back to STATEMENT state STATEMENT, // CR: can't be first character of named parameter, go back to STATEMENT state STRING, // APOSTROPHE: not a named parameter but beginning of SQL string processing, - // switch to STRING state + // switch to STRING state STATEMENT, // STAR: can't be first character of named parameter, go back to STATEMENT state SINGLELN_COMMENT_BG, // DASH: not a named parameter but possible starting sequence of single line comment, - // switch to SINGLELN_COMMENT_BG state + // switch to SINGLELN_COMMENT_BG state MULTILN_COMMENT_BG, // SLASH: not a named parameter but possible starting sequence of multi line comment, - // switch to MULTILN_COMMENT_BG state + // switch to MULTILN_COMMENT_BG state COLON, // COLON: not a named parameter but possible beginning of another named parameter, - // retry named parameter processing + // retry named parameter processing STATEMENT // OTHER: can't be first character of named parameter, go back to STATEMENT state }, // Transitions from PARAMETER state @@ -149,51 +149,51 @@ private enum State { STATEMENT, // LF: can't be next character of named parameter, go back to STATEMENT state STATEMENT, // CR: can't be next character of named parameter, go back to STATEMENT state STRING, // APOSTROPHE: end of named parameter and beginning of SQL string processing, - // switch to STRING state + // switch to STRING state STATEMENT, // STAR: can't be next character of named parameter, go back to STATEMENT state - SINGLELN_COMMENT_BG, // DASH: end of named parameter and possible starting sequence of single line comment, - // switch to SINGLELN_COMMENT_BG state - MULTILN_COMMENT_BG, // SLASH: end of named parameter and possible starting sequence of multi line comment, - // switch to MULTILN_COMMENT_BG state + SINGLELN_COMMENT_BG, // DASH: end of named parameter and possible starting sequence of single + // line comment, switch to SINGLELN_COMMENT_BG state + MULTILN_COMMENT_BG, // SLASH: end of named parameter and possible starting sequence of multi + // line comment, switch to MULTILN_COMMENT_BG state COLON, // COLON: end of named parameter and possible beginning of another named parameter, - // switch to COLON state to restart named parameter processing + // switch to COLON state to restart named parameter processing STATEMENT // OTHER: can't be next character of named parameter, go back to STATEMENT state }, // Transitions from MULTILN_COMMENT_BG state { STATEMENT, // IDENTIFIER_START: not starting sequence of multi line comment, - // go back to STATEMENT state + // go back to STATEMENT state STATEMENT, // IDENTIFIER_PART: not starting sequence of multi line comment, - // go back to STATEMENT state + // go back to STATEMENT state STATEMENT, // LF: not starting sequence of multi line comment, go back to STATEMENT state STATEMENT, // CR: not starting sequence of multi line comment, go back to STATEMENT state STRING, // APOSTROPHE: not starting sequence of multi line comment but beginning of SQL - // string processing, switch to STRING state + // string processing, switch to STRING state MULTILN_COMMENT, // STAR: end of starting sequence of multi line comment, - // switch to MULTILN_COMMENT state + // switch to MULTILN_COMMENT state SINGLELN_COMMENT_BG, // DASH: not starting sequence of multi line comment but possible starting sequence - // of single line comment, switch to SINGLELN_COMMENT_BG state + // of single line comment, switch to SINGLELN_COMMENT_BG state MULTILN_COMMENT_BG, // SLASH: not starting sequence of multi line comment but possible starting sequence - // of next multi line comment, retry multi line comment processing + // of next multi line comment, retry multi line comment processing COLON, // COLON: not starting sequence of multi line comment but possible beginning - // of named parameter, switch to COLON state + // of named parameter, switch to COLON state STATEMENT // OTHER: not starting sequence of multi line comment, go back to STATEMENT state }, // Transitions from MULTILN_COMMENT_END state { MULTILN_COMMENT, // IDENTIFIER_START: not ending sequence of multi line comment, - // go back to MULTILN_COMMENT state + // go back to MULTILN_COMMENT state MULTILN_COMMENT, // IDENTIFIER_PART: not ending sequence of multi line comment, - // go back to MULTILN_COMMENT state + // go back to MULTILN_COMMENT state MULTILN_COMMENT, // LF: not ending sequence of multi line comment, go back to MULTILN_COMMENT state MULTILN_COMMENT, // CR: not ending sequence of multi line comment, go back to MULTILN_COMMENT state MULTILN_COMMENT, // APOSTROPHE: not ending sequence of multi line comment, - // go back to MULTILN_COMMENT state + // go back to MULTILN_COMMENT state MULTILN_COMMENT_END, // STAR: not ending sequence of multi line comment but possible ending sequence - // of next multi line comment, retry end of multi line comment processing + // of next multi line comment, retry end of multi line comment processing MULTILN_COMMENT, // DASH: not ending sequence of multi line comment, go back to MULTILN_COMMENT state STATEMENT, // SLASH: end of ending sequence of multi line comment, - // switch to STATEMENT state + // switch to STATEMENT state MULTILN_COMMENT, // COLON: not ending sequence of multi line comment, go back to MULTILN_COMMENT state MULTILN_COMMENT // OTHER: not ending sequence of multi line comment, go back to MULTILN_COMMENT state }, @@ -205,7 +205,7 @@ private enum State { MULTILN_COMMENT, // CR: regular multi line comment, keep processing it MULTILN_COMMENT, // APOSTROPHE: regular multi line comment, keep processing it MULTILN_COMMENT_END, // STAR: possible ending sequence of multi line comment, - // switch to MULTILN_COMMENT_END state + // switch to MULTILN_COMMENT_END state MULTILN_COMMENT, // DASH: regular multi line comment, keep processing it MULTILN_COMMENT, // SLASH: regular multi line comment, keep processing it MULTILN_COMMENT, // COLON: regular multi line comment, keep processing it @@ -214,38 +214,44 @@ private enum State { // Transitions from SINGLELN_COMMENT_BG state { STATEMENT, // IDENTIFIER_START: not starting sequence of single line comment, - // go back to STATEMENT state + // go back to STATEMENT state STATEMENT, // IDENTIFIER_PART: not starting sequence of single line comment, - // go back to STATEMENT state + // go back to STATEMENT state STATEMENT, // LF: not starting sequence of single line comment, go back to STATEMENT state STATEMENT, // CR: not starting sequence of single line comment, go back to STATEMENT state STRING, // APOSTROPHE: not starting sequence of single line comment but beginning of SQL - // string processing, switch to STRING state + // string processing, switch to STRING state STATEMENT, // STAR: not starting sequence of single line comment, go back to STATEMENT state SINGLELN_COMMENT, // DASH: end of starting sequence of single line comment, - // switch to SINGLELN_COMMENT state - MULTILN_COMMENT_BG, // SLASH: not starting sequence of single line comment but possible starting sequence - // of next multi line comment, switch to MULTILN_COMMENT_BG state + // switch to SINGLELN_COMMENT state + MULTILN_COMMENT_BG, // SLASH: not starting sequence of single line comment + // but possible starting sequence + // of next multi line comment, switch to MULTILN_COMMENT_BG state COLON, // COLON: not starting sequence of single line comment but possible beginning - // of named parameter, switch to COLON state + // of named parameter, switch to COLON state STATEMENT // OTHER: not starting sequence of single line comment, go back to STATEMENT state }, // Transitions from SINGLELN_COMMENT_END state { SINGLELN_COMMENT, // IDENTIFIER_START: not ending sequence of single line comment, - // go back to SINGLELN_COMMENT state + // go back to SINGLELN_COMMENT state SINGLELN_COMMENT, // IDENTIFIER_PART: not ending sequence of single line comment, - // go back to SINGLELN_COMMENT state + // go back to SINGLELN_COMMENT state STATEMENT, // LF: end of single line comment, switch to STATEMENT state SINGLELN_COMMENT_END, // CR: not ending sequence of single line comment but possible ending sequence - // of next single line comment, retry end of single line comment processing + // of next single line comment, retry end of single line comment processing SINGLELN_COMMENT, // APOSTROPHE: not ending sequence of single line comment, - // go back to SINGLELN_COMMENT state - SINGLELN_COMMENT, // STAR: not ending sequence of single line comment, go back to SINGLELN_COMMENT state - SINGLELN_COMMENT, // DASH: not ending sequence of single line comment, go back to SINGLELN_COMMENT state - SINGLELN_COMMENT, // SLASH: not ending sequence of single line comment, go back to SINGLELN_COMMENT state - SINGLELN_COMMENT, // COLON: not ending sequence of single line comment, go back to SINGLELN_COMMENT state - SINGLELN_COMMENT // OTHER: not ending sequence of single line comment, go back to SINGLELN_COMMENT state + // go back to SINGLELN_COMMENT state + SINGLELN_COMMENT, // STAR: not ending sequence of single line comment, + // go back to SINGLELN_COMMENT state + SINGLELN_COMMENT, // DASH: not ending sequence of single line comment, + // go back to SINGLELN_COMMENT state + SINGLELN_COMMENT, // SLASH: not ending sequence of single line comment, + // go back to SINGLELN_COMMENT state + SINGLELN_COMMENT, // COLON: not ending sequence of single line comment, + // go back to SINGLELN_COMMENT state + SINGLELN_COMMENT // OTHER: not ending sequence of single line comment, + // go back to SINGLELN_COMMENT state }, // Transitions from SINGLELN_COMMENT state { @@ -253,7 +259,7 @@ private enum State { SINGLELN_COMMENT, // IDENTIFIER_PART: regular single line comment, keep processing it STATEMENT, // LF: end of single line comment, switch to STATEMENT state SINGLELN_COMMENT_END, // CR: possible beginning of ending sequence of multi line comment, - // switch to SINGLELN_COMMENT_END state + // switch to SINGLELN_COMMENT_END state SINGLELN_COMMENT, // APOSTROPHE: regular single line comment, keep processing it SINGLELN_COMMENT, // STAR: regular single line comment, keep processing it SINGLELN_COMMENT, // DASH: regular single line comment, keep processing it @@ -276,9 +282,10 @@ private enum State { NamedStatementParser::copyChar, // CR: copy regular statement character to output NamedStatementParser::copyChar, // APOSTROPHE: copy SQL string character to output NamedStatementParser::copyChar, // STAR: copy regular statement character to output - NamedStatementParser::copyChar, // DASH: copy character to output, no matter wheter it's comment or not - NamedStatementParser::copyChar, // SLASH: copy character to output, no matter wheter it's comment or not - NamedStatementParser::doNothing, // COLON: delay character copying until it's obvious whether this is parameter or not + NamedStatementParser::copyChar, // DASH: copy character to output, no matter whether it's comment or not + NamedStatementParser::copyChar, // SLASH: copy character to output, no matter whether it's comment or not + NamedStatementParser::doNothing, // COLON: delay character copying until it's obvious + // whether this is parameter or not NamedStatementParser::copyChar // OTHER: copy regular statement character to output }, // Actions performed on transitions from STRING state @@ -297,45 +304,49 @@ private enum State { // Actions performed on transitions from COLON state { NamedStatementParser::setFirstParamChar, // IDENTIFIER_START: set first parameter character - NamedStatementParser::addColonAndCopyChar, // IDENTIFIER_PART: not a parameter, add delayed colon and copy current - // statement character to output - NamedStatementParser::addColonAndCopyChar, // LF: not a parameter, add delayed colon and copy current statement character - // to output - NamedStatementParser::addColonAndCopyChar, // CR: not a parameter, add delayed colon and copy current statement character - // to output - NamedStatementParser::addColonAndCopyChar, // APOSTROPHE: not a parameter, add delayed colon and copy current SQL string - // character to output - NamedStatementParser::addColonAndCopyChar, // STAR: not a parameter, add delayed colon and copy current statement character - // to output - NamedStatementParser::addColonAndCopyChar, // DASH: not a parameter, add delayed colon and copy current statement character - // to output, no matter wheter it's comment or not - NamedStatementParser::addColonAndCopyChar, // SLASH: not a parameter, add delayed colon and copy current statement character - // to output, no matter wheter it's comment or not - NamedStatementParser::addColon, // COLON: not a parameter, add delayed colon and delay current colon copying - // until it's obvious whether this is parameter or not - NamedStatementParser::addColonAndCopyChar // OTHER: not a parameter, add delayed colon and copy current statement character - // to output + NamedStatementParser::addColonAndCopyChar, // IDENTIFIER_PART: not a parameter, add delayed colon and copy + // current statement character to output + NamedStatementParser::addColonAndCopyChar, // LF: not a parameter, add delayed colon and copy current + // statement character to output + NamedStatementParser::addColonAndCopyChar, // CR: not a parameter, add delayed colon and copy current + // statement character to output + NamedStatementParser::addColonAndCopyChar, // APOSTROPHE: not a parameter, add delayed colon and copy + // current SQL string character to output + NamedStatementParser::addColonAndCopyChar, // STAR: not a parameter, add delayed colon and copy current + // statement character to output + NamedStatementParser::addColonAndCopyChar, // DASH: not a parameter, add delayed colon and copy current + // statement character to output, no matter whether + // it's comment or not + NamedStatementParser::addColonAndCopyChar, // SLASH: not a parameter, add delayed colon and copy current + // statement character to output, no matter whether + // it's comment or not + NamedStatementParser::addColon, // COLON: not a parameter, add delayed colon and delay current + // colon copying until it's obvious whether + // this is parameter or not + NamedStatementParser::addColonAndCopyChar // OTHER: not a parameter, add delayed colon and copy current + // statement character to output }, // Actions performed on transitions from PARAMETER state { NamedStatementParser::setNextParamChar, // IDENTIFIER_START: set next parameter character NamedStatementParser::setNextParamChar, // IDENTIFIER_PART: set next parameter character - NamedStatementParser::finishParamAndCopyChar, // LF: finish parameter processing and copy current character as part - // of regular statement - NamedStatementParser::finishParamAndCopyChar, // CR: finish parameter processing and copy current character as part - // of regular statement - NamedStatementParser::finishParamAndCopyChar, // APOSTROPHE: finish parameter processing and copy current character as part - // of regular statement - NamedStatementParser::finishParamAndCopyChar, // STAR: finish parameter processing and copy current character as part - // of regular statement - NamedStatementParser::finishParamAndCopyChar, // DASH: finish parameter processing and copy current character as part - // of regular statement - NamedStatementParser::finishParamAndCopyChar, // SLASH: finish parameter processing and copy current character as part - // of regular statement - NamedStatementParser::finishParam, // COLON: finish parameter processing and delay character copying until - // it's obvious whether this is next parameter or not - NamedStatementParser::finishParamAndCopyChar // OTHER: finish parameter processing and copy current character as part - // of regular statement + NamedStatementParser::finishParamAndCopyChar, // LF: finish parameter processing and copy current character + // as part of regular statement + NamedStatementParser::finishParamAndCopyChar, // CR: finish parameter processing and copy current character + // as part of regular statement + NamedStatementParser::finishParamAndCopyChar, // APOSTROPHE: finish parameter processing and copy current + // character as part of regular statement + NamedStatementParser::finishParamAndCopyChar, // STAR: finish parameter processing and copy current + // character as part of regular statement + NamedStatementParser::finishParamAndCopyChar, // DASH: finish parameter processing and copy current + // character as part of regular statement + NamedStatementParser::finishParamAndCopyChar, // SLASH: finish parameter processing and copy current + // character as part of regular statement + NamedStatementParser::finishParam, // COLON: finish parameter processing and delay character + // copying until it's obvious whether this is next + // parameter or not + NamedStatementParser::finishParamAndCopyChar // OTHER: finish parameter processing and copy current + // character as part of regular statement }, // Actions performed on transitions from MULTILN_COMMENT_BG state { @@ -345,9 +356,10 @@ private enum State { NamedStatementParser::copyChar, // CR: copy regular statement character to output NamedStatementParser::copyChar, // APOSTROPHE: copy SQL string character to output NamedStatementParser::copyChar, // STAR: copy multi line comment character to output - NamedStatementParser::copyChar, // DASH: copy character to output, no matter wheter it's comment or not - NamedStatementParser::copyChar, // SLASH: copy character to output, no matter wheter it's comment or not - NamedStatementParser::doNothing, // COLON: delay character copying until it's obvious whether this is parameter or not + NamedStatementParser::copyChar, // DASH: copy character to output, no matter whether it's comment or not + NamedStatementParser::copyChar, // SLASH: copy character to output, no matter whether it's comment or not + NamedStatementParser::doNothing, // COLON: delay character copying until it's obvious whether + // this is parameter or not NamedStatementParser::copyChar // OTHER: copy regular statement character to output }, // Actions performed on transitions from MULTILN_COMMENT_END state @@ -385,8 +397,9 @@ private enum State { NamedStatementParser::copyChar, // APOSTROPHE: copy SQL string character to output NamedStatementParser::copyChar, // STAR: copy regular statement character to output NamedStatementParser::copyChar, // DASH: copy single line comment character to output - NamedStatementParser::copyChar, // SLASH: copy character to output, no matter wheter it's comment or not - NamedStatementParser::doNothing, // COLON: delay character copying until it's obvious whether this is parameter or not + NamedStatementParser::copyChar, // SLASH: copy character to output, no matter whether it's comment or not + NamedStatementParser::doNothing, // COLON: delay character copying until it's obvious whether + // this is parameter or not NamedStatementParser::copyChar // OTHER: copy regular statement character to output }, // Actions performed on transitions from SINGLELN_COMMENT_END state diff --git a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/ParameterValueHandler.java b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/ParameterValueHandler.java index 3092838647c..e0891832d09 100644 --- a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/ParameterValueHandler.java +++ b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/ParameterValueHandler.java @@ -31,12 +31,16 @@ interface ParameterValueHandler { // Primitive types are stored directly in their own records. abstract class AbstractHandler implements ParameterValueHandler { - T value; + private final T value; AbstractHandler(T value) { this.value = value; } + T value() { + return value; + } + @Override public String valueToString() { return value.toString(); @@ -52,7 +56,7 @@ final class ObjectHandler extends AbstractHandler { @Override public void set(PreparedStatement statement, int index) throws SQLException { - statement.setObject(index, value); + statement.setObject(index, value()); } } @@ -65,7 +69,7 @@ final class StringHandler extends AbstractHandler { @Override public void set(PreparedStatement statement, int index) throws SQLException { - statement.setString(index, value); + statement.setString(index, value()); } } @@ -176,7 +180,7 @@ final class BigDecimalHandler extends AbstractHandler { @Override public void set(PreparedStatement statement, int index) throws SQLException { - statement.setBigDecimal(index, value); + statement.setBigDecimal(index, value()); } } @@ -189,9 +193,9 @@ final class BytesHandler extends AbstractHandler { @Override public void set(PreparedStatement statement, int index) throws SQLException { - statement.setBytes(index, value); + statement.setBytes(index, value()); } } -} \ No newline at end of file +} diff --git a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/StatementContext.java b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/StatementContext.java index ce5039df070..bb8158d072f 100644 --- a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/StatementContext.java +++ b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/StatementContext.java @@ -30,7 +30,10 @@ class StatementContext { private final CommonClientContext clientContext; private final JdbcConnectionPool connectionPool; - private StatementContext(String statementName, String statement, CommonClientContext context, JdbcConnectionPool connectionPool) { + private StatementContext(String statementName, + String statement, + CommonClientContext context, + JdbcConnectionPool connectionPool) { this.statementName = statementName; this.statement = statement; this.clientContext = context; diff --git a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/StatementParams.java b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/StatementParams.java index 85689c88612..84bfdc27505 100644 --- a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/StatementParams.java +++ b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/StatementParams.java @@ -37,7 +37,7 @@ class StatementParams implements JdbcStatement.Builder { // Create statement and store it in this instance for execution @Override public Statement createStatement(Connection connection) throws SQLException { - statement = connection.createStatement();; + statement = connection.createStatement(); return statement; } diff --git a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/package-info.java b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/package-info.java new file mode 100644 index 00000000000..aaa86c1ce69 --- /dev/null +++ b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/package-info.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * JDBC client for Helidon. + */ +package io.helidon.dbclient.jdbc; diff --git a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/spi/package-info.java b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/spi/package-info.java new file mode 100644 index 00000000000..0baf5eb0c66 --- /dev/null +++ b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/spi/package-info.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Service provider interface for Helidon DB implementation for JDBC. + * + * The main entry point for JDBC DB Client configuration services implementation + * is {@link io.helidon.dbclient.jdbc.spi.HikariCpExtensionProvider}. + */ +package io.helidon.dbclient.jdbc.spi;