Adapter and lazy loading

Posts   
 
    
mattcole
User
Posts: 15
Joined: 25-May-2006
# Posted on: 31-May-2006 09:08:21   

Hi, I realise that the adapter scenario doesn't explicitly support lazy loading, and I've read here on the forum that the idea is that the business layer will handle the explicit loading of all of the entity objects.

I have the scenario where I have a hierachy setup in the database, but no way of knowing it's depth. I can specify an arbitrary level of depth for my prefetch paths, but what is the recommended way of detecting that a given level is the leaf level as far as being preloaded, and how should I go about loading further levels of the hierachy from there?

Is there a better way than detecting the relevant collection has count == 0 and passing the object back to load that property?

Thanks, Matt

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 31-May-2006 14:12:16   

Would you please elaborate more with examples?

Also post the hierachy setup in mind.

mattcole
User
Posts: 15
Joined: 25-May-2006
# Posted on: 31-May-2006 14:51:14   

Hi Walaa,

Thanks again for the reply simple_smile

Basically as an example imagine I have a table which stores product categories, and a product category can have a parent (also a product category entity) or have null for the parentCategoryID column. If I want to retrieve all the descendents of a given product category I would need to know in advance how many generations are beneath it. I can do something like (excuse my lack of actual syntax the code is on another machine)

prefetch.add(childproperty).subpath(childproperty).subpath(childproperty)

and that would get me a collection of children, each of the children would also have a collection with it's children (assuming there are any). In some calling code I process the collection to build a tree view. When I get to a collection of entities that are grandchildren of the initial entity, if I had a lazy loading capability, when I accessed the collection that would store its children, it would load them if it had any. With the adapter model, because I specified only 3 generations to prefetch, their collections have count = 0. From memory there is some way to tell whether it has been loaded and there are no children, or whether it has not actually been loaded, maybe I need to use that and if it hasn't been loaded call a method which takes the entity and explicitly loads the collection, I was just wondering if there was a more elegant way.

Thanks again, Matt

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
mattcole
User
Posts: 15
Joined: 25-May-2006
# Posted on: 01-Jun-2006 03:48:32   

Thanks Walaa.