From 49e3882ae6552a05fd2cd56e7ecd560d3f795ece Mon Sep 17 00:00:00 2001 From: James Moger Date: Mon, 25 Mar 2013 22:49:16 -0400 Subject: Documentation --- src/site/examples.mkd | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'src/site/examples.mkd') diff --git a/src/site/examples.mkd b/src/site/examples.mkd index 33cb9c4..d8d3dfd 100644 --- a/src/site/examples.mkd +++ b/src/site/examples.mkd @@ -1,6 +1,6 @@ ## Select Statements -%BEGINCODE% +---JAVA--- // select * from products List allProducts = db.from(p).select(); @@ -23,11 +23,11 @@ List productPrices = category = p.category; price = p.unitPrice; }}); -%ENDCODE% +---JAVA--- ## Insert Statements -%BEGINCODE% +---JAVA--- // single record insertion db.insert(singleProduct); @@ -39,11 +39,11 @@ db.insertAll(myProducts); // batch insertion with primary key retrieval List myKeys = db.insertAllAndGetKeys(list); -%ENDCODE% +---JAVA--- ## Update Statements -%BEGINCODE% +---JAVA--- // single record update db.update(singleProduct); @@ -59,22 +59,21 @@ db.from(p).set(p.productName).to("updated") // reusable, parameterized update query String q = db.from(p).set(p.productName).toParameter().where(p.productId).is(1).toSQL(); db.executeUpdate(q, "Lettuce"); - -%ENDCODE% +---JAVA--- ## Merge Statements Merge statements currently generate the [H2 merge syntax](http://h2database.com/html/grammar.html#merge). -%BEGINCODE% +---JAVA--- Product pChang = db.from(p).where(p.productName).is("Chang").selectFirst(); pChang.unitPrice = 19.5; pChang.unitsInStock = 16; db.merge(pChang); -%ENDCODE% +---JAVA--- ## Delete Statements -%BEGINCODE% +---JAVA--- // single record deletion db.delete(singleProduct); @@ -83,12 +82,11 @@ db.deleteAll(myProducts); // delete query db.from(p).where(p.productId).atLeast(10).delete(); - -%ENDCODE% +---JAVA--- ## Inner Join Statements -%BEGINCODE% +---JAVA--- final Customer c = new Customer(); final Order o = new Order(); @@ -98,7 +96,6 @@ List customersWithLargeOrders = where(o.total).greaterThan(new BigDecimal("500.00")). groupBy(c.customerId).select(); - List orders = db.from(c). innerJoin(o).on(c.customerId).is(o.customerId). @@ -109,11 +106,11 @@ List orders = orderId = o.orderId; total = o.total; }}); -%ENDCODE% +---JAVA--- ## View Statements -%BEGINCODE% +---JAVA--- // the view named "ProductView" is created from the "Products" table @IQView(viewTableName = "Products") public class ProductView { @@ -163,14 +160,13 @@ db.from(p).where(p.id).atLeast(250L).and(p.id).lessThan(350L).replaceView(Produc // now drop the view from the database db.dropView(ProductViewInherited.class); - -%ENDCODE% +---JAVA--- ## Dynamic Queries Dynamic queries skip all field type checking and, depending on which approach you use, may skip model class/table name checking too. -%BEGINCODE% +---JAVA--- // where fragment with object parameters List restock = db.from(p).where("unitsInStock=? and productName like ? order by productId", 0, "Chef%").select(); @@ -192,5 +188,4 @@ List restock = db.executeQuery(Product.class, "select * from products w ResultSet rs = db.executeQuery("select * from products"); List allProducts = db.buildObjects(Product.class, rs); JdbcUtils.closeSilently(rs, true); - -%ENDCODE% \ No newline at end of file +---JAVA--- -- cgit v1.2.3