U2SpringDao

HomePage | RecentChanges | Preferences

Reusing the [UniSessionFactory]

Application Code:

         ApplicationContext ctx = new ClassPathXmlApplicationContext( "SpringConfig.xml" );
         DataImportService service = (DataImportService) ctx.getBean( "dataImportService" );
         List<Student> missingStudents = service.findMissingStudents();
         service.addMissingStudents( missingStudents );

Spring XML config file:

   <bean id="uniSession"
         class="edu.asu.vpia.dao.UniSessionFactory"
         factory-method="openSession"
         singleton="false" />

   <bean id="importDAO" class="edu.asu.vpia.dao.spring.ImportUojDAO">
        <property name="uniSession">
           <ref local="uniSession"/>
        </property>
   </bean>

  <bean id="dataImportService" class="edu.asu.vpia.dao.spring.DataImportServiceImpl">
    <property name="studentDao">
      <ref local="studentDAO"/>
    </property>
    <property name="importDao">
       <ref local="importDAO"/>
    </property>
  </bean>


Discarded original version

Application Code:

        ApplicationContext context = new ClassPathXmlApplicationContext( Constants.DAO_CONTEXT );
        UniSessionBean uSession = (UniSessionBean) context.getBean("uniSession");

daoContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
      "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

    <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>classpath:u2.properties</value>
        </property>
    </bean>

    <bean id="uniSession"
        class="net.wsmoak.dao.spring.UniSessionBean">
        <property name="hostName"><value>${HOST_NAME}</value></property>
        <property name="userName"><value>${USER_NAME}</value></property>
        <property name="password"><value>${PASSWORD}</value></property>
        <property name="hostPort"><value>${HOST_PORT}</value></property>
        <property name="accountPath"><value>${ACCOUNT_PATH}</value></property>
        <property name="connectionString"><value>${CONNECTION_STRING}</value></property>
    </bean>

</beans>

u2.properties:

HOST_NAME=localhost
USER_NAME=user
HOST_PORT=31438
PASSWORD=pass
ACCOUNT_PATH=c:\\ibm\\ud61\\demo
CONNECTION_STRING=udcs

UniSessionBean.java:

package net.wsmoak.dao.spring;

import asjava.uniobjects.UniSession;
import asjava.uniobjects.UniSessionException;

/**
 * Wrap IBM's UniSession class which is not a proper JavaBean
 * (get/set method types don't match, multiple 'set' methods
 */
public class UniSessionBean {

    private UniSession uSession;

    public UniSessionBean() {
        uSession = new UniSession();
    }

    public String getUserName() {
        return uSession.getUserName();
    }

    public void setUserName(String userName) {
        uSession.setUserName(userName);
    }

    public String getHostName() {
        return uSession.getHostName();
    }

    public void setHostName(String hostName) {
        uSession.setHostName( hostName );
    }

    public int getHostPort() {
        return uSession.getHostPort();
    }

    public void setHostPort(int hostPort) {
        uSession.setHostPort( hostPort );
    }

    public String getPassword() {
        return uSession.getPassword();
    }

    public void setPassword(String password) {
        uSession.setPassword(password);
    }

    public String getAccountPath() {
        return uSession.getAccountPath();
    }

    public void setAccountPath(String accountPath) {
        uSession.setAccountPath( accountPath );
    }

    public String getConnectionString() {
        return uSession.getConnectionString();
    }

    public void setConnectionString(String connectionString) {
        uSession.setConnectionString(connectionString);
    }

    public UniSession openConnection() throws UniSessionException {
        uSession.connect();
        return uSession;
    }
}


HomePage | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited November 29, 2005 12:56 pm by WendySmoak (diff)
Search: