Results 1 to 4 of 4

Thread: multiple data sources to populate model objects

  1. #1
    Join Date
    Apr 2005
    Location
    Holland, MI USA
    Posts
    5

    Default multiple data sources to populate model objects

    I am using 3 different data sources for my application and I am struggling to find a clean way to populate the model objects in my DAOs. For example, in my application, I have a CourseDAO with the method:

    public Course getCourse(String courseId)

    The Course object has some attributes that come from one data source, and some that come from another. It is also composed of objects, like Section, that are also populated from multiple data sources.

    I'm extending JdbcDaoSupport with my CourseDAO. The first questions is, is there a preferred way to work with multiple data sources using JdbcDaoSupport? I'm just creating dataSourceX and dataSourceY. Second, any suggestions for using multiple data sources in a MappingSqlQuery?

    Thanks,
    Brandon

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    I'd personally create a service layer with a number of DAOs, one for each datasource. Or doesn't that suit your needs?

    rgds,
    Alef
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  3. #3
    Join Date
    Apr 2005
    Location
    Holland, MI USA
    Posts
    5

    Default

    Quote Originally Posted by Alef Arendsen
    I'd personally create a service layer with a number of DAOs, one for each datasource. Or doesn't that suit your needs?
    Yeah, I have a service layer, but shouldn't the model objects be populated in the DAO layer? Otherwised, my DAOs would just return primative data types and there would be one query against the database for every piece of information that I needed, right?

  4. #4
    Join Date
    Aug 2004
    Location
    Germany, Magdeburg
    Posts
    279

    Default

    This depends on the implementation. I am also in favour of the one datasource + one responsibility per DAO stuff. If you need three datasources to create a single object (or list of them), this is an implementation detail and should be transparent.

    Never the less nothing can stop you trying to create cooperative DAOs. I also don't think you are creating a plain model object here. Incorporating three datasources may need a stiff and catchy programming metaphor. It looks more like a bigger afford than just a 'normal' easy cheesy persistence related task.

    If the shot would be on me, I guess, I would create a DAO implementation using a factory object and passing it around on all three minor DAO implementations (one for each datasource). While going around the factory object gets feed with all the datas. After it have passed the last minor DAO, all needed datas are collected by it and the create button may be pressed - by calling a method of cause - and the object gets created.

    Another idea is having a domain object implementation that allows anemic setter methods. (like setName, setAddress, setPrice etc.). So you can create the instance one and pass this domain object around until all minor DAOs got there shots and the domain object(s) is/are fully initialized.

    Both works normally very well (check if iBatis can lend you a hand) and requires nearly no additional documentation (which is highly desirable). The factory object is preferable never the less (in my opinion..), since the object creation and initialization is monopolized and not spread during the whole 'get around and catch all datas' process.

    So there is no need for your minor DAOs to return primitive values which is in dead not desirable.


    Cheers,

    Martin (Kersten)

Similar Threads

  1. Replies: 3
    Last Post: Dec 27th, 2009, 10:11 PM
  2. Replies: 2
    Last Post: Oct 10th, 2005, 05:12 PM
  3. Multiple Data Sources + Hibernate + Spring
    By joeserel in forum Data
    Replies: 2
    Last Post: May 18th, 2005, 09:22 AM
  4. Multiple data sources in Spring
    By Yeshaswi in forum Data
    Replies: 1
    Last Post: May 4th, 2005, 04:34 AM
  5. Content Provider vs View Model
    By Martin Kersten in forum Swing
    Replies: 21
    Last Post: Mar 10th, 2005, 02:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •