hibernate+proxool整合与分别使用
让hibernate调用proxool的连接池,同时让proxool的连接池也可以在程序中直接调用,的方法
1.proxool配置,正常,如
<?xml version="1.0" encoding="utf-8"?>
<something-else-entirely>
<proxool>
<alias>dbpool</alias>
<!--proxool只能管理由自己产生的连接-->
<driver-url>
jdbc:microsoft:sqlserver://xxxxxxxx;DatabaseName=xxxxxxxxx
</driver-url>
<driver-class>
com.microsoft.jdbc.sqlserver.SQLServerDriver
</driver-class>
<driver-properties>
<property name="user" value="xxxx" />
<property name="password" value="xxxxxxxx" />
</driver-properties>
<!-- proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁-->
<house-keeping-sleep-time>90000</house-keeping-sleep-time>
<!-- 指因未有空闲连接可以分配而在队列中等候的最大请求数,超过这个请求数的用户连接就不会被接受-->
<maximum-new-connections>20</maximum-new-connections>
<!-- 最少保持的空闲连接数-->
<prototype-count>5</prototype-count>
<!-- 允许最大连接数,超过了这个连接,再有请求时,就排在队列中等候,最大的等待请求数由maximum-new-connections决定-->
<maximum-connection-count>100</maximum-connection-count>
<!-- 最小连接数-->
<minimum-connection-count>10</minimum-connection-count>
</proxool>
</something-else-entirely>
2.要让自己程序直接使用proxool连接池,要在web.xml中配置启动
<servlet>
<servlet-name>ServletConfigurator</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.configuration.ServletConfigurator</servlet-class>
<init-param>
<param-name>xmlFile</param-name>
<param-value>WEB-INF/classes/conf/Proxool.cnf.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- 下面是配置连接池的管理servlet,正式部署时候,最好去掉-->
<servlet>
<servlet-name>Admin</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.admin.servlet.AdminServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Admin</servlet-name>
<url-pattern>/Admin</url-pattern>
</servlet-mapping>
3.hibernate的配置,如果还是正常配置,
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="proxool.pool_alias">dbpool</property>
<property name="proxool.xml">conf/Proxool.cnf.xml</property>
<property name="connection.provider_class">
org.hibernate.connection.ProxoolConnectionProvider
</property>
<property name="connection.driver_class">
com.microsoft.jdbc.sqlserver.SQLServerDriver
</property>
<property name="show_sql">true</property>
<mapping resource="com/.................m.xml" />
<mapping resource="com/..................xml" />
</session-factory>
</hibernate-configuration>
就会报
org.logicalcobwebs.proxool.ProxoolException: Parsing failed.错误
因为同名的proxool连接池已经启动,而hibernate开始运行时会自己启动关联的proxool连接池,
这时需加上
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.proxool.existing_pool">true</property>
完整的如下
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="proxool.pool_alias">cgzhpt_gy</property>
<property name="proxool.xml">conf/Proxool.cnf.xml</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.proxool.existing_pool">true</property>
<property name="connection.provider_class">
org.hibernate.connection.ProxoolConnectionProvider
</property>
<property name="connection.driver_class">
com.microsoft.jdbc.sqlserver.SQLServerDriver
</property>
<property name="show_sql">true</property>
<mapping resource="com/jsinfo/friendlink/link.hbm.xml" />
<mapping resource="com/jsinfo/flashfloat/flashfloat.hbm.xml" />
</session-factory>
</hibernate-configuration>
hibernate+proxool整合与分个使用
最新推荐文章于 2024-08-25 21:18:14 发布