Search in sources :

Example 6 with DataSet

use of net.sourceforge.sqlexplorer.dataset.DataSet 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 7 with DataSet

use of net.sourceforge.sqlexplorer.dataset.DataSet 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)

Example 8 with DataSet

use of net.sourceforge.sqlexplorer.dataset.DataSet 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 9 with DataSet

use of net.sourceforge.sqlexplorer.dataset.DataSet 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 10 with DataSet

use of net.sourceforge.sqlexplorer.dataset.DataSet in project tdq-studio-se by Talend.

the class AbstractSQLTab method getDataSet.

public final DataSet getDataSet() throws Exception {
    DataSet dataSet = null;
    int timeOut = SQLExplorerPlugin.getDefault().getPluginPreferences().getInt(IConstants.INTERACTIVE_QUERY_TIMEOUT);
    SQLConnection connection = null;
    ResultSet rs = null;
    Statement stmt = null;
    PreparedStatement pStmt = null;
    try {
        connection = getNode().getSession().grabConnection();
        Object[] params = getSQLParameters();
        if (params == null || params.length == 0) {
            // use normal statement
            stmt = connection.createStatement();
            stmt.setQueryTimeout(timeOut);
            rs = stmt.executeQuery(getSQL());
        } else {
            // use prepared statement
            pStmt = connection.prepareStatement(getSQL());
            pStmt.setQueryTimeout(timeOut);
            for (int i = 0; i < params.length; i++) {
                if (params[i] instanceof String) {
                    pStmt.setString(i + 1, (String) params[i]);
                } else if (params[i] instanceof Integer) {
                    pStmt.setInt(i + 1, ((Integer) params[i]).intValue());
                } else if (params[i] instanceof String) {
                    pStmt.setLong(i + 1, ((Long) params[i]).longValue());
                }
            }
            rs = pStmt.executeQuery();
        }
        dataSet = new DataSet(rs, null);
        rs.close();
        rs = null;
    } catch (Exception e) {
        SQLExplorerPlugin.error(Messages.getString("AbstractSQLSourceTab.cannotLoadSource") + getNode().getName(), e);
    } finally {
        if (rs != null)
            try {
                rs.close();
            } catch (SQLException e) {
                SQLExplorerPlugin.error(Messages.getString("DataSet.errorCloseRs"), e);
            }
        if (stmt != null)
            try {
                stmt.close();
            } catch (SQLException e) {
                SQLExplorerPlugin.error(Messages.getString("DataSet.errorCloseStmt"), e);
            }
        if (pStmt != null)
            try {
                pStmt.close();
            } catch (SQLException e) {
                SQLExplorerPlugin.error(Messages.getString("DataSet.errorCloseStmt"), e);
            }
        if (connection != null)
            getNode().getSession().releaseConnection(connection);
    }
    return dataSet;
}
Also used : DataSet(net.sourceforge.sqlexplorer.dataset.DataSet) SQLException(java.sql.SQLException) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) SQLConnection(net.sourceforge.sqlexplorer.dbproduct.SQLConnection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Aggregations

DataSet (net.sourceforge.sqlexplorer.dataset.DataSet)24 INode (net.sourceforge.sqlexplorer.dbstructure.nodes.INode)12 TableNode (net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode)12 ResultSet (java.sql.ResultSet)8 File (java.io.File)7 SQLException (java.sql.SQLException)6 SQLConnection (net.sourceforge.sqlexplorer.dbproduct.SQLConnection)4 BufferedWriter (java.io.BufferedWriter)3 FileWriter (java.io.FileWriter)3 PrintStream (java.io.PrintStream)3 DataSetRow (net.sourceforge.sqlexplorer.dataset.DataSetRow)3 FileDialog (org.eclipse.swt.widgets.FileDialog)3 Statement (java.sql.Statement)2 DatabaseProduct (net.sourceforge.sqlexplorer.dbproduct.DatabaseProduct)2 Query (net.sourceforge.sqlexplorer.parsers.Query)2 Message (net.sourceforge.sqlexplorer.plugin.editors.Message)2 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 CallableStatement (java.sql.CallableStatement)1 DatabaseMetaData (java.sql.DatabaseMetaData)1