Search in sources :

Example 6 with TableNode

use of net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode in project tdq-studio-se by Talend.

the class VersionsTab method getDataSet.

public DataSet getDataSet() throws Exception {
    INode node = getNode();
    if (node == null) {
        return null;
    }
    if (node instanceof TableNode) {
        TableNode tableNode = (TableNode) node;
        ResultSet resultSet = node.getSession().getMetaData().getVersionColumns(tableNode.getTableInfo());
        DataSet dataSet = new DataSet(resultSet, null);
        resultSet.close();
        return dataSet;
    }
    return null;
}
Also used : INode(net.sourceforge.sqlexplorer.dbstructure.nodes.INode) DataSet(net.sourceforge.sqlexplorer.dataset.DataSet) TableNode(net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode) ResultSet(java.sql.ResultSet)

Example 7 with TableNode

use of net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode in project tdq-studio-se by Talend.

the class IndexesTab method getDataSet.

public DataSet getDataSet() throws Exception {
    INode node = getNode();
    if (node == null) {
        return null;
    }
    if (node instanceof TableNode) {
        TableNode tableNode = (TableNode) node;
        List<IndexInfo> indexes = node.getSession().getMetaData().getIndexInfo(tableNode.getTableInfo());
        List<Comparable[]> dataRows = new ArrayList<Comparable[]>();
        int index = 0;
        for (IndexInfo col : indexes) {
            // type)
            if ("STATISTIC".equalsIgnoreCase(col.getIndexType().name())) {
                continue;
            }
            Comparable[] row = new Comparable[COLUMN_LABELS.length];
            dataRows.add(row);
            int i = 0;
            row[i++] = col.isNonUnique();
            row[i++] = col.getIndexQualifier();
            row[i++] = col.getSimpleName();
            row[i++] = col.getIndexType();
            row[i++] = col.getOrdinalPosition();
            row[i++] = col.getColumnName();
            row[i++] = col.getSortOrder();
            row[i++] = col.getCardinality();
            row[i++] = col.getPages();
            row[i++] = col.getFilterCondition();
            if (i != COLUMN_LABELS.length)
                throw new RuntimeException(Messages.getString("ColumnInfoTab.runtimeException"));
        }
        DataSet dataSet = new DataSet(COLUMN_LABELS, dataRows.toArray(new Comparable[dataRows.size()][]));
        return dataSet;
    }
    return null;
}
Also used : INode(net.sourceforge.sqlexplorer.dbstructure.nodes.INode) DataSet(net.sourceforge.sqlexplorer.dataset.DataSet) TableNode(net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode) ArrayList(java.util.ArrayList) IndexInfo(net.sourceforge.squirrel_sql.fw.sql.IndexInfo)

Example 8 with TableNode

use of net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode in project tdq-studio-se by Talend.

the class ColumnPriviligesTab method getDataSet.

public DataSet getDataSet() throws Exception {
    INode node = getNode();
    if (node == null) {
        return null;
    }
    if (node instanceof TableNode) {
        TableNode tableNode = (TableNode) node;
        ResultSet resultSet = node.getSession().getMetaData().getColumnPrivileges(tableNode.getTableInfo());
        DataSet dataSet = new DataSet(resultSet, new int[] { 4, 5, 6, 7, 8 });
        resultSet.close();
        return dataSet;
    }
    return null;
}
Also used : INode(net.sourceforge.sqlexplorer.dbstructure.nodes.INode) DataSet(net.sourceforge.sqlexplorer.dataset.DataSet) TableNode(net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode) ResultSet(java.sql.ResultSet)

Example 9 with TableNode

use of net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode in project tdq-studio-se by Talend.

the class UnsignedWordRule method evaluate.

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) {
                                SQLExplorerPlugin.error("Error getting columns names", 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);
                                    }
                                } else if (colTree != null && j > 0) {
                                }
                            }
                        }
                    }
                }
                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(net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode)

Example 10 with TableNode

use of net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode in project tdq-studio-se by Talend.

the class Dictionary method loadSchemaCatalog.

/**
 * Load dictionary data for catalog
 *
 * @param node catalognode to load
 * @param monitor ProgressMonitor displayed whilst loading
 * @throws InterruptedException If user cancelled loading
 */
private void loadSchemaCatalog(INode iNode, IProgressMonitor monitor) throws InterruptedException {
    if (_logger.isDebugEnabled()) {
        _logger.debug("Loading dictionary: " + iNode.getName());
    }
    // check for cancellation by user
    if (monitor.isCanceled()) {
        throw new InterruptedException(Messages.getString("Progress.Dictionary.Cancelled"));
    }
    putCatalogSchemaName(iNode.toString(), iNode);
    monitor.subTask(iNode.getName());
    INode[] children = iNode.getChildNodes();
    if (children != null) {
        // check for cancellation by user
        if (monitor.isCanceled()) {
            throw new InterruptedException(Messages.getString("Progress.Dictionary.Cancelled"));
        }
        // divide work equally between type nodes
        int typeNodeWorkUnit = ROOT_WORK_UNIT / SUPPORTED_CONTENT_ASSIST_TYPES.length;
        int typeNodeWorkCompleted = 0;
        for (int i = 0; i < children.length; i++) {
            INode typeNode = children[i];
            if (_logger.isDebugEnabled()) {
                _logger.debug("Loading dictionary: " + typeNode.getName());
            }
            // only load a few types like tables and view nodes into the
            // dictionary
            boolean isIncludedInContentAssist = false;
            for (int j = 0; j < SUPPORTED_CONTENT_ASSIST_TYPES.length; j++) {
                if (typeNode.getType().equalsIgnoreCase(SUPPORTED_CONTENT_ASSIST_TYPES[j])) {
                    isIncludedInContentAssist = true;
                }
            }
            if (!isIncludedInContentAssist) {
                continue;
            }
            monitor.subTask(typeNode.getName());
            // check for cancellation by user
            if (monitor.isCanceled()) {
                throw new InterruptedException(Messages.getString("Progress.Dictionary.Cancelled"));
            }
            INode[] tableNodes = typeNode.getChildNodes();
            if (tableNodes != null) {
                // check for cancellation by user
                if (monitor.isCanceled()) {
                    throw new InterruptedException(Messages.getString("Progress.Dictionary.Cancelled"));
                }
                int tableNodeWorkUnit = typeNodeWorkUnit / tableNodes.length;
                for (int j = 0; j < tableNodes.length; j++) {
                    INode tableNode = tableNodes[j];
                    if (_logger.isDebugEnabled()) {
                        _logger.debug("Loading dictionary: " + tableNode.getName());
                    }
                    if (monitor != null) {
                        monitor.worked(tableNodeWorkUnit);
                        typeNodeWorkCompleted = typeNodeWorkCompleted + tableNodeWorkUnit;
                        if (_logger.isDebugEnabled()) {
                            _logger.debug("worked table: " + tableNodeWorkUnit + ", total type work: " + typeNodeWorkCompleted);
                        }
                        monitor.subTask(tableNode.getQualifiedName());
                        // check for cancellation by user
                        if (monitor.isCanceled()) {
                            throw new InterruptedException(Messages.getString("Progress.Dictionary.Cancelled"));
                        }
                    }
                    // add table name
                    ArrayList tableDetails = (ArrayList) getByTableName(tableNode.getName());
                    if (tableDetails == null) {
                        tableDetails = new ArrayList();
                        putTableName(tableNode.getName(), tableDetails);
                    }
                    tableDetails.add(tableNode);
                    // add column names
                    if (tableNode instanceof TableNode) {
                        TreeSet columnNames = new TreeSet();
                        List columns = ((TableNode) tableNode).getColumnNames();
                        if (columns != null) {
                            Iterator it = columns.iterator();
                            while (it.hasNext()) {
                                columnNames.add(it.next());
                            }
                        }
                        putColumnsByTableName(tableNode.getName(), columnNames);
                    }
                }
            }
            if (typeNodeWorkCompleted < typeNodeWorkUnit) {
                if (_logger.isDebugEnabled()) {
                    _logger.debug("consuming remainder: " + (typeNodeWorkUnit - typeNodeWorkCompleted));
                }
                monitor.worked(typeNodeWorkUnit - typeNodeWorkCompleted);
            }
            typeNodeWorkCompleted = 0;
        }
    }
}
Also used : INode(net.sourceforge.sqlexplorer.dbstructure.nodes.INode) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) TableNode(net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

TableNode (net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode)21 INode (net.sourceforge.sqlexplorer.dbstructure.nodes.INode)15 DataSet (net.sourceforge.sqlexplorer.dataset.DataSet)12 ResultSet (java.sql.ResultSet)7 ArrayList (java.util.ArrayList)7 SQLException (java.sql.SQLException)5 Iterator (java.util.Iterator)3 TreeSet (java.util.TreeSet)3 List (java.util.List)2 DatabaseNode (net.sourceforge.sqlexplorer.dbstructure.nodes.DatabaseNode)2 SQLEditor (net.sourceforge.sqlexplorer.plugin.editors.SQLEditor)2 SQLEditorInput (net.sourceforge.sqlexplorer.plugin.editors.SQLEditorInput)2 ITableInfo (net.sourceforge.squirrel_sql.fw.sql.ITableInfo)2 TableColumnInfo (net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo)2 Point (org.eclipse.swt.graphics.Point)2 Statement (java.sql.Statement)1 ExplorerException (net.sourceforge.sqlexplorer.ExplorerException)1 SQLCannotConnectException (net.sourceforge.sqlexplorer.SQLCannotConnectException)1 ColumnInfoTab (net.sourceforge.sqlexplorer.dbdetail.tab.ColumnInfoTab)1 ColumnPriviligesTab (net.sourceforge.sqlexplorer.dbdetail.tab.ColumnPriviligesTab)1