Search in sources :

Example 1 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class ConnectionPageSettings method getSubPages.

@Nullable
@Override
public IDialogPage[] getSubPages() {
    if (subPages != null) {
        return subPages;
    }
    if (this.connectionEditor == null) {
        this.connectionEditor = viewDescriptor.createView(IDataSourceConnectionEditor.class);
        this.connectionEditor.setSite(this);
    }
    if (connectionEditor instanceof ICompositeDialogPage) {
        subPages = ((ICompositeDialogPage) connectionEditor).getSubPages();
        if (!ArrayUtils.isEmpty(subPages)) {
            for (IDialogPage page : subPages) {
                if (page instanceof IDataSourceConnectionEditor) {
                    ((IDataSourceConnectionEditor) page).setSite(this);
                }
            }
        }
        if (extraPages != null) {
            subPages = ArrayUtils.concatArrays(subPages, extraPages);
        }
        return subPages;
    } else {
        return extraPages;
    }
}
Also used : IDialogPage(org.eclipse.jface.dialogs.IDialogPage) Nullable(org.jkiss.code.Nullable)

Example 2 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class ExasolDataSource method getErrorPosition.

@Nullable
@Override
public ErrorPosition[] getErrorPosition(@NotNull DBRProgressMonitor monitor, @NotNull DBCExecutionContext context, @NotNull String query, @NotNull Throwable error) {
    while (error instanceof DBException) {
        if (error.getCause() == null) {
            return null;
        }
        error = error.getCause();
    }
    String message = error.getMessage();
    if (!CommonUtils.isEmpty(message)) {
        Matcher matcher = ERROR_POSITION_PATTERN.matcher(message);
        List<ErrorPosition> positions = new ArrayList<>();
        while (matcher.find()) {
            DBPErrorAssistant.ErrorPosition pos = new DBPErrorAssistant.ErrorPosition();
            pos.info = matcher.group(1);
            pos.line = Integer.parseInt(matcher.group(2)) - 1;
            pos.position = Integer.parseInt(matcher.group(3)) - 1;
            positions.add(pos);
        }
        if (!positions.isEmpty()) {
            return positions.toArray(new ErrorPosition[positions.size()]);
        }
    }
    return null;
}
Also used : DBException(org.jkiss.dbeaver.DBException) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) DBPErrorAssistant(org.jkiss.dbeaver.model.DBPErrorAssistant) Nullable(org.jkiss.code.Nullable)

Example 3 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class SQLSemanticProcessor method getConstraintTable.

/**
     * Extract alias (or source table name) for specified constraint from SQL select.
     * Searches in FROM and JOIN
     */
@Nullable
public static Table getConstraintTable(PlainSelect select, DBDAttributeConstraint constraint) {
    String constrTable;
    DBSAttributeBase ca = constraint.getAttribute();
    if (ca instanceof DBDAttributeBinding) {
        constrTable = ((DBDAttributeBinding) ca).getMetaAttribute().getEntityName();
    } else if (ca instanceof DBSEntityAttribute) {
        constrTable = ((DBSEntityAttribute) ca).getParentObject().getName();
    } else {
        return null;
    }
    if (constrTable == null) {
        return null;
    }
    FromItem fromItem = select.getFromItem();
    Table table = findTableInFrom(fromItem, constrTable);
    if (table == null) {
        // Maybe it is a join
        if (!CommonUtils.isEmpty(select.getJoins())) {
            for (Join join : select.getJoins()) {
                table = findTableInFrom(join.getRightItem(), constrTable);
                if (table != null) {
                    break;
                }
            }
        }
    }
    return table;
}
Also used : Table(net.sf.jsqlparser.schema.Table) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) DBSAttributeBase(org.jkiss.dbeaver.model.struct.DBSAttributeBase) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) Nullable(org.jkiss.code.Nullable)

Example 4 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class SQLUtils method getConstraintCondition.

@Nullable
public static String getConstraintCondition(@NotNull DBPDataSource dataSource, @NotNull DBDAttributeConstraint constraint, boolean inlineCriteria) {
    String criteria = constraint.getCriteria();
    if (!CommonUtils.isEmpty(criteria)) {
        final char firstChar = criteria.trim().charAt(0);
        if (!Character.isLetter(firstChar) && firstChar != '=' && firstChar != '>' && firstChar != '<' && firstChar != '!') {
            return '=' + criteria;
        } else {
            return criteria;
        }
    } else if (constraint.getOperator() != null) {
        DBCLogicalOperator operator = constraint.getOperator();
        StringBuilder conString = new StringBuilder();
        Object value = constraint.getValue();
        if (DBUtils.isNullValue(value)) {
            if (operator.getArgumentCount() == 0) {
                return operator.getStringValue();
            }
            conString.append("IS ");
            if (constraint.isReverseOperator()) {
                conString.append("NOT ");
            }
            conString.append("NULL");
            return conString.toString();
        }
        if (constraint.isReverseOperator()) {
            conString.append("NOT ");
        }
        if (operator.getArgumentCount() > 0) {
            conString.append(operator.getStringValue());
            for (int i = 0; i < operator.getArgumentCount(); i++) {
                if (i > 0) {
                    conString.append(" AND");
                }
                if (inlineCriteria) {
                    conString.append(' ').append(convertValueToSQL(dataSource, constraint.getAttribute(), value));
                } else {
                    conString.append(" ?");
                }
            }
        } else if (operator.getArgumentCount() < 0) {
            // Multiple arguments
            int valueCount = Array.getLength(value);
            boolean hasNull = false, hasNotNull = false;
            for (int i = 0; i < valueCount; i++) {
                final boolean isNull = DBUtils.isNullValue(Array.get(value, i));
                if (isNull && !hasNull) {
                    hasNull = true;
                }
                if (!isNull && !hasNotNull) {
                    hasNotNull = true;
                }
            }
            if (!hasNotNull) {
                return "IS NULL";
            }
            if (hasNull) {
                conString.append("IS NULL OR ").append(DBUtils.getObjectFullName(dataSource, constraint.getAttribute(), DBPEvaluationContext.DML)).append(" ");
            }
            conString.append(operator.getStringValue());
            conString.append(" (");
            if (!value.getClass().isArray()) {
                value = new Object[] { value };
            }
            boolean hasValue = false;
            for (int i = 0; i < valueCount; i++) {
                Object itemValue = Array.get(value, i);
                if (DBUtils.isNullValue(itemValue)) {
                    continue;
                }
                if (hasValue) {
                    conString.append(",");
                }
                hasValue = true;
                if (inlineCriteria) {
                    conString.append(convertValueToSQL(dataSource, constraint.getAttribute(), itemValue));
                } else {
                    conString.append("?");
                }
            }
            conString.append(")");
        }
        return conString.toString();
    } else {
        return null;
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) DBCLogicalOperator(org.jkiss.dbeaver.model.exec.DBCLogicalOperator) Nullable(org.jkiss.code.Nullable)

Example 5 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class DBNModel method getParentNode.

@Nullable
public DBNDatabaseNode getParentNode(DBSObject object) {
    DBNDatabaseNode node = getNodeByObject(object);
    if (node != null) {
        if (node.getParentNode() instanceof DBNDatabaseNode) {
            return (DBNDatabaseNode) node.getParentNode();
        } else {
            log.error("Object's " + object.getName() + "' parent node is not a database node: " + node.getParentNode());
            return null;
        }
    }
    DBSObject[] path = DBUtils.getObjectPath(object, false);
    for (int i = 0; i < path.length; i++) {
        DBSObject item = path[i];
        node = getNodeByObject(item);
        if (node == null) {
            // Parent node read
            return null;
        }
        DBNDatabaseNode[] children = node.getChildNodes();
        if (ArrayUtils.isEmpty(children)) {
            // Parent node is not read
            return null;
        }
        if (item == object.getParentObject()) {
            // Try to find parent node withing children
            for (DBNDatabaseNode child : children) {
                if (child instanceof DBNDatabaseFolder) {
                    Class<?> itemsClass = ((DBNDatabaseFolder) child).getChildrenClass();
                    if (itemsClass != null && itemsClass.isAssignableFrom(object.getClass())) {
                        return child;
                    }
                }
            }
        }
    }
    // Not found
    return null;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) Nullable(org.jkiss.code.Nullable)

Aggregations

Nullable (org.jkiss.code.Nullable)49 DBException (org.jkiss.dbeaver.DBException)6 Tree (org.eclipse.swt.widgets.Tree)5 TreeColumn (org.eclipse.swt.widgets.TreeColumn)5 TreeItem (org.eclipse.swt.widgets.TreeItem)5 NotNull (org.jkiss.code.NotNull)5 SQLException (java.sql.SQLException)4 Matcher (java.util.regex.Matcher)4 SQLScriptStatusDialog (org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog)4 DB2TableColumn (org.jkiss.dbeaver.ext.db2.model.DB2TableColumn)3 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)3 DBCResultSet (org.jkiss.dbeaver.model.exec.DBCResultSet)3 DBCStatement (org.jkiss.dbeaver.model.exec.DBCStatement)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 IProject (org.eclipse.core.resources.IProject)2 IStatus (org.eclipse.core.runtime.IStatus)2 IFindReplaceTarget (org.eclipse.jface.text.IFindReplaceTarget)2 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)2 Font (org.eclipse.swt.graphics.Font)2