use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryDatabaseDelegate method insertDatabase.
public synchronized ObjectId insertDatabase(String name, String type, String access, String host, String dbname, String port, String user, String pass, String servername, String data_tablespace, String index_tablespace) throws KettleException {
ObjectId id = repository.connectionDelegate.getNextDatabaseID();
ObjectId id_database_type = getDatabaseTypeID(type);
if (id_database_type == null) {
// New support database type: add it!
id_database_type = repository.connectionDelegate.getNextDatabaseTypeID();
String tablename = KettleDatabaseRepository.TABLE_R_DATABASE_TYPE;
RowMetaInterface tableMeta = new RowMeta();
tableMeta.addValueMeta(new ValueMetaInteger(KettleDatabaseRepository.FIELD_DATABASE_TYPE_ID_DATABASE_TYPE, 5, 0));
tableMeta.addValueMeta(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_TYPE_CODE, KettleDatabaseRepository.REP_STRING_CODE_LENGTH, 0));
tableMeta.addValueMeta(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_TYPE_DESCRIPTION, KettleDatabaseRepository.REP_STRING_LENGTH, 0));
repository.connectionDelegate.getDatabase().prepareInsert(tableMeta, tablename);
Object[] tableData = new Object[3];
int tableIndex = 0;
tableData[tableIndex++] = new LongObjectId(id_database_type).longValue();
tableData[tableIndex++] = type;
tableData[tableIndex++] = type;
repository.connectionDelegate.getDatabase().setValuesInsert(tableMeta, tableData);
repository.connectionDelegate.getDatabase().insertRow();
repository.connectionDelegate.getDatabase().closeInsert();
}
ObjectId id_database_contype = getDatabaseConTypeID(access);
RowMetaAndData table = new RowMetaAndData();
table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_DATABASE_ID_DATABASE), id);
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_NAME), name);
table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_DATABASE_ID_DATABASE_TYPE), id_database_type);
table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_DATABASE_ID_DATABASE_CONTYPE), id_database_contype);
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_HOST_NAME), host);
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_DATABASE_NAME), dbname);
table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_DATABASE_PORT), Long.valueOf(Const.toLong(port, -1)));
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_USERNAME), user);
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_PASSWORD), Encr.encryptPasswordIfNotUsingVariables(pass));
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_SERVERNAME), servername);
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_DATA_TBS), data_tablespace);
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_INDEX_TBS), index_tablespace);
repository.connectionDelegate.getDatabase().prepareInsert(table.getRowMeta(), KettleDatabaseRepository.TABLE_R_DATABASE);
repository.connectionDelegate.getDatabase().setValuesInsert(table);
repository.connectionDelegate.getDatabase().insertRow();
repository.connectionDelegate.getDatabase().closeInsert();
return id;
}
use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.
the class GetXMLDataStepAnalyzerTest method testGetInputRowMetaInterfaces_isNotInField.
@Test
public void testGetInputRowMetaInterfaces_isNotInField() throws Exception {
Map<String, RowMetaInterface> inputs = new HashMap<>();
RowMetaInterface inputRmi = mock(RowMetaInterface.class);
List<ValueMetaInterface> vmis = new ArrayList<>();
ValueMetaInterface vmi = new ValueMeta("filename");
vmis.add(vmi);
when(inputRmi.getValueMetaList()).thenReturn(vmis);
inputs.put("test", inputRmi);
doReturn(inputs).when(analyzer).getInputFields(meta);
when(parentTransMeta.getPrevStepNames(parentStepMeta)).thenReturn(null);
RowMetaInterface rowMetaInterface = new RowMeta();
rowMetaInterface.addValueMeta(vmi);
ValueMetaInterface vmi2 = new ValueMeta("otherField");
rowMetaInterface.addValueMeta(vmi2);
doReturn(rowMetaInterface).when(analyzer).getOutputFields(meta);
when(meta.isInFields()).thenReturn(false);
when(meta.getIsAFile()).thenReturn(false);
when(meta.isReadUrl()).thenReturn(false);
Map<String, RowMetaInterface> rowMetaInterfaces = analyzer.getInputRowMetaInterfaces(meta);
assertNotNull(rowMetaInterfaces);
assertEquals(2, rowMetaInterfaces.size());
RowMetaInterface metaInterface = rowMetaInterfaces.get(ExternalResourceStepAnalyzer.RESOURCE);
// the row meta interface should only have 1 value meta in it, and it should NOT be filename
assertEquals(1, metaInterface.size());
assertEquals("otherField", metaInterface.getFieldNames()[0]);
}
use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.
the class GetXMLDataTest method createResultRowMetaInterface.
public RowMetaInterface createResultRowMetaInterface() {
RowMetaInterface rm = new RowMeta();
ValueMetaInterface[] valuesMeta = { new ValueMeta("field1", ValueMeta.TYPE_STRING), new ValueMeta("objectid", ValueMeta.TYPE_STRING), new ValueMeta("sapident", ValueMeta.TYPE_STRING), new ValueMeta("quantity", ValueMeta.TYPE_STRING), new ValueMeta("merkmalname", ValueMeta.TYPE_STRING), new ValueMeta("merkmalswert", ValueMeta.TYPE_STRING) };
for (int i = 0; i < valuesMeta.length; i++) {
rm.addValueMeta(valuesMeta[i]);
}
return rm;
}
use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.
the class BaseXmlInputStreamParsingTest method before.
/**
* Initialize step info.
*/
@Before
public void before() {
meta = new XMLInputStreamMeta();
meta.setDefault();
data = new XMLInputStreamData();
data.outputRowMeta = new RowMeta();
}
use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.
the class XMLInputStreamTest method testFromPreviousStep.
@Test
public void testFromPreviousStep() throws Exception {
xmlInputStreamMeta.sourceFromInput = true;
xmlInputStreamMeta.sourceFieldName = "inf";
xmlInputStreamData.outputRowMeta = new RowMeta();
RowMeta rm = new RowMeta();
String xml = "<ProductGroup attribute1=\"v1\"/>";
ValueMetaString ms = new ValueMetaString("inf");
RowSet rs = new SingleRowRowSet();
rs.putRow(rm, new Object[] { xml });
rs.setDone();
XMLInputStream xmlInputStream = new XMLInputStream(stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans);
xmlInputStream.setInputRowMeta(rm);
xmlInputStream.getInputRowMeta().addValueMeta(ms);
xmlInputStream.addRowSetToInputRowSets(rs);
xmlInputStream.setOutputRowSets(new ArrayList<>());
xmlInputStream.init(xmlInputStreamMeta, xmlInputStreamData);
xmlInputStream.addRowListener(rl);
boolean haveRowsToRead;
do {
haveRowsToRead = !xmlInputStream.processRow(xmlInputStreamMeta, xmlInputStreamData);
} while (!haveRowsToRead);
int expectedRowNum = 1;
assertEquals(INCORRECT_XML_DATA_TYPE_DESCRIPTION_MESSAGE, "<ProductGroup attribute1=\"v1\"/>", rl.getWritten().get(expectedRowNum)[typeDescriptionPos]);
assertEquals(INCORRECT_XML_DATA_TYPE_DESCRIPTION_MESSAGE, "START_ELEMENT", rl.getWritten().get(expectedRowNum)[typeDescriptionPos + 1]);
assertEquals(INCORRECT_XML_PATH_MESSAGE, "/ProductGroup", rl.getWritten().get(expectedRowNum)[pathPos + 1]);
assertEquals(INCORRECT_XML_DATA_NAME_MESSAGE, "ProductGroup", rl.getWritten().get(expectedRowNum)[dataNamePos + 1]);
// attributes
// ATTRIBUTE_1
expectedRowNum++;
assertEquals(INCORRECT_XML_DATA_TYPE_DESCRIPTION_MESSAGE, "ATTRIBUTE", rl.getWritten().get(expectedRowNum)[typeDescriptionPos + 1]);
assertEquals(INCORRECT_XML_PATH_MESSAGE, "/ProductGroup", rl.getWritten().get(expectedRowNum)[pathPos + 1]);
assertEquals(INCORRECT_XML_DATA_NAME_MESSAGE, "attribute1", rl.getWritten().get(expectedRowNum)[dataNamePos + 1]);
assertEquals(INCORRECT_XML_DATA_VALUE_MESSAGE, "v1", rl.getWritten().get(expectedRowNum)[dataValue + 1]);
// check EndElement for the ProductGroup element
expectedRowNum++;
assertEquals(INCORRECT_XML_DATA_TYPE_DESCRIPTION_MESSAGE, "END_ELEMENT", rl.getWritten().get(expectedRowNum)[typeDescriptionPos + 1]);
assertEquals(INCORRECT_XML_PATH_MESSAGE, "/ProductGroup", rl.getWritten().get(expectedRowNum)[pathPos + 1]);
assertEquals(INCORRECT_XML_DATA_NAME_MESSAGE, "ProductGroup", rl.getWritten().get(expectedRowNum)[dataNamePos + 1]);
}
Aggregations