Search in sources :

Example 1 with Condition

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

the class JdbcUtils method setPreparedStatementParameters.

public static void setPreparedStatementParameters(final PreparedStatement statement, final Query query) {
    int index = 1;
    for (final Object parameter : query.getParameters()) {
        final JdbcFieldDefinition attribute = JdbcFieldDefinition.newFieldDefinition(parameter);
        try {
            index = attribute.setPreparedStatementValue(statement, index, parameter);
        } catch (final SQLException e) {
            throw new RuntimeException("Error setting value:" + parameter, e);
        }
    }
    final Condition where = query.getWhereCondition();
    if (!where.isEmpty()) {
        where.appendParameters(index, statement);
    }
}
Also used : Condition(com.revolsys.record.query.Condition) JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) SQLException(java.sql.SQLException)

Example 2 with Condition

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

the class JdbcUtils method appendWhere.

public static void appendWhere(final StringBuilder sql, final Query query) {
    final Condition where = query.getWhereCondition();
    if (!where.isEmpty()) {
        sql.append(" WHERE ");
        final RecordDefinition recordDefinition = query.getRecordDefinition();
        if (recordDefinition == null) {
            where.appendSql(query, null, sql);
        } else {
            final RecordStore recordStore = recordDefinition.getRecordStore();
            where.appendSql(query, recordStore, sql);
        }
    }
}
Also used : Condition(com.revolsys.record.query.Condition) JdbcRecordStore(com.revolsys.jdbc.io.JdbcRecordStore) RecordStore(com.revolsys.record.schema.RecordStore) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 3 with Condition

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

the class OgrRecordStore method getWhereClause.

protected StringBuilder getWhereClause(final Query query) {
    final StringBuilder whereClause = new StringBuilder();
    final Condition whereCondition = query.getWhereCondition();
    if (!whereCondition.isEmpty()) {
        appendQueryValue(query, whereClause, whereCondition);
    }
    return whereClause;
}
Also used : SqlCondition(com.revolsys.record.query.SqlCondition) Condition(com.revolsys.record.query.Condition) AbstractMultiCondition(com.revolsys.record.query.AbstractMultiCondition) BinaryCondition(com.revolsys.record.query.BinaryCondition) RightUnaryCondition(com.revolsys.record.query.RightUnaryCondition) LeftUnaryCondition(com.revolsys.record.query.LeftUnaryCondition)

Example 4 with Condition

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

the class QueryValueTest method testILike.

@SuppressWarnings("unchecked")
private void testILike() {
    for (final Object like : Arrays.asList(10, "%10", "10%", "%10%", "%1%", "%0%")) {
        final Condition trueCondition = Q.iLike(this.idField, like);
        assertConditionTrue(trueCondition, this.record);
    }
    for (final String like : Arrays.asList("%Foobar", "fooBar%", "%foObar%", "%fOo%", "%bAr%", "%o%B%")) {
        final Condition trueCondition = Q.iLike(this.nameAttribute, like);
        assertConditionTrue(trueCondition, this.record);
    }
    for (final String like : Arrays.asList("%Foobar1", "Foobar1%", "%Foobar1%", "%Foo1%", "%Bar1%", "%a%b%")) {
        final Condition falseCondition = Q.iLike(this.nameAttribute, like);
        assertConditionFalse(falseCondition, this.record);
    }
}
Also used : Condition(com.revolsys.record.query.Condition)

Example 5 with Condition

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

the class QueryValueTest method testLike.

@SuppressWarnings("unchecked")
private void testLike() {
    for (final Object like : Arrays.asList(10, "%10", "10%", "%10%", "%1%", "%0%")) {
        final Condition trueCondition = Q.like(this.idField, like);
        assertConditionTrue(trueCondition, this.record);
    }
    for (final String like : Arrays.asList("%foobar", "foobar%", "%foobar%", "%foo%", "%bar%", "%o%b%")) {
        final Condition trueCondition = Q.like(this.nameAttribute, like);
        assertConditionTrue(trueCondition, this.record);
    }
    for (final String like : Arrays.asList("%Foobar", "Foobar%", "%Foobar%", "%Foo%", "%Bar%", "%O%b%")) {
        final Condition falseCondition = Q.like(this.nameAttribute, like);
        assertConditionFalse(falseCondition, this.record);
    }
}
Also used : Condition(com.revolsys.record.query.Condition)

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