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);
}
}
Aggregations