Search in sources :

Example 1 with SqlQueriesNotSupportedException

use of org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException in project data-access by pentaho.

the class DSWDatasourceServiceImpl method doPreview.

public SerializedResultSet doPreview(String connectionName, String query, String previewLimit) throws DatasourceServiceException {
    if (!hasDataAccessPermission()) {
        // $NON-NLS-1$
        logger.error(Messages.getErrorString("DatasourceServiceImpl.ERROR_0001_PERMISSION_DENIED"));
        throw new DatasourceServiceException(Messages.getErrorString(// $NON-NLS-1$
        "DatasourceServiceImpl.ERROR_0001_PERMISSION_DENIED"));
    }
    SerializedResultSet returnResultSet;
    try {
        connectionName = UtilHtmlSanitizer.getInstance().safeEscapeHtml(connectionName);
        executeQuery(connectionName, query, previewLimit);
        returnResultSet = DatasourceServiceHelper.getSerializeableResultSet(connectionName, query, Integer.parseInt(previewLimit), PentahoSessionHolder.getSession());
    } catch (QueryValidationException e) {
        throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
        e);
    } catch (SqlQueriesNotSupportedException e) {
        // $NON-NLS-1$
        throw new DatasourceServiceException(e.getLocalizedMessage(), e);
    }
    return returnResultSet;
}
Also used : QueryValidationException(org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException) SerializedResultSet(org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet) SqlQueriesNotSupportedException(org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 2 with SqlQueriesNotSupportedException

use of org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException in project data-access by pentaho.

the class DSWDatasourceServiceImpl method checkSqlQueriesSupported.

/**
 * Method is designed to check whether sql queries can be executed via connection with a {@core connName}.
 * For now we can't allow sql queries for connections, that are based on Pentaho Data Services.
 * See BISERVER-13225 for more info.
 *
 * @param connName
 *          name of connection, to be examined for sql queries support
 * @throws ConnectionServiceException
 *            if an error occurs while receiving connection with {@code connectionName}
 * @throws SqlQueriesNotSupportedException
 *            if query is not supported for a connection with a {@code connectionName}
 */
void checkSqlQueriesSupported(String connName) throws ConnectionServiceException, SqlQueriesNotSupportedException {
    IDatabaseConnection conn = connService.getConnectionByName(connName);
    IDatabaseType dbType = conn.getDatabaseType();
    if (dbType.getName().equals(DB_TYPE_ID_PENTAHO_DATA_SERVICE)) {
        throw new SqlQueriesNotSupportedException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0024_SQL_QUERIES_NOT_SUPPORTED_FOR_PENTAHO_DATA_SERVICE"));
    }
}
Also used : IDatabaseType(org.pentaho.database.model.IDatabaseType) SqlQueriesNotSupportedException(org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 3 with SqlQueriesNotSupportedException

use of org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException in project data-access by pentaho.

the class DSWDatasourceServiceImpl method executeQuery.

IPentahoResultSet executeQuery(String connectionName, String query, String previewLimit) throws QueryValidationException, SqlQueriesNotSupportedException {
    SQLConnection sqlConnection = null;
    try {
        checkSqlQueriesSupported(connectionName);
        int limit = (previewLimit != null && previewLimit.length() > 0) ? Integer.parseInt(previewLimit) : -1;
        sqlConnection = (SQLConnection) PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, connectionName, PentahoSessionHolder.getSession(), new SimpleLogger(DatasourceServiceHelper.class.getName()));
        sqlConnection.setMaxRows(limit);
        sqlConnection.setReadOnly(true);
        return sqlConnection.executeQuery(BEFORE_QUERY + query + AFTER_QUERY);
    } catch (SqlQueriesNotSupportedException e) {
        logger.error(e.getLocalizedMessage());
        throw e;
    } catch (SQLException e) {
        String error = "DatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED";
        if (e.getSQLState().equals("S0021")) {
            // Column already exists
            error = "DatasourceServiceImpl.ERROR_0021_DUPLICATE_COLUMN_NAMES";
        }
        logger.error(Messages.getErrorString(error, e.getLocalizedMessage()));
        throw new QueryValidationException(Messages.getString(error, e.getLocalizedMessage()));
    } catch (Exception e) {
        logger.error(Messages.getErrorString(// $NON-NLS-1$
        "DatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), e);
        throw new QueryValidationException(e.getLocalizedMessage(), e);
    } finally {
        if (sqlConnection != null) {
            sqlConnection.close();
        }
    }
}
Also used : QueryValidationException(org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException) SQLException(java.sql.SQLException) SQLConnection(org.pentaho.platform.plugin.services.connections.sql.SQLConnection) SqlQueriesNotSupportedException(org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException) SimpleLogger(org.pentaho.platform.util.logging.SimpleLogger) ModelerException(org.pentaho.agilebi.modeler.ModelerException) QueryValidationException(org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException) SQLModelGeneratorException(org.pentaho.metadata.util.SQLModelGeneratorException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) SQLException(java.sql.SQLException) SqlQueriesNotSupportedException(org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException) CsvTransformGeneratorException(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException)

Example 4 with SqlQueriesNotSupportedException

use of org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException in project data-access by pentaho.

the class DSWDatasourceServiceImpl method generateLogicalModel.

/**
 * This method gets the business data which are the business columns, columns types and sample preview data
 *
 * @param modelName, connection, query, previewLimit
 * @return BusinessData
 * @throws DatasourceServiceException
 */
public BusinessData generateLogicalModel(String modelName, String connectionName, String dbType, String query, String previewLimit) throws DatasourceServiceException {
    if (!hasDataAccessPermission()) {
        // $NON-NLS-1$
        logger.error(Messages.getErrorString("DatasourceServiceImpl.ERROR_0001_PERMISSION_DENIED"));
        throw new DatasourceServiceException(Messages.getErrorString(// $NON-NLS-1$
        "DatasourceServiceImpl.ERROR_0001_PERMISSION_DENIED"));
    }
    try {
        // Testing whether the query is correct or not
        connectionName = UtilHtmlSanitizer.getInstance().safeEscapeHtml(connectionName);
        executeQuery(connectionName, query, previewLimit);
        Boolean securityEnabled = (getPermittedRoleList() != null && getPermittedRoleList().size() > 0) || (getPermittedUserList() != null && getPermittedUserList().size() > 0);
        SerializedResultSet resultSet = DatasourceServiceHelper.getSerializeableResultSet(connectionName, query, Integer.parseInt(previewLimit), PentahoSessionHolder.getSession());
        SQLModelGenerator sqlModelGenerator = new SQLModelGenerator(modelName, connectionName, dbType, resultSet.getColumnTypes(), resultSet.getColumns(), query, securityEnabled, getEffectivePermittedUserList(securityEnabled), getPermittedRoleList(), getDefaultAcls(), (PentahoSessionHolder.getSession() != null) ? PentahoSessionHolder.getSession().getName() : null);
        Domain domain = sqlModelGenerator.generate();
        return new BusinessData(domain, resultSet.getData());
    } catch (SQLModelGeneratorException smge) {
        logger.error(Messages.getErrorString("DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", smge.getLocalizedMessage()), // $NON-NLS-1$
        smge);
        throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", smge.getLocalizedMessage()), // $NON-NLS-1$
        smge);
    } catch (QueryValidationException e) {
        throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
        e);
    } catch (SqlQueriesNotSupportedException e) {
        // $NON-NLS-1$
        throw new DatasourceServiceException(e.getLocalizedMessage(), e);
    }
}
Also used : BusinessData(org.pentaho.platform.dataaccess.datasource.beans.BusinessData) SQLModelGeneratorException(org.pentaho.metadata.util.SQLModelGeneratorException) SQLModelGenerator(org.pentaho.metadata.util.SQLModelGenerator) QueryValidationException(org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException) SerializedResultSet(org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet) SqlQueriesNotSupportedException(org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException) Domain(org.pentaho.metadata.model.Domain) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 5 with SqlQueriesNotSupportedException

use of org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException in project data-access by pentaho.

the class DSWDatasourceServiceImpl method generateQueryDomain.

@Override
public QueryDatasourceSummary generateQueryDomain(String name, String query, DatabaseConnection connection, DatasourceDTO datasourceDTO) throws DatasourceServiceException {
    ModelerWorkspace modelerWorkspace = new ModelerWorkspace(new GwtModelerWorkspaceHelper(), getGeoContext());
    ModelerService modelerService = createModelerService();
    modelerWorkspace.setModelName(name);
    try {
        UtilHtmlSanitizer.getInstance().sanitizeConnectionParameters(connection);
        executeQuery(UtilHtmlSanitizer.getInstance().safeEscapeHtml(datasourceDTO.getConnectionName()), query, "1");
        Boolean securityEnabled = (getPermittedRoleList() != null && getPermittedRoleList().size() > 0) || (getPermittedUserList() != null && getPermittedUserList().size() > 0);
        SerializedResultSet resultSet = DatasourceServiceHelper.getSerializeableResultSet(connection.getName(), query, 10, PentahoSessionHolder.getSession());
        SQLModelGenerator sqlModelGenerator = new SQLModelGenerator(name, connection.getName(), connection.getDatabaseType().getShortName(), resultSet.getColumnTypes(), resultSet.getColumns(), query, securityEnabled, getEffectivePermittedUserList(securityEnabled), getPermittedRoleList(), getDefaultAcls(), (PentahoSessionHolder.getSession() != null) ? PentahoSessionHolder.getSession().getName() : null);
        Domain domain = sqlModelGenerator.generate();
        domain.getPhysicalModels().get(0).setId(connection.getName());
        modelerWorkspace.setDomain(domain);
        modelerWorkspace.getWorkspaceHelper().autoModelFlat(modelerWorkspace);
        modelerWorkspace.getWorkspaceHelper().autoModelRelationalFlat(modelerWorkspace);
        modelerWorkspace.setModelName(datasourceDTO.getDatasourceName());
        modelerWorkspace.getWorkspaceHelper().populateDomain(modelerWorkspace);
        domain.getLogicalModels().get(0).setProperty("datasourceModel", serializeModelState(datasourceDTO));
        domain.getLogicalModels().get(0).setProperty("DatasourceType", "SQL-DS");
        QueryDatasourceSummary summary = new QueryDatasourceSummary();
        prepareForSerializaton(domain);
        modelerService.serializeModels(domain, modelerWorkspace.getModelName());
        summary.setDomain(domain);
        return summary;
    } catch (SQLModelGeneratorException smge) {
        logger.error(// $NON-NLS-1$
        Messages.getErrorString(// $NON-NLS-1$
        "DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", smge.getLocalizedMessage()), smge);
        throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", smge.getLocalizedMessage()), // $NON-NLS-1$
        smge);
    } catch (QueryValidationException e) {
        logger.error(Messages.getErrorString("DatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
        e);
        throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
        e);
    } catch (ModelerException e) {
        logger.error(// $NON-NLS-1$
        Messages.getErrorString(// $NON-NLS-1$
        "DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), e);
        throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), // $NON-NLS-1$
        e);
    } catch (SqlQueriesNotSupportedException e) {
        // $NON-NLS-1$
        throw new DatasourceServiceException(e.getLocalizedMessage(), e);
    } catch (Exception e) {
        logger.error(// $NON-NLS-1$
        Messages.getErrorString(// $NON-NLS-1$
        "DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), e);
        throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), // $NON-NLS-1$
        e);
    }
}
Also used : SQLModelGeneratorException(org.pentaho.metadata.util.SQLModelGeneratorException) ModelerException(org.pentaho.agilebi.modeler.ModelerException) SerializedResultSet(org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet) ModelerException(org.pentaho.agilebi.modeler.ModelerException) QueryValidationException(org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException) SQLModelGeneratorException(org.pentaho.metadata.util.SQLModelGeneratorException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) SQLException(java.sql.SQLException) SqlQueriesNotSupportedException(org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException) CsvTransformGeneratorException(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException) GwtModelerWorkspaceHelper(org.pentaho.agilebi.modeler.gwt.GwtModelerWorkspaceHelper) QueryDatasourceSummary(org.pentaho.platform.dataaccess.datasource.wizard.sources.query.QueryDatasourceSummary) SQLModelGenerator(org.pentaho.metadata.util.SQLModelGenerator) QueryValidationException(org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException) SqlQueriesNotSupportedException(org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException) Domain(org.pentaho.metadata.model.Domain) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Aggregations

SqlQueriesNotSupportedException (org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException)5 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)4 QueryValidationException (org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException)4 SQLModelGeneratorException (org.pentaho.metadata.util.SQLModelGeneratorException)3 SerializedResultSet (org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 ModelerException (org.pentaho.agilebi.modeler.ModelerException)2 Domain (org.pentaho.metadata.model.Domain)2 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)2 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)2 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)2 SQLModelGenerator (org.pentaho.metadata.util.SQLModelGenerator)2 CsvTransformGeneratorException (org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException)2 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)2 MondrianCatalogServiceException (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException)2 ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)1 GwtModelerWorkspaceHelper (org.pentaho.agilebi.modeler.gwt.GwtModelerWorkspaceHelper)1 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)1 IDatabaseType (org.pentaho.database.model.IDatabaseType)1