Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What about a data layer?

 
Danl Thompson
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts provides a great MVC implementation. What about a data layer? I just got done reading Fowler's new book, which leads me to think there are several ways to implement business layers and data layers for Struts to use. One project I just finished up had 7 !! separate layers to the data layer alone. Clearly overkill, and JDBC directly from the struts action would have been good enough. What are other people doing for data layers?
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's nothing stopping you using EJB CMP for your persistence needs. However a more lightweight O/R framework like hibernate might just do the trick. I use Hibernate.
Object Relational Frameworks
Pho
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts is a model neutral framework, so you can use any data layer you want.
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Danl Thompson:
and JDBC directly from the struts action would have been good enough.

But that is something you would probably want to avoid. In general your business objects would be what is communicating with the database, not your controller objects.
 
Ted Husted
Author
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
People use all types of persistance layers with Struts: JDBC, JDO, EJB, OJB, CORBA, Torque, you name it.
But regardless of how you connect to a persistance layer, the best advice is to develop a facade (or internal API) for your application. The facade declares the inputs and outputs for each discrete function your application performs. Behind the facade, these input and outputs can connect to whatever you want. In front of the facade, a Struts Action can pass through the input (from an ActionForm) and then return the output (either in ActionForm or some type of collection or result object).
A facade also makes it easy to use more than one persistance layer. One method may use JDBC. Another method may use a search engine, like Lucene. A third may reach out to a web service. But they all look the same to whatever controller you want to use (including Struts).
The Artimus application bundled with Struts in Action uses this technique to connect to both JDBC and Lucene. Interally, we can switch from one to the other without the rest of the application knowing the difference.
A facade also makes it easy to switch between a working persitance layer and a mock persistance layer for unit testing.
HTH, Ted.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic