Search in sources :

Example 26 with DBDAttributeConstraint

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

the class SearchDataQuery method findRows.

private DBCStatistics findRows(@NotNull DBCSession session, @NotNull DBSDataContainer dataContainer, @NotNull TestDataReceiver dataReceiver) throws DBCException {
    DBSEntity entity;
    if (dataContainer instanceof DBSEntity) {
        entity = (DBSEntity) dataContainer;
    } else {
        log.warn("Data container " + dataContainer + " isn't entity");
        return null;
    }
    try {
        List<DBDAttributeConstraint> constraints = new ArrayList<>();
        for (DBSEntityAttribute attribute : CommonUtils.safeCollection(entity.getAttributes(session.getProgressMonitor()))) {
            if (params.fastSearch) {
                if (DBUtils.findAttributeIndex(session.getProgressMonitor(), attribute) == null) {
                    continue;
                }
            }
            if (DBUtils.isPseudoAttribute(attribute) || DBUtils.isHiddenObject(attribute)) {
                continue;
            }
            DBCLogicalOperator[] supportedOperators = DBUtils.getAttributeOperators(attribute);
            DBCLogicalOperator operator;
            Object value;
            switch(attribute.getDataKind()) {
                case BOOLEAN:
                    continue;
                case NUMERIC:
                    if (!params.searchNumbers) {
                        continue;
                    }
                    if (!ArrayUtils.contains(supportedOperators, DBCLogicalOperator.EQUALS)) {
                        continue;
                    }
                    operator = DBCLogicalOperator.EQUALS;
                    try {
                        value = Integer.valueOf(params.searchString);
                    } catch (NumberFormatException e) {
                        try {
                            value = Long.valueOf(params.searchString);
                        } catch (NumberFormatException e1) {
                            try {
                                value = Double.valueOf(params.searchString);
                            } catch (NumberFormatException e2) {
                                try {
                                    value = new BigDecimal(params.searchString);
                                } catch (Exception e3) {
                                    // Not a number
                                    continue;
                                }
                            }
                        }
                    }
                    break;
                case CONTENT:
                case BINARY:
                    if (!params.searchLOBs) {
                        continue;
                    }
                case STRING:
                    if (!params.isCaseSensitive() && ArrayUtils.contains(supportedOperators, DBCLogicalOperator.ILIKE)) {
                        operator = DBCLogicalOperator.ILIKE;
                        value = "%" + params.searchString + "%";
                    } else if (ArrayUtils.contains(supportedOperators, DBCLogicalOperator.LIKE)) {
                        operator = DBCLogicalOperator.LIKE;
                        value = "%" + params.searchString + "%";
                    } else if (ArrayUtils.contains(supportedOperators, DBCLogicalOperator.EQUALS)) {
                        operator = DBCLogicalOperator.EQUALS;
                        value = params.searchString;
                    } else {
                        continue;
                    }
                    break;
                default:
                    {
                        // On success search by exact match
                        if (!ArrayUtils.contains(supportedOperators, DBCLogicalOperator.EQUALS)) {
                            continue;
                        }
                        String typeName = attribute.getTypeName();
                        if (typeName.equals(DBConstants.TYPE_NAME_UUID) || typeName.equals(DBConstants.TYPE_NAME_UUID2)) {
                            try {
                                UUID uuid = UUID.fromString(params.searchString);
                                operator = DBCLogicalOperator.EQUALS;
                                value = uuid.toString();
                            } catch (Exception e) {
                                // No a UUID
                                continue;
                            }
                        } else {
                            continue;
                        }
                    }
            }
            DBDAttributeConstraint constraint = new DBDAttributeConstraint(attribute, constraints.size());
            constraint.setOperator(operator);
            constraint.setValue(value);
            constraint.setVisible(true);
            constraints.add(constraint);
        }
        if (constraints.isEmpty()) {
            return null;
        }
        dataReceiver.filter = new DBDDataFilter(constraints);
        dataReceiver.filter.setAnyConstraint(true);
        DBCExecutionSource searchSource = new AbstractExecutionSource(dataContainer, session.getExecutionContext(), this);
        return dataContainer.readData(searchSource, session, dataReceiver, dataReceiver.filter, -1, -1, 0, 0);
    } catch (DBException e) {
        throw new DBCException("Error finding rows", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint) BigDecimal(java.math.BigDecimal) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) DBException(org.jkiss.dbeaver.DBException) DBDDataFilter(org.jkiss.dbeaver.model.data.DBDDataFilter) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) AbstractExecutionSource(org.jkiss.dbeaver.model.impl.AbstractExecutionSource) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity)

Example 27 with DBDAttributeConstraint

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

the class FilterSettingsDialog method okPressed.

@Override
protected void okPressed() {
    treeEditor.okPressed();
    boolean hasVisibleColumns = false;
    for (DBDAttributeConstraint constraint : dataFilter.getConstraints()) {
        // constraint.setVisualPosition(this.constraints.indexOf(constraint));
        if (constraint.isVisible()) {
            hasVisibleColumns = true;
        }
    }
    if (!hasVisibleColumns) {
        UIUtils.showMessageBox(getShell(), "Bad filter", "You have to set at least one column visible", SWT.ICON_WARNING);
        return;
    }
    if (!CommonUtils.isEmpty(orderText.getText())) {
        dataFilter.setOrder(orderText.getText());
    } else {
        dataFilter.setOrder(null);
    }
    if (!CommonUtils.isEmpty(whereText.getText())) {
        dataFilter.setWhere(whereText.getText());
    } else {
        dataFilter.setWhere(null);
    }
    boolean filtersChanged = true;
    if (dataFilter.equalFilters(resultSetViewer.getModel().getDataFilter(), true)) {
        // Only attribute visibility was changed
        filtersChanged = false;
    }
    resultSetViewer.setDataFilter(dataFilter, filtersChanged);
    super.okPressed();
}
Also used : DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint)

Example 28 with DBDAttributeConstraint

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

the class FilterSettingsDialog method swapColumns.

private void swapColumns(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)

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