Search in sources :

Example 16 with QueryValue

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

QueryValue (com.revolsys.record.query.QueryValue)16 Column (com.revolsys.record.query.Column)5 Value (com.revolsys.record.query.Value)5 ILike (com.revolsys.record.query.ILike)4 FieldDefinition (com.revolsys.record.schema.FieldDefinition)4 JdbcFieldDefinition (com.revolsys.jdbc.field.JdbcFieldDefinition)3 ArcSdeStGeometryFieldDefinition (com.revolsys.oracle.recordstore.esri.ArcSdeStGeometryFieldDefinition)3 OracleJdbcRowIdFieldDefinition (com.revolsys.oracle.recordstore.field.OracleJdbcRowIdFieldDefinition)3 OracleSdoGeometryJdbcFieldDefinition (com.revolsys.oracle.recordstore.field.OracleSdoGeometryJdbcFieldDefinition)3 BinaryCondition (com.revolsys.record.query.BinaryCondition)3 CollectionValue (com.revolsys.record.query.CollectionValue)3 EnvelopeIntersects (com.revolsys.record.query.functions.EnvelopeIntersects)3 ValueNode (com.akiban.sql.parser.ValueNode)2 BoundingBox (com.revolsys.geometry.model.BoundingBox)2 AbstractBinaryQueryValue (com.revolsys.record.query.AbstractBinaryQueryValue)2 AbstractMultiCondition (com.revolsys.record.query.AbstractMultiCondition)2 AbstractMultiQueryValue (com.revolsys.record.query.AbstractMultiQueryValue)2 Condition (com.revolsys.record.query.Condition)2 In (com.revolsys.record.query.In)2 IsNotNull (com.revolsys.record.query.IsNotNull)2