Search in sources :

Example 6 with SerializedResultSet

use of org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet 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;
}
Also used : QueryValidationException(org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException) SerializedResultSet(org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 7 with SerializedResultSet

use of org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet 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);
    }
}
Also used : SQLModelGeneratorException(org.pentaho.metadata.util.SQLModelGeneratorException) ModelerException(org.pentaho.agilebi.modeler.ModelerException) SerializedResultSet(org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) ModelerException(org.pentaho.agilebi.modeler.ModelerException) SQLException(java.sql.SQLException) QueryValidationException(org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SQLModelGeneratorException(org.pentaho.metadata.util.SQLModelGeneratorException) 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) Domain(org.pentaho.metadata.model.Domain) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 8 with SerializedResultSet

use of org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet in project data-access by pentaho.

the class DSWDatasourceServiceImplTest method testDoPreview_NullQuery.

@Test(expected = DatasourceServiceException.class)
public void testDoPreview_NullQuery() throws DatasourceServiceException {
    doReturn(true).when(dswService).hasDataAccessPermission();
    SerializedResultSet result = dswService.doPreview(CONNECTION_NAME, null, PREVIEW_LIMIT);
    try {
        verify(dswService).executeQuery("[connection 接続 <;>!@#$%^&*()_-=+.,]", VALID_QUERY, PREVIEW_LIMIT);
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertNotNull(result);
    assertArrayEquals(columns, result.getColumns());
    assertArrayEquals(columnTypes, result.getColumnTypes());
}
Also used : SerializedResultSet(org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet) ModelerException(org.pentaho.agilebi.modeler.ModelerException) 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) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) Test(org.junit.Test)

Example 9 with SerializedResultSet

use of org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet in project data-access by pentaho.

the class DatasourceInMemoryServiceHelperTest method testGetSerializeableResultSet.

@Test
public void testGetSerializeableResultSet() throws DatasourceServiceException, SQLException {
    SerializedResultSet rs = DatasourceInMemoryServiceHelper.getSerializeableResultSet(GENERIC_CONN_DRIVER_CLASS, SAMPLE_VALID_QUERY, 10, null);
    assertNotNull(rs);
    verify(sqlConnection).close();
}
Also used : SerializedResultSet(org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet) Test(org.junit.Test)

Example 10 with SerializedResultSet

use of org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet in project data-access by pentaho.

the class DSWDatasourceServiceImplTest method testDoPreview.

@Test
public void testDoPreview() throws DatasourceServiceException {
    doReturn(true).when(dswService).hasDataAccessPermission();
    SerializedResultSet result = dswService.doPreview(CONNECTION_NAME, VALID_QUERY, PREVIEW_LIMIT);
    try {
        verify(dswService).executeQuery("[connection 接続 <;>!@#$%^&*()_-=+.,]", VALID_QUERY, PREVIEW_LIMIT);
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertNotNull(result);
    assertArrayEquals(columns, result.getColumns());
    assertArrayEquals(columnTypes, result.getColumnTypes());
}
Also used : SerializedResultSet(org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet) ModelerException(org.pentaho.agilebi.modeler.ModelerException) 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) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) Test(org.junit.Test)

Aggregations

SerializedResultSet (org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet)13 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)10 SQLException (java.sql.SQLException)6 Domain (org.pentaho.metadata.model.Domain)6 QueryValidationException (org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException)6 ModelerException (org.pentaho.agilebi.modeler.ModelerException)5 SqlQueriesNotSupportedException (org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)4 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)4 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)4 SQLModelGenerator (org.pentaho.metadata.util.SQLModelGenerator)4 SQLModelGeneratorException (org.pentaho.metadata.util.SQLModelGeneratorException)4 BusinessData (org.pentaho.platform.dataaccess.datasource.beans.BusinessData)4 IOException (java.io.IOException)3 Test (org.junit.Test)3 MondrianCatalogServiceException (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException)3 FileNotFoundException (java.io.FileNotFoundException)2 ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)2