Search in sources :

Example 1 with DbGenerationManager

use of org.talend.designer.dbmap.language.generation.DbGenerationManager in project tdi-studio-se by Talend.

the class PostgresGenerationManager method getHandledTableName.

protected String getHandledTableName(DbMapComponent component, String name, String aliasName, boolean generateSubSql) {
    List<IConnection> inputConnections = (List<IConnection>) component.getIncomingConnections();
    if (inputConnections == null) {
        return name;
    }
    for (IConnection iconn : inputConnections) {
        boolean inputIsELTDBMap = false;
        INode source = iconn.getSource();
        String schemaStr = "";
        String tableNameStr = "";
        if (source != null) {
            inputIsELTDBMap = isELTDBMap(source);
            if (inputIsELTDBMap) {
                tableNameStr = iconn.getName();
            } else {
                IElementParameter schema = source.getElementParameter("ELT_SCHEMA_NAME");
                IElementParameter tableName = source.getElementParameter("ELT_TABLE_NAME");
                if (schema != null && schema.getValue() != null) {
                    schemaStr = TalendTextUtils.removeQuotes(schema.getValue().toString());
                }
                if (tableName != null && tableName.getValue() != null) {
                    tableNameStr = TalendTextUtils.removeQuotes(tableName.getValue().toString());
                }
            }
        }
        String tableName = schemaStr;
        if ("".equals(tableName)) {
            tableName = tableNameStr;
        } else {
            if (!"".equals(tableNameStr)) {
                tableName = tableName + "." + tableNameStr;
            }
        }
        if (tableName.equals(name)) {
            StringBuffer sb = new StringBuffer();
            if (inputIsELTDBMap && generateSubSql) {
                DbMapComponent externalNode = null;
                if (source instanceof DbMapComponent) {
                    externalNode = (DbMapComponent) source;
                } else {
                    externalNode = (DbMapComponent) source.getExternalNode();
                }
                DbGenerationManager genManager = externalNode.getGenerationManager();
                String deliveredTable = genManager.buildSqlSelect(externalNode, iconn.getMetadataTable().getTableName(), //$NON-NLS-1$
                tabSpaceString + "  ");
                int begin = 1;
                int end = deliveredTable.length() - 1;
                if (begin <= end) {
                    //$NON-NLS-1$ //$NON-NLS-2$
                    sb.append("(").append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString).append("  ");
                    sb.append(deliveredTable.substring(begin, end)).append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString).append(//$NON-NLS-1$
                    " ) ");
                }
                if (aliasName != null && !aliasName.trim().isEmpty()) {
                    tableNameStr = aliasName;
                }
            }
            StringBuffer tempExp = getSchemaAndTable(schemaStr, tableNameStr);
            sb.append(tempExp);
            return sb.toString();
        }
    }
    return name;
}
Also used : INode(org.talend.core.model.process.INode) DbMapComponent(org.talend.designer.dbmap.DbMapComponent) DbGenerationManager(org.talend.designer.dbmap.language.generation.DbGenerationManager) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) IConnection(org.talend.core.model.process.IConnection)

Example 2 with DbGenerationManager

use of org.talend.designer.dbmap.language.generation.DbGenerationManager in project tdi-studio-se by Talend.

the class UIManager method refreshSqlExpression.

/**
     * Refresh Sql select query in the bottom tab and its title.
     */
public void refreshSqlExpression() {
    if (getTabFolderEditors().getSelectionIndex() == 2) {
        mapperManager.getComponent().restoreMapperModelFromInternalData();
        OutputDataMapTableView selectedOutputTableView = getCurrentSelectedOutputTableView();
        if (selectedOutputTableView == null) {
        } else {
            IDataMapTable dataMapTable = selectedOutputTableView.getDataMapTable();
            String tableName = dataMapTable.getName();
            DbGenerationManager generationMnager = mapperManager.getComponent().getGenerationManager();
            String sql = generationMnager.buildSqlSelect(mapperManager.getComponent(), tableName);
            getTabFolderEditors().getItem(2).setText(//$NON-NLS-1$
            Messages.getString("TabFolderEditors.SqlSelectQuery", new Object[] { tableName }));
            getTabFolderEditors().getStyledSqlText().setText(sql);
        }
    }
}
Also used : DbGenerationManager(org.talend.designer.dbmap.language.generation.DbGenerationManager) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) OutputDataMapTableView(org.talend.designer.dbmap.ui.visualmap.table.OutputDataMapTableView)

Aggregations

DbGenerationManager (org.talend.designer.dbmap.language.generation.DbGenerationManager)2 List (java.util.List)1 IConnection (org.talend.core.model.process.IConnection)1 IElementParameter (org.talend.core.model.process.IElementParameter)1 INode (org.talend.core.model.process.INode)1 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)1 DbMapComponent (org.talend.designer.dbmap.DbMapComponent)1 OutputDataMapTableView (org.talend.designer.dbmap.ui.visualmap.table.OutputDataMapTableView)1