Search in sources :

Example 6 with ExecuteQueryControllerServiceRequestBuilder

use of com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder in project kylo by Teradata.

the class DBCPConnectionPoolService method executePreviewQueryForDatasource.

/**
 * Executes the specified SELECT query in the context of the specified data source.
 *
 * @param datasource the JDBC datasource
 * @param query      the query to execute
 * @return the query results
 * @throws DataAccessException      if the query cannot be executed
 * @throws IllegalArgumentException if the datasource is invalid
 */
@Nonnull
public QueryResult executePreviewQueryForDatasource(@Nonnull final JdbcDatasource datasource, @Nonnull final String schema, @Nonnull final String tableName, final int limit) {
    final Optional<ControllerServiceDTO> controllerService = Optional.ofNullable(datasource.getControllerServiceId()).map(id -> getControllerService(id, null));
    if (controllerService.isPresent()) {
        final DatabaseType dbType = DatabaseType.fromJdbcConnectionString(datasource.getDatabaseConnectionUrl());
        final ExecuteQueryControllerServiceRequest serviceProperties = new ExecuteQueryControllerServiceRequestBuilder(controllerService.get()).password(datasource.getPassword()).previewQuery(dbType, schema, tableName, limit).useEnvironmentProperties(false).build();
        final PoolingDataSourceService.DataSourceProperties dataSourceProperties = getDataSourceProperties(serviceProperties);
        return executeQueryForControllerService(dataSourceProperties, serviceProperties);
    } else {
        log.error("Cannot execute query for datasource: {}", datasource);
        throw new IllegalArgumentException("Missing controller service for datasource: " + datasource);
    }
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) PoolingDataSourceService(com.thinkbiganalytics.db.PoolingDataSourceService) DatabaseType(com.thinkbiganalytics.jdbc.util.DatabaseType) ExecuteQueryControllerServiceRequestBuilder(com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder) Nonnull(javax.annotation.Nonnull)

Aggregations

ExecuteQueryControllerServiceRequestBuilder (com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder)6 ControllerServiceDTO (org.apache.nifi.web.api.dto.ControllerServiceDTO)6 PoolingDataSourceService (com.thinkbiganalytics.db.PoolingDataSourceService)5 DatabaseType (com.thinkbiganalytics.jdbc.util.DatabaseType)4 Nonnull (javax.annotation.Nonnull)4