@Before public void setup() { db = IciqlSuite.openNewDb(); db.insertAll(UserId.getList()); db.insertAll(UserNote.getList()); }
@Test public void testRuntimeQuery() { Db db = IciqlSuite.openNewDb(); db.insertAll(Product.getList()); Product p = new Product(); List<Product> products = db.from(p).where("unitsInStock=?", 120).orderBy(p.productId).select(); assertEquals(1, products.size()); products = db.from(p) .where("unitsInStock=? and productName like ? order by productId", 0, "Chef%") .select(); assertEquals(1, products.size()); db.close(); }
@Test public void testExecuteQuery() throws SQLException { Db db = IciqlSuite.openNewDb(); db.insertAll(Product.getList()); // test plain statement List<Product> products = db.executeQuery(Product.class, "select * from product where unitsInStock=120"); assertEquals(1, products.size()); assertEquals("Condiments", products.get(0).category); // test prepared statement products = db.executeQuery(Product.class, "select * from product where unitsInStock=?", 120); assertEquals(1, products.size()); assertEquals("Condiments", products.get(0).category); db.close(); }
@Test public void testBuildObjects() throws SQLException { Db db = IciqlSuite.openNewDb(); db.insertAll(Product.getList()); // test plain statement ResultSet rs = db.executeQuery("select * from product where unitsInStock=120"); List<Product> products = db.buildObjects(Product.class, rs); JdbcUtils.closeSilently(rs, true); assertEquals(1, products.size()); assertEquals("Condiments", products.get(0).category); // test prepared statement rs = db.executeQuery("select * from product where unitsInStock=?", 120); products = db.buildObjects(Product.class, rs); JdbcUtils.closeSilently(rs, true); assertEquals(1, products.size()); assertEquals("Condiments", products.get(0).category); db.close(); }