use of org.jkiss.dbeaver.debug.DBGEvent in project dbeaver by dbeaver.
the class PostgreDebugSession method attachLocal.
private void attachLocal(int OID, String call) throws DBGException {
executionTarget = createExecutionTarget();
createSlot(executionTarget, OID);
String taskName = "Local attached to " + String.valueOf(targetId);
runProc(executionTarget, call, taskName);
waitPortNumber();
sessionId = attachToPort();
getController().fireEvent(new DBGEvent(this, DBGEvent.SUSPEND, DBGEvent.MODEL_SPECIFIC));
try {
getConnection().setClientInfo("ApplicationName", "Debug Mode (local) : " + String.valueOf(sessionId));
} catch (SQLClientInfoException e) {
log.warn("Unable to set Application name", e);
e.printStackTrace();
}
}
use of org.jkiss.dbeaver.debug.DBGEvent in project dbeaver by dbeaver.
the class PostgreDebugSession method attachGlobal.
private void attachGlobal(int oid, int targetPID) throws DBGException {
try (Statement stmt = getConnection().createStatement();
ResultSet rs = stmt.executeQuery(SQL_LISTEN)) {
if (rs.next()) {
sessionId = rs.getInt("sessionid");
getConnection().setClientInfo("ApplicationName", "Debug Mode : " + String.valueOf(sessionId));
} else {
throw new DBGException("Unable to create debug instance");
}
} catch (SQLException e) {
throw new DBGException("SQL error", e);
}
PostgreDebugBreakpointProperties properties = new PostgreDebugBreakpointProperties(true);
bpGlobal = new PostgreDebugBreakpointDescriptor(oid, properties);
addBreakpoint(bpGlobal);
String sessionParam = String.valueOf(getSessionId());
String taskName = sessionParam + " global attached to " + String.valueOf(targetId);
String sql = SQL_ATTACH.replaceAll("\\?sessionid", sessionParam);
DBGEvent begin = new DBGEvent(this, DBGEvent.RESUME, DBGEvent.MODEL_SPECIFIC);
DBGEvent end = new DBGEvent(this, DBGEvent.SUSPEND, DBGEvent.BREAKPOINT);
runAsync(sql, taskName, begin, end);
}
use of org.jkiss.dbeaver.debug.DBGEvent in project dbeaver by dbeaver.
the class PostgreDebugSession method execStep.
/**
* Execute step SQL command asynchronously, set debug session name to
* [sessionID] name [managerPID]
*
* @param commandPattern
* - SQL command for execute step
* @param nameParameter
* - session 'name' part
* @throws DBGException
*/
public void execStep(String commandPattern, String nameParameter, int eventDetail) throws DBGException {
acquireWriteLock();
try {
String sql = commandPattern.replaceAll("\\?sessionid", String.valueOf(sessionId));
String taskName = String.valueOf(sessionId) + nameParameter + String.valueOf(targetId);
DBGEvent begin = new DBGEvent(this, DBGEvent.RESUME, eventDetail);
DBGEvent end = new DBGEvent(this, DBGEvent.SUSPEND, eventDetail);
runAsync(sql, taskName, begin, end);
} finally {
lock.writeLock().unlock();
}
}
use of org.jkiss.dbeaver.debug.DBGEvent in project dbeaver by dbeaver.
the class PostgreDebugSession method runProc.
protected void runProc(Connection connection, String commandSQL, String name) throws DBGException {
job = new Job(name) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
try (final Statement stmt = connection.createStatement()) {
localStatement = stmt;
stmt.execute(commandSQL);
// And Now His Watch Is Ended
fireEvent(new DBGEvent(this, DBGEvent.RESUME, DBGEvent.STEP_RETURN));
}
} catch (SQLException e) {
fireEvent(new DBGEvent(this, DBGEvent.TERMINATE, DBGEvent.CLIENT_REQUEST));
String sqlState = e.getSQLState();
if (!PostgreConstants.EC_QUERY_CANCELED.equals(sqlState)) {
log.error(name, e);
return DebugCore.newErrorStatus(name, e);
}
}
return Status.OK_STATUS;
}
};
job.schedule();
}
Aggregations