Grokbase Groups Cayenne user May 2010
FAQ
Hi All

Is there a way to define default prefetching on a Persistent object?

Eg:

If I have:

Category -> Products -> Orders

I want to call category.getProducts() and automatically prefetch all the
Orders for the products which are returned?

Thank you

Gary

Search Discussions

  • Marcin Skladaniec at May 19, 2010 at 5:15 am
    Hi Gary

    Prefetching a select query which should meet your requirements:
    SelectQuery sq = new SelectQuery(Category.class);
    sq.addPrefetch(Category.PRODUCTS_PROPERTY);
    sq.addPrefetch(Category.PRODUCTS_PROPERTY+"."+Product.ORDERS_PROPERTY);
    context.performQuery(sq);

    http://cayenne.apache.org/doc30/prefetching.html

    All best
    Marcin
    On 19/05/10 2:11 PM, Gary Jarrel wrote:
    Hi All

    Is there a way to define default prefetching on a Persistent object?

    Eg:

    If I have:

    Category -> Products -> Orders

    I want to call category.getProducts() and automatically prefetch all the
    Orders for the products which are returned?

    Thank you

    Gary
  • Marcin Skladaniec at May 19, 2010 at 5:21 am
    Actually I re-read your question. There is no way of specifying a
    default prefetch for a given entity.
    Some time ago I lodged a confusing feature request, I think 'default
    prefetch' can be solution for it.
    (https://issues.apache.org/jira/browse/CAY-1234)
    Cheers
    Marcin
    On 19/05/10 2:11 PM, Gary Jarrel wrote:
    Hi All

    Is there a way to define default prefetching on a Persistent object?

    Eg:

    If I have:

    Category -> Products -> Orders

    I want to call category.getProducts() and automatically prefetch all the
    Orders for the products which are returned?

    Thank you

    Gary
  • Gary Jarrel at May 19, 2010 at 7:31 am

    On Wed, May 19, 2010 at 3:20 PM, Marcin Skladaniec wrote:

    Actually I re-read your question. There is no way of specifying a default
    prefetch for a given entity.
    Some time ago I lodged a confusing feature request, I think 'default
    prefetch' can be solution for it. (
    https://issues.apache.org/jira/browse/CAY-1234)
    Cheers

    Marcin

    Thank you Marcin,

    Do you think it is something that could be implemented via Annotations?

    Perhaps a class level or method annotation

    @Prefetch("products.orders");
    public class Category() {

    @Prefetch // this could pre-fetch products
    @Prefetch("orders") // this could pre-fetch products.orders
    public List<Product> getProducts() {
    ....
    }
    }
  • Lachlan Deck at May 19, 2010 at 12:49 pm

    On 19/05/2010, at 5:30 PM, Gary Jarrel wrote:

    Do you think it is something that could be implemented via Annotations?

    Perhaps a class level or method annotation

    @Prefetch("products.orders");
    public class Category() {

    @Prefetch // this could pre-fetch products
    @Prefetch("orders") // this could pre-fetch products.orders
    public List<Product> getProducts() {
    ....
    }
    }
    You could utilise those annotations yourself, in the absence of an officially supported mechanism, by subclassing SelectQuery and creating your own library of annotations (with runtime retention) and it'd be quite simple.

    I suspect a more official approach would involve adding prefetch definitions to the model.

    with regards,
    --

    Lachlan Deck

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedMay 19, '10 at 4:11a
activeMay 19, '10 at 12:49p
posts5
users3
websitecayenne.apache.org

People

Translate

site design / logo © 2021 Grokbase