隨筆-48  評(píng)論-26  文章-0  trackbacks-0

          import java.util.List;

           

          import org.hibernate.Query;

          import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

           

          /*

           * 最基本的DAO操作,已供應(yīng)其他類來(lái)調(diào)用

           */

          public class BaseDAO extends HibernateDaoSupport {

              /*

               * 添加

               */

              public boolean addObject(Object obj) {

                 boolean state = true;

                 try {

                     this.getHibernateTemplate().save(obj);

           

                 } catch (Exception e) {

                     e.printStackTrace();

                     state = false;

                 }

                 return state;

              }

           

              /*

               * 刪除

               */

              public boolean delObject(Object obj) {

                 boolean state = true;

                 try {

                     this.getHibernateTemplate().delete(obj);

                 } catch (Exception e) {

           

                     state = false;

                 }

                 return state;

           

              }

          }

           

          這個(gè)類是最原始的去DAO,封裝了一些數(shù)據(jù)的增刪查改,然后我編寫(xiě)了數(shù)據(jù)訪問(wèn)接口,數(shù)據(jù)訪問(wèn)的實(shí)現(xiàn)類繼承自這個(gè)類再實(shí)現(xiàn)接口。代碼如下:

           

          import com.custservice.base.BasdBase;

          import com.custservice.basicdao.BaseDAO;

           

          public class BasdService extends BaseDAO implements BasdBase {

           

              public boolean delete(Object obj) {

                 return super.delObject(obj);

              }

              public boolean saveObj(Object obj) {

           

                 return super.addObject(obj);

              }

          }

          當(dāng)我AOP的切入點(diǎn)配置到BaseDAO是事務(wù)是不會(huì)提交的,這個(gè)事務(wù)的切入點(diǎn)必須配置到直接訪問(wèn)數(shù)據(jù)庫(kù)類的上一層。配置文件如下:

          <tx:advice id="txAdvice" transaction-manager="transactionManager">

                 <tx:attributes>

                     <tx:method name="save*" propagation="REQUIRED" />

                     <tx:method name="update*" propagation="REQUIRED" />

                     <tx:method name="del*" propagation="REQUIRED" />

                     <tx:method name="*" read-only="true" />

                 </tx:attributes>

              </tx:advice>

           

              <aop:config>

                 <aop:pointcut id="allMethod"

                     expression="execution(* com.custservice.service.*.*(..))" />

                 <aop:advisor pointcut-ref="allMethod" advice-ref="txAdvice" />

              </aop:config>
          文章來(lái)源:http://www.aygfsteel.com/NicholasEcho/archive/2009/02/06/253649.html
          posted on 2009-02-06 23:41 Worker 閱讀(86) 評(píng)論(0)  編輯  收藏 所屬分類: Web

          主站蜘蛛池模板: 石狮市| 前郭尔| 论坛| 义乌市| 瑞安市| 高尔夫| 双鸭山市| 咸丰县| 会同县| 萨嘎县| 南木林县| 卓尼县| 新津县| 板桥市| 峨眉山市| 余庆县| 西华县| 绥中县| 西安市| 邹城市| 鹿泉市| 高邮市| 谢通门县| 阜宁县| 资中县| 河东区| 陈巴尔虎旗| 青铜峡市| 临湘市| 云南省| 和静县| 河东区| 兴安盟| 普兰店市| 西林县| 昭平县| 旌德县| 塔河县| 紫阳县| 长沙市| 呼伦贝尔市|