Search in sources :

Example 1 with QueryExecutor

use of com.hortonworks.registries.storage.impl.jdbc.provider.sql.factory.QueryExecutor in project registry by hortonworks.

the class JdbcStorageManager method init.

/**
 * Initializes this instance with {@link QueryExecutor} created from the given {@code properties}.
 * Some of these properties are jdbcDriverClass, jdbcUrl, queryTimeoutInSecs.
 *
 * @param properties properties with name/value pairs
 */
@Override
public void init(Map<String, Object> properties) {
    if (!properties.containsKey(DB_TYPE)) {
        throw new IllegalArgumentException("db.type should be set on jdbc properties");
    }
    String type = (String) properties.get(DB_TYPE);
    // For now, keeping it simple as there are only 2.
    if (!"mysql".equals(type) && !"postgresql".equals(type) && !"oracle".equals(type)) {
        throw new IllegalArgumentException("Unknown jdbc storage provider type: " + type);
    }
    log.info("jdbc provider type: [{}]", type);
    Map<String, Object> dbProperties = (Map<String, Object>) properties.get("db.properties");
    QueryExecutor queryExecutor = QueryExecutorFactory.get(type, dbProperties);
    this.queryExecutor = queryExecutor;
    this.queryExecutor.setStorableFactory(storableFactory);
}
Also used : QueryExecutor(com.hortonworks.registries.storage.impl.jdbc.provider.sql.factory.QueryExecutor) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with QueryExecutor

use of com.hortonworks.registries.storage.impl.jdbc.provider.sql.factory.QueryExecutor in project registry by hortonworks.

the class QueryExecutorFactory method get.

public static QueryExecutor get(String type, Map<String, Object> dbProperties) {
    HikariCPConnectionBuilder connectionBuilder = getHikariCPConnnectionBuilder(dbProperties);
    ExecutionConfig executionConfig = getExecutionConfig(dbProperties);
    QueryExecutor queryExecutor = null;
    switch(type) {
        case "mysql":
            queryExecutor = new MySqlExecutor(executionConfig, connectionBuilder);
            break;
        case "postgresql":
            queryExecutor = new PostgresqlExecutor(executionConfig, connectionBuilder);
            break;
        case "oracle":
            queryExecutor = new OracleExecutor(executionConfig, connectionBuilder);
            break;
        default:
            throw new IllegalArgumentException("Unsupported storage provider type: " + type);
    }
    return queryExecutor;
}
Also used : HikariCPConnectionBuilder(com.hortonworks.registries.storage.impl.jdbc.connection.HikariCPConnectionBuilder) MySqlExecutor(com.hortonworks.registries.storage.impl.jdbc.provider.mysql.factory.MySqlExecutor) PostgresqlExecutor(com.hortonworks.registries.storage.impl.jdbc.provider.postgresql.factory.PostgresqlExecutor) QueryExecutor(com.hortonworks.registries.storage.impl.jdbc.provider.sql.factory.QueryExecutor) OracleExecutor(com.hortonworks.registries.storage.impl.jdbc.provider.oracle.factory.OracleExecutor) ExecutionConfig(com.hortonworks.registries.storage.impl.jdbc.config.ExecutionConfig)

Aggregations

QueryExecutor (com.hortonworks.registries.storage.impl.jdbc.provider.sql.factory.QueryExecutor)2 ExecutionConfig (com.hortonworks.registries.storage.impl.jdbc.config.ExecutionConfig)1 HikariCPConnectionBuilder (com.hortonworks.registries.storage.impl.jdbc.connection.HikariCPConnectionBuilder)1 MySqlExecutor (com.hortonworks.registries.storage.impl.jdbc.provider.mysql.factory.MySqlExecutor)1 OracleExecutor (com.hortonworks.registries.storage.impl.jdbc.provider.oracle.factory.OracleExecutor)1 PostgresqlExecutor (com.hortonworks.registries.storage.impl.jdbc.provider.postgresql.factory.PostgresqlExecutor)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1