Search in sources :

Example 1 with DBCExecutionContext

use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.

the class AbstractSessionEditor method createPartControl.

@Override
public void createPartControl(Composite parent) {
    final DBCExecutionContext executionContext = getExecutionContext();
    if (executionContext != null) {
        setPartName("Sessions - " + executionContext.getDataSource().getContainer().getName());
        sessionsViewer = createSessionViewer(executionContext, parent);
        sessionsViewer.refreshSessions();
    }
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext)

Example 2 with DBCExecutionContext

use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by dbeaver.

the class Debugger method main.

public static void main(String[] args) throws DBGException {
    // "jdbc:postgresql://localhost/postgres?user=postgres&password=postgres&ssl=false";
    String url = "jdbc:postgresql://192.168.229.133/postgres?user=postgres&password=postgres&ssl=false";
    DBPDataSourceContainer dataSource = null;
    Connection conn;
    DBGBaseController controller;
    try {
        conn = DriverManager.getConnection(url);
    } catch (SQLException e) {
        e.printStackTrace();
        return;
    }
    // TODO: fix connection
    controller = new PostgreDebugController(dataSource);
    Scanner sc = new Scanner(System.in);
    Scanner scArg;
    String command;
    while (true) {
        System.out.print(PROMPT);
        command = sc.next();
        switch(command.toUpperCase()) {
            case COMMAND_HELP:
                System.out.println("W Show sessions");
                System.out.println("N New session");
                System.out.println("D Show debug objects");
                System.out.println("S Stack");
                System.out.println("F Frame");
                System.out.println("V Variables");
                System.out.println("= Set Variables");
                System.out.println("L List breakpoint(s)");
                System.out.println("Q List debug session(s)");
                System.out.println("B Set breakpoint");
                System.out.println("R Remove breakpoint");
                System.out.println("C Continue execution");
                System.out.println("I Step into");
                System.out.println("O Step over");
                System.out.println("X Close session");
                System.out.println("T Abort session");
                System.out.println("E Exit debugger");
                System.out.println("? This help");
                break;
            case COMMAND_CLOSE:
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionC = chooseSession(sc, controller);
                if (debugSessionC == null) {
                    break;
                }
                controller.detach(debugSessionC.getSessionId(), new VoidProgressMonitor());
                System.out.println("Session closed");
                break;
            case COMMAND_STACK:
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionSL = chooseSession(sc, controller);
                if (debugSessionSL == null) {
                    break;
                }
                List<? extends DBGStackFrame> stack = debugSessionSL.getStack();
                if (stack.size() == 0) {
                    System.out.println("No stack defined");
                }
                for (DBGStackFrame s : stack) {
                    System.out.println(s.toString());
                }
                break;
            case COMMAND_FRAME:
                System.out.println("FRAME!!!");
                break;
            case COMMAND_VARIABLES:
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionVL = chooseSession(sc, controller);
                if (debugSessionVL == null) {
                    break;
                }
                List<? extends DBGVariable<?>> vars = debugSessionVL.getVariables();
                if (vars.size() == 0) {
                    System.out.println("No vars defined");
                }
                for (DBGVariable<?> v : vars) {
                    System.out.println(v.toString());
                }
                break;
            case COMMAND_VARIABLE_SET:
                String strVal = "";
                String argcV = sc.nextLine();
                if (argcV.length() > 0) {
                    scArg = new Scanner(argcV);
                    if (scArg.hasNext()) {
                        strVal = scArg.next();
                    }
                    scArg.close();
                }
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionVS = chooseSession(sc, controller);
                if (debugSessionVS == null) {
                    break;
                }
                DBGVariable<?> var = chooseVariable(sc, controller, debugSessionVS);
                if (var == null) {
                    break;
                }
                debugSessionVS.setVariableVal(var, strVal);
                System.out.println(String.format("Variable Set %s", strVal));
                break;
            case COMMAND_BREAKPOINT:
                String strObjId = ANY_ARG;
                String strLineNo = ANY_ARG;
                String argc = sc.nextLine();
                if (argc.length() > 0) {
                    scArg = new Scanner(argc);
                    if (scArg.hasNext()) {
                        strObjId = scArg.next();
                        if (scArg.hasNext()) {
                            argc = scArg.nextLine();
                            if (argc.length() > 0) {
                                strLineNo = argc;
                            }
                        }
                    }
                    scArg.close();
                }
                Integer objId = -1;
                try {
                    objId = Integer.valueOf(strObjId.trim());
                } catch (Exception e) {
                    System.out.println(String.format("Incorrect object ID '%s'", strObjId));
                    break;
                }
                int lineNo = -1;
                if (strLineNo.trim().length() > 0) {
                    try {
                        lineNo = Integer.valueOf(strLineNo.trim());
                    } catch (Exception e) {
                        System.out.println(String.format("Incorrect line number '%s'", strLineNo));
                        break;
                    }
                }
                DBGObjectDescriptor debugObject = null;
                for (DBGObjectDescriptor o : controller.getObjects("_", "_")) {
                    if (objId.equals(o.getID())) {
                        debugObject = o;
                    }
                }
                if (debugObject == null) {
                    System.out.println(String.format("Object ID '%s' no found", strObjId));
                    break;
                }
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSession = chooseSession(sc, controller);
                if (debugSession == null) {
                    break;
                }
                PostgreDebugBreakpointProperties breakpointProperties = lineNo > 0 ? new PostgreDebugBreakpointProperties(lineNo, true) : new PostgreDebugBreakpointProperties(true);
                Object oid = debugObject.getID();
                PostgreDebugBreakpointDescriptor descriptor = new PostgreDebugBreakpointDescriptor(oid, breakpointProperties);
                debugSession.addBreakpoint(descriptor);
                System.out.println("Breakpoint added");
                System.out.println(breakpointProperties.toString());
                break;
            case COMMAND_BREAKPOINT_LIST:
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionBL = chooseSession(sc, controller);
                if (debugSessionBL == null) {
                    break;
                }
                if (debugSessionBL.getBreakpoints().size() == 0) {
                    System.out.println("No breakpoints defined");
                }
                for (DBGBreakpointDescriptor bpl : debugSessionBL.getBreakpoints()) {
                    System.out.println(bpl.toString());
                }
                break;
            case COMMAND_BREAKPOINT_REMOVE:
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionBR = chooseSession(sc, controller);
                if (debugSessionBR == null) {
                    break;
                }
                if (debugSessionBR.getBreakpoints().size() == 0) {
                    System.out.println("No breakpoints defined");
                }
                DBGBreakpointDescriptor bpr = chooseBreakpoint(sc, controller, debugSessionBR);
                debugSessionBR.removeBreakpoint(bpr);
                System.out.println("Breakpoint removed ...");
                break;
            case COMMAND_CONTINUE:
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionSC = chooseSession(sc, controller);
                if (debugSessionSC == null) {
                    break;
                }
                debugSessionSC.execContinue();
                System.out.println("Continue ...");
                break;
            case COMMAND_INTO:
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionSI = chooseSession(sc, controller);
                if (debugSessionSI == null) {
                    break;
                }
                debugSessionSI.execStepInto();
                System.out.println("Step Into ...");
                break;
            case COMMAND_OVER:
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionSO = chooseSession(sc, controller);
                if (debugSessionSO == null) {
                    break;
                }
                debugSessionSO.execStepOver();
                System.out.println("Step over ...");
                break;
            case COMMAND_SESSIONS:
                for (DBGSessionInfo s : controller.getSessionDescriptors()) {
                    System.out.println(s);
                }
                break;
            case COMMAND_DEBUG_LIST:
                if (controller.getSessions().size() == 0) {
                    System.out.println("no debug sessions");
                    break;
                }
                for (DBGSession s : controller.getSessions()) {
                    System.out.println(s);
                }
                break;
            case COMMAND_NEW:
                try {
                    Connection debugConn = DriverManager.getConnection(url);
                    // TODO: fix connection
                    DBCExecutionContext executionContext = null;
                    DBGSession s = controller.createSession(null, executionContext);
                    System.out.println("created");
                    System.out.println(s);
                } catch (SQLException e) {
                    e.printStackTrace();
                    break;
                }
                break;
            case COMMAND_OBJ:
                String proc = ANY_ARG;
                String owner = ANY_ARG;
                String arg = sc.nextLine();
                if (arg.length() > 0) {
                    scArg = new Scanner(arg);
                    if (scArg.hasNext()) {
                        proc = scArg.next();
                        if (scArg.hasNext()) {
                            arg = scArg.nextLine();
                            if (arg.length() > 0) {
                                owner = arg;
                            }
                        }
                    }
                    scArg.close();
                }
                for (DBGObjectDescriptor o : controller.getObjects(owner.equals(ANY_ARG) ? "_" : owner, proc.equals(ANY_ARG) ? "_" : proc)) {
                    System.out.println(o);
                }
                break;
            case COMMAND_ATTACH:
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionA = chooseSession(sc, controller);
                if (debugSessionA == null) {
                    break;
                }
                System.out.println("Waiting for target session ...");
                break;
            case COMMAND_TERMINATE:
                System.out.println("EXIT.....");
                return;
            default:
                System.out.println(String.format("Unnown command '%s' for command list type ?", command));
                break;
        }
    }
}
Also used : Scanner(java.util.Scanner) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) SQLException(java.sql.SQLException) PostgreDebugBreakpointDescriptor(org.jkiss.dbeaver.ext.postgresql.debug.internal.impl.PostgreDebugBreakpointDescriptor) Connection(java.sql.Connection) PostgreDebugController(org.jkiss.dbeaver.ext.postgresql.debug.internal.impl.PostgreDebugController) DBGBreakpointDescriptor(org.jkiss.dbeaver.debug.DBGBreakpointDescriptor) DBGSession(org.jkiss.dbeaver.debug.DBGSession) DBGException(org.jkiss.dbeaver.debug.DBGException) SQLException(java.sql.SQLException) DBGStackFrame(org.jkiss.dbeaver.debug.DBGStackFrame) PostgreDebugBreakpointProperties(org.jkiss.dbeaver.ext.postgresql.debug.internal.impl.PostgreDebugBreakpointProperties) DBGBaseController(org.jkiss.dbeaver.debug.DBGBaseController) DBGSessionInfo(org.jkiss.dbeaver.debug.DBGSessionInfo) DBGObjectDescriptor(org.jkiss.dbeaver.debug.DBGObjectDescriptor) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 3 with DBCExecutionContext

use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by dbeaver.

the class PostgreDebugController method getObjects.

@Override
public List<PostgreDebugObjectDescriptor> getObjects(String ownerCtx, String nameCtx) throws DBGException {
    DBCExecutionContext executionContext = getExecutionContext();
    String sql = SQL_OBJECT.replaceAll("\\?nameCtx", nameCtx).replaceAll("\\?userCtx", ownerCtx).toLowerCase();
    try (Statement stmt = getConnection(executionContext).createStatement();
        ResultSet rs = stmt.executeQuery(sql)) {
        List<PostgreDebugObjectDescriptor> res = new ArrayList<PostgreDebugObjectDescriptor>();
        while (rs.next()) {
            int oid = rs.getInt("oid");
            String proname = rs.getString("proname");
            String owner = rs.getString("owner");
            String nspname = rs.getString("nspname");
            String lang = rs.getString("lang");
            PostgreDebugObjectDescriptor object = new PostgreDebugObjectDescriptor(oid, proname, owner, nspname, lang);
            res.add(object);
        }
        return res;
    } catch (SQLException e) {
        throw new DBGException("SQL error", e);
    }
}
Also used : DBGException(org.jkiss.dbeaver.debug.DBGException) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) JDBCExecutionContext(org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext) SQLException(java.sql.SQLException) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList)

Example 4 with DBCExecutionContext

use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by dbeaver.

the class NavigatorHandlerObjectGoto method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    DBCExecutionContext context = null;
    DBSObject container = null;
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof DBPContextProvider) {
        context = ((DBPContextProvider) activePart).getExecutionContext();
    } else if (activePart instanceof INavigatorModelView) {
        final ISelection selection = HandlerUtil.getCurrentSelection(event);
        if (selection instanceof IStructuredSelection) {
            Object element = ((IStructuredSelection) selection).getFirstElement();
            if (element instanceof DBSWrapper) {
                DBSObject object = ((DBSWrapper) element).getObject();
                if (object != null) {
                    container = object;
                    while (container instanceof DBSFolder) {
                        container = container.getParentObject();
                    }
                    DBPDataSource dataSource = object.getDataSource();
                    if (dataSource != null) {
                        context = dataSource.getDefaultContext(true);
                    }
                }
            }
        }
    }
    if (context == null) {
        DBUserInterface.getInstance().showError("Go to object", "No active datasource");
        return null;
    }
    IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    GotoObjectDialog dialog = new GotoObjectDialog(HandlerUtil.getActiveShell(event), context, container);
    dialog.open();
    Object[] objectsToOpen = dialog.getResult();
    if (!ArrayUtils.isEmpty(objectsToOpen)) {
        Collection<DBNDatabaseNode> nodes = NavigatorHandlerObjectBase.getNodesByObjects(Arrays.asList(objectsToOpen));
        for (DBNDatabaseNode node : nodes) {
            NavigatorUtils.openNavigatorNode(node, workbenchWindow);
        }
    }
    return null;
}
Also used : DBSFolder(org.jkiss.dbeaver.model.struct.DBSFolder) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) GotoObjectDialog(org.jkiss.dbeaver.ui.dialogs.GotoObjectDialog) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 5 with DBCExecutionContext

use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.

the class AbstractLockEditor method createEditorControl.

@Override
public void createEditorControl(Composite parent) {
    final DBCExecutionContext executionContext = getExecutionContext();
    if (executionContext != null) {
        setPartName(LocksUIMessages.create_editor_control_name_lock + executionContext.getDataSource().getContainer().getName());
        lockViewer = createLockViewer(executionContext, parent);
        lockViewer.refreshLocks(null);
    }
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext)

Aggregations

DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)107 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)27 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)22 DBException (org.jkiss.dbeaver.DBException)21 DBPContextProvider (org.jkiss.dbeaver.model.DBPContextProvider)20 InvocationTargetException (java.lang.reflect.InvocationTargetException)16 DBCExecutionContextDefaults (org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults)16 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)15 GridData (org.eclipse.swt.layout.GridData)12 IEditorPart (org.eclipse.ui.IEditorPart)12 DBCException (org.jkiss.dbeaver.model.exec.DBCException)12 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)12 ArrayList (java.util.ArrayList)10 Composite (org.eclipse.swt.widgets.Composite)10 DBSCatalog (org.jkiss.dbeaver.model.struct.rdb.DBSCatalog)10 DBSSchema (org.jkiss.dbeaver.model.struct.rdb.DBSSchema)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)8 SelectionEvent (org.eclipse.swt.events.SelectionEvent)8 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)8 NotNull (org.jkiss.code.NotNull)8