cuiyi's blog(崔毅 crazycy)

          記錄點滴 鑒往事之得失 以資于發(fā)展
          數(shù)據(jù)加載中……

          Transaction續(xù)一

          (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技術

          主站蜘蛛池模板: 莆田市| 湾仔区| 盱眙县| 铜鼓县| 霸州市| 庄河市| 塔河县| 靖西县| 昭通市| 藁城市| 淮南市| 灌阳县| 彰化市| 闽清县| 黄山市| 铁岭县| 江西省| 安徽省| 措勤县| 岳池县| 阳朔县| 庐江县| 墨江| 馆陶县| 隆德县| 都江堰市| 海阳市| 屏边| 安仁县| 涞源县| 六枝特区| 德清县| 西畴县| 方正县| 榆中县| 德惠市| 旌德县| 兰考县| 岳池县| 大足县| 双柏县|