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