Search in sources :

Example 21 with DatabaseInterface

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

the class TableOutputExternalResourceConsumerTest method testGetResourcesFromMeta_runtime.

@Test
public void testGetResourcesFromMeta_runtime() 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_RUNTIME));
    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 DatabaseInterface

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

the class ExternalResourceInfoFactoryTest method testCreateDatabaseResource.

@Test
public void testCreateDatabaseResource() throws Exception {
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    when(dbMeta.getName()).thenReturn("myConnection");
    when(dbMeta.getDescription()).thenReturn("Description");
    DatabaseInterface dbInterface = mock(DatabaseInterface.class);
    when(dbMeta.getDatabaseInterface()).thenReturn(dbInterface);
    when(dbMeta.getAccessType()).thenReturn(DatabaseMeta.TYPE_ACCESS_NATIVE);
    when(dbMeta.getAccessTypeDesc()).thenReturn("Native");
    IExternalResourceInfo resourceInfo = ExternalResourceInfoFactory.createDatabaseResource(dbMeta);
    assertTrue(resourceInfo.isInput());
    resourceInfo = ExternalResourceInfoFactory.createDatabaseResource(dbMeta, false);
    assertFalse(resourceInfo.isInput());
    when(dbMeta.getAccessType()).thenReturn(DatabaseMeta.TYPE_ACCESS_JNDI);
    when(dbMeta.getAccessTypeDesc()).thenReturn("JNDI");
    resourceInfo = ExternalResourceInfoFactory.createDatabaseResource(dbMeta);
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Example 23 with DatabaseInterface

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

the class JdbcResourceInfoTest method testDbMetaVarPort.

@Test
public void testDbMetaVarPort() throws Exception {
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    DatabaseInterface dbInterface = mock(DatabaseInterface.class);
    when(dbMeta.getDatabaseInterface()).thenReturn(dbInterface);
    when(dbMeta.getAccessTypeDesc()).thenReturn("Native");
    final VariableSpace vs = new Variables();
    when(dbMeta.getDatabasePortNumberString()).thenReturn("${port_var}");
    when(dbMeta.environmentSubstitute(any(String.class))).thenAnswer(new Answer<String>() {

        public String answer(InvocationOnMock invocation) throws Throwable {
            return vs.environmentSubstitute((String) invocation.getArguments()[0]);
        }
    });
    // check if var replaced
    vs.setVariable("port_var", "4321");
    JdbcResourceInfo jdbcResourceInfo = new JdbcResourceInfo(dbMeta);
    assertEquals(jdbcResourceInfo.getPort(), new Integer(4321));
    // check no exception when empty
    vs.setVariable("port_var", "");
    jdbcResourceInfo = new JdbcResourceInfo(dbMeta);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) VariableSpace(org.pentaho.di.core.variables.VariableSpace) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Example 24 with DatabaseInterface

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

the class JdbcResourceInfoTest method testConstructorDatabaseMeta.

@Test(expected = IllegalArgumentException.class)
public void testConstructorDatabaseMeta() {
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    when(dbMeta.getName()).thenReturn("myConnection");
    when(dbMeta.getDescription()).thenReturn("Description");
    DatabaseInterface dbInterface = mock(DatabaseInterface.class);
    when(dbInterface.getPluginId()).thenReturn("myPlugin");
    when(dbMeta.getDatabaseInterface()).thenReturn(dbInterface);
    when(dbMeta.getAccessType()).thenReturn(DatabaseMeta.TYPE_ACCESS_JNDI);
    jdbcResourceInfo = new JdbcResourceInfo(dbMeta);
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Example 25 with DatabaseInterface

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

the class TableOutput method init.

public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
    meta = (TableOutputMeta) smi;
    data = (TableOutputData) sdi;
    if (super.init(smi, sdi)) {
        try {
            data.commitSize = Integer.parseInt(environmentSubstitute(meta.getCommitSize()));
            data.databaseMeta = meta.getDatabaseMeta();
            DatabaseInterface dbInterface = data.databaseMeta.getDatabaseInterface();
            // Batch updates are not supported on PostgreSQL (and look-a-likes)
            // together with error handling (PDI-366).
            // For these situations we can use savepoints to help out.
            // 
            data.useSafePoints = data.databaseMeta.getDatabaseInterface().useSafePoints() && getStepMeta().isDoingErrorHandling();
            // Get the boolean that indicates whether or not we can/should release
            // savepoints during data load.
            // 
            data.releaseSavepoint = dbInterface.releaseSavepoint();
            // Disable batch mode in case
            // - we use an unlimited commit size
            // - if we need to pick up auto-generated keys
            // - if you are running the transformation as a single database transaction (unique connections)
            // - if we are reverting to save-points
            // 
            data.batchMode = meta.useBatchUpdate() && data.commitSize > 0 && !meta.isReturningGeneratedKeys() && !getTransMeta().isUsingUniqueConnections() && !data.useSafePoints;
            // 
            if (getStepMeta().isDoingErrorHandling() && !dbInterface.supportsErrorHandlingOnBatchUpdates()) {
                log.logMinimal(BaseMessages.getString(PKG, "TableOutput.Warning.ErrorHandlingIsNotFullySupportedWithBatchProcessing"));
            }
            if (meta.getDatabaseMeta() == null) {
                throw new KettleException(BaseMessages.getString(PKG, "TableOutput.Exception.DatabaseNeedsToBeSelected"));
            }
            if (meta.getDatabaseMeta() == null) {
                logError(BaseMessages.getString(PKG, "TableOutput.Init.ConnectionMissing", getStepname()));
                return false;
            }
            data.db = new Database(this, meta.getDatabaseMeta());
            data.db.shareVariablesWith(this);
            if (getTransMeta().isUsingUniqueConnections()) {
                synchronized (getTrans()) {
                    data.db.connect(getTrans().getTransactionId(), getPartitionID());
                }
            } else {
                data.db.connect(getPartitionID());
            }
            if (log.isBasic()) {
                logBasic("Connected to database [" + meta.getDatabaseMeta() + "] (commit=" + data.commitSize + ")");
            }
            // 
            if (data.commitSize == 0) {
                data.commitSize = Integer.MAX_VALUE;
            }
            data.db.setCommit(data.commitSize);
            if (!meta.isPartitioningEnabled() && !meta.isTableNameInField()) {
                data.tableName = environmentSubstitute(meta.getTableName());
            }
            return true;
        } catch (KettleException e) {
            logError("An error occurred intialising this step: " + e.getMessage());
            stopAll();
            setErrors(1);
        }
    }
    return false;
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) KettleException(org.pentaho.di.core.exception.KettleException) Database(org.pentaho.di.core.database.Database)

Aggregations

DatabaseInterface (org.pentaho.di.core.database.DatabaseInterface)35 Test (org.junit.Test)22 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)16 MySQLDatabaseMeta (org.pentaho.di.core.database.MySQLDatabaseMeta)7 ResultSetMetaData (java.sql.ResultSetMetaData)5 ResultSet (java.sql.ResultSet)4 MariaDBDatabaseMeta (org.pentaho.di.core.database.MariaDBDatabaseMeta)4 NetezzaDatabaseMeta (org.pentaho.di.core.database.NetezzaDatabaseMeta)4 Vertica5DatabaseMeta (org.pentaho.di.core.database.Vertica5DatabaseMeta)4 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 GenericDatabaseMeta (org.pentaho.di.core.database.GenericDatabaseMeta)3 PacketTooBigException (com.mysql.jdbc.PacketTooBigException)2 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)2 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)2 TableOutputMeta (org.pentaho.di.trans.steps.tableoutput.TableOutputMeta)2 AnalysisContext (org.pentaho.metaverse.api.AnalysisContext)2 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)2 XulTextbox (org.pentaho.ui.xul.components.XulTextbox)2 MysqlDataTruncation (com.mysql.jdbc.MysqlDataTruncation)1