Search in sources :

Example 6 with DatabaseMeta

use of org.pentaho.di.core.database.DatabaseMeta in project data-access by pentaho.

the class MultitableDatasourceService method retrieveSchemas.

public List<String> retrieveSchemas(IDatabaseConnection connection) throws DatasourceServiceException {
    List<String> schemas = new ArrayList<String>();
    try {
        DatabaseMeta databaseMeta = this.getDatabaseMeta(connection);
        Database database = new Database(null, databaseMeta);
        database.connect();
        Map<String, Collection<String>> tableMap = database.getTableMap(null, this.isDataServicesConnection(connection) ? new HashMap<String, String>() {

            {
                put("STREAMING", "N");
            }
        } : null);
        // database.getSchemas()
        Set<String> schemaNames = tableMap.keySet();
        schemas.addAll(schemaNames);
        database.disconnect();
    } catch (KettleDatabaseException e) {
        logger.error("Error creating database object", e);
        throw new DatasourceServiceException(e);
    } catch (ConnectionServiceException e) {
        logger.error("Error getting database meta", e);
        throw new DatasourceServiceException(e);
    }
    return schemas;
}
Also used : ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) HashMap(java.util.HashMap) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) ArrayList(java.util.ArrayList) Database(org.pentaho.di.core.database.Database) Collection(java.util.Collection) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 7 with DatabaseMeta

use of org.pentaho.di.core.database.DatabaseMeta in project data-access by pentaho.

the class MultitableDatasourceService method serializeJoins.

public IDatasourceSummary serializeJoins(MultiTableDatasourceDTO dto, IDatabaseConnection connection) throws DatasourceServiceException {
    try {
        ModelerService modelerService = new ModelerService();
        modelerService.initKettle();
        DSWDatasourceServiceImpl datasourceService = new DSWDatasourceServiceImpl();
        GeoContext geoContext = datasourceService.getGeoContext();
        DatabaseMeta databaseMeta = this.getDatabaseMeta(connection);
        MultiTableModelerSource multiTable = new MultiTableModelerSource(databaseMeta, dto.getSchemaModel(), dto.getDatasourceName(), dto.getSelectedTables(), geoContext);
        Domain domain = multiTable.generateDomain(dto.isDoOlap());
        String modelState = serializeModelState(dto);
        for (LogicalModel lm : domain.getLogicalModels()) {
            lm.setProperty("datasourceModel", modelState);
            lm.setProperty("DatasourceType", "MULTI-TABLE-DS");
            // BISERVER-6450 - add security settings to the logical model
            applySecurity(lm);
        }
        modelerService.serializeModels(domain, dto.getDatasourceName(), dto.isDoOlap());
        QueryDatasourceSummary summary = new QueryDatasourceSummary();
        summary.setDomain(domain);
        return summary;
    } catch (Exception e) {
        logger.error("Error serializing joins", e);
        throw new DatasourceServiceException(e);
    }
}
Also used : MultiTableModelerSource(org.pentaho.agilebi.modeler.util.MultiTableModelerSource) LogicalModel(org.pentaho.metadata.model.LogicalModel) QueryDatasourceSummary(org.pentaho.platform.dataaccess.datasource.wizard.sources.query.QueryDatasourceSummary) Domain(org.pentaho.metadata.model.Domain) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) GeoContext(org.pentaho.agilebi.modeler.geo.GeoContext) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 8 with DatabaseMeta

use of org.pentaho.di.core.database.DatabaseMeta in project data-access by pentaho.

the class MultitableDatasourceService method getDatabaseMeta.

private DatabaseMeta getDatabaseMeta(IDatabaseConnection connection) throws ConnectionServiceException {
    if (this.connectionServiceImpl == null) {
        return this.databaseMeta;
    }
    // DatabaseConnection objects may be de-serialized from the client and missing extra parameters and attributes.
    // Resolve the connection by name through ConnectionService before use.
    // All public methods should use getDatabaseMeta to guarantee accurate connection info.
    // NOTE: We want to retrieve the connection again later, so we don't want an unsanitized name here
    connection = connectionServiceImpl.getConnectionByName(connection.getName(), false);
    connection.setPassword(ConnectionServiceHelper.getConnectionPassword(connection.getName(), connection.getPassword()));
    DatabaseMeta dbmeta = DatabaseUtil.convertToDatabaseMeta(connection);
    dbmeta.getDatabaseInterface().setQuoteAllFields(// This line probably shouldn't be here.  It overrides the "Quote all in Database" checkbox
    true);
    return dbmeta;
}
Also used : DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Example 9 with DatabaseMeta

use of org.pentaho.di.core.database.DatabaseMeta in project data-access by pentaho.

the class SerializeMultiTableServiceIT method getDatabaseMeta.

private DatabaseMeta getDatabaseMeta() {
    DatabaseMeta database = new DatabaseMeta();
    try {
        // database.setDatabaseInterface(new HypersonicDatabaseMeta());
        // $NON-NLS-1$
        database.setDatabaseType("Hypersonic");
        // database.setUsername("sa");//$NON-NLS-1$
        // database.setPassword("");//$NON-NLS-1$
        database.setAccessType(DatabaseMeta.TYPE_ACCESS_JNDI);
        // database.setHostname(".");
        // $NON-NLS-1$
        database.setDBName("SampleData");
        // database.setDBPort("9001");//$NON-NLS-1$
        // $NON-NLS-1$
        database.setName("SampleData");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return database;
}
Also used : DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException) DataAccessException(org.springframework.dao.DataAccessException) DuplicateDatasourceException(org.pentaho.platform.api.repository.datasource.DuplicateDatasourceException) NonExistingDatasourceException(org.pentaho.platform.api.repository.datasource.NonExistingDatasourceException)

Example 10 with DatabaseMeta

use of org.pentaho.di.core.database.DatabaseMeta in project data-access by pentaho.

the class SerializeMultiTableServiceIT method testSerialize.

@Test
public void testSerialize() throws Exception {
    if (ModelerMessagesHolder.getMessages() == null) {
        ModelerMessagesHolder.setMessages(new SpoonModelerMessages());
    }
    try {
        KettleEnvironment.init();
        Props.init(Props.TYPE_PROPERTIES_EMPTY);
    } catch (Exception e) {
    // may already be initialized by another test
    }
    login("suzy", "", false);
    String solutionStorage = AgileHelper.getDatasourceSolutionStorage();
    String path = solutionStorage + RepositoryFile.SEPARATOR + "resources" + RepositoryFile.SEPARATOR + "metadata" + // $NON-NLS-1$  //$NON-NLS-2$
    RepositoryFile.SEPARATOR;
    String olapPath = null;
    IApplicationContext appContext = PentahoSystem.getApplicationContext();
    if (appContext != null) {
        path = PentahoSystem.getApplicationContext().getSolutionPath(path);
        olapPath = PentahoSystem.getApplicationContext().getSolutionPath(// $NON-NLS-1$  //$NON-NLS-2$
        "system" + RepositoryFile.SEPARATOR + "olap" + RepositoryFile.SEPARATOR);
    }
    // $NON-NLS-1$
    File olap1 = new File(olapPath + "datasources.xml");
    // $NON-NLS-1$
    File olap2 = new File(olapPath + "tmp_datasources.xml");
    FileUtils.copyFile(olap1, olap2);
    DatabaseMeta database = getDatabaseMeta();
    MultiTableModelerSource multiTable = new MultiTableModelerSource(database, getSchema(), database.getName(), Arrays.asList("CUSTOMERS", "PRODUCTS", "CUSTOMERNAME", "PRODUCTCODE"));
    Domain domain = multiTable.generateDomain();
    List<OlapDimension> olapDimensions = new ArrayList<OlapDimension>();
    OlapDimension dimension = new OlapDimension();
    // $NON-NLS-1$
    dimension.setName("test");
    dimension.setTimeDimension(false);
    olapDimensions.add(dimension);
    // $NON-NLS-1$
    domain.getLogicalModels().get(0).setProperty("olap_dimensions", olapDimensions);
    ModelerService service = new ModelerService();
    // $NON-NLS-1$
    service.serializeModels(domain, "test_file");
    Assert.assertEquals((String) domain.getLogicalModels().get(0).getProperty("MondrianCatalogRef"), "SampleData");
}
Also used : MultiTableModelerSource(org.pentaho.agilebi.modeler.util.MultiTableModelerSource) SpoonModelerMessages(org.pentaho.agilebi.modeler.util.SpoonModelerMessages) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) Domain(org.pentaho.metadata.model.Domain) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) OlapDimension(org.pentaho.metadata.model.olap.OlapDimension) ModelerService(org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ModelerService) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException) DataAccessException(org.springframework.dao.DataAccessException) DuplicateDatasourceException(org.pentaho.platform.api.repository.datasource.DuplicateDatasourceException) NonExistingDatasourceException(org.pentaho.platform.api.repository.datasource.NonExistingDatasourceException) Test(org.junit.Test)

Aggregations

DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)522 Test (org.junit.Test)133 KettleException (org.pentaho.di.core.exception.KettleException)131 Database (org.pentaho.di.core.database.Database)88 MessageBox (org.eclipse.swt.widgets.MessageBox)66 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)63 TransMeta (org.pentaho.di.trans.TransMeta)57 StepMeta (org.pentaho.di.trans.step.StepMeta)54 ArrayList (java.util.ArrayList)53 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)48 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)44 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)42 SlaveServer (org.pentaho.di.cluster.SlaveServer)33 IMetaStore (org.pentaho.metastore.api.IMetaStore)30 ObjectId (org.pentaho.di.repository.ObjectId)29 DatabaseExplorerDialog (org.pentaho.di.ui.core.database.dialog.DatabaseExplorerDialog)29 JobMeta (org.pentaho.di.job.JobMeta)26 TransHopMeta (org.pentaho.di.trans.TransHopMeta)26 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)24 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)24