From 1e4fc9cc867b925d82410f5ab3d5091987d60c4a Mon Sep 17 00:00:00 2001 From: James Moger Date: Wed, 22 Oct 2014 20:40:52 -0400 Subject: Implement execution tests of nested conditions and documentation --- src/site/usage.mkd | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'src/site/usage.mkd') diff --git a/src/site/usage.mkd b/src/site/usage.mkd index b1f4c48..8b54dce 100644 --- a/src/site/usage.mkd +++ b/src/site/usage.mkd @@ -69,6 +69,44 @@ List allProducts = db.buildObjects(Product.class, rs); JdbcUtils.closeSilently(rs, true); ---JAVA--- +### Compound Conditions + +It is possible to specify type-safe compound where clauses using nested `And` and `Or` statements. + +---JAVA--- +final Customer model = new Customer(); + +List regionals = + db.from(model).where(model.customerId).isNotNull() + .and(model.region).isNotNull() + .and(new Or(db, model) {{ + or(model.region).is("LA"); + or(model.region).is("CA"); + }}); + +List regionalType1s = + db.from(model).where(new And(db, model) {{ + and(model.type).is(1); + and(new Or(db, model) {{ + or(model.region).is("CA"); + or(model.region).is("LA"); + }}); + }}); + +---JAVA--- + +### Finding Matches for a List of Values + +You can use SQL's *IN* WHERE clause with the `oneOf` or `noneOf` conditions. + +---JAVA--- +final Customer model = new Customer(); + +List regionals = db.from(model).where(model.region).oneOf("CA", "LA"); +List others = db.from(model).where(model.region).noneOf("CA", "LA"); + +---JAVA--- + ### Read-only Views View model classes can inherit their field definitions from a parent table model class. @@ -232,4 +270,4 @@ for (int i = 0; i < 5; i++) { ---JAVA--- - \ No newline at end of file + -- cgit v1.2.3