Boas.
Eu estou a desenvolver uma aplicação que usa o Hibernate para persistir os dados. Agora estou a tentar implementar isto usando database pooling mas a tarefa nao está a ser nada fácil.
Aqui está o meu “antigo” (sem database pooling) aplicationContext.xml:
[i]<?xml version=“1.0” encoding=“UTF-8”?>
<!DOCTYPE beans PUBLIC “-//SPRING//DTD BEAN//EN”
“http://www.springframework.org/dtd/spring-beans.dtd”>
<beans>
<bean id="personDAO"
class=“form.dao.hibernate.PersonDAOImpl”>
<property name=“hibernateTemplate”>
<ref local=“hibernateTemplate”/>
</property>
</bean>
<bean id="dataSource"
class=“org.springframework.jdbc.datasource.DriverManagerDataSource”>
<property name=“driverClassName” value=“com.mysql.jdbc.Driver” />
<property name=“url” value=“jdbc:mysql://localhost:3306/bi” />
<property name=“username” value=“root” />
<property name=“password” value=“1234” />
</bean>
<bean id="sessionFactory"
class=“org.springframework.orm.hibernate3.LocalSessionFactoryBean”>
<property name=“dataSource”>
<ref bean=“dataSource”/>
</property>
<property name=“mappingResources”>
<list>
<value>form/action/Person.hbm.xml</value>
</list>
</property>
<property name=“hibernateProperties”>
<props>
<prop key=“hibernate.dialect”>org.hibernate.dialect.MySQLDialect</prop>
<prop key=“hibernate.show_sql”>true</prop>
</props>
</property>
</bean>
<bean id="hibernateTemplate"
class=“org.springframework.orm.hibernate3.HibernateTemplate” >
<property name=“sessionFactory”>
<ref local=“sessionFactory”/>
</property>
</bean>
<bean id=“personAction” class=“form.action.PersonAction”>
<constructor-arg ref=“personDAO” />
</bean>
</beans>[/i]
Aqui está o novo aplicationContext.xml:
[i]<?xml version=“1.0” encoding=“UTF-8”?>
<!DOCTYPE beans PUBLIC “-//SPRING//DTD BEAN//EN”
“http://www.springframework.org/dtd/spring-beans.dtd”>
<beans>
<!-- datasource (database connection) -->
<!-- poolable connection -->
<bean id=“poolableConnectionFactory” class=“org.apache.commons.dbcp.PoolableConnectionFactory”>
<constructor-arg index=“0”><ref bean=“dsConnectionFactory”/></constructor-arg>
<constructor-arg index=“1”><ref bean=“pool”/></constructor-arg>
<constructor-arg index=“2”><null/></constructor-arg>
<constructor-arg index=“3”><null/></constructor-arg>
<constructor-arg index=“4”><value>false</value></constructor-arg>
<constructor-arg index=“5”><value>true</value></constructor-arg>
</bean>
<bean id=“dsConnectionFactory” class=“org.apache.commons.dbcp.DataSourceConnectionFactory”>
<constructor-arg><ref bean=“cpmsDS”/></constructor-arg>
</bean>
<bean id=“pool” class=“org.apache.commons.pool.impl.GenericObjectPool”>
<property name=“minEvictableIdleTimeMillis”><value>300000</value></property>
<property name=“timeBetweenEvictionRunsMillis”><value>60000</value></property>
</bean>
<bean id=“cpmsDS” class=“org.springframework.jdbc.datasource.DriverManagerDataSource”>
<property name=“driverClassName”><value>com.mysql.jdbc.Driver</value></property>
<property name=“url”><value>jdbc:mysql://localhost:3306/bi</value></property>
<property name=“username”><value>root</value></property>
<property name=“password”><value>1234</value></property>
</bean>
<!-- Hibernate SessionFactory -->
<bean id=“pooledDS” class=“org.apache.commons.dbcp.PoolingDataSource” depends-on=“poolableConnectionFactory”>
<constructor-arg><ref bean=“pool”/></constructor-arg>
</bean>
<!-- References all OR mapping files. -->
<bean id=“sessionFactory” class=“org.springframework.orm.hibernate3.LocalSessionFactoryBean”>
<property name=“dataSource”><ref local=“pooledDS”/></property>
<property name=“mappingResources”>
<list>
<value>form/action/Person.hbm.xml</value>
</list>
</property>
<!-- Set the type of database; changing this one property will port this to Oracle, MS SQL etc. -->
<property name=“hibernateProperties”>
<props>
<prop key=“hibernate.dialect”>org.hibernate.dialect.MySQLDialect</prop>
</props>
</property>
</bean>
<!-- Transaction manager for a single Hibernate SessionFactory -->
<bean id=“transactionManager” class=“org.springframework.orm.hibernate3.HibernateTransactionManager”>
<property name=“sessionFactory”><ref local=“sessionFactory”/></property>
</bean>
<!-- parent template for the transaction proxy beans -->
<bean id=“txProxyTemplate” abstract=“true” class=“org.springframework.transaction.interceptor.TransactionProxyFactoryBean”>
<property name=“transactionManager”><ref local=“transactionManager”/></property>
<property name=“transactionAttributes”>
<props>
<prop key=“get*”>PROPAGATION_REQUIRED,readOnly</prop>
<prop key=“add*”>PROPAGATION_REQUIRED</prop>
<prop key=“delete*”>PROPAGATION_REQUIRED</prop>
<prop key=“update*”>PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- personMangerDao data access object: Hibernate implementation -->
<bean id=“personDAO” class=“form.dao.hibernate.PersonDAOImpl”>
<property name=“sessionFactory”><ref local=“sessionFactory”/></property>
</bean>
<!-- Transactional proxy for jobManagerDao data access object. -->
<bean id=“personManagerDAO” parent=“txProxyTemplate”>
<property name=“target”><ref local=“personDAO”/></property>
</bean>
<bean id=“personAction” class=“form.action.PersonAction”>
<constructor-arg ref=“personDAO”/>
</bean>
</beans>[/i]
O banco de dados é MySQL e o servidor de aplicações é o Websphere Community Edition.
A minha classe PersonAction deve ter agora algum método especial?
Não estou a perceber nada disto :???:
Se precisarem de mais alguma informação digam.
Obrigado.