Search in sources :

Example 11 with TableEntryLocation

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

the class UIManager method processColumnNameChanged.

/**
     * DOC amaumont Comment method "processNewProcessColumnName".
     * 
     * @param previousColumnName TODO
     * @param dataMapTableView
     * @param renamingDependentEntries TODO
     * @param text
     * @param entry
     */
public void processColumnNameChanged(final String previousColumnName, final String newColumnName, final DataMapTableView dataMapTableView, final ITableEntry currentModifiedITableEntry, boolean renamingDependentEntries) {
    mapperManager.changeColumnName(currentModifiedITableEntry, previousColumnName, newColumnName);
    Collection<DataMapTableView> tableViews = mapperManager.getTablesView();
    boolean atLeastOneLinkHasBeenRemoved = false;
    for (DataMapTableView view : tableViews) {
        IDataMapTable dataMapTable = view.getDataMapTable();
        List<IColumnEntry> metadataTableEntries = dataMapTable.getColumnEntries();
        for (IColumnEntry entry : metadataTableEntries) {
            if (parseExpression(entry.getExpression(), entry, true, true, false).isAtLeastOneLinkRemoved()) {
                atLeastOneLinkHasBeenRemoved = true;
            }
        }
        if (dataMapTable instanceof OutputTable) {
            List<FilterTableEntry> constraintWhereEntries = ((OutputTable) dataMapTable).getWhereFilterEntries();
            for (FilterTableEntry entry : constraintWhereEntries) {
                if (parseExpression(entry.getExpression(), entry, true, true, false).isAtLeastOneLinkRemoved()) {
                    atLeastOneLinkHasBeenRemoved = true;
                }
            }
            List<FilterTableEntry> constraintOtherEntries = ((OutputTable) dataMapTable).getOtherFilterEntries();
            for (FilterTableEntry entry : constraintOtherEntries) {
                if (parseExpression(entry.getExpression(), entry, true, true, false).isAtLeastOneLinkRemoved()) {
                    atLeastOneLinkHasBeenRemoved = true;
                }
            }
        }
    }
    mapperManager.getUiManager().refreshBackground(false, false);
    dataMapTableView.getTableViewerCreatorForColumns().getTableViewer().refresh(currentModifiedITableEntry);
    TableEntryLocation previousLocation = new TableEntryLocation(currentModifiedITableEntry.getParentName(), previousColumnName);
    TableEntryLocation newLocation = new TableEntryLocation(currentModifiedITableEntry.getParentName(), newColumnName);
    mapperManager.replacePreviousLocationInAllExpressions(previousLocation, newLocation);
    refreshSqlExpression();
    if (!renamingDependentEntries) {
        AbstractInOutTable currentTable = (AbstractInOutTable) currentModifiedITableEntry.getParent();
        if (currentTable instanceof InputTable) {
            InputTable currentInputTable = (InputTable) currentTable;
            String physicalTableName = currentInputTable.getTableName();
            String alias = currentInputTable.getAlias();
            InputTable physicalInputTable = null;
            List<InputTable> inputTables = mapperManager.getInputTables();
            if (alias != null) {
                for (InputTable table : inputTables) {
                    if (table.equals(physicalTableName)) {
                        physicalInputTable = table;
                    }
                }
            } else {
                physicalInputTable = currentInputTable;
            }
            if (physicalInputTable == null) {
                List<IOConnection> incomingConnections = mapperManager.getComponent().getMapperMain().getIoInputConnections();
                IOConnection connectionFound = null;
                for (IOConnection connection : incomingConnections) {
                    if (connection.getName().equals(physicalTableName)) {
                        connectionFound = connection;
                    }
                }
                IMetadataColumn metadataColumn = connectionFound.getTable().getColumn(previousColumnName);
                if (metadataColumn != null) {
                    metadataColumn.setLabel(newColumnName);
                }
            }
            for (InputTable table : inputTables) {
                if ((// Physical table parent
                alias != null && table.getAlias() == null && table.getName().equals(physicalTableName) || // Alias table
                alias == null && table.getAlias() != null && table.getTableName().equals(physicalTableName))) {
                    TableEntryLocation location = new TableEntryLocation(table.getName(), previousColumnName);
                    DataMapTableView aliasTableView = mapperManager.retrieveDataMapTableView(location);
                    ITableEntry aliasTableEntry = mapperManager.retrieveTableEntry(location);
                    if (aliasTableEntry != null) {
                        processColumnNameChanged(previousColumnName, newColumnName, aliasTableView, aliasTableEntry, true);
                    }
                }
            }
        }
    }
// if (atLeastOneLinkHasBeenRemoved) {
// new AsynchronousThreading(20, false, dataMapTableView.getDisplay(), new Runnable() {
//
// public void run() {
// TableViewerCreator tableViewerCreatorForColumns = dataMapTableView
// .getTableViewerCreatorForColumns();
// boolean propagate = MessageDialog.openQuestion(tableViewerCreatorForColumns.getTable().getShell(),
// Messages.getString("UIManager.propagateTitle"), //$NON-NLS-1$
// Messages.getString("UIManager.propagateMessage")); //$NON-NLS-1$
// if (propagate) {
// TableEntryLocation previousLocation = new TableEntryLocation(currentModifiedITableEntry
// .getParentName(), previousColumnName);
// TableEntryLocation newLocation = new TableEntryLocation(currentModifiedITableEntry
// .getParentName(), newColumnName);
// mapperManager.replacePreviousLocationInAllExpressions(previousLocation, newLocation);
// refreshSqlExpression();
// }
// }
// }).start();
// }
}
Also used : ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) FilterTableEntry(org.talend.designer.dbmap.model.tableentry.FilterTableEntry) AbstractInOutTable(org.talend.designer.dbmap.model.table.AbstractInOutTable) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) InputDataMapTableView(org.talend.designer.dbmap.ui.visualmap.table.InputDataMapTableView) OutputDataMapTableView(org.talend.designer.dbmap.ui.visualmap.table.OutputDataMapTableView) DataMapTableView(org.talend.designer.dbmap.ui.visualmap.table.DataMapTableView) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) OutputTable(org.talend.designer.dbmap.model.table.OutputTable) InputTable(org.talend.designer.dbmap.model.table.InputTable) IOConnection(org.talend.designer.dbmap.external.connection.IOConnection) TableEntryLocation(org.talend.designer.dbmap.model.tableentry.TableEntryLocation)

Example 12 with TableEntryLocation

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

the class OracleGenerationManager method buildSqlSelect.

/**
     * 
     * ggu Comment method "buildSqlSelect".
     * 
     * @param component
     * @param outputTableName
     * @param tabSpaceString
     * @return
     */
@Override
public String buildSqlSelect(DbMapComponent component, String outputTableName, String tabString) {
    //$NON-NLS-1$
    queryColumnsName = "\"";
    aliasAlreadyDeclared.clear();
    this.tabSpaceString = tabString;
    List<IConnection> outputConnections = (List<IConnection>) component.getOutgoingConnections();
    Map<String, IConnection> nameToOutputConnection = new HashMap<String, IConnection>();
    for (IConnection connection : outputConnections) {
        nameToOutputConnection.put(connection.getUniqueName(), connection);
    }
    ExternalDbMapData data = (ExternalDbMapData) component.getExternalData();
    StringBuilder sb = new StringBuilder();
    List<ExternalDbMapTable> outputTables = data.getOutputTables();
    int lstOutputTablesSize = outputTables.size();
    ExternalDbMapTable outputTable = null;
    for (int i = 0; i < lstOutputTablesSize; i++) {
        ExternalDbMapTable temp = outputTables.get(i);
        if (outputTableName.equals(temp.getName())) {
            outputTable = temp;
            break;
        }
    }
    if (outputTable != null) {
        IConnection connection = nameToOutputConnection.get(outputTable.getName());
        List<IMetadataColumn> columns = new ArrayList<IMetadataColumn>();
        if (connection != null) {
            IMetadataTable metadataTable = connection.getMetadataTable();
            if (metadataTable != null) {
                columns.addAll(metadataTable.getListColumns());
            // call this function seems no use now but only problems
            // outputTable = removeUnmatchingEntriesWithColumnsOfMetadataTable(outputTable, metadataTable);
            }
        }
        //$NON-NLS-1$
        sb.append("\"");
        sb.append(DbMapSqlConstants.SELECT);
        sb.append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString);
        List<ExternalDbMapEntry> metadataTableEntries = outputTable.getMetadataTableEntries();
        if (metadataTableEntries != null) {
            int lstSizeOutTableEntries = metadataTableEntries.size();
            for (int i = 0; i < lstSizeOutTableEntries; i++) {
                ExternalDbMapEntry dbMapEntry = metadataTableEntries.get(i);
                String expression = dbMapEntry.getExpression();
                expression = initExpression(component, dbMapEntry);
                expression = addQuoteForSpecialChar(expression, component);
                // for (IMetadataColumn column : columns) {
                // if (expression != null && column.getLabel().equals(dbMapEntry.getName())) {
                //                            expression = expression.replaceFirst("." + dbMapEntry.getName(), //$NON-NLS-1$
                //                                    "." + column.getOriginalDbColumnName()); //$NON-NLS-1$
                // break;
                // }
                // }
                boolean added = false;
                if (!DEFAULT_TAB_SPACE_STRING.equals(this.tabSpaceString)) {
                    expression += DbMapSqlConstants.SPACE + DbMapSqlConstants.AS + DbMapSqlConstants.SPACE + getAliasOf(dbMapEntry.getName());
                    added = true;
                }
                if (i > 0) {
                    sb.append(DbMapSqlConstants.COMMA);
                    sb.append(DbMapSqlConstants.SPACE);
                    queryColumnsName += DbMapSqlConstants.COMMA + DbMapSqlConstants.SPACE;
                }
                if (expression != null && expression.trim().length() > 0) {
                    sb.append(expression);
                    if (component.getMapperMain() == null) {
                        component.getExternalEmfData();
                    }
                    if (component.getMapperMain() != null) {
                        MapperManager mapperManager = component.getMapperMain().getMapperManager();
                        DataMapExpressionParser dataMapExpressionParser = new DataMapExpressionParser(mapperManager.getCurrentLanguage());
                        TableEntryLocation[] tableEntriesLocationsSources = dataMapExpressionParser.parseTableEntryLocations(expression);
                        boolean columnChanged = false;
                        if (tableEntriesLocationsSources.length > 1) {
                            columnChanged = true;
                        } else {
                            for (TableEntryLocation tableEntriesLocationsSource : tableEntriesLocationsSources) {
                                TableEntryLocation location = tableEntriesLocationsSource;
                                String entryName = getAliasOf(dbMapEntry.getName());
                                if (location != null && entryName != null && !entryName.startsWith("_") && !entryName.equals(location.columnName)) {
                                    //$NON-NLS-1$
                                    columnChanged = true;
                                }
                            }
                        }
                        if (!added && columnChanged) {
                            sb.append(DbMapSqlConstants.SPACE + DbMapSqlConstants.AS + DbMapSqlConstants.SPACE + getAliasOf(dbMapEntry.getName()));
                        }
                    }
                    queryColumnsName += expression;
                } else {
                    sb.append(DbMapSqlConstants.LEFT_COMMENT);
                    String str = outputTable.getName() + DbMapSqlConstants.DOT + dbMapEntry.getName();
                    //$NON-NLS-1$
                    sb.append(Messages.getString("DbGenerationManager.OuputExpSetMessage", str));
                    sb.append(DbMapSqlConstants.RIGHT_COMMENT);
                }
            }
        }
        sb.append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString);
        sb.append(DbMapSqlConstants.FROM);
        List<ExternalDbMapTable> inputTables = data.getInputTables();
        // load input table in hash
        boolean explicitJoin = false;
        int lstSizeInputTables = inputTables.size();
        Map<String, ExternalDbMapTable> nameToInputTable = new HashMap<String, ExternalDbMapTable>();
        for (int i = 0; i < lstSizeInputTables; i++) {
            ExternalDbMapTable inputTable = inputTables.get(i);
            nameToInputTable.put(inputTable.getName(), inputTable);
            IJoinType joinType = language.getJoin(inputTable.getJoinType());
            if (!language.unuseWithExplicitJoin().contains(joinType) && i > 0) {
                explicitJoin = true;
            }
        }
        StringBuilder sbWhere = new StringBuilder();
        boolean isFirstClause = true;
        for (int i = 0; i < lstSizeInputTables; i++) {
            ExternalDbMapTable inputTable = inputTables.get(i);
            if (buildConditions(component, sbWhere, inputTable, false, isFirstClause)) {
                isFirstClause = false;
            }
        }
        sb.append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString);
        IJoinType previousJoinType = null;
        for (int i = 0; i < lstSizeInputTables; i++) {
            ExternalDbMapTable inputTable = inputTables.get(i);
            IJoinType joinType = null;
            if (i == 0) {
                joinType = AbstractDbLanguage.JOIN.NO_JOIN;
            } else {
                joinType = language.getJoin(inputTable.getJoinType());
            }
            boolean commaCouldBeAdded = !explicitJoin && i > 0;
            boolean crCouldBeAdded = false;
            if (language.unuseWithExplicitJoin().contains(joinType) && !explicitJoin) {
                buildTableDeclaration(component, sb, inputTable, commaCouldBeAdded, crCouldBeAdded, false);
            } else if (!language.unuseWithExplicitJoin().contains(joinType) && explicitJoin) {
                if (i > 0) {
                    if (previousJoinType == null) {
                        buildTableDeclaration(component, sb, inputTables.get(i - 1), commaCouldBeAdded, crCouldBeAdded, true);
                        previousJoinType = joinType;
                    } else {
                        sb.append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString);
                    }
                    sb.append(DbMapSqlConstants.SPACE);
                }
                String labelJoinType = joinType.getLabel();
                sb.append(labelJoinType);
                sb.append(DbMapSqlConstants.SPACE);
                if (joinType == AbstractDbLanguage.JOIN.CROSS_JOIN) {
                    ExternalDbMapTable nextTable = null;
                    if (i < lstSizeInputTables) {
                        nextTable = inputTables.get(i);
                        buildTableDeclaration(component, sb, nextTable, false, false, true);
                    }
                } else {
                    // ExternalDbMapTable rightTable = joinLeftToJoinRightTables.get(inputTable.getName());
                    buildTableDeclaration(component, sb, inputTable, false, false, true);
                    // if (rightTable != null) {
                    // } else {
                    // sb.append(" <!! NO JOIN CLAUSES FOR '" + inputTable.getName() + "' !!> ");
                    // }
                    sb.append(DbMapSqlConstants.SPACE);
                    sb.append(DbMapSqlConstants.ON);
                    sb.append(DbMapSqlConstants.LEFT_BRACKET);
                    sb.append(DbMapSqlConstants.SPACE);
                    if (!buildConditions(component, sb, inputTable, true, true)) {
                        sb.append(DbMapSqlConstants.LEFT_COMMENT);
                        sb.append(DbMapSqlConstants.SPACE);
                        //$NON-NLS-1$
                        sb.append(Messages.getString("DbGenerationManager.conditionNotSet"));
                        sb.append(DbMapSqlConstants.SPACE);
                        sb.append(DbMapSqlConstants.RIGHT_COMMENT);
                    }
                    sb.append(DbMapSqlConstants.SPACE);
                    sb.append(DbMapSqlConstants.RIGHT_BRACKET);
                }
            }
        }
        /*
             * for addition conditions
             */
        // like as input.newcolumn1>100
        List<String> whereAddition = new ArrayList<String>();
        // olny pure start with group or order, like as order/group by input.newcolumn1
        // List<String> byAddition = new ArrayList<String>();
        // like as input.newcolumn1>100 group/oder by input.newcolumn1
        // List<String> containWhereAddition = new ArrayList<String>();
        // like as "OR/AND input.newcolumn1", will keep original
        List<String> originalWhereAddition = new ArrayList<String>();
        List<String> otherAddition = new ArrayList<String>();
        if (outputTable != null) {
            List<ExternalDbMapEntry> customWhereConditionsEntries = outputTable.getCustomWhereConditionsEntries();
            if (customWhereConditionsEntries != null) {
                for (ExternalDbMapEntry entry : customWhereConditionsEntries) {
                    String exp = initExpression(component, entry);
                    if (exp != null && !DbMapSqlConstants.EMPTY.equals(exp.trim())) {
                        // } else
                        if (containWith(exp, DbMapSqlConstants.OR, true) || containWith(exp, DbMapSqlConstants.AND, true)) {
                            originalWhereAddition.add(exp);
                        } else {
                            whereAddition.add(exp);
                        }
                    }
                }
            }
            List<ExternalDbMapEntry> customOtherConditionsEntries = outputTable.getCustomOtherConditionsEntries();
            if (customOtherConditionsEntries != null) {
                for (ExternalDbMapEntry entry : customOtherConditionsEntries) {
                    String exp = initExpression(component, entry);
                    if (exp != null && !DbMapSqlConstants.EMPTY.equals(exp.trim())) {
                        otherAddition.add(exp);
                    }
                }
            }
        }
        String whereClauses = sbWhere.toString();
        boolean whereFlag = whereClauses.trim().length() > 0;
        boolean whereAddFlag = !whereAddition.isEmpty();
        boolean whereOriginalFlag = !originalWhereAddition.isEmpty();
        if (whereFlag || whereAddFlag || whereOriginalFlag) {
            sb.append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString);
            sb.append(DbMapSqlConstants.WHERE);
        }
        if (whereFlag) {
            sb.append(whereClauses);
        }
        if (whereAddFlag) {
            for (int i = 0; i < whereAddition.size(); i++) {
                if (i == 0 && whereFlag || i > 0) {
                    sb.append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString);
                    sb.append(DbMapSqlConstants.SPACE);
                    sb.append(DbMapSqlConstants.AND);
                }
                sb.append(DbMapSqlConstants.SPACE);
                sb.append(whereAddition.get(i));
            }
        }
        if (whereOriginalFlag) {
            for (String s : originalWhereAddition) {
                sb.append(DbMapSqlConstants.NEW_LINE);
                sb.append(DbMapSqlConstants.SPACE);
                sb.append(s);
            }
        }
        if (!otherAddition.isEmpty()) {
            sb.append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString);
            for (String s : otherAddition) {
                sb.append(s);
                sb.append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString);
            }
        }
    }
    String sqlQuery = sb.toString();
    if (DEFAULT_TAB_SPACE_STRING.equals(tabSpaceString)) {
        List<String> contextList = getContextList(component);
        boolean haveReplace = false;
        for (String context : contextList) {
            if (sqlQuery.contains(context)) {
                //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                sqlQuery = sqlQuery.replaceAll("\\b" + context + "\\b", "\" +" + context + "+ \"");
                haveReplace = true;
            }
            if (queryColumnsName.contains(context)) {
                //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                queryColumnsName = queryColumnsName.replaceAll("\\b" + context + "\\b", "\" +" + context + "+ \"");
            }
        }
        if (!haveReplace) {
            List<String> connContextList = getConnectionContextList(component);
            for (String context : connContextList) {
                if (sqlQuery.contains(context)) {
                    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                    sqlQuery = sqlQuery.replaceAll("\\b" + context + "\\b", "\" +" + context + "+ \"");
                }
                if (queryColumnsName.contains(context)) {
                    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                    queryColumnsName = queryColumnsName.replaceAll("\\b" + context + "\\b", "\" +" + context + "+ \"");
                }
            }
        }
    }
    sqlQuery = handleQuery(sqlQuery);
    queryColumnsName = handleQuery(queryColumnsName);
    return sqlQuery;
}
Also used : HashMap(java.util.HashMap) ExternalDbMapData(org.talend.designer.dbmap.external.data.ExternalDbMapData) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) TableEntryLocation(org.talend.designer.dbmap.model.tableentry.TableEntryLocation) ArrayList(java.util.ArrayList) List(java.util.List) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry) MapperManager(org.talend.designer.dbmap.managers.MapperManager) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) DataMapExpressionParser(org.talend.designer.dbmap.utils.DataMapExpressionParser) IJoinType(org.talend.designer.dbmap.language.IJoinType)

Example 13 with TableEntryLocation

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

the class MapperManager method replaceLocation.

/**
     * 
     * DOC amaumont Comment method "replaceLocation".
     * 
     * @param previousLocation
     * @param newLocation
     * @param dataMapExpressionParser
     * @param table
     * @param entry
     * @return true if expression of entry has changed
     */
private boolean replaceLocation(final TableEntryLocation previousLocation, final TableEntryLocation newLocation, DataMapExpressionParser dataMapExpressionParser, IDataMapTable table, ITableEntry entry) {
    boolean expressionHasChanged = false;
    String currentExpression = entry.getExpression();
    TableEntryLocation[] tableEntryLocations = dataMapExpressionParser.parseTableEntryLocations(currentExpression);
    // loop on all locations of current expression
    for (TableEntryLocation currentLocation : tableEntryLocations) {
        if (currentLocation.equals(previousLocation)) {
            currentExpression = dataMapExpressionParser.replaceLocation(currentExpression, previousLocation, newLocation);
            expressionHasChanged = true;
        }
    }
    if (expressionHasChanged) {
        entry.setExpression(currentExpression);
        DataMapTableView dataMapTableView = retrieveIDataMapTableView(table);
        TableViewerCreator tableViewerCreator = null;
        if (entry instanceof IColumnEntry) {
            tableViewerCreator = dataMapTableView.getTableViewerCreatorForColumns();
        } else if (entry instanceof FilterTableEntry) {
            if (FilterTableEntry.OTHER_FILTER.equals(((FilterTableEntry) entry).getFilterKind())) {
                tableViewerCreator = dataMapTableView.getTableViewerCreatorForOtherFilters();
            } else {
                tableViewerCreator = dataMapTableView.getTableViewerCreatorForWhereFilters();
            }
        }
        tableViewerCreator.getTableViewer().refresh(entry);
        uiManager.parseExpression(currentExpression, entry, false, true, false);
        return true;
    }
    return false;
}
Also used : TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) TableEntryLocation(org.talend.designer.dbmap.model.tableentry.TableEntryLocation) FilterTableEntry(org.talend.designer.dbmap.model.tableentry.FilterTableEntry) InputDataMapTableView(org.talend.designer.dbmap.ui.visualmap.table.InputDataMapTableView) OutputDataMapTableView(org.talend.designer.dbmap.ui.visualmap.table.OutputDataMapTableView) DataMapTableView(org.talend.designer.dbmap.ui.visualmap.table.DataMapTableView) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry)

Example 14 with TableEntryLocation

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

the class TableEntriesManager method renameEntryName.

/**
     * DOC amaumont Comment method "renameEntryName".
     * 
     * @param dataMapTableEntry
     * @param newColumnName
     * @param newColumnName
     */
public void renameEntryName(ITableEntry dataMapTableEntry, String previousColumnName, String newColumnName) {
    TableEntryLocation tableEntryLocationKey = new TableEntryLocation(dataMapTableEntry.getParentName(), previousColumnName);
    // TableEntriesManager.buildLocation(dataMapTableEntry);
    ITableEntry entry = tableEntries.get(tableEntryLocationKey);
    if (entry != dataMapTableEntry) {
        //$NON-NLS-1$
        throw new IllegalStateException(Messages.getString("TableEntriesManager.exceptionMessage.tableEntriesNotSame"));
    }
    tableEntries.remove(tableEntryLocationKey);
    tableEntryLocationKey.columnName = newColumnName;
    tableEntries.put(tableEntryLocationKey, dataMapTableEntry);
    // update matching column
    IMetadataColumn metadataColumn = null;
    InputTable inputTable = isPhysicalTable(dataMapTableEntry.getParent());
    if (inputTable != null) {
        metadataColumn = getColumnFromDbTable(inputTable.getName(), dataMapTableEntry.getName());
        removeMetadataColumnFromDbTable(inputTable.getTableName(), dataMapTableEntry.getName());
        addMetadataColumnFromDbTable(inputTable.getTableName(), newColumnName, metadataColumn);
    }
    dataMapTableEntry.setName(newColumnName);
}
Also used : InputTable(org.talend.designer.dbmap.model.table.InputTable) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) TableEntryLocation(org.talend.designer.dbmap.model.tableentry.TableEntryLocation) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Example 15 with TableEntryLocation

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

the class DataMapExpressionParser method addTablePrefixToColumnName.

public String addTablePrefixToColumnName(String expression, TableEntryLocation[] locations) {
    String returnedExpression = expression;
    for (TableEntryLocation location : locations) {
        recompilePatternIfNecessary(StringHelper.replacePrms(language.getSubstPatternForPrefixColumnName(), new Object[] { location.tableName, location.columnName }));
        if (returnedExpression != null) {
            matcher.setMultiline(true);
            Perl5Substitution substitution = new Perl5Substitution(//$NON-NLS-1$
            language.getPrefixTableRegexp() + "$1" + language.getPrefixFieldRegexp() + "$1__$2" + language.getSuffixFieldRegexp(), //$NON-NLS-1$
            Perl5Substitution.INTERPOLATE_ALL);
            returnedExpression = Util.substitute(matcher, pattern, substitution, returnedExpression, Util.SUBSTITUTE_ALL);
        }
    }
    return returnedExpression;
}
Also used : Perl5Substitution(org.apache.oro.text.regex.Perl5Substitution) TableEntryLocation(org.talend.designer.dbmap.model.tableentry.TableEntryLocation)

Aggregations

TableEntryLocation (org.talend.designer.dbmap.model.tableentry.TableEntryLocation)16 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)6 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)6 ArrayList (java.util.ArrayList)5 IColumnEntry (org.talend.designer.abstractmap.model.tableentry.IColumnEntry)5 DataMapTableView (org.talend.designer.dbmap.ui.visualmap.table.DataMapTableView)5 InputDataMapTableView (org.talend.designer.dbmap.ui.visualmap.table.InputDataMapTableView)4 OutputDataMapTableView (org.talend.designer.dbmap.ui.visualmap.table.OutputDataMapTableView)4 TableViewerCreator (org.talend.commons.ui.swt.tableviewer.TableViewerCreator)3 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)3 ExternalDbMapTable (org.talend.designer.dbmap.external.data.ExternalDbMapTable)3 List (java.util.List)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 Point (org.eclipse.swt.graphics.Point)2 MetadataTableEditor (org.talend.core.ui.metadata.editor.MetadataTableEditor)2 MetadataTableEditorView (org.talend.core.ui.metadata.editor.MetadataTableEditorView)2 ExternalDbMapEntry (org.talend.designer.dbmap.external.data.ExternalDbMapEntry)2 AbstractInOutTable (org.talend.designer.dbmap.model.table.AbstractInOutTable)2 InputTable (org.talend.designer.dbmap.model.table.InputTable)2 FilterTableEntry (org.talend.designer.dbmap.model.tableentry.FilterTableEntry)2