Search in sources :

Example 1 with DBSProcedure

use of org.jkiss.dbeaver.model.struct.rdb.DBSProcedure in project dbeaver by dbeaver.

the class GenerateSQLContributor method CALL_GENERATOR.

@NotNull
public static SQLGenerator<DBSProcedure> CALL_GENERATOR(final List<DBSProcedure> entities) {
    return new ProcedureAnalysisRunner(entities) {

        @Override
        protected void generateSQL(DBRProgressMonitor monitor, StringBuilder sql, DBSProcedure proc) throws DBException {
            Collection<? extends DBSProcedureParameter> parameters = proc.getParameters(monitor);
            DBPDataSource dataSource = proc.getDataSource();
            if (dataSource instanceof SQLDataSource) {
                SQLDataSource sqlDataSource = (SQLDataSource) dataSource;
                SQLDialect sqlDialect = sqlDataSource.getSQLDialect();
                sqlDialect.generateStoredProcedureCall(sql, proc, parameters);
            }
        }
    };
}
Also used : SQLDialect(org.jkiss.dbeaver.model.sql.SQLDialect) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) SQLDataSource(org.jkiss.dbeaver.model.sql.SQLDataSource) DBSProcedure(org.jkiss.dbeaver.model.struct.rdb.DBSProcedure) NotNull(org.jkiss.code.NotNull)

Example 2 with DBSProcedure

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

the class SQLEditorHandlerRunProcedureConsole method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    SQLNavigatorContext navContext = null;
    String procName = null;
    ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
    List<DBSObject> selectedObjects = NavigatorUtils.getSelectedObjects(currentSelection);
    List<DBSProcedure> entities = new ArrayList<>();
    for (DBSObject object : selectedObjects) {
        if (object instanceof DBSProcedure) {
            DBSProcedure proc = (DBSProcedure) object;
            procName = proc.getName();
            entities.add(proc);
            if (navContext == null) {
                navContext = new SQLNavigatorContext(object);
            }
        }
    }
    if (navContext == null || navContext.getDataSourceContainer() == null) {
        log.debug("No active datasource");
        return null;
    }
    DBRRunnableWithResult<String> generator = SQLGeneratorContributor.CALL_GENERATOR(entities);
    String title = "Stored procedures call";
    if (entities.size() == 1 && !CommonUtils.isEmpty(procName)) {
        title = procName + " call";
    }
    try {
        openConsole(workbenchWindow, generator, navContext, title, false, currentSelection);
    } catch (Exception e) {
        DBWorkbench.getPlatformUI().showError("Open console", "Can open SQL editor", e);
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) DBSProcedure(org.jkiss.dbeaver.model.struct.rdb.DBSProcedure) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 3 with DBSProcedure

use of org.jkiss.dbeaver.model.struct.rdb.DBSProcedure in project dbeaver by dbeaver.

the class SQLEditorHandlerRunProcedureConsole method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    SQLNavigatorContext navContext = null;
    String procName = null;
    ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
    List<DBSObject> selectedObjects = NavigatorUtils.getSelectedObjects(currentSelection);
    List<DBSProcedure> entities = new ArrayList<>();
    for (DBSObject object : selectedObjects) {
        if (object instanceof DBSProcedure) {
            DBSProcedure proc = (DBSProcedure) object;
            procName = proc.getName();
            entities.add(proc);
            if (navContext == null) {
                navContext = new SQLNavigatorContext(object);
            }
        }
    }
    if (navContext == null || navContext.getDataSourceContainer() == null) {
        log.debug("No active datasource");
        return null;
    }
    DBRRunnableWithResult<String> generator = SQLGeneratorContributor.CALL_GENERATOR(entities);
    String title = "Stored procedures call";
    if (entities.size() == 1 && !CommonUtils.isEmpty(procName)) {
        title = procName + " call";
    }
    try {
        openConsole(workbenchWindow, generator, navContext, title, false, currentSelection);
    } catch (Exception e) {
        DBWorkbench.getPlatformUI().showError("Open console", "Can open SQL editor", e);
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) DBSProcedure(org.jkiss.dbeaver.model.struct.rdb.DBSProcedure) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 4 with DBSProcedure

use of org.jkiss.dbeaver.model.struct.rdb.DBSProcedure in project dbeaver by dbeaver.

the class SQLCompletionProposalBase method getExtraString.

public String getExtraString() {
    try {
        VoidProgressMonitor monitor = new VoidProgressMonitor();
        if (object instanceof DBSObjectReference) {
            if (DBSProcedure.class.isAssignableFrom(((DBSObjectReference) object).getObjectType().getTypeClass())) {
                object = ((DBSObjectReference) object).resolveObject(monitor);
            }
        }
        if (object instanceof DBSProcedure) {
            // Ad parameter marks
            boolean isExec = CommonUtils.toBoolean(params.get(PARAM_EXEC));
            Collection<? extends DBSProcedureParameter> parameters = ((DBSProcedure) object).getParameters(monitor);
            if (!CommonUtils.isEmpty(parameters)) {
                StringBuilder params = new StringBuilder();
                for (DBSProcedureParameter param : parameters) {
                    if (param.getParameterKind().isInput()) {
                        if (params.length() > 0)
                            params.append(", ");
                        if (isExec) {
                            params.append(":").append(param.getName());
                        } else {
                            params.append(param.getParameterType().getFullTypeName());
                        }
                    }
                }
                return "(" + params.toString() + ")";
            } else {
                return "()";
            }
        }
        return null;
    } catch (DBException e) {
        log.error("Error resolving procedure parameters", e);
        return null;
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSProcedureParameter(org.jkiss.dbeaver.model.struct.rdb.DBSProcedureParameter) DBSObjectReference(org.jkiss.dbeaver.model.struct.DBSObjectReference) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBSProcedure(org.jkiss.dbeaver.model.struct.rdb.DBSProcedure)

Example 5 with DBSProcedure

use of org.jkiss.dbeaver.model.struct.rdb.DBSProcedure in project dbeaver by dbeaver.

the class RunProcedureConsoleHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    DBPDataSourceContainer ds = null;
    String procName = null;
    List<DBSObject> selectedObjects = NavigatorUtils.getSelectedObjects(HandlerUtil.getCurrentSelection(event));
    List<DBSProcedure> entities = new ArrayList<>();
    for (DBSObject object : selectedObjects) {
        if (object instanceof DBSProcedure) {
            DBSProcedure proc = (DBSProcedure) object;
            procName = proc.getName();
            entities.add(proc);
            ds = object.getDataSource().getContainer();
        }
    }
    DBRRunnableWithResult<String> generator = GenerateSQLContributor.CALL_GENERATOR(entities);
    String title = "Stored procedures call";
    if (entities.size() == 1 && !CommonUtils.isEmpty(procName)) {
        title = procName + " call";
    }
    openConsole(workbenchWindow, generator, ds, title, false);
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ArrayList(java.util.ArrayList) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBSProcedure(org.jkiss.dbeaver.model.struct.rdb.DBSProcedure)

Aggregations

DBSProcedure (org.jkiss.dbeaver.model.struct.rdb.DBSProcedure)6 ArrayList (java.util.ArrayList)3 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)3 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)3 ExecutionException (org.eclipse.core.commands.ExecutionException)2 ISelection (org.eclipse.jface.viewers.ISelection)2 DBException (org.jkiss.dbeaver.DBException)2 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)2 DBSObjectReference (org.jkiss.dbeaver.model.struct.DBSObjectReference)2 DBSProcedureParameter (org.jkiss.dbeaver.model.struct.rdb.DBSProcedureParameter)2 NotNull (org.jkiss.code.NotNull)1 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)1 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)1 SQLDataSource (org.jkiss.dbeaver.model.sql.SQLDataSource)1 SQLDialect (org.jkiss.dbeaver.model.sql.SQLDialect)1