Search in sources :

Example 6 with ExternalDbMapTable

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

the class DbMapComponent method renameMetadataColumnName.

@Override
protected void renameMetadataColumnName(String conectionName, String oldColumnName, String newColumnName) {
    if (conectionName == null || oldColumnName == null || newColumnName == null) {
        throw new NullPointerException();
    }
    if (externalData != null) {
        // rename metadata column name
        List<ExternalDbMapTable> tables = new ArrayList<ExternalDbMapTable>(externalData.getInputTables());
        tables.addAll(externalData.getOutputTables());
        ExternalDbMapTable tableFound = null;
        for (ExternalDbMapTable table : tables) {
            if (table.getName().equals(conectionName)) {
                List<ExternalDbMapEntry> metadataTableEntries = table.getMetadataTableEntries();
                for (ExternalDbMapEntry entry : metadataTableEntries) {
                    if (entry.getName().equals(oldColumnName)) {
                        entry.setName(newColumnName);
                        tableFound = table;
                        break;
                    }
                }
                break;
            }
        }
        // it is necessary to update expressions only if renamed column come from input table
        if (tableFound != null && externalData.getInputTables().indexOf(tableFound) != -1) {
            TableEntryLocation oldLocation = new TableEntryLocation(conectionName, oldColumnName);
            TableEntryLocation newLocation = new TableEntryLocation(conectionName, newColumnName);
            replaceLocationsInAllExpressions(oldLocation, newLocation, false);
        }
    }
}
Also used : ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) ArrayList(java.util.ArrayList) TableEntryLocation(org.talend.designer.dbmap.model.tableentry.TableEntryLocation) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry)

Example 7 with ExternalDbMapTable

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

the class DbGenerationManager method removeUnmatchingEntriesWithColumnsOfMetadataTable.

/**
     * DOC amaumont Comment method "removeUnmatchingEntriesWithColumnsOfMetadataTable".
     *
     * @param outputTable
     * @param metadataTable
     */
protected ExternalDbMapTable removeUnmatchingEntriesWithColumnsOfMetadataTable(ExternalDbMapTable externalDbMapTable, IMetadataTable metadataTable) {
    ExternalDbMapTable clonedTable = null;
    try {
        clonedTable = (ExternalDbMapTable) externalDbMapTable.clone();
    } catch (CloneNotSupportedException e) {
        ExceptionHandler.process(e);
    }
    List<ExternalDbMapEntry> metadataTableEntries = clonedTable.getMetadataTableEntries();
    if (metadataTableEntries != null) {
        HashMap<String, IMetadataColumn> hNameToColumn = new HashMap<String, IMetadataColumn>();
        List<IMetadataColumn> listColumns = metadataTable.getListColumns();
        for (IMetadataColumn column : listColumns) {
            hNameToColumn.put(column.getLabel(), column);
        }
        List<ExternalDbMapEntry> dbMapEntriesToRemove = new ArrayList<ExternalDbMapEntry>();
        for (ExternalDbMapEntry externalTableEntry : metadataTableEntries) {
            String entryName = externalTableEntry.getName();
            IMetadataColumn column = hNameToColumn.get(entryName);
            if (column == null) {
                dbMapEntriesToRemove.add(externalTableEntry);
            }
        }
        metadataTableEntries.removeAll(dbMapEntriesToRemove);
    }
    return clonedTable;
}
Also used : ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry)

Example 8 with ExternalDbMapTable

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

the class DbMapComponent method sortOutputsConnectionsLikeVisualOrder.

/**
     * Sort outgoingConnections for code generation as visible output zone of tMap.
     */
@SuppressWarnings("unchecked")
private void sortOutputsConnectionsLikeVisualOrder() {
    if (!MapperMain.isStandAloneMode()) {
        List<IConnection> outgoingConnections = (List<IConnection>) getOutgoingConnections();
        Map<String, IConnection> connectionNameToOutgoingConnection = new HashMap<String, IConnection>();
        for (IConnection connection : outgoingConnections) {
            connectionNameToOutgoingConnection.put(connection.getUniqueName(), connection);
        }
        List<ExternalDbMapTable> outputTables = externalData.getOutputTables();
        List<IConnection> tmpList = new ArrayList<IConnection>(outgoingConnections);
        outgoingConnections.clear();
        int lstSize = outputTables.size();
        for (int i = 0; i < lstSize; i++) {
            ExternalDbMapTable table = outputTables.get(i);
            String tableName = table.getName();
            IConnection connection = connectionNameToOutgoingConnection.get(tableName);
            if (connection != null) {
                outgoingConnections.add(connection);
            }
        }
        // add connections without metadata
        for (IConnection connection : tmpList) {
            if (!outgoingConnections.contains(connection)) {
                outgoingConnections.add(connection);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) IConnection(org.talend.core.model.process.IConnection)

Example 9 with ExternalDbMapTable

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

the class DbMapComponent method buildExternalData.

@Override
public void buildExternalData(AbstractExternalData abstractData) {
    externalData = new ExternalDbMapData();
    if (abstractData instanceof DBMapData) {
        DBMapData mapperData = (DBMapData) abstractData;
        List<ExternalDbMapTable> externalTables = new ArrayList<ExternalDbMapTable>();
        // input
        for (InputTable pTable : mapperData.getInputTables()) {
            ExternalDbMapTable externalTable = new ExternalDbMapTable();
            externalTable.setName(pTable.getName());
            externalTable.setMinimized(pTable.isMinimized());
            externalTable.setAlias(pTable.getAlias());
            externalTable.setJoinType(pTable.getJoinType());
            externalTable.setTableName(pTable.getTableName());
            List<ExternalDbMapEntry> entities = new ArrayList<ExternalDbMapEntry>();
            for (DBMapperTableEntry pEntity : pTable.getDBMapperTableEntries()) {
                ExternalDbMapEntry entity = new ExternalDbMapEntry();
                entity.setExpression(pEntity.getExpression());
                entity.setJoin(pEntity.isJoin());
                entity.setName(pEntity.getName());
                entity.setOperator(pEntity.getOperator());
                entities.add(entity);
            }
            externalTable.setMetadataTableEntries(entities);
            externalTables.add(externalTable);
        }
        externalData.setInputTables(externalTables);
        // output
        externalTables = new ArrayList<ExternalDbMapTable>();
        for (OutputTable pTable : mapperData.getOutputTables()) {
            ExternalDbMapTable externalTable = new ExternalDbMapTable();
            externalTable.setName(pTable.getName());
            externalTable.setMinimized(pTable.isMinimized());
            externalTable.setTableName(pTable.getTableName());
            List<ExternalDbMapEntry> entities = new ArrayList<ExternalDbMapEntry>();
            for (DBMapperTableEntry pEntity : pTable.getDBMapperTableEntries()) {
                ExternalDbMapEntry entity = new ExternalDbMapEntry();
                entity.setExpression(pEntity.getExpression());
                entity.setName(pEntity.getName());
                entities.add(entity);
            }
            externalTable.setMetadataTableEntries(entities);
            // filters
            entities = new ArrayList<ExternalDbMapEntry>();
            List<ExternalDbMapEntry> otherFilterEntities = new ArrayList<ExternalDbMapEntry>();
            for (FilterEntry pFilter : pTable.getFilterEntries()) {
                ExternalDbMapEntry entity = new ExternalDbMapEntry();
                entity.setExpression(pFilter.getExpression());
                entity.setName(pFilter.getName());
                if (FilterTableEntry.OTHER_FILTER.equals(pFilter.getFilterKind())) {
                    otherFilterEntities.add(entity);
                } else {
                    entities.add(entity);
                }
            }
            externalTable.setCustomWhereConditionsEntries(entities);
            externalTable.setCustomOtherConditionsEntries(otherFilterEntities);
            externalTables.add(externalTable);
        }
        externalData.setOutputTables(externalTables);
    }
    this.setExternalData(externalData);
}
Also used : DBMapData(org.talend.designer.dbmap.model.emf.dbmap.DBMapData) ExternalDbMapData(org.talend.designer.dbmap.external.data.ExternalDbMapData) ArrayList(java.util.ArrayList) DBMapperTableEntry(org.talend.designer.dbmap.model.emf.dbmap.DBMapperTableEntry) OutputTable(org.talend.designer.dbmap.model.emf.dbmap.OutputTable) InputTable(org.talend.designer.dbmap.model.emf.dbmap.InputTable) ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) FilterEntry(org.talend.designer.dbmap.model.emf.dbmap.FilterEntry) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry)

Example 10 with ExternalDbMapTable

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

the class DbMapComponentDocumentation method generateXMLInfo.

/**
     * Generates all information which for XML file.
     */
private void generateXMLInfo() {
    document = DocumentHelper.createDocument();
    //$NON-NLS-1$
    Element externalNodeElement = document.addElement("externalNode");
    generateMessages(externalNodeElement);
    //$NON-NLS-1$
    externalNodeElement.addAttribute("name", HTMLDocUtils.checkString(this.componentName));
    //$NON-NLS-1$
    externalNodeElement.addAttribute("preview", HTMLDocUtils.checkString(this.previewPicPath));
    List<ExternalDbMapTable> inputTables = externalData.getInputTables();
    List<ExternalDbMapTable> outputTables = externalData.getOutputTables();
    List<ExternalDbMapTable> varTables = externalData.getVarsTables();
    handleMapperTablesInfo(inputTables, externalNodeElement, IHTMLDocConstants.MAPPER_TABLE_INPUT);
    handleMapperTablesInfo(outputTables, externalNodeElement, IHTMLDocConstants.MAPPER_TABLE_OUPUT);
    handleMapperTablesInfo(varTables, externalNodeElement, IHTMLDocConstants.MAPPER_TABLE_VAR);
}
Also used : ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) Element(org.dom4j.Element)

Aggregations

ExternalDbMapTable (org.talend.designer.dbmap.external.data.ExternalDbMapTable)24 ArrayList (java.util.ArrayList)17 ExternalDbMapEntry (org.talend.designer.dbmap.external.data.ExternalDbMapEntry)15 ExternalDbMapData (org.talend.designer.dbmap.external.data.ExternalDbMapData)9 IConnection (org.talend.core.model.process.IConnection)8 HashMap (java.util.HashMap)7 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)6 List (java.util.List)5 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)5 TableEntryLocation (org.talend.designer.dbmap.model.tableentry.TableEntryLocation)3 Element (org.dom4j.Element)2 EList (org.eclipse.emf.common.util.EList)2 Before (org.junit.Before)2 Process (org.talend.designer.core.ui.editor.process.Process)2 DbMapComponent (org.talend.designer.dbmap.DbMapComponent)2 IOConnection (org.talend.designer.dbmap.external.connection.IOConnection)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