<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)論

    主站蜘蛛池模板: 四虎影视在线看免费观看| 亚洲国产综合人成综合网站00| 亚洲精品无码aⅴ中文字幕蜜桃| 亚洲天堂免费在线| 亚洲一卡2卡3卡4卡国产网站 | 免费的涩涩视频在线播放| 亚洲成_人网站图片| 无码一区二区三区AV免费| 亚洲色大成网站www永久男同| 成人在线视频免费| 国产成人精品久久亚洲高清不卡| 国产成人免费a在线视频色戒| 男女超爽视频免费播放| 国产精品亚洲αv天堂无码| 青柠影视在线观看免费高清| 亚洲av无码精品网站| 91成年人免费视频| 亚洲国产乱码最新视频| 亚洲 另类 无码 在线| 天黑黑影院在线观看视频高清免费| 亚洲AV日韩AV鸥美在线观看| 亚欧在线精品免费观看一区| 亚洲欧洲免费无码| 国产成人亚洲综合| 91免费国产自产地址入| 亚洲AV色欲色欲WWW| 亚洲伊人久久精品影院| 91久久成人免费| 色一情一乱一伦一视频免费看| 亚洲精品乱码久久久久久| 24小时日本电影免费看| 最新亚洲人成网站在线观看| 亚洲精品无码MV在线观看| 性xxxxx免费视频播放| 男人扒开添女人下部免费视频| 亚洲ⅴ国产v天堂a无码二区| 免费看美女让人桶尿口| 在线观看人成视频免费无遮挡 | 亚洲日韩AV无码一区二区三区人| 亚洲精品无码日韩国产不卡?V| 最近免费中文字幕大全高清大全1|