use of org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException 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;
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException in project data-access by pentaho.
the class InMemoryDSWDatasourceServiceImpl method doPreview.
public SerializedResultSet doPreview(String connectionName, String query, String previewLimit) throws DatasourceServiceException {
SerializedResultSet returnResultSet;
try {
executeQuery(connectionName, query, previewLimit);
returnResultSet = DatasourceInMemoryServiceHelper.getSerializeableResultSet(connectionName, query, Integer.parseInt(previewLimit), null);
} catch (QueryValidationException e) {
logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
throw new DatasourceServiceException(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
}
return returnResultSet;
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException in project data-access by pentaho.
the class InMemoryDSWDatasourceServiceImpl 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 = new ModelerService();
modelerWorkspace.setModelName(name);
try {
Boolean securityEnabled = (getPermittedRoleList() != null && getPermittedRoleList().size() > 0) || (getPermittedUserList() != null && getPermittedUserList().size() > 0);
SerializedResultSet resultSet = DatasourceInMemoryServiceHelper.getSerializeableResultSet(connection.getName(), query, Integer.parseInt("10"), null);
SQLModelGenerator sqlModelGenerator = new SQLModelGenerator(name, connection.getName(), connection.getDatabaseType().getShortName(), resultSet.getColumnTypes(), resultSet.getColumns(), query, securityEnabled, getPermittedRoleList(), getPermittedUserList(), getDefaultAcls(), "joe");
Domain domain = sqlModelGenerator.generate();
modelerWorkspace.setDomain(domain);
modelerWorkspace.getWorkspaceHelper().autoModelFlat(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();
modelerService.serializeModels(domain, modelerWorkspace.getModelName());
summary.setDomain(domain);
return summary;
} catch (SQLModelGeneratorException smge) {
logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0016_UNABLE_TO_GENERATE_MODEL", smge.getLocalizedMessage()), smge);
throw new DatasourceServiceException(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0015_UNABLE_TO_GENERATE_MODEL"), // $NON-NLS-1$
smge);
} catch (QueryValidationException e) {
logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
throw new DatasourceServiceException(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
} catch (ModelerException e) {
logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0016_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), e);
throw new DatasourceServiceException(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0015_UNABLE_TO_GENERATE_MODEL"), // $NON-NLS-1$
e);
} catch (Exception e) {
logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0016_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), e);
throw new DatasourceServiceException(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0015_UNABLE_TO_GENERATE_MODEL"), // $NON-NLS-1$
e);
}
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException in project data-access by pentaho.
the class InMemoryDSWDatasourceServiceImpl method executeQuery.
private IPentahoResultSet executeQuery(String connectionName, String query, String previewLimit) throws QueryValidationException {
SQLConnection sqlConnection = null;
int limit = (previewLimit != null && previewLimit.length() > 0) ? Integer.parseInt(previewLimit) : -1;
try {
sqlConnection = DatasourceInMemoryServiceHelper.getConnection(connectionName);
sqlConnection.setMaxRows(limit);
sqlConnection.setReadOnly(true);
return sqlConnection.executeQuery(BEFORE_QUERY + query + AFTER_QUERY);
} catch (Exception e) {
logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
// $NON-NLS-1$
throw new QueryValidationException(e.getLocalizedMessage(), e);
} finally {
if (sqlConnection != null) {
sqlConnection.close();
}
}
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException 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();
}
}
}
Aggregations