use of net.sourceforge.squirrel_sql.fw.sql.SQLConnection in project tdi-studio-se by Talend.
the class OracleExplainPlanAction method run.
/*
* (non-Javadoc)
*
* @see org.talend.sqlbuilder.actions.AbstractEditorAction#run()
*/
//$NON-NLS-1$
@SuppressWarnings("unchecked")
@Override
public void run() {
RepositoryNode node = editor.getRepositoryNode();
SessionTreeNodeManager nodeManager = new SessionTreeNodeManager();
SessionTreeNode runNode = null;
try {
runNode = nodeManager.getSessionTreeNode(node, editor.getDialog().getSelectedContext());
} catch (Exception e) {
//$NON-NLS-1$
MessageDialog.openError(null, Messages.getString("AbstractSQLExecution.Executing.Error"), e.getMessage());
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage1"), e);
return;
}
Preferences prefs = SqlBuilderPlugin.getDefault().getPluginPreferences();
String queryDelimiter = prefs.getString(IConstants.QUERY_DELIMITER);
String alternateDelimiter = prefs.getString(IConstants.ALTERNATE_DELIMITER);
String commentDelimiter = prefs.getString(IConstants.COMMENT_DELIMITER);
QueryTokenizer qt = new QueryTokenizer(getSQLToBeExecuted(), queryDelimiter, alternateDelimiter, commentDelimiter);
List queryStrings = new ArrayList();
while (qt.hasQuery()) {
final String querySql = qt.nextQuery();
// ignore commented lines.
if (!querySql.startsWith("--")) {
//$NON-NLS-1$
queryStrings.add(querySql);
}
}
// check if we can run explain plans
try {
Statement st = runNode.getInteractiveConnection().createStatement();
boolean createPlanTable = false;
boolean notFoundTable = true;
try {
//$NON-NLS-1$
ResultSet rs = st.executeQuery("select statement_id from plan_table");
notFoundTable = false;
rs.close();
} catch (Throwable e) {
createPlanTable = MessageDialog.openQuestion(null, //$NON-NLS-1$
Messages.getString("oracle.editor.actions.explain.notFound.Title"), //$NON-NLS-1$
Messages.getString("oracle.editor.actions.explain.notFound"));
} finally {
try {
st.close();
} catch (Throwable e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage2"), e);
}
}
if (notFoundTable && !createPlanTable) {
return;
}
if (notFoundTable && createPlanTable) {
SQLConnection conn = runNode.getInteractiveConnection();
st = conn.createStatement();
try {
st.execute(createPlanTableScript);
if (!conn.getAutoCommit()) {
conn.commit();
}
} catch (Throwable e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage2"), e);
//$NON-NLS-1$
MessageDialog.openError(//$NON-NLS-1$
null, //$NON-NLS-1$
Messages.getString("oracle.editor.actions.explain.createError.Title"), //$NON-NLS-1$
Messages.getString("oracle.editor.actions.explain.createError"));
try {
st.close();
} catch (Throwable e1) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage3"), e1);
}
return;
}
try {
st.close();
} catch (Throwable e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage3"), e);
}
}
} catch (Exception e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage4"), e);
}
try {
while (!queryStrings.isEmpty()) {
String querySql = (String) queryStrings.remove(0);
if (querySql != null) {
resultDisplayer.addSQLExecution(new OracleExplainPlanExecution(querySql, runNode));
}
}
} catch (Exception e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage5"), e);
}
}
use of net.sourceforge.squirrel_sql.fw.sql.SQLConnection in project tdi-studio-se by Talend.
the class AbstractSQLSourceTab method getSource.
public String getSource() {
String source = null;
SQLConnection connection = getNode().getSession().getInteractiveConnection();
ResultSet rs = null;
Statement stmt = null;
PreparedStatement pStmt = null;
int timeOut = SqlBuilderPlugin.getDefault().getPluginPreferences().getInt(IConstants.INTERACTIVE_QUERY_TIMEOUT);
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();
}
//$NON-NLS-1$
source = "";
while (rs.next()) {
source = source + rs.getString(1);
}
rs.close();
} catch (Exception e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("AbstractSQLSourceTab.logMessage1") + getNode().getName(), e);
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (Exception e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("AbstractSQLSourceTab.logMessage2"), e);
}
}
if (pStmt != null) {
try {
pStmt.close();
} catch (Exception e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("AbstractSQLSourceTab.logMessage2"), e);
}
}
}
return source;
}
use of net.sourceforge.squirrel_sql.fw.sql.SQLConnection 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;
}
use of net.sourceforge.squirrel_sql.fw.sql.SQLConnection in project tdi-studio-se by Talend.
the class SessionTreeNodeUtils method createSQLConnection.
private static List createSQLConnection(DatabaseConnection con, String selectedContext, IMetadataConnection iMetadataConnection) throws Exception {
// bug 17980
ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance();
List list = extractMeta.getConnection(iMetadataConnection.getDbType(), iMetadataConnection.getUrl(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDatabase(), iMetadataConnection.getSchema(), iMetadataConnection.getDriverClass(), iMetadataConnection.getDriverJarPath(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getAdditionalParams());
SQLConnection sqlConnection = new SQLConnection(extractMeta.getConn(), null);
if (sqlConnection != null) {
list.add(sqlConnection);
}
return list;
}
use of net.sourceforge.squirrel_sql.fw.sql.SQLConnection in project tdi-studio-se by Talend.
the class SessionTreeNodeUtils method disposeConnections.
/**
* disposeConnections.
*/
private static void disposeConnections() {
SQLConnection connection = null;
for (Iterator it = connections.iterator(); it.hasNext(); ) {
connection = (SQLConnection) it.next();
try {
connection.close();
} catch (Exception e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("SessionTreeNodeUtils.logMessage"), e);
}
}
connections.clear();
}
Aggregations