From aa01545eaf5b37f885960c8413d0843aa3d0d9ca Mon Sep 17 00:00:00 2001 From: scott Date: Mon, 14 Aug 2023 17:37:13 -0400 Subject: [PATCH] manifold-sql changes - change usage of multiple service provider interfaces to a single SPI that is basically a simple dependency injection configuration point, much easier manage and override default behavior - other cleanup --- .../sql/rt/api/ConnectionNotifier.java | 45 --------- .../sql/rt/api/ConnectionProvider.java | 24 ----- .../manifold/sql/rt/api/CrudProvider.java | 32 ------- .../manifold/sql/rt/api/DbConfigProvider.java | 13 --- .../sql/rt/api/DbLocationProvider.java | 14 +-- .../manifold/sql/rt/api/Dependencies.java | 68 ++++++++++++++ .../main/java/manifold/sql/rt/api/Result.java | 3 +- .../main/java/manifold/sql/rt/api/Runner.java | 12 +-- .../manifold/sql/rt/api/TxScopeProvider.java | 37 +------- .../manifold/sql/rt/api/ValueAccessor.java | 50 +--------- .../sql/rt/api/ValueAccessorProvider.java | 22 +++++ .../sql/rt/config/DefaultDependencies.java | 82 +++++++++++++++++ .../BasicCrudProvider.java | 24 +++-- .../rt/{connection => impl}/BasicTxScope.java | 15 +-- .../BasicTxScopeProvider.java | 4 +- .../{connection => impl}/DbConfigFinder.java | 36 +------- .../rt/{connection => impl}/DbConfigImpl.java | 3 +- .../DefaultTxScopeProvider.java | 6 +- .../HikariConnectionProvider.java | 17 +++- .../ResourceDbLocationProvider.java | 2 +- .../accessors}/ArrayValueAccessor.java | 2 +- .../accessors}/BigIntValueAccessor.java | 2 +- .../accessors}/BinaryValueAccessor.java | 2 +- .../accessors}/BitValueAccessor.java | 2 +- .../accessors}/BlobValueAccessor.java | 2 +- .../accessors}/BooleanValueAccessor.java | 2 +- .../accessors}/CharValueAccessor.java | 2 +- .../accessors}/ClobValueAccessor.java | 2 +- .../accessors}/DataLinkValueAccessor.java | 2 +- .../accessors}/DateValueAccessor.java | 2 +- .../accessors}/DecimalValueAccessor.java | 2 +- .../DefaultValueAccessorProvider.java | 91 +++++++++++++++++++ .../accessors}/DoubleValueAccessor.java | 2 +- .../accessors}/FloatValueAccessor.java | 2 +- .../accessors}/IntegerValueAccessor.java | 2 +- .../accessors}/LongNvarcharValueAccessor.java | 2 +- .../LongVarBinaryValueAccessor.java | 2 +- .../accessors}/LongVarcharValueAccessor.java | 2 +- .../accessors}/NcharValueAccessor.java | 2 +- .../accessors}/NclobValueAccessor.java | 2 +- .../accessors}/NumericValueAccessor.java | 2 +- .../accessors}/NvarcharValueAccessor.java | 2 +- .../accessors}/OtherValueAccessor.java | 2 +- .../accessors}/RealValueAccessor.java | 2 +- .../accessors}/RowIdValueAccessor.java | 2 +- .../accessors}/SmallIntValueAccessor.java | 2 +- .../accessors}/SqlXmlValueAccessor.java | 2 +- .../accessors}/TimeValueAccessor.java | 2 +- .../TimeWithTimeZoneValueAccessor.java | 2 +- .../accessors}/TimestampValueAccessor.java | 2 +- .../TimestampWithTimeZoneValueAccessor.java | 2 +- .../accessors}/TinyIntValueAccessor.java | 2 +- .../accessors}/VarBinaryValueAccessor.java | 2 +- .../accessors}/VarcharValueAccessor.java | 2 +- .../PropertyExpressionProcessor.java | 8 +- .../{connection => util}/SqlScriptParser.java | 2 +- .../manifold.sql.rt.api.ConnectionProvider | 1 - .../services/manifold.sql.rt.api.CrudProvider | 1 - .../manifold.sql.rt.api.DbLocationProvider | 1 - .../services/manifold.sql.rt.api.Dependencies | 1 + .../manifold.sql.rt.api.TxScopeProvider | 1 - .../manifold.sql.rt.api.ValueAccessor | 33 ------- .../test/java/manifold/sql/BaseDbTest.java | 11 +-- .../test/java/manifold/sql/schema/H2JDBC.java | 5 - .../java/manifold/sql/schema/SQLiteJDBC.java | 2 +- .../java/manifold/sql/scripts/RunDdl.java | 2 +- .../java/manifold/sql/api/DataElement.java | 3 +- .../sql/query/jdbc/JdbcQueryTable.java | 10 +- .../sql/query/type/SqlParentType.java | 4 +- .../manifold/sql/query/type/SqlScope.java | 2 +- .../schema/jdbc/ConnectionProviderCloser.java | 5 +- .../manifold/sql/schema/jdbc/JdbcSchema.java | 9 +- .../schema/jdbc/oneoff/SqliteTypeMapping.java | 13 +-- .../sql/schema/type/SchemaManifold.java | 2 +- .../manifold/sql/schema/type/SchemaModel.java | 6 +- .../sql/schema/type/SchemaParentType.java | 14 +-- 76 files changed, 393 insertions(+), 409 deletions(-) delete mode 100644 manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/ConnectionNotifier.java create mode 100644 manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/Dependencies.java create mode 100644 manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/ValueAccessorProvider.java create mode 100644 manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/config/DefaultDependencies.java rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{connection => impl}/BasicCrudProvider.java (92%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{connection => impl}/BasicTxScope.java (94%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{connection => impl}/BasicTxScopeProvider.java (89%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{connection => impl}/DbConfigFinder.java (80%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{connection => impl}/DbConfigImpl.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{connection => impl}/DefaultTxScopeProvider.java (91%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{connection => impl}/HikariConnectionProvider.java (81%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{connection => impl}/ResourceDbLocationProvider.java (99%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/ArrayValueAccessor.java (99%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/BigIntValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/BinaryValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/BitValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/BlobValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/BooleanValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/CharValueAccessor.java (95%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/ClobValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/DataLinkValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/DateValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/DecimalValueAccessor.java (97%) create mode 100644 manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/DefaultValueAccessorProvider.java rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/DoubleValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/FloatValueAccessor.java (95%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/IntegerValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/LongNvarcharValueAccessor.java (95%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/LongVarBinaryValueAccessor.java (95%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/LongVarcharValueAccessor.java (95%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/NcharValueAccessor.java (95%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/NclobValueAccessor.java (95%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/NumericValueAccessor.java (95%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/NvarcharValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/OtherValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/RealValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/RowIdValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/SmallIntValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/SqlXmlValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/TimeValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/TimeWithTimeZoneValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/TimestampValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/TimestampWithTimeZoneValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/TinyIntValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/VarBinaryValueAccessor.java (95%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{jdbc => impl/accessors}/VarcharValueAccessor.java (97%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{connection => util}/PropertyExpressionProcessor.java (93%) rename manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/{connection => util}/SqlScriptParser.java (99%) delete mode 100644 manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.ConnectionProvider delete mode 100644 manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.CrudProvider delete mode 100644 manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.DbLocationProvider create mode 100644 manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.Dependencies delete mode 100644 manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.TxScopeProvider delete mode 100644 manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.ValueAccessor diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/ConnectionNotifier.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/ConnectionNotifier.java deleted file mode 100644 index 58a6c8e88..000000000 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/ConnectionNotifier.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2023 - Manifold Systems LLC - * - * 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. - */ - -package manifold.sql.rt.api; - -import manifold.rt.api.util.ServiceUtil; -import manifold.util.concurrent.LocklessLazyVar; - -import java.sql.Connection; -import java.util.HashSet; -import java.util.Set; - -/** - * Notifies implementors immediately after a JDBC connection is established. Useful for testing, debugging, and connection - * related environment setup. - *

- * Note, implement {@link manifold.sql.rt.api.ConnectionProvider} to control the Connection itself. - */ -public interface ConnectionNotifier -{ - LocklessLazyVar> PROVIDERS = - LocklessLazyVar.make( () -> { - Set registered = new HashSet<>(); - ServiceUtil.loadRegisteredServices( registered, ConnectionNotifier.class, ConnectionNotifier.class.getClassLoader() ); - return registered; - } ); - - /** - * Invoked immediately after a JDBC connection is established. - */ - void init( Connection c ); -} diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/ConnectionProvider.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/ConnectionProvider.java index 2463f4823..b6cf1fa64 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/ConnectionProvider.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/ConnectionProvider.java @@ -16,38 +16,14 @@ package manifold.sql.rt.api; -import manifold.rt.api.util.ServiceUtil; -import manifold.util.concurrent.LocklessLazyVar; - import java.sql.Connection; -import java.sql.Driver; import java.sql.SQLException; -import java.util.HashSet; -import java.util.Set; /** * Implementors provide JDBC connections for all manifold-sql JDBC operations. */ public interface ConnectionProvider { - LocklessLazyVar> PROVIDERS = - LocklessLazyVar.make( () -> { - // first, ensure jdbc drivers are loaded - Set drivers = new HashSet<>(); - ServiceUtil.loadRegisteredServices( drivers, Driver.class, ConnectionProvider.class.getClassLoader() ); - - Set registered = new HashSet<>(); - ServiceUtil.loadRegisteredServices( registered, ConnectionProvider.class, ConnectionProvider.class.getClassLoader() ); - return registered; - } ); - - static ConnectionProvider findFirst() - { - return ConnectionProvider.PROVIDERS.get().stream() - .findFirst() - .orElseThrow( () -> new RuntimeException( "Could not find SQL connection provider" ) ); - } - /** * Provides a JDBC connection corresponding with the {@code configName} {@link DbConfig} and optional {@code classContext}. * A standard implementation sources the {@code configName} DbConfig in the following order: diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/CrudProvider.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/CrudProvider.java index 0fd4acb89..b52ed47f1 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/CrudProvider.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/CrudProvider.java @@ -16,44 +16,12 @@ package manifold.sql.rt.api; -import manifold.rt.api.util.ServiceUtil; -import manifold.util.concurrent.LocklessLazyVar; - import java.sql.Connection; -import java.util.*; -import java.util.function.Supplier; public interface CrudProvider { - LocklessLazyVar> PROVIDERS = - LocklessLazyVar.make( () -> { - Set registered = new HashSet<>(); - ServiceUtil.loadRegisteredServices( registered, CrudProvider.class, CrudProvider.class.getClassLoader() ); - return registered; - } ); - - LocklessLazyVar BY_PRIORITY = - LocklessLazyVar.make( () -> - PROVIDERS.get().stream().max( Comparator.comparingInt( CrudProvider::getPriority ) ) - .orElseThrow( () -> new IllegalStateException() ) ); - - static CrudProvider instance() - { - return BY_PRIORITY.get(); - } - - void create( Connection c, UpdateContext ctx ); T read( QueryContext ctx ); void update( Connection c, UpdateContext ctx ); void delete( Connection c, UpdateContext ctx ); - - /** - * Greater = higher priority. Higher priority overrides lower. Default implementations are lowest priority. They can be - * overridden. - */ - default int getPriority() - { - return Integer.MIN_VALUE; - } } diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/DbConfigProvider.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/DbConfigProvider.java index b7660e992..99e9d2cb0 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/DbConfigProvider.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/DbConfigProvider.java @@ -16,20 +16,7 @@ package manifold.sql.rt.api; -import manifold.rt.api.util.ServiceUtil; -import manifold.util.concurrent.LocklessLazyVar; - -import java.util.HashSet; -import java.util.Set; - public interface DbConfigProvider { - LocklessLazyVar> PROVIDERS = - LocklessLazyVar.make( () -> { - Set registered = new HashSet<>(); - ServiceUtil.loadRegisteredServices( registered, DbConfigProvider.class, DbConfigProvider.class.getClassLoader() ); - return registered; - } ); - DbConfig loadDbConfig( String configName, Class ctx ); } diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/DbLocationProvider.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/DbLocationProvider.java index 4cc8b4993..84d5facc8 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/DbLocationProvider.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/DbLocationProvider.java @@ -18,25 +18,17 @@ import manifold.api.fs.IFile; import manifold.api.util.cache.FqnCache; -import manifold.rt.api.util.ServiceUtil; -import manifold.util.concurrent.LocklessLazyVar; -import java.util.HashSet; -import java.util.Set; import java.util.function.Function; +/** + * Note, implementers must chain/forward to the default provider to fall back on existing behavior. + */ public interface DbLocationProvider { String PROVIDED = "#"; Object UNHANDLED = new Object() {}; - LocklessLazyVar> PROVIDERS = - LocklessLazyVar.make( () -> { - Set registered = new HashSet<>(); - ServiceUtil.loadRegisteredServices( registered, DbLocationProvider.class, DbLocationProvider.class.getClassLoader() ); - return registered; - } ); - enum Mode {CompileTime, DesignTime, Runtime, Unknown} Object getLocation( Function> resByExt, Mode mode, String tag, String... args ); diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/Dependencies.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/Dependencies.java new file mode 100644 index 000000000..b1e927bab --- /dev/null +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/Dependencies.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2023 - Manifold Systems LLC + * + * 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. + */ + +package manifold.sql.rt.api; + +import manifold.rt.api.util.ServiceUtil; +import manifold.sql.rt.config.DefaultDependencies; +import manifold.util.concurrent.LocklessLazyVar; + +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Set; + +public interface Dependencies +{ + LocklessLazyVar> PROVIDERS = + LocklessLazyVar.make( () -> { + Set registered = new LinkedHashSet<>(); + ServiceUtil.loadRegisteredServices( registered, Dependencies.class, Dependencies.class.getClassLoader() ); + return registered; + } ); + + static Dependencies instance() + { + if( PROVIDERS.get().isEmpty() ) + { + throw new RuntimeException( "Could not find Dependencies service provider" ); + } + + Dependencies result = null; + for( Dependencies dependencies : PROVIDERS.get() ) + { + // favor non-default dependencies + if( result == null || result instanceof DefaultDependencies ) + { + result = dependencies; + } + } + return result; + } + + DbConfigProvider getDbConfigProvider(); + + ConnectionProvider getConnectionProvider(); + + CrudProvider getCrudProvider(); + + DbLocationProvider getDbLocationProvider(); + + TxScopeProvider getTxScopeProvider(); + + ValueAccessorProvider getValueAccessorProvider(); + + T fetch( Class cls ); +} diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/Result.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/Result.java index bdcc3b80a..fba6b86bd 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/Result.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/Result.java @@ -56,10 +56,11 @@ private void rip( ResultSet resultSet, Function ctx, String sqlQuery ) @SuppressWarnings( "unused" ) public Result run() { - ConnectionProvider cp = ConnectionProvider.findFirst(); + ConnectionProvider cp = Dependencies.instance().getConnectionProvider(); try( Connection c = cp.getConnection( _ctx.getConfigName(), _ctx.getQueryClass() ) ) { - for( ConnectionNotifier p : ConnectionNotifier.PROVIDERS.get() ) - { - p.init( c ); - } - try( PreparedStatement ps = c.prepareStatement( _sqlQuery ) ) { setParameters( ps ); try( ResultSet resultSet = ps.executeQuery() ) { - return new Result( _ctx.getTxScope(), resultSet, _ctx.getRowMaker() ); + return new Result<>( _ctx.getTxScope(), resultSet, _ctx.getRowMaker() ); } } } @@ -60,9 +55,10 @@ public Result run() private void setParameters( PreparedStatement ps ) throws SQLException { int i = 0; + ValueAccessorProvider accProvider = Dependencies.instance().getValueAccessorProvider(); for( Object param : _ctx.getParams().values() ) { - ValueAccessor accessor = ValueAccessor.get( _ctx.getJdbcParamTypes()[i] ); + ValueAccessor accessor = accProvider.get( _ctx.getJdbcParamTypes()[i] ); accessor.setParameter( ps, ++i, param ); } } diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/TxScopeProvider.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/TxScopeProvider.java index 2a19d376a..43316a881 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/TxScopeProvider.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/TxScopeProvider.java @@ -16,42 +16,7 @@ package manifold.sql.rt.api; -import manifold.rt.api.util.ServiceUtil; -import manifold.util.concurrent.LocklessLazyVar; - -import java.util.Comparator; -import java.util.HashSet; -import java.util.Set; - public interface TxScopeProvider { - LocklessLazyVar> PROVIDERS = - LocklessLazyVar.make( () -> { - Set registered = new HashSet<>(); - ServiceUtil.loadRegisteredServices( registered, TxScopeProvider.class, TxScopeProvider.class.getClassLoader() ); - return registered; - } ); - - LocklessLazyVar BY_PRIORITY = - LocklessLazyVar.make( () -> - PROVIDERS.get().stream().max( Comparator.comparingInt( TxScopeProvider::getPriority ) ) - .orElseThrow( () -> new IllegalStateException( "No " + TxScopeProvider.class.getSimpleName() + "'s found." ) ) ); - - static TxScope newScope( Class schemaClass ) - { - return BY_PRIORITY.get().create( schemaClass ); - } - - - TxScope create( Class schemaClass ); - - - /** - * Greater = higher priority. Higher priority overrides lower. Default implementations are lowest priority. They can be - * overridden. - */ - default int getPriority() - { - return Integer.MIN_VALUE; - } + TxScope newScope( Class schemaClass ); } diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/ValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/ValueAccessor.java index 29dba775d..c93a5bc51 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/ValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/ValueAccessor.java @@ -16,23 +16,13 @@ package manifold.sql.rt.api; -import manifold.rt.api.util.ServiceUtil; -import manifold.util.concurrent.LocklessLazyVar; - import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; /** - * Each implementation of this interface handles a JDBC type from {@link java.sql.Types} and must be registered as a Java - * Service Provider. The value returned from {@link #getJdbcType()} indicates the JDBC type handled by the SPI implementation. - * Manifold provides default implementations that are suitable for most use-cases, however these implementations can be - * overridden by custom implementations, a higher priority from {@link #getPriority()} overrides lower priority implementations. - * All Manifold implementations default to the lowest priority. + * The value returned from {@link #getJdbcType()} indicates the JDBC type handled by the implementation. + * Manifold provides default implementations that are suitable for most use-cases. *

* This interface performs the following:
* - resolves the Java type corresponding with the JDBC type from {@link java.sql.Types}
@@ -42,47 +32,11 @@ */ public interface ValueAccessor { - LocklessLazyVar> ACCESSORS = - LocklessLazyVar.make( () -> { - Set registered = new HashSet<>(); - ServiceUtil.loadRegisteredServices( registered, ValueAccessor.class, ValueAccessor.class.getClassLoader() ); - return registered; - } ); - - LocklessLazyVar> BY_JDBC_TYPE = - LocklessLazyVar.make( () -> { - Map map = new HashMap<>(); - for( ValueAccessor acc : ACCESSORS.get() ) - { - int jdbcType = acc.getJdbcType(); - ValueAccessor existing = map.get( jdbcType ); - if( existing == null || existing.getPriority() < acc.getPriority() ) - { - map.put( jdbcType, acc ); - } - } - return map; - } ); - - static ValueAccessor get( int jdbcType ) - { - return BY_JDBC_TYPE.get().get( jdbcType ); - } - /** * @return The {@link java.sql.Types} id this accessor handles. */ int getJdbcType(); - /** - * Greater = higher priority. Higher priority overrides lower. Default implementations are lowest priority. They can be - * overridden. - */ - default int getPriority() - { - return Integer.MIN_VALUE; - } - /** * @return The resulting type of the value in Java code. Note this type may not correspond with SQL-to-Java type mappings * from the JDBC specification. For instance, although {@code java.sql.Types#CLOB} maps to {@code java.sql.CLOB} (appendix diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/ValueAccessorProvider.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/ValueAccessorProvider.java new file mode 100644 index 000000000..27a06bc02 --- /dev/null +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/ValueAccessorProvider.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 - Manifold Systems LLC + * + * 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. + */ + +package manifold.sql.rt.api; + +public interface ValueAccessorProvider +{ + ValueAccessor get( int jdbcType ); +} diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/config/DefaultDependencies.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/config/DefaultDependencies.java new file mode 100644 index 000000000..62df79da7 --- /dev/null +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/config/DefaultDependencies.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2023 - Manifold Systems LLC + * + * 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. + */ + +package manifold.sql.rt.config; + +import manifold.sql.rt.api.*; +import manifold.sql.rt.impl.accessors.DefaultValueAccessorProvider; +import manifold.sql.rt.impl.*; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class DefaultDependencies implements Dependencies +{ + private final Map, Object> _instances = new ConcurrentHashMap<>(); + + @Override + public DbConfigProvider getDbConfigProvider() + { + // loads config from .dbconfig file + return fetch( DbConfigFinder.class ); + } + + @Override + public ConnectionProvider getConnectionProvider() + { + return fetch( HikariConnectionProvider.class ); + } + + @Override + public CrudProvider getCrudProvider() + { + return fetch( BasicCrudProvider.class ); + } + + @Override + public DbLocationProvider getDbLocationProvider() + { + return fetch( ResourceDbLocationProvider.class ); + } + + @Override + public TxScopeProvider getTxScopeProvider() + { + return fetch( BasicTxScopeProvider.class ); + } + + @Override + public ValueAccessorProvider getValueAccessorProvider() + { + return fetch( DefaultValueAccessorProvider.class ); + } + + public T fetch( Class cls ) + { + //noinspection unchecked + return (T)_instances + .computeIfAbsent( cls, __ -> { + try + { + return cls.newInstance(); + } + catch( Exception e ) + { + throw new RuntimeException( e ); + } + } ); + } +} diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/BasicCrudProvider.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/BasicCrudProvider.java similarity index 92% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/BasicCrudProvider.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/BasicCrudProvider.java index 9278ed43b..7a6a78420 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/BasicCrudProvider.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/BasicCrudProvider.java @@ -14,10 +14,9 @@ * limitations under the License. */ -package manifold.sql.rt.connection; +package manifold.sql.rt.impl; import manifold.ext.rt.api.IBindingsBacked; -import manifold.rt.api.util.Pair; import manifold.sql.rt.api.*; import manifold.util.ManExceptionUtil; @@ -55,10 +54,11 @@ public void create( Connection c, UpdateContext ctx ) private void setInsertParameters( UpdateContext ctx, PreparedStatement ps ) throws SQLException { int i = 0; + ValueAccessorProvider accProvider = Dependencies.instance().getValueAccessorProvider(); for( Map.Entry entry: ctx.getTable().getBindings().entrySet() ) { int jdbcType = ctx.getAllColsWithJdbcType().get( entry.getKey() ); - ValueAccessor accessor = ValueAccessor.get( jdbcType ); + ValueAccessor accessor = accProvider.get( jdbcType ); Object value = entry.getValue(); value = patchFk( value, entry.getKey(), ctx.getTable().getBindings() ); accessor.setParameter( ps, ++i, value ); @@ -120,14 +120,9 @@ private String makeInsertStmt( String ddlTableName, TableRow table ) @SuppressWarnings( "unused" ) public T read( QueryContext ctx ) { - ConnectionProvider cp = ConnectionProvider.findFirst(); + ConnectionProvider cp = Dependencies.instance().getConnectionProvider(); try( Connection c = cp.getConnection( ctx.getConfigName(), ctx.getQueryClass() ) ) { - for( ConnectionNotifier p : ConnectionNotifier.PROVIDERS.get() ) - { - p.init( c ); - } - // todo: put a cache on this String sql = makeReadStatement( ctx ); @@ -253,9 +248,10 @@ private void setUpdateParameters( UpdateContext ctx, Set { throw new SQLException( "Expecting changed entries." ); } + ValueAccessorProvider accProvider = Dependencies.instance().getValueAccessorProvider(); for( Map.Entry entry : changeEntries ) { - ValueAccessor accessor = ValueAccessor.get( ctx.getAllColsWithJdbcType().get( entry.getKey() ) ); + ValueAccessor accessor = accProvider.get( ctx.getAllColsWithJdbcType().get( entry.getKey() ) ); Object value = entry.getValue(); accessor.setParameter( ps, ++paramIndex, value ); } @@ -263,7 +259,7 @@ private void setUpdateParameters( UpdateContext ctx, Set { for( String whereColumn : whereColumns ) { - ValueAccessor accessor = ValueAccessor.get( ctx.getAllColsWithJdbcType().get( whereColumn ) ); + ValueAccessor accessor = accProvider.get( ctx.getAllColsWithJdbcType().get( whereColumn ) ); Object value = ctx.getTable().getBindings().getPersistedStateValue( whereColumn ); accessor.setParameter( ps, ++paramIndex, value ); } @@ -280,9 +276,10 @@ private void setDeleteParameters( UpdateContext ctx, Set int paramIndex = 0; if( !whereColumns.isEmpty() ) { + ValueAccessorProvider accProvider = Dependencies.instance().getValueAccessorProvider(); for( String whereColumn : whereColumns ) { - ValueAccessor accessor = ValueAccessor.get( ctx.getAllColsWithJdbcType().get( whereColumn ) ); + ValueAccessor accessor = accProvider.get( ctx.getAllColsWithJdbcType().get( whereColumn ) ); Object value = ctx.getTable().getBindings().getPersistedStateValue( whereColumn ); accessor.setParameter( ps, ++paramIndex, value ); } @@ -378,9 +375,10 @@ else if( !ctx.getUkCols().isEmpty() ) private void setQueryParameters( QueryContext ctx, PreparedStatement ps ) throws SQLException { int i = 0; + ValueAccessorProvider accProvider = Dependencies.instance().getValueAccessorProvider(); for( Object param : ctx.getParams().values() ) { - ValueAccessor accessor = ValueAccessor.get( ctx.getJdbcParamTypes()[i] ); + ValueAccessor accessor = accProvider.get( ctx.getJdbcParamTypes()[i] ); accessor.setParameter( ps, ++i, param ); } } diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/BasicTxScope.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/BasicTxScope.java similarity index 94% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/BasicTxScope.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/BasicTxScope.java index 479f64c1f..a1bd7e203 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/BasicTxScope.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/BasicTxScope.java @@ -14,10 +14,9 @@ * limitations under the License. */ -package manifold.sql.rt.connection; +package manifold.sql.rt.impl; import manifold.rt.api.util.ManClassUtil; -import manifold.rt.api.util.Pair; import manifold.sql.rt.api.*; import java.sql.Connection; @@ -35,7 +34,8 @@ class BasicTxScope implements OperableTxScope public BasicTxScope( Class schemaClass ) { - _dbConfig = DbConfigFinder.instance().findConfig( ManClassUtil.getShortClassName( schemaClass ), schemaClass ); + _dbConfig = Dependencies.instance().getDbConfigProvider() + .loadDbConfig( ManClassUtil.getShortClassName( schemaClass ), schemaClass ); _rows = new LinkedHashSet<>(); _lock = new ReentrantReadWriteLock(); } @@ -120,16 +120,11 @@ public boolean commit() throws SQLException TableRow first = _rows.stream().findFirst().get(); - ConnectionProvider cp = ConnectionProvider.findFirst(); + ConnectionProvider cp = Dependencies.instance().getConnectionProvider(); try( Connection c = cp.getConnection( getDbConfig().getName(), first.getClass() ) ) { try { - for( ConnectionNotifier p : ConnectionNotifier.PROVIDERS.get() ) - { - p.init( c ); - } - c.setAutoCommit( false ); Set visited = new HashSet<>(); @@ -178,7 +173,7 @@ private void doCrud( Connection c, TableRow row, Map> unres doFkDependenciesFirst( c, row, unresolvedDeps, visited ); - CrudProvider crud = CrudProvider.instance(); + CrudProvider crud = Dependencies.instance().getCrudProvider(); TableInfo ti = row.tableInfo(); UpdateContext ctx = new UpdateContext<>( this, row, ti.getDdlTableName(), _dbConfig.getName(), diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/BasicTxScopeProvider.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/BasicTxScopeProvider.java similarity index 89% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/BasicTxScopeProvider.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/BasicTxScopeProvider.java index 5eca41ff3..9173be15d 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/BasicTxScopeProvider.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/BasicTxScopeProvider.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.connection; +package manifold.sql.rt.impl; import manifold.sql.rt.api.SchemaType; import manifold.sql.rt.api.TxScope; @@ -23,7 +23,7 @@ public class BasicTxScopeProvider implements TxScopeProvider { @Override - public TxScope create( Class schemaClass ) + public TxScope newScope( Class schemaClass ) { return new BasicTxScope( schemaClass ); } diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/DbConfigFinder.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/DbConfigFinder.java similarity index 80% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/DbConfigFinder.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/DbConfigFinder.java index 8ca2b3d04..653226bcc 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/DbConfigFinder.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/DbConfigFinder.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.connection; +package manifold.sql.rt.impl; import manifold.json.rt.Json; import manifold.rt.api.Bindings; @@ -31,34 +31,21 @@ /** */ -public class DbConfigFinder +public class DbConfigFinder implements DbConfigProvider { public static final String DBCONFIG_EXT = ".dbconfig"; - private static DbConfigFinder INSTANCE; private final Map _configs; - public static DbConfigFinder instance() - { - return INSTANCE == null ? INSTANCE = new DbConfigFinder() : INSTANCE; - } - - private DbConfigFinder() + public DbConfigFinder() { _configs = new LinkedHashMap<>(); } - DbConfig findConfig( String configName, Class ctx ) + public DbConfig loadDbConfig( String configName, Class ctx ) { return _configs.computeIfAbsent( configName, __ -> { - // DbConfigProviders have precedence - DbConfig dbConfig = loadConfigFromSpi( configName, ctx ); - if( dbConfig != null ) - { - return dbConfig; - } - - // Now try finding a *.dbconfig file + // find a *.dbconfig file Object module = JreUtil.isJava8() || ctx == null ? null : ReflectUtil.method( (Object)ctx, "getModule" ).invoke(); @@ -70,19 +57,6 @@ DbConfig findConfig( String configName, Class ctx ) } ); } - private static DbConfig loadConfigFromSpi( String configName, Class ctx ) - { - for( DbConfigProvider provider : DbConfigProvider.PROVIDERS.get() ) - { - DbConfig dbConfig = provider.loadDbConfig( configName, ctx ); - if( dbConfig != null ) - { - return dbConfig; - } - } - return null; - } - private static DbConfig findConfig( String module, String configName, Class ctx ) { InputStream stream = findConfigInCurrentDir( configName ); diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/DbConfigImpl.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/DbConfigImpl.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/DbConfigImpl.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/DbConfigImpl.java index 77c7fdb72..7579155f8 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/DbConfigImpl.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/DbConfigImpl.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.connection; +package manifold.sql.rt.impl; import manifold.api.fs.IFile; import manifold.api.util.cache.FqnCache; @@ -22,6 +22,7 @@ import manifold.rt.api.Bindings; import manifold.sql.rt.api.DbConfig; import manifold.sql.rt.api.DbLocationProvider.Mode; +import manifold.sql.rt.util.PropertyExpressionProcessor; import java.util.function.Function; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/DefaultTxScopeProvider.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/DefaultTxScopeProvider.java similarity index 91% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/DefaultTxScopeProvider.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/DefaultTxScopeProvider.java index 767b59ff1..f0e8da149 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/DefaultTxScopeProvider.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/DefaultTxScopeProvider.java @@ -14,11 +14,11 @@ * limitations under the License. */ -package manifold.sql.rt.connection; +package manifold.sql.rt.impl; +import manifold.sql.rt.api.Dependencies; import manifold.sql.rt.api.SchemaType; import manifold.sql.rt.api.TxScope; -import manifold.sql.rt.api.TxScopeProvider; import java.util.LinkedHashMap; import java.util.Map; @@ -49,7 +49,7 @@ public TxScope defaultScope( Class schemaClass ) TxScope defaultScope = defaultScopes.get( schemaClass ); if( defaultScope == null ) { - defaultScope = TxScopeProvider.newScope( schemaClass ); + defaultScope = Dependencies.instance().getTxScopeProvider().newScope( schemaClass ); defaultScopes.put( schemaClass, defaultScope ); } return defaultScope; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/HikariConnectionProvider.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/HikariConnectionProvider.java similarity index 81% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/HikariConnectionProvider.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/HikariConnectionProvider.java index c1da41405..79816ebba 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/HikariConnectionProvider.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/HikariConnectionProvider.java @@ -14,29 +14,42 @@ * limitations under the License. */ -package manifold.sql.rt.connection; +package manifold.sql.rt.impl; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; +import manifold.rt.api.util.ServiceUtil; import manifold.sql.rt.api.ConnectionProvider; import manifold.sql.rt.api.DbConfig; +import manifold.sql.rt.api.Dependencies; import manifold.util.ManExceptionUtil; +import manifold.util.concurrent.LocklessLazyVar; import java.sql.Connection; +import java.sql.Driver; import java.sql.SQLException; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; public class HikariConnectionProvider implements ConnectionProvider { private final Map _dataSources = new ConcurrentHashMap<>(); + public HikariConnectionProvider() + { + // ensure jdbc drivers are loaded + Set drivers = new HashSet<>(); + ServiceUtil.loadRegisteredServices( drivers, Driver.class, ConnectionProvider.class.getClassLoader() ); + } + @Override public Connection getConnection( String configName, Class classContext ) { //noinspection resource HikariDataSource ds = _dataSources.computeIfAbsent( configName, __ -> { - DbConfig dbConfig = DbConfigFinder.instance().findConfig( configName, classContext ); + DbConfig dbConfig = Dependencies.instance().getDbConfigProvider().loadDbConfig( configName, classContext ); if( dbConfig == null ) { throw ManExceptionUtil.unchecked( diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/ResourceDbLocationProvider.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/ResourceDbLocationProvider.java similarity index 99% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/ResourceDbLocationProvider.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/ResourceDbLocationProvider.java index 5d190e4a1..99cfd23ec 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/ResourceDbLocationProvider.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/ResourceDbLocationProvider.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.connection; +package manifold.sql.rt.impl; import manifold.api.fs.IFile; import manifold.api.util.cache.FqnCache; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/ArrayValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/ArrayValueAccessor.java similarity index 99% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/ArrayValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/ArrayValueAccessor.java index e2627d4dd..9ca940ab0 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/ArrayValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/ArrayValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/BigIntValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/BigIntValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/BigIntValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/BigIntValueAccessor.java index 097d329da..4da00724a 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/BigIntValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/BigIntValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/BinaryValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/BinaryValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/BinaryValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/BinaryValueAccessor.java index d46eb08cc..21c89a4c2 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/BinaryValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/BinaryValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/BitValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/BitValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/BitValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/BitValueAccessor.java index d4afc8bb1..b7a09c7c3 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/BitValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/BitValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/BlobValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/BlobValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/BlobValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/BlobValueAccessor.java index 0ae8be8e1..ffab0f46a 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/BlobValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/BlobValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/BooleanValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/BooleanValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/BooleanValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/BooleanValueAccessor.java index fd522446c..5fb43755d 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/BooleanValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/BooleanValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/CharValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/CharValueAccessor.java similarity index 95% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/CharValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/CharValueAccessor.java index 238f2f914..b7fc2bc3e 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/CharValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/CharValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import java.sql.Types; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/ClobValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/ClobValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/ClobValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/ClobValueAccessor.java index db82b5cf4..0536fde43 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/ClobValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/ClobValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/DataLinkValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/DataLinkValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/DataLinkValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/DataLinkValueAccessor.java index ef747561a..29d9b4237 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/DataLinkValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/DataLinkValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/DateValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/DateValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/DateValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/DateValueAccessor.java index 4642b2184..dd5368d06 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/DateValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/DateValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/DecimalValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/DecimalValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/DecimalValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/DecimalValueAccessor.java index 71874c211..1b66ae223 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/DecimalValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/DecimalValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/DefaultValueAccessorProvider.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/DefaultValueAccessorProvider.java new file mode 100644 index 000000000..60400bf18 --- /dev/null +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/DefaultValueAccessorProvider.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2023 - Manifold Systems LLC + * + * 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. + */ + +package manifold.sql.rt.impl.accessors; + +import manifold.sql.rt.api.ValueAccessor; +import manifold.sql.rt.api.ValueAccessorProvider; +import manifold.util.concurrent.LocklessLazyVar; + +import java.util.LinkedHashMap; +import java.util.Map; + +public class DefaultValueAccessorProvider implements ValueAccessorProvider +{ + private final LocklessLazyVar> _byJdbcType = + LocklessLazyVar.make( () -> { + LinkedHashMap map = new LinkedHashMap<>(); + for( Class accClass : getAll() ) + { + try + { + ValueAccessor acc = accClass.newInstance(); + int jdbcType = acc.getJdbcType(); + map.put( jdbcType, acc ); + } + catch( Exception e ) + { + throw new RuntimeException( e ); + } + } + return map; + } ); + + public Class[] getAll() + { + return new Class[]{ + ArrayValueAccessor.class, + BinaryValueAccessor.class, + BitValueAccessor.class, + BlobValueAccessor.class, + BooleanValueAccessor.class, + CharValueAccessor.class, + ClobValueAccessor.class, + DataLinkValueAccessor.class, + DateValueAccessor.class, + DecimalValueAccessor.class, + DoubleValueAccessor.class, + FloatValueAccessor.class, + IntegerValueAccessor.class, + LongNvarcharValueAccessor.class, + BigIntValueAccessor.class, + LongVarBinaryValueAccessor.class, + LongVarcharValueAccessor.class, + NcharValueAccessor.class, + NclobValueAccessor.class, + NumericValueAccessor.class, + NvarcharValueAccessor.class, + OtherValueAccessor.class, + RealValueAccessor.class, + RowIdValueAccessor.class, + SmallIntValueAccessor.class, + SqlXmlValueAccessor.class, + TimestampValueAccessor.class, + TimestampWithTimeZoneValueAccessor.class, + TimeValueAccessor.class, + TimeWithTimeZoneValueAccessor.class, + TinyIntValueAccessor.class, + VarBinaryValueAccessor.class, + VarcharValueAccessor.class + }; + } + + @Override + public ValueAccessor get( int jdbcType ) + { + return _byJdbcType.get().get( jdbcType ); + } +} diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/DoubleValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/DoubleValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/DoubleValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/DoubleValueAccessor.java index c929d37e5..cc34dc0e6 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/DoubleValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/DoubleValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/FloatValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/FloatValueAccessor.java similarity index 95% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/FloatValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/FloatValueAccessor.java index 76612248d..55331710c 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/FloatValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/FloatValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import java.sql.Types; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/IntegerValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/IntegerValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/IntegerValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/IntegerValueAccessor.java index 2a8ebc3c6..df976ceab 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/IntegerValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/IntegerValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/LongNvarcharValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/LongNvarcharValueAccessor.java similarity index 95% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/LongNvarcharValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/LongNvarcharValueAccessor.java index 3b545dd3e..e822d1bdc 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/LongNvarcharValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/LongNvarcharValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import java.sql.Types; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/LongVarBinaryValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/LongVarBinaryValueAccessor.java similarity index 95% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/LongVarBinaryValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/LongVarBinaryValueAccessor.java index 2a783c60c..b55fa9fdc 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/LongVarBinaryValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/LongVarBinaryValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import java.sql.Types; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/LongVarcharValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/LongVarcharValueAccessor.java similarity index 95% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/LongVarcharValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/LongVarcharValueAccessor.java index 9054bfc5e..4574a93cc 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/LongVarcharValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/LongVarcharValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import java.sql.Types; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/NcharValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/NcharValueAccessor.java similarity index 95% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/NcharValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/NcharValueAccessor.java index 0665cce45..861925445 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/NcharValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/NcharValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import java.sql.Types; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/NclobValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/NclobValueAccessor.java similarity index 95% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/NclobValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/NclobValueAccessor.java index 1f40844fa..1832d7b0a 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/NclobValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/NclobValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import java.sql.*; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/NumericValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/NumericValueAccessor.java similarity index 95% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/NumericValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/NumericValueAccessor.java index 80f8dd45d..ae28aa322 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/NumericValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/NumericValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import java.sql.Types; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/NvarcharValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/NvarcharValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/NvarcharValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/NvarcharValueAccessor.java index 9880cf3a5..ee0a872f7 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/NvarcharValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/NvarcharValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/OtherValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/OtherValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/OtherValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/OtherValueAccessor.java index 18e3f3b12..51df8fc40 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/OtherValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/OtherValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/RealValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/RealValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/RealValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/RealValueAccessor.java index 694cfdf82..138ce3fd5 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/RealValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/RealValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/RowIdValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/RowIdValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/RowIdValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/RowIdValueAccessor.java index 10c765982..2b8630478 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/RowIdValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/RowIdValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/SmallIntValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/SmallIntValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/SmallIntValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/SmallIntValueAccessor.java index 04e172b09..e9707df92 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/SmallIntValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/SmallIntValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/SqlXmlValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/SqlXmlValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/SqlXmlValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/SqlXmlValueAccessor.java index f4955109e..ccaa64eb3 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/SqlXmlValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/SqlXmlValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/TimeValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/TimeValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/TimeValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/TimeValueAccessor.java index ed48900d4..e977e1cbe 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/TimeValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/TimeValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/TimeWithTimeZoneValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/TimeWithTimeZoneValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/TimeWithTimeZoneValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/TimeWithTimeZoneValueAccessor.java index a0b890de9..8fd2aa4b1 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/TimeWithTimeZoneValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/TimeWithTimeZoneValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/TimestampValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/TimestampValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/TimestampValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/TimestampValueAccessor.java index 12c9b6117..cc80c5c96 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/TimestampValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/TimestampValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/TimestampWithTimeZoneValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/TimestampWithTimeZoneValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/TimestampWithTimeZoneValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/TimestampWithTimeZoneValueAccessor.java index 7300622b4..4281113fa 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/TimestampWithTimeZoneValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/TimestampWithTimeZoneValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/TinyIntValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/TinyIntValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/TinyIntValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/TinyIntValueAccessor.java index 8d63110d3..e1dcfcf19 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/TinyIntValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/TinyIntValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/VarBinaryValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/VarBinaryValueAccessor.java similarity index 95% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/VarBinaryValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/VarBinaryValueAccessor.java index 8ee6ccc8b..77744d0d3 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/VarBinaryValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/VarBinaryValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import java.sql.Types; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/VarcharValueAccessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/VarcharValueAccessor.java similarity index 97% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/VarcharValueAccessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/VarcharValueAccessor.java index 0b8222aea..0aa9a5a52 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/jdbc/VarcharValueAccessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/impl/accessors/VarcharValueAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.jdbc; +package manifold.sql.rt.impl.accessors; import manifold.sql.rt.api.BaseElement; import manifold.sql.rt.api.ValueAccessor; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/PropertyExpressionProcessor.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/util/PropertyExpressionProcessor.java similarity index 93% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/PropertyExpressionProcessor.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/util/PropertyExpressionProcessor.java index 7a56aeedc..141c79be0 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/PropertyExpressionProcessor.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/util/PropertyExpressionProcessor.java @@ -14,12 +14,13 @@ * limitations under the License. */ -package manifold.sql.rt.connection; +package manifold.sql.rt.util; import manifold.api.fs.IFile; import manifold.api.util.cache.FqnCache; import manifold.sql.rt.api.DbLocationProvider; import manifold.sql.rt.api.DbLocationProvider.Mode; +import manifold.sql.rt.api.Dependencies; import java.util.ArrayList; import java.util.List; @@ -128,9 +129,10 @@ private static String evalProvided( Function> resByExt, args.add( arg ); } String[] argsArray = args.toArray( new String[0] ); - for( DbLocationProvider p : DbLocationProvider.PROVIDERS.get() ) + DbLocationProvider dbLocProvider = Dependencies.instance().getDbLocationProvider(); + if( dbLocProvider != null ) { - Object location = p.getLocation( resByExt, mode, tag, argsArray ); + Object location = dbLocProvider.getLocation( resByExt, mode, tag, argsArray ); if( location != UNHANDLED ) { return String.valueOf( location ); diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/SqlScriptParser.java b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/util/SqlScriptParser.java similarity index 99% rename from manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/SqlScriptParser.java rename to manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/util/SqlScriptParser.java index 18f9ce3b0..d054a9876 100644 --- a/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/connection/SqlScriptParser.java +++ b/manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/util/SqlScriptParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package manifold.sql.rt.connection; +package manifold.sql.rt.util; import java.util.ArrayList; import java.util.List; diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.ConnectionProvider b/manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.ConnectionProvider deleted file mode 100644 index 33583a6aa..000000000 --- a/manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.ConnectionProvider +++ /dev/null @@ -1 +0,0 @@ -manifold.sql.rt.connection.HikariConnectionProvider diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.CrudProvider b/manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.CrudProvider deleted file mode 100644 index ecc76e24b..000000000 --- a/manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.CrudProvider +++ /dev/null @@ -1 +0,0 @@ -manifold.sql.rt.connection.BasicCrudProvider diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.DbLocationProvider b/manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.DbLocationProvider deleted file mode 100644 index 7cd6373a7..000000000 --- a/manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.DbLocationProvider +++ /dev/null @@ -1 +0,0 @@ -manifold.sql.rt.connection.ResourceDbLocationProvider diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.Dependencies b/manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.Dependencies new file mode 100644 index 000000000..2749433d5 --- /dev/null +++ b/manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.Dependencies @@ -0,0 +1 @@ +manifold.sql.rt.config.DefaultDependencies diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.TxScopeProvider b/manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.TxScopeProvider deleted file mode 100644 index a88182bf2..000000000 --- a/manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.TxScopeProvider +++ /dev/null @@ -1 +0,0 @@ -manifold.sql.rt.connection.BasicTxScopeProvider diff --git a/manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.ValueAccessor b/manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.ValueAccessor deleted file mode 100644 index 257920c7f..000000000 --- a/manifold-deps-parent/manifold-sql-rt/src/main/resources/META-INF/services/manifold.sql.rt.api.ValueAccessor +++ /dev/null @@ -1,33 +0,0 @@ -manifold.sql.rt.jdbc.ArrayValueAccessor -manifold.sql.rt.jdbc.BinaryValueAccessor -manifold.sql.rt.jdbc.BitValueAccessor -manifold.sql.rt.jdbc.BlobValueAccessor -manifold.sql.rt.jdbc.BooleanValueAccessor -manifold.sql.rt.jdbc.CharValueAccessor -manifold.sql.rt.jdbc.ClobValueAccessor -manifold.sql.rt.jdbc.DataLinkValueAccessor -manifold.sql.rt.jdbc.DateValueAccessor -manifold.sql.rt.jdbc.DecimalValueAccessor -manifold.sql.rt.jdbc.DoubleValueAccessor -manifold.sql.rt.jdbc.FloatValueAccessor -manifold.sql.rt.jdbc.IntegerValueAccessor -manifold.sql.rt.jdbc.LongNvarcharValueAccessor -manifold.sql.rt.jdbc.BigIntValueAccessor -manifold.sql.rt.jdbc.LongVarBinaryValueAccessor -manifold.sql.rt.jdbc.LongVarcharValueAccessor -manifold.sql.rt.jdbc.NcharValueAccessor -manifold.sql.rt.jdbc.NclobValueAccessor -manifold.sql.rt.jdbc.NumericValueAccessor -manifold.sql.rt.jdbc.NvarcharValueAccessor -manifold.sql.rt.jdbc.OtherValueAccessor -manifold.sql.rt.jdbc.RealValueAccessor -manifold.sql.rt.jdbc.RowIdValueAccessor -manifold.sql.rt.jdbc.SmallIntValueAccessor -manifold.sql.rt.jdbc.SqlXmlValueAccessor -manifold.sql.rt.jdbc.TimestampValueAccessor -manifold.sql.rt.jdbc.TimestampWithTimeZoneValueAccessor -manifold.sql.rt.jdbc.TimeValueAccessor -manifold.sql.rt.jdbc.TimeWithTimeZoneValueAccessor -manifold.sql.rt.jdbc.TinyIntValueAccessor -manifold.sql.rt.jdbc.VarBinaryValueAccessor -manifold.sql.rt.jdbc.VarcharValueAccessor diff --git a/manifold-deps-parent/manifold-sql-test/src/test/java/manifold/sql/BaseDbTest.java b/manifold-deps-parent/manifold-sql-test/src/test/java/manifold/sql/BaseDbTest.java index 7a3eabd23..dbff0728f 100644 --- a/manifold-deps-parent/manifold-sql-test/src/test/java/manifold/sql/BaseDbTest.java +++ b/manifold-deps-parent/manifold-sql-test/src/test/java/manifold/sql/BaseDbTest.java @@ -17,8 +17,8 @@ package manifold.sql; import manifold.rt.api.util.StreamUtil; -import manifold.sql.rt.api.ConnectionProvider; -import manifold.sql.rt.connection.DefaultTxScopeProvider; +import manifold.sql.rt.api.Dependencies; +import manifold.sql.rt.impl.DefaultTxScopeProvider; import manifold.sql.schema.simple.ScratchTest; import java.io.File; @@ -54,9 +54,8 @@ void _setup( String db_resource ) void _cleanup( String db_resource ) throws InterruptedException { - // close db connections - ConnectionProvider.PROVIDERS.get().forEach( p -> p.closeAll() ); - ConnectionProvider.PROVIDERS.clear(); + // close and clear db connections + Dependencies.instance().getConnectionProvider().closeAll(); // clear default tx scopes DefaultTxScopeProvider.instance().clear(); @@ -72,7 +71,7 @@ void _cleanup( String db_resource ) throws InterruptedException Path path = Paths.get( file.toURI() ); while( !Files.notExists( path ) ) { - synchronized( this ) { wait( 100 ); }; + synchronized( this ) { wait( 100 ); } } } } diff --git a/manifold-deps-parent/manifold-sql-test/src/test/java/manifold/sql/schema/H2JDBC.java b/manifold-deps-parent/manifold-sql-test/src/test/java/manifold/sql/schema/H2JDBC.java index c56995a23..aaa27d7ee 100644 --- a/manifold-deps-parent/manifold-sql-test/src/test/java/manifold/sql/schema/H2JDBC.java +++ b/manifold-deps-parent/manifold-sql-test/src/test/java/manifold/sql/schema/H2JDBC.java @@ -16,14 +16,9 @@ package manifold.sql.schema; -import manifold.rt.api.util.StreamUtil; -import manifold.sql.rt.connection.SqlScriptParser; import manifold.util.ManExceptionUtil; -import java.io.InputStreamReader; -import java.io.Reader; import java.sql.*; -import java.util.List; public class H2JDBC { diff --git a/manifold-deps-parent/manifold-sql-test/src/test/java/manifold/sql/schema/SQLiteJDBC.java b/manifold-deps-parent/manifold-sql-test/src/test/java/manifold/sql/schema/SQLiteJDBC.java index 338a97358..a33eb5b85 100644 --- a/manifold-deps-parent/manifold-sql-test/src/test/java/manifold/sql/schema/SQLiteJDBC.java +++ b/manifold-deps-parent/manifold-sql-test/src/test/java/manifold/sql/schema/SQLiteJDBC.java @@ -17,7 +17,7 @@ package manifold.sql.schema; import manifold.rt.api.util.StreamUtil; -import manifold.sql.rt.connection.SqlScriptParser; +import manifold.sql.rt.util.SqlScriptParser; import manifold.util.ManExceptionUtil; import java.io.InputStreamReader; diff --git a/manifold-deps-parent/manifold-sql-test/src/test/java/manifold/sql/scripts/RunDdl.java b/manifold-deps-parent/manifold-sql-test/src/test/java/manifold/sql/scripts/RunDdl.java index 752d049ab..3c9330706 100644 --- a/manifold-deps-parent/manifold-sql-test/src/test/java/manifold/sql/scripts/RunDdl.java +++ b/manifold-deps-parent/manifold-sql-test/src/test/java/manifold/sql/scripts/RunDdl.java @@ -17,7 +17,7 @@ package manifold.sql.scripts; import manifold.rt.api.util.StreamUtil; -import manifold.sql.rt.connection.SqlScriptParser; +import manifold.sql.rt.util.SqlScriptParser; import manifold.util.ManExceptionUtil; import java.io.File; diff --git a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/api/DataElement.java b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/api/DataElement.java index 66daa3886..c1ebf44be 100644 --- a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/api/DataElement.java +++ b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/api/DataElement.java @@ -17,6 +17,7 @@ package manifold.sql.api; import manifold.sql.rt.api.BaseElement; +import manifold.sql.rt.api.Dependencies; import manifold.sql.rt.api.ValueAccessor; public interface DataElement extends BaseElement @@ -27,7 +28,7 @@ public interface DataElement extends BaseElement default Class getType() { - ValueAccessor accessor = ValueAccessor.get( getJdbcType() ); + ValueAccessor accessor = Dependencies.instance().getValueAccessorProvider().get( getJdbcType() ); return accessor == null ? null : accessor.getJavaType( this ); } } diff --git a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/query/jdbc/JdbcQueryTable.java b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/query/jdbc/JdbcQueryTable.java index a12aaeb45..a28547d6a 100644 --- a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/query/jdbc/JdbcQueryTable.java +++ b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/query/jdbc/JdbcQueryTable.java @@ -24,12 +24,11 @@ import manifold.sql.query.type.SqlIssueContainer; import manifold.sql.query.type.SqlScope; import manifold.sql.rt.api.ConnectionProvider; -import manifold.sql.rt.api.ConnectionNotifier; +import manifold.sql.rt.api.Dependencies; import manifold.sql.schema.api.Schema; import manifold.sql.schema.api.SchemaColumn; import manifold.sql.schema.api.SchemaForeignKey; import manifold.sql.schema.api.SchemaTable; -import manifold.util.ManExceptionUtil; import java.sql.*; import java.util.*; @@ -59,7 +58,7 @@ public JdbcQueryTable( SqlScope scope, String simpleName, String query ) return; } - ConnectionProvider cp = ConnectionProvider.findFirst(); + ConnectionProvider cp = Dependencies.instance().getConnectionProvider(); try( Connection c = cp.getConnection( scope.getDbconfig() ) ) { build( c, paramNames ); @@ -84,11 +83,6 @@ private static String replaceNamesWithQuestion( String source, List p private void build( Connection c, List paramNames ) throws SQLException { - for( ConnectionNotifier p : ConnectionNotifier.PROVIDERS.get() ) - { - p.init( c ); - } - try( PreparedStatement preparedStatement = c.prepareStatement( _source ) ) { // todo: handle warnings, make them compiler warnings diff --git a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/query/type/SqlParentType.java b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/query/type/SqlParentType.java index 87614c1bb..4268e0873 100644 --- a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/query/type/SqlParentType.java +++ b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/query/type/SqlParentType.java @@ -34,7 +34,7 @@ import manifold.sql.query.api.QueryParameter; import manifold.sql.query.api.QueryTable; import manifold.sql.rt.api.*; -import manifold.sql.rt.connection.DefaultTxScopeProvider; +import manifold.sql.rt.impl.DefaultTxScopeProvider; import manifold.sql.schema.api.SchemaTable; import javax.tools.DiagnosticListener; @@ -368,7 +368,7 @@ private void addFkFetcher( SrcLinkedClass srcClass, ForeignKeyQueryRef fkRef ) Column referencedCol = col.getSchemaColumn().getForeignKey(); sb.append( " paramBindings.put(\"${referencedCol.getName()}\", getBindings().get(${col.getName()}));\n" ); } - sb.append( " return CrudProvider.instance().read(new QueryContext<$tableFqn>(getBindings().getTxScope(), $tableFqn.class,\n" + + sb.append( " return ${Dependencies.class.getName()}.instance().getCrudProvider().read(new QueryContext<$tableFqn>(getBindings().getTxScope(), $tableFqn.class,\n" + "\"${table.getName()}\", $jdbcParamTypes, paramBindings, \"$configName\",\n" + "rowBindings -> new $tableFqn() {public TxBindings getBindings() { return rowBindings; }}));" ); fkFetchMethod.body( sb.toString() ); diff --git a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/query/type/SqlScope.java b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/query/type/SqlScope.java index 312112503..bd0bc691a 100644 --- a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/query/type/SqlScope.java +++ b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/query/type/SqlScope.java @@ -22,7 +22,7 @@ import manifold.api.type.ITypeManifold; import manifold.internal.javac.IIssue; import manifold.sql.rt.api.DbConfig; -import manifold.sql.rt.connection.DbConfigImpl; +import manifold.sql.rt.impl.DbConfigImpl; import manifold.sql.schema.api.Schema; import manifold.sql.schema.type.SchemaIssueContainer; import manifold.sql.schema.type.SchemaManifold; diff --git a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/jdbc/ConnectionProviderCloser.java b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/jdbc/ConnectionProviderCloser.java index 8545a03ae..c711e0156 100644 --- a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/jdbc/ConnectionProviderCloser.java +++ b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/jdbc/ConnectionProviderCloser.java @@ -17,14 +17,13 @@ package manifold.sql.schema.jdbc; import manifold.internal.javac.IFinishedCompilingListener; -import manifold.sql.rt.api.ConnectionProvider; +import manifold.sql.rt.api.Dependencies; public class ConnectionProviderCloser implements IFinishedCompilingListener { @Override public void closing() { - ConnectionProvider.PROVIDERS.get().forEach( p -> p.closeAll() ); - ConnectionProvider.PROVIDERS.clear(); + Dependencies.instance().getConnectionProvider().closeAll(); } } diff --git a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/jdbc/JdbcSchema.java b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/jdbc/JdbcSchema.java index 35729a378..4235b5f39 100644 --- a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/jdbc/JdbcSchema.java +++ b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/jdbc/JdbcSchema.java @@ -18,8 +18,8 @@ import manifold.sql.rt.api.ConnectionProvider; import manifold.sql.rt.api.DbConfig; +import manifold.sql.rt.api.Dependencies; import manifold.sql.schema.api.Schema; -import manifold.sql.rt.api.ConnectionNotifier; import manifold.sql.schema.api.SchemaTable; import java.sql.*; @@ -44,7 +44,7 @@ public JdbcSchema( DbConfig dbConfig ) throws SQLException _tables = new LinkedHashMap<>(); _javaToName = new LinkedHashMap<>(); _nameToJava = new LinkedHashMap<>(); - ConnectionProvider cp = ConnectionProvider.findFirst(); + ConnectionProvider cp = Dependencies.instance().getConnectionProvider(); try( Connection c = cp.getConnection( dbConfig ) ) { _dbProductName = c.getMetaData().getDatabaseProductName(); @@ -67,11 +67,6 @@ public JdbcSchema( DbConfig dbConfig ) throws SQLException private void build( Connection c, DatabaseMetaData metaData ) throws SQLException { - for( ConnectionNotifier p : ConnectionNotifier.PROVIDERS.get() ) - { - p.init( c ); - } - try( ResultSet resultSet = metaData.getTables( _dbConfig.getCatalogName(), _name, null, new String[]{"TABLE", "VIEW"} ) ) { diff --git a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/jdbc/oneoff/SqliteTypeMapping.java b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/jdbc/oneoff/SqliteTypeMapping.java index fcf16a172..394781769 100644 --- a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/jdbc/oneoff/SqliteTypeMapping.java +++ b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/jdbc/oneoff/SqliteTypeMapping.java @@ -24,15 +24,12 @@ import java.util.regex.Pattern; /** - * Sqlite is pretty much a mess with getting types correctly mapped.
- * - issue 928
- * - issue 933
- * - issue 935
- * - issue 937
+ * Sqlite is pretty much a mess regarding schema types reflecting result set types. The former is barely typed, lots of + * strings etc., while the latter is more specific. However, since schema types correspond with schema column types, we have + * to do better. *

- * Here is an attempt to at least get schema columns properly typed. The logic used here is taken from, ironically, the - * sqlite JDBC3ResultSet#getColumnType() implementation, which unlike DatabaseMetadata#getColumns() + getString("DATA_TYPE"), - * gets it mostly right. + * Here is an attempt to improve the situation. The logic used here is taken from, ironically, the sqlite JDBC3ResultSet#getColumnType() + * implementation, which unlike DatabaseMetadata#getColumns() + getString("DATA_TYPE"), gets it mostly right. */ public class SqliteTypeMapping { diff --git a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/type/SchemaManifold.java b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/type/SchemaManifold.java index 226256fcf..e5e6ac29a 100644 --- a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/type/SchemaManifold.java +++ b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/type/SchemaManifold.java @@ -25,7 +25,7 @@ import manifold.rt.api.Bindings; import manifold.rt.api.util.ManClassUtil; import manifold.rt.api.util.StreamUtil; -import manifold.sql.rt.connection.DbConfigImpl; +import manifold.sql.rt.impl.DbConfigImpl; import manifold.sql.schema.api.Schema; import manifold.sql.schema.api.SchemaTable; diff --git a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/type/SchemaModel.java b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/type/SchemaModel.java index 00f909020..35c55b6ef 100644 --- a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/type/SchemaModel.java +++ b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/type/SchemaModel.java @@ -26,10 +26,10 @@ import manifold.json.rt.Json; import manifold.rt.api.Bindings; import manifold.rt.api.util.StreamUtil; -import manifold.sql.rt.api.ConnectionProvider; import manifold.sql.rt.api.DbConfig; import manifold.sql.rt.api.DbLocationProvider; -import manifold.sql.rt.connection.DbConfigImpl; +import manifold.sql.rt.api.Dependencies; +import manifold.sql.rt.impl.DbConfigImpl; import manifold.sql.schema.api.Schema; import manifold.sql.schema.api.SchemaProvider; import manifold.sql.schema.api.SchemaTable; @@ -137,7 +137,7 @@ SchemaParentType getType() public void updateFile( IFile file ) { super.updateFile( file ); - ConnectionProvider.findFirst().closeDataSource( _dbConfig ); + Dependencies.instance().getConnectionProvider().closeDataSource( _dbConfig ); init(); } diff --git a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/type/SchemaParentType.java b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/type/SchemaParentType.java index 994f3ee04..e5604fd8a 100644 --- a/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/type/SchemaParentType.java +++ b/manifold-deps-parent/manifold-sql/src/main/java/manifold/sql/schema/type/SchemaParentType.java @@ -24,7 +24,7 @@ import manifold.sql.api.Column; import manifold.sql.rt.api.*; import manifold.sql.rt.api.OperableTxScope; -import manifold.sql.rt.connection.DefaultTxScopeProvider; +import manifold.sql.rt.impl.DefaultTxScopeProvider; import manifold.sql.schema.api.*; import manifold.util.concurrent.LocklessLazyVar; @@ -117,7 +117,7 @@ private void addNewScopeMethod( SrcLinkedClass srcClass ) .modifiers( Modifier.PUBLIC | Modifier.STATIC ) .name( "newScope" ) .returns( new SrcType( TxScope.class.getSimpleName() ) ); - method.body( "return TxScopeProvider.newScope(${srcClass.getName()}.class);" ); + method.body( "return ${Dependencies.class.getName()}.instance().getTxScopeProvider().newScope(${srcClass.getName()}.class);" ); srcClass.addMethod( method ); } @@ -177,7 +177,7 @@ private void addTableInfoMethod( SrcLinkedClass srcClass, SchemaTable table ) { SrcField tableInfoField = new SrcField( "myTableInfo", new SrcType( LocklessLazyVar.class.getSimpleName() ).addTypeParam( TableInfo.class ) ); StringBuilder sb = new StringBuilder( "LocklessLazyVar.make(() -> {\n" ); - sb.append( " Map allCols = new LinkedHashMap<>();\n" ); + sb.append( " LinkedHashMap allCols = new LinkedHashMap<>();\n" ); for( Map.Entry entry : table.getColumns().entrySet() ) { //noinspection unused @@ -186,14 +186,14 @@ private void addTableInfoMethod( SrcLinkedClass srcClass, SchemaTable table ) int jdbcType = entry.getValue().getJdbcType(); sb.append( " allCols.put(\"$colName\", $jdbcType);\n"); } - sb.append( " Set pkCols = new HashSet<>();\n" ); + sb.append( " HashSet pkCols = new HashSet<>();\n" ); for( SchemaColumn pkCol : table.getPrimaryKey() ) { //noinspection unused String pkColName = pkCol.getName(); sb.append( " pkCols.add(\"$pkColName\");\n\n" ); } - sb.append( " Set ukCols = new HashSet<>();\n" ); + sb.append( " HashSet ukCols = new HashSet<>();\n" ); for( Map.Entry> entry : table.getNonNullUniqueKeys().entrySet() ) { // just need one @@ -470,7 +470,7 @@ private void addFkProperty( SrcLinkedClass srcClass, SchemaForeignKey sfk ) String jdbcParamTypes = getJdbcParamTypes( sfk.getColumns() ); //noinspection unused String configName = _model.getDbConfig().getName(); - sb.append( " return CrudProvider.instance().read(" + + sb.append( " return ${Dependencies.class.getName()}.instance().getCrudProvider().read(" + "new QueryContext<$tableFqn>(getBindings().getTxScope(), $tableFqn.class, \"${table.getName()}\", $jdbcParamTypes, paramBindings, \"$configName\", " + "rowBindings -> new $tableFqn() {public TxBindings getBindings() { return rowBindings; }}));" ); fkFetchMethod.body( sb.toString() ); @@ -584,7 +584,7 @@ private void addReadMethods( SrcLinkedClass srcClass, SchemaTable table ) String paramName = makePascalCaseIdentifier( col.getName(), false ); sb.append( " paramBindings.put(\"${col.getName()}\", $paramName);\n" ); } - sb.append( " return CrudProvider.instance().read(new QueryContext<$tableFqn>(txScope, $tableFqn.class,\n" + + sb.append( " return ${Dependencies.class.getName()}.instance().getCrudProvider().read(new QueryContext<$tableFqn>(txScope, $tableFqn.class,\n" + "\"${table.getName()}\", $jdbcParamTypes, paramBindings, \"$configName\",\n" + "rowBindings -> new $tableFqn() {public TxBindings getBindings() { return rowBindings; }}));" ); method.body( sb.toString() );