<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Spring例子JPetStore分析---------3jpetstore的各層之間的關(guān)系部分分析

    下面就jpetstore的賬號管理部分,來分析一下jpetstore的各層之間的關(guān)系:

    1。持久層分析

    1.1賬號管理的iBatis的xml影射部分如下:

    賬號管理涉及到四張表:

    signon 存放用戶名,密碼

    account, 存放用戶的基本信息

     profile,  存放用戶選擇的語言,以及喜愛的商品分類

     bannerdata 目前不清楚

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "

    <sqlMap namespace="Account">

    《賬號信息結(jié)果集》

      <resultMap id="result" class="org.springframework.samples.jpetstore.domain.Account">
        <result property="username" column="userid" columnIndex="1"/>
        <result property="email" column="email" columnIndex="2"/>
        <result property="firstName" column="firstname" columnIndex="3"/>
        <result property="lastName" column="lastname" columnIndex="4"/>
        <result property="status" column="status" columnIndex="5"/>
        <result property="address1" column="addr1" columnIndex="6"/>
        <result property="address2" column="addr2" columnIndex="7"/>
        <result property="city" column="city" columnIndex="8"/>
        <result property="state" column="state" columnIndex="9"/>
        <result property="zip" column="zip" columnIndex="10"/>
        <result property="country" column="country" columnIndex="11"/>
        <result property="phone" column="phone" columnIndex="12"/>
        <result property="languagePreference" column="langpref" columnIndex="13"/>
        <result property="favouriteCategoryId" column="favcategory" columnIndex="14"/>
        <result property="listOption" column="mylistopt" columnIndex="15"/>
        <result property="bannerOption" column="banneropt" columnIndex="16"/>
        <result property="bannerName" column="bannername" columnIndex="17"/>
      </resultMap>

    《根據(jù)用戶名,獲得用戶信息》

      <select id="getAccountByUsername" resultMap="result">
        select
              signon.username as userid,
              account.email,
              account.firstname,
              account.lastname,
              account.status,
              account.addr1,
              account.addr2,
              account.city,
              account.state,
              account.zip,
              account.country,
              account.phone,
              profile.langpref,
              profile.favcategory,
              profile.mylistopt,
              profile.banneropt,
              bannerdata.bannername
        from account, profile, signon, bannerdata
        where account.userid = #value#
          and signon.username = account.userid
          and profile.userid = account.userid
          and profile.favcategory = bannerdata.favcategory
      </select>

    《根據(jù)賬號,密碼,獲取賬號》

      <select id="getAccountByUsernameAndPassword" resultMap="result">
        select
          signon.username as userid,
          account.email,
          account.firstname,
          account.lastname,
          account.status,
          account.addr1,
          account.addr2,
          account.city,
          account.state,
          account.zip,
          account.country,
          account.phone,
          profile.langpref,
          profile.favcategory,
          profile.mylistopt,
          profile.banneropt,
          bannerdata.bannername
        from account, profile, signon, bannerdata
        where account.userid = #username#
          and signon.password = #password#
          and signon.username = account.userid
          and profile.userid = account.userid
          and profile.favcategory = bannerdata.favcategory
      </select>

    《獲取系統(tǒng)用戶名列表》

      <select id="getUsernameList" resultClass="java.lang.String">
        select username as value from signon
      </select>

    《更新賬號信息》

      <update id="updateAccount">
        update account set email = #email#, firstname = #firstName#, lastname = #lastName#, status = #status#, addr1 = #address1#, addr2 = #address2:varchar#, city = #city#, state = #state#, zip = #zip#, country = #country#, phone = #phone# where userid = #username#
      </update>

    《增加新賬號》

      <insert id="insertAccount">
        insert into account (email, firstname, lastname, status, addr1, addr2, city, state, zip, country, phone, userid) values (#email#, #firstName#, #lastName#, #status#, #address1#, #address2:varchar#, #city#, #state#, #zip#, #country#, #phone#, #username#)
      </insert>

    《更新用戶profile表,其中包括用戶語言選擇,以及喜歡的動物分類

      <update id="updateProfile">
        update profile set langpref = #languagePreference#, favcategory = #favouriteCategoryId#, mylistopt = #listOptionAsInt#, banneropt = #bannerOptionAsInt# where userid = #username#
      </update>

    《增加用戶profile信息〉

      <insert id="insertProfile">
        insert into profile (langpref, favcategory, mylistopt, banneropt, userid) values (#languagePreference#, #favouriteCategoryId#, #listOptionAsInt#, #bannerOptionAsInt#, #username#)
      </insert>

    〈更新用戶密碼〉

      <update id="updateSignon">
        update signon set password = #password# where username = #username#
      </update>

    增加用戶名,密碼到用戶登錄表Signon〉

      <insert id="insertSignon">
        insert into signon (password,username) values (#password#,#username#)
      </insert>

    </sqlMap>
    1.2  Account為賬號管理的POJO類,AccountDao 為賬號管理interface,規(guī)定了一系列方法:

    public interface AccountDao {

      Account getAccount(String username) throws DataAccessException;

      Account getAccount(String username, String password) throws DataAccessException;

      void insertAccount(Account account) throws DataAccessException;

      void updateAccount(Account account) throws DataAccessException;

     List getUsernameList() throws DataAccessException;

    }

    1.3Account interface 實現(xiàn):

    public class SqlMapAccountDao extends SqlMapClientDaoSupport implements AccountDao {

      public Account getAccount(String username) throws DataAccessException {
        return (Account) getSqlMapClientTemplate().queryForObject("getAccountByUsername", username);
      }

    根據(jù)用戶名,密碼,獲得賬號

      public Account getAccount(String username, String password) throws DataAccessException {
        Account account = new Account();
        account.setUsername(username);
        account.setPassword(password);
        return (Account) getSqlMapClientTemplate().queryForObject("getAccountByUsernameAndPassword", account);
      }

    創(chuàng)建賬號,需要更新account,signon,profile三張表

      public void insertAccount(Account account) throws DataAccessException {
        getSqlMapClientTemplate().insert("insertAccount", account);
        getSqlMapClientTemplate().insert("insertProfile", account);
        getSqlMapClientTemplate().insert("insertSignon", account);
      }

    更新賬號,需要更新account,signon,profile三張表

      public void updateAccount(Account account) throws DataAccessException {
        getSqlMapClientTemplate().update("updateAccount", account, 1);
        getSqlMapClientTemplate().update("updateProfile", account, 1);
        if (account.getPassword() != null && account.getPassword().length() > 0) {
          getSqlMapClientTemplate().update("updateSignon", account, 1);
        }
      }

    《獲取系統(tǒng)用戶名列表》
     
     public List getUsernameList() throws DataAccessException {
      return getSqlMapClientTemplate().queryForList("getUsernameList", null);
     }

    }

    總結(jié):

    iBatis持久層使用sql-map-config.xml配置所有ibatis .xml文件

    <sqlMapConfig>

     <sqlMap resource="org/springframework/samples/jpetstore/dao/ibatis/maps/Account.xml"/>
     <sqlMap resource="org/springframework/samples/jpetstore/dao/ibatis/maps/Category.xml"/>
     <sqlMap resource="org/springframework/samples/jpetstore/dao/ibatis/maps/Product.xml"/>
     <sqlMap resource="org/springframework/samples/jpetstore/dao/ibatis/maps/Item.xml"/>
     <sqlMap resource="org/springframework/samples/jpetstore/dao/ibatis/maps/Order.xml"/>
     <sqlMap resource="org/springframework/samples/jpetstore/dao/ibatis/maps/LineItem.xml"/>
     <sqlMap resource="org/springframework/samples/jpetstore/dao/ibatis/maps/Sequence.xml"/>

    </sqlMapConfig>

    使用dataAccessContext-config.xml配置所有DAO實現(xiàn)

    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
      <property name="configLocation" value="WEB-INF/sql-map-config.xml"/>
      <property name="dataSource" ref="dataSource"/>
     </bean>

     <bean id="accountDao" class="org.springframework.samples.jpetstore.dao.ibatis.SqlMapAccountDao">
      <property name="sqlMapClient" ref="sqlMapClient"/>
     </bean>

    2,持久層和業(yè)務(wù)邏輯層的耦合,業(yè)務(wù)邏輯接口中包含了AccountDAO的接口操作

    public interface PetStoreFacade {

     Account getAccount(String username);

     Account getAccount(String username, String password);

     void insertAccount(Account account);

     void updateAccount(Account account);

     List getUsernameList();

    。。。。。。。

    }

    業(yè)務(wù)邏輯對象PetStoreImpl 實現(xiàn)了對accountDao的再次封裝

    public class PetStoreImpl implements PetStoreFacade, OrderService {

     private AccountDao accountDao;

    public Account getAccount(String username) {
      return this.accountDao.getAccount(username);
     }

     public Account getAccount(String username, String password) {
      return this.accountDao.getAccount(username, password);
     }

     public void insertAccount(Account account) {
      this.accountDao.insertAccount(account);
     }

     public void updateAccount(Account account) {
      this.accountDao.updateAccount(account);
     }

     public List getUsernameList() {
      return this.accountDao.getUsernameList();
     }

    。。。。

    }

    總結(jié):

    持久層與業(yè)務(wù)邏輯層的耦合是在applicationContext.cml中:

    為業(yè)務(wù)邏輯層提供事務(wù)管理


    <bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
        abstract="true">
      <property name="transactionManager"><ref bean="transactionManager"/></property>
      <property name="transactionAttributes">
       <props>
        <prop key="insert*">PROPAGATION_REQUIRED</prop>
        <prop key="update*">PROPAGATION_REQUIRED</prop>
        <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
       </props>
      </property>
     </bean>

     
     <bean id="petStore" parent="baseTransactionProxy">
      <property name="target">
       <bean class="org.springframework.samples.jpetstore.domain.logic.PetStoreImpl">
        <property name="accountDao" ref="accountDao"/>
        <property name="categoryDao" ref="categoryDao"/>
        <property name="productDao" ref="productDao"/>
        <property name="itemDao" ref="itemDao"/>
        <property name="orderDao" ref="orderDao"/>
       </bean>
      </property>

    4表示層和業(yè)務(wù)邏輯層的耦合:

    表示層和業(yè)務(wù)邏輯層的耦合是通過BaseAction來實現(xiàn)的,并通過接口來訪問業(yè)務(wù)邏輯對象:

    public abstract class BaseAction extends Action {

      private PetStoreFacade petStore;

     public void setServlet(ActionServlet actionServlet) {
      super.setServlet(actionServlet);
      if (actionServlet != null) {
       ServletContext servletContext = actionServlet.getServletContext();
       WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
       this.petStore = (PetStoreFacade) wac.getBean("petStore");
      }
     }

     protected PetStoreFacade getPetStore() {
      return petStore;
     }

    }

    所有的系統(tǒng)里面的Action都是從BaseAction派生過來的,而BaseAction的派生類中,提供了對業(yè)務(wù)邏輯對象
     PetStoreFacade 的訪問。

    posted on 2007-06-18 18:05 chenguo 閱讀(370) 評論(0)  編輯  收藏 所屬分類: Spring Dev

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導(dǎo)航

    統(tǒng)計

    留言簿

    隨筆分類(1)

    文章分類(52)

    好友 小山的博客

    最新隨筆

    最新評論

    主站蜘蛛池模板: 亚洲国产精品久久| 亚洲自偷自偷偷色无码中文| 久久综合亚洲色HEZYO社区| 中文字幕免费在线看| 国产综合亚洲专区在线| 窝窝影视午夜看片免费| 国产成人无码a区在线观看视频免费| 国产精品亚洲综合五月天| 国产免费久久精品99re丫y| 亚洲av乱码一区二区三区香蕉| 全免费毛片在线播放| 亚洲中文字幕久久无码| 国产精品美女自在线观看免费| 理论亚洲区美一区二区三区| 亚洲国产成人久久综合区| 一个人看的在线免费视频| 亚洲精品午夜国产VA久久成人| a级日本高清免费看| 久久精品国产亚洲77777| 18禁网站免费无遮挡无码中文| 亚洲 欧洲 自拍 另类 校园| 四虎影视免费永久在线观看| 边摸边吃奶边做爽免费视频网站 | 亚洲变态另类一区二区三区| 免费观看男人免费桶女人视频| 国产亚洲人成在线播放| a级亚洲片精品久久久久久久 | 91精品视频在线免费观看| 亚洲一区动漫卡通在线播放| 国产又粗又长又硬免费视频| 精精国产www视频在线观看免费| 亚洲色图在线播放| 好吊妞788免费视频播放| 91av免费在线视频| 亚洲影视自拍揄拍愉拍| 国产成人免费一区二区三区| 国产拍拍拍无码视频免费| 亚洲综合小说另类图片动图| 国产亚洲老熟女视频| 日本一区二区三区免费高清| 99久久免费国产特黄|