Search in sources :

Example 21 with ExternalDbMapTable

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

the class ExternalDataConverter method prepareExternalData.

/**
     * 
     * Prepare ExternalMapperData object from internal data.
     * 
     * @param mapperModel
     * @return
     */
public ExternalDbMapData prepareExternalData(MapperModel mapperModel, ExternalDbMapUiProperties uiProperties) {
    ExternalDbMapData externalData = new ExternalDbMapData();
    inputTables = new ArrayList<ExternalDbMapTable>();
    externalData.setInputTables(inputTables);
    outputTables = new ArrayList<ExternalDbMapTable>();
    externalData.setOutputTables(outputTables);
    varsTables = new ArrayList<ExternalDbMapTable>();
    externalData.setVarsTables(varsTables);
    loadInExternalData(mapperModel.getInputDataMapTables());
    loadInExternalData(mapperModel.getOutputDataMapTables());
    externalData.setUiProperties(uiProperties);
    return externalData;
}
Also used : ExternalDbMapData(org.talend.designer.dbmap.external.data.ExternalDbMapData) ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable)

Example 22 with ExternalDbMapTable

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

the class ExternalDataConverter method loadInExternalData.

private void loadInExternalData(Collection<? extends IDataMapTable> tables) {
    for (IDataMapTable table : tables) {
        ExternalDbMapTable externalMapperTable = new ExternalDbMapTable();
        fillExternalTable(table, externalMapperTable);
        ArrayList<ExternalDbMapEntry> perTableEntries = new ArrayList<ExternalDbMapEntry>();
        boolean isInputTable = table instanceof InputTable;
        for (ITableEntry dataMapTableEntry : table.getColumnEntries()) {
            ExternalDbMapEntry externalMapperTableEntry = new ExternalDbMapEntry();
            externalMapperTableEntry.setExpression(dataMapTableEntry.getExpression());
            externalMapperTableEntry.setName(dataMapTableEntry.getName());
            if (isInputTable) {
                externalMapperTableEntry.setOperator(((InputColumnTableEntry) dataMapTableEntry).getOperator());
                externalMapperTableEntry.setJoin(((InputColumnTableEntry) dataMapTableEntry).isJoin());
            }
            perTableEntries.add(externalMapperTableEntry);
        }
        externalMapperTable.setMetadataTableEntries(perTableEntries);
    }
}
Also used : InputTable(org.talend.designer.dbmap.model.table.InputTable) ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) ArrayList(java.util.ArrayList) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry)

Example 23 with ExternalDbMapTable

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

the class DbMapComponent method renameInputConnection.

@Override
public void renameInputConnection(String oldConnectionName, String newConnectionName) {
    if (oldConnectionName == null || newConnectionName == null) {
        throw new NullPointerException();
    }
    if (externalData != null) {
        List<ExternalDbMapTable> inputTables = externalData.getInputTables();
        for (ExternalDbMapTable table : inputTables) {
            if (table.getTableName() != null && (table.getTableName().equals(oldConnectionName) || table.getName().equals(oldConnectionName))) {
                table.setTableName(newConnectionName);
                table.setName(newConnectionName);
                TableEntryLocation oldLocation = new TableEntryLocation(oldConnectionName, null);
                TableEntryLocation newLocation = new TableEntryLocation(newConnectionName, null);
                replaceLocationsInAllExpressions(oldLocation, newLocation, true);
            }
        }
    }
}
Also used : ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) TableEntryLocation(org.talend.designer.dbmap.model.tableentry.TableEntryLocation)

Example 24 with ExternalDbMapTable

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

the class ExternalDataConverter method prepareInputTables.

public ArrayList<InputTable> prepareInputTables(List<IOConnection> inputConnections, ExternalDbMapData externalData) {
    // Map<String, ExternalMapperTable> nameToInputPersistentTable = new HashMap<String, ExternalMapperTable>();
    // if (externalData != null) {
    // for (ExternalMapperTable persistentTable : externalData.getInputTables()) {
    // nameToInputPersistentTable.put(persistentTable.getName(), persistentTable);
    // }
    // }
    Map<String, IOConnection> nameToConnection = new HashMap<String, IOConnection>();
    for (IOConnection connection : inputConnections) {
        nameToConnection.put(connection.getName(), connection);
    }
    ArrayList<InputTable> inputDataMapTables = new ArrayList<InputTable>();
    if (externalData == null) {
        for (IOConnection connection : inputConnections) {
            InputTable inputTable = new InputTable(this.mapperManager, connection, connection.getName());
            inputTable.initFromExternalData(null);
            inputDataMapTables.add(inputTable);
        }
    } else {
        ArrayList<IOConnection> remainingConnections = new ArrayList<IOConnection>(inputConnections);
        for (ExternalDbMapTable persistentTable : externalData.getInputTables()) {
            String name = persistentTable.getTableName() != null ? persistentTable.getTableName() : persistentTable.getName();
            IOConnection connection = nameToConnection.get(name);
            if (connection != null) {
                remainingConnections.remove(connection);
                InputTable inputTable = new InputTable(this.mapperManager, connection, connection.getName());
                inputTable.initFromExternalData(persistentTable);
                inputDataMapTables.add(inputTable);
            }
        }
    // if(externalData.getInputTables().size() > 0) {
    // for (IOConnection connection : remainingConnections) {
    // InputTable inputTable = new InputTable(this.mapperManager, connection, connection.getName());
    // inputTable.initFromExternalData(null);
    // inputDataMapTables.add(inputTable);
    // }
    // }
    }
    // sort for put table with main connection at top position of the list
    Collections.sort(inputDataMapTables, new Comparator<InputTable>() {

        @Override
        public int compare(InputTable o1, InputTable o2) {
            if (o1.isMainConnection()) {
                return -1;
            } else if (o2.isMainConnection()) {
                return 1;
            }
            return 0;
        }
    });
    return inputDataMapTables;
}
Also used : InputTable(org.talend.designer.dbmap.model.table.InputTable) HashMap(java.util.HashMap) IOConnection(org.talend.designer.dbmap.external.connection.IOConnection) ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) ArrayList(java.util.ArrayList)

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