wood burning stoves 2.0*
The moose likes Struts and the fly likes What about a data layer? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "What about a data layer?" Watch "What about a data layer?" New topic
Author

What about a data layer?

Danl Thompson
Ranch Hand

Joined: Apr 04, 2001
Posts: 93
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

Joined: Nov 05, 2000
Posts: 761

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


Regards,

Pho
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
Struts is a model neutral framework, so you can use any data layer you want.


Matthew Phillips
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
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

Joined: Dec 02, 2002
Posts: 37
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.


<a href="http://husted.com/struts/book.html" target="_blank" rel="nofollow">Struts in Action</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What about a data layer?