use of org.talend.sqlbuilder.util.QueryTokenizer in project tdi-studio-se by Talend.
the class EMFRepositoryNodeManager method initSqlStatement.
public String initSqlStatement(String currentSql) {
QueryTokenizer qt = new QueryTokenizer(currentSql, queryDelimiter, alternateDelimiter, commentDelimiter);
List<String> queryStrings = new ArrayList<String>();
while (qt.hasQuery()) {
String querySql = qt.nextQuery();
// ignore commented lines.
if (!querySql.startsWith("--")) {
//$NON-NLS-1$
queryStrings.add(querySql);
}
}
if (queryStrings.size() < 1) {
// .getString("EMFRepositoryNodeManager.Notice.info"));
return null;
}
Boolean isForce = null;
if (queryStrings.size() > 1 && isPrompt) {
isForce = //$NON-NLS-1$
MessageDialog.openQuestion(//$NON-NLS-1$
new Shell(), //$NON-NLS-1$
Messages.getString("EMFRepositoryNodeManager.Notice.Title2"), //$NON-NLS-1$
Messages.getString("EMFRepositoryNodeManager.Notice.info2"));
}
//$NON-NLS-1$ //$NON-NLS-2$
String string = queryStrings.get(0).toLowerCase().replaceAll("\n", " ");
//$NON-NLS-1$ //$NON-NLS-2$
string = string.replaceAll("\t", " ");
//$NON-NLS-1$ //$NON-NLS-2$
string = string.replaceAll("\r", " ");
// string = string.replaceAll("\"", ""); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-1$ //$NON-NLS-2$
string = string.replaceAll("\'", "");
if (!string.startsWith("select ")) {
//$NON-NLS-1$
if (isPrompt) {
MessageDialog.openWarning(new Shell(), Messages.getString("EMFRepositoryNodeManager.Notice.title3"), //$NON-NLS-1$
Messages.getString(//$NON-NLS-1$
"EMFRepositoryNodeManager.Notice.info3"));
}
}
if (isForce != null && !isForce.booleanValue()) {
return null;
}
// buttom of the GUI.");
return string;
}
use of org.talend.sqlbuilder.util.QueryTokenizer 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 org.talend.sqlbuilder.util.QueryTokenizer in project tdi-studio-se by Talend.
the class ExecSQLAction method run.
/**
* DOC qianbing Comment method "run". Processes the database operation.
*
* @param maxRows
*/
protected void run(int maxRows) {
RepositoryNode node = editor.getRepositoryNode();
SessionTreeNodeManager nodeManager = new SessionTreeNodeManager();
SessionTreeNode runNode = null;
try {
ConnectionContextHelper.setSqlBuilderDialogShell(editor.getDialog().getShell());
runNode = nodeManager.getSessionTreeNode(node, editor.getDialog().getSelectedContext());
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
//$NON-NLS-1$
MessageDialog.openError(null, Messages.getString("AbstractSQLExecution.Executing.Error"), e.getMessage());
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("ExecSQLAction.logMessageGetSessionTreeNodeFail"), e);
return;
}
QueryTokenizer qt = new QueryTokenizer(getSQLToBeExecuted(), queryDelimiter, alternateDelimiter, commentDelimiter);
List<String> queryStrings = new ArrayList<String>();
while (qt.hasQuery()) {
String querySql = qt.nextQuery();
// ignore commented lines.
if (!querySql.startsWith("--")) {
//$NON-NLS-1$
queryStrings.add(querySql);
}
}
try {
// Diaplay data in sqlResult Composites
while (!queryStrings.isEmpty()) {
String querySql = queryStrings.remove(0);
if (querySql != null) {
SQLExecution sqlExe = new SQLExecution(querySql, maxRows, runNode);
resultViewer.addSQLExecution(sqlExe);
// editor.setSQLRunTime(sqlExe.getSQLResult().getExecutionTimeMillis());
}
}
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("ExecSQLAction.logMessageErrorCreatingSqlTab"), e);
}
}
use of org.talend.sqlbuilder.util.QueryTokenizer in project tdi-studio-se by Talend.
the class GUIModificationQueryAction method run.
/*
* (non-Java)
*
* @see org.talend.sqlbuilder.actions.AbstractEditorAction#run()
*/
@Override
public void run() {
currentSql = getEditor().getSQLToBeExecuted();
// }
if (dialog instanceof SQLBuilderDialog) {
SQLBuilderDialog d = (SQLBuilderDialog) dialog;
final CTabItem selection = d.getEditorComposite().getTabFolder().getSelection();
if (selection.getData("KEY") instanceof MultiPageSqlBuilderEditor) {
//$NON-NLS-1$
//$NON-NLS-1$
MultiPageSqlBuilderEditor editor = (MultiPageSqlBuilderEditor) selection.getData("KEY");
switch(editor.getActivePage()) {
case 1:
isDesigner = true;
break;
default:
isDesigner = false;
break;
}
}
}
String query = null;
if (isDesigner) {
SqlEditDialog textDialog = new SqlEditDialog(dialog.getShell(), Messages.getString("GUIModificationQueryAction.TextDialog.TitleText"), currentSql, //$NON-NLS-1$
currentNode);
if (Window.OK == textDialog.open()) {
query = textDialog.getSql();
}
} else {
List<IRepositoryNode> selectedNodes = null;
try {
selectedNodes = EMFRepositoryNodeManager.getInstance().parseSqlStatement(currentSql, currentNode);
} catch (Exception e) {
MessageDialog.openError(new Shell(), Messages.getString("GUIModificationQueryAction.Error.Notice"), //$NON-NLS-1$ //$NON-NLS-2$
Messages.getString("GUIModificationQueryAction.SqlStatement.ErrorMsg"));
}
if (selectedNodes == null) {
return;
}
// String info = Messages.getString("MultiPageSqlBuilderEditor.Notice.InformationNotFull");
// MessageDialog.openInformation(new Shell(),
// Messages.getString("GUIModificationQueryAction.Information.Msg"), info); //$NON-NLS-1$
ErDiagramDialog erDiagramDialog = new ErDiagramDialog(dialog.getShell(), Messages.getString("GUIModificationQueryAction.Dialog.TitleText"), //$NON-NLS-1$
currentNode);
erDiagramDialog.setDialog(dialog);
erDiagramDialog.setNodes(selectedNodes);
erDiagramDialog.setSqlText(currentSql);
EMFRepositoryNodeManager.getInstance().setRoot(currentNode);
if (Window.OK == erDiagramDialog.open()) {
query = erDiagramDialog.getSql();
}
}
if (query == null) {
return;
}
if (!query.endsWith(";\n") && !query.endsWith(";")) {
//$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-1$
query += ";\n";
}
//$NON-NLS-1$
String targetSql = "";
boolean isfirst = true;
QueryTokenizer qt = new QueryTokenizer(currentSql, queryDelimiter, alternateDelimiter, commentDelimiter);
while (qt.hasQuery()) {
String querySql = qt.nextQuery();
if (querySql.startsWith("--") || !isfirst) {
//$NON-NLS-1$
//$NON-NLS-1$
targetSql += querySql + ";\n";
} else {
targetSql += query;
isfirst = false;
}
}
if (!qt.hasQuery()) {
targetSql = query;
}
// currentSql = currentSql.replaceFirst(queryStrings.get(0), query);
getEditor().setEditorContent(targetSql);
}
use of org.talend.sqlbuilder.util.QueryTokenizer in project tdi-studio-se by Talend.
the class DB2ExplainPlanAction 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("DB2ExplainPlanAction.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);
final 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 queryno from SYSTOOLS.EXPLAIN_STATEMENT");
notFoundTable = false;
rs.close();
} catch (Throwable e) {
createPlanTable = MessageDialog.openQuestion(null, //$NON-NLS-1$
Messages.getString("db2.editor.actions.explain.notFound.Title"), //$NON-NLS-1$
Messages.getString("db2.editor.actions.explain.notFound"));
} finally {
try {
st.close();
} catch (Throwable e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("DB2ExplainPlanAction.logMessage2"), e);
}
}
if (notFoundTable && !createPlanTable) {
return;
}
if (notFoundTable && createPlanTable) {
SQLConnection conn = runNode.getInteractiveConnection();
st = conn.createStatement();
try {
st.execute(createPlanScript1);
st.execute(createPlanScript2);
st.execute(createPlanScript3);
st.execute(createPlanScript4);
st.execute(createPlanScript5);
st.execute(createPlanScript6);
st.execute(createPlanScript7);
if (!conn.getAutoCommit()) {
conn.commit();
}
} catch (Throwable e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("DB2ExplainPlanAction.logMessage3"), e);
//$NON-NLS-1$
MessageDialog.openError(//$NON-NLS-1$
null, //$NON-NLS-1$
Messages.getString("db2.editor.actions.explain.createError.Title"), //$NON-NLS-1$
Messages.getString("db2.editor.actions.explain.createError"));
try {
st.close();
} catch (Throwable e1) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("DB2ExplainPlanAction.logMessage2"), e1);
}
return;
}
try {
st.close();
} catch (Throwable e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("DB2ExplainPlanAction.logMessage2"), e);
}
}
} catch (Exception e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("DB2ExplainPlanAction.logMessage4"), e);
}
try {
while (!queryStrings.isEmpty()) {
String querySql = (String) queryStrings.remove(0);
if (querySql != null) {
resultDisplayer.addSQLExecution(new DB2ExplainPlanExecution(querySql, runNode));
}
}
} catch (Exception e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("DB2ExplainPlanAction.logMessage5"), e);
}
}
Aggregations