Search in sources :

Example 1 with DBMapperTableEntry

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

use of org.talend.designer.dbmap.model.emf.dbmap.DBMapperTableEntry 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)

Example 3 with DBMapperTableEntry

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

the class DBMapDataImplTest method test4.

private void test4() {
    DBMapDataImpl mapData1 = new DBMapDataImpl();
    DBMapDataImpl mapData2 = new DBMapDataImpl();
    assertTrue(mapData1.equals(mapData2));
    final OutputTable persistentTable = DbmapFactory.eINSTANCE.createOutputTable();
    persistentTable.setMinimized(true);
    persistentTable.setName("table1");
    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.getOutputTables().add(persistentTable);
    final InputTable persistentTable2 = DbmapFactory.eINSTANCE.createInputTable();
    persistentTable2.setMinimized(true);
    persistentTable2.setName("table1");
    persistentTable2.setTableName("tableName");
    final DBMapperTableEntry emfMapperTableEntry2 = DbmapFactory.eINSTANCE.createDBMapperTableEntry();
    emfMapperTableEntry2.setExpression("expression1");
    emfMapperTableEntry2.setName("entityName");
    emfMapperTableEntry2.setJoin(true);
    emfMapperTableEntry2.setOperator("operator1");
    persistentTable2.getDBMapperTableEntries().add(emfMapperTableEntry2);
    mapData2.getOutputTables().add(persistentTable);
    assertFalse(mapData1.equals(mapData2));
}
Also used : InputTable(org.talend.designer.dbmap.model.emf.dbmap.InputTable) OutputTable(org.talend.designer.dbmap.model.emf.dbmap.OutputTable) DBMapperTableEntry(org.talend.designer.dbmap.model.emf.dbmap.DBMapperTableEntry)

Example 4 with DBMapperTableEntry

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

the class DBMapDataImplTest method test1.

private void test1() {
    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("expression1");
    emfMapperTableEntry2.setName("entityName1");
    emfMapperTableEntry2.setJoin(true);
    emfMapperTableEntry2.setOperator("operator1");
    persistentTable2.getDBMapperTableEntries().add(emfMapperTableEntry2);
    mapData2.getInputTables().add(persistentTable2);
    assertTrue(mapData1.equals(mapData2));
}
Also used : InputTable(org.talend.designer.dbmap.model.emf.dbmap.InputTable) DBMapperTableEntry(org.talend.designer.dbmap.model.emf.dbmap.DBMapperTableEntry)

Example 5 with DBMapperTableEntry

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

the class DbMapServiceTest method setUp.

@Before
public void setUp() throws Exception {
    nodeType = TalendFileFactory.eINSTANCE.createNodeType();
    DBMapData data = DbmapFactory.eINSTANCE.createDBMapData();
    nodeType.setNodeData(data);
    InputTable input = DbmapFactory.eINSTANCE.createInputTable();
    input.setName(oldValue);
    input.setTableName(oldValue);
    DBMapperTableEntry inputEntry = DbmapFactory.eINSTANCE.createDBMapperTableEntry();
    inputEntry.setName("column");
    data.getInputTables().add(input);
    input.getDBMapperTableEntries().add(inputEntry);
    OutputTable out = DbmapFactory.eINSTANCE.createOutputTable();
    out.setName("output");
    out.setTableName("output");
    DBMapperTableEntry outEntry = DbmapFactory.eINSTANCE.createDBMapperTableEntry();
    outEntry.setName("column");
    outEntry.setExpression(oldValue + ".column");
    out.getDBMapperTableEntries().add(outEntry);
    data.getOutputTables().add(out);
}
Also used : InputTable(org.talend.designer.dbmap.model.emf.dbmap.InputTable) DBMapData(org.talend.designer.dbmap.model.emf.dbmap.DBMapData) DBMapperTableEntry(org.talend.designer.dbmap.model.emf.dbmap.DBMapperTableEntry) OutputTable(org.talend.designer.dbmap.model.emf.dbmap.OutputTable) Before(org.junit.Before)

Aggregations

DBMapperTableEntry (org.talend.designer.dbmap.model.emf.dbmap.DBMapperTableEntry)10 InputTable (org.talend.designer.dbmap.model.emf.dbmap.InputTable)8 OutputTable (org.talend.designer.dbmap.model.emf.dbmap.OutputTable)7 DBMapData (org.talend.designer.dbmap.model.emf.dbmap.DBMapData)4 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 AbstractExternalData (org.talend.designer.core.model.utils.emf.talendfile.AbstractExternalData)1 ExternalDbMapData (org.talend.designer.dbmap.external.data.ExternalDbMapData)1