Search in sources :

Example 1 with InputTable

use of org.talend.designer.dbmap.model.emf.dbmap.InputTable in project tdi-studio-se by Talend.

the class DbMapComponent method removeInput.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.process.AbstractNode#removeInput(org.talend.core.model.process.IConnection)
     */
@Override
public void removeInput(IConnection connection) {
    Connection conn = null;
    DBMapData externalEmfData = (DBMapData) getExternalEmfData();
    InputTable toRemove = null;
    for (InputTable inputTable : externalEmfData.getInputTables()) {
        if (inputTable.getTableName() != null && inputTable.getTableName().equals(connection.getName())) {
            toRemove = inputTable;
            break;
        }
    }
    if (toRemove != null) {
        EList<InputTable> inputTableList = externalEmfData.getInputTables();
        inputTableList.remove(toRemove);
        ExternalNodeUtils.prepareExternalNodeReadyToOpen(getExternalNode());
        IODataComponentContainer iContainer = getIODataComponents();
        if (iContainer != null) {
            mapperMain.initIOConnections(iContainer);
            mapperMain.getMapperManager().initInternalData();
        }
        buildExternalData(externalEmfData);
    }
}
Also used : InputTable(org.talend.designer.dbmap.model.emf.dbmap.InputTable) DBMapData(org.talend.designer.dbmap.model.emf.dbmap.DBMapData) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) IODataComponentContainer(org.talend.core.model.components.IODataComponentContainer)

Example 2 with InputTable

use of org.talend.designer.dbmap.model.emf.dbmap.InputTable 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 3 with InputTable

use of org.talend.designer.dbmap.model.emf.dbmap.InputTable in project tdi-studio-se by Talend.

the class DBMapDataImpl method equals.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated not
     */
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (obj == null) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }
    DBMapDataImpl dbObj = (DBMapDataImpl) obj;
    EList<InputTable> inputs = dbObj.getInputTables();
    EList<OutputTable> outputs = dbObj.getOutputTables();
    EList<VarTable> vars = dbObj.getVarTables();
    if (inputs.size() != getInputTables().size()) {
        return false;
    }
    if (outputs.size() != getOutputTables().size()) {
        return false;
    }
    if (vars.size() != getVarTables().size()) {
        return false;
    }
    for (InputTable inputTable : inputTables) {
        boolean found = false;
        for (InputTable input : inputs) {
            if (inputTable.getName().equals(input.getName())) {
                found = true;
                if (!inputTable.equals(input)) {
                    return false;
                }
                break;
            }
        }
        if (found == false) {
            return false;
        }
    }
    for (OutputTable outputTable : outputTables) {
        boolean found = false;
        for (OutputTable output : outputs) {
            if (outputTable.getName().equals(output.getName())) {
                found = true;
                if (!outputTable.equals(output)) {
                    return false;
                }
                break;
            }
        }
        if (found == false) {
            return false;
        }
    }
    for (VarTable varTable : varTables) {
        boolean found = false;
        for (VarTable var : vars) {
            if (varTable.getName().equals(var.getName())) {
                found = true;
                if (!varTable.equals(var)) {
                    return false;
                }
                break;
            }
        }
        if (found == false) {
            return false;
        }
    }
    return true;
}
Also used : VarTable(org.talend.designer.dbmap.model.emf.dbmap.VarTable) InputTable(org.talend.designer.dbmap.model.emf.dbmap.InputTable) OutputTable(org.talend.designer.dbmap.model.emf.dbmap.OutputTable)

Example 4 with InputTable

use of org.talend.designer.dbmap.model.emf.dbmap.InputTable 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 5 with InputTable

use of org.talend.designer.dbmap.model.emf.dbmap.InputTable in project tdi-studio-se by Talend.

the class DBMapDataImplTest method test2.

private void test2() {
    DBMapDataImpl mapData1 = new DBMapDataImpl();
    DBMapDataImpl mapData2 = new DBMapDataImpl();
    assertTrue(mapData1.equals(mapData2));
    final InputTable persistentTable = DbmapFactory.eINSTANCE.createInputTable();
    persistentTable.setMinimized(true);
    persistentTable.setName("table1");
    persistentTable.setAlias("alias1");
    persistentTable.setJoinType("type1");
    persistentTable.setTableName("tableName");
    final DBMapperTableEntry emfMapperTableEntry = DbmapFactory.eINSTANCE.createDBMapperTableEntry();
    emfMapperTableEntry.setExpression("expression1");
    emfMapperTableEntry.setName("entityName1");
    emfMapperTableEntry.setJoin(true);
    emfMapperTableEntry.setOperator("operator1");
    persistentTable.getDBMapperTableEntries().add(emfMapperTableEntry);
    mapData1.getInputTables().add(persistentTable);
    final InputTable persistentTable2 = DbmapFactory.eINSTANCE.createInputTable();
    persistentTable2.setMinimized(true);
    persistentTable2.setName("table1");
    persistentTable2.setAlias("alias1");
    persistentTable2.setJoinType("type1");
    persistentTable2.setTableName("tableName");
    final DBMapperTableEntry emfMapperTableEntry2 = DbmapFactory.eINSTANCE.createDBMapperTableEntry();
    emfMapperTableEntry2.setExpression("expression_");
    emfMapperTableEntry2.setName("entityName1");
    emfMapperTableEntry2.setJoin(true);
    emfMapperTableEntry2.setOperator("operator1");
    persistentTable2.getDBMapperTableEntries().add(emfMapperTableEntry2);
    mapData2.getInputTables().add(persistentTable2);
    assertFalse(mapData1.equals(mapData2));
}
Also used : InputTable(org.talend.designer.dbmap.model.emf.dbmap.InputTable) DBMapperTableEntry(org.talend.designer.dbmap.model.emf.dbmap.DBMapperTableEntry)

Aggregations

InputTable (org.talend.designer.dbmap.model.emf.dbmap.InputTable)10 DBMapperTableEntry (org.talend.designer.dbmap.model.emf.dbmap.DBMapperTableEntry)8 OutputTable (org.talend.designer.dbmap.model.emf.dbmap.OutputTable)7 DBMapData (org.talend.designer.dbmap.model.emf.dbmap.DBMapData)5 ArrayList (java.util.ArrayList)2 ExternalDbMapEntry (org.talend.designer.dbmap.external.data.ExternalDbMapEntry)2 ExternalDbMapTable (org.talend.designer.dbmap.external.data.ExternalDbMapTable)2 FilterEntry (org.talend.designer.dbmap.model.emf.dbmap.FilterEntry)2 Before (org.junit.Before)1 Test (org.junit.Test)1 IODataComponentContainer (org.talend.core.model.components.IODataComponentContainer)1 IConnection (org.talend.core.model.process.IConnection)1 AbstractExternalData (org.talend.designer.core.model.utils.emf.talendfile.AbstractExternalData)1 Connection (org.talend.designer.core.ui.editor.connections.Connection)1 ExternalDbMapData (org.talend.designer.dbmap.external.data.ExternalDbMapData)1 VarTable (org.talend.designer.dbmap.model.emf.dbmap.VarTable)1