Entity Injection

Posts   
 
    
Max avatar
Max
User
Posts: 221
Joined: 14-Jul-2006
# Posted on: 12-Oct-2006 17:20:55   

Last night I was thinking about a new type of problem about O/R Mapper. ("With Great Power Comes Great Responsibility" simple_smile )

Said that I have a project with 3 entities.

Customer --> Address Customer --> Phones

Said that I have a business class (BcCustAddr) that fetch/persist a graph composed by Customers and Address. Said that I have another business class (BcPhones) that add phones to the customer, but olny after some particular validation.

Now My Gui layer can fetch a group of Customers/Address through BcCustAddr. After that, the Gui layer can create a new Phones entity, and inject this entity in to the object graph. Now the Gui can use BcCustAddr to persist the changes, and even the injected phones will be written down in the DB (bypassing the validation imposed by BcPhones).

How do you handle this type of problem?

I'm thinking about the following approach: *) My business class know the data that will be loaded, because of a PrefetchPath harcoded in de businessClass *) so my BC can explore the prefetchpath and create a list of the admitted EntityType *) After that, during Persist/Validation, the BC can explore the entity graph, and check that all the entities are of the correct type

This is a simplistic approach, and will fail if a particular type of entity can exist in different branch of the prefetch path. I'll need to think about some better check routine... sunglasses

What do you think about this approach?

Thanks, Max

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 13-Oct-2006 15:44:53   

You can strip off unwanted related entities in the different BL methods/classes.

RaFaLe avatar
RaFaLe
User
Posts: 27
Joined: 26-Oct-2006
# Posted on: 09-Nov-2006 10:16:52   

Another approach is to generate custom code using custom templates.

I've used custom code now for some time - generate "lightweight" versions of your entities and use those in your UI. Provide a method than enables the conversion from your lightweight object back into a full LL Entity. This then forces the validation.

Alternatively, Extend all the default Entities and override the Save [Self Servicing] (Or SaveEntity [Adapter]) method, calling validation first.

I hope I've helped some? Or have I missed the boat?

Max avatar
Max
User
Posts: 221
Joined: 14-Jul-2006
# Posted on: 09-Nov-2006 15:02:05   

RaFaLe wrote:

Another approach is to generate custom code using custom templates.

Alternatively, Extend all the default Entities and override the Save [Self Servicing] (Or SaveEntity [Adapter]) method, calling validation first.

I'm using Adapter. I will override save/delete of dataadaper to force validation. I will even use the commonBaseClass to automatically create a validator object for each entity.

RaFaLe wrote:

I hope I've helped some? Or have I missed the boat?

Any idea is welcome simple_smile