Updated HibernateItemReaderHelper to use reflection for Session#close()

Hibernate 5 changed the signature of the Session#close() method from
returning a Connection to being void.  To support both verions, we've
moved to making the call via reflection.

This commit also upgrades the ActiveMQ version used in testing to be
compliant with the Spring IO Platform.

Resolves BATCH-2496
This commit is contained in:
Michael Minella
2016-04-19 12:38:45 -05:00
parent 851fc6629c
commit 7c081c6daf
5 changed files with 23 additions and 21 deletions

View File

@@ -11,6 +11,7 @@ buildscript {
classpath 'io.spring.gradle:docbook-reference-plugin:0.3.1'
classpath 'org.springframework.build.gradle:propdeps-plugin:0.0.7'
classpath 'io.spring.gradle:spring-io-plugin:0.0.5.RELEASE'
classpath "io.spring.gradle:dependency-management-plugin:0.5.1.RELEASE"
}
}
@@ -22,7 +23,7 @@ ext {
linkScmConnection = 'git://github.com/spring-projects/spring-batch.git'
linkScmDevConnection = 'git@github.com:spring-projects/spring-batch.git'
mainProjects = subprojects.findAll { !it.name.endsWith('tests') && !it.name.endsWith('samples') }
mainProjects = subprojects.findAll { !it.name.endsWith('tests') && !it.name.endsWith('samples') && it.name.startsWith('spring-batch-')}
}
allprojects {
@@ -54,7 +55,7 @@ allprojects {
springIntegrationVersion = '4.0.1.RELEASE'
springLdapVersion = '2.0.2.RELEASE'
activemqVersion = '5.9.1'
activemqVersion = '5.13.2'
aspectjVersion = '1.8.0'
castorVersion = '1.3.2'
commonsCollectionsVersion = '3.2.1'
@@ -218,12 +219,10 @@ configure(mainProjects) {
maven { url "https://repo.spring.io/libs-snapshot" }
}
dependencies {
dependencyManagement {
springIoTestRuntime {
imports {
mavenBom "io.spring.platform:platform-bom:${platformVersion}"
}
dependencyManagement {
springIoTestRuntime {
imports {
mavenBom "io.spring.platform:platform-bom:${platformVersion}"
}
}
}

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.batch.item.database;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -28,6 +29,7 @@ import org.hibernate.StatelessSession;
import org.springframework.batch.item.database.orm.HibernateQueryProvider;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
/**
@@ -197,7 +199,9 @@ public class HibernateItemReaderHelper<T> implements InitializingBean {
statelessSession = null;
}
if (statefulSession != null) {
statefulSession.close();
Method close = ReflectionUtils.findMethod(Session.class, "close");
ReflectionUtils.invokeMethod(close, statefulSession);
statefulSession = null;
}
}

View File

@@ -15,16 +15,17 @@
*/
package org.springframework.batch.item.database;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.Test;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.sample.Foo;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* Tests for {@link HibernateCursorItemReader} using standard hibernate {@link Session}.
*
@@ -53,7 +54,6 @@ public class HibernateCursorItemReaderStatefulIntegrationTests extends AbstractH
when(sessionFactory.openSession()).thenReturn(session);
when(session.createQuery("testQuery")).thenReturn(scrollableResults);
when(scrollableResults.setFetchSize(0)).thenReturn(scrollableResults);
when(session.close()).thenReturn(null);
itemReader.open(new ExecutionContext());
itemReader.close();

View File

@@ -12,15 +12,13 @@
*/
package org.springframework.batch.integration.partition;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
@@ -34,6 +32,9 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author Dave Syer
*
@@ -67,7 +68,7 @@ public class JmsIntegrationTests {
int after = jobInstances.size();
assertEquals(1, after - before);
JobExecution jobExecution = jobExplorer.getJobExecutions(jobInstances.get(jobInstances.size() - 1)).get(0);
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
assertEquals(jobExecution.getExitStatus().getExitDescription(), BatchStatus.COMPLETED, jobExecution.getStatus());
assertEquals(3, jobExecution.getStepExecutions().size());
for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
// BATCH-1703: we are using a map dao so the step executions in the job execution are old and we need to
@@ -77,5 +78,4 @@ public class JmsIntegrationTests {
assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
}
}
}

View File

@@ -15,9 +15,8 @@
</bean>
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" depends-on="brokerService">
<property name="brokerURL">
<value>vm://localhost</value>
</property>
<property name="brokerURL" value="vm://localhost"/>
<property name="trustAllPackages" value="true"/>
</bean>
<bean id="brokerService" class="org.apache.activemq.broker.BrokerService" init-method="start"