Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using DAOs with composite Objects

I am trying to rewrite a bunch of DAOs here is the setting:

  • only plain JDBC (no JPA, ORM whatsoever)
  • no interfaces used
  • lots of checks before inserting an object
  • Business objects are strongly linked

My main question is: How do I persist/retrieve a business object that is composed of multiple other objects? e.g. does my CustomerDAO know the AddressDAO and retrieve the csutomers adresses from there?

like image 432
er4z0r Avatar asked Nov 12 '22 22:11

er4z0r


1 Answers

only plain JDBC (no JPA, ORM whatsoever) Business objects are strongly linked

Not sure why you don't want to use JPA while you want your business objects to be linked, but at least you should use Spring JDBC template that would relieve you from some boilerplate code.

Regarding the other constraints, I would do it as follows:

  1. I would still employ interfaces to define the DAO methods and implement them in a Spring JDBC template backed DAOImpl. Use the DAO everywhere and inject the DAOImpl.
  2. My DAOs will be simply one-to-one mapping to the underlying tables and each DAO wouldn't know about the existence of other DAOs.
  3. My Manager layer will have all the business logic that runs validation checks and prepares the set of objects that need to be persisted, calls the appropriate DAO and appropriate method (CREATE/UPDATE/DELETE) to persist the objects.
  4. Again, the Manager layer will follow the interface-based implementation and the view layer would have manager types injected with the ManagerImpls.

My two cents!

like image 166
Vikdor Avatar answered Nov 15 '22 12:11

Vikdor