use of net.sourceforge.sqlexplorer.plugin.editors.Message in project tdq-studio-se by Talend.
the class AbstractSQLExecution method logException.
/**
* Handles a SQLException by parsing the message and populating the messages tab;
* where error messages from the server are numbered, they start relative to the
* line number of the query that was sent; lineNoOffset is added to each line
* number so that they relate to the line in SQLEditor
* @param e The exception
* @param query The Query that triggered the exception
* @param positionEditor Whether to reposition the text caret of the editor to the first message
*/
protected void logException(SQLException e, Query query, boolean positionEditor) throws SQLException {
DatabaseProduct product = _session.getDatabaseProduct();
if (product == null)
return;
final Collection<Message> messages = product.getErrorMessages(_connection, e, query.getLineNo() - 1);
if (messages == null)
return;
for (Message message : messages) {
int lineNo = message.getLineNo();
lineNo = queryParser.adjustLineNo(lineNo);
message.setLineNo(lineNo);
message.setSql(query.getQuerySql());
}
addMessages(messages);
if (positionEditor) {
final Shell shell = getEditor().getSite().getShell();
shell.getDisplay().asyncExec(new Runnable() {
public void run() {
if (messages.size() > 0) {
Message msg = messages.iterator().next();
getEditor().setCursorPosition(msg.getLineNo(), msg.getCharNo());
}
}
});
}
}
use of net.sourceforge.sqlexplorer.plugin.editors.Message in project tdq-studio-se by Talend.
the class AbstractSQLExecution method logException.
/**
* Handles a SQLException by parsing the message and populating the messages tab;
* where error messages from the server are numbered, they start relative to the
* line number of the query that was sent; lineNoOffset is added to each line
* number so that they relate to the line in SQLEditor
* @param e
*/
protected void logException(SQLException e, String sql) throws SQLException {
Collection<Message> messages = _session.getDatabaseProduct().getErrorMessages(_connection, e, 0);
if (messages == null)
return;
for (Message message : messages) {
int lineNo = message.getLineNo();
lineNo = queryParser.adjustLineNo(lineNo);
message.setLineNo(lineNo);
message.setSql(sql);
}
addMessages(messages);
}
use of net.sourceforge.sqlexplorer.plugin.editors.Message in project tdq-studio-se by Talend.
the class BatchJob method run.
@Override
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask(Messages.getString("BatchJob.ExecutingScripts"), files.size());
DatabaseProduct product = user.getAlias().getDriver().getDatabaseProduct();
SQLConnection connection = null;
try {
if (session == null)
session = user.createSession();
connection = session.grabConnection();
int index = 0;
for (File file : files) {
if (monitor.isCanceled())
break;
monitor.worked(index++);
monitor.subTask(file.getName());
_logger.fatal(file.getAbsolutePath());
String sql = null;
try {
char[] buffer = new char[(int) file.length() + 10];
FileReader reader = new FileReader(file);
int length = reader.read(buffer);
reader.close();
if (length < 0 || length >= buffer.length) {
SQLExplorerPlugin.error("Cannot read from file " + file.getAbsolutePath());
continue;
}
// Normalise this to have standard \n in strings. \r confuses Oracle and
// isn't normally needed internally anyway
StringBuffer sb = new StringBuffer(new String(buffer, 0, length));
buffer = null;
for (int i = 0; i < sb.length(); i++) {
if (sb.charAt(i) == '\r') {
sb.deleteCharAt(i);
i--;
}
}
sql = sb.toString();
sb = null;
} catch (IOException e) {
SQLExplorerPlugin.error("Cannot read from file " + file.getAbsolutePath(), e);
continue;
}
QueryParser parser = product.getQueryParser(sql, 1);
parser.parse();
for (Query query : parser) {
DatabaseProduct.ExecutionResults results = null;
try {
results = product.executeQuery(connection, query, -1);
DataSet dataSet;
while ((dataSet = results.nextDataSet()) != null) {
LinkedList<Message> messages = new LinkedList<Message>();
Collection<Message> messagesTmp = session.getDatabaseProduct().getErrorMessages(connection, query);
if (messagesTmp != null)
messages.addAll(messagesTmp);
messagesTmp = session.getDatabaseProduct().getServerMessages(connection);
if (messagesTmp != null)
messages.addAll(messagesTmp);
for (Message msg : messages) msg.setLineNo(parser.adjustLineNo(msg.getLineNo()));
for (Message message : messages) {
_logger.fatal(message.getSql());
}
}
} catch (SQLException e) {
_logger.fatal(e.getMessage());
} finally {
try {
if (results != null) {
results.close();
results = null;
}
} catch (SQLException e) {
// Nothing
}
}
}
}
monitor.done();
} catch (SQLException e) {
SQLExplorerPlugin.error(e);
} catch (ParserException e) {
SQLExplorerPlugin.error(e);
} finally {
if (connection != null)
session.releaseConnection(connection);
}
return new Status(IStatus.OK, getClass().getName(), IStatus.OK, Messages.getString("BatchJob.Success"), null);
}
Aggregations