Search in sources :

Example 1 with DBDAttributeConstraint

use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by serge-rider.

the class SQLSemanticProcessor method patchSelectQuery.

private static boolean patchSelectQuery(DBPDataSource dataSource, PlainSelect select, DBDDataFilter filter) throws JSQLParserException {
    // WHERE
    if (filter.hasConditions()) {
        for (DBDAttributeConstraint co : filter.getConstraints()) {
            if (co.hasCondition()) {
                Table table = getConstraintTable(select, co);
                if (table != null) {
                    if (table.getAlias() != null) {
                        co.setEntityAlias(table.getAlias().getName());
                    } else {
                        co.setEntityAlias(table.getName());
                    }
                } else {
                    co.setEntityAlias(null);
                }
            }
        }
        StringBuilder whereString = new StringBuilder();
        SQLUtils.appendConditionString(filter, dataSource, null, whereString, true);
        String condString = whereString.toString();
        addWhereToSelect(select, condString);
    }
    // ORDER
    if (filter.hasOrdering()) {
        List<OrderByElement> orderByElements = select.getOrderByElements();
        if (orderByElements == null) {
            orderByElements = new ArrayList<>();
            select.setOrderByElements(orderByElements);
        }
        for (DBDAttributeConstraint co : filter.getOrderConstraints()) {
            Expression orderExpr = getConstraintExpression(select, co);
            OrderByElement element = new OrderByElement();
            element.setExpression(orderExpr);
            if (co.isOrderDescending()) {
                element.setAsc(false);
                element.setAscDescPresent(true);
            }
            orderByElements.add(element);
        }
    }
    return true;
}
Also used : Table(net.sf.jsqlparser.schema.Table) DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint) Expression(net.sf.jsqlparser.expression.Expression) AndExpression(net.sf.jsqlparser.expression.operators.conditional.AndExpression)

Example 2 with DBDAttributeConstraint

use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by serge-rider.

the class FilterSettingsDialog method moveColumn.

private void moveColumn(int curIndex, int newIndex) {
    final DBDAttributeConstraint c1 = getBindingConstraint((DBDAttributeBinding) columnsViewer.getTree().getItem(curIndex).getData());
    final DBDAttributeConstraint c2 = getBindingConstraint((DBDAttributeBinding) columnsViewer.getTree().getItem(newIndex).getData());
    final int vp2 = c2.getVisualPosition();
    c2.setVisualPosition(c1.getVisualPosition());
    c1.setVisualPosition(vp2);
    refreshData();
    moveTopButton.setEnabled(newIndex > 0);
    moveUpButton.setEnabled(newIndex > 0);
    moveDownButton.setEnabled(newIndex < getItemsCount() - 1);
    moveBottomButton.setEnabled(newIndex < getItemsCount() - 1);
}
Also used : DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint) DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint)

Example 3 with DBDAttributeConstraint

use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by dbeaver.

the class SQLSemanticProcessor method patchSelectQuery.

private static boolean patchSelectQuery(DBPDataSource dataSource, PlainSelect select, DBDDataFilter filter) throws JSQLParserException {
    // WHERE
    if (filter.hasConditions()) {
        for (DBDAttributeConstraint co : filter.getConstraints()) {
            if (co.hasCondition()) {
                Table table = getConstraintTable(select, co);
                if (table != null) {
                    if (table.getAlias() != null) {
                        co.setEntityAlias(table.getAlias().getName());
                    } else {
                        co.setEntityAlias(table.getName());
                    }
                } else {
                    co.setEntityAlias(null);
                }
            }
        }
        StringBuilder whereString = new StringBuilder();
        SQLUtils.appendConditionString(filter, dataSource, null, whereString, true);
        String condString = whereString.toString();
        addWhereToSelect(select, condString);
    }
    // ORDER
    if (filter.hasOrdering()) {
        List<OrderByElement> orderByElements = select.getOrderByElements();
        if (orderByElements == null) {
            orderByElements = new ArrayList<>();
            select.setOrderByElements(orderByElements);
        }
        for (DBDAttributeConstraint co : filter.getOrderConstraints()) {
            Expression orderExpr = getConstraintExpression(dataSource, select, co);
            OrderByElement element = new OrderByElement();
            element.setExpression(orderExpr);
            if (co.isOrderDescending()) {
                element.setAsc(false);
                element.setAscDescPresent(true);
            }
            orderByElements.add(element);
        }
    }
    return true;
}
Also used : Table(net.sf.jsqlparser.schema.Table) DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint) AndExpression(net.sf.jsqlparser.expression.operators.conditional.AndExpression) Expression(net.sf.jsqlparser.expression.Expression)

Example 4 with DBDAttributeConstraint

use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by serge-rider.

the class SQLSemanticProcessor method patchSelectQuery.

private static boolean patchSelectQuery(DBRProgressMonitor monitor, DBPDataSource dataSource, PlainSelect select, DBDDataFilter filter) throws JSQLParserException, DBException {
    // WHERE
    if (filter.hasConditions()) {
        for (DBDAttributeConstraint co : filter.getConstraints()) {
            if (co.hasCondition()) {
                Table table = getConstraintTable(select, co);
                if (!isValidTableColumn(monitor, dataSource, table, co)) {
                    table = null;
                }
                if (table != null) {
                    if (table.getAlias() != null) {
                        co.setEntityAlias(table.getAlias().getName());
                    } else {
                        co.setEntityAlias(table.getName());
                    }
                } else {
                    co.setEntityAlias(null);
                }
            }
        }
        StringBuilder whereString = new StringBuilder();
        SQLUtils.appendConditionString(filter, dataSource, null, whereString, true);
        String condString = whereString.toString();
        addWhereToSelect(select, condString);
    }
    // ORDER
    if (filter.hasOrdering()) {
        List<OrderByElement> orderByElements = select.getOrderByElements();
        if (orderByElements == null) {
            orderByElements = new ArrayList<>();
            select.setOrderByElements(orderByElements);
        }
        for (DBDAttributeConstraint co : filter.getOrderConstraints()) {
            String columnName = co.getAttributeName();
            boolean forceNumeric = filter.hasNameDuplicates(columnName) || !SQLUtils.PATTERN_SIMPLE_NAME.matcher(columnName).matches();
            Expression orderExpr = getOrderConstraintExpression(monitor, dataSource, select, co, forceNumeric);
            OrderByElement element = new OrderByElement();
            element.setExpression(orderExpr);
            if (co.isOrderDescending()) {
                element.setAsc(false);
                element.setAscDescPresent(true);
            }
            orderByElements.add(element);
        }
    }
    return true;
}
Also used : Table(net.sf.jsqlparser.schema.Table) DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint) AndExpression(net.sf.jsqlparser.expression.operators.conditional.AndExpression) Expression(net.sf.jsqlparser.expression.Expression)

Example 5 with DBDAttributeConstraint

use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by serge-rider.

the class FilterSettingsDialog method moveColumns.

private void moveColumns(int curIndex, int newIndex) {
    if (curIndex == newIndex) {
        return;
    }
    final DBDAttributeConstraint curAttr = getBindingConstraint((DBDAttributeBinding) columnsViewer.getTree().getItem(curIndex).getData());
    // Update other constraints indexes
    for (DBDAttributeConstraint c : constraints) {
        if (newIndex < curIndex) {
            if (c.getVisualPosition() >= newIndex && c.getVisualPosition() < curIndex) {
                c.setVisualPosition(c.getVisualPosition() + 1);
            }
        } else {
            if (c.getVisualPosition() > curIndex && c.getVisualPosition() <= newIndex) {
                c.setVisualPosition(c.getVisualPosition() - 1);
            }
        }
    }
    curAttr.setVisualPosition(newIndex);
    refreshData();
    moveTopButton.setEnabled(newIndex > 0);
    moveUpButton.setEnabled(newIndex > 0);
    moveDownButton.setEnabled(newIndex < getItemsCount() - 1);
    moveBottomButton.setEnabled(newIndex < getItemsCount() - 1);
}
Also used : DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint)

Aggregations

DBDAttributeConstraint (org.jkiss.dbeaver.model.data.DBDAttributeConstraint)28 DBDDataFilter (org.jkiss.dbeaver.model.data.DBDDataFilter)13 DBException (org.jkiss.dbeaver.DBException)7 Expression (net.sf.jsqlparser.expression.Expression)4 AndExpression (net.sf.jsqlparser.expression.operators.conditional.AndExpression)4 Table (net.sf.jsqlparser.schema.Table)4 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)4 ArrayList (java.util.ArrayList)3 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)3 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 java.util (java.util)2 List (java.util.List)2 Pattern (java.util.regex.Pattern)2 ControlEnableState (org.eclipse.jface.dialogs.ControlEnableState)2 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)2 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)2 org.eclipse.jface.viewers (org.eclipse.jface.viewers)2 SWT (org.eclipse.swt.SWT)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2