????我們可能已經(jīng)很熟悉在未使用數(shù)據(jù)庫(kù)連接池的hibernate的環(huán)境下,配置p6spy和sql profiler.這在單獨(dú)使用hibernate,以及項(xiàng)目初期是有效的.但是,在真實(shí)的開(kāi)發(fā)環(huán)境下,往往是項(xiàng)目進(jìn)行到中后期時(shí),才考慮到優(yōu)化系統(tǒng)的性能,才考慮優(yōu)化sql和數(shù)據(jù)庫(kù)設(shè)計(jì),而且在很多的項(xiàng)目中都會(huì)采用數(shù)據(jù)庫(kù)連接池.為了減少配置文件在jdbc和datasource之間的配置切換,能不能考慮在使用數(shù)據(jù)庫(kù)連接池的hibernate環(huán)境下配置p6spy和sqlfiler呢?
????下面就以spring,hibernate環(huán)境為例來(lái)說(shuō)明在使用數(shù)據(jù)庫(kù)連接池情況下配置p6spy和sql profiler:
????1.下載p6spy和sqlprofiler
?????????http://www.p6spy.com
?????????http://www.jahia.org
???2.把解壓后得到的p6spy.jar加入項(xiàng)目文件的CLASSPATH.
???
????3.把解壓sql profiler后得到的spy.properties放入運(yùn)行環(huán)境的根目錄(Eclipse中,將其置于src目錄節(jié)點(diǎn)之下),修改spy.properties如下:
??????????????????????????????# the mysql open source driver
??????????????????????????????realdriver=net.sourceforge.jtds.jdbc.Driver??????? //這里填寫(xiě)你用的實(shí)際數(shù)據(jù)庫(kù)驅(qū)動(dòng)
???
?????4.配置spring文件
?????????<bean id="dataSource"
??????????????class="org.apache.commons.dbcp.BasicDataSource"
??????????????destroy-method="close">
????????????????????<property name="driverClassName" value="${jdbc.driverClassName}" />
????????????????????<property name="url" value="${jdbc.url}" />
????????????????????<property name="username" value="${jdbc.username}" />
??????????????????????<property name="password" value="${jdbc.password}" />
?????????</bean>
??????????<bean id="myDataSource" class="com.p6spy.engine.spy.P6DataSource"
????????????????????????????????????????????????? destroy-method="close">
??????????????????<constructor-arg>
?????????????????????????<ref local="dataSource"/>
????????????????????</constructor-arg>
???????????</bean>
??????????<!--Hibernate SessionFatory-->
??????????<bean id="sessionFactory"
?????????????????class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
?????????????????<property name="dataSource" ref="myDataSource" />
?????????????????<property name="mappingDirectoryLocations">
??????????????????<list>
??????????????????????<value>
??????????????????????????classpath:/com/got/caip/domain/
??????????????????????</value>
??????????????????</list>
?????????????????</property>
?????????????????<property name="hibernateProperties">
?????????????????????<props>
?????????????????????????<prop key="hibernate.dialect">
?????????????????????????????org.hibernate.dialect.SQLServerDialect
?????????????????????????</prop>
?????????????????????????<prop key="hibernate.show_sql">
????????????????????????????????${hibernate.show_sql}
?????????????????????????</prop>
?????????????????????????<prop key="hibernate.cache.use_query_cache">
????????????????????????????????${hibernate.cache.use_query_cache}
??????????????????????????</prop>
???????????????????<prop key="hibernate.cache.provider_class">
??????????????????????????${hibernate.cache.provider_class}
???????????????????</prop>
???????????????????<prop key="hibernate.jdbc.batch_size">
???????????????????????20
??????????????????</prop>
???????????????????<prop key="net.sf.ehcache.configurationResourceName">
??????????????????????????/ehcache.xml
???????????????????</prop>
??????????????????</props>
???????????????????</property>
?????????????</bean>
??????5.通過(guò)java -jar sqlprofiler啟動(dòng)sql profiler
posted on 2007-03-26 15:19
zhangxl 閱讀(680)
評(píng)論(0) 編輯 收藏 所屬分類(lèi):
ORM(包括hibernate等)