• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

database code in MVC model

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where does the database code go in case of the MVC model? We could take the example SimpleCommand.war (https://coderanch.com/how-to/java/CodeBarnSimpleCommand) as a reference. So would the database connection go in one of the 'command classes'? If yes, then the database connection code would be part of the controller and not the model right?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All database information and activity should occur in the model. The controller should not be involved in anything to do with the DB.
 
Nev Mehta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So we would have some service objects (which are part of the model) which return populated Model objects to the Controller? Something like this.

So in that sense could we say that the UserService is also part of the model?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, if you are a fan of the service pattern, that's one way of doing it. Regardless, the point is that by keeping the presentation layer (controller/view) free from detailed information of how the model is getting/storing its data, the presentation layer stays decoupled from the details that only the model should have to deal with. This frees the model to do whatever it wants (use a database, use flat files, use stone knives and bearskins, use mock objects for testing, et cetera...)
reply
    Bookmark Topic Watch Topic
  • New Topic