Search in sources :

Example 16 with INode

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

the class ExportedKeysTab 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().getExportedKeys(tableNode.getTableInfo());
        DataSet dataSet = new DataSet(resultSet, new int[] { 4, 7, 8, 9, 10, 11, 12, 13, 14 });
        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 17 with INode

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

the class ColumnInfoTab method getDataSet.

@Override
public DataSet getDataSet() {
    INode node = getNode();
    if (node == null) {
        return null;
    }
    if (node instanceof TableNode) {
        TableNode tableNode = (TableNode) node;
        DataSet dataSet = null;
        // something(.e.g,ResultSetColumnReader.getLong(16))
        try {
            TableColumnInfo[] cols = node.getSession().getMetaData().getColumnInfo(tableNode.getTableInfo());
            Comparable[][] dataRows = new Comparable[cols.length][];
            int index = 0;
            for (TableColumnInfo col : cols) {
                Comparable[] row = new Comparable[COLUMN_LABELS.length];
                dataRows[index++] = row;
                int i = 0;
                row[i++] = col.getColumnName();
                row[i++] = col.getDataType();
                row[i++] = col.getTypeName();
                row[i++] = col.getColumnSize();
                row[i++] = col.getDecimalDigits();
                row[i++] = col.getRadix();
                row[i++] = col.isNullAllowed();
                row[i++] = col.getRemarks();
                row[i++] = col.getDefaultValue();
                row[i++] = col.getOctetLength();
                row[i++] = col.getOrdinalPosition();
                row[i++] = col.isNullable();
                if (i != COLUMN_LABELS.length) {
                    throw new RuntimeException(Messages.getString("ColumnInfoTab.runtimeException"));
                }
            }
            dataSet = new DataSet(COLUMN_LABELS, dataRows);
        } catch (Exception e) {
            SQLExplorerPlugin.error(Messages.getString("AbstractDataSetTab.error"), e);
            boolean isODBCTeradata = false;
            try {
                isODBCTeradata = ConnectionUtils.isOdbcTeradata(node.getSession().getMetaData().getJDBCMetaData()) ? true : false;
            } catch (SQLException e1) {
                SQLExplorerPlugin.error("Failed to get the type of Database", e);
            }
            if (isODBCTeradata) {
                MessageDialog.openError(Display.getDefault().getActiveShell(), "unsupported", "This operation is unsupported by ODBC Teradata in SQLExplorer!");
            }
        }
        return dataSet;
    }
    return null;
}
Also used : INode(net.sourceforge.sqlexplorer.dbstructure.nodes.INode) DataSet(net.sourceforge.sqlexplorer.dataset.DataSet) SQLException(java.sql.SQLException) TableNode(net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode) TableColumnInfo(net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo) SQLException(java.sql.SQLException)

Example 18 with INode

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

the class SqlexplorerService method findSqlExplorerTableNode.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.dataprofiler.service.ISqlexplorerService#findSqlExplorerTableNode(org.talend.core.model.metadata.builder
     * .connection.Connection, orgomg.cwm.objectmodel.core.Package, java.lang.String, java.lang.String)
     */
@Override
public void findSqlExplorerTableNode(Connection providerConnection, Package parentPackageElement, String tableName, String activeTabName) {
    // Open data explore perspective.
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQRepositoryService.class)) {
        ITDQRepositoryService service = (ITDQRepositoryService) GlobalServiceRegister.getDefault().getService(ITDQRepositoryService.class);
        if (service != null) {
            service.changePerspectiveAction(SQLExplorerPluginPerspective.class.getName());
        } else {
            return;
        }
    }
    Collection<Alias> aliases = SQLExplorerPlugin.getDefault().getAliasManager().getAliases();
    String url = JavaSqlFactory.getURL(providerConnection);
    User currentUser = null;
    for (Alias alias : aliases) {
        if (alias.getUrl().equals(url)) {
            currentUser = alias.getDefaultUser();
            OpenPasswordConnectDialogAction openDlgAction = new OpenPasswordConnectDialogAction(alias, alias.getDefaultUser(), false);
            openDlgAction.run();
            break;
        }
    }
    // MOD qiongli bug 13093,2010-7-2,show the warning dialog when the table can't be found
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    if (currentUser == null) {
        // $NON-NLS-1$
        MessageDialog.openWarning(// $NON-NLS-1$
        shell, // $NON-NLS-1$
        Messages.getString("SqlExplorerBridge.Warning"), // $NON-NLS-1$
        Messages.getString("SqlExplorerBridge.MissTable") + tableName);
        return;
    }
    DatabaseNode root = currentUser.getMetaDataSession().getRoot();
    root.load();
    List<INode> catalogs = root.getCatalogs();
    List<INode> schemas = root.getSchemas();
    Catalog catalog = SwitchHelpers.CATALOG_SWITCH.doSwitch(parentPackageElement);
    Schema schema = SwitchHelpers.SCHEMA_SWITCH.doSwitch(parentPackageElement);
    INode catalogOrSchemaNode = null;
    // TDQ-12005: fix Exasol/hive(TDQ-11887: hdp20 at least) database can view index/keys well
    String findCatalogNodeName = isExasol(url) ? "EXA_DB" : (isHive(url) ? "NoCatalog" : "");
    if (!findCatalogNodeName.equals("") && !catalogs.isEmpty()) {
        for (INode catalogNode : catalogs) {
            if (findCatalogNodeName.equalsIgnoreCase(catalogNode.getName())) {
                catalogOrSchemaNode = catalogNode;
                break;
            }
        }
    } else {
        if (catalog != null) {
            // MOD klliu bug 14662 2010-08-05
            if (!catalogs.isEmpty()) {
                for (INode catalogNode : catalogs) {
                    if (parentPackageElement.getName().equalsIgnoreCase(catalogNode.getName())) {
                        catalogOrSchemaNode = catalogNode;
                        break;
                    }
                }
            } else {
                catalogOrSchemaNode = root;
            }
        } else {
            // MOD by zshen for 20517
            if (schemas.isEmpty()) {
                // the case for mssql/postgrel(which have catalog and schema structor) schema analysis.
                Catalog shcmeaOfCatalogNode = CatalogHelper.getParentCatalog(parentPackageElement);
                for (INode catalogNode : catalogs) {
                    if (shcmeaOfCatalogNode != null && shcmeaOfCatalogNode.getName().equalsIgnoreCase(catalogNode.getName())) {
                        catalogOrSchemaNode = catalogNode;
                        break;
                    }
                }
            }
            for (INode schemaNode : schemas) {
                if (parentPackageElement.getName().equalsIgnoreCase(schemaNode.getName())) {
                    catalogOrSchemaNode = schemaNode;
                    break;
                }
            }
        }
    }
    // find the table folder node.
    if (catalogOrSchemaNode == null) {
        // $NON-NLS-1$
        throw new NullPointerException(Messages.getString("SqlExplorerBridge.CATORSCHMISNULL"));
    }
    // catalog node.
    if (schema != null) {
        if (catalogOrSchemaNode.getSchemaName() == null) {
            catalogOrSchemaNode.setSchemaName(schema.getName());
        } else if (!StringUtils.equals(catalogOrSchemaNode.getSchemaName(), schema.getName())) {
            // if this catalog already loaded its children of some schema, should reload for this schema.
            if (catalogOrSchemaNode.isChildrenLoaded()) {
                SQLExplorerPlugin.getDefault().getDatabaseStructureView().refreshSessionTrees(currentUser.getMetaDataSession());
                List<INode> catalogs2 = currentUser.getMetaDataSession().getRoot().getCatalogs();
                if (catalogs2.size() != 0) {
                    for (INode catalogNode : catalogs2) {
                        if (catalogOrSchemaNode.getName().equalsIgnoreCase(catalogNode.getName())) {
                            catalogOrSchemaNode = catalogNode;
                            catalogOrSchemaNode.setSchemaName(schema.getName());
                            break;
                        }
                    }
                }
            }
        }
    }
    // ~
    INode[] childNodes = catalogOrSchemaNode.getChildNodes();
    // need to find the schema and load the table nodes
    if (isNetezza(url)) {
        SchemaNode sNode = getNetezzaSchema(childNodes, JavaSqlFactory.getUsername(providerConnection));
        if (sNode != null) {
            childNodes = sNode.getChildNodes();
        }
    }
    TableFolderNode tableFolderNode = null;
    for (INode node : childNodes) {
        if ("TABLE".equals(node.getQualifiedName())) {
            // $NON-NLS-1$
            tableFolderNode = (TableFolderNode) node;
            break;
        }
    }
    if (tableFolderNode == null) {
        // $NON-NLS-1$
        log.fatal(Messages.getString("SqlExplorerBridge.TABLE_FOLDER_NULL0"));
    } else {
        INode[] tableNodes = tableFolderNode.getChildNodes();
        for (INode node : tableNodes) {
            if (tableName.equalsIgnoreCase(node.getName())) {
                DetailTabManager.setActiveTabName(activeTabName);
                DatabaseStructureView dsView = SQLExplorerPlugin.getDefault().getDatabaseStructureView();
                dsView.setSessionSelectionNode(currentUser.getMetaDataSession(), new StructuredSelection(node));
                // MOD qiongli bug 13093,2010-7-2
                SQLExplorerPlugin.getDefault().getConnectionsView().getTreeViewer().setSelection(new StructuredSelection(currentUser));
                return;
            }
        }
    }
    // $NON-NLS-1$
    MessageDialog.openWarning(// $NON-NLS-1$
    shell, // $NON-NLS-1$
    Messages.getString("SqlExplorerBridge.Warning"), // $NON-NLS-1$
    Messages.getString("SqlExplorerBridge.MissTable") + tableName);
}
Also used : INode(net.sourceforge.sqlexplorer.dbstructure.nodes.INode) User(net.sourceforge.sqlexplorer.dbproduct.User) ITDQRepositoryService(org.talend.core.ITDQRepositoryService) Schema(orgomg.cwm.resource.relational.Schema) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) OpenPasswordConnectDialogAction(net.sourceforge.sqlexplorer.plugin.actions.OpenPasswordConnectDialogAction) Catalog(orgomg.cwm.resource.relational.Catalog) TableFolderNode(net.sourceforge.sqlexplorer.dbstructure.nodes.TableFolderNode) SchemaNode(net.sourceforge.sqlexplorer.dbstructure.nodes.SchemaNode) Shell(org.eclipse.swt.widgets.Shell) DatabaseNode(net.sourceforge.sqlexplorer.dbstructure.nodes.DatabaseNode) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) SQLExplorerPluginPerspective(net.sourceforge.sqlexplorer.plugin.perspectives.SQLExplorerPluginPerspective) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) DatabaseStructureView(net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView)

Example 19 with INode

use of net.sourceforge.sqlexplorer.dbstructure.nodes.INode in project tdq-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()) {
            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()) {
                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(net.sourceforge.sqlexplorer.dbstructure.nodes.SchemaNode) INode(net.sourceforge.sqlexplorer.dbstructure.nodes.INode) CatalogNode(net.sourceforge.sqlexplorer.dbstructure.nodes.CatalogNode)

Example 20 with INode

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

the class SQLCompletionProcessor method computeCompletionProposals.

/**
 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer,
 *      int)
 */
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
    if (dictionary == null)
        return null;
    String text = viewer.getDocument().get();
    String string = text.substring(0, documentOffset);
    if (// $NON-NLS-1$
    string.equals(""))
        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(""))
        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;
        int otherDot = name.lastIndexOf(".");
        if (otherDot != -1)
            name = name.substring(otherDot + 1);
        if (name == null || name.equals(""))
            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) {
            Object[] children = (Object[]) node.getChildNodes();
            ArrayList propList = new ArrayList();
            if (children != null) {
                for (int i = 0; i < children.length; i++) {
                    String childName = children[i].toString().toLowerCase();
                    if (childName.equals("table") || childName.equals("view")) {
                        Object[] tables = (Object[]) ((INode) children[i]).getChildNodes();
                        if (tables != null) {
                            for (int j = 0; j < tables.length; j++) {
                                Image tmpImage = null;
                                String tableName = tables[j].toString();
                                if (tables[j] instanceof TableNode) {
                                    if (((TableNode) tables[j]).isTable())
                                        tmpImage = tableImage;
                                    else if (((TableNode) tables[j]).isView())
                                        tmpImage = viewImage;
                                    propList.add(new ExtendedCompletionProposal(tableName, documentOffset, 0, tableName.length(), tmpImage, tableName, (TableNode) tables[j]));
                                }
                            }
                        }
                    }
                }
            }
            ICompletionProposal[] res = new ICompletionProposal[propList.size()];
            System.arraycopy(propList.toArray(), 0, res, 0, propList.size());
            Arrays.sort(res, new ICompletionProposalComparator());
            return res;
        }
    } else if (// The string does not contain "."
    dotIndex == -1) {
        String[] keywordProposal = Dictionary.matchKeywordsPrefix(string);
        ICompletionProposal[] resKey = new ICompletionProposal[keywordProposal.length];
        for (int i = 0; i < keywordProposal.length; i++) {
            resKey[i] = new CompletionProposal(keywordProposal[i], documentOffset - length, length, keywordProposal[i].length(), keywordImage, keywordProposal[i], null, null);
        }
        String[] proposalsString = dictionary.matchTablePrefix(string.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;
                if (tbNode.isView())
                    tmpImage = viewImage;
                else if (tbNode.isTable())
                    tmpImage = tableImage;
                ICompletionProposal cmp = new ExtendedCompletionProposal(proposalsString[i], documentOffset - length, length, proposalsString[i].length(), tmpImage, proposalsString[i], tbNode);
                propList.add(cmp);
            }
        }
        String[] proposalsString2 = dictionary.matchCatalogSchemaPrefix(string.toLowerCase());
        ICompletionProposal[] resKey2 = new ICompletionProposal[proposalsString2.length];
        for (int i = 0; i < proposalsString2.length; i++) {
            resKey2[i] = new CompletionProposal(proposalsString2[i], documentOffset - length, length, proposalsString2[i].length(), catalogImage, proposalsString2[i], null, null);
        }
        ICompletionProposal[] res = new ICompletionProposal[propList.size() + keywordProposal.length + resKey2.length];
        System.arraycopy(resKey, 0, res, 0, resKey.length);
        System.arraycopy(propList.toArray(), 0, res, resKey.length, propList.size());
        System.arraycopy(resKey2, 0, res, resKey.length + propList.size(), resKey2.length);
        Arrays.sort(res, new ICompletionProposalComparator());
        return res;
    } else if (dotIndex != -1) {
        String firstPart = string.substring(0, dotIndex);
        int otherDot = firstPart.indexOf(".");
        if (otherDot != -1)
            firstPart = firstPart.substring(otherDot + 1);
        String lastPart = string.substring(dotIndex + 1);
        if (lastPart == null || firstPart == null || lastPart.equals("") || firstPart.equals(""))
            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) {
            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;
        }
    }
    return null;
}
Also used : INode(net.sourceforge.sqlexplorer.dbstructure.nodes.INode) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) TableFolderNode(net.sourceforge.sqlexplorer.dbstructure.nodes.TableFolderNode) TreeSet(java.util.TreeSet) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) TableNode(net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode) Iterator(java.util.Iterator)

Aggregations

INode (net.sourceforge.sqlexplorer.dbstructure.nodes.INode)22 TableNode (net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode)15 DataSet (net.sourceforge.sqlexplorer.dataset.DataSet)12 ResultSet (java.sql.ResultSet)7 ArrayList (java.util.ArrayList)6 SQLException (java.sql.SQLException)4 Iterator (java.util.Iterator)3 List (java.util.List)2 TreeSet (java.util.TreeSet)2 SQLConnection (net.sourceforge.sqlexplorer.dbproduct.SQLConnection)2 DatabaseNode (net.sourceforge.sqlexplorer.dbstructure.nodes.DatabaseNode)2 SchemaNode (net.sourceforge.sqlexplorer.dbstructure.nodes.SchemaNode)2 TableFolderNode (net.sourceforge.sqlexplorer.dbstructure.nodes.TableFolderNode)2 Point (org.eclipse.swt.graphics.Point)2 DatabaseMetaData (java.sql.DatabaseMetaData)1 Statement (java.sql.Statement)1 LinkedList (java.util.LinkedList)1 SQLCannotConnectException (net.sourceforge.sqlexplorer.SQLCannotConnectException)1 Alias (net.sourceforge.sqlexplorer.dbproduct.Alias)1 User (net.sourceforge.sqlexplorer.dbproduct.User)1