The Artima Developer Community
Sponsored Link

Design Forum
Designing CRUD operations

1 reply on 1 page. Most recent reply: Oct 27, 2005 5:56 AM by Cameron Purdy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
unmesh joshi

Posts: 1
Nickname: unmeshjoah
Registered: Aug, 2005

Designing CRUD operations Posted: Aug 20, 2005 4:05 AM
Reply to this message Reply
Advertisement
Hi,

I have a question regarding use of Domain Model pattern for CRUD operations. In our project we are creating customer profiles. We have modeled profile like this

class Profile {
Name name;
List<Address> addressList;
List <Phone> phoneList;
....
}

We have CRUD operations for Profile, Addresses, and Phones.
For crud operations, we have DAO facade as,

class ProfileDao {
void insertProfile(Profile profile);
void Profile getProfile(String profileId);
void addAddress(String profileId, Address a);
void addPhone(String profileId, Phone p);
void updateAddress(String addressId, Address a);
void updatePhone(String phoneId, Phone p);
void deleteAddress(String addressId);
void deletePhone(String phoneId);
..........

}


Client for this code will be like this.

class ProfileClient {
void testAddAddress() {
Address address = new Address("112 Fifth Street", "NJ", "US", "08857");

String profileId = getProfileIdentifier();

getProfileDao().update(profileId, address);

}
}

Instead of using DAO Facade , I thought we could use it like following.

1. Clients will do all CRUD operations on Profile object itself.
2. All the classes will have isUpdated, isNew and isDeleted flag.
3. Dao will have just one update(Profile p) method.
4. Dao will check for updates and make queries accordingly

Dao will now become like this.

class ProfileDao {
void insertProfile(Profile profile);
void Profile getProfile(String profileId);
void update(Profile p);
}

Client for this code will be like this.

class ProfileClient {

void testAddAddress() {
Address address = new Address("112 Fifth Street", "NJ", "US", "08857");
Profile p = getProfile();
p.addAddress(address);

getProfileDao().update(profile);

}
}

This second approach looks cleaner, but the concern raised by my team mates is that every time I need to add, update, delete a single address, I need to load whole profile object in memory. This looks more like a "stateful" implementation as opposed to "stateless" implementation of Dao Facade. If Profile object is a huge one, then it can be a overkill to load the whole object just to add/change one address. But I certainly dont like the facade implementation. It does not allow me to do inserts/updates/deletes in batch. I have to do operations one at a time. Secondly any object level validations or business rules (Like Profile should have only one delivery address) are harder to implement in facade approach. What is your opinion on this? Is this a standard Domain Model vs Transaction Script issue?

Thanks,
Unmesh


Cameron Purdy

Posts: 186
Nickname: cpurdy
Registered: Dec, 2004

Re: Designing CRUD operations Posted: Oct 27, 2005 5:56 AM
Reply to this message Reply
It's a balance. In OO applications, you don't usually want your conceptual entities to be too granular (e.g. normalized) or too coarse (giant object graphs).

There are a number of additional considerations:

1) How long does it actually take to populate your complex object? Three queries may not be an issue.

2) Do you cache the object once populated? If so, it may be a very efficient approach (as those three queries will be executed rarely).

3) What unnatural payments will you be forced to make later if you don't populate it as a complex object?

4) Are there opportunities for lazy loading the remainder of the complex object, i.e. a single query for the main data and leave the rest unloaded until asked for.

5) What situations will CRUD break down completely for your application? (This, IMHO, is the one to watch out for the most!) For example, if you have to display a list of "n" Profile objects, is it three queries, or 3*n queries? etc.

Peace,

Cameron Purdy
http://www.tangosol.com/

Flat View: This topic has 1 reply on 1 page
Topic: Should I create an interface if I have only one implementation? Previous Topic   Next Topic Topic: Database design help

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use