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;
}
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;
}
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");
}
}
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);
}
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);
}
Aggregations