Search in sources :

Example 1 with ExternalDbMapEntry

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);
        }
    }
}
Also used : 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) ArrayList(java.util.ArrayList) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry) DBMapperTableEntry(org.talend.designer.dbmap.model.emf.dbmap.DBMapperTableEntry) OutputTable(org.talend.designer.dbmap.model.emf.dbmap.OutputTable)

Example 2 with ExternalDbMapEntry

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);
}
Also used : ExternalDbMapData(org.talend.designer.dbmap.external.data.ExternalDbMapData) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) Process(org.talend.designer.core.ui.editor.process.Process) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) JobContextManager(org.talend.core.model.context.JobContextManager) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry)

Example 3 with ExternalDbMapEntry

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;
}
Also used : ArrayList(java.util.ArrayList) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry)

Example 4 with ExternalDbMapEntry

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);
}
Also used : DbMapComponent(org.talend.designer.dbmap.DbMapComponent) INodeConnector(org.talend.core.model.process.INodeConnector) NodeConnector(org.talend.designer.core.model.components.NodeConnector) ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) Process(org.talend.designer.core.ui.editor.process.Process) INodeConnector(org.talend.core.model.process.INodeConnector) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry) Before(org.junit.Before)

Example 5 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)

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