Search in sources :

Example 6 with ExternalDbMapEntry

use of org.talend.designer.dbmap.external.data.ExternalDbMapEntry in project tdi-studio-se by Talend.

the class DbMapComponentDocumentation method generateMapperTablesInfo.

/**
     * This method used for generating all mapper tables information into xml file.
     * 
     * @param externalNodeElement
     * @param tables
     * @param mapperTableType
     */
private void generateMapperTablesInfo(Element externalNodeElement, List<ExternalDbMapTable> tables, String mapperTableType) {
    //$NON-NLS-1$
    Element mapperTableElement = externalNodeElement.addElement("mapperTable");
    //$NON-NLS-1$
    mapperTableElement.addAttribute("type", HTMLDocUtils.checkString(mapperTableType));
    Element tableElement = null;
    for (ExternalDbMapTable table : tables) {
        //$NON-NLS-1$
        tableElement = mapperTableElement.addElement("table");
        generateTableSummaryInfo(mapperTableElement, tableElement, table);
        List<ExternalDbMapEntry> metadataTableEntries = table.getMetadataTableEntries();
        if (!HTMLDocUtils.checkList(metadataTableEntries)) {
            continue;
        }
        //$NON-NLS-1$
        Element metadataTableEntriesElement = tableElement.addElement("metadataTableEntries");
        for (ExternalDbMapEntry entry : metadataTableEntries) {
            generateTablesEntriesInfo(metadataTableEntriesElement, entry);
        }
        /**
             * generate custom Where clauses conditions entries
             */
        List<ExternalDbMapEntry> customWhereConditionsEntries = table.getCustomWhereConditionsEntries();
        if (!HTMLDocUtils.checkList(customWhereConditionsEntries)) {
            continue;
        }
        //$NON-NLS-1$
        Element customWhereConditionsEntriesElement = tableElement.addElement("customWhereConditionsEntries");
        for (ExternalDbMapEntry entry : customWhereConditionsEntries) {
            generateTablesEntriesInfo(customWhereConditionsEntriesElement, entry);
        }
        /**
             * generate custom Other clauses conditions entries
             */
        List<ExternalDbMapEntry> customOtherConditionsEntries = table.getCustomOtherConditionsEntries();
        if (!HTMLDocUtils.checkList(customOtherConditionsEntries)) {
            continue;
        }
        //$NON-NLS-1$
        Element customOtherConditionsEntriesElement = tableElement.addElement("customOtherConditionsEntries");
        for (ExternalDbMapEntry entry : customOtherConditionsEntries) {
            generateTablesEntriesInfo(customOtherConditionsEntriesElement, entry);
        }
    }
}
Also used : ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) Element(org.dom4j.Element) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry)

Example 7 with ExternalDbMapEntry

use of org.talend.designer.dbmap.external.data.ExternalDbMapEntry in project tdi-studio-se by Talend.

the class UpdateELTMapComponentCommand method execute.

private void execute(String oldValue, String newValue) {
    connection.setName(newValue);
    // update table name
    for (IExternalMapTable input : newInputTables) {
        if (input instanceof ExternalDbMapTable) {
            ExternalDbMapTable dbMapTable = (ExternalDbMapTable) input;
            if (oldValue.equals(dbMapTable.getName()) || oldValue.equals(dbMapTable.getTableName())) {
                dbMapTable.setName(newValue);
                dbMapTable.setTableName(newValue);
            }
        }
    }
    // update expression
    for (IExternalMapTable output : newOutputTables) {
        if (output instanceof ExternalDbMapTable) {
            List<ExternalDbMapEntry> entries = ((ExternalDbMapTable) output).getMetadataTableEntries();
            for (ExternalDbMapEntry entry : entries) {
                String expression = entry.getExpression();
                if (expression != null && !"".equals(expression.trim())) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$
                    int index = expression.lastIndexOf(".");
                    // at least "a.b"
                    if (index > 0) {
                        String connectionName = expression.substring(0, index);
                        if (oldValue.equals(connectionName)) {
                            entry.setExpression(newValue + expression.substring(index, expression.length()));
                        }
                    }
                }
            }
        }
    }
}
Also used : ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) IExternalMapTable(org.talend.core.model.process.node.IExternalMapTable) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry)

Example 8 with ExternalDbMapEntry

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();
    }
}
Also used : IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) InputColumnTableEntry(org.talend.designer.dbmap.model.tableentry.InputColumnTableEntry) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry)

Example 9 with ExternalDbMapEntry

use of org.talend.designer.dbmap.external.data.ExternalDbMapEntry in project tdi-studio-se by Talend.

the class OutputTable method initFromExternalData.

@Override
public void initFromExternalData(ExternalDbMapTable externalMapperTable) {
    super.initFromExternalData(externalMapperTable);
    List<IMetadataColumn> columns = this.metadataTable.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);
        }
    }
    for (IMetadataColumn column : columns) {
        AbstractInOutTableEntry columnEntry = getNewTableEntry(column);
        ExternalDbMapEntry externalMapperTableEntry = nameToPerTabEntry.get(columnEntry.getMetadataColumn().getLabel());
        // Entry match with current column
        if (externalMapperTableEntry != null) {
            columnEntry.setExpression(externalMapperTableEntry.getExpression());
        }
        dataMapTableEntries.add(columnEntry);
    }
    if (externalMapperTable != null) {
        List<ExternalDbMapEntry> externalWhereConstraintTableEntries = externalMapperTable.getCustomWhereConditionsEntries();
        if (externalWhereConstraintTableEntries != null) {
            for (ExternalDbMapEntry entry : externalWhereConstraintTableEntries) {
                FilterTableEntry whereFilterTableEntry = new FilterTableEntry(this, entry.getName(), entry.getExpression(), FilterTableEntry.WHERE_FILTER);
                // mapperManager.getProblemsManager().checkProblemsForTableEntry(filterTableEntry, false);
                addWhereFilterEntry(whereFilterTableEntry);
            }
        }
        List<ExternalDbMapEntry> externalOtherConstraintTableEntries = externalMapperTable.getCustomOtherConditionsEntries();
        if (externalOtherConstraintTableEntries != null) {
            for (ExternalDbMapEntry entry : externalOtherConstraintTableEntries) {
                FilterTableEntry otherFilterTableEntry = new FilterTableEntry(this, entry.getName(), entry.getExpression(), FilterTableEntry.OTHER_FILTER);
                // mapperManager.getProblemsManager().checkProblemsForTableEntry(filterTableEntry, false);
                addOtherFilterEntry(otherFilterTableEntry);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) FilterTableEntry(org.talend.designer.dbmap.model.tableentry.FilterTableEntry) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) AbstractInOutTableEntry(org.talend.designer.dbmap.model.tableentry.AbstractInOutTableEntry) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry)

Example 10 with ExternalDbMapEntry

use of org.talend.designer.dbmap.external.data.ExternalDbMapEntry in project tdi-studio-se by Talend.

the class VarsTable method initFromExternalData.

public void initFromExternalData(ExternalDbMapTable externalMapperTable) {
    super.initFromExternalData(externalMapperTable);
    if (externalMapperTable != null) {
        List<ExternalDbMapEntry> metadataTableEntries = externalMapperTable.getMetadataTableEntries();
        if (metadataTableEntries != null) {
            for (ExternalDbMapEntry externalMapperTableEntry : metadataTableEntries) {
                IColumnEntry varTableEntry = new VarTableEntry(this, externalMapperTableEntry.getName(), externalMapperTableEntry.getExpression(), externalMapperTableEntry.getOperator());
                // mapperManager.getProblemsManager().checkProblemsForTableEntry(varTableEntry, false);
                addColumnEntry(varTableEntry);
            }
        }
    } else {
        setMinimized(true);
    }
}
Also used : VarTableEntry(org.talend.designer.dbmap.model.tableentry.VarTableEntry) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry)

Aggregations

ExternalDbMapEntry (org.talend.designer.dbmap.external.data.ExternalDbMapEntry)22 ArrayList (java.util.ArrayList)16 ExternalDbMapTable (org.talend.designer.dbmap.external.data.ExternalDbMapTable)15 HashMap (java.util.HashMap)6 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)6 IConnection (org.talend.core.model.process.IConnection)6 ExternalDbMapData (org.talend.designer.dbmap.external.data.ExternalDbMapData)6 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)4 List (java.util.List)3 Before (org.junit.Before)2 Process (org.talend.designer.core.ui.editor.process.Process)2 DbMapComponent (org.talend.designer.dbmap.DbMapComponent)2 IJoinType (org.talend.designer.dbmap.language.IJoinType)2 DBMapperTableEntry (org.talend.designer.dbmap.model.emf.dbmap.DBMapperTableEntry)2 FilterEntry (org.talend.designer.dbmap.model.emf.dbmap.FilterEntry)2 InputTable (org.talend.designer.dbmap.model.emf.dbmap.InputTable)2 OutputTable (org.talend.designer.dbmap.model.emf.dbmap.OutputTable)2 FilterTableEntry (org.talend.designer.dbmap.model.tableentry.FilterTableEntry)2 TableEntryLocation (org.talend.designer.dbmap.model.tableentry.TableEntryLocation)2 DataMapExpressionParser (org.talend.designer.dbmap.utils.DataMapExpressionParser)2