Search in sources :

Example 51 with IRepositoryNode

use of org.talend.repository.model.IRepositoryNode in project tdi-studio-se by Talend.

the class EMFRepositoryNodeManager method parseSqlStatement.

@SuppressWarnings("unchecked")
public List<IRepositoryNode> parseSqlStatement(String sql, RepositoryNode currRoot) throws Exception {
    // inital the quote depence on the dbtype
    IRepositoryViewObject rObject = currRoot.getObject();
    DatabaseConnectionItem item = (DatabaseConnectionItem) rObject.getProperty().getItem();
    DatabaseConnection dbConnection = (DatabaseConnection) item.getConnection();
    String dbType = dbConnection.getDatabaseType();
    leftDbQuote = TalendTextUtils.getQuoteByDBType(dbType, true);
    rightDbQuote = TalendTextUtils.getQuoteByDBType(dbType, false);
    sql = initSqlStatement(sql);
    if (sql == null || "".equals(sql) || !sql.startsWith("select ")) {
        //$NON-NLS-1$ //$NON-NLS-2$
        return Collections.EMPTY_LIST;
    }
    List<String> tableNames = new ArrayList<String>();
    List<String> columnsNames = new ArrayList<String>();
    String[] cols = parseSqlToNameList(sql, tableNames, columnsNames);
    List<IRepositoryNode> nodes = new ArrayList<IRepositoryNode>();
    for (IRepositoryNode tableNode : currRoot.getChildren()) {
        for (int i = 0; i < tableNames.size(); i++) {
            //$NON-NLS-1$
            String tableLabel = "";
            if (tableNode.getObject() instanceof MetadataTableRepositoryObject) {
                MetadataTableRepositoryObject object = (MetadataTableRepositoryObject) tableNode.getObject();
                tableLabel = object.getSourceName();
            } else {
                tableLabel = tableNode.getObject().getLabel();
            }
            boolean isNeed = false;
            if (cols.length == 1 && cols[0].equals("*")) {
                //$NON-NLS-1$
                for (String string : tableNames) {
                    if (string.equals(tableLabel.toLowerCase())) {
                        nodes.add(tableNode);
                        isNeed = true;
                    }
                }
            }
            if (tableLabel != null) {
                for (String string : tableNames) {
                    if (string.equals(tableLabel.toLowerCase())) {
                        isNeed = true;
                    }
                }
            }
            if (isNeed) {
                for (IRepositoryNode colNode : tableNode.getChildren()) {
                    //$NON-NLS-1$
                    String collabel = "";
                    if (colNode.getObject() instanceof MetadataColumnRepositoryObject) {
                        MetadataColumnRepositoryObject object2 = (MetadataColumnRepositoryObject) colNode.getObject();
                        collabel = object2.getSourceName();
                    } else {
                        collabel = colNode.getObject().getLabel();
                    }
                    if (collabel != null) {
                        for (String string : columnsNames) {
                            if ((string.replaceAll("\\" + leftDbQuote, "").replaceAll("\\" + rightDbQuote, "")).equals(//$NON-NLS-1$ //$NON-NLS-2$
                            collabel.toLowerCase())) {
                                nodes.add(colNode);
                            }
                            // right bracket
                            if ((string.replaceAll("\\" + leftDbQuote, "").replaceAll("\\" + rightDbQuote, "")).equals(tableLabel.toLowerCase() + "." + collabel.toLowerCase())) {
                                //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
                                if (!nodes.contains(colNode)) {
                                    nodes.add(colNode);
                                }
                            }
                            for (int j = 0; j < relations.size(); j++) {
                                String[] pks = relations.get(j);
                                String pk = pks[0];
                                String fk = pks[1];
                                boolean isSet = false;
                                if (pk.equals(collabel.toLowerCase())) {
                                    isSet = true;
                                    //$NON-NLS-1$
                                    pk = tableLabel.toLowerCase() + "." + collabel.toLowerCase();
                                    if (!nodes.contains(colNode)) {
                                        nodes.add(colNode);
                                    }
                                }
                                if (fk.equals(collabel.toLowerCase())) {
                                    isSet = true;
                                    //$NON-NLS-1$
                                    fk = tableLabel.toLowerCase() + "." + collabel.toLowerCase();
                                    if (!nodes.contains(colNode)) {
                                        nodes.add(colNode);
                                    }
                                }
                                if (pk.equals(tableLabel.toLowerCase() + "." + collabel.toLowerCase())) {
                                    //$NON-NLS-1$
                                    if (!nodes.contains(colNode)) {
                                        nodes.add(colNode);
                                    }
                                }
                                if (fk.equals(tableLabel.toLowerCase() + "." + collabel.toLowerCase())) {
                                    //$NON-NLS-1$
                                    if (!nodes.contains(colNode)) {
                                        nodes.add(colNode);
                                    }
                                }
                                if (isSet) {
                                    relations.set(j, new String[] { pk, fk });
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return nodes;
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) ArrayList(java.util.ArrayList) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) MetadataTableRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) MetadataColumnRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataColumnRepositoryObject)

Example 52 with IRepositoryNode

use of org.talend.repository.model.IRepositoryNode in project tdi-studio-se by Talend.

the class EMFRepositoryNodeManager method getTables.

@SuppressWarnings("unchecked")
public List<MetadataTable> getTables(List<IRepositoryNode> nodes, List<MetadataColumn> selectedColumns) {
    List<MetadataTable> tables = new ArrayList<MetadataTable>();
    for (IRepositoryNode node : nodes) {
        RepositoryNodeType type = SQLBuilderRepositoryNodeManager.getRepositoryType((RepositoryNode) node);
        if (type == RepositoryNodeType.DATABASE) {
            root = (RepositoryNode) node;
            DatabaseConnection connection = (DatabaseConnection) SQLBuilderRepositoryNodeManager.getItem((RepositoryNode) node).getConnection();
            for (MetadataTable table : ConnectionHelper.getTables(connection)) {
                if (!tables.contains(table)) {
                    tables.add(table);
                    selectedColumns.addAll(table.getColumns());
                }
            }
            // if database is selected , It does not need to check others.
            break;
        } else if (type == RepositoryNodeType.TABLE) {
            MetadataTable table = ((MetadataTableRepositoryObject) node.getObject()).getTable();
            if (!tables.contains(table)) {
                tables.add(table);
                selectedColumns.addAll(table.getColumns());
            }
            root = SQLBuilderRepositoryNodeManager.getRoot((RepositoryNode) node);
        } else if (type == RepositoryNodeType.COLUMN) {
            MetadataColumn column = ((MetadataColumnRepositoryObject) node.getObject()).getColumn();
            if (!selectedColumns.contains(column)) {
                selectedColumns.add(column);
            }
            MetadataTable table = column.getTable();
            if (!tables.contains(table)) {
                tables.add(table);
            }
            root = SQLBuilderRepositoryNodeManager.getRoot((RepositoryNode) node);
        }
        setRoot(null);
    }
    return tables;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) IRepositoryNode(org.talend.repository.model.IRepositoryNode) RepositoryNodeType(org.talend.sqlbuilder.dbstructure.RepositoryNodeType) ArrayList(java.util.ArrayList) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) MetadataColumnRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataColumnRepositoryObject) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode)

Example 53 with IRepositoryNode

use of org.talend.repository.model.IRepositoryNode in project tdi-studio-se by Talend.

the class StatusManagerSettingPage method expandSomeNodes.

private void expandSomeNodes(IProjectRepositoryNode root) {
    if (root instanceof IProjectRepositoryNode) {
        final IProjectRepositoryNode rootNode = root;
        // metadata
        IRepositoryNode metadataConNode = rootNode.getRootRepositoryNode(ERepositoryObjectType.METADATA);
        if (metadataConNode != null) {
            treeViewer.expandToLevel(metadataConNode, 1);
        }
        // code
        IRepositoryNode codeNode = rootNode.getRootRepositoryNode(ERepositoryObjectType.CODE);
        if (codeNode != null) {
            treeViewer.expandToLevel(codeNode, 1);
        }
    }
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) IProjectRepositoryNode(org.talend.repository.model.nodes.IProjectRepositoryNode)

Example 54 with IRepositoryNode

use of org.talend.repository.model.IRepositoryNode in project tdi-studio-se by Talend.

the class JobExportAction method getProcesses.

private static List<ExportFileResource> getProcesses(Collection<? extends IRepositoryNode> nodes, String path) {
    List<ExportFileResource> value = new ArrayList<ExportFileResource>();
    for (IRepositoryNode node : nodes) {
        if (node.getType() == ENodeType.SYSTEM_FOLDER || node.getType() == ENodeType.SIMPLE_FOLDER) {
            value.addAll(getProcesses(node.getChildren(), node.getProperties(EProperties.LABEL).toString() + '/'));
        }
        if (node.getType() == ENodeType.REPOSITORY_ELEMENT) {
            IRepositoryViewObject repositoryObject = node.getObject();
            if (repositoryObject.getProperty().getItem() instanceof ProcessItem) {
                ProcessItem processItem = (ProcessItem) repositoryObject.getProperty().getItem();
                ExportFileResource resource = new ExportFileResource(processItem, path + processItem.getProperty().getLabel());
                resource.setNode(node);
                value.add(resource);
            }
        }
    }
    return value;
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) ProcessItem(org.talend.core.model.properties.ProcessItem) ExportFileResource(org.talend.repository.documentation.ExportFileResource) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 55 with IRepositoryNode

use of org.talend.repository.model.IRepositoryNode in project tdi-studio-se by Talend.

the class BuildJobManager method getProcesses.

private List<ProcessItem> getProcesses(List<? extends IRepositoryNode> nodes) {
    List<ProcessItem> value = new ArrayList<ProcessItem>();
    for (IRepositoryNode node : nodes) {
        if (node.getType() == ENodeType.SYSTEM_FOLDER || node.getType() == ENodeType.SIMPLE_FOLDER) {
            value.addAll(getProcesses(node.getChildren()));
        }
        if (node.getType() == ENodeType.REPOSITORY_ELEMENT) {
            IRepositoryViewObject repositoryObject = node.getObject();
            if (repositoryObject.getProperty().getItem() instanceof ProcessItem) {
                ProcessItem processItem = (ProcessItem) repositoryObject.getProperty().getItem();
                value.add(processItem);
            }
        }
    }
    return value;
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Aggregations

IRepositoryNode (org.talend.repository.model.IRepositoryNode)73 RepositoryNode (org.talend.repository.model.RepositoryNode)24 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)21 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)13 PersistenceException (org.talend.commons.exception.PersistenceException)13 ArrayList (java.util.ArrayList)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 WizardDialog (org.eclipse.jface.wizard.WizardDialog)10 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)8 IEditorPart (org.eclipse.ui.IEditorPart)8 ProjectRepositoryNode (org.talend.core.repository.model.ProjectRepositoryNode)8 ISelection (org.eclipse.jface.viewers.ISelection)6 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)6 ProcessItem (org.talend.core.model.properties.ProcessItem)6 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)6 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)6 IRepositoryView (org.talend.repository.ui.views.IRepositoryView)6 IPath (org.eclipse.core.runtime.IPath)5 PartInitException (org.eclipse.ui.PartInitException)5 Item (org.talend.core.model.properties.Item)5