Results 1 to 3 of 3

Thread: Legacy Webapp upgrade

Hybrid View

  1. #1

    Default Legacy Webapp upgrade

    OK, I've had a look at all the examples and scoured the forums but I'm still not too sure about this one.

    I'm in the process of migrating a legacy web from webshpere 3.something to websphere 6.0 - yeah I know.

    I'm pushed for time as it is, so is the following a) feasible, b) the right way forward (given the time contraint).

    Currently each jsp page is grabbing a connection from a general utility bean, passing that connection into each bean used by the jsp, then (sometimes) closing that connection off at the end of the jsp page.

    What I'm proposing, is to replace that existing utility bean with a spring db datasource bean, and pass the connection from that bean into the other beans within the jsps.
    So the context contain something like;

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
    p:driverClassName="${jdbc.driverClassName}"
    p:url="${jdbc.url}" p:username="${jdbc.username}"
    password="${jdbc.password}"/>


    <bean id="mynewds" class="com.blah.wang.mynewds">
    <property name="dataSource">
    <ref local="dataSource"/>
    </property>
    </bean>

    The datasource bean would be pretty much empty.

    mynewds.java
    public class mynewds extends JdbcDaoSupport{}

    --------
    and the jsps could just do the following...

    ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext .xml");

    mynewds ds = (dataconimpl) ctx.getBean("dataconimpl");
    myLegacybean.setDatasource( ds.getDataSource() );
    etc...

    The leagacy classes wouldn't need changing (at this point in time).
    MyLegacyBean.java ...
    Connection c = datasource.getConnection();
    statement s = c.createStatement() etc...

    So is this right? Would the connections still get closed by Spring?

    Thanks

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Currently each jsp page is grabbing a connection from a general utility bean, passing that connection into each bean used by the jsp, then (sometimes) closing that connection off at the end of the jsp page.
    Shiver and shudder...... Using a connection (i.e. database access straight from your screen?!) in a jsp makes me always shiver.

    and the jsps could just do the following...

    ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext .xml");
    If you want your application to come to a grinding halt after x request/pages this is the way to go...

    Simply let the ContextLoaderListener load your application context ONCE then use the WebApplicationContextUtils to get just that application context and reuse it.

    Code:
    ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(application);
    So is this right? Would the connections still get closed by Spring?
    No. Spring isn't under control here so will not close anything for you.

    The datasource bean would be pretty much empty.

    mynewds.java
    public class mynewds extends JdbcDaoSupport{}
    Why would you need a bean?! Why not get the configured datasource directly instead of creating yet again a new class....

    The best way to go is to implement a correct MVC pattern, however you are under some constraints as you already mentioned.

    What I would do is eliminate that datasource/connection grabbing from the jsp and make all of those legacy beans spring configured beans. Then instead of retrieving the datasource and putting it inside your legacybean in the jsp, simply retrieve the legacy bean from the applicationContext. Configure datasource and transactions in your application context and spring will manage the connections for you.

    If you have more time at hand it is probably a next step to modify your legacy beans to use the JdbcTemplate instead of working with the DataSource/Connection directly.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3

    Default

    Thanks for the prompt reply, looks like I've got a bit of work to do then eh?

    "get the configured datasource directly instead of creating yet again a new class..." - yeah, thats the whole point of this framework isn't it - can you tell I'm new to this?

    I'll have a look at the ContextLoaderListener - I knew there must be a better way of loading the app context.

    Ok, I'll have a bash at this today and see how I get on.

    Thanks again!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •