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);
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations