X

Geertjan's Blog

  • March 26, 2006

Towards More Portable Web Applications (Part 2)

Geertjan Wielenga
Product Manager
I never knew that it was even possible to deploy to any server of my choosing without setting up a different data source for each. Personally, I prefer the JBoss approach to data sources. With JBoss, you get a folder containing a long list of templates containing connection code for most/all databases. Then you just copy one of these templates into the server's lib folder, modify it with your database URL (and a few other small bits of information), restart the server, and then you're set. All you then need to do is refer to the data source in your code. Both Tomcat and the Sun Java System Application Server provide kind of cumbersome admin tools to deal with data sources. It shouldn't have to be that hard.

Now that I've discovered the Struts approach—i.e., create a data source in struts-config.xml and then reuse it in your code, regardless of which server you're going to deploy to—I'm not going to look back. It seems to me, though, that the Struts approach works best for testing applications, not for the final deployment stage, because you're not able to use the advanced features that a J2EE vendor might provide. However, you can even use the DAO pattern when you're using the Struts data source. And this is the added section I've added to the draft tutorial that I mentioned yesterday. I've fleshed it out a lot, added several NetBeans IDE features that make developing Struts applications even easier, and I think it's now pretty much done (although some explanatory text needs to be added still here and there). Here it is again:

Draft: NetBeans IDE 5.0 Tutorial for Accessing Data with a Struts Data Source

Comments welcome!

Join the discussion

Comments ( 11 )
  • ludo Sunday, March 26, 2006
    Hi,
    Did you look at the Sun File Wizards under the new File...Sun Resources Category?
    For example, the jdbc connection proposes a list of well known Databases to help defining these ugly db URLs...
    Some changes are also in the work for 5.5 regarding Data Source.
    It would be nice to have a short tutorial on these resource wizards :-)
  • DonBrown Sunday, March 26, 2006
    While I do agree a data source is best handled by an application, I wouldn't recommend using the Struts data source feature. It was deprecated in Struts 1.2 and has been removed in Struts 1.3.
  • Geertjan Sunday, March 26, 2006
    Hi Ludo. Yes, I've seen these file wizards. I'm actually working on a database tutorial for NetBeans, and one of the areas that will be covered is those wizard.

    Hi Don, yes, I've seen that the Struts data source is deprecated. But what is its replacement? Is there any way to achieve the same effect -- i.e., application-based rather than server-based data sources?

  • Geertjan Monday, March 27, 2006
    By the way, NetBeans IDE support Struts 1.2.7, hence the Struts data source works for the combination of NetBeans-Struts in 5.0. Unless I see a replacement for the Struts data source, or some Struts alternative, I'd recommend using the Struts data source over server-based data sources, even though the Struts data source is deprecated in Struts 1.2.
  • Don Brown Monday, March 27, 2006
    The reason we removed the data source feature in Struts is we decided Struts should only be concerned with the presentation tier, and a data source is an application/business tier concern. There are many open source JDBC connection pools available or you could write your own. Spring comes with great support for data source pooling, for example.
  • Don Brown Monday, March 27, 2006
    The reason we removed the data source feature in Struts is we decided Struts should only be concerned with the presentation tier, and a data source is an application/business tier concern. There are many open source JDBC connection pools available or you could write your own. Spring comes with great support for data source pooling, for example.
  • Geertjan Monday, March 27, 2006
    I gotta tell you dude, I am very disappointed. It's probably my favorite Struts feature!
  • Nazrul Islam Monday, March 27, 2006
    Hi,
    I noticed your comment about the data source. We are looking at the user experience of Sun Java System Application Server. I would be interested to hear more about it to understand the specific issues. Application Server (download) is comes with Derby database. There are sample connection pool and resources configured out of the box.
    Thanks.
    -- Nazrul
  • Nazrul Monday, March 27, 2006
    Here is the download link of Java EE 5 SDK.
  • Graham Monday, March 27, 2006
    I find that using Spring's IoC to manage DataSources works great. Unfortunately, we have multiple different containers between devel, test, and production, and setting up JNDI DataSources is too cumbersome. Spring makes it easy to inject a DataSource into your DAOs. It's super simple to inject a driver or a pool, depending on your need, and the DAO never needs to know anything about it.
  • Geertjan Tuesday, March 28, 2006
    Hi Nazrul, I know about the wizards for connection pooling with the Sun Java Syetm Application Server. In fact, one of my very first blog entries (here) is about how cool and quickly one can make a connection pool for the Sun Java System Application Server with NetBeans IDE. However, the point is that I cannot reuse that data source for other servers (JBoss, Tomcat, etc.) That is because the data source is erver-based and not application-based (i.e., not contained within the application, as with the Struts data source, which is found in the <tt>struts-config.xml</tt> file). I doubt that there's anything you can do from within a Sun perspective to change that.

    Graham, the way you describe it sounds exactly the kind of scenario that I'm looking for. The Struts data source works fine, irrespective of whether or not Struts has decided to discontinue its use. It is also good to know why Struts discontinued its use -- as pointed out by Don above -- i.e., not because it doesn't work, but because the good people at Struts wants to focus on other things.

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.