This is a huge coincidence, but I was just logging in to ask what I believe 
is the same question.

Let's say was have a table of books and a table of authors. I want to 
return a list of instances of Book, but with attached Author instances as 
well (which I can access using Book.getAuthors()). For better efficiency 
and for atomicity, I suppose I can do a join, which won't return me a 
BookRecord anymore. Moreover, as there could be many, many books returned, 
I use fetchLazy() to give me a cursor. As far as I can tell, I have to do 
this:

List<Book> bookList=new ArrayList<Book>();
Book currentBook=null;
Author currentAuthor=null;
while(cursor.hasNext()) {
  Record record=cursor.fetchOne();
  String bookID=record.getValue(BOOK.ID);
  //if we are changing books
  if(currentBook==null || !currentBook.getID.equals(bookID) {
    //if we were populating a book
    if(currentBook!=null) {
      bookList.add(currentBook);
     }
    //start a new book
    currentBook=new Book(bookID);
    currentAuthor=null;
    currentBook.setTitle(record.getValue(BOOK.TITLE));
    ...
  }
  String authorID=record.getValue(AUTHOR.ID);  
  if(currentAuthor==null || !currentAuthor.getID().equals(authorID)) {
    if(currentAuthor!=null) {
      currentBook.addAuthor(author);
    }
    currentAuthor=new Author();
    currentAuthor.setLastName(record.getValue(AUTHOR.LAST_NAME));
    ...

And so it goes. Because a join will produce records with duplicated 
information for the objects in one-to-many relationships, I'll have to have 
this bulky logic for detecting when an instance changes, correct? But that 
is so tedious!! I could instead do multiple queries to create the instances 
as I walk the graph---but isn't that less efficient and not atomic?

What does jOOQ expect us to do to retrieve instance graphs in an efficient 
way?

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to