New string comparison operators: Here are a series of calls to a Query class method
setQueryName, and the where-clauses produced by QueryBuilder: CALL: PersonQuery pq = new PersonQuery();
CALL: pq.setQueryName( "MaryJo", EQUAL );
WHERE clause: name = 'MaryJo'
CALL: pq.setQueryName( "MaryJo", CASE_INSENSITIVE_EQUAL );
WHERE clause: LOWER( name ) = 'maryjo'
CALL: pq.setQueryName( "MaryJo", CASE_SENSITIVE_CONTAINS );
WHERE clause: name LIKE '%MaryJo%'
CALL: pq.setQueryName( "MaryJo", CASE_INSENSITIVE_CONTAINS );
WHERE clause: LOWER( name ) LIKE '%maryjo%'
CALL: pq.setQueryName( "MaryJo", CASE_SENSITIVE_STARTS_WITH );
WHERE clause: name LIKE 'MaryJo%'
CALL: pq.setQueryName( "MaryJo", CASE_INSENSITIVE_STARTS_WITH );
WHERE clause: LOWER( name ) LIKE 'maryjo%'
CALL: pq.setQueryName( "MaryJo", CASE_SENSITIVE_ENDS_WITH );
WHERE clause: name LIKE '%MaryJo'
CALL: pq.setQueryName( "MaryJo", CASE_INSENSITIVE_ENDS_WITH );
WHERE clause: LOWER( name ) LIKE '%maryjo'
New QueryBuilder.compare() methods: QueryBuilder has 3 new static methods that compare
two values using the QueryBuilder comparison operators: static public boolean QueryBuilder.compare(
boolean a, boolean b, String comparison_operator )
static public boolean QueryBuilder.compare(
double a, double b, String comparison_operator )
static public boolean QueryBuilder.compare(
Object a, Object b, String comparison_operator )
For a cache-enabled XxxDO class generated by DODS, the corresponding
XxxQuery.setQueryYyy() methods use the new QueryBuilder.compare() methods to perform cache
filtering. This allows the XxxQuery classes to perform more elaborate queries against the
XxxDO cache. (Previously, only EQUALS comparisons were supported.) The
QueryBuilder.compare() methods can be handy whereever an application must compare values.
Simpler standalone use of QueryBuilder: Let's say you just want to generate a report
containing the Name and Age of everyone in the Person table. You could use DO's, like so: PersonQuery pq = new PersonQuery();
PersonDO[] people = pq.getDOArray();
for ( int i = 0; i < people.length; i++ ) {
print( people[i].getName() );
print( people[i].getAge() );
}
But if an array of PersonDO's would eat too much memory, you could use just the
QueryBuilder to get this data:
QueryBuilder qb = new QueryBuilder();
qb.select( PersonDO.Name );
qb.select( PersonDO.Age );
RDBRow row;
while ( null != ( row = qb.getNextRow() ) ) {
print( row.get( PersonDO.Name ).getString() );
print( row.get( PersonDO.Age ).getInt() );
}
Let's say you also have an Address table, and each Person has a reference to an
Address. You could list the names of cities containing people over 100 years old, like so:
QueryBuilder qb = new QueryBuilder();
qb.select( AddressDO.Name );
qb.addWhere( PersonDO.Age, 100, QueryBuilder.GREATER_THAN );
qb.addWhere( PersonDO.Address, AddressDO.PrimaryKey );
RDBRow row;
while ( null != ( row = qb.getNextRow() ) ) {
print( row.get( CityDO.Name ).getString() );
}
QueryBuilder can also be used to read data from a legacy database. Let's say the Person
table was _not_ created by DODS, and so there is no PersonQuery and PersonDO class.
RDBTable person = new RDBTable( "Person" );
RDBColumn name = new RDBColumn( person, "Name" );
RDBColumn age = new RDBColumn( person, "Age" );
QueryBuilder qb = new QueryBuilder();
qb.select( name );
qb.select( age );
RDBRow row;
while ( null != ( row = qb.getNextRow() ) ) {
print( row.get( name ).getString() );
print( row.get( age ).getInt() );
}