Search in sources :

Example 1 with MetadataTableRepositoryObject

use of org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject in project tdi-studio-se by Talend.

the class SessionTreeNodeManager method convert2INode.

/**
     * DOC qianbing Comment method "convert2INode". Converts the RepositoryNode input to INode. INode is used for the
     * sql editor,result viewer and the detail viewer.
     * 
     * @param repositoryNode RepositoryNode
     * @param selectedContext
     * @return INode
     */
public INode convert2INode(RepositoryNode repositoryNode, String selectedContext, SessionTreeNode sessionTreeNode) throws Exception {
    // Creates the SessionTreeNode.
    RepositoryNodeType nodeType = getRepositoryType(repositoryNode);
    if (nodeType.equals(RepositoryNodeType.DATABASE)) {
        // processes the database
        DatabaseModel model = sessionTreeNode.getDbModel();
        INode[] nodes = model.getChildNodes();
        DatabaseNode dn = (DatabaseNode) nodes[0];
        return dn;
    } else if (nodeType.equals(RepositoryNodeType.TABLE)) {
        // processes the table
        MetadataTableRepositoryObject tableObject = (MetadataTableRepositoryObject) repositoryNode.getObject();
        MetadataTable table = tableObject.getTable();
        String realName = table.getSourceName();
        DatabaseModel model = sessionTreeNode.getDbModel();
        INode[] nodes = model.getChildNodes();
        DatabaseNode dn = (DatabaseNode) nodes[0];
        nodes = dn.getChildNodes();
        CatalogNode cn = (CatalogNode) nodes[0];
        nodes = cn.getChildNodes();
        if (nodes != null && nodes.length > 0) {
            for (INode node : nodes) {
                TableNode tableNode = (TableNode) node;
                if (tableNode.getName().equals(realName)) {
                    return node;
                }
            }
        }
    } else if (nodeType.equals(RepositoryNodeType.COLUMN)) {
        // Processes the column.
        // Gets the repositoryNode's parent,should be the repositoryNode of table infomation.
        repositoryNode = repositoryNode.getParent();
        return convert2INode(repositoryNode, selectedContext, sessionTreeNode);
    }
    return null;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) DatabaseNode(org.talend.sqlbuilder.dbstructure.nodes.DatabaseNode) CatalogNode(org.talend.sqlbuilder.dbstructure.nodes.CatalogNode) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) MetadataTableRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject)

Example 2 with MetadataTableRepositoryObject

use of org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject in project tdi-studio-se by Talend.

the class MetadataColumnComparator method isChangeElementColor.

/**
     * dev Comment method "isChangeElementColor".
     * 
     * @param node
     * @return
     */
public boolean isChangeElementColor(RepositoryNode node) {
    boolean flag = false;
    Object type = node.getProperties(EProperties.CONTENT_TYPE);
    if (type.equals(RepositoryNodeType.DATABASE)) {
        return getItem(node).getConnection().isDivergency();
    }
    if (type.equals(RepositoryNodeType.TABLE)) {
        MetadataTableRepositoryObject object = (MetadataTableRepositoryObject) node.getObject();
        MetadataTable table = object.getTable();
        flag = table.getSourceName().equals(table.getLabel());
        flag = flag && table.isDivergency();
    }
    return flag;
}
Also used : MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) SqlBuilderRepositoryObject(org.talend.sqlbuilder.dbstructure.SqlBuilderRepositoryObject) MetadataTableRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryObject(org.talend.core.model.repository.RepositoryObject) MetadataColumnRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataColumnRepositoryObject) MetadataTableRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject)

Example 3 with MetadataTableRepositoryObject

use of org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject in project tdi-studio-se by Talend.

the class MetadataColumnComparator method isDiff.

/**
     * dev Comment method "isDiff".
     * 
     * @param node
     * @return
     */
@SuppressWarnings("unchecked")
public boolean[] isDiff(RepositoryNode node) {
    boolean isDiffDivergency = false;
    boolean isDiffSyschronize = false;
    boolean isDiffGray = false;
    Object type = node.getProperties(EProperties.CONTENT_TYPE);
    if (type.equals(RepositoryNodeType.DATABASE)) {
        DatabaseConnection connection = (DatabaseConnection) getItem(node).getConnection();
        Set<MetadataTable> tables = ConnectionHelper.getTables(connection);
        for (MetadataTable table : tables) {
            List<MetadataColumn> columns = table.getColumns();
            for (MetadataColumn column : columns) {
                if (column.isDivergency()) {
                    isDiffDivergency = true;
                }
                if (column.isSynchronised()) {
                    isDiffSyschronize = true;
                }
                if (column.getLabel() == null || "".equals(column.getLabel())) {
                    //$NON-NLS-1$
                    isDiffGray = true;
                }
            }
            if (table.isDivergency()) {
                isDiffDivergency = true;
            }
            if (table.getLabel() == null || "".equals(table.getLabel())) {
                //$NON-NLS-1$
                isDiffGray = true;
            }
        }
    } else if (type.equals(RepositoryNodeType.TABLE)) {
        MetadataTableRepositoryObject object = (MetadataTableRepositoryObject) node.getObject();
        MetadataTable table = object.getTable();
        List<MetadataColumn> columns = table.getColumns();
        for (MetadataColumn column : columns) {
            if (column.isDivergency()) {
                isDiffDivergency = true;
            }
            if (column.isSynchronised()) {
                isDiffSyschronize = true;
            }
            if (column.getLabel() == null || "".equals(column.getLabel())) {
                //$NON-NLS-1$
                isDiffGray = true;
            }
        }
        if (table.isDivergency()) {
            isDiffDivergency = true;
        }
    }
    return new boolean[] { isDiffGray, isDiffDivergency, isDiffSyschronize };
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) SqlBuilderRepositoryObject(org.talend.sqlbuilder.dbstructure.SqlBuilderRepositoryObject) MetadataTableRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryObject(org.talend.core.model.repository.RepositoryObject) MetadataColumnRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataColumnRepositoryObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) List(java.util.List) ArrayList(java.util.ArrayList) MetadataTableRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject)

Example 4 with MetadataTableRepositoryObject

use of org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject in project tdi-studio-se by Talend.

the class SQLBuilderDialog method okPressed.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.dialogs.Dialog#okPressed()
     */
@Override
public void okPressed() {
    // gain the contextmode from sqlbuilder,and set it in connParameters,add by hyWang
    MultiPageSqlBuilderEditor editor = null;
    CTabFolder folder = getEditorComposite().getTabFolder();
    CTabItem[] a = folder.getItems();
    for (CTabItem itm : a) {
        //$NON-NLS-1$
        Object obj = itm.getData("KEY");
        if (obj instanceof MultiPageSqlBuilderEditor) {
            editor = (MultiPageSqlBuilderEditor) obj;
        }
        if (editor != null) {
            if (itm.getData() instanceof Query) {
                Query q = (Query) itm.getData();
                connParameters.setIfContextButtonCheckedFromBuiltIn(q.isContextMode());
            }
        }
    }
    if (EParameterFieldType.DBTABLE.equals(connParameters.getFieldType())) {
        final IStructuredSelection selection = (IStructuredSelection) structureComposite.getTreeViewer().getSelection();
        final Object firstElement = selection.getFirstElement();
        if (firstElement instanceof RepositoryNode) {
            RepositoryNode node = (RepositoryNode) firstElement;
            boolean is = node.getProperties(EProperties.CONTENT_TYPE).equals(RepositoryNodeType.TABLE);
            if (is) {
                MetadataTableRepositoryObject object = (MetadataTableRepositoryObject) node.getObject();
                connParameters.setSelectDBTable(object.getSourceName());
            }
        }
    } else {
        //$NON-NLS-1$
        String sql = "";
        // sql = editorComposite.getDefaultTabSql();
        sql = editorComposite.getCurrentTabSql();
        // if (ConnectionParameters.isJavaProject()) {
        // sql = sql.replace("\"", "\\" + "\"");
        // } else {
        // sql = sql.replace("'", "\\'");
        // }
        // sql = QueryUtil.checkAndAddQuotes(sql);
        connParameters.setQuery(sql);
        if (connParameters.isFromRepository() && !connParameters.isNodeReadOnly()) {
            List<Query> qs = new ArrayList<Query>();
            boolean isInfo = false;
            final CTabFolder tabFolder = getEditorComposite().getTabFolder();
            final CTabItem[] items = tabFolder.getItems();
            for (CTabItem item : items) {
                final String text = item.getText();
                //$NON-NLS-1$
                boolean isInfo2 = text.length() > 1 && text.substring(0, 1).equals("*");
                if (isInfo2) {
                    isInfo = true;
                }
            }
            if (isInfo) {
                //$NON-NLS-1$
                String title = Messages.getString("SQLBuilderDialog.SaveAllQueries.Title");
                //$NON-NLS-1$
                String info = Messages.getString("SQLBuilderDialog.SaveAllQueries.Info");
                boolean openQuestion = MessageDialog.openQuestion(getShell(), title, info);
                if (openQuestion) {
                    for (CTabItem item : items) {
                        final String text = item.getText();
                        //$NON-NLS-1$
                        boolean isInfo2 = text.length() > 1 && text.substring(0, 1).equals("*");
                        if (isInfo2) {
                            MultiPageSqlBuilderEditor meditor = null;
                            //$NON-NLS-1$
                            Object control = item.getData("KEY");
                            if (control instanceof MultiPageSqlBuilderEditor) {
                                meditor = (MultiPageSqlBuilderEditor) control;
                            }
                            if (meditor != null) {
                                RepositoryNode node = null;
                                node = meditor.getActivePageRepositoryNode();
                                if (text.substring(1).startsWith(AbstractSQLEditorComposite.QUERY_PREFIX)) {
                                    if (item.getData() instanceof Query) {
                                        Query q = (Query) item.getData();
                                        q.setValue(meditor.getActivePageSqlString());
                                        // add by hyWang
                                        q.setContextMode(meditor.getActiveEditors().getContextmode().getContextmodeaction().isChecked());
                                        qs.add(q);
                                        if (node != null && q != null) {
                                            manager.saveQuery(node, q, null);
                                        }
                                    }
                                } else {
                                    meditor.getActivePageSaveAsSQLAction().run();
                                }
                            }
                        }
                    }
                }
            }
            if (connParameters.getQueryObject() != null) {
                RepositoryUpdateManager.updateQuery(connParameters.getQueryObject(), node);
            }
        }
    }
    deleteNoUseTable();
    super.okPressed();
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) Query(org.talend.core.model.metadata.builder.connection.Query) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) CTabItem(org.eclipse.swt.custom.CTabItem) MetadataTableRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject) MultiPageSqlBuilderEditor(org.talend.sqlbuilder.editors.MultiPageSqlBuilderEditor) MetadataTableRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 5 with MetadataTableRepositoryObject

use of org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject in project tdi-studio-se by Talend.

the class TableNode method getMetadataTable.

/**
     * Get repository table from table repositoryNode.
     * 
     * @param repositoryNode -- table repositoryNode
     * @return columns
     * @exception
     */
//$NON-NLS-1$
@SuppressWarnings("deprecation")
public static MetadataTable getMetadataTable(RepositoryNode repositoryNode) {
    RepositoryNodeType type = SQLBuilderRepositoryNodeManager.getRepositoryType(repositoryNode);
    if (type != RepositoryNodeType.TABLE) {
        //$NON-NLS-1$
        throw new RuntimeException(Messages.getString("TableNode.exceptionMessage"));
    }
    MetadataTableRepositoryObject tableObject = (MetadataTableRepositoryObject) repositoryNode.getObject();
    return tableObject.getTable();
}
Also used : RepositoryNodeType(org.talend.sqlbuilder.dbstructure.RepositoryNodeType) MetadataTableRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject)

Aggregations

MetadataTableRepositoryObject (org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject)6 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)4 ArrayList (java.util.ArrayList)3 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)3 MetadataColumnRepositoryObject (org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataColumnRepositoryObject)3 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)2 RepositoryObject (org.talend.core.model.repository.RepositoryObject)2 IRepositoryNode (org.talend.repository.model.IRepositoryNode)2 SqlBuilderRepositoryObject (org.talend.sqlbuilder.dbstructure.SqlBuilderRepositoryObject)2 List (java.util.List)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)1 Query (org.talend.core.model.metadata.builder.connection.Query)1 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)1 RepositoryNode (org.talend.repository.model.RepositoryNode)1 RepositoryNodeType (org.talend.sqlbuilder.dbstructure.RepositoryNodeType)1 CatalogNode (org.talend.sqlbuilder.dbstructure.nodes.CatalogNode)1 DatabaseNode (org.talend.sqlbuilder.dbstructure.nodes.DatabaseNode)1