Search in sources :

Example 1 with TestConnectionProviderSource

use of org.projectnessie.versioned.persist.tests.extension.TestConnectionProviderSource in project nessie by projectnessie.

the class DatabaseAdapters method createDatabaseConnectionProvider.

public static DatabaseConnectionProvider<DatabaseConnectionConfig> createDatabaseConnectionProvider(String databaseAdapterName, Map<String, String> configuration) {
    DatabaseAdapterFactory<DatabaseAdapterConfig, DatabaseAdapterConfig, DatabaseConnectionProvider<?>> factory = DatabaseAdapterFactory.loadFactoryByName(databaseAdapterName);
    String providerSpec = databaseAdapterName.indexOf(':') == -1 ? null : databaseAdapterName.substring(databaseAdapterName.indexOf(':') + 1).toLowerCase(Locale.ROOT);
    DatabaseAdapterFactory.Builder<DatabaseAdapterConfig, DatabaseAdapterConfig, DatabaseConnectionProvider<?>> builder = factory.newBuilder();
    TestConnectionProviderSource<DatabaseConnectionConfig> providerSource = TestConnectionProviderSource.findCompatibleProviderSource(builder.getConfig(), factory, providerSpec);
    providerSource.configureConnectionProviderConfigFromDefaults(config -> SystemPropertiesConfigurer.configureFromPropertiesGeneric(config, DatabaseConnectionConfig.class, prop -> configuration.getOrDefault(prop, System.getProperty(prop))));
    try {
        // createConnectionProvider method is protected, not defined on DatabaseConnectionProvider,
        // but on AbstractTestConnectionProviderSource
        Method createConnectionProviderMethod = providerSource.getClass().getMethod("createConnectionProvider");
        @SuppressWarnings("unchecked") DatabaseConnectionProvider<DatabaseConnectionConfig> connectionProvider = (DatabaseConnectionProvider<DatabaseConnectionConfig>) createConnectionProviderMethod.invoke(providerSource);
        connectionProvider.configure(providerSource.getConnectionProviderConfig());
        connectionProvider.initialize();
        return connectionProvider;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DatabaseConnectionProvider(org.projectnessie.versioned.persist.adapter.DatabaseConnectionProvider) TestConnectionProviderSource(org.projectnessie.versioned.persist.tests.extension.TestConnectionProviderSource) GenericContentVariantSupplier(org.projectnessie.versioned.persist.store.GenericContentVariantSupplier) InvocationTargetException(java.lang.reflect.InvocationTargetException) Builder(org.projectnessie.versioned.persist.adapter.DatabaseAdapterFactory.Builder) TableCommitMetaStoreWorker(org.projectnessie.server.store.TableCommitMetaStoreWorker) DatabaseConnectionConfig(org.projectnessie.versioned.persist.adapter.DatabaseConnectionConfig) Locale(java.util.Locale) Map(java.util.Map) DatabaseAdapterConfig(org.projectnessie.versioned.persist.adapter.DatabaseAdapterConfig) DatabaseAdapterFactory(org.projectnessie.versioned.persist.adapter.DatabaseAdapterFactory) Method(java.lang.reflect.Method) ContentVariantSupplier(org.projectnessie.versioned.persist.adapter.ContentVariantSupplier) DatabaseAdapter(org.projectnessie.versioned.persist.adapter.DatabaseAdapter) SystemPropertiesConfigurer(org.projectnessie.versioned.persist.tests.SystemPropertiesConfigurer) DatabaseConnectionConfig(org.projectnessie.versioned.persist.adapter.DatabaseConnectionConfig) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) DatabaseAdapterFactory(org.projectnessie.versioned.persist.adapter.DatabaseAdapterFactory) DatabaseConnectionProvider(org.projectnessie.versioned.persist.adapter.DatabaseConnectionProvider) DatabaseAdapterConfig(org.projectnessie.versioned.persist.adapter.DatabaseAdapterConfig)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Locale (java.util.Locale)1 Map (java.util.Map)1 TableCommitMetaStoreWorker (org.projectnessie.server.store.TableCommitMetaStoreWorker)1 ContentVariantSupplier (org.projectnessie.versioned.persist.adapter.ContentVariantSupplier)1 DatabaseAdapter (org.projectnessie.versioned.persist.adapter.DatabaseAdapter)1 DatabaseAdapterConfig (org.projectnessie.versioned.persist.adapter.DatabaseAdapterConfig)1 DatabaseAdapterFactory (org.projectnessie.versioned.persist.adapter.DatabaseAdapterFactory)1 Builder (org.projectnessie.versioned.persist.adapter.DatabaseAdapterFactory.Builder)1 DatabaseConnectionConfig (org.projectnessie.versioned.persist.adapter.DatabaseConnectionConfig)1 DatabaseConnectionProvider (org.projectnessie.versioned.persist.adapter.DatabaseConnectionProvider)1 GenericContentVariantSupplier (org.projectnessie.versioned.persist.store.GenericContentVariantSupplier)1 SystemPropertiesConfigurer (org.projectnessie.versioned.persist.tests.SystemPropertiesConfigurer)1 TestConnectionProviderSource (org.projectnessie.versioned.persist.tests.extension.TestConnectionProviderSource)1