public void testComplexSelectWithOrdering() throws Exception { removeAll(Book.class); ArrayList authors = new ArrayList(); authors.add(new Author("Tom", "Petty")); authors.add(new Author("Lynyrd", "Skynyrd")); Book b1 = new Book("Book of Bokonon", "1-2-3-4"); b1.setAuthors(authors); b1.setMainAuthor(new Author("Bokonon Jr.", "")); Book b2 = new Book("Book of Bokonon", "4-3-2-1"); authors = new ArrayList(); authors.add(new Author("Tom", "Petty")); b2.setAuthors(authors); b2.setMainAuthor(new Author("Bokonon", "")); Book b3 = new Book("Starhip design", "2-2-2-2"); Book b4 = new Book("NetMind Persistence tutorial", "0-0-0-0"); // Save getStore().save(b1); getStore().save(b2); getStore().save(b3); getStore().save(b4); // Get List result = getStore() .find( "find book where (book.authors contains tom(author)) " + "and tom.firstname='Tom' and book.authors contains lynyrd(author) and lynyrd.firstname='Lynyrd' and book.mainauthor.firstname like 'Bokonon%'"); Assert.assertEquals(result.size(), 1); Assert.assertEquals(result.get(0), b1); }
public Object handle(ResultSet rs, PageArgument pageArg) throws SQLException { Book bean = null; if (rs.next()) { bean = new Book(); bean.setId(rs.getLong("id")); bean.setTitle(rs.getString("title")); bean.setAuthors(rs.getString("authors")); } return bean; }
public void testNegatedContains() throws Exception { removeAll(Book.class); ArrayList authors = new ArrayList(); authors.add(new Author("Tom", "Petty")); authors.add(new Author("Lynyrd", "Skynyrd")); Book b1 = new Book("Book of Bokonon", "1-2-3-4"); b1.setAuthors(authors); // Save getStore().save(b1); // Get try { List result = getStore() .find("find book where not book.authors contains author and author.firstname='Tom'"); Assert.fail("negated contains did not throw exception."); } catch (Exception e) { logger.debug("expected exception", e); } }
public void testContainsOperatorOnList() throws Exception { // Create test setup removeAll(Book.class); // Create Book book = new Book("Starship internals", "1-3-5-7"); ArrayList authors = new ArrayList(); authors.add(new Author("Geordi", "LaForge")); authors.add(new Author("Data", "")); authors.add(new Author("Scott", "Montgomery")); book.setAuthors(authors); // Save getStore().save(book); // Select ref1 List result = getStore() .find("find book where book.authors contains author and author.firstname = 'Geordi'"); Assert.assertEquals(result.size(), 1); Assert.assertEquals(result.get(0), book); }