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 閱讀(522) 評論(0)  編輯  收藏 所屬分類: JavaEE技術

          主站蜘蛛池模板: 土默特右旗| 蓝田县| 贺州市| 寿阳县| 政和县| 民和| 恩施市| 健康| 博爱县| 屏东县| 新巴尔虎左旗| 吴忠市| 甘南县| 宜春市| 阿克陶县| 寿阳县| 土默特右旗| 吉首市| 谷城县| 汉川市| 绥滨县| 遵化市| 本溪市| 壶关县| 贵南县| 柘城县| 集贤县| 顺义区| 郁南县| 海林市| 潼南县| 建阳市| 新和县| 武义县| 鹤峰县| 墨竹工卡县| 杭锦旗| 三门县| 阜宁县| 临海市| 永康市|