wood burning stoves 2.0*
The moose likes Struts and the fly likes Persistence layer on Struts app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Persistence layer on Struts app" Watch "Persistence layer on Struts app" New topic
Author

Persistence layer on Struts app

raul marzo
Greenhorn

Joined: Apr 09, 2007
Posts: 21
Hi,

I'm currently working on a website where I've been using Struts. To keep things clean, I layered the application, having my own jdbc database access classes to map the objects from the bussiness layer, but it has been a complete failure in terms of performance, so I'm thinking on using something like Hibernate, JDO, Castor, etc.

I need it to work in a short span of time, and maintaining the database queries and structure (which are a bit complicated and inherited from a fully functional app) unchanged.

Which is the persistante layer to go for?

Thanks in advance

(Sorry for my English, it's a bit rusty)

[ October 19, 2007: Message edited by: raul marzo ]
[ October 19, 2007: Message edited by: raul marzo ]

<a href="http://benderscasino.blogspot.com/" target="_blank" rel="nofollow">http://benderscasino.blogspot.com/</a>
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
This is not really a Struts question. Generally you can get better performance with optimized queries and JDBC than you can get with an object mapping tool in the middle. Do you know where the performance issues are coming from? Also if you are stuck with an existing database structure and logic that is implemented in the data layer (queries, views, stored procedures, etc) then trying to fit them to an object mapping tool can be very challenging.

- Brent
raul marzo
Greenhorn

Joined: Apr 09, 2007
Posts: 21
I think the major problem comes with the inability to mantain database connections during a user session, because I couldn't figure out how to make a connection accesible to the beans that I use in the bussiness layer, or at least, not in a direct way without passing them throught actions, trying to maintain the different layers as independent as possible.

Any suggestions about how to fix that?
John Melton
Ranch Hand

Joined: Aug 17, 2004
Posts: 49
One (drastic, but generally useful) way to handle getting database connections beans in your beans without passing them through actions is to inject the connection into the beans. You can do this using the Spring framework (or other dependency injection containers). This is extremely useful - when you allow spring to manage the instantiation of your classes, you can remove some of the complexity from passing objects around to having them injection. IMHO, it makes for much cleaner code, and simplifies your life to some extent.
Hope this helps.


[url]www.jtmelton.com[/url]
raul marzo
Greenhorn

Joined: Apr 09, 2007
Posts: 21
When you talk about using the Spring Framework, are you saying to use Spring together with Struts, or simply replace Struts for Spring? I ask this because I need to work rather soon, and I don't have the time to recode all my application again.
John Melton
Ranch Hand

Joined: Aug 17, 2004
Posts: 49
No, you would use struts in conjunction with spring. A good place to look for getting started with this might be: http://www-128.ibm.com/developerworks/java/library/j-sr2.html
Hope this helps.
raul marzo
Greenhorn

Joined: Apr 09, 2007
Posts: 21
Thanks for your replies.

One last question. If I decide to stick with my old jdbc access to database, and I implement it using the singleton pattern, would that be any good?

I mean, the problem was that I was creating a connection for every query to the database, but I think that if I only have one instance of the classes that access the database, that would be enough to maintain that connections alive, doesn't it?
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
What business layer technology are you using? There should be a database connection pooling strategy or technology that would fit your application.

- Brent
raul marzo
Greenhorn

Joined: Apr 09, 2007
Posts: 21
Thank you all.

At last, the application is up and running, and working quite well. I finnaly used a self made ConnectionPool class, combined with a singleton approach.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Persistence layer on Struts app
 
Similar Threads
Persistence layer on Struts app
Locking in Standalone mode
WSA 5.1 problem connecting to DB2 9.1
Strust2 or Spring !
Any JSP + Hibernate examples?