Docstoc

Role and Competency management - iCALMS

Document Sample
Role and Competency management - iCALMS Powered By Docstoc
					Part III. Portable Service Abstractions and Spring MVC



Buenos Aires, June 2009.
 The problem
 The Spring Framework
 Dependency Injection
 Aspect-Oriented Programming
 Portable Service Abstractions

 Best Practices
 The problem
 The Spring Framework
 Dependency Injection
 Aspect-Oriented Programming

  Portable Service Abstractions
 Best Practices
•   Consistent integration with various standard and 3rd party APIs.

•   Allows access to these frameworks without knowing how they actually work.

•   Spring provides abstraction and integration for:

     – Transaction Management: JTA, JDBC, others

     – Data Access: JDBC, Hibernate, JDO, TopLink, iBatis

     – Email

     – Remoting

     – EJB, Web Services, RMI

     – Integrates nicely with Struts, JSF, Tapestry, Velocity and other web frameworks

•   Spring also provides it’s own web framework, Spring Web MVC
Benefits:

•   Insulates you from the underlying APIs

•   Greater reusability

•   Spring abstractions always consist of interfaces

•   This makes testing simpler

•   For data access, Spring uses a generic transaction infrastructure and DAO exception
    hierarchy that is common across all supported platforms
•      Define a DataSource bean
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
          <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
          <property name="url" value="jdbc:oracle:thin:@localhost:1521:XE"/>
          <property name="username" value=“pepe"/>
          <property name="password" value=“1234"/>
    </bean>

•      Define a Session Factory bean
<bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="annotatedClasses">
            <list>
                  <value>demo.entity.Contact</value>
            </list>
      </property>
      <property name="dataSource“ ref="dataSource" />
      <property name="hibernateProperties">
            <props>
                  <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
            </props>
      </property>
</bean>
•      Define an Hibernate Template bean
    <bean id="hibernateTemplate“ class="org.springframework.orm.hibernate3.HibernateTemplate">
          <property name="sessionFactory" ref="sessionFactory" />
    </bean>




•      Define a Transaction Manager bean
<bean id="transactionManager“       class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="sessionFactory">
            <ref bean="sessionFactory" />
      </property>
</bean>



•      Define a Parent DAO bean for CRUD operations
    <bean id="baseDao" abstract="true" class="demo.dao.HibernateGenericDAO">
          <property name="hibernateTemplate" ref="hibernateTemplate" />
    </bean>
•    Define an Transaction Proxy Template bean
<bean id="parentService"      class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
      abstract="true">
      <property name="transactionManager" ref="transactionManager" />
      <property name="transactionAttributes">
            <props>
                  <prop key="*">PROPAGATION_REQUIRED</prop>
            </props>
      </property>
</bean>




•    Service interface and implementation
<bean id="contactServiceImpl" class="demo.service.impl.ContactServiceImpl">
      <property name="contactDAO" ref="contactDAOImpl"/>
</bean>

<bean id="contactService" parent="parentService">
      <property name="target" ref="contactServiceImpl"/>
      <property name="proxyInterfaces" value="demo.service.ContactService" />
</bean>
•   DAO interface and implementation
<bean id="contactDAOImpl" class="demo.dao.impl.HibernateContactDAO" parent="baseDao" />

<bean id="contactDAO" parent="parentService">
      <property name="target" ref="contactDAOImpl" />
</bean>
•   Spring can effectively organize your middle tier objects, whether or not you choose to
    use EJB.

•   Spring can eliminate the proliferation of Singletons seen on many projects.

•   Spring can eliminate the need to use a variety of custom properties file formats, by
    handling configuration in a consistent way throughout applications and projects.

•   Spring can facilitate good programming practice by reducing the cost of
    programming to interfaces, rather than classes, almost to zero.

•   Spring is designed so that applications built with it depend on as few of its APIs as
    possible.

•   Applications built using Spring are very easy to unit test.
•   Spring can make the use of EJB an implementation choice, rather than the
    determinant of application architecture.

•   Spring helps you solve many problems without using EJB. For example, using AOP
    to deliver declarative transaction management without using an EJB container.

•   Spring provides a consistent framework for data access, whether using JDBC or an
    O/R mapping product such as TopLink, Hibernate or a JDO implementation.

•   Spring provides a consistent, simple programming model in many areas, making it an
    ideal architectural "glue."

    Spring is essentially a technology dedicated to enabling you to build applications
    using POJOs.
Thank You

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:25
posted:1/5/2013
language:English
pages:12