Search in sources :

Example 36 with Condition

use of com.revolsys.record.query.Condition in project com.revolsys.open by revolsys.

the class RecordStoreLayer method getRecordCountChangeModified.

/**
 * Get the count of the modified records where the original record did not match the filter but
 * the modified record does.
 * @param query
 * @return
 */
protected int getRecordCountChangeModified(final Query query) {
    final Condition filter = query.getWhereCondition();
    if (filter.isEmpty()) {
        return 0;
    } else {
        int count = 0;
        for (final LayerRecord record : getRecordsModified()) {
            final Record originalRecord = record.getOriginalRecord();
            final boolean modifiedMatches = filter.test(record);
            final boolean originalMatches = filter.test(originalRecord);
            if (modifiedMatches) {
                if (!originalMatches) {
                    count++;
                }
            } else {
                if (originalMatches) {
                    count--;
                }
            }
        }
        return count;
    }
}
Also used : Condition(com.revolsys.record.query.Condition) Record(com.revolsys.record.Record)

Example 37 with Condition

use of com.revolsys.record.query.Condition in project com.revolsys.open by revolsys.

the class ModeAbstractCached method forEachRecord.

@Override
public void forEachRecord(final Query query, final Consumer<? super LayerRecord> action) {
    final Condition filter = query.getWhereCondition();
    final Map<? extends CharSequence, Boolean> orderBy = query.getOrderBy();
    final AbstractRecordLayer layer = getLayer();
    final Iterable<LayerRecord> records = new ListByIndexIterator<>(this.records);
    layer.forEachRecord(records, filter, orderBy, action);
}
Also used : Condition(com.revolsys.record.query.Condition) ListByIndexIterator(com.revolsys.collection.list.ListByIndexIterator) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord)

Example 38 with Condition

use of com.revolsys.record.query.Condition in project com.revolsys.open by revolsys.

the class ModeAllPaged method recordUpdated.

@Override
protected void recordUpdated(final LayerRecord record) {
    Invoke.later(() -> {
        final Condition filter = getFilter();
        final AbstractRecordLayer layer = getLayer();
        if (layer.isNew(record)) {
            if (filter.test(record)) {
                addCachedRecord(record);
            } else {
                removeCachedRecord(record);
            }
        } else if (!filter.isEmpty()) {
            if (layer.isModified(record)) {
                if (filterTestModified(filter, record)) {
                    addCachedRecord(record);
                } else {
                    removeCachedRecord(record);
                }
            }
        }
    });
}
Also used : Condition(com.revolsys.record.query.Condition) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer)

Example 39 with Condition

use of com.revolsys.record.query.Condition in project com.revolsys.open by revolsys.

the class QueryWhereConditionField method save.

@Override
public void save() {
    super.save();
    final Condition condition = getFieldValue();
    this.listener.propertyChange(new PropertyChangeEvent(this, "filter", this.originalFilter, condition));
}
Also used : Condition(com.revolsys.record.query.Condition) PropertyChangeEvent(java.beans.PropertyChangeEvent)

Example 40 with Condition

use of com.revolsys.record.query.Condition in project com.revolsys.open by revolsys.

the class QueryWhereConditionField method verifyCondition.

public void verifyCondition() {
    this.validating = true;
    this.valid = true;
    this.statusLabel.setText("");
    try {
        final String whereClause = this.whereTextField.getText();
        if (Property.hasValue(whereClause)) {
            final String sql = "SELECT * FROM X WHERE " + "\n" + whereClause;
            try {
                final StatementNode statement = new SQLParser().parseStatement(sql);
                if (statement instanceof CursorNode) {
                    final CursorNode selectStatement = (CursorNode) statement;
                    final ResultSetNode resultSetNode = selectStatement.getResultSetNode();
                    if (resultSetNode instanceof SelectNode) {
                        final SelectNode selectNode = (SelectNode) resultSetNode;
                        final ValueNode where = selectNode.getWhereClause();
                        final QueryValue queryValue = toQueryValue(where);
                        if (queryValue instanceof Condition) {
                            final Condition condition = (Condition) queryValue;
                            if (this.valid) {
                                setFieldValue(condition);
                                this.statusLabel.setForeground(WebColors.DarkGreen);
                                this.statusLabel.setText("Valid");
                            }
                        }
                    }
                }
            } catch (final SQLParserException e) {
                final int offset = e.getErrorPosition();
                setInvalidMessage(offset - this.sqlPrefix.length(), "Error parsing SQL: " + e.getMessage());
            } catch (final StandardException e) {
                Logs.error(this, "Error parsing SQL: " + whereClause, e);
            }
        } else {
            setFieldValue(Condition.ALL);
            this.statusLabel.setForeground(WebColors.DarkGreen);
            this.statusLabel.setText("Valid");
        }
    } finally {
        if (!this.valid) {
            setFieldValue(null);
        }
        this.validating = false;
    }
}
Also used : Condition(com.revolsys.record.query.Condition) StandardException(com.akiban.sql.StandardException) SQLParser(com.akiban.sql.parser.SQLParser) SelectNode(com.akiban.sql.parser.SelectNode) ValueNode(com.akiban.sql.parser.ValueNode) SQLParserException(com.akiban.sql.parser.SQLParserException) StatementNode(com.akiban.sql.parser.StatementNode) QueryValue(com.revolsys.record.query.QueryValue) CursorNode(com.akiban.sql.parser.CursorNode) ResultSetNode(com.akiban.sql.parser.ResultSetNode)

Aggregations

Condition (com.revolsys.record.query.Condition)40 BinaryCondition (com.revolsys.record.query.BinaryCondition)7 AbstractRecordLayer (com.revolsys.swing.map.layer.record.AbstractRecordLayer)6 Record (com.revolsys.record.Record)5 Query (com.revolsys.record.query.Query)5 RightUnaryCondition (com.revolsys.record.query.RightUnaryCondition)5 RecordDefinition (com.revolsys.record.schema.RecordDefinition)5 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)5 ValueNode (com.akiban.sql.parser.ValueNode)2 ListByIndexIterator (com.revolsys.collection.list.ListByIndexIterator)2 AbstractMultiCondition (com.revolsys.record.query.AbstractMultiCondition)2 QueryWhereConditionField (com.revolsys.swing.field.QueryWhereConditionField)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 StandardException (com.akiban.sql.StandardException)1 BetweenOperatorNode (com.akiban.sql.parser.BetweenOperatorNode)1 BinaryArithmeticOperatorNode (com.akiban.sql.parser.BinaryArithmeticOperatorNode)1 BinaryLogicalOperatorNode (com.akiban.sql.parser.BinaryLogicalOperatorNode)1 BinaryOperatorNode (com.akiban.sql.parser.BinaryOperatorNode)1 CastNode (com.akiban.sql.parser.CastNode)1