Search in sources :

Example 1 with TableNode

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

the class GenerateSelectSQLAction method run.

/**
 * Generate select statement
 *
 * @see org.eclipse.jface.action.IAction#run()
 */
@Override
public void run() {
    try {
        String query = null;
        if (_selectedNodes[0] instanceof ColumnNode) {
            query = createColumnSelect();
        }
        if (_selectedNodes[0] instanceof TableNode) {
            query = createTableSelect();
        }
        if (query == null) {
            return;
        }
        SQLEditorInput input = new SQLEditorInput(// $NON-NLS-1$
        "SQL Editor (" + SQLExplorerPlugin.getDefault().getEditorSerialNo() + // $NON-NLS-1$
        ").sql");
        input.setUser(_selectedNodes[0].getSession().getUser());
        IWorkbenchPage page = SQLExplorerPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
        SQLEditor editorPart = (SQLEditor) page.openEditor(input, SQLEditor.class.getName());
        editorPart.setText(query);
    } catch (Throwable e) {
        SQLExplorerPlugin.error("Could generate sql.", e);
    }
}
Also used : SQLEditorInput(net.sourceforge.sqlexplorer.plugin.editors.SQLEditorInput) SQLEditor(net.sourceforge.sqlexplorer.plugin.editors.SQLEditor) ColumnNode(net.sourceforge.sqlexplorer.dbstructure.nodes.ColumnNode) TableNode(net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 2 with TableNode

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

the class DetailTabManager method createTabs.

/**
 * Returns a list of all available tabs for a given node. These tabs can be
 * standard or plugin tabs.
 *
 * @param node for which to find tabs.
 * @return List of tabs
 */
private static List<IDetailTab> createTabs(INode node) {
    if (_logger.isDebugEnabled()) {
        // $NON-NLS-1$
        _logger.debug("Creating tabs for: " + node.getUniqueIdentifier());
    }
    ArrayList<IDetailTab> tabList = new ArrayList<IDetailTab>();
    // create connection info tab if needed
    if (node instanceof DatabaseNode) {
        IDetailTab dbTab = new ConnectionInfoTab();
        dbTab.setNode(node);
        tabList.add(dbTab);
    }
    // create our basic table tabs
    if (node instanceof TableNode) {
        IDetailTab tab1 = new ColumnInfoTab();
        IDetailTab tab2 = new TableInfoTab();
        IDetailTab tab3 = new PreviewTab();
        IDetailTab tab4 = new RowCountTab();
        IDetailTab tab5 = new PrimaryKeysTab();
        IDetailTab tab6 = new ExportedKeysTab();
        IDetailTab tab7 = new ImportedKeysTab();
        IDetailTab tab8 = new IndexesTab();
        IDetailTab tab9 = new PriviligesTab();
        IDetailTab tab10 = new ColumnPriviligesTab();
        IDetailTab tab11 = new RowIdsTab();
        IDetailTab tab12 = new VersionsTab();
        tab1.setNode(node);
        tab2.setNode(node);
        tab3.setNode(node);
        tab4.setNode(node);
        tab5.setNode(node);
        tab6.setNode(node);
        tab7.setNode(node);
        tab8.setNode(node);
        tab9.setNode(node);
        tab10.setNode(node);
        tab11.setNode(node);
        tab12.setNode(node);
        tabList.add(tab1);
        tabList.add(tab2);
        tabList.add(tab3);
        tabList.add(tab4);
        tabList.add(tab5);
        tabList.add(tab6);
        tabList.add(tab7);
        tabList.add(tab8);
        tabList.add(tab9);
        tabList.add(tab10);
        tabList.add(tab11);
        tabList.add(tab12);
    }
    // create extension point tabs
    String databaseProductName = node.getSession().getRoot().getDatabaseProductName().toLowerCase().trim();
    String nodeType = node.getType().toLowerCase().trim();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    // $NON-NLS-1$ $NON-NLS-2$
    IExtensionPoint point = registry.getExtensionPoint("net.sourceforge.sqlexplorer", "nodeDetailTab");
    IExtension[] extensions = point.getExtensions();
    for (int i = 0; i < extensions.length; i++) {
        IExtension e = extensions[i];
        IConfigurationElement[] ces = e.getConfigurationElements();
        for (int j = 0; j < ces.length; j++) {
            try {
                boolean isValidProduct = false;
                boolean isValidNodeType = false;
                // $NON-NLS-1$ $NON-NLS-2$
                String[] validProducts = ces[j].getAttribute("database-product-name").split(",");
                // $NON-NLS-1$ $NON-NLS-2$
                String[] validNodeTypes = ces[j].getAttribute("node-type").split(",");
                // check if tab is valid for current database product
                for (int k = 0; k < validProducts.length; k++) {
                    String product = validProducts[k].toLowerCase().trim();
                    if (product.length() == 0) {
                        continue;
                    }
                    if (product.equals("*")) {
                        // $NON-NLS-1$
                        isValidProduct = true;
                        break;
                    }
                    // $NON-NLS-1$ $NON-NLS-2$
                    String regex = TextUtil.replaceChar(product, '*', ".*");
                    if (databaseProductName.matches(regex)) {
                        isValidProduct = true;
                        break;
                    }
                }
                if (!isValidProduct) {
                    continue;
                }
                // check if tab is valid for current node type
                for (int k = 0; k < validNodeTypes.length; k++) {
                    String type = validNodeTypes[k].toLowerCase().trim();
                    if (type.length() == 0) {
                        continue;
                    }
                    if (type.equals("*")) {
                        // $NON-NLS-1$
                        isValidNodeType = true;
                        break;
                    }
                    // $NON-NLS-1$ $NON-NLS-2$
                    String regex = TextUtil.replaceChar(type, '*', ".*");
                    if (nodeType.matches(regex)) {
                        isValidNodeType = true;
                        break;
                    }
                }
                if (!isValidNodeType) {
                    continue;
                }
                // add tab to list
                // $NON-NLS-1$
                IDetailTab tab = (IDetailTab) ces[j].createExecutableExtension("class");
                tab.setNode(node);
                tabList.add(tab);
            } catch (Throwable ex) {
                SQLExplorerPlugin.error(Messages.getString("DataSetTableActionGroup.cannotCreateMenuAction"), ex);
            }
        }
    }
    return tabList;
}
Also used : ArrayList(java.util.ArrayList) TableInfoTab(net.sourceforge.sqlexplorer.dbdetail.tab.TableInfoTab) RowIdsTab(net.sourceforge.sqlexplorer.dbdetail.tab.RowIdsTab) ColumnPriviligesTab(net.sourceforge.sqlexplorer.dbdetail.tab.ColumnPriviligesTab) PriviligesTab(net.sourceforge.sqlexplorer.dbdetail.tab.PriviligesTab) VersionsTab(net.sourceforge.sqlexplorer.dbdetail.tab.VersionsTab) DatabaseNode(net.sourceforge.sqlexplorer.dbstructure.nodes.DatabaseNode) IExtension(org.eclipse.core.runtime.IExtension) PreviewTab(net.sourceforge.sqlexplorer.dbdetail.tab.PreviewTab) ColumnInfoTab(net.sourceforge.sqlexplorer.dbdetail.tab.ColumnInfoTab) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) ColumnPriviligesTab(net.sourceforge.sqlexplorer.dbdetail.tab.ColumnPriviligesTab) ImportedKeysTab(net.sourceforge.sqlexplorer.dbdetail.tab.ImportedKeysTab) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) ConnectionInfoTab(net.sourceforge.sqlexplorer.dbdetail.tab.ConnectionInfoTab) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) PrimaryKeysTab(net.sourceforge.sqlexplorer.dbdetail.tab.PrimaryKeysTab) RowCountTab(net.sourceforge.sqlexplorer.dbdetail.tab.RowCountTab) TableNode(net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode) IndexesTab(net.sourceforge.sqlexplorer.dbdetail.tab.IndexesTab) ExportedKeysTab(net.sourceforge.sqlexplorer.dbdetail.tab.ExportedKeysTab)

Example 3 with TableNode

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

the class TableInfoTab method getDataSet.

public DataSet getDataSet() throws Exception {
    INode node = getNode();
    if (node == null) {
        return null;
    }
    if (node instanceof TableNode) {
        TableNode tableNode = (TableNode) node;
        ITableInfo tableInfo = tableNode.getTableInfo();
        String[] header = new String[2];
        header[0] = Messages.getString("DatabaseDetailView.Tab.Info.Property");
        header[1] = Messages.getString("DatabaseDetailView.Tab.Info.Value");
        String[][] data = new String[6][2];
        data[0][0] = Messages.getString("DatabaseDetailView.Tab.Info.Name");
        data[0][1] = tableInfo.getSimpleName();
        data[1][0] = Messages.getString("DatabaseDetailView.Tab.Info.QualifiedName");
        data[1][1] = tableInfo.getQualifiedName();
        data[2][0] = Messages.getString("DatabaseDetailView.Tab.Info.Catalog");
        data[2][1] = tableInfo.getCatalogName();
        data[3][0] = Messages.getString("DatabaseDetailView.Tab.Info.Schema");
        data[3][1] = tableInfo.getSchemaName();
        data[4][0] = Messages.getString("DatabaseDetailView.Tab.Info.Type");
        data[4][1] = tableInfo.getType();
        data[5][0] = Messages.getString("DatabaseDetailView.Tab.Info.Remarks");
        data[5][1] = tableInfo.getRemarks();
        DataSet dataSet = new DataSet(header, data);
        return dataSet;
    }
    return null;
}
Also used : INode(net.sourceforge.sqlexplorer.dbstructure.nodes.INode) ITableInfo(net.sourceforge.squirrel_sql.fw.sql.ITableInfo) DataSet(net.sourceforge.sqlexplorer.dataset.DataSet) TableNode(net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode)

Example 4 with TableNode

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

the class PriviligesTab 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().getTablePrivileges(tableNode.getTableInfo());
        DataSet dataSet = new DataSet(resultSet, new int[] { 3, 4, 5, 6, 7 });
        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 5 with TableNode

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

the class RowIdsTab method getDataSet.

public DataSet getDataSet() throws Exception {
    INode node = getNode();
    if (node == null) {
        return null;
    }
    if (node instanceof TableNode) {
        TableNode tableNode = (TableNode) node;
        BestRowIdentifier[] rowIds = node.getSession().getMetaData().getBestRowIdentifier(tableNode.getTableInfo());
        Comparable[][] data = new Comparable[rowIds.length][];
        int index = 0;
        for (BestRowIdentifier rowId : rowIds) {
            Comparable[] row = new Comparable[COLUMN_LABELS.length];
            data[index++] = row;
            int i = 0;
            row[i++] = rowId.getScope();
            row[i++] = rowId.getColumnName();
            row[i++] = rowId.getSQLDataType();
            row[i++] = rowId.getTypeName();
            row[i++] = rowId.getPrecision();
            row[i++] = rowId.getScale();
            row[i++] = rowId.getPseudoColumn();
            if (i != COLUMN_LABELS.length)
                throw new RuntimeException(Messages.getString("RowIdsTab.RuntimeException"));
        }
        DataSet dataSet = new DataSet(COLUMN_LABELS, data);
        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) BestRowIdentifier(net.sourceforge.squirrel_sql.fw.sql.dbobj.BestRowIdentifier)

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