<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配置 在同一容器中部署多個(gè)應(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>
        <!--可載入多個(gè)配置文件分隔符 , ;  \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>

    配置延遲加載時(shí)使用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>
           <!--指定對(duì)Spring配置中哪個(gè)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的配置獨(dú)立到一個(gè)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個(gè)事務(wù)策略:
    1、  PROPAGATION_REQUIRED -- 支持當(dāng)前的事務(wù),如果不存在就創(chuàng)建一個(gè)新的。這是最常用的選擇。
    2 、 PROPAGATION_SUPPORTS -- 支持當(dāng)前的事務(wù),如果不存在就不使用事務(wù)。
    3 、 PROPAGATION_MANDATORY -- 支持當(dāng)前的事務(wù),如果不存在就拋出異常。
    4 、 PROPAGATION_REQUIRES_NEW -- 創(chuàng)建一個(gè)新的事務(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個(gè)隔離策略:  
      ISOLATION_DEFAULT  
      ISOLATION_READ_UNCOMMITED  
      ISOLATION_COMMITED  
      ISOLATION_REPEATABLE_READ  
      ISOLATION_SERIALIZABLE
     ●   未授權(quán)讀取(Read Uncommitted):允許臟讀取,但不允許更新丟失。如果一個(gè)事務(wù)已經(jīng)開始寫數(shù)據(jù),則另外一個(gè)數(shù)據(jù)則不允許同時(shí)進(jìn)行寫操作,但允許其他事務(wù)讀此行數(shù)據(jù)。該隔離級(jí)別可以通過“排他寫鎖”實(shí)現(xiàn)。
     ●   授權(quán)讀取(Read Committed):允許不可重復(fù)讀取,但不允許臟讀取。這可以通過“瞬間共享讀鎖”和“排他寫鎖”實(shí)現(xiàn)。讀取數(shù)據(jù)的事務(wù)允許其他事務(wù)繼續(xù)訪問該行數(shù)據(jù),但是未提交的寫事務(wù)將會(huì)禁止其他事務(wù)訪問該行。
     ●   可重復(fù)讀取(Repeatable Read):禁止不可重復(fù)讀取和臟讀取,但是有時(shí)可能出現(xiàn)幻影數(shù)據(jù)。這可以通過“共享讀鎖”和“排他寫鎖”實(shí)現(xiàn)。讀取數(shù)據(jù)的事務(wù)將會(huì)禁止寫事務(wù)(但允許讀事務(wù)),寫事務(wù)則禁止任何其他事務(wù)。
     ●   序列化(Serializable):提供嚴(yán)格的事務(wù)隔離。它要求事務(wù)序列化執(zhí)行,事務(wù)只能一個(gè)接著一個(gè)地執(zhí)行,但不能并發(fā)執(zhí)行。如果僅僅通過“行級(jí)鎖”是無法實(shí)現(xiàn)事務(wù)序列化的,必須通過其他機(jī)制保證新插入的數(shù)據(jù)不會(huì)被剛執(zhí)行查詢操作的事務(wù)訪問到。


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

                                     Dirty reads          non-repeatable reads            phantom reads
    SERIALIZABLE                   不會(huì)                   不會(huì)                               不會(huì)
    REPEATABLE READ            不會(huì)                   不會(huì)                               會(huì)
    READ COMMITTED             不會(huì)                   會(huì)                                  會(huì)
    READ UNCOMMITTED         會(huì)                      會(huì)                                  會(huì)




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

    留言簿(1)

    隨筆分類

    文章分類(25)

    文章檔案(23)

    新聞檔案(8)

    相冊

    最新隨筆

    搜索

    •  

    最新評(píng)論

    主站蜘蛛池模板: 黄色网页免费观看| 亚洲中文字幕丝袜制服一区| 高清永久免费观看| 亚洲国产精品ⅴa在线观看| 内射少妇36P亚洲区| 亚洲男人的天堂www| 亚洲成aⅴ人片久青草影院| 在线观看成人免费| 日韩精品无码区免费专区| 无码人妻一区二区三区免费看| 色爽黄1000部免费软件下载| 亚洲日韩乱码中文字幕| 亚洲国产日韩在线成人蜜芽| 久热综合在线亚洲精品| 亚洲中文久久精品无码ww16| 免费永久在线观看黄网站| 女性无套免费网站在线看| 国产一卡2卡3卡4卡无卡免费视频| 日韩免费在线视频| 九九精品成人免费国产片| 中国videos性高清免费| jizz在线免费播放| 一二三四在线观看免费中文在线观看| 色五月五月丁香亚洲综合网| 亚洲一级毛片视频| 亚洲伊人久久大香线蕉影院| 亚洲精品中文字幕无码AV| 2022年亚洲午夜一区二区福利 | 亚洲成a人片在线观看无码| 亚洲色婷婷综合开心网| 亚洲欧洲中文日韩久久AV乱码| 国产婷婷高清在线观看免费| 日韩一级免费视频| 国产乱色精品成人免费视频| 免费高清小黄站在线观看| 午夜小视频免费观看| 国产又粗又长又硬免费视频| 国产成人3p视频免费观看| 全部免费毛片在线| 亚洲中文字幕不卡无码| 亚洲成年轻人电影网站www|