Search in sources :

Example 21 with DatabaseMeta

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

the class TableOutputExternalResourceConsumerTest method testGetResourcesFromMeta_static.

@Test
public void testGetResourcesFromMeta_static() throws Exception {
    TableOutputMeta meta = mock(TableOutputMeta.class);
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    DatabaseInterface dbi = mock(DatabaseInterface.class);
    when(meta.getDatabaseMeta()).thenReturn(dbMeta);
    when(meta.getTableName()).thenReturn("tableName");
    when(meta.getSchemaName()).thenReturn("schemaName");
    when(meta.getParentStepMeta()).thenReturn(parentStepMeta);
    when(parentStepMeta.getParentTransMeta()).thenReturn(parentTransMeta);
    when(parentTransMeta.environmentSubstitute("tableName")).thenReturn("tableName");
    when(parentTransMeta.environmentSubstitute("schemaName")).thenReturn("schemaName");
    when(dbMeta.getAccessTypeDesc()).thenReturn("JNDI");
    when(dbMeta.getName()).thenReturn("TestConnection");
    when(dbMeta.getDescription()).thenReturn("my conn description");
    when(dbMeta.getDatabaseInterface()).thenReturn(dbi);
    when(dbi.getPluginId()).thenReturn("POSTGRESQL");
    Collection<IExternalResourceInfo> resources = consumer.getResourcesFromMeta(meta, new AnalysisContext(DictionaryConst.CONTEXT_STATIC));
    assertEquals(1, resources.size());
    IExternalResourceInfo res = resources.iterator().next();
    assertEquals("TestConnection", res.getName());
    assertEquals("tableName", res.getAttributes().get(DictionaryConst.PROPERTY_TABLE));
    assertEquals("schemaName", res.getAttributes().get(DictionaryConst.PROPERTY_SCHEMA));
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) AnalysisContext(org.pentaho.metaverse.api.AnalysisContext) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Example 22 with DatabaseMeta

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

the class AbstractMetaJsonSerializer method serializeConnections.

protected void serializeConnections(T meta, JsonGenerator json) throws IOException {
    // connections
    json.writeArrayFieldStart(JSON_PROPERTY_CONNECTIONS);
    for (DatabaseMeta dbmeta : meta.getDatabases()) {
        BaseResourceInfo resourceInfo = (BaseResourceInfo) ExternalResourceInfoFactory.createDatabaseResource(dbmeta);
        resourceInfo.setInput(true);
        json.writeObject(resourceInfo);
    }
    json.writeEndArray();
}
Also used : BaseResourceInfo(org.pentaho.metaverse.api.model.BaseResourceInfo) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Example 23 with DatabaseMeta

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

the class TransMetaJsonDeserializerTest method testDeserializeConnections.

@Test
public void testDeserializeConnections() throws Exception {
    JndiResourceInfo jndi = new JndiResourceInfo("jndi");
    jndi.setPluginId("ORACLE");
    JdbcResourceInfo jdbc = new JdbcResourceInfo("localhost", "test", 5432, "sa", "password");
    jdbc.setPluginId("POSTGRESQL");
    transMeta = spy(new TransMeta());
    root_connectionsArray.add(root_connectionsArray_Node0);
    root_connectionsArray.add(root_connectionsArray_Node1);
    when(root_connectionsArray_Node0.toString()).thenReturn("mocked jdbc");
    when(root_connectionsArray_Node0.get(IInfo.JSON_PROPERTY_CLASS)).thenReturn(root_connectionsArray_Node0_classNode);
    when(root_connectionsArray_Node0_classNode.asText()).thenReturn(JdbcResourceInfo.class.getName());
    when(root_connectionsArray_Node1.toString()).thenReturn("mocked jndi");
    when(root_connectionsArray_Node1.get(IInfo.JSON_PROPERTY_CLASS)).thenReturn(root_connectionsArray_Node1_classNode);
    when(root_connectionsArray_Node1_classNode.asText()).thenReturn(JndiResourceInfo.class.getName());
    when(mapper.readValue("mocked jdbc", JdbcResourceInfo.class)).thenReturn(jdbc);
    when(mapper.readValue("mocked jndi", JndiResourceInfo.class)).thenReturn(jndi);
    deserializer.deserializeConnections(transMeta, root, mapper);
    assertEquals(root_connectionsArray.size(), transMeta.getDatabases().size());
    for (DatabaseMeta databaseMeta : transMeta.getDatabases()) {
        assertNotNull(databaseMeta.getDatabaseInterface());
    }
}
Also used : JdbcResourceInfo(org.pentaho.metaverse.api.model.JdbcResourceInfo) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) JndiResourceInfo(org.pentaho.metaverse.api.model.JndiResourceInfo) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Example 24 with DatabaseMeta

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

the class AbstractMeta method loadSharedObject.

protected boolean loadSharedObject(SharedObjectInterface object) {
    if (object instanceof DatabaseMeta) {
        DatabaseMeta databaseMeta = (DatabaseMeta) object;
        databaseMeta.shareVariablesWith(this);
        addOrReplaceDatabase(databaseMeta);
    } else if (object instanceof SlaveServer) {
        SlaveServer slaveServer = (SlaveServer) object;
        slaveServer.shareVariablesWith(this);
        addOrReplaceSlaveServer(slaveServer);
    } else {
        return false;
    }
    return true;
}
Also used : SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Example 25 with DatabaseMeta

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

the class AbstractMeta method addDatabase.

protected void addDatabase(DatabaseMeta databaseMeta, boolean replace) {
    int index = databases.indexOf(databaseMeta);
    if (index < 0) {
        addDatabase(databaseMeta);
    } else if (replace) {
        DatabaseMeta previous = getDatabase(index);
        previous.replaceMeta(databaseMeta);
        previous.setShared(databaseMeta.isShared());
    }
    changedDatabases = true;
}
Also used : DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Point(org.pentaho.di.core.gui.Point)

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