Search in sources :

Example 6 with DataSet

use of org.talend.sqlbuilder.dataset.dataset.DataSet in project tdi-studio-se by Talend.

the class SQLExecution method doExecution.

protected void doExecution() throws Exception {
    final long startTime = System.currentTimeMillis();
    try {
        stmt = connection.createStatement();
        //$NON-NLS-1$
        setProgressMessage(Messages.getString("SQLResultsView.Executing"));
        stmt.setMaxRows(maxRows);
        if (isCancelled) {
            return;
        }
        boolean b = stmt.execute(sqlStatement);
        if (isCancelled) {
            closeStatement();
            return;
        }
        if (b) {
            final ResultSet rs = stmt.getResultSet();
            if (rs != null) {
                if (isCancelled) {
                    closeStatement();
                    return;
                }
                // create new dataset from results
                DataSet dataSet = new DataSet(null, rs, null);
                final long endTime = System.currentTimeMillis();
                // update sql result
                sqlResult.setDataSet(dataSet);
                sqlResult.setExecutionTimeMillis(endTime - startTime);
                closeStatement();
                if (isCancelled) {
                    return;
                }
                // show results..
                displayResults();
                // update text on editor
                composite.getDisplay().asyncExec(new Runnable() {

                    public void run() {
                    }
                });
            }
        } else {
            // update text on editor
            composite.getDisplay().asyncExec(new Runnable() {

                public void run() {
                    // close tab
                    parentTab.dispose();
                }
            });
            closeStatement();
            if (isCancelled) {
                return;
            }
        }
        stmt = null;
    } catch (Exception e) {
        closeStatement();
        throw e;
    } finally {
        // bug 17980
        DriverShim wapperDriver = session.getWapperDriver();
        if (wapperDriver != null) {
            try {
                //$NON-NLS-1$
                wapperDriver.connect("jdbc:derby:;shutdown=true", null);
            } catch (SQLException e) {
            // exception of shutdown success. no need to catch.
            }
        }
    }
}
Also used : DataSet(org.talend.sqlbuilder.dataset.dataset.DataSet) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DriverShim(org.talend.core.model.metadata.builder.database.DriverShim) SQLException(java.sql.SQLException)

Example 7 with DataSet

use of org.talend.sqlbuilder.dataset.dataset.DataSet in project tdi-studio-se by Talend.

the class ColumnInfoTab 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().getColumns(ti.getCatalogName(), ti.getSchemaName(), realTableName, //$NON-NLS-1$
            "%");
        } else {
            // https://jira.talendforge.org/browse/TDI-28578
            String tableName = ti.getSimpleName();
            if (tableName.contains("/")) {
                tableName = tableName.replaceAll("/", "//");
            }
            resultSet = node.getSession().getMetaData().getJDBCMetaData().getColumns(ti.getCatalogName(), ti.getSchemaName(), tableName, "%");
        // resultSet = node.getSession().getMetaData().getColumns(tableNode.getTableInfo());
        }
        DataSet dataSet = new DataSet(null, resultSet, new int[] { 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 });
        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 8 with DataSet

use of org.talend.sqlbuilder.dataset.dataset.DataSet in project tdi-studio-se by Talend.

the class ConnectionInfoTab method getDataSet.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.sqlbuilder.dbdetail.tab.AbstractDataSetTab#getDataSet()
     */
@Override
public DataSet getDataSet() throws Exception {
    INode node = getNode();
    if (node == null) {
        return null;
    }
    if (node.getSession() == null) {
        return null;
    }
    SQLDatabaseMetaData sqlMetaData = node.getSession().getMetaData();
    if (sqlMetaData == null) {
        return null;
    }
    DatabaseMetaData jdbcMetaData = sqlMetaData.getJDBCMetaData();
    String[] header = new String[2];
    //$NON-NLS-1$
    header[0] = Messages.getString("DatabaseDetailView.Tab.ConnectionInfo.Property");
    //$NON-NLS-1$
    header[1] = Messages.getString("DatabaseDetailView.Tab.ConnectionInfo.Value");
    String[][] data = new String[124][2];
    setDataTo20(node, sqlMetaData, jdbcMetaData, data);
    setDataTo40(jdbcMetaData, data);
    setDataTo60(jdbcMetaData, data);
    setDataTo80(jdbcMetaData, data);
    setDataTo100(jdbcMetaData, data);
    setDataTo120(jdbcMetaData, data);
    int[] types = new int[2];
    types[0] = DataSet.TYPE_STRING;
    types[1] = DataSet.TYPE_STRING;
    DataSet dataSet = new DataSet(header, data, types);
    return dataSet;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) SQLDatabaseMetaData(net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData) DataSet(org.talend.sqlbuilder.dataset.dataset.DataSet) SQLDatabaseMetaData(net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 9 with DataSet

use of org.talend.sqlbuilder.dataset.dataset.DataSet in project tdi-studio-se by Talend.

the class IndexesTab 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().getIndexInfo(ti.getCatalogName(), ti.getSchemaName(), realTableName, true, true);
        } else {
            resultSet = node.getSession().getMetaData().getIndexInfo((tableNode.getTableInfo()));
        }
        DataSet dataSet = new DataSet(null, resultSet, new int[] { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 });
        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 10 with DataSet

use of org.talend.sqlbuilder.dataset.dataset.DataSet in project tdi-studio-se by Talend.

the class PreviewTab 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;
        if (tableNode.getTableInfo() == null) {
            return null;
        }
        int maxResults = SqlBuilderPlugin.getDefault().getPluginPreferences().getInt(IConstants.PRE_ROW_COUNT);
        if (maxResults == 0) {
            maxResults = 50;
        }
        Statement statement = tableNode.getSession().getInteractiveConnection().createStatement();
        statement.setMaxRows(maxResults);
        //$NON-NLS-1$
        statement.execute("select * from " + tableNode.getQualifiedName());
        ResultSet resultSet = statement.getResultSet();
        DataSet dataSet = new DataSet(null, resultSet, null);
        resultSet.close();
        statement.close();
        return dataSet;
    }
    return null;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) DataSet(org.talend.sqlbuilder.dataset.dataset.DataSet) Statement(java.sql.Statement) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) ResultSet(java.sql.ResultSet)

Aggregations

DataSet (org.talend.sqlbuilder.dataset.dataset.DataSet)11 ResultSet (java.sql.ResultSet)8 INode (org.talend.sqlbuilder.dbstructure.nodes.INode)8 TableNode (org.talend.sqlbuilder.dbstructure.nodes.TableNode)7 ITableInfo (net.sourceforge.squirrel_sql.fw.sql.ITableInfo)5 SessionTreeNode (org.talend.sqlbuilder.sessiontree.model.SessionTreeNode)5 Statement (java.sql.Statement)2 DatabaseMetaData (java.sql.DatabaseMetaData)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 SQLConnection (net.sourceforge.squirrel_sql.fw.sql.SQLConnection)1 SQLDatabaseMetaData (net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData)1 GridData (org.eclipse.swt.layout.GridData)1 Label (org.eclipse.swt.widgets.Label)1 DriverShim (org.talend.core.model.metadata.builder.database.DriverShim)1 DataSetTable (org.talend.sqlbuilder.dataset.dataset.DataSetTable)1