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;
}
}
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);
}
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);
}
}
}
});
}
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));
}
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;
}
}
Aggregations