Search in sources :

Example 76 with Database

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

the class TransTest method testEndProcessing_StatusCalculation_Stopped.

/**
 * <p>PDI-18458: A Stopped transformation would be logged as 'Running'.</p>
 *
 * @see #testEndProcessing_StatusCalculation_Base()
 * @see #testEndProcessing_StatusCalculation_Finished()
 * @see #testEndProcessing_StatusCalculation_Paused()
 * @see #testEndProcessing_StatusCalculation_Running()
 */
@Test
public void testEndProcessing_StatusCalculation_Stopped() throws Exception {
    Database database = testEndProcessing_StatusCalculation_Base();
    // Set 'Stopped'
    trans.setStopped(true);
    int allCount = 0;
    for (boolean finished : new boolean[] { false, true }) {
        for (boolean initializing : new boolean[] { false, true }) {
            for (boolean paused : new boolean[] { false, true }) {
                for (boolean preparing : new boolean[] { false, true }) {
                    for (boolean running : new boolean[] { false, true }) {
                        trans.setFinished(finished);
                        trans.setInitializing(initializing);
                        trans.setPaused(paused);
                        trans.setPreparing(preparing);
                        trans.setRunning(running);
                        trans.fireTransFinishedListeners();
                        ++allCount;
                    }
                }
            }
        }
    }
    // All cases should result in status being 'Stopped'.
    verify(database, times(allCount)).writeLogRecord(meta.getTransLogTable(), LogStatus.STOP, trans, null);
}
Also used : Database(org.pentaho.di.core.database.Database) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 77 with Database

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

the class TransTest method testEndProcessing_StatusCalculation_Running.

/**
 * <p>PDI-18458: A Stopped transformation would be logged as 'Running'.</p>
 *
 * @see #testEndProcessing_StatusCalculation_Base()
 * @see #testEndProcessing_StatusCalculation_Finished()
 * @see #testEndProcessing_StatusCalculation_Paused()
 * @see #testEndProcessing_StatusCalculation_Stopped()
 */
@Test
public void testEndProcessing_StatusCalculation_Running() throws Exception {
    Database database = testEndProcessing_StatusCalculation_Base();
    // It can't be 'Finished', 'Paused' nor 'Stopped'
    trans.setFinished(false);
    trans.setPaused(false);
    trans.setStopped(false);
    int allCount = 0;
    for (boolean initializing : new boolean[] { false, true }) {
        for (boolean preparing : new boolean[] { false, true }) {
            for (boolean running : new boolean[] { false, true }) {
                trans.setInitializing(initializing);
                trans.setPreparing(preparing);
                trans.setRunning(running);
                trans.fireTransFinishedListeners();
                ++allCount;
            }
        }
    }
    // All cases should result in status being 'Running'.
    verify(database, times(allCount)).writeLogRecord(meta.getTransLogTable(), LogStatus.RUNNING, trans, null);
}
Also used : Database(org.pentaho.di.core.database.Database) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 78 with Database

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

the class InsertUpdateIT method setUp.

@Override
@Before
public void setUp() throws Exception {
    KettleEnvironment.init();
    /* SET UP TRANSFORMATION */
    // Create a new transformation...
    TransMeta transMeta = new TransMeta();
    transMeta.setName("insert/update test");
    // Add the database connections
    for (int i = 0; i < databasesXML.length; i++) {
        DatabaseMeta databaseMeta = new DatabaseMeta(databasesXML[i]);
        transMeta.addDatabase(databaseMeta);
    }
    DatabaseMeta dbInfo = transMeta.findDatabase("db");
    /* SET UP DATABASE */
    // Create target table
    db = new Database(transMeta, dbInfo);
    db.connect();
    String source = db.getCreateTableStatement(TARGET_TABLE, getTargetTableRowMeta(), null, false, null, true);
    db.execStatement(source);
    // populate target table
    for (String sql : insertStatement) {
        db.execStatement(sql);
    }
    /* SET UP TRANSFORMATION STEPS */
    PluginRegistry registry = PluginRegistry.getInstance();
    // create an injector step...
    String injectorStepName = "injector step";
    InjectorMeta im = new InjectorMeta();
    // Set the information of the injector.
    String injectorPid = registry.getPluginId(StepPluginType.class, im);
    StepMeta injectorStep = new StepMeta(injectorPid, injectorStepName, im);
    transMeta.addStep(injectorStep);
    // create the update step...
    String updateStepName = "insert/update [" + TARGET_TABLE + "]";
    insupd = new InsertUpdateMeta();
    insupd.setDatabaseMeta(transMeta.findDatabase("db"));
    insupd.setTableName(TARGET_TABLE);
    insupd.setUpdateLookup(new String[] { "VALUE", "ROW_ORDER" });
    insupd.setUpdateStream(new String[] { "VALUE", "ROW_ORDER" });
    insupd.setUpdate(new Boolean[] { true, false });
    String fromid = registry.getPluginId(StepPluginType.class, insupd);
    StepMeta updateStep = new StepMeta(fromid, updateStepName, insupd);
    updateStep.setDescription("insert/update data in table [" + TARGET_TABLE + "] on database [" + dbInfo + "]");
    transMeta.addStep(updateStep);
    TransHopMeta hi = new TransHopMeta(injectorStep, updateStep);
    transMeta.addTransHop(hi);
    /* PREPARE TRANSFORMATION EXECUTION */
    trans = new Trans(transMeta);
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(updateStepName, 0);
    rc = new RowStepCollector();
    si.addRowListener(rc);
    rp = trans.addRowProducer(injectorStepName, 0);
}
Also used : RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) StepInterface(org.pentaho.di.trans.step.StepInterface) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) Database(org.pentaho.di.core.database.Database) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans) Before(org.junit.Before)

Example 79 with Database

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

the class DimensionLookupIT method prepareMocksForInsertTest.

public void prepareMocksForInsertTest() {
    mockDimensionLookupData.schemaTable = "testSchemaTable";
    ValueMetaInterface mockKeyValueMeta = mock(ValueMetaInterface.class);
    when(mockDimensionLookupMeta.getDatabaseMeta()).thenReturn(mockDatabaseMeta);
    when(mockDatabaseMeta.quoteField(anyString())).thenAnswer(new Answer<String>() {

        public String answer(InvocationOnMock invocation) throws Throwable {
            return "\"" + invocation.getArguments()[0] + "\"";
        }
    });
    String keyField = "testKeyField";
    when(mockDimensionLookupMeta.getKeyField()).thenReturn(keyField);
    when(mockDimensionLookupMeta.getVersionField()).thenReturn("testVersionField");
    when(mockDimensionLookupMeta.getDateFrom()).thenReturn("1900-01-01");
    when(mockDimensionLookupMeta.getDateTo()).thenReturn("1901-01-01");
    when(mockDimensionLookupMeta.getKeyLookup()).thenReturn(new String[] {});
    when(mockDimensionLookupMeta.getFieldLookup()).thenReturn(new String[] {});
    when(mockDimensionLookupMeta.getFieldUpdate()).thenReturn(new int[] {});
    mockDimensionLookupData.keynrs = new int[] {};
    mockDimensionLookupData.fieldnrs = new int[] {};
    Database mockDatabase = mock(Database.class);
    when(mockDatabase.getConnection()).thenReturn(mockConnection);
    mockDimensionLookupData.db = mockDatabase;
    when(mockKeyValueMeta.getName()).thenReturn("testKey");
    when(mockOutputRowMeta.getValueMeta(0)).thenReturn(mockKeyValueMeta);
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) Database(org.pentaho.di.core.database.Database) Matchers.anyString(org.mockito.Matchers.anyString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 80 with Database

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

the class ExecSQLRowMeta method check.

public void check(List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore) {
    CheckResult cr;
    if (databaseMeta != null) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "ExecSQLRowMeta.CheckResult.ConnectionExists"), stepMeta);
        remarks.add(cr);
        Database db = new Database(loggingObject, databaseMeta);
        // keep track of it for cancelling purposes...
        databases = new Database[] { db };
        try {
            db.connect();
            cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "ExecSQLRowMeta.CheckResult.DBConnectionOK"), stepMeta);
            remarks.add(cr);
            if (sqlField != null && sqlField.length() != 0) {
                cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "ExecSQLRowMeta.CheckResult.SQLFieldNameEntered"), stepMeta);
            } else {
                cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "ExecSQLRowMeta.CheckResult.SQLFieldNameMissing"), stepMeta);
            }
            remarks.add(cr);
        } catch (KettleException e) {
            cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "ExecSQLRowMeta.CheckResult.ErrorOccurred") + e.getMessage(), stepMeta);
            remarks.add(cr);
        } finally {
            db.disconnect();
        }
    } else {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "ExecSQLRowMeta.CheckResult.ConnectionNeeded"), stepMeta);
        remarks.add(cr);
    }
    if (input.length > 0) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "ExecSQLRowMeta.CheckResult.StepReceivingInfoOK"), stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "ExecSQLRowMeta.CheckResult.NoInputReceivedError"), stepMeta);
        remarks.add(cr);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) CheckResult(org.pentaho.di.core.CheckResult) Database(org.pentaho.di.core.database.Database)

Aggregations

Database (org.pentaho.di.core.database.Database)238 KettleException (org.pentaho.di.core.exception.KettleException)135 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)90 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)82 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)62 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)46 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)32 KettleStepException (org.pentaho.di.core.exception.KettleStepException)30 MessageBox (org.eclipse.swt.widgets.MessageBox)28 CheckResult (org.pentaho.di.core.CheckResult)25 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)25 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)24 RowMeta (org.pentaho.di.core.row.RowMeta)22 SQLStatement (org.pentaho.di.core.SQLStatement)21 EnterSelectionDialog (org.pentaho.di.ui.core.dialog.EnterSelectionDialog)21 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)18 KettleValueException (org.pentaho.di.core.exception.KettleValueException)17 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)16 ColumnInfo (org.pentaho.di.ui.core.widget.ColumnInfo)15