Example Class Usage Notes

The example class specifies how to build a dynamic where clause. Each non-BLOB column in the table can optionally be included in the where clause. Examples are the best way to demonstrate the usage of this class.

The example class can be used to generate a virtually unlimited where clauses.

The example classes contain an inner static class called Criteria that holds a list of conditions that will be anded together in the where clause. The outer class holds a list of Criteria objects and all the clauses from the inner classes will be ored together. Using different sets of Criteria classes allows you to generate virtually unlimited types of where clauses.

Criteria objects must be created with the createCriteria method in the example class. When the first Criteria object is created it is automatically added to the list of Criteria objects - this makes it easy to write a simple where clause if you don't need to or several other clauses together.

This example shows how to generate a simple WHERE clause using the generated example class:

  TestTableExample example = new TestTableExample();

  example.createCriteria().andField1EqualTo(5);

In the above example, the dynamically generated where clause will effectively be:

  where field1 = 5

The next example shows how to generate a complex WHERE clause using the generated example class (using JSE 5.0 parameterized types):

  TestTableExample example = new TestTableExample();

  example.createCriteria()
    .andField1EqualTo(5)
    .andField2IsNull();

  example.or(example.createCriteria()
    .andField3NotEqualTo(9)
    .andField4IsNotNull());

  List<Integer> field5Values = new ArrayList<Integer>();
  field5Values.add(8);
  field5Values.add(11);
  field5Values.add(14);
  field5Values.add(22);

  example.or(example.createCriteria()
    .andField5In(field5Values));

  example.or(example.createCriteria()
    .andField6Between(3, 7));

In the above example, the dynamically generated where clause will effectively be:

  where (field1 = 5 and field2 is null)
     or (field3 <> 9 and field4 is not null)
     or (field5 in (8, 11, 14, 22))
     or (field6 between 3 and 7)

Returned records will meet these criteria.

The Criteria inner class includes andXXX methods for each field, and each standard SQL predicate including: