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

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

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

    posts - 0,  comments - 1,  trackbacks - 0
    web.xml
    載入Log4j配置
    <
    context-param><!--Log4j配置 在同一容器中部署多個應(yīng)用不能使用默認(rèn)的webAppRootKey,必須指定唯一KEY,以免沖突-->
        
    <param-name>webAppRootKey</param-name>
        
    <param-value>itservice.root</param-value>
        <!--在log4j.properties中設(shè)置日志路徑log4j.appender.file.File=${itservice.root}/WEB-INF/itservice.log-->

    </context-param>
    <context-param>
        
    <param-name>log4jConfigLocation</param-name>
        
    <param-value>/WEB-INF/classes/log4j.properties</param-value>
    </context-param>
    <listener>
        
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>


      載入Spring配置文件
    <context-param>
        
    <param-name>contextConfigLocation</param-name>
        
    <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
        <!--可載入多個配置文件分隔符 , ;  \t \n -->

      
    </context-param>
      
    <listener>
        
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      
    </listener>

      字符編碼過濾器
    <filter>
        
    <filter-name>encodingFilter</filter-name>
        
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        
    <init-param>
          
    <param-name>encoding</param-name>
          
    <param-value>UTF-8</param-value>
        
    </init-param>
      
    </filter>
     <filter-mapping>
        
    <filter-name>encodingFilter</filter-name>
        
    <url-pattern>/*</url-pattern>
      
    </filter-mapping>
      
    <filter-mapping>

    配置延遲加載時使用OpenSessionInView
    <
    filter>
        
    <filter-name>openSessionInViewFilter</filter-name>
        
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
        
    <init-param>
          
    <param-name>singleSession</param-name>
          
    <param-value>true</param-value>
        
    </init-param>
        
    <init-param>
          
    <param-name>sessionFactoryBeanName</param-name>
           <!--指定對Spring配置中哪個sessionFactory使用OpenSessionInView-->

          
    <param-value>sessionFactory_itdb</param-value>
        
    </init-param>
      
    </filter>
        <filter-name>openSessionInViewFilter</filter-name>
        
    <url-pattern>/*</url-pattern>
      
    </filter-mapping>

    Struts-config.xml
    <action input="/index.jsp" name="loginActionForm" parameter="method" path="/loginAction" scope="session" type="org.springframework.web.struts.DelegatingActionProxy" validate="true" />
    <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
        
    <set-property property="contextConfigLocation" value="/WEB-INF/classes/action-servlet.xml" />
           
    <!--將spring配置中關(guān)于ACTION的配置獨立到一個action-servlet.xml文件中-->
      
    </plug-in>

    ApplicationContext.xml
    <!--直接使用hibernate配置文件-->
     
    <bean id="sessionFactory_itdb" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        
    <property name="configLocation">
             <value>classpath:hibernate_itdb.cfg.xml</value>
        
    </property>
      </bean>

    <!--使用JNDI DataSource-->
    <bean id="it_dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
      
    <value>jdbc/itdb</value>
    </property>
    </bean>

    <!-- Spring配置DataSource -->
      <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        
    <property name="location">
           
    <value>classpath:init.properties</value>
        
    </property>
      
    </bean>
     
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
       
    <property name="driverClassName" value="${dataSource.driverClassName}"></property>
       
    <property name="url" value="${dataSource.url}"></property>
       
    <property name="username" value="${dataSource.username}"></property>
       
    <property name="password" value="${dataSource.password}"></property>
     
    </bean>
    <!-- *********************Hibernate*********************** -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
     
    <property name="dataSource" ref="dataSource"></property>
      
    <property name="mappingResources">
      
    <list>
        
    <value>com/usish/shweb/hbm/ShwebFile.hbm.xml</value>
        
    <value>com/usish/shweb/hbm/ShwebLog.hbm.xml</value>
      
    </list>
     
    </property>
     
    <property name="hibernateProperties">
      
    <props>
         
    <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
         
    <prop key="hibernate.show_sql">false</prop>
         
    <prop key="hibernate.jdbc.fetch_size">50</prop>
         
    <prop key="hibernate.jdbc.batch_size">30</prop>
         
    <prop key="hibernate.cache.use_second_level_cache">true</prop>
         
    <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
         
    <prop key="hibernate.cache.use_query_cache">true</prop>
      
    </props>
     
    </property>
    </bean>

    <!--******************TransactionManager***********************-->
    <bean id="transactionManager"
        class
    ="org.springframework.orm.hibernate3.HibernateTransactionManager">
       
    <property name="sessionFactory">
           
    <ref local="sessionFactory" />
       
    </property>
    </bean>
    <bean id="baseTxProxy"  class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" lazy-init="true" abstract="true">
      
    <property name="transactionManager">
        
    <ref bean="transactionManager" />
      
    </property>
      
    <property name="transactionAttributes">
        
    <props>
         
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
         
    <prop key="get*">PROPAGATION_REQUIRED</prop>
         
    <prop key="save*">PROPAGATION_REQUIRED</prop>
         
    <prop key="insert*">PROPAGATION_REQUIRED</prop>
         
    <prop key="update*">PROPAGATION_REQUIRED</prop>
         
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
        
    </props>
      
    </property>
    </bean>

    <!--AOP TX-->
    <tx:advice id="txAdvice" transaction-manager="txManager">
       <tx:attributes>
         <tx:method name="get*" propagation="NEVER"/>
         <tx:method name="find*" propagation="NEVER"/>
         <tx:method name="*" propagation="REQUIRED"/>
       </tx:attributes>
     </tx:advice>
     
     <aop:config>
        <aop:pointcut id="txBusinessMethods" expression="execution(* com.ztgame.blog.business.*BusinessImpl.*(..))"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="txBusinessMethods"/>
     </aop:config>

    <!--annotation TX-->
    <tx:annotation-driven proxy-target-class="true" transaction-manager="txManager"/>
     
    Spring編程式事物
    <
    bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
          
    <property name="transactionManager">
            
    <ref bean="TransactionManager"/>
          
    </property>
        
    </bean>
        
    <bean id="courseService" class="com.test.CourseService">
          
    <property name="transactionTemplate">
            
    <ref bean="transactionTemplate"/>
          
    </property>
     
    </bean>


    private TransactionTemplate transactionTemplate;
        public void enrollStudent()...{
            transactionTemplate.execute(new TransactionCallback()...{
                public Object doInTransaction(TransactionStatus ts)...{
                    try ...{
    //                    需要事務(wù)控制的方法代碼
                    } catch (Exception e) ...{
                        ts.setRollbackOnly();  //回滾
                    }
                    return null;  //事務(wù)提交
                }   
            });
        }
    }


    7個事務(wù)策略:
    1、  PROPAGATION_REQUIRED -- 支持當(dāng)前的事務(wù),如果不存在就創(chuàng)建一個新的。這是最常用的選擇。
    2 、 PROPAGATION_SUPPORTS -- 支持當(dāng)前的事務(wù),如果不存在就不使用事務(wù)。
    3 、 PROPAGATION_MANDATORY -- 支持當(dāng)前的事務(wù),如果不存在就拋出異常。
    4 、 PROPAGATION_REQUIRES_NEW -- 創(chuàng)建一個新的事務(wù),并暫停當(dāng)前的事務(wù)(如果存在)。
    5 、 PROPAGATION_NOT_SUPPORTED -- 不使用事務(wù),并暫停當(dāng)前的事務(wù)(如果存在)。
    6 、 PROPAGATION_NEVER -- 不使用事務(wù),如果當(dāng)前存在事務(wù)就拋出異常。
    7 、 PROPAGATION_NESTED -- 如果當(dāng)前存在事務(wù)就作為嵌入事務(wù)執(zhí)行,否則與 PROPAGATION_REQUIRED 類似。

      
      5個隔離策略:  
      ISOLATION_DEFAULT  
      ISOLATION_READ_UNCOMMITED  
      ISOLATION_COMMITED  
      ISOLATION_REPEATABLE_READ  
      ISOLATION_SERIALIZABLE
     ●   未授權(quán)讀取(Read Uncommitted):允許臟讀取,但不允許更新丟失。如果一個事務(wù)已經(jīng)開始寫數(shù)據(jù),則另外一個數(shù)據(jù)則不允許同時進(jìn)行寫操作,但允許其他事務(wù)讀此行數(shù)據(jù)。該隔離級別可以通過“排他寫鎖”實現(xiàn)。
     ●   授權(quán)讀取(Read Committed):允許不可重復(fù)讀取,但不允許臟讀取。這可以通過“瞬間共享讀鎖”和“排他寫鎖”實現(xiàn)。讀取數(shù)據(jù)的事務(wù)允許其他事務(wù)繼續(xù)訪問該行數(shù)據(jù),但是未提交的寫事務(wù)將會禁止其他事務(wù)訪問該行。
     ●   可重復(fù)讀取(Repeatable Read):禁止不可重復(fù)讀取和臟讀取,但是有時可能出現(xiàn)幻影數(shù)據(jù)。這可以通過“共享讀鎖”和“排他寫鎖”實現(xiàn)。讀取數(shù)據(jù)的事務(wù)將會禁止寫事務(wù)(但允許讀事務(wù)),寫事務(wù)則禁止任何其他事務(wù)。
     ●   序列化(Serializable):提供嚴(yán)格的事務(wù)隔離。它要求事務(wù)序列化執(zhí)行,事務(wù)只能一個接著一個地執(zhí)行,但不能并發(fā)執(zhí)行。如果僅僅通過“行級鎖”是無法實現(xiàn)事務(wù)序列化的,必須通過其他機制保證新插入的數(shù)據(jù)不會被剛執(zhí)行查詢操作的事務(wù)訪問到。


     ●   更新丟失(Lost update):兩個事務(wù)都同時更新一行數(shù)據(jù),但是第二個事務(wù)卻中途失敗退出,導(dǎo)致對數(shù)據(jù)的兩個修改都失效了。這是因為系統(tǒng)沒有執(zhí)行任何的鎖操作,因此并發(fā)事務(wù)并沒有被隔離開來。
     ●   臟讀取(Dirty Reads):一個事務(wù)開始讀取了某行數(shù)據(jù),但是另外一個事務(wù)已經(jīng)更新了此數(shù)據(jù)但沒有能夠及時提交。這是相當(dāng)危險的,因為很可能所有的操作都被回滾。
     ●   不可重復(fù)讀取(Non-repeatable Reads):一個事務(wù)對同一行數(shù)據(jù)重復(fù)讀取兩次,但是卻得到了不同的結(jié)果。例如,在兩次讀取的中途,有另外一個事務(wù)對該行數(shù)據(jù)進(jìn)行了修改,并提交。
     ●   兩次更新問題(Second lost updates problem):無法重復(fù)讀取的特例。有兩個并發(fā)事務(wù)同時讀取同一行數(shù)據(jù),然后其中一個對它進(jìn)行修改提交,而另一個也進(jìn)行了修改提交。這就會造成第一次寫操作失效。
     ●   虛讀(Phantom Reads):事務(wù)在操作過程中進(jìn)行兩次查詢,第二次查詢的結(jié)果包含了第一次查詢中未出現(xiàn)的數(shù)據(jù)(這里并不要求兩次查詢的SQL語句相同)。這是因為在兩次查詢過程中有另外一個事務(wù)插入數(shù)據(jù)造成的。

                                     Dirty reads          non-repeatable reads            phantom reads
    SERIALIZABLE                   不會                   不會                               不會
    REPEATABLE READ            不會                   不會                               會
    READ COMMITTED             不會                   會                                  會
    READ UNCOMMITTED         會                      會                                  會




    posted on 2008-03-27 17:08 火焰出林 閱讀(236) 評論(0)  編輯  收藏 所屬分類: J2EE
    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    留言簿(1)

    隨筆分類

    文章分類(25)

    文章檔案(23)

    新聞檔案(8)

    相冊

    最新隨筆

    搜索

    •  

    最新評論

    主站蜘蛛池模板: 久久亚洲AV成人无码国产最大| 中文字幕无码不卡免费视频| 亚洲AV无码一区二区一二区 | 香蕉视频免费在线| 亚洲大香伊人蕉在人依线| 亚洲精品高清国产一线久久| 免费国产a国产片高清网站| 啦啦啦高清视频在线观看免费| 久久永久免费人妻精品| 一级美国片免费看| 激情小说亚洲色图| 亚洲欧美不卡高清在线| 在线亚洲高清揄拍自拍一品区| 久久精品国产亚洲AV高清热| 好看的电影网站亚洲一区| 亚洲国产精品一区二区第一页免| 啦啦啦www免费视频| 国产h视频在线观看免费| 啦啦啦完整版免费视频在线观看 | 久久久久国产精品免费免费搜索 | 免费可以看黄的视频s色| 中文字幕无码日韩专区免费| 久久久久久久国产免费看 | 波多野结衣久久高清免费| 在线看片韩国免费人成视频| 99re免费视频| 亚洲免费精彩视频在线观看| a毛片免费播放全部完整| 一个人免费观看视频在线中文| 九一在线完整视频免费观看| 在线观看亚洲免费| 黄色免费在线网址| 日本视频免费观看| 一级毛片在线完整免费观看| 一级做a爰全过程免费视频毛片| 日韩一级片免费观看| 永久免费观看黄网站| 精品一区二区三区免费视频| 你好老叔电影观看免费| 午夜免费福利小电影| 亚洲一级免费视频|