Search in sources :

Example 1 with DBGEvent

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();
    }
}
Also used : SQLClientInfoException(java.sql.SQLClientInfoException) DBGEvent(org.jkiss.dbeaver.debug.DBGEvent)

Example 2 with DBGEvent

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);
}
Also used : DBGException(org.jkiss.dbeaver.debug.DBGException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) DBGEvent(org.jkiss.dbeaver.debug.DBGEvent) ResultSet(java.sql.ResultSet)

Example 3 with DBGEvent

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();
    }
}
Also used : DBGEvent(org.jkiss.dbeaver.debug.DBGEvent)

Example 4 with DBGEvent

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) DBGEvent(org.jkiss.dbeaver.debug.DBGEvent) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

DBGEvent (org.jkiss.dbeaver.debug.DBGEvent)4 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 ResultSet (java.sql.ResultSet)1 SQLClientInfoException (java.sql.SQLClientInfoException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Job (org.eclipse.core.runtime.jobs.Job)1 DBGException (org.jkiss.dbeaver.debug.DBGException)1