Predicate methods reference

The following table lists the types of comparisons and matches you can make with methods on the query object.

Predicate method

Parameter (Type)

Description

and

Gosu block that contains a list of predicate methods applied to columns in the query.

Checks whether a value satisfies a set of predicate methods, such as compare, contains, and between. All of the predicate methods must evaluate to true for the item that contains the value to be included in the result.

between

  • Column name (String)
  • Start value (Object)
  • End value (Object)

Checks whether a value is between two values. This method supports String values, date values, and number values.

query.between(Activity#PublicID, "abc:01", 
        "abc:99")

To specify an unbounded range on the lower or upper end, pass null as the first or second range argument but not both. You can pass null as a parameter regardless of null restrictions on the column.

compare

  • Column name (String)
  • Operation type (Relop)
  • Value (Object)

Compares a column to a value. For the operation type, pass one of the following values to represent the operation type:

Equals
Matches if the values are equal
NotEquals
Matches if the values are not equal
LessThan
Matches if the row’s value for that column is less than the value passed to the compare method
LessThanOrEquals
Matches if the row’s value for that column is less than or equal to the value passed to the compare method
GreaterThan
Matches if the row’s value for that column is greater than the value passed to the compare method
GreaterThanOrEquals
Matches if the row’s value for that column is greater than or equal to the value passed to the compare method

Pass these values without quote symbols around them. These names are values in the Relop enumeration.

For the value object, you can use numeric types, String types, PolicyCenter entities, keys, or typekeys. For String values, the comparison is case-sensitive.

Example of a simple equality comparison:

query.compare(Activity#Priority, Equals, 5)

Example of a simple less than or equal to comparison:

query.compare(Activity#Priority, 
        LessThanOrEquals, 5)

To compare the value to the value in another column, generate a column reference and pass that instead.

You can use algebraic functions that evaluate to an expression that can be evaluated at run time to be the appropriate type. For example:

var prefix = "abc:"
var recordNumber = "1234"
query.compare(Activity#PublicID, Equals, 
        prefix + recordNumber)

Or combine a column reference and algebraic functions:

query.compare(Activity#Priority, Equals, 
       DBFunction.Expr({
         query.getColumnRef("OldPriority"), 
           "+", "10"}))

compareIgnoreCase

  • Column name (String)
  • Operation type (Relop)
  • Value (Object)

Compares a character column to a character value while ignoring uppercase and lowercase variations. For example, if the following comparison succeeds:

query.compare("Name", Equals, "Acme")

Both of the following comparisons also succeed:

query.compareIgnoreCase("Name", Equals, Acme")
query.compareIgnoreCase(Company#Name, 
       Equals, "ACME") 

compareIn

  • Column name (String)
  • List of values that could match the database row for the column (Object[])

Compares the value for this column for each row to a list of non-null objects that you specify. If the column value for a row matches any of them, the query successfully matches that row. For example:

query.compareIn(Activity#PublicID, 
       {"default_data:1", default_data:3"})

compareNotIn

  • Column name (String)
  • List of values that could match the database row for that column (Object[])

Compares the value for this column for each row to a list of non-null objects that you specify. If the column value for a row matches none of them, the query successfully matches that row. For example:

query.compareNotIn(Activity#PublicID, 
       {"default_data:1", default_data:3"})

contains

  • Column name (String)
  • Contains value (String)
  • Ignore case (Boolean)

Checks whether the value in that column for each row contains a specific substring. For example, if the substring is "jo", it will match the value "anjoy" and "job" but not the values "yo" or "ji". If you pass true to the final argument, Gosu ignores case differences in its comparison. For example:

query.contains(Person#FirstName, "jo", 
        true /* ignore case */)

Test the use of the contains method in a realistic environment. Using the contains method as the most restrictive predicate on a query causes a full-table scan in the database because the query cannot use an index.

Warning: For a query on a large table, using contains as the most restrictive predicate can cause an unacceptable delay to the user interface.

or

Gosu block that contains a list of predicate methods applied to columns in the query.

Checks whether a value satisfies one or more predicate methods, such as compare, contains, and between. Only one of the predicate methods must evaluate to true for the item that contains the value to be included in the result.

startsWith

  • Column name (String)
  • Substring value (String)
  • Ignore case (Boolean)

Checks whether the value in that column for each row starts with a specific substring. For example, if the substring is "jo", it will match the value "john" and "joke" but not the values "j" or "jar". If you pass true to the Boolean argument (the third argument), Gosu ignores case differences in its comparison. For example:

query.startsWith(Person#FirstName, "jo",
         true /* ignore case */)

Note: If you choose case-insensitive partial comparisons, Gosu generates an SQL function that depends on your PolicyCenter and database configuration to implement the comparison predicate. However, if the data model definition of the column specifies the supportsLinguisticSearch attribute set to true, Gosu uses the denormalized version of the column, instead.

Important: Test the use of the startsWith method in a realistic environment. Using the startsWith method as the most restrictive predicate on a query can cause a delay on the user interface.

subselect

The arguments provide set inclusion and exclusion predicates.

Perform a join with another table and select a subset of the data by combining tables.

withinDistance
  • Identifier for column of type SpatialPoint

    (IQueryablePropertyInfo)

  • Path to location or spatial property. Use only in complex entity queries, such as those containing a join. (String)

  • Center (SpatialPoint)

  • Distance (Number)

  • Unit of distance (UnitOfDistance)

Checks whether a location or spatial property on a column identifies a location that is within a given number of distance units of a center or reference location. For example:

addressQuery.withinDistance(
  Address.SPATIALPOINT_PROP.get(), 
  SAN_MATEO, 10, 
  UnitOfDistance.TC_MILE) 
addressTable.withinDistance(
  Address.SPATIALPOINT_PROP.get(),
  "Person.PrimaryAddress.SpatialPoint",
  SAN_MATEO, 10, 
  UnitOfDistance.TC_MILE) 

Predicate methods that support DBFunction arguments

The predicate methods that support a DBFunction object as the comparison value are:

  • compare
  • compareIgnoreCase
  • between
  • startsWith
  • contains
  • subselect

See also