Search in sources :

Example 6 with INode

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

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

the class Dictionary method load.

/**
     * Perform full load of dictionary for dbNode.
     * 
     * @param dbNode DatabaseNode of which to load dictionary information
     * @param monitor ProgressMonitor displayed whilst loading
     * @throws InterruptedException If user cancelled loading
     */
public void load(DatabaseNode dbNode, IProgressMonitor monitor) throws InterruptedException {
    try {
        // check for cancellation by user
        if (monitor.isCanceled()) {
            //$NON-NLS-1$
            throw new InterruptedException(Messages.getString("Progress.Dictionary.Cancelled"));
        }
        INode[] children = dbNode.getChildNodes();
        if (children == null) {
            return;
        }
        // start task with a 1000 work units for every root node
        monitor.beginTask(dbNode.getSession().toString(), children.length * ROOT_WORK_UNIT);
        for (int i = 0; i < children.length; i++) {
            // check for cancellation by user
            if (monitor.isCanceled()) {
                //$NON-NLS-1$
                throw new InterruptedException(Messages.getString("Progress.Dictionary.Cancelled"));
            }
            INode node = (INode) children[i];
            if (node instanceof SchemaNode || node instanceof CatalogNode) {
                loadSchemaCatalog(node, monitor);
            }
        }
        // store dictionary immediately so that
        // we can resuse it if a second session is opened
        store();
    } finally {
        monitor.done();
    }
}
Also used : SchemaNode(org.talend.sqlbuilder.dbstructure.nodes.SchemaNode) INode(org.talend.sqlbuilder.dbstructure.nodes.INode) CatalogNode(org.talend.sqlbuilder.dbstructure.nodes.CatalogNode)

Example 8 with INode

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

the class Dictionary method loadSchemaCatalog.

/**
     * Load dictionary data for catalog.
     * 
     * @param iNode catalognode to load
     * @param monitor ProgressMonitor displayed whilst loading
     * @throws InterruptedException If user cancelled loading
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private void loadSchemaCatalog(INode iNode, IProgressMonitor monitor) throws InterruptedException {
    // check for cancellation by user
    if (monitor.isCanceled()) {
        //$NON-NLS-1$
        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()) {
            //$NON-NLS-1$
            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()) {
                //$NON-NLS-1$
                throw new InterruptedException(Messages.getString("Progress.Dictionary.Cancelled"));
            }
            INode[] tableNodes = typeNode.getChildNodes();
            if (tableNodes != null) {
                // check for cancellation by user
                if (monitor.isCanceled()) {
                    //$NON-NLS-1$
                    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 (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()) {
                            //$NON-NLS-1$
                            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) {
                // consume remainder of work for this type node
                //                    if (logger.isDebugEnabled()) {
                //                        logger.debug("consuming remainder: " + (typeNodeWorkUnit - typeNodeWorkCompleted));
                //                    }
                monitor.worked(typeNodeWorkUnit - typeNodeWorkCompleted);
            }
            typeNodeWorkCompleted = 0;
        }
    }
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with INode

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

the class SQLCompletionProcessor method getProposalsByNode2.

/**
     * DOC dev Comment method "getProposalsByNode2".
     * 
     * @param documentOffset
     * @param lastPart
     * @param node
     * @return
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private ICompletionProposal[] getProposalsByNode2(int documentOffset, String lastPart, INode node) {
    String[] proposalsString = dictionary.matchTablePrefix(lastPart.toLowerCase());
    ArrayList propList = new ArrayList();
    for (int i = 0; i < proposalsString.length; i++) {
        ArrayList ls = dictionary.getTableObjectList(proposalsString[i]);
        for (int j = 0; j < ls.size(); j++) {
            TableNode tbNode = (TableNode) ls.get(j);
            Image tmpImage = null;
            TableFolderNode totn = (TableFolderNode) tbNode.getParent();
            INode catSchema = (INode) totn.getParent();
            if (catSchema == node) {
                if (tbNode.isView()) {
                    tmpImage = viewImage;
                } else if (tbNode.isTable()) {
                    tmpImage = tableImage;
                }
                ICompletionProposal cmp = new ExtendedCompletionProposal(proposalsString[i], documentOffset - lastPart.length(), lastPart.length(), proposalsString[i].length(), tmpImage, proposalsString[i], tbNode);
                propList.add(cmp);
            }
        }
    }
    ICompletionProposal[] res = new ICompletionProposal[propList.size()];
    System.arraycopy(propList.toArray(), 0, res, 0, propList.size());
    return res;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) TableFolderNode(org.talend.sqlbuilder.dbstructure.nodes.TableFolderNode)

Example 10 with INode

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

the class SQLCompletionProcessor method computeCompletionProposals.

/**
     * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer,
     * int)
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
    if (dictionary == null) {
        return null;
    }
    String text = viewer.getDocument().get();
    String string = text.substring(0, documentOffset);
    if (string.equals("")) {
        //$NON-NLS-1$
        return null;
    }
    int position = string.length() - 1;
    char character;
    while (position > 0) {
        character = string.charAt(position);
        if (!Character.isJavaIdentifierPart(character) && (character != '.')) {
            break;
        }
        --position;
    }
    if (position == 0) {
        position = -1;
    }
    string = string.substring(position + 1);
    // JFaceDbcPlugin.error("String: "+string,new Exception());
    if (string == null || string.equals("")) {
        //$NON-NLS-1$
        return null;
    }
    string = string.toLowerCase();
    int length = string.length();
    if (length < 1) {
        return null;
    }
    //$NON-NLS-1$
    int dotIndex = string.lastIndexOf(".");
    if (string.charAt(length - 1) == ' ') {
        return null;
    } else if (string.charAt(length - 1) == '.') {
        // Last typed character
        // is '.'
        String name = string.substring(0, length - 1);
        if (name == null) {
            return null;
        }
        //$NON-NLS-1$
        int otherDot = name.lastIndexOf(".");
        if (otherDot != -1) {
            name = name.substring(otherDot + 1);
        }
        if (name == null || name.equals("")) {
            //$NON-NLS-1$
            return null;
        }
        TreeSet st = (TreeSet) dictionary.getColumnListByTableName(name);
        if (st != null) {
            ArrayList list = (ArrayList) dictionary.getByTableName(name);
            if (list == null) {
                return null;
            }
            TableNode nd = null;
            if (list.size() == 1) {
                nd = (TableNode) list.get(0);
            } else {
                return null;
            }
            Object[] obj = st.toArray();
            String[] arr = new String[obj.length];
            System.arraycopy(obj, 0, arr, 0, obj.length);
            ICompletionProposal[] result = new ICompletionProposal[arr.length];
            String tableDesc = null;
            if (nd != null) {
                tableDesc = nd.getTableDesc();
            }
            for (int i = 0; i < arr.length; i++) {
                result[i] = new CompletionProposal(arr[i], documentOffset, 0, arr[i].length(), colImage, arr[i], null, tableDesc);
            }
            return result;
        }
        INode node = (INode) dictionary.getByCatalogSchemaName(name);
        if (node != null) {
            return getProposalsByNode(documentOffset, node);
        }
    } else if (dotIndex == -1) {
        return inputNotContainDot(documentOffset, string, length);
    } else if (dotIndex != -1) {
        String firstPart = string.substring(0, dotIndex);
        //$NON-NLS-1$
        int otherDot = firstPart.indexOf(".");
        if (otherDot != -1) {
            firstPart = firstPart.substring(otherDot + 1);
        }
        String lastPart = string.substring(dotIndex + 1);
        if (//$NON-NLS-1$
        lastPart == null || firstPart == null || lastPart.equals("") || firstPart.equals("")) {
            //$NON-NLS-1$
            return null;
        }
        TreeSet st = (TreeSet) dictionary.getColumnListByTableName(firstPart);
        if (st != null) {
            Iterator iter = st.iterator();
            ArrayList propList = new ArrayList();
            while (iter.hasNext()) {
                String colName = (String) iter.next();
                int length2 = lastPart.length();
                if (colName.length() >= length2) {
                    if ((colName.substring(0, lastPart.length())).equalsIgnoreCase(lastPart)) {
                        CompletionProposal cmp = new CompletionProposal(colName, documentOffset - length2, length2, colName.length(), colImage, colName, null, null);
                        propList.add(cmp);
                    }
                }
            }
            ICompletionProposal[] res = new ICompletionProposal[propList.size()];
            System.arraycopy(propList.toArray(), 0, res, 0, propList.size());
            return res;
        }
        INode node = (INode) dictionary.getByCatalogSchemaName(firstPart);
        if (node != null) {
            return getProposalsByNode2(documentOffset, lastPart, node);
        }
    }
    return null;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) Iterator(java.util.Iterator) Point(org.eclipse.swt.graphics.Point)

Aggregations

INode (org.talend.sqlbuilder.dbstructure.nodes.INode)16 TableNode (org.talend.sqlbuilder.dbstructure.nodes.TableNode)11 DataSet (org.talend.sqlbuilder.dataset.dataset.DataSet)8 ResultSet (java.sql.ResultSet)6 ArrayList (java.util.ArrayList)5 ITableInfo (net.sourceforge.squirrel_sql.fw.sql.ITableInfo)5 SessionTreeNode (org.talend.sqlbuilder.sessiontree.model.SessionTreeNode)5 Iterator (java.util.Iterator)4 List (java.util.List)2 TreeSet (java.util.TreeSet)2 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 Point (org.eclipse.swt.graphics.Point)2 CatalogNode (org.talend.sqlbuilder.dbstructure.nodes.CatalogNode)2 DatabaseNode (org.talend.sqlbuilder.dbstructure.nodes.DatabaseNode)2 DatabaseMetaData (java.sql.DatabaseMetaData)1 Statement (java.sql.Statement)1 SQLDatabaseMetaData (net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1 ListenerList (org.eclipse.core.runtime.ListenerList)1 IAction (org.eclipse.jface.action.IAction)1