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.
}
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations