use of com.revolsys.record.query.QueryValue 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