Announcement Announcement Module
Collapse
No announcement yet.
multiple data sources to populate model objects Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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?

      Comment


      • #4
        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)

        Comment

        Working...
        X