Search in sources :

Example 1 with TableNode

use of org.talend.sqlbuilder.dbstructure.nodes.TableNode 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 TableNode

use of org.talend.sqlbuilder.dbstructure.nodes.TableNode in project tdi-studio-se by Talend.

the class ImportedKeysTab method getDataSet.

public DataSet getDataSet() throws Exception {
    INode node = getNode();
    if (node == null) {
        return null;
    }
    if (node.getSession() == null) {
        return null;
    }
    if (node instanceof TableNode) {
        TableNode tableNode = (TableNode) node;
        ITableInfo ti = tableNode.getTableInfo();
        if (tableNode.getTableInfo() == null) {
            return null;
        }
        ResultSet resultSet = null;
        SessionTreeNode treeNode = node.getSession();
        // For synonym table, should get the corresponding table.
        if (ti.getType().equals("SYNONYM")) {
            //$NON-NLS-1$
            String realTableName = ExtractMetaDataFromDataBase.getTableNameBySynonym(treeNode.getInteractiveConnection().getConnection(), ti.getSimpleName());
            resultSet = treeNode.getMetaData().getJDBCMetaData().getImportedKeys(ti.getCatalogName(), ti.getSchemaName(), realTableName);
        } else {
            resultSet = node.getSession().getMetaData().getImportedKeys((tableNode.getTableInfo()));
        }
        DataSet dataSet = new DataSet(null, resultSet, new int[] { 3, 4, 8, 9, 10, 11, 12, 13, 14 });
        resultSet.close();
        return dataSet;
    }
    return null;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) ITableInfo(net.sourceforge.squirrel_sql.fw.sql.ITableInfo) DataSet(org.talend.sqlbuilder.dataset.dataset.DataSet) SessionTreeNode(org.talend.sqlbuilder.sessiontree.model.SessionTreeNode) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) ResultSet(java.sql.ResultSet)

Example 3 with TableNode

use of org.talend.sqlbuilder.dbstructure.nodes.TableNode in project tdi-studio-se by Talend.

the class PrimaryKeysTab method getDataSet.

public DataSet getDataSet() throws Exception {
    INode node = getNode();
    if (node == null) {
        return null;
    }
    if (node.getSession() == null) {
        return null;
    }
    if (node instanceof TableNode) {
        TableNode tableNode = (TableNode) node;
        ITableInfo ti = tableNode.getTableInfo();
        if (tableNode.getTableInfo() == null) {
            return null;
        }
        ResultSet resultSet = null;
        SessionTreeNode treeNode = node.getSession();
        // For synonym table, should get the corresponding table name .
        if (ti.getType().equals("SYNONYM")) {
            //$NON-NLS-1$
            String realTableName = ExtractMetaDataFromDataBase.getTableNameBySynonym(treeNode.getInteractiveConnection().getConnection(), ti.getSimpleName());
            resultSet = treeNode.getMetaData().getJDBCMetaData().getPrimaryKeys(ti.getCatalogName(), ti.getSchemaName(), realTableName);
        } else {
            resultSet = node.getSession().getMetaData().getPrimaryKeys((tableNode.getTableInfo()));
        }
        DataSet dataSet = new DataSet(null, resultSet, new int[] { 4, 5, 6 });
        resultSet.close();
        return dataSet;
    }
    return null;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) ITableInfo(net.sourceforge.squirrel_sql.fw.sql.ITableInfo) DataSet(org.talend.sqlbuilder.dataset.dataset.DataSet) SessionTreeNode(org.talend.sqlbuilder.sessiontree.model.SessionTreeNode) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) ResultSet(java.sql.ResultSet)

Example 4 with TableNode

use of org.talend.sqlbuilder.dbstructure.nodes.TableNode in project tdi-studio-se by Talend.

the class ExportedKeysTab method getDataSet.

public DataSet getDataSet() throws Exception {
    INode node = getNode();
    if (node == null) {
        return null;
    }
    if (node.getSession() == null) {
        return null;
    }
    if (node instanceof TableNode) {
        TableNode tableNode = (TableNode) node;
        ITableInfo ti = tableNode.getTableInfo();
        if (tableNode.getTableInfo() == null) {
            return null;
        }
        ResultSet resultSet = null;
        SessionTreeNode treeNode = node.getSession();
        // For synonym table, should get the corresponding table.
        if (ti.getType().equals("SYNONYM")) {
            //$NON-NLS-1$
            String realTableName = ExtractMetaDataFromDataBase.getTableNameBySynonym(treeNode.getInteractiveConnection().getConnection(), ti.getSimpleName());
            resultSet = treeNode.getMetaData().getJDBCMetaData().getExportedKeys(ti.getCatalogName(), ti.getSchemaName(), realTableName);
        } else {
            resultSet = node.getSession().getMetaData().getExportedKeys((tableNode.getTableInfo()));
        }
        DataSet dataSet = new DataSet(null, resultSet, new int[] { 4, 7, 8, 9, 10, 11, 12, 13, 14 });
        resultSet.close();
        return dataSet;
    }
    return null;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) ITableInfo(net.sourceforge.squirrel_sql.fw.sql.ITableInfo) DataSet(org.talend.sqlbuilder.dataset.dataset.DataSet) SessionTreeNode(org.talend.sqlbuilder.sessiontree.model.SessionTreeNode) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) ResultSet(java.sql.ResultSet)

Example 5 with TableNode

use of org.talend.sqlbuilder.dbstructure.nodes.TableNode in project tdi-studio-se by Talend.

the class UnsignedWordRule method evaluate.

//$NON-NLS-1$
@SuppressWarnings("unchecked")
public IToken evaluate(ICharacterScanner scanner) {
    int c = scanner.read();
    if (fDetector.isWordStart((char) c)) {
        if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {
            fBuffer.setLength(0);
            do {
                fBuffer.append((char) c);
                c = scanner.read();
            } while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c));
            scanner.unread();
            String tokenName = fBuffer.substring(0, fBuffer.length()).toLowerCase();
            IToken token = (IToken) fWords.get(tokenName);
            if (token != null) {
                if ((token == fTableToken) && (dictionary != null)) {
                    ArrayList list = (ArrayList) dictionary.getByTableName(tokenName);
                    if (list != null) {
                        for (int j = 0; j < list.size(); j++) {
                            TableNode nd = (TableNode) list.get(j);
                            ArrayList ls = null;
                            try {
                                ls = (ArrayList) nd.getColumnNames();
                            } catch (Throwable e) {
                                //$NON-NLS-1$
                                SqlBuilderPlugin.log(Messages.getString("UnsignedWordRule.logMessage"), e);
                            }
                            if (ls != null) {
                                TreeSet colTree = (TreeSet) dictionary.getColumnListByTableName(tokenName);
                                if (colTree == null && j == 0) {
                                    colTree = new TreeSet();
                                    dictionary.putColumnsByTableName(tokenName, colTree);
                                    for (int i = 0; i < ls.size(); i++) {
                                        String lo = ((String) ls.get(i));
                                        addWord(lo, fColumnToken);
                                        colTree.add(lo);
                                    }
                                }
                            }
                        }
                    }
                }
                return token;
            }
            if (fDefaultToken.isUndefined()) {
                unreadBuffer(scanner);
            }
            return fDefaultToken;
        }
    }
    scanner.unread();
    return Token.UNDEFINED;
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode)

Aggregations

TableNode (org.talend.sqlbuilder.dbstructure.nodes.TableNode)15 INode (org.talend.sqlbuilder.dbstructure.nodes.INode)11 ArrayList (java.util.ArrayList)7 DataSet (org.talend.sqlbuilder.dataset.dataset.DataSet)7 ResultSet (java.sql.ResultSet)6 ITableInfo (net.sourceforge.squirrel_sql.fw.sql.ITableInfo)5 SessionTreeNode (org.talend.sqlbuilder.sessiontree.model.SessionTreeNode)5 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)4 Point (org.eclipse.swt.graphics.Point)4 TreeSet (java.util.TreeSet)3 Image (org.eclipse.swt.graphics.Image)3 Iterator (java.util.Iterator)2 CompletionProposal (org.eclipse.jface.text.contentassist.CompletionProposal)2 DatabaseNode (org.talend.sqlbuilder.dbstructure.nodes.DatabaseNode)2 Statement (java.sql.Statement)1 List (java.util.List)1 IToken (org.eclipse.jface.text.rules.IToken)1 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)1 ColumnInfoTab (org.talend.sqlbuilder.dbdetail.tab.ColumnInfoTab)1 ConnectionInfoTab (org.talend.sqlbuilder.dbdetail.tab.ConnectionInfoTab)1