• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

one DAO querying 2 tables? (Spring security, user & auth)

 
Christopher Whu
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a user DAO for a project, i added spring security to it, i now have a user_role table.

From your professional experience should i create a separate DAO/DTO fro the user_role?

I am always curious to see how others do this.

I apologize in advance for my English...
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In some situations, it is better to implement a single DAO for each data source. For example, if the application is using data-oriented web services then there would be a DAO for this data. And if the application also is using a relational database then there would be a second DAO for the database. In cases where there is more than one relational database, a DAO for each database works well.
 
Christopher Whu
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in the end i just ended up creating a separate DAO & DTO for both the role(authority) and user table. I was really asking a coding style question. I am always curious to see if i am doing my programming the HIP and current way... I want to be like one of the cool kids...
 
Ryan Waggoner
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christopher,

I agree with the decision you ended up making (for what its worth).
With the functionality so finite and different, I would create 2 DAOs.

With that being said, there are times where I have created DAOs that query 2 or more tables, because I need a little bit of information from each to get all of the data I need.
In these cases, I thought it would be silly looking to have a method that is declaring and using 5 DAOs to get the data I needed.

Note: As you can tell I made my decision solely on looks.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17989
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I routinely work with very complex interrelationships and it has led me to develop a 2-tier persistency access architecture. The "service" classes access working sets of related tables and tend to contain persistence-related business logic. The "DAO" classes access individual tables and do the low-level find and CRUD functions. The service classes do not contain entityManagers. Instead, they invoke the DAOs. Transactions are bounded at the service level.
 
Christopher Whu
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for all the incite... My code usually works but i always want to see what everyone else does...

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic