aspose file tools*
The moose likes Object Relational Mapping and the fly likes General data fetching best practice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "General data fetching best practice" Watch "General data fetching best practice" New topic
Author

General data fetching best practice

Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 507
Our application has 2 interfaces, one is web and the other is mobile. My question is, do you guys use single( read same) service layer method for specific functionality to serve web and mobile interface? Or have separate methods?

For example, get/EditUserDetails(userId). On web interface, you want to display all user related details whereas on mobile you only want to fetch some of the details. Since the amount of data being fetched is different, do you write separate method for each or only one method where you fetch everything? There is tread-off between # of LOC and amount of data being fetched.

Thank you for your time.
Roger Sterling
Ranch Hand

Joined: Apr 06, 2012
Posts: 426

Presentation layer should always be separate from the data layer. There is no reason the data layer needs to be duplicated to support more than one presentation layer. Ideally, your data layer should be Service-based, which is composable to form new and unique uses. See Service Oriented Architecture / Composable Services.
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 507
Roger Sterling wrote:Presentation layer should always be separate from the data layer. There is no reason the data layer needs to be duplicated to support more than one presentation layer. Ideally, your data layer should be Service-based, which is composable to form new and unique uses. See Service Oriented Architecture / Composable Services.


Should I have two methods at service layer? One that feeds web app,and another which operates on the output of first method and strip it down and return the result to mobile app. Is this right?
Roger Sterling
Ranch Hand

Joined: Apr 06, 2012
Posts: 426

Saurabh Pillai wrote:
Roger Sterling wrote:Presentation layer should always be separate from the data layer. There is no reason the data layer needs to be duplicated to support more than one presentation layer. Ideally, your data layer should be Service-based, which is composable to form new and unique uses. See Service Oriented Architecture / Composable Services.


Should I have two methods at service layer? One that feeds web app,and another which operates on the output of first method and strip it down and return the result to mobile app. Is this right?


Why do you need two ? Whats wrong with using one ? Two presentation layers making the same call to the one data layer. Did you look at the article I posted earlier in this thread ? About Service Composability?
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 507
Roger Sterling wrote:Why do you need two ? Whats wrong with using one ? Two presentation layers making the same call to the one data layer. Did you look at the article I posted earlier in this thread ? About Service Composability?


Web app needs more user related data whereas mobile app needs lesser user related data. That's why I mentioned about 2 methods. Because if I use the same method that I am using for web app then I would transfer unnecessary data to mobile app. They both accept different amount of user related data. For example, Web app needs 30 attributes of user whereas mobile app only need 10 attributes. I hope I am clear enough.

And yes I read the article.

Thank you
Roger Sterling
Ranch Hand

Joined: Apr 06, 2012
Posts: 426

You are talking about filtering , which could be done via a view. The callable interface could support a parameter that selects various available views. One view brings back a certain set of data whereas a second view brings back a more constrained (ie limited) set of data. Thanks for reading the article.
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 507
Roger Sterling wrote:You are talking about filtering , which could be done via a view. The callable interface could support a parameter that selects various available views. One view brings back a certain set of data whereas a second view brings back a more constrained (ie limited) set of data. Thanks for reading the article.


Why I should I fetch some data from DB that I am certainly going to discard at view layer? This is what bothering me. If I understood you correctly, I will use single method that serves both views, web app and mobile app. So when mobile app requests it, I fetch the data then strip it down to what is necessary and then send it to mobile app. Why should not I fetch data that is necessary for ONLY mobile app? Why should not I write 2 methods one for web app (fetches 30 attributes) and one for mobile app(fetches 10 attributes)? This way it will reduce load on DB since for mobile request, it only fetches 10 fields as opposed to fetching 30 fields for web app.

PS :- Not trying to argue but just want to be 100% clear.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: General data fetching best practice