cuiyi's blog(崔毅 crazycy)

          記錄點滴 鑒往事之得失 以資于發展
          數據加載中……

          Transaction續一

          (Resent)  The mail topic "share some knowledge based on Felcra project"

          1) About transaction

              Inside transaction logic:

              Never use:  try{}catch(Exception e) {e.printStackTrace();};

              Never use:  try{}catch(Exception e) {};

              Never use:  try{}catch(Exception e) {log.....};


              but     use:  try{

                                    //biz logic

                                 } catch(Exception e) {

                                   //can print //can log

                                   throw e; //very very important 

                                 };

           

                Spring can define the rollback transaction exception type, but if the defined exception is not thrown from the catch-block, the whole transaction will not be rolled back. This point is very very important.

                

           2) About Error thrown.

              Try not to do biz logic at the catch-block, except throws exception directly.

              But sometime need to write log or db, which is special case.

            

              Do less thing at the catch-block, especially never include any business logic.

              If some biz logic is necessary, try to think use Boolean-Return or State-Pattern or Object-Return to replace.

              The reason? Because biz logic in catch-block will cost a lot of JVM resource and it will also cause performance problem, this is traps in JAVA.

           

           

          (Resent)  The mail topic "knowledage for ost-dao-config.xml"

          3) About ost-dao-config.xml.

          There are 2 interceptors inside "ost-dao-config.xml", which is quite different from SD FFB Book. 

           

          SD FFB only use Hibernate, whose scope includes "*Service" "HibernateDao"

          FC Raw use both Hibernate, Spring JDBC, also JMS.

           

          If only Hibernate, OpenSessionInView Pattern will manage the transaction, which should transacted SessionFactory. 

           

          If not only Hiberante, SessionFactory which is transaction-wrapped can only manage Hibernate. Spring JDBC/JMS is out of the SessionFactory scope.

           

          Now come to explain the 2 interceptors:

          1) transactionInterceptor:  It manages beans with name: <value>*dbcTemplate,*Service,*Sender,mhlImportBean</value>. It manages all except Hibernate-related.

          2) hibernateInterceptor: It manages bean: sessionFactory, which will transaction-wrapped Hiberante-related. If hibernateInterceptor is not configured, the evil thing will happen: HibernateDao will write into DB while error thrown in *Service.

           

          4) How does the 2 methods in Hibernate get data?

              HibernateDao.getObject(), which used a lot in FC Raw/SD FFB Book.

              In fact, it uses Spring HibernateTemplate.get(); which will get data from Hibernate 1st-level cache first, if get, then return; Otherwise, get from Database.

               Another one is Criteria.list(); The method will get data from database as queried.

            

          5) HibernateDao.flush()

              It is out-of any transaction-rollback scope. Should Never or less use.

           

          posted on 2010-09-06 20:44 crazycy 閱讀(518) 評論(0)  編輯  收藏 所屬分類: JavaEE技術

          主站蜘蛛池模板: 宜丰县| 日土县| 襄垣县| 耒阳市| 普格县| 慈利县| 桃园县| 连州市| 朝阳县| 惠州市| 芜湖县| 城市| 仙居县| 文登市| 六枝特区| 公主岭市| 土默特右旗| 虹口区| 铁力市| 宁河县| 南投县| 宁南县| 黄龙县| 仁寿县| 平湖市| 玉屏| 个旧市| 武城县| 盐池县| 渝中区| 登封市| 饶阳县| 蓬安县| 衡水市| 佛山市| 五台县| 新建县| 灵山县| 会理县| 柯坪县| 靖远县|