Search in sources :

Example 76 with DBSObject

use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.

the class DatabaseLaunchContributionItem method extractSelectedObjects.

protected Object[] extractSelectedObjects() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return NO_OBJECTS;
    }
    ISelection selection = window.getSelectionService().getSelection();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structured = (IStructuredSelection) selection;
        Object[] array = structured.toArray();
        Object o = structured.getFirstElement();
        if (o instanceof IEditorPart) {
            IEditorPart part = (IEditorPart) o;
            array[0] = part.getEditorInput();
        }
        return array;
    }
    if (selection instanceof ITextSelection) {
        IWorkbenchPage activePage = window.getActivePage();
        if (activePage != null) {
            IEditorPart activeEditor = activePage.getActiveEditor();
            DBSObject databaseObject = DebugUI.extractDatabaseObject(activeEditor);
            if (databaseObject != null) {
                return new Object[] { databaseObject };
            }
        }
    }
    return NO_OBJECTS;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 77 with DBSObject

use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.

the class ToggleProcedureBreakpointTarget method toggleLineBreakpoints.

@Override
public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
    IEditorPart editorPart = (IEditorPart) part;
    IResource resource = extractResource(editorPart, selection);
    if (resource == null) {
        return;
    }
    DBSObject databaseObject = DebugUI.extractDatabaseObject(editorPart);
    if (databaseObject == null) {
        return;
    }
    DBNDatabaseNode node = DBWorkbench.getPlatform().getNavigatorModel().getNodeByObject(new VoidProgressMonitor(), databaseObject, false);
    if (node == null) {
        return;
    }
    String nodeItemPath = node.getNodeItemPath();
    ITextSelection textSelection = (ITextSelection) selection;
    int lineNumber = textSelection.getStartLine();
    IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(DBGConstants.MODEL_IDENTIFIER_DATABASE);
    for (IBreakpoint breakpoint : breakpoints) {
        if (breakpoint instanceof IDatabaseBreakpoint) {
            IDatabaseBreakpoint databaseBreakpoint = (IDatabaseBreakpoint) breakpoint;
            if (nodeItemPath.equals(databaseBreakpoint.getNodePath())) {
                if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) {
                    DebugUITools.deleteBreakpoints(new IBreakpoint[] { breakpoint }, part.getSite().getShell(), null);
                    return;
                }
            }
        }
    }
    int charstart = -1, charend = -1;
    DBGBreakpointDescriptor breakpointDescriptor = GeneralUtils.adapt(databaseObject, DBGBreakpointDescriptor.class);
    if (breakpointDescriptor == null) {
        throw new CoreException(GeneralUtils.makeErrorStatus("Object '" + DBUtils.getObjectFullName(databaseObject, DBPEvaluationContext.UI) + "' doesn't support breakpoints"));
    }
    // create line breakpoint (doc line numbers start at 0)
    new DatabaseLineBreakpoint(databaseObject, node, resource, breakpointDescriptor, lineNumber + 1, charstart, charend, true);
}
Also used : DatabaseLineBreakpoint(org.jkiss.dbeaver.debug.core.breakpoints.DatabaseLineBreakpoint) IDatabaseBreakpoint(org.jkiss.dbeaver.debug.core.breakpoints.IDatabaseBreakpoint) IEditorPart(org.eclipse.ui.IEditorPart) DBGBreakpointDescriptor(org.jkiss.dbeaver.debug.DBGBreakpointDescriptor) ITextSelection(org.eclipse.jface.text.ITextSelection) ILineBreakpoint(org.eclipse.debug.core.model.ILineBreakpoint) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) DatabaseLineBreakpoint(org.jkiss.dbeaver.debug.core.breakpoints.DatabaseLineBreakpoint) IDatabaseBreakpoint(org.jkiss.dbeaver.debug.core.breakpoints.IDatabaseBreakpoint) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) CoreException(org.eclipse.core.runtime.CoreException) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) IResource(org.eclipse.core.resources.IResource)

Example 78 with DBSObject

use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.

the class DatabaseLaunchShortcut method launch.

@Override
public void launch(IEditorPart editor, String mode) {
    IEditorSite editorSite = editor.getEditorSite();
    workbenchPartSite = editorSite;
    ISelection selection = editorSite.getSelectionProvider().getSelection();
    if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
        Object[] array = ((IStructuredSelection) selection).toArray();
        searchAndLaunch(array, mode, getEditorEmptyMessage());
    } else {
        DBSObject databaseObject = DebugUI.extractDatabaseObject(editor);
        if (databaseObject != null) {
            Object[] array = new Object[] { databaseObject };
            searchAndLaunch(array, mode, getEditorEmptyMessage());
        }
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ISelection(org.eclipse.jface.viewers.ISelection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 79 with DBSObject

use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.

the class PostgresRolePrivilegesEditor method updateCurrentPrivileges.

private void updateCurrentPrivileges(boolean grant, PostgrePrivilegeType privilegeType) {
    if (ArrayUtils.isEmpty(currentObjects)) {
        DBWorkbench.getPlatformUI().showError("Update privilege", "Can't update privilege - no current object");
        return;
    }
    PostgrePrivilegeOwner databaseObject = getDatabaseObject();
    for (int i = 0; i < currentObjects.length; i++) {
        DBSObject currentObject = currentObjects[i];
        PostgrePrivilege permission = currentPermissions[i];
        if (permission == null) {
            if (!grant) {
                // No permission - nothing to revoke
                continue;
            }
            if (isRoleEditor()) {
                PostgrePrivilegeOwner permissionsOwner = (PostgrePrivilegeOwner) currentObject;
                PostgrePrivilegeGrant.Kind kind;
                String objectName;
                if (permissionsOwner instanceof PostgreProcedure) {
                    if (((PostgreProcedure) permissionsOwner).getKind() == PostgreProcedureKind.p) {
                        kind = PostgrePrivilegeGrant.Kind.PROCEDURE;
                    } else {
                        kind = PostgrePrivilegeGrant.Kind.FUNCTION;
                    }
                    objectName = ((PostgreProcedure) permissionsOwner).getUniqueName();
                } else {
                    if (permissionsOwner instanceof PostgreSchema) {
                        kind = PostgrePrivilegeGrant.Kind.SCHEMA;
                    } else if (permissionsOwner instanceof PostgreSequence) {
                        kind = PostgrePrivilegeGrant.Kind.SEQUENCE;
                    } else {
                        kind = PostgrePrivilegeGrant.Kind.TABLE;
                    }
                    objectName = permissionsOwner.getName();
                }
                permission = new PostgreRolePrivilege(databaseObject, kind, permissionsOwner.getSchema().getName(), objectName, Collections.emptyList());
            } else {
                String currentUser = databaseObject.getDataSource().getContainer().getActualConnectionConfiguration().getUserName();
                PostgrePrivilegeGrant privGrant = new PostgrePrivilegeGrant(currentUser, currentObject.getName(), databaseObject.getDatabase().getName(), databaseObject.getSchema().getName(), databaseObject.getName(), privilegeType, false, false);
                permission = new PostgreObjectPrivilege(databaseObject, currentObject.getName(), Collections.singletonList(privGrant));
            }
            // Add to map
            currentPermissions[i] = permission;
            permissionMap.put(permission.getName(), permission);
        } else if (privilegeType != null) {
            // Check for privilege was already granted for this object
            boolean hasPriv = permission.getPermission(privilegeType) != PostgrePrivilege.NONE;
            if (grant != hasPriv && !grant) {
                permissionMap.remove(permission.getName());
            }
        }
        // Add command
        addChangeCommand(new PostgreCommandGrantPrivilege(databaseObject, grant, currentObject, permission, privilegeType == null ? null : new PostgrePrivilegeType[] { privilegeType }), new DBECommandReflector<PostgrePrivilegeOwner, PostgreCommandGrantPrivilege>() {

            @Override
            public void redoCommand(PostgreCommandGrantPrivilege cmd) {
            // if (!privTable.isDisposed() && curCatalog == selectedCatalog && curTable == selectedTable) {
            // privTable.checkPrivilege(privilege, isGrant);
            // }
            // updateLocalData(privilege, isGrant, curCatalog, curTable);
            }

            @Override
            public void undoCommand(PostgreCommandGrantPrivilege cmd) {
            // if (!privTable.isDisposed() && curCatalog == selectedCatalog && curTable == selectedTable) {
            // privTable.checkPrivilege(privilege, !isGrant);
            // }
            // updateLocalData(privilege, !isGrant, curCatalog, curTable);
            }
        });
    }
}
Also used : PostgreCommandGrantPrivilege(org.jkiss.dbeaver.ext.postgresql.edit.PostgreCommandGrantPrivilege) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject)

Example 80 with DBSObject

use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.

the class DataFilterRegistry method makeObjectId.

public static String makeObjectId(DBSObject object) {
    DBSObject[] path = DBUtils.getObjectPath(object, true);
    StringBuilder objName = new StringBuilder();
    for (DBSObject p : path) {
        if (objName.length() > 0)
            objName.append(OBJ_PATH_DELIMITER);
        objName.append(p.getName());
    }
    return objName.toString();
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject)

Aggregations

DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)374 DBException (org.jkiss.dbeaver.DBException)129 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)66 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)66 ArrayList (java.util.ArrayList)54 InvocationTargetException (java.lang.reflect.InvocationTargetException)52 ISelection (org.eclipse.jface.viewers.ISelection)46 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)46 AbstractObjectReference (org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference)44 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)38 GridData (org.eclipse.swt.layout.GridData)38 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)38 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)30 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)29 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)29 DBSObjectContainer (org.jkiss.dbeaver.model.struct.DBSObjectContainer)28 Composite (org.eclipse.swt.widgets.Composite)27 IEditorPart (org.eclipse.ui.IEditorPart)26 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)24 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)22