Spring Framework Orm Di

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    2 Favorites

    Spring Framework Orm Di - Presentation Transcript

    1. Code Sample
    2. Dependency Injection (1) package au.com.sgb.example.t1.service; … public class TradeServiceImpl implements TradeService { TradeDAO dao; public TradeServiceImpl(TradeDAO dao) { this.dao = dao; } @Transactional public Trade newTrade(Equity e, String s, Double qty) { Trade t = new Trade(e, s, qty); return save(t); } … public Trade save(Trade data) { return dao.save(data); }
    3. Dependency Injection (2) <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <!DOCTYPE beans PUBLIC &quot;-//SPRING//DTD BEAN//EN&quot; &quot;http://www.springframework.org/dtd/spring-beans.dtd&quot;> <beans <bean id=&quot; tradeDAO &quot; class=&quot;au.com.sgb.example.t1.dao.hibernate.TradeDAOImpl&quot; > <property name=&quot;sessionFactory&quot; ref=&quot;sessionFactory&quot;/> </bean> <bean id=&quot; tradeService &quot; class=&quot; au.com.sgb.example.t1.service.TradeServiceImpl &quot;> <constructor-arg ref=&quot; tradeDAO &quot; /> </bean …
    4. DAO Implemenation Using Hibernate (1) package au.com.sgb.example.t1.dao.hibernate; … public class EquityDAOImpl extends HibernateDaoSupport implements EquityDAO { @Override public List<Equity> findByName(String name) { return getHibernateTemplate().find(&quot;from Equity e where e.name like ?&quot;, &quot;%&quot; + name + &quot;%&quot;); } @Override public List<Equity> findAll() { return getHibernateTemplate().find(&quot;from Equity e&quot;); }
    5. DAO Implemenation Using Hibernate (2) @Override public Equity findById(int id) { List equities = getHibernateTemplate().find(&quot;from Equity e where e.equity_id = ?&quot;, id); if (equities == null || equities.size() == 0) { return null; } else { return (Equity) equities.get(0); } } @Override public Equity save(Equity data) { getHibernateTemplate().saveOrUpdate(data); return data; } }
    6. Web Tier (1) <bean name=&quot; urlMapper &quot; class=&quot;org.springframework.web.servlet.handler.SimpleUrlHandlerMapping&quot; > <property name=&quot;mappings&quot;> <props> <prop key=&quot; /listequity.htm &quot;>listEquityController</prop> <prop key=&quot;/doequity.htm&quot;>doEquityController</prop> <prop key=&quot;/listtrade.htm&quot;>listTradeController</prop> <prop key=&quot;/dotrade.htm&quot;>doTradeController</prop> </props> </property> </bean> … <bean id=&quot; viewResolver &quot; class=&quot;org.springframework.web.servlet.view.InternalResourceViewResolver&quot;> <property name=&quot;viewClass&quot;><value>org.springframework.web.servlet.view.JstlView</value></property> <property name=&quot;prefix&quot;><value>/WEB-INF/jsp/</value></property> <property name=&quot;suffix&quot;><value>.jsp</value></property> </bean>
    7. Web Tier (2) public class TradeListController extends AbstractController { TradeService tradeService; TradeListController(TradeService service) { this.tradeService = service; } @Override protected ModelAndView handleRequestInternal(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception { List<Trade> ts = tradeService.findAll(); Map<String, Object> vals = new HashMap<String, Object>(); vals.put(&quot;trades&quot;, ts); return new ModelAndView(&quot;listtrade&quot;, vals); } }

    + ahwkong2000ahwkong2000, 2 years ago

    custom

    490 views, 2 favs, 1 embeds more stats

    Example code

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 490
      • 489 on SlideShare
      • 1 from embeds
    • Comments 0
    • Favorites 2
    • Downloads 19
    Most viewed embeds
    • 1 views on http://static.slideshare.net

    more

    All embeds
    • 1 views on http://static.slideshare.net

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags