use of org.talend.designer.dbmap.external.data.ExternalDbMapEntry in project tdi-studio-se by Talend.
the class DBMapHelper method saveDataToEmf.
public static void saveDataToEmf(DBMapData emfMapperData, ExternalDbMapData externalData) {
// input
if (externalData.getInputTables() != null && !externalData.getInputTables().isEmpty()) {
for (ExternalDbMapTable table : externalData.getInputTables()) {
final InputTable persistentTable = DbmapFactory.eINSTANCE.createInputTable();
persistentTable.setMinimized(table.isMinimized());
persistentTable.setName(table.getName());
persistentTable.setAlias(table.getAlias());
persistentTable.setJoinType(table.getJoinType());
persistentTable.setTableName(table.getTableName());
if (table.getMetadataTableEntries() != null && !table.getMetadataTableEntries().isEmpty()) {
List<DBMapperTableEntry> persistentEntities = new ArrayList<DBMapperTableEntry>();
for (ExternalDbMapEntry entity : table.getMetadataTableEntries()) {
final DBMapperTableEntry emfMapperTableEntry = DbmapFactory.eINSTANCE.createDBMapperTableEntry();
emfMapperTableEntry.setExpression(entity.getExpression());
emfMapperTableEntry.setName(entity.getName());
emfMapperTableEntry.setJoin(entity.isJoin());
emfMapperTableEntry.setOperator(entity.getOperator());
persistentEntities.add(emfMapperTableEntry);
}
persistentTable.getDBMapperTableEntries().addAll(persistentEntities);
}
emfMapperData.getInputTables().add(persistentTable);
}
}
// output
if (externalData.getOutputTables() != null && !externalData.getOutputTables().isEmpty()) {
for (ExternalDbMapTable table : externalData.getOutputTables()) {
final OutputTable persistentTable = DbmapFactory.eINSTANCE.createOutputTable();
persistentTable.setMinimized(table.isMinimized());
persistentTable.setName(table.getName());
persistentTable.setTableName(table.getTableName());
if (table.getMetadataTableEntries() != null && !table.getMetadataTableEntries().isEmpty()) {
for (ExternalDbMapEntry entity : table.getMetadataTableEntries()) {
final DBMapperTableEntry emfMapperTableEntry = DbmapFactory.eINSTANCE.createDBMapperTableEntry();
emfMapperTableEntry.setExpression(entity.getExpression());
emfMapperTableEntry.setName(entity.getName());
persistentTable.getDBMapperTableEntries().add(emfMapperTableEntry);
}
// filters
if (table.getCustomWhereConditionsEntries() != null && !table.getCustomWhereConditionsEntries().isEmpty()) {
for (ExternalDbMapEntry entity : table.getCustomWhereConditionsEntries()) {
final FilterEntry persistentEntry = DbmapFactory.eINSTANCE.createFilterEntry();
persistentEntry.setName(entity.getName());
persistentEntry.setExpression(entity.getExpression());
persistentEntry.setFilterKind(FilterTableEntry.WHERE_FILTER);
persistentTable.getFilterEntries().add(persistentEntry);
}
}
if (table.getCustomOtherConditionsEntries() != null && !table.getCustomOtherConditionsEntries().isEmpty()) {
for (ExternalDbMapEntry entity : table.getCustomOtherConditionsEntries()) {
final FilterEntry persistentEntry = DbmapFactory.eINSTANCE.createFilterEntry();
persistentEntry.setName(entity.getName());
persistentEntry.setExpression(entity.getExpression());
persistentEntry.setFilterKind(FilterTableEntry.OTHER_FILTER);
persistentTable.getFilterEntries().add(persistentEntry);
}
}
}
emfMapperData.getOutputTables().add(persistentTable);
}
}
}
use of org.talend.designer.dbmap.external.data.ExternalDbMapEntry in project tdi-studio-se by Talend.
the class PostgresGenerationManagerTest method init.
private void init(String schema, String main_table, String lookup_table) {
List<IConnection> incomingConnections = new ArrayList<IConnection>();
String[] mainTableEntities = new String[] { "id", "name", "classNum" };
String[] lookupEndtities = new String[] { "id", "score" };
incomingConnections.add(mockConnection(schema, main_table, mainTableEntities));
incomingConnections.add(mockConnection(schema, lookup_table, lookupEndtities));
component.setIncomingConnections(incomingConnections);
ExternalDbMapData externalData = new ExternalDbMapData();
List<ExternalDbMapTable> inputs = new ArrayList<ExternalDbMapTable>();
List<ExternalDbMapTable> outputs = new ArrayList<ExternalDbMapTable>();
// main table
ExternalDbMapTable inputTable = new ExternalDbMapTable();
inputTable.setTableName(schema + "." + main_table);
List<ExternalDbMapEntry> entities = getMetadataEntities(mainTableEntities, new String[3]);
inputTable.setMetadataTableEntries(entities);
inputs.add(inputTable);
// lookup table
inputTable = new ExternalDbMapTable();
inputTable.setTableName(schema + "." + lookup_table);
entities = getMetadataEntities(lookupEndtities, new String[2]);
inputTable.setMetadataTableEntries(entities);
inputs.add(inputTable);
// output
ExternalDbMapTable outputTable = new ExternalDbMapTable();
outputTable.setName("grade");
List<ExternalDbMapEntry> conditions = new ArrayList<ExternalDbMapEntry>();
conditions.add(new ExternalDbMapEntry(schema + "." + main_table + ".id =3"));
outputTable.setCustomWhereConditionsEntries(conditions);
String[] names = new String[] { "id", "name", "classNum", "score" };
String[] expressions = new String[] { schema + "." + main_table + ".id", schema + "." + main_table + ".name", schema + "." + main_table + ".classNum", schema + "." + lookup_table + ".score" };
outputTable.setMetadataTableEntries(getMetadataEntities(names, expressions));
outputs.add(outputTable);
externalData.setInputTables(inputs);
externalData.setOutputTables(outputs);
component.setExternalData(externalData);
List<IMetadataTable> metadataList = new ArrayList<IMetadataTable>();
MetadataTable metadataTable = getMetadataTable(names);
metadataTable.setLabel("grade");
metadataList.add(metadataTable);
component.setMetadataList(metadataList);
Process process = mock(Process.class);
when(process.getContextManager()).thenReturn(new JobContextManager());
component.setProcess(process);
}
use of org.talend.designer.dbmap.external.data.ExternalDbMapEntry in project tdi-studio-se by Talend.
the class PostgresGenerationManagerTest method getMetadataEntities.
private List<ExternalDbMapEntry> getMetadataEntities(String[] entitiesName, String[] expressions) {
List<ExternalDbMapEntry> entities = new ArrayList<ExternalDbMapEntry>();
for (int i = 0; i < entitiesName.length; i++) {
ExternalDbMapEntry entity = new ExternalDbMapEntry();
entity.setName(entitiesName[i]);
if (i < expressions.length && !"".equals(expressions[i]) && expressions[i] != null) {
entity.setExpression(expressions[i]);
}
entities.add(entity);
}
return entities;
}
use of org.talend.designer.dbmap.external.data.ExternalDbMapEntry in project tdi-studio-se by Talend.
the class UpdateELTMapComponentCommandTest method before.
@Before
public void before() {
Process process = new Process(createProperty());
sourceNode = new Node(sourceComponent, process);
INodeConnector connector = new NodeConnector(sourceNode);
connector.setName("connector");
connector.setDefaultConnectionType(EConnectionType.FLOW_MAIN);
ArrayList<INodeConnector> connectors = new ArrayList<INodeConnector>();
connectors.add(connector);
sourceNode.setListConnector(connectors);
targetNode = new Node(targetComponent, process);
DbMapComponent component = new DbMapComponent();
targetNode.setExternalNode(component);
connection = new Connection(sourceNode, targetNode, EConnectionType.FLOW_MAIN, "connector", "meta", "oldTable", true);
inputs = (List<ExternalDbMapTable>) targetNode.getExternalData().getInputTables();
ExternalDbMapTable input = new ExternalDbMapTable();
input.setName("oldTable");
input.setTableName("oldTable");
inputs.add(input);
outputs = (List<ExternalDbMapTable>) targetNode.getExternalData().getOutputTables();
ExternalDbMapTable output = new ExternalDbMapTable();
ExternalDbMapEntry entry = new ExternalDbMapEntry("oldTable", "oldTable.column");
output.setMetadataTableEntries(new ArrayList<ExternalDbMapEntry>());
output.getMetadataTableEntries().add(entry);
outputs.add(output);
}
use of org.talend.designer.dbmap.external.data.ExternalDbMapEntry in project tdi-studio-se by Talend.
the class InputTable method initFromExternalData.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.dbmap.model.table.AbstractInOutTable#initFromExternalData(org.talend.designer.dbmap.external
* .data.ExternalMapperTable)
*/
@Override
public void initFromExternalData(ExternalDbMapTable externalMapperTable) {
boolean isAliasTable = externalMapperTable != null && externalMapperTable.getAlias() != null;
if (isAliasTable) {
// dbmap table is alias
setMetadataTable(connection.getTable().clone());
} else if (connection != null) {
// dbmap table references a physical table
setMetadataTable(connection.getTable());
}
super.initFromExternalData(externalMapperTable);
List<IMetadataColumn> columns = getMetadataTable().getListColumns();
Map<String, ExternalDbMapEntry> nameToPerTabEntry = new HashMap<String, ExternalDbMapEntry>();
if (externalMapperTable != null && externalMapperTable.getMetadataTableEntries() != null) {
for (ExternalDbMapEntry perTableEntry : externalMapperTable.getMetadataTableEntries()) {
nameToPerTabEntry.put(perTableEntry.getName(), perTableEntry);
}
}
ArrayList<IMetadataColumn> columnsToRemove = new ArrayList<IMetadataColumn>();
for (IMetadataColumn column : columns) {
InputColumnTableEntry inputEntry = (InputColumnTableEntry) getNewTableEntry(column);
ExternalDbMapEntry externalMapperTableEntry = nameToPerTabEntry.get(inputEntry.getMetadataColumn().getLabel());
// Entry match with current column
if (externalMapperTableEntry != null) {
fillInputEntry(inputEntry, externalMapperTableEntry);
nameToPerTabEntry.remove(externalMapperTableEntry.getName());
}
if (externalMapperTableEntry != null || !isAliasTable) {
dataMapTableEntries.add(inputEntry);
} else {
columnsToRemove.add(column);
}
}
columns.removeAll(columnsToRemove);
// create unmatching entries
for (ExternalDbMapEntry perTableEntry : nameToPerTabEntry.values()) {
MetadataColumn column = new MetadataColumn();
column.setLabel(perTableEntry.getName());
InputColumnTableEntry inputEntry = (InputColumnTableEntry) getNewTableEntry(column);
ExternalDbMapEntry externalMapperTableEntry = nameToPerTabEntry.get(inputEntry.getMetadataColumn().getLabel());
fillInputEntry(inputEntry, externalMapperTableEntry);
dataMapTableEntries.add(inputEntry);
columns.add(column);
}
if (externalMapperTable != null) {
joinType = mapperManager.getCurrentLanguage().getJoin(externalMapperTable.getJoinType());
if (joinType == null) {
joinType = mapperManager.getCurrentLanguage().getAvailableJoins()[0];
}
alias = externalMapperTable.getAlias();
tableName = externalMapperTable.getTableName() != null ? externalMapperTable.getTableName() : connection.getName();
}
}
Aggregations