ENH-171/172 ... control over lazy loading queries (batch size, joins etc) ... and secondary queries

13 views
Skip to first unread message

Rob Bygrave

unread,
Nov 1, 2009, 6:56:56 AM11/1/09
to ebean@googlegroups
FYI:

In HEAD is code to support ENH-171 and ENH-172.

These enable you to control/specify the lazy loading queries.

Example:

  1. Query<Order> query = Ebean.find(Order.class)  
  2.     .join("customer","+lazy(10) name, status")  
  3.     .join("customer.contacts"); 

This becomes...

- Find Orders...
- Lazy load customers 10 at a time...
- the lazy load query is:    
        find customer (name, status)
        join contacts where id in (?,?,?,?,?,?,?,?,?,?)


Note that instead of using the +lazy(10) hint... you could use JoinConfig and write:  

.join("customer","name, status", new JoinConfig().lazy(10)



In Addition to controlling the lazy loading query we can specify a "query join"
 ... which means fetch this part of the object graph using a second query.

That is, instead of building the object graph using 1 query (and then lazy loading) we can specify to use multiple queries (and then use lazy loading).  Note that it can be more efficient to use multiple queries in some cases (such as when you have multiple OneToMany relationships to load - aka to avoid a cartesian product).


  1. List<Order> list = Ebean.find(Order.class)  
  2.     .join("customer"new JoinConfig().query(3).lazy(10))  
  3.     .findList(); 
Find Orders
.. then immedidately Load the first 3 customers referenced by those orders
.. after that lazy load customers 10 at a time as needed


Anyway, that's in HEAD for those that want to play. 


Cheers, Rob.



 
Reply all
Reply to author
Forward
0 new messages