Exemple #1
0
 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);
 }
Exemple #2
0
 public void testInOperatorWithList() throws Exception {
   // Create test setup
   removeAll(Book.class);
   removeAll(Author.class);
   // Create
   Author author1 = new Author("Geordi", "LaForge");
   Author author2 = new Author("Data", "");
   Author author3 = new Author("Scott", "Montgomery");
   Book book = new Book("Starship internals", "1-3-5-7");
   book.setMainAuthor(author1);
   // Save
   getStore().save(book);
   getStore().save(author1);
   getStore().save(author2);
   getStore().save(author3);
   // Create list
   ArrayList authorList = new ArrayList();
   authorList.add(author1);
   authorList.add(author2);
   authorList.add(author3);
   // Select
   List result =
       getStore().find("find book where book.mainauthor in ?", new Object[] {authorList});
   logger.debug("result is: " + result);
   Assert.assertEquals(result.size(), 1);
 }
Exemple #3
0
 public void testRemovedAttributesSelect() throws Exception {
   // Drop
   removeAll(Book.class);
   // Create bookS
   Author author1 = new Author("One", "Author");
   Book book1 = new Book("Book", "1");
   book1.setMainAuthor(author1);
   getStore().save(book1);
   Author author2 = new Author("Two", "Author");
   Book book2 = new Book("Book", "2");
   book2.setMainAuthor(author2);
   getStore().save(book2);
   // Remove both authors
   getStore().remove(author1);
   getStore().remove(author2);
   // Run the select
   Assert.assertEquals(
       getStore()
           .find(
               "find book where book.isbn='1' and book2(book).isbn='2' and book.mainauthor=book2.mainauthor")
           .size(),
       1);
 }
Exemple #4
0
 public void testRemovedAttributeSelect() throws Exception {
   // Drop
   removeAll(Book.class);
   removeAll(Author.class);
   // Create book with mainauthor
   Author author = new Author("Short", "Live");
   Book book = new Book("The Death of Null", "0");
   book.setMainAuthor(author);
   getStore().save(book);
   // Now remove mainauthor
   getStore().remove(author);
   // Run the select
   Assert.assertEquals(getStore().find("find book where book.mainauthor is null").size(), 1);
   Assert.assertEquals(getStore().find("find book where book.mainauthor is not null").size(), 0);
 }
Exemple #5
0
 public void testMixedSelectWithAlias() throws Exception {
   // Create test setup
   removeAll(Book.class);
   // Create
   Book book = new Book("Starship internals", "1-3-5-7");
   book.setMainAuthor(new Author("Geordi", "LaForge"));
   // Save
   getStore().save(book);
   // Select
   List result = getStore().find("find book,book.mainauthor.firstName authorname");
   logger.debug("result is: " + result);
   Assert.assertEquals(result.size(), 1);
   Assert.assertEquals(((Map) result.get(0)).get("object"), book);
   Assert.assertEquals(((Map) result.get(0)).get("authorname"), "Geordi");
 }
Exemple #6
0
 public void testRemovedObjectIdSelect() throws Exception {
   // Drop
   removeAll(Book.class);
   // Create book
   Author author = new Author("Joe", "Author");
   Book book = new Book("Book", "X");
   book.setMainAuthor(author);
   getStore().save(book);
   // Remove author
   getStore().remove(author);
   // Run the select
   Assert.assertEquals(
       getStore().find("find book where book.mainauthor=?", new Object[] {author}).size(), 0);
   Assert.assertEquals(
       getStore().find("find book where book.mainauthor=?", new Object[] {null}).size(), 1);
 }
Exemple #7
0
  public void testSelectSymbolTable() throws Exception {
    // Drop books
    removeAll(Book.class);
    removeAll(Author.class);

    // Create
    Book book = new Book("Title", "Isbn");
    book.setMainAuthor(new Author("Peter", "Jackson"));
    getStore().save(book);

    // Select
    List result =
        getStore()
            .find(
                "find book where book.mainauthor.firstname='Peter' or book.mainauthor.firstname='Peter'");
    Assert.assertEquals(result.size(), 1);
  }