use of org.pentaho.metadata.model.SqlPhysicalModel 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);
}
use of org.pentaho.metadata.model.SqlPhysicalModel 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());
}
Aggregations