Search in sources :

Example 1 with DbMapComponent

use of org.talend.designer.dbmap.DbMapComponent 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 DbMapComponent

use of org.talend.designer.dbmap.DbMapComponent in project tdi-studio-se by Talend.

the class OracleGenerationManagerTest method setUp.

@Before
public void setUp() throws Exception {
    dbMapComponent = new DbMapComponent();
    List<IConnection> incomingConnections = new ArrayList<IConnection>();
    conn = mock(IConnection.class);
    incomingConnections.add(conn);
    dbMapComponent.setIncomingConnections(incomingConnections);
    oracleManager = new OracleGenerationManager();
}
Also used : DbMapComponent(org.talend.designer.dbmap.DbMapComponent) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) Before(org.junit.Before)

Example 3 with DbMapComponent

use of org.talend.designer.dbmap.DbMapComponent in project tdi-studio-se by Talend.

the class UpdateELTMapComponentCommandTest method before.

@Before
public void before() {
    Process process = new Process(createProperty());
    sourceNode = new Node(sourceComponent, process);
    INodeConnector connector = new NodeConnector(sourceNode);
    connector.setName("connector");
    connector.setDefaultConnectionType(EConnectionType.FLOW_MAIN);
    ArrayList<INodeConnector> connectors = new ArrayList<INodeConnector>();
    connectors.add(connector);
    sourceNode.setListConnector(connectors);
    targetNode = new Node(targetComponent, process);
    DbMapComponent component = new DbMapComponent();
    targetNode.setExternalNode(component);
    connection = new Connection(sourceNode, targetNode, EConnectionType.FLOW_MAIN, "connector", "meta", "oldTable", true);
    inputs = (List<ExternalDbMapTable>) targetNode.getExternalData().getInputTables();
    ExternalDbMapTable input = new ExternalDbMapTable();
    input.setName("oldTable");
    input.setTableName("oldTable");
    inputs.add(input);
    outputs = (List<ExternalDbMapTable>) targetNode.getExternalData().getOutputTables();
    ExternalDbMapTable output = new ExternalDbMapTable();
    ExternalDbMapEntry entry = new ExternalDbMapEntry("oldTable", "oldTable.column");
    output.setMetadataTableEntries(new ArrayList<ExternalDbMapEntry>());
    output.getMetadataTableEntries().add(entry);
    outputs.add(output);
}
Also used : DbMapComponent(org.talend.designer.dbmap.DbMapComponent) INodeConnector(org.talend.core.model.process.INodeConnector) NodeConnector(org.talend.designer.core.model.components.NodeConnector) ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) Process(org.talend.designer.core.ui.editor.process.Process) INodeConnector(org.talend.core.model.process.INodeConnector) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry) Before(org.junit.Before)

Example 4 with DbMapComponent

use of org.talend.designer.dbmap.DbMapComponent in project tdi-studio-se by Talend.

the class DbGenerationManager method buildTableDeclaration.

protected void buildTableDeclaration(DbMapComponent component, StringBuilder sb, ExternalDbMapTable inputTable) {
    Object inConns = component.getIncomingConnections();
    List<IConnection> inputConnections = null;
    if (inConns != null) {
        inputConnections = (List<IConnection>) inConns;
    }
    if (inputConnections != null) {
        IConnection iconn = this.getConnectonByName(inputConnections, inputTable.getTableName());
        if (iconn == null) {
            return;
        }
        boolean replace = false;
        String inputTableName = inputTable.getName();
        IMetadataTable metadataTable = iconn.getMetadataTable();
        INode source = iconn.getSource();
        String tableName = metadataTable.getTableName();
        if (isELTDBMap(source)) {
            DbMapComponent externalNode = null;
            if (source instanceof DbMapComponent) {
                externalNode = (DbMapComponent) source;
            } else {
                externalNode = (DbMapComponent) source.getExternalNode();
            }
            DbGenerationManager genManager = externalNode.getGenerationManager();
            /* the new tabSpaceString in subquery must not be same with the parent!!! */
            //$NON-NLS-1$
            String deliveredTable = genManager.buildSqlSelect(externalNode, tableName, 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$
                " ) ");
            }
        }
        String tableColneName = tableName;
        tableColneName = MetadataToolHelper.validateTableName(tableColneName);
        if (inputTableName.contains(".") && tableName != null) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            MapExpressionParser mapParser2 = new MapExpressionParser("\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*");
            List<Map<String, String>> tableNameList = mapParser2.parseInTableEntryLocations(inputTableName);
            for (Map<String, String> tableNameMap : tableNameList) {
                Set<Entry<String, String>> setTable = tableNameMap.entrySet();
                Iterator<Entry<String, String>> iteTable = setTable.iterator();
                while (iteTable.hasNext()) {
                    Entry<String, String> tableEntry = iteTable.next();
                    String tableLabel = tableEntry.getKey();
                    String schemaValue = tableEntry.getValue();
                    if (tableLabel.equals(metadataTable.getLabel()) && tableColneName.equals(tableLabel)) {
                        sb.append(schemaValue);
                        //$NON-NLS-1$
                        sb.append(".");
                        sb.append(tableName);
                        replace = true;
                    }
                }
            }
        } else if (tableName != null) {
            if (inputTableName.equals(metadataTable.getLabel()) && tableColneName.equals(inputTableName)) {
                sb.append(tableName);
                replace = true;
            }
        }
        if (!replace) {
            sb.append(inputTable.getName());
        }
    }
}
Also used : INode(org.talend.core.model.process.INode) IConnection(org.talend.core.model.process.IConnection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry) Entry(java.util.Map.Entry) DbMapComponent(org.talend.designer.dbmap.DbMapComponent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with DbMapComponent

use of org.talend.designer.dbmap.DbMapComponent in project tdi-studio-se by Talend.

the class DbGenerationManagerTest method setUp.

@Before
public void setUp() throws Exception {
    dbMapComponent = new DbMapComponent();
    ExternalDbMapData externalDbMapData = new ExternalDbMapData();
    dbMapComponent.setExternalData(externalDbMapData);
    List<ExternalDbMapTable> inputTables = new ArrayList<>();
    externalDbMapData.setInputTables(inputTables);
    ExternalDbMapTable externalDbMapTable = new ExternalDbMapTable();
    inputTables.add(externalDbMapTable);
    externalDbMapTable.setName("t1");
    externalDbMapTable.setAlias("t1");
    externalDbMapTable.setTableName("t1");
    externalDbMapTable.setJoinType("NO_JOIN");
    tableEntries = new ArrayList<>();
    externalDbMapTable.setMetadataTableEntries(tableEntries);
    extMapEntry = new ExternalDbMapEntry("id", "t1.id");
    tableEntries.add(extMapEntry);
    List<IConnection> incomingConnections = new ArrayList<IConnection>();
    String[] columns = new String[] { "\\\"id\\\"" };
    incomingConnections.add(createConnection("t1", "t1", "id", columns));
    dbMapComponent.setIncomingConnections(incomingConnections);
    dbManager = new GenericDbGenerationManager();
}
Also used : DbMapComponent(org.talend.designer.dbmap.DbMapComponent) ExternalDbMapData(org.talend.designer.dbmap.external.data.ExternalDbMapData) ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry) Before(org.junit.Before)

Aggregations

IConnection (org.talend.core.model.process.IConnection)5 DbMapComponent (org.talend.designer.dbmap.DbMapComponent)5 ArrayList (java.util.ArrayList)3 Before (org.junit.Before)3 ExternalDbMapEntry (org.talend.designer.dbmap.external.data.ExternalDbMapEntry)3 INode (org.talend.core.model.process.INode)2 ExternalDbMapTable (org.talend.designer.dbmap.external.data.ExternalDbMapTable)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 IElementParameter (org.talend.core.model.process.IElementParameter)1 INodeConnector (org.talend.core.model.process.INodeConnector)1 NodeConnector (org.talend.designer.core.model.components.NodeConnector)1 Connection (org.talend.designer.core.ui.editor.connections.Connection)1 Node (org.talend.designer.core.ui.editor.nodes.Node)1 Process (org.talend.designer.core.ui.editor.process.Process)1 ExternalDbMapData (org.talend.designer.dbmap.external.data.ExternalDbMapData)1 DbGenerationManager (org.talend.designer.dbmap.language.generation.DbGenerationManager)1