Search in sources :

Example 6 with DBSProcedure

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

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)

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