use of org.talend.designer.dbmap.external.data.ExternalDbMapTable 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.ExternalDbMapTable 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.ExternalDbMapTable 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.ExternalDbMapTable in project tdi-studio-se by Talend.
the class DbGenerationManager method initExpression.
protected String initExpression(DbMapComponent component, ExternalDbMapEntry dbMapEntry) {
String expression = dbMapEntry.getExpression();
if (expression != null) {
List<Map<String, String>> itemNameList = null;
// MapExpressionParser mapParser = new MapExpressionParser("((\\s*(\\w+)\\s*\\.)*)(\\w+)");
// List<String> parseInTableEntryLocations = mapParser.parseInTableEntryLocations2(expression);
// for (String entryLocation : parseInTableEntryLocations) {
//
// }
// context.schema.context.table.column
// context.schema.table.column
// schema.context.table.column
// schema.table.column
// table.column
// add \\w*#* for oracle 12 , schema name start with C##
//$NON-NLS-1$
MapExpressionParser mapParser1 = new MapExpressionParser("((\\s*(\\w*#*\\w+)\\s*\\.)*)(\\w+)");
itemNameList = mapParser1.parseInTableEntryLocations2(expression);
if (itemNameList == null || itemNameList.isEmpty()) {
//$NON-NLS-1$
MapExpressionParser mapParser2 = new MapExpressionParser("\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*");
itemNameList = mapParser2.parseInTableEntryLocations(expression);
}
for (Map<String, String> itemNamemap : itemNameList) {
Set<Entry<String, String>> set = itemNamemap.entrySet();
Iterator<Entry<String, String>> ite = set.iterator();
while (ite.hasNext()) {
Entry<String, String> entry = ite.next();
String columnValue = entry.getKey();
String tableValue = entry.getValue();
String tableNameValue = tableValue;
// find original table name if tableValue is alias
String originaltableName = tableValue;
ExternalDbMapData externalData = (ExternalDbMapData) component.getExternalData();
final List<ExternalDbMapTable> inputTables = externalData.getInputTables();
for (ExternalDbMapTable inputTable : inputTables) {
if (inputTable.getAlias() != null && inputTable.getAlias().equals(tableValue)) {
originaltableName = inputTable.getTableName();
tableNameValue = inputTable.getAlias();
}
}
List<IConnection> inputConnections = (List<IConnection>) component.getIncomingConnections();
if (inputConnections == null) {
return expression;
}
for (IConnection iconn : inputConnections) {
IMetadataTable metadataTable = iconn.getMetadataTable();
String tName = iconn.getName();
if ((originaltableName.equals(tName) || tableValue.equals(tName)) && metadataTable != null) {
List<IMetadataColumn> lColumn = metadataTable.getListColumns();
String tableName = metadataTable.getTableName();
String tableColneName = tableName;
tableColneName = MetadataToolHelper.validateTableName(tableColneName);
if (tableValue.contains(".") && tableName != null) {
//$NON-NLS-1$
//$NON-NLS-1$
MapExpressionParser mapParser2 = new MapExpressionParser("\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*");
List<Map<String, String>> tableNameList = mapParser2.parseInTableEntryLocations(tableValue);
for (Map<String, String> tableNameMap : tableNameList) {
Set<Entry<String, String>> setTable = tableNameMap.entrySet();
Iterator<Entry<String, String>> iteTable = setTable.iterator();
while (iteTable.hasNext()) {
Entry<String, String> tableEntry = iteTable.next();
String tableLabel = tableEntry.getKey();
String schemaValue = tableEntry.getValue();
if (tableLabel.equals(metadataTable.getLabel()) && tableColneName.equals(tableLabel)) {
//$NON-NLS-1$//$NON-NLS-2$
tableName = tableName.replaceAll("\\$", "\\\\\\$");
//$NON-NLS-1$
expression = expression.replaceFirst(tableValue, schemaValue + "." + tableName);
}
}
}
} else if (tableName != null) {
if (tableValue.equals(metadataTable.getLabel()) && tableColneName.equals(tableValue)) {
//$NON-NLS-1$ //$NON-NLS-2$
tableName = tableName.replaceAll("\\$", "\\\\\\$");
expression = expression.replaceFirst(tableValue, tableName);
}
}
for (IMetadataColumn co : lColumn) {
if (columnValue.equals(co.getLabel())) {
String oriName = co.getOriginalDbColumnName();
// if OriginalDbColumn is empty , still use label to generate sql
if (oriName == null || "".equals(oriName)) {
//$NON-NLS-1$
continue;
}
if (expression.trim().equals(tableValue + "." + oriName)) {
continue;
}
if (expression.trim().equals(originaltableName + "." + oriName)) {
continue;
}
// if it is temp delived table, use label to generate sql
if (iconn.getLineStyle() == EConnectionType.TABLE_REF) {
continue;
}
//$NON-NLS-1$ //$NON-NLS-2$
oriName = oriName.replaceAll("\\$", "\\\\\\$");
expression = //$NON-NLS-1$
expression.replaceFirst(//$NON-NLS-1$
"\\." + co.getLabel(), //$NON-NLS-1$
"\\." + oriName);
expression = expression.replace("\"", "\\\"");
}
}
}
}
}
}
}
return expression;
}
use of org.talend.designer.dbmap.external.data.ExternalDbMapTable in project tdi-studio-se by Talend.
the class DbMapComponent method inputMetadataColumnAmountChanged.
private void inputMetadataColumnAmountChanged(IODataComponent dataComponent, IExternalNode externalNode) {
List<ColumnNameChanged> removedMetadataColumns = dataComponent.getRemoveMetadataColumns();
IExternalData iExternalData = externalNode.getExternalData();
if (iExternalData == null || removedMetadataColumns == null || removedMetadataColumns.size() == 0) {
return;
}
List<ExternalDbMapTable> metaTableList = (List<ExternalDbMapTable>) iExternalData.getInputTables();
if (metaTableList == null || metaTableList.size() == 0) {
return;
}
// in the eltmap, the input table name is same with it's input connection name
String tableName = dataComponent.getName();
if (StringUtils.isEmpty(tableName)) {
return;
}
for (ExternalDbMapTable metaTable : metaTableList) {
if (tableName.equals(metaTable.getTableName())) {
List<IExternalMapEntry> externalMapEntryList = (List<IExternalMapEntry>) metaTable.returnTableEntries();
if (externalMapEntryList == null || externalMapEntryList.size() == 0) {
continue;
}
if (removedMetadataColumns != null && 0 < removedMetadataColumns.size()) {
for (ColumnNameChanged removedMetadataColumn : removedMetadataColumns) {
if ("".equals(removedMetadataColumn.getNewName())) {
//$NON-NLS-1$
String columnName = removedMetadataColumn.getOldName();
for (int i = externalMapEntryList.size() - 1; 0 <= i; i--) {
IExternalMapEntry mapEntry = externalMapEntryList.get(i);
if (columnName.equals(mapEntry.getName())) {
externalMapEntryList.remove(i);
break;
}
}
}
}
}
}
}
}
Aggregations