Search in sources :

Example 1 with PostgreProcedure

use of org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure in project dbeaver by dbeaver.

the class PostgreSqlDebugCore method createConfiguration.

public static ILaunchConfigurationWorkingCopy createConfiguration(DBSObject launchable) throws CoreException {
    boolean isInstance = launchable instanceof PostgreProcedure;
    if (!isInstance) {
        throw DebugCore.abort(PostgreDebugCoreMessages.PostgreSqlDebugCore_e_procedure_required);
    }
    PostgreProcedure procedure = (PostgreProcedure) launchable;
    PostgreDataSource dataSource = procedure.getDataSource();
    DBPDataSourceContainer dataSourceContainer = dataSource.getContainer();
    PostgreDatabase database = procedure.getDatabase();
    PostgreSchema schema = procedure.getContainer();
    String databaseName = database.getName();
    String schemaName = schema.getName();
    String procedureName = procedure.getName();
    Object[] bindings = new Object[] { dataSourceContainer.getName(), databaseName, procedureName, schemaName };
    String name = NLS.bind(PostgreDebugCoreMessages.PostgreSqlDebugCore_launch_configuration_name, bindings);
    // Let's use metadata area for storage
    IContainer container = null;
    ILaunchConfigurationWorkingCopy workingCopy = DebugCore.createConfiguration(container, CONFIGURATION_TYPE, name);
    workingCopy.setAttribute(DebugCore.ATTR_DRIVER_ID, dataSourceContainer.getDriver().getId());
    workingCopy.setAttribute(DebugCore.ATTR_DATASOURCE_ID, dataSourceContainer.getId());
    workingCopy.setAttribute(DebugCore.ATTR_DATABASE_NAME, databaseName);
    workingCopy.setAttribute(DebugCore.ATTR_SCHEMA_NAME, schemaName);
    workingCopy.setAttribute(DebugCore.ATTR_PROCEDURE_OID, String.valueOf(procedure.getObjectId()));
    workingCopy.setAttribute(DebugCore.ATTR_PROCEDURE_NAME, procedureName);
    workingCopy.setAttribute(DebugCore.ATTR_ATTACH_PROCESS, DebugCore.ATTR_ATTACH_PROCESS_DEFAULT);
    workingCopy.setAttribute(DebugCore.ATTR_ATTACH_KIND, DebugCore.ATTR_ATTACH_KIND_DEFAULT);
    workingCopy.setAttribute(DebugCore.ATTR_SCRIPT_EXECUTE, DebugCore.ATTR_SCRIPT_EXECUTE_DEFAULT);
    workingCopy.setAttribute(DebugCore.ATTR_SCRIPT_TEXT, DebugCore.composeScriptText(procedure));
    final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
    DBNDatabaseNode node = navigatorModel.getNodeByObject(procedure);
    workingCopy.setAttribute(DebugCore.ATTR_NODE_PATH, node.getNodeItemPath());
    return workingCopy;
}
Also used : PostgreDataSource(org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource) PostgreDatabase(org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) PostgreProcedure(org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IContainer(org.eclipse.core.resources.IContainer) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 2 with PostgreProcedure

use of org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure in project dbeaver by dbeaver.

the class PostgreResolver method resolveObject.

@Override
public DBSObject resolveObject(Map<String, Object> context, Object identifier, DBRProgressMonitor monitor) throws DBException {
    Long oid = null;
    final String errorIdentifier = String.format("Unknown procedure identifier %s", identifier);
    if (identifier instanceof Number) {
        Number number = (Number) identifier;
        oid = number.longValue();
    } else if (identifier instanceof String) {
        String string = (String) identifier;
        try {
            oid = Long.parseLong(string);
        } catch (NumberFormatException e) {
            throw new DBException(errorIdentifier, e, dataSource);
        }
    }
    if (oid == null) {
        throw new DBException(errorIdentifier);
    }
    String databaseName = String.valueOf(context.get(DBGController.DATABASE_NAME));
    PostgreDatabase database = dataSource.getDatabase(databaseName);
    if (database == null) {
        return null;
    }
    String schemaName = String.valueOf(context.get(DBGController.SCHEMA_NAME));
    PostgreSchema schema = null;
    schema = database.getSchema(monitor, schemaName);
    if (schema == null) {
        return null;
    }
    PostgreProcedure procedure = schema.getProcedure(monitor, oid);
    return procedure;
}
Also used : DBException(org.jkiss.dbeaver.DBException) PostgreDatabase(org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase) PostgreProcedure(org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema)

Example 3 with PostgreProcedure

use of org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure in project dbeaver by dbeaver.

the class PostgreDebugSession method attach.

/**
 * This method attach debug session to debug object (procedure) and wait
 * forever while target or any (depend on targetPID) session will run target
 * procedure
 */
public void attach(DBRProgressMonitor monitor, Map<String, Object> configuration) throws DBException {
    if (!checkDebugPlagin(monitor)) {
        throw new DBGException("PostgreSQL debug plugin is not installed on the server.\n" + "Refer to this WIKI article for installation instructions:\n" + "https://github.com/dbeaver/dbeaver/wiki/PGDebugger#installation");
    }
    log.debug("Attaching...");
    functionOid = CommonUtils.toInt(configuration.get(PostgreDebugConstants.ATTR_FUNCTION_OID));
    log.debug(String.format("Function OID %d", functionOid));
    boolean global = isGlobalSession(configuration);
    if (global) {
        int processId = CommonUtils.toInt(configuration.get(PostgreDebugConstants.ATTR_ATTACH_PROCESS));
        attachKind = PostgreDebugAttachKind.GLOBAL;
        attachGlobal(monitor, functionOid, processId);
        log.debug("Global attached");
    } else {
        attachKind = PostgreDebugAttachKind.LOCAL;
        PostgreProcedure function = PostgreSqlDebugCore.resolveFunction(monitor, controllerConnection.getDataSource().getContainer(), configuration);
        List<String> parameterValues = (List<String>) configuration.get(PostgreDebugConstants.ATTR_FUNCTION_PARAMETERS);
        attachLocal(monitor, function, parameterValues);
        log.debug("Local attached");
    }
}
Also used : PostgreProcedure(org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with PostgreProcedure

use of org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure in project dbeaver by dbeaver.

the class PostgreDebugPanelFunction method createFunctionGroup.

private void createFunctionGroup(Composite parent) {
    Group functionGroup = UIUtils.createControlGroup(parent, "Function", 2, GridData.VERTICAL_ALIGN_BEGINNING, SWT.DEFAULT);
    UIUtils.createControlLabel(functionGroup, "Function");
    functionCombo = new CSmartSelector<PostgreProcedure>(functionGroup, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY, new LabelProvider() {

        @Override
        public Image getImage(Object element) {
            return DBeaverIcons.getImage(DBIcon.TREE_PROCEDURE);
        }

        @Override
        public String getText(Object element) {
            if (element == null) {
                return "N/A";
            }
            return ((PostgreProcedure) element).getFullQualifiedSignature();
        }
    }) {

        @Override
        protected void dropDown(boolean drop) {
            if (drop) {
                DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
                DBNDatabaseNode dsNode = navigatorModel.getNodeByObject(container.getDataSource());
                if (dsNode != null) {
                    DBNNode curNode = selectedFunction == null ? null : navigatorModel.getNodeByObject(selectedFunction);
                    DBNNode node = DBWorkbench.getPlatformUI().selectObject(parent.getShell(), "Select function to debug", dsNode, curNode, new Class[] { DBSInstance.class, DBSObjectContainer.class, PostgreProcedure.class }, new Class[] { PostgreProcedure.class }, null);
                    if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof PostgreProcedure) {
                        functionCombo.removeAll();
                        selectedFunction = (PostgreProcedure) ((DBNDatabaseNode) node).getObject();
                        functionCombo.addItem(selectedFunction);
                        functionCombo.select(selectedFunction);
                        updateParametersTable();
                        container.updateDialogState();
                    }
                    parametersTable.setEnabled(selectedFunction != null);
                }
            }
        }
    };
    functionCombo.addItem(null);
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.widthHint = UIUtils.getFontHeight(functionCombo) * 40 + 10;
    functionCombo.setLayoutData(gd);
    processIdText = UIUtils.createLabelText(functionGroup, "Process ID", "", SWT.BORDER, new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.widthHint = UIUtils.getFontHeight(processIdText) * 10 + 10;
    processIdText.setLayoutData(gd);
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBSInstance(org.jkiss.dbeaver.model.struct.DBSInstance) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) PostgreProcedure(org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) GridData(org.eclipse.swt.layout.GridData) LabelProvider(org.eclipse.jface.viewers.LabelProvider) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 5 with PostgreProcedure

use of org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure in project dbeaver by serge-rider.

the class PostgreDebugPanelFunction method createFunctionGroup.

private void createFunctionGroup(Composite parent) {
    Group functionGroup = UIUtils.createControlGroup(parent, "Function", 2, GridData.VERTICAL_ALIGN_BEGINNING, SWT.DEFAULT);
    UIUtils.createControlLabel(functionGroup, "Function");
    functionCombo = new CSmartSelector<PostgreProcedure>(functionGroup, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY, new LabelProvider() {

        @Override
        public Image getImage(Object element) {
            return DBeaverIcons.getImage(DBIcon.TREE_PROCEDURE);
        }

        @Override
        public String getText(Object element) {
            if (element == null) {
                return "N/A";
            }
            return ((PostgreProcedure) element).getFullQualifiedSignature();
        }
    }) {

        @Override
        protected void dropDown(boolean drop) {
            if (drop) {
                DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
                DBNDatabaseNode dsNode = navigatorModel.getNodeByObject(container.getDataSource());
                if (dsNode != null) {
                    DBNNode curNode = selectedFunction == null ? null : navigatorModel.getNodeByObject(selectedFunction);
                    DBNNode node = DBWorkbench.getPlatformUI().selectObject(parent.getShell(), "Select function to debug", dsNode, curNode, new Class[] { DBSInstance.class, DBSObjectContainer.class, PostgreProcedure.class }, new Class[] { PostgreProcedure.class }, null);
                    if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof PostgreProcedure) {
                        functionCombo.removeAll();
                        selectedFunction = (PostgreProcedure) ((DBNDatabaseNode) node).getObject();
                        functionCombo.addItem(selectedFunction);
                        functionCombo.select(selectedFunction);
                        updateParametersTable();
                        container.updateDialogState();
                    }
                    parametersTable.setEnabled(selectedFunction != null);
                }
            }
        }
    };
    functionCombo.addItem(null);
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.widthHint = UIUtils.getFontHeight(functionCombo) * 40 + 10;
    functionCombo.setLayoutData(gd);
    processIdText = UIUtils.createLabelText(functionGroup, "Process ID", "", SWT.BORDER, new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.widthHint = UIUtils.getFontHeight(processIdText) * 10 + 10;
    processIdText.setLayoutData(gd);
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBSInstance(org.jkiss.dbeaver.model.struct.DBSInstance) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) PostgreProcedure(org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) GridData(org.eclipse.swt.layout.GridData) LabelProvider(org.eclipse.jface.viewers.LabelProvider) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Aggregations

PostgreProcedure (org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure)11 PostgreDatabase (org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase)5 PostgreSchema (org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema)5 DBException (org.jkiss.dbeaver.DBException)3 PostgreDataSource (org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource)3 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)3 DBNModel (org.jkiss.dbeaver.model.navigator.DBNModel)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 LabelProvider (org.eclipse.jface.viewers.LabelProvider)2 GridData (org.eclipse.swt.layout.GridData)2 SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)2 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)2 DBSInstance (org.jkiss.dbeaver.model.struct.DBSInstance)2 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)2 DBSObjectContainer (org.jkiss.dbeaver.model.struct.DBSObjectContainer)2 HashMap (java.util.HashMap)1 IContainer (org.eclipse.core.resources.IContainer)1 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)1 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)1