use of org.projectnessie.versioned.persist.adapter.DatabaseConnectionConfig 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);
}
}
Aggregations