Search in sources :

Example 6 with ExecutionConfig

use of com.hortonworks.registries.storage.impl.jdbc.config.ExecutionConfig in project registry by hortonworks.

the class MySqlStorageManagerNoCacheIntegrationTest method setFields.

private void setFields(ConnectionBuilder connectionBuilder, Database db) {
    JdbcStorageManagerIntegrationTest.connectionBuilder = connectionBuilder;
    jdbcStorageManager = createJdbcStorageManager(new MySqlExecutor(new ExecutionConfig(-1), connectionBuilder));
    database = db;
}
Also used : MySqlExecutor(com.hortonworks.registries.storage.impl.jdbc.provider.mysql.factory.MySqlExecutor) ExecutionConfig(com.hortonworks.registries.storage.impl.jdbc.config.ExecutionConfig)

Example 7 with ExecutionConfig

use of com.hortonworks.registries.storage.impl.jdbc.config.ExecutionConfig in project registry by hortonworks.

the class AbstractQueryExecutor method getColumnNames.

@Override
public CaseAgnosticStringSet getColumnNames(String namespace) throws SQLException {
    CaseAgnosticStringSet columns = new CaseAgnosticStringSet();
    Connection connection = null;
    try {
        connection = getConnection();
        final ResultSetMetaData rsMetadata = PreparedStatementBuilder.of(connection, new ExecutionConfig(queryTimeoutSecs), storageDataTypeContext, new SqlSelectQuery(namespace)).getMetaData();
        for (int i = 1; i <= rsMetadata.getColumnCount(); i++) {
            columns.add(rsMetadata.getColumnName(i));
        }
        return columns;
    } catch (SQLException e) {
        log.error(e.getMessage(), e);
        throw new RuntimeException(e);
    } finally {
        if (!transactionBookKeeper.hasActiveTransaction(Thread.currentThread().getId())) {
            closeConnection(connection);
        }
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) CaseAgnosticStringSet(com.hortonworks.registries.storage.impl.jdbc.util.CaseAgnosticStringSet) SqlSelectQuery(com.hortonworks.registries.storage.impl.jdbc.provider.sql.query.SqlSelectQuery) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ExecutionConfig(com.hortonworks.registries.storage.impl.jdbc.config.ExecutionConfig)

Example 8 with ExecutionConfig

use of com.hortonworks.registries.storage.impl.jdbc.config.ExecutionConfig in project registry by hortonworks.

the class OracleExecutor method getColumnNames.

@Override
public CaseAgnosticStringSet getColumnNames(String namespace) throws SQLException {
    CaseAgnosticStringSet columns = new CaseAgnosticStringSet();
    Connection connection = null;
    try {
        connection = getConnection();
        final ResultSetMetaData rsMetadata = PreparedStatementBuilder.of(connection, new ExecutionConfig(queryTimeoutSecs), ORACLE_DATA_TYPE_CONTEXT, new OracleSelectQuery(namespace)).getMetaData();
        for (int i = 1; i <= rsMetadata.getColumnCount(); i++) {
            columns.add(rsMetadata.getColumnName(i));
        }
        return columns;
    } catch (SQLException e) {
        log.error(e.getMessage(), e);
        throw new RuntimeException(e);
    } finally {
        if (!transactionBookKeeper.hasActiveTransaction(Thread.currentThread().getId())) {
            closeConnection(connection);
        }
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) CaseAgnosticStringSet(com.hortonworks.registries.storage.impl.jdbc.util.CaseAgnosticStringSet) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ExecutionConfig(com.hortonworks.registries.storage.impl.jdbc.config.ExecutionConfig) OracleSelectQuery(com.hortonworks.registries.storage.impl.jdbc.provider.oracle.query.OracleSelectQuery)

Example 9 with ExecutionConfig

use of com.hortonworks.registries.storage.impl.jdbc.config.ExecutionConfig in project registry by hortonworks.

the class OracleSequenceIdQuery method getNextID.

public Long getNextID(Connection connection) {
    OracleSqlQuery nextValueQuery = new OracleSqlQuery(String.format("SELECT \"%s\".%s from DUAL", namespace.toUpperCase(), nextValueFunction));
    Long nextId = 0l;
    try {
        ResultSet selectResultSet = PreparedStatementBuilder.of(connection, new ExecutionConfig(queryTimeoutSecs), oracleDatabaseStorageContext, nextValueQuery).getPreparedStatement(nextValueQuery).executeQuery();
        if (selectResultSet.next()) {
            nextId = selectResultSet.getLong(nextValueFunction);
        } else {
            throw new RuntimeException("No sequence-id created for the current sequence of [" + namespace + "]");
        }
        log.debug("Generated sequence id [{}] for [{}]", nextId, namespace);
    } catch (SQLException e) {
        log.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
    return nextId;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ExecutionConfig(com.hortonworks.registries.storage.impl.jdbc.config.ExecutionConfig)

Example 10 with ExecutionConfig

use of com.hortonworks.registries.storage.impl.jdbc.config.ExecutionConfig 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

ExecutionConfig (com.hortonworks.registries.storage.impl.jdbc.config.ExecutionConfig)10 MySqlExecutor (com.hortonworks.registries.storage.impl.jdbc.provider.mysql.factory.MySqlExecutor)7 HikariCPConnectionBuilder (com.hortonworks.registries.storage.impl.jdbc.connection.HikariCPConnectionBuilder)3 SQLException (java.sql.SQLException)3 StorageManager (com.hortonworks.registries.storage.StorageManager)2 JdbcStorageManager (com.hortonworks.registries.storage.impl.jdbc.JdbcStorageManager)2 CaseAgnosticStringSet (com.hortonworks.registries.storage.impl.jdbc.util.CaseAgnosticStringSet)2 Connection (java.sql.Connection)2 ResultSetMetaData (java.sql.ResultSetMetaData)2 Before (org.junit.Before)2 OracleExecutor (com.hortonworks.registries.storage.impl.jdbc.provider.oracle.factory.OracleExecutor)1 OracleSelectQuery (com.hortonworks.registries.storage.impl.jdbc.provider.oracle.query.OracleSelectQuery)1 PostgresqlExecutor (com.hortonworks.registries.storage.impl.jdbc.provider.postgresql.factory.PostgresqlExecutor)1 QueryExecutor (com.hortonworks.registries.storage.impl.jdbc.provider.sql.factory.QueryExecutor)1 SqlSelectQuery (com.hortonworks.registries.storage.impl.jdbc.provider.sql.query.SqlSelectQuery)1 ResultSet (java.sql.ResultSet)1