Search in sources :

Example 6 with SqlPhysicalTable

use of org.pentaho.metadata.model.SqlPhysicalTable in project data-access by pentaho.

the class DSWDatasourceServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    SqlDataSource dataSource = new SqlDataSource();
    dataSource.setDatabaseName(CONNECTION_NAME);
    SqlPhysicalTable sqlTable = new SqlPhysicalTable();
    sqlTable.setTargetTable(VALID_QUERY);
    SqlPhysicalModel sqlModel = new SqlPhysicalModel();
    sqlModel.addPhysicalTable(sqlTable);
    sqlModel.setDatasource(dataSource);
    analysisModel = new LogicalModel();
    analysisModel.setId(LOGICAL_MODEL_ID_ANALYSIS);
    analysisModel.setProperty(DSWDatasourceServiceImpl.LM_PROP_VISIBLE, LOGICAL_MODEL_CONTEXTNAME);
    reportingModel = new LogicalModel();
    reportingModel.setId(LOGICAL_MODEL_ID_REPORTING);
    domain2Models = new Domain();
    domain2Models.setId(DOMAIN_ID_2MODELS);
    domain2Models.addLogicalModel(analysisModel);
    domain2Models.addLogicalModel(reportingModel);
    domain2Models.setLocales(Arrays.asList(new LocaleType("en_US", "Test locale")));
    domain2Models.addPhysicalModel(sqlModel);
    Set<String> domains = new TreeSet<String>();
    domains.add(DOMAIN_ID_2MODELS);
    doReturn(domain2Models).when(domainRepository).getDomain(DOMAIN_ID_2MODELS);
    doReturn(domains).when(domainRepository).getDomainIds();
    doAnswer(new Answer<Object>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            final String modelId = (String) invocation.getArguments()[1];
            final LogicalModel modelToRemove = domain2Models.findLogicalModel(modelId);
            domain2Models.getLogicalModels().remove(modelToRemove);
            return null;
        }
    }).when(domainRepository).removeModel(anyString(), anyString());
    workspace2Models = mock(ModelerWorkspace.class);
    when(workspace2Models.getLogicalModel(ModelerPerspective.ANALYSIS)).thenReturn(analysisModel);
    when(workspace2Models.getLogicalModel(ModelerPerspective.REPORTING)).thenReturn(reportingModel);
    dswService = spy(new DSWDatasourceServiceImpl(mock(ConnectionServiceImpl.class)));
    doNothing().when(dswService).checkSqlQueriesSupported(anyString());
    dswService.setMetadataDomainRepository(domainRepository);
    Object[][] coumnHeaders = new Object[][] { columns };
    SQLMetaData metadata = mock(SQLMetaData.class);
    when(metadata.getColumnHeaders()).thenReturn(coumnHeaders);
    when(metadata.getJDBCColumnTypes()).thenReturn(columnTypes);
    IPentahoResultSet resultSet = mock(IPentahoResultSet.class);
    when(resultSet.getMetaData()).thenReturn(metadata);
    doReturn(resultSet).when(sqlConnection).executeQuery(matches("(.*" + VALID_QUERY + ".*)"));
    when(sqlConnection.executeQuery(matches("(.*" + QUERY_COLUMN_ALREADY_EXIST + ".*)"))).thenThrow(new SQLException("Reason", "S0021", 21));
    doReturn(nativeConnection).when(sqlConnection).getNativeConnection();
    MondrianCatalog catalog = mock(MondrianCatalog.class);
    doReturn(catalog).when(mondrianService).getCatalog(anyString(), any(IPentahoSession.class));
    pentahoObjectFactory = mock(IPentahoObjectFactory.class);
    when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
    when(pentahoObjectFactory.get(this.anyClass(), anyString(), any(IPentahoSession.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            if (invocation.getArguments()[0].equals(IMondrianCatalogService.class)) {
                return mondrianService;
            }
            if (invocation.getArguments()[0].equals(IPentahoConnection.class)) {
                return sqlConnection;
            }
            if (invocation.getArguments()[0].equals(IMetadataDomainRepository.class)) {
                return domainRepository;
            }
            return null;
        }
    });
    PentahoSystem.registerObjectFactory(pentahoObjectFactory);
    IPentahoSession pentahoSessionMock = mock(IPentahoSession.class);
    when(pentahoSessionMock.getName()).thenReturn("sessionName");
    PentahoSessionHolder.setSession(pentahoSessionMock);
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) SQLException(java.sql.SQLException) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) Mockito.anyString(org.mockito.Mockito.anyString) SqlPhysicalModel(org.pentaho.metadata.model.SqlPhysicalModel) SqlPhysicalTable(org.pentaho.metadata.model.SqlPhysicalTable) IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) LogicalModel(org.pentaho.metadata.model.LogicalModel) TreeSet(java.util.TreeSet) LocaleType(org.pentaho.metadata.model.concept.types.LocaleType) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IMetadataDomainRepository(org.pentaho.metadata.repository.IMetadataDomainRepository) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) SQLMetaData(org.pentaho.platform.plugin.services.connections.sql.SQLMetaData) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SqlDataSource(org.pentaho.metadata.model.SqlDataSource) Domain(org.pentaho.metadata.model.Domain) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) Before(org.junit.Before)

Example 7 with SqlPhysicalTable

use of org.pentaho.metadata.model.SqlPhysicalTable in project data-access by pentaho.

the class InlineSqlModelerSource method initialize.

public void initialize(Domain domain) throws ModelerException {
    SqlPhysicalModel model = (SqlPhysicalModel) domain.getPhysicalModels().get(0);
    SqlPhysicalTable table = model.getPhysicalTables().get(0);
    // $NON-NLS-1$
    String targetTable = (String) table.getProperty("target_table");
    if (!StringUtils.isEmpty(targetTable)) {
        domain.setId(targetTable);
    }
    this.databaseMeta = ThinModelConverter.convertToLegacy(model.getId(), model.getDatasource());
}
Also used : SqlPhysicalModel(org.pentaho.metadata.model.SqlPhysicalModel) SqlPhysicalTable(org.pentaho.metadata.model.SqlPhysicalTable)

Aggregations

SqlPhysicalModel (org.pentaho.metadata.model.SqlPhysicalModel)7 SqlPhysicalTable (org.pentaho.metadata.model.SqlPhysicalTable)7 Domain (org.pentaho.metadata.model.Domain)6 LogicalModel (org.pentaho.metadata.model.LogicalModel)6 LogicalTable (org.pentaho.metadata.model.LogicalTable)5 SqlDataSource (org.pentaho.metadata.model.SqlDataSource)5 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)5 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)4 SqlPhysicalColumn (org.pentaho.metadata.model.SqlPhysicalColumn)4 Category (org.pentaho.metadata.model.Category)3 LocaleType (org.pentaho.metadata.model.concept.types.LocaleType)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)2 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)2 AggregationType (org.pentaho.metadata.model.concept.types.AggregationType)2 BusinessData (org.pentaho.platform.dataaccess.datasource.beans.BusinessData)2 SQLException (java.sql.SQLException)1 TreeSet (java.util.TreeSet)1 Before (org.junit.Before)1