use of com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfigBuilder in project aws-athena-query-federation by awslabs.
the class JDBCUtil method createJdbcRecordHandlerMap.
/**
* Creates a map of Catalog to respective record handler to be used by Multiplexer.
*
* @param properties system properties.
* @param jdbcRecordHandlerFactory
* @return Map of String -> {@link JdbcRecordHandler}
*/
public static Map<String, JdbcRecordHandler> createJdbcRecordHandlerMap(final Map<String, String> properties, JdbcRecordHandlerFactory jdbcRecordHandlerFactory) {
ImmutableMap.Builder<String, JdbcRecordHandler> recordHandlerMap = ImmutableMap.builder();
final String functionName = Validate.notBlank(properties.get(LAMBDA_FUNCTION_NAME_PROPERTY), "Lambda function name not present in environment.");
List<DatabaseConnectionConfig> databaseConnectionConfigs = new DatabaseConnectionConfigBuilder().engine(jdbcRecordHandlerFactory.getEngine()).properties(properties).build();
if (databaseConnectionConfigs.isEmpty()) {
throw new RuntimeException("At least one connection string required.");
}
boolean defaultPresent = false;
for (DatabaseConnectionConfig databaseConnectionConfig : databaseConnectionConfigs) {
JdbcRecordHandler jdbcRecordHandler = jdbcRecordHandlerFactory.createJdbcRecordHandler(databaseConnectionConfig);
recordHandlerMap.put(databaseConnectionConfig.getCatalog(), jdbcRecordHandler);
if (DatabaseConnectionConfigBuilder.DEFAULT_CONNECTION_STRING_PROPERTY.equals(databaseConnectionConfig.getCatalog())) {
recordHandlerMap.put(DEFAULT_CATALOG_PREFIX + functionName, jdbcRecordHandler);
defaultPresent = true;
}
}
if (!defaultPresent) {
throw new RuntimeException("Must provide connection parameters for default database instance " + DatabaseConnectionConfigBuilder.DEFAULT_CONNECTION_STRING_PROPERTY);
}
return recordHandlerMap.build();
}
use of com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfigBuilder in project aws-athena-query-federation by awslabs.
the class JDBCUtil method createJdbcMetadataHandlerMap.
/**
* Creates a map of Catalog to respective metadata handler to be used by Multiplexer.
*
* @param properties system properties.
* @param metadataHandlerFactory factory for creating the appropriate metadata handler for the database type
* @return Map of String -> {@link JdbcMetadataHandler}
*/
public static Map<String, JdbcMetadataHandler> createJdbcMetadataHandlerMap(final Map<String, String> properties, JdbcMetadataHandlerFactory metadataHandlerFactory) {
ImmutableMap.Builder<String, JdbcMetadataHandler> metadataHandlerMap = ImmutableMap.builder();
final String functionName = Validate.notBlank(properties.get(LAMBDA_FUNCTION_NAME_PROPERTY), "Lambda function name not present in environment.");
List<DatabaseConnectionConfig> databaseConnectionConfigs = new DatabaseConnectionConfigBuilder().engine(metadataHandlerFactory.getEngine()).properties(properties).build();
if (databaseConnectionConfigs.isEmpty()) {
throw new RuntimeException("At least one connection string required.");
}
boolean defaultPresent = false;
for (DatabaseConnectionConfig databaseConnectionConfig : databaseConnectionConfigs) {
JdbcMetadataHandler jdbcMetadataHandler = metadataHandlerFactory.createJdbcMetadataHandler(databaseConnectionConfig);
metadataHandlerMap.put(databaseConnectionConfig.getCatalog(), jdbcMetadataHandler);
if (DatabaseConnectionConfigBuilder.DEFAULT_CONNECTION_STRING_PROPERTY.equals(databaseConnectionConfig.getCatalog())) {
metadataHandlerMap.put(DEFAULT_CATALOG_PREFIX + functionName, jdbcMetadataHandler);
defaultPresent = true;
}
}
if (!defaultPresent) {
throw new RuntimeException("Must provide connection parameters for default database instance " + DatabaseConnectionConfigBuilder.DEFAULT_CONNECTION_STRING_PROPERTY);
}
return metadataHandlerMap.build();
}
Aggregations