use of org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException in project data-access by pentaho.
the class DatasourceServiceHelper method getSerializeableResultSet.
public static SerializedResultSet getSerializeableResultSet(String connectionName, String query, int rowLimit, IPentahoSession session) throws DatasourceServiceException {
SerializedResultSet serializedResultSet = null;
SQLConnection sqlConnection = null;
try {
sqlConnection = (SQLConnection) PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, connectionName, PentahoSessionHolder.getSession(), null);
sqlConnection.setMaxRows(rowLimit);
sqlConnection.setReadOnly(true);
IPentahoResultSet resultSet = sqlConnection.executeQuery(query);
// $NON-NLS-1$
logger.debug("ResultSet is not scrollable. Copying into memory");
if (!resultSet.isScrollable()) {
resultSet = convertToMemoryResultSet(resultSet);
}
MarshallableResultSet marshallableResultSet = new MarshallableResultSet();
marshallableResultSet.setResultSet(resultSet);
IPentahoMetaData ipmd = resultSet.getMetaData();
int[] columnTypes = null;
if (ipmd instanceof SQLMetaData) {
SQLMetaData smd = (SQLMetaData) ipmd;
columnTypes = smd.getJDBCColumnTypes();
} else if (ipmd instanceof MemoryMetaData) {
MemoryMetaData mmd = (MemoryMetaData) ipmd;
String[] columnTypesAsString = mmd.getColumnTypes();
columnTypes = new int[columnTypesAsString.length];
for (int i = 0; i < columnTypesAsString.length; i++) {
columnTypes[i] = Integer.parseInt(columnTypesAsString[i]);
}
}
if (columnTypes != null) {
// Hack warning - get JDBC column types
// TODO: Need to generalize this amongst all IPentahoResultSets
List<List<String>> data = new ArrayList<List<String>>();
for (MarshallableRow row : marshallableResultSet.getRows()) {
String[] rowData = row.getCell();
List<String> rowDataList = new ArrayList<String>(rowData.length);
for (int j = 0; j < rowData.length; j++) {
rowDataList.add(rowData[j]);
}
data.add(rowDataList);
}
serializedResultSet = new SerializedResultSet(columnTypes, marshallableResultSet.getColumnNames().getColumnName(), data);
}
} catch (Exception e) {
logger.error(Messages.getErrorString("DatasourceServiceHelper.ERROR_0001_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceHelper.ERROR_0001_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
} finally {
if (sqlConnection != null) {
sqlConnection.close();
}
}
return serializedResultSet;
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException in project data-access by pentaho.
the class InlineSqlModelerSource method generateDomain.
@Override
public Domain generateDomain(boolean dualModelingMode) throws ModelerException {
try {
BusinessData bd = datasourceImpl.generateLogicalModel(datasourceName, connectionName, dbType, query, "10");
Domain domain = bd.getDomain();
return domain;
} catch (DatasourceServiceException dce) {
throw new ModelerException(dce);
}
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException in project data-access by pentaho.
the class DataSourceWizardService method removeDSW.
public void removeDSW(String dswId) throws PentahoAccessControlException {
try {
ensureDataAccessPermissionCheck();
} catch (ConnectionServiceException e) {
throw new PentahoAccessControlException();
}
Domain domain = metadataDomainRepository.getDomain(dswId);
ModelerWorkspace model = createModelerWorkspace();
model.setDomain(domain);
LogicalModel logicalModel = model.getLogicalModel(ModelerPerspective.ANALYSIS);
if (logicalModel == null) {
logicalModel = model.getLogicalModel(ModelerPerspective.REPORTING);
}
if (logicalModel.getProperty(MONDRIAN_CATALOG_REF) != null) {
String catalogRef = (String) logicalModel.getProperty(MONDRIAN_CATALOG_REF);
try {
mondrianCatalogService.removeCatalog(catalogRef, getSession());
} catch (MondrianCatalogServiceException e) {
logger.warn("Failed to remove mondrian catalog", e);
}
}
try {
dswService.deleteLogicalModel(domain.getId(), logicalModel.getId());
} catch (DatasourceServiceException ex) {
logger.warn("Failed to remove logical model", ex);
}
metadataDomainRepository.removeDomain(dswId);
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException in project data-access by pentaho.
the class DataSourceWizardService method createMondrianDswBundle.
/**
* Generate a mondrian schema from the model and create the appropriate import bundle
* @param domain domain with olap model
* @return import bundle
* @throws DatasourceServiceException
* @throws Exception If schema generation fails
*/
protected IPlatformImportBundle createMondrianDswBundle(Domain domain, RepositoryFileAclDto acl) throws DatasourceServiceException, DswPublishValidationException, IOException {
final String analysisDomainId = toAnalysisDomainId(domain.getId());
final String dataSource = ModelerService.getMondrianDatasource(domain);
// get olap logical model
final String locale = Locale.getDefault().toString();
ModelerWorkspace workspace = new ModelerWorkspace(new ModelerWorkspaceHelper(locale), dswService.getGeoContext());
workspace.setModelName(analysisDomainId);
workspace.setDomain(domain);
LogicalModel olapModel = workspace.getLogicalModel(ModelerPerspective.ANALYSIS);
if (olapModel == null) {
throw new IllegalArgumentException("No analysis model in xmi.");
}
// reference schema in xmi
olapModel.setProperty(MONDRIAN_CATALOG_REF, analysisDomainId);
// generate schema
MondrianModelExporter exporter = new MondrianModelExporter(olapModel, locale);
exporter.updateModelToNewDomainName(analysisDomainId);
String mondrianSchema = null;
try {
mondrianSchema = exporter.createMondrianModelXML();
} catch (Exception e) {
throw new DswPublishValidationException(Type.INVALID_XMI, e.getMessage());
}
// create bundle
final RepositoryFileImportBundle.Builder builder = new RepositoryFileImportBundle.Builder().input(IOUtils.toInputStream(mondrianSchema, ENCODING)).name(MONDRIAN_SCHEMA_NAME).charSet(ENCODING).overwriteFile(true).mime(MONDRIAN_MIME).withParam(IMPORT_DOMAIN_ID, analysisDomainId).withParam(MONDRIAN_CONNECTION_PARAM, "DataSource=" + dataSource);
if (acl != null) {
builder.acl(repositoryFileAclAdapter.unmarshal(acl)).applyAclSettings(true);
}
return builder.build();
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException 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;
}
Aggregations