Search in sources :

Example 1 with DataSet

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

the class AbstractDataSetTab method fillDetailComposite.

public final void fillDetailComposite(Composite composite) {
    try {
        pComposite = composite;
        DataSet dataSet = getCachedDataSet();
        if (dataSet == null) {
            return;
        }
        // store for later use in dataset table
        //$NON-NLS-1$
        composite.setData("IDetailTab", this);
        new DataSetTable(composite, dataSet, getStatusMessage(), false);
    } catch (Exception e) {
        //$NON-NLS-1$
        SqlBuilderPlugin.log(Messages.getString("AbstractDataSetTab.logMessage1"), e);
        // couldn't get results.. clean mess up
        Control[] controls = composite.getChildren();
        for (int i = 0; i < controls.length; i++) {
            controls[i].dispose();
        }
        // and show error message
        Label label = new Label(composite, SWT.FILL);
        //$NON-NLS-1$ //$NON-NLS-2$
        label.setText(Messages.getString("DatabaseDetailView.Tab.Unavailable") + " " + e.getMessage());
        label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
        //$NON-NLS-1$
        SqlBuilderPlugin.log(Messages.getString("AbstractDataSetTab.logMessage2"), e);
    }
}
Also used : DataSet(org.talend.sqlbuilder.dataset.dataset.DataSet) DataSetTable(org.talend.sqlbuilder.dataset.dataset.DataSetTable) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData)

Example 2 with DataSet

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

the class AbstractSQLTab method getDataSet.

public final DataSet getDataSet() throws Exception {
    DataSet dataSet = null;
    int timeOut = SqlBuilderPlugin.getDefault().getPluginPreferences().getInt(IConstants.INTERACTIVE_QUERY_TIMEOUT);
    SQLConnection connection = getNode().getSession().getInteractiveConnection();
    ResultSet rs = null;
    Statement stmt = null;
    PreparedStatement pStmt = null;
    try {
        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(null, rs, null);
        rs.close();
    } catch (Exception e) {
        //$NON-NLS-1$
        SqlBuilderPlugin.log(Messages.getString("AbstractSQLTab.logMessage1") + getNode().getName(), e);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (Exception e) {
                //$NON-NLS-1$
                SqlBuilderPlugin.log(Messages.getString("AbstractSQLTab.logMessage2"), e);
            }
        }
        if (pStmt != null) {
            try {
                pStmt.close();
            } catch (Exception e) {
                //$NON-NLS-1$
                SqlBuilderPlugin.log(Messages.getString("AbstractSQLTab.logMessage2"), e);
            }
        }
    }
    return dataSet;
}
Also used : DataSet(org.talend.sqlbuilder.dataset.dataset.DataSet) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) SQLConnection(net.sourceforge.squirrel_sql.fw.sql.SQLConnection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 3 with DataSet

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

the class ImportedKeysTab 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().getImportedKeys(ti.getCatalogName(), ti.getSchemaName(), realTableName);
        } else {
            resultSet = node.getSession().getMetaData().getImportedKeys((tableNode.getTableInfo()));
        }
        DataSet dataSet = new DataSet(null, resultSet, new int[] { 3, 4, 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 4 with DataSet

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

the class PrimaryKeysTab 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 name .
        if (ti.getType().equals("SYNONYM")) {
            //$NON-NLS-1$
            String realTableName = ExtractMetaDataFromDataBase.getTableNameBySynonym(treeNode.getInteractiveConnection().getConnection(), ti.getSimpleName());
            resultSet = treeNode.getMetaData().getJDBCMetaData().getPrimaryKeys(ti.getCatalogName(), ti.getSchemaName(), realTableName);
        } else {
            resultSet = node.getSession().getMetaData().getPrimaryKeys((tableNode.getTableInfo()));
        }
        DataSet dataSet = new DataSet(null, resultSet, new int[] { 4, 5, 6 });
        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 5 with DataSet

use of org.talend.sqlbuilder.dataset.dataset.DataSet 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)

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