Search in sources :

Example 1 with DBMapData

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

Example 2 with DBMapData

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

the class DBMapSplitTableConstraintFiltersMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    IProxyRepositoryFactory factory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
    ProcessType processType = getProcessType(item);
    boolean modified = false;
    if (processType != null) {
        for (Object obj : processType.getNode()) {
            NodeType nodeType = (NodeType) obj;
            AbstractExternalData externalData = nodeType.getNodeData();
            if (externalData instanceof DBMapData) {
                DBMapData mapperData = (DBMapData) externalData;
                for (OutputTable pTable : mapperData.getOutputTables()) {
                    int i = 0;
                    List<FilterEntry> needSplitFilters = new ArrayList<FilterEntry>();
                    List<FilterEntry> newFilters = new ArrayList<FilterEntry>();
                    for (FilterEntry pFilter : pTable.getFilterEntries()) {
                        String expression = pFilter.getExpression();
                        if (expression != null && !expression.trim().isEmpty()) {
                            if (!DbGenerationManager.containWith(expression, DbMapSqlConstants.GROUP_BY_PATTERN, false) && !DbGenerationManager.containWith(expression, DbMapSqlConstants.ORDER_BY_PATTERN, false)) {
                                continue;
                            } else {
                                // can not split the clause directly here, because clause like this(a = b GROUP BY
                                // c) will be put at
                                // the end of where clause
                                needSplitFilters.add(pFilter);
                            }
                        }
                    }
                    if (!needSplitFilters.isEmpty()) {
                        EList<FilterEntry> entryList = pTable.getFilterEntries();
                        for (FilterEntry pFilter : needSplitFilters) {
                            String expression = pFilter.getExpression().trim();
                            int splitIndex = firstIndexInString(expression, DbMapSqlConstants.GROUP_BY_PATTERN);
                            int orderIndex = firstIndexInString(expression, DbMapSqlConstants.ORDER_BY_PATTERN);
                            if (splitIndex < 0 || (0 <= orderIndex && orderIndex < splitIndex)) {
                                splitIndex = orderIndex;
                            }
                            if (splitIndex == 0) {
                                // keep the order of "GROUP BY" and "ORDER BY"
                                pFilter.setFilterKind(FilterTableEntry.OTHER_FILTER);
                                entryList.remove(pFilter);
                                newFilters.add(pFilter);
                            } else {
                                String whereClause = expression.substring(0, splitIndex);
                                if (//$NON-NLS-1$
                                !DbGenerationManager.containWith(expression, DbMapSqlConstants.OR + "\\b", true) && !DbGenerationManager.containWith(expression, DbMapSqlConstants.AND + "\\b", true)) {
                                    //$NON-NLS-1$ 
                                    //$NON-NLS-1$
                                    whereClause = DbMapSqlConstants.AND + " " + whereClause;
                                }
                                pFilter.setExpression(whereClause);
                                FilterEntry tFilter = DbmapFactory.eINSTANCE.createFilterEntry();
                                //$NON-NLS-1$
                                tFilter.setName("newFilterSplited" + ++i);
                                tFilter.setExpression(expression.substring(splitIndex).trim());
                                tFilter.setFilterKind(FilterTableEntry.OTHER_FILTER);
                                entryList.remove(pFilter);
                                entryList.add(pFilter);
                                newFilters.add(tFilter);
                            }
                            modified = true;
                        }
                        if (!newFilters.isEmpty()) {
                            pTable.getFilterEntries().addAll(newFilters);
                            modified = true;
                        }
                    }
                }
            }
        }
    }
    try {
        if (modified) {
            factory.save(item, true);
            return ExecutionResult.SUCCESS_WITH_ALERT;
        } else {
            return ExecutionResult.SUCCESS_NO_ALERT;
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : AbstractExternalData(org.talend.designer.core.model.utils.emf.talendfile.AbstractExternalData) DBMapData(org.talend.designer.dbmap.model.emf.dbmap.DBMapData) ArrayList(java.util.ArrayList) OutputTable(org.talend.designer.dbmap.model.emf.dbmap.OutputTable) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) FilterEntry(org.talend.designer.dbmap.model.emf.dbmap.FilterEntry) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 3 with DBMapData

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

the class DbMapComponent method addInput.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.process.AbstractNode#addInput(org.talend.core.model.process.IConnection)
     */
@Override
public void addInput(IConnection connection) {
    Object eData = getExternalEmfData();
    if (eData == null) {
        return;
    }
    DBMapData externalEmfData = (DBMapData) eData;
    ExternalNodeUtils.prepareExternalNodeReadyToOpen(this);
    IODataComponentContainer iContainer = getIODataComponents();
    if (iContainer != null) {
        mapperMain.initIOConnections(iContainer);
        mapperMain.getMapperManager().initInternalData();
    }
    buildExternalData(externalEmfData);
}
Also used : DBMapData(org.talend.designer.dbmap.model.emf.dbmap.DBMapData) IODataComponentContainer(org.talend.core.model.components.IODataComponentContainer)

Example 4 with DBMapData

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

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

Aggregations

DBMapData (org.talend.designer.dbmap.model.emf.dbmap.DBMapData)9 InputTable (org.talend.designer.dbmap.model.emf.dbmap.InputTable)5 OutputTable (org.talend.designer.dbmap.model.emf.dbmap.OutputTable)5 DBMapperTableEntry (org.talend.designer.dbmap.model.emf.dbmap.DBMapperTableEntry)4 ExternalDbMapData (org.talend.designer.dbmap.external.data.ExternalDbMapData)3 ArrayList (java.util.ArrayList)2 IODataComponentContainer (org.talend.core.model.components.IODataComponentContainer)2 AbstractExternalData (org.talend.designer.core.model.utils.emf.talendfile.AbstractExternalData)2 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)2 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)2 FilterEntry (org.talend.designer.dbmap.model.emf.dbmap.FilterEntry)2 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 MarshalException (org.exolab.castor.xml.MarshalException)1 Unmarshaller (org.exolab.castor.xml.Unmarshaller)1 ValidationException (org.exolab.castor.xml.ValidationException)1 Before (org.junit.Before)1 Test (org.junit.Test)1