From 85048aaa1d1560e91cd14ff999768aabc44c90c7 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Tue, 7 Apr 2015 18:52:23 +0200 Subject: [PATCH] DATAJPA-703 - Added build profile for Hibernate 5. Disabled outdated Travis build profiles for Spring 4.0 and 4.1. Upgraded profiles for Hibernate 4.2 and 4.3 to the most recent releases. Fixed stored procedure integration test to really run on EclipseLink for the EclipseLink specific tests. Added workaround for EclipseLink using invalid syntax (see [0]). [0] https://bugs.eclipse.org/bugs/show_bug.cgi?id=467072 --- .travis.yml | 3 +- pom.xml | 22 ++++++- .../data/jpa/domain/sample/Dummy.java | 4 +- .../CustomEclipseLinkJpaVendorAdapter.java | 64 +++++++++++++++++++ ...seLinkStoredProcedureIntegrationTests.java | 12 +++- ...penJpaStoredProcedureIntegrationTests.java | 8 ++- .../StoredProcedureIntegrationTests.java | 63 ++++++------------ .../PartTreeJpaQueryIntegrationTests.java | 16 ++++- src/test/resources/eclipselink.xml | 2 +- 9 files changed, 135 insertions(+), 59 deletions(-) create mode 100644 src/test/java/org/springframework/data/jpa/repository/CustomEclipseLinkJpaVendorAdapter.java diff --git a/.travis.yml b/.travis.yml index e83e12486..6e3d656e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,13 +6,12 @@ jdk: env: matrix: - PROFILE=ci - - PROFILE=spring4-next - - PROFILE=spring41 - PROFILE=spring41-next - PROFILE=spring42-next - PROFILE=hibernate-41 - PROFILE=hibernate-42 - PROFILE=hibernate-43 + - PROFILE=hibernate-5 - PROFILE=querydsl-next sudo: false diff --git a/pom.xml b/pom.xml index 1396d1140..ea63a1c75 100644 --- a/pom.xml +++ b/pom.xml @@ -43,15 +43,33 @@ hibernate-42 - 4.2.11.Final + 4.2.19.Final hibernate-43 - 4.3.4.Final + 4.3.9.Final + + hibernate-5 + + 5.0.0.Beta2 + + + + hibernate-5-next + + 5.0.0-SNAPSHOT + + + + jboss + https://repository.jboss.org/nexus/content/repositories/public + + + diff --git a/src/test/java/org/springframework/data/jpa/domain/sample/Dummy.java b/src/test/java/org/springframework/data/jpa/domain/sample/Dummy.java index ead55531d..42e10bb22 100644 --- a/src/test/java/org/springframework/data/jpa/domain/sample/Dummy.java +++ b/src/test/java/org/springframework/data/jpa/domain/sample/Dummy.java @@ -47,12 +47,12 @@ import org.springframework.util.ObjectUtils; , @NamedStoredProcedureQuery(name = "Dummy.procedureWith1InputAnd1OutputParameterWithResultSet", procedureName = "procedure_in1_out0_return_rs_no_update", parameters = { - @StoredProcedureParameter(mode = ParameterMode.IN, type = Integer.class), + @StoredProcedureParameter(mode = ParameterMode.IN, type = String.class), @StoredProcedureParameter(mode = ParameterMode.REF_CURSOR, type = void.class) }) // , @NamedStoredProcedureQuery(name = "Dummy.procedureWith1InputAnd1OutputParameterWithResultSetWithUpdate", procedureName = "procedure_in1_out0_return_rs_with_update", parameters = { - @StoredProcedureParameter(mode = ParameterMode.IN, type = Integer.class), + @StoredProcedureParameter(mode = ParameterMode.IN, type = String.class), @StoredProcedureParameter(mode = ParameterMode.REF_CURSOR, type = void.class) }) // , @NamedStoredProcedureQuery(name = "Dummy.procedureWith1InputAndNoOutputParameterWithUpdate", diff --git a/src/test/java/org/springframework/data/jpa/repository/CustomEclipseLinkJpaVendorAdapter.java b/src/test/java/org/springframework/data/jpa/repository/CustomEclipseLinkJpaVendorAdapter.java new file mode 100644 index 000000000..fc0ae6cb3 --- /dev/null +++ b/src/test/java/org/springframework/data/jpa/repository/CustomEclipseLinkJpaVendorAdapter.java @@ -0,0 +1,64 @@ +/* + * Copyright 2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.jpa.repository; + +import org.eclipse.persistence.internal.databaseaccess.DatabasePlatform; +import org.eclipse.persistence.platform.database.HSQLPlatform; +import org.springframework.orm.jpa.vendor.Database; +import org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter; + +/** + * Custom {@link EclipseLinkJpaVendorAdapter} to customize the {@link DatabasePlatform} to be sued with EclipseLink to + * work around a bug in stored procedure execution on HSQLDB. + * + * @author Oliver Gierke + * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=467072 + */ +public class CustomEclipseLinkJpaVendorAdapter extends EclipseLinkJpaVendorAdapter { + + /* + * (non-Javadoc) + * @see org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter#determineTargetDatabaseName(org.springframework.orm.jpa.vendor.Database) + */ + @Override + protected String determineTargetDatabaseName(Database database) { + + if (Database.HSQL.equals(database)) { + return EclipseLinkHsqlPlatform.class.getName(); + } + + return super.determineTargetDatabaseName(database); + } + + /** + * Workaround {@link HSQLPlatform} to make sure EclipseLink uses the right syntax to call stored procedures on HSQL. + * + * @author Oliver Gierke + * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=467072 + */ + @SuppressWarnings("serial") + public static class EclipseLinkHsqlPlatform extends HSQLPlatform { + + /* + * (non-Javadoc) + * @see org.eclipse.persistence.internal.databaseaccess.DatabasePlatform#getProcedureCallHeader() + */ + @Override + public String getProcedureCallHeader() { + return "CALL "; + } + } +} diff --git a/src/test/java/org/springframework/data/jpa/repository/EclipseLinkStoredProcedureIntegrationTests.java b/src/test/java/org/springframework/data/jpa/repository/EclipseLinkStoredProcedureIntegrationTests.java index 4219e9d54..718ebcb36 100644 --- a/src/test/java/org/springframework/data/jpa/repository/EclipseLinkStoredProcedureIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/EclipseLinkStoredProcedureIntegrationTests.java @@ -15,6 +15,7 @@ */ package org.springframework.data.jpa.repository; +import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; import org.springframework.test.context.ContextConfiguration; @@ -22,7 +23,12 @@ import org.springframework.test.context.ContextConfiguration; * Testcase to run {@link StoredProcedureIntegrationTests} integration tests on top of EclipseLink. * * @author Thomas Darimont + * @author Oliver Gierke */ -@ContextConfiguration(classes = { StoredProcedureIntegrationTests.Config.class }) -@ImportResource("classpath:eclipselink.xml") -public class EclipseLinkStoredProcedureIntegrationTests extends StoredProcedureIntegrationTests {} +@ContextConfiguration +public class EclipseLinkStoredProcedureIntegrationTests extends StoredProcedureIntegrationTests { + + @Configuration + @ImportResource({ "classpath:infrastructure.xml", "classpath:eclipselink.xml" }) + static class TestConfig extends Config {} +} diff --git a/src/test/java/org/springframework/data/jpa/repository/OpenJpaStoredProcedureIntegrationTests.java b/src/test/java/org/springframework/data/jpa/repository/OpenJpaStoredProcedureIntegrationTests.java index 00c24ccf1..4e6a1cdf1 100644 --- a/src/test/java/org/springframework/data/jpa/repository/OpenJpaStoredProcedureIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/OpenJpaStoredProcedureIntegrationTests.java @@ -24,8 +24,12 @@ import org.springframework.test.context.ContextConfiguration; * supported since, the OpenJPA tests need to be executed with hsqldb1 which doesn't supported stored procedures. * * @author Thomas Darimont + * @author Oliver Gierke */ @Ignore @ContextConfiguration(classes = { StoredProcedureIntegrationTests.Config.class }) -@ImportResource("classpath:openjpa.xml") -public class OpenJpaStoredProcedureIntegrationTests extends StoredProcedureIntegrationTests {} +public class OpenJpaStoredProcedureIntegrationTests extends StoredProcedureIntegrationTests { + + @ImportResource({ "classpath:infrastructure.xml", "classpath:openjpa.xml" }) + static class TestConfig extends Config {} +} diff --git a/src/test/java/org/springframework/data/jpa/repository/StoredProcedureIntegrationTests.java b/src/test/java/org/springframework/data/jpa/repository/StoredProcedureIntegrationTests.java index cce06e9ba..0ab282a6f 100644 --- a/src/test/java/org/springframework/data/jpa/repository/StoredProcedureIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/StoredProcedureIntegrationTests.java @@ -26,6 +26,7 @@ import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -41,35 +42,33 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; /** - * @see scripts/schema-stored-procedures.sql for procedure definitions. + * Integration tests for + * * @author Thomas Darimont + * @author Oliver Gierke + * @see scripts/schema-stored-procedures.sql for procedure definitions. */ @Transactional -@ContextConfiguration +@ContextConfiguration(classes = StoredProcedureIntegrationTests.TestConfig.class) @RunWith(SpringJUnit4ClassRunner.class) public class StoredProcedureIntegrationTests { + private static final String NOT_SUPPORTED = "Stored procedures with ResultSets are currently not supported for any JPA provider"; + @PersistenceContext EntityManager em; @Autowired DummyRepository repository; - Dummy dummyA; - Dummy dummyB; - Dummy dummyC; - @Configuration @EnableJpaRepositories(basePackageClasses = DummyRepository.class, includeFilters = { @Filter( pattern = ".*DummyRepository", type = FilterType.REGEX) }) + static abstract class Config {} + @ImportResource("classpath:infrastructure.xml") - static class Config {} + static class TestConfig extends Config {} @Before public void setup() { - assumeTrue(currentEntityManagerIsAJpa21EntityManager(em)); - - dummyA = em.merge(new Dummy("A")); - dummyB = em.merge(new Dummy("B")); - dummyC = em.merge(new Dummy("C")); } /** @@ -77,7 +76,7 @@ public class StoredProcedureIntegrationTests { */ @Test public void shouldExecuteAdHocProcedureWithNoInputAnd1OutputParameter() { - assertThat(repository.adHocProcedureWithNoInputAnd1OutputParameter(), is(equalTo(42))); + assertThat(repository.adHocProcedureWithNoInputAnd1OutputParameter(), is(42)); } /** @@ -85,7 +84,7 @@ public class StoredProcedureIntegrationTests { */ @Test public void shouldExecuteAdHocProcedureWith1InputAnd1OutputParameter() { - assertThat(repository.adHocProcedureWith1InputAnd1OutputParameter(23), is(equalTo(24))); + assertThat(repository.adHocProcedureWith1InputAnd1OutputParameter(23), is(24)); } /** @@ -93,25 +92,18 @@ public class StoredProcedureIntegrationTests { */ @Test public void shouldExecuteAdHocProcedureWith1InputAndNoOutputParameter() { - repository.adHocProcedureWith1InputAndNoOutputParameter(42); - - assertTrue(true); } /** * @see DATAJPA-652 */ @Test + @Ignore(NOT_SUPPORTED) public void shouldExecuteAdHocProcedureWith1InputAnd1OutputParameterWithResultSet() { - // hibernate currently (v4.3) doesn't support returning ResultSets in output parameters - assumeFalse(currentEntityManagerIsHibernateEntityManager(em)); - List dummies = repository.adHocProcedureWith1InputAnd1OutputParameterWithResultSet("FOO"); - System.out.println("### Found dummies: " + dummies); - assertThat(dummies, is(notNullValue())); assertThat(dummies.size(), is(equalTo(3))); } @@ -120,15 +112,11 @@ public class StoredProcedureIntegrationTests { * @see DATAJPA-652 */ @Test + @Ignore(NOT_SUPPORTED) public void shouldExecuteAdHocProcedureWith1InputAnd1OutputParameterWithResultSetWithUpdate() { - // hibernate currently (v4.3) doesn't support returning ResultSets in output parameters - assumeFalse(currentEntityManagerIsHibernateEntityManager(em)); - List dummies = repository.adHocProcedureWith1InputAnd1OutputParameterWithResultSetWithUpdate("FOO"); - System.out.println("### Found dummies: " + dummies); - assertThat(dummies, is(notNullValue())); assertThat(dummies.size(), is(equalTo(3))); } @@ -138,10 +126,7 @@ public class StoredProcedureIntegrationTests { */ @Test public void shouldExecuteAdHocProcedureWith1InputAnd1OutputParameterWithUpdate() { - repository.adHocProcedureWith1InputAndNoOutputParameterWithUpdate("FOO"); - - assertTrue(true); } /** @@ -149,7 +134,7 @@ public class StoredProcedureIntegrationTests { */ @Test public void shouldExecuteProcedureWithNoInputAnd1OutputParameter() { - assertThat(repository.procedureWithNoInputAnd1OutputParameter(), is(equalTo(42))); + assertThat(repository.procedureWithNoInputAnd1OutputParameter(), is(42)); } /** @@ -157,7 +142,7 @@ public class StoredProcedureIntegrationTests { */ @Test public void shouldExecuteProcedureWith1InputAnd1OutputParameter() { - assertThat(repository.procedureWith1InputAnd1OutputParameter(23), is(equalTo(24))); + assertThat(repository.procedureWith1InputAnd1OutputParameter(23), is(24)); } /** @@ -165,21 +150,16 @@ public class StoredProcedureIntegrationTests { */ @Test public void shouldExecuteProcedureWith1InputAndNoOutputParameter() { - repository.procedureWith1InputAndNoOutputParameter(42); - - assertTrue(true); } /** * @see DATAJPA-652 */ @Test + @Ignore(NOT_SUPPORTED) public void shouldExecuteProcedureWith1InputAnd1OutputParameterWithResultSet() { - // hibernate currently (v4.3) doesn't support returning ResultSets in output parameters - assumeFalse(currentEntityManagerIsHibernateEntityManager(em)); - List dummies = repository.procedureWith1InputAnd1OutputParameterWithResultSet("FOO"); assertThat(dummies, is(notNullValue())); @@ -190,11 +170,9 @@ public class StoredProcedureIntegrationTests { * @see DATAJPA-652 */ @Test + @Ignore(NOT_SUPPORTED) public void shouldExecuteProcedureWith1InputAnd1OutputParameterWithResultSetWithUpdate() { - // hibernate currently (v4.3) doesn't support returning ResultSets in output parameters - assumeFalse(currentEntityManagerIsHibernateEntityManager(em)); - List dummies = repository.procedureWith1InputAnd1OutputParameterWithResultSetWithUpdate("FOO"); assertThat(dummies, is(notNullValue())); @@ -206,9 +184,6 @@ public class StoredProcedureIntegrationTests { */ @Test public void shouldExecuteProcedureWith1InputAnd1OutputParameterWithUpdate() { - repository.procedureWith1InputAndNoOutputParameterWithUpdate("FOO"); - - assertTrue(true); } } diff --git a/src/test/java/org/springframework/data/jpa/repository/query/PartTreeJpaQueryIntegrationTests.java b/src/test/java/org/springframework/data/jpa/repository/query/PartTreeJpaQueryIntegrationTests.java index bf6f25f7a..bf0815996 100644 --- a/src/test/java/org/springframework/data/jpa/repository/query/PartTreeJpaQueryIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/query/PartTreeJpaQueryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2013 the original author or authors. + * Copyright 2011-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License import org.springframework.aop.framework.Advised; @@ -59,6 +59,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @ContextConfiguration("classpath:infrastructure.xml") public class PartTreeJpaQueryIntegrationTests { + private static String PROPERTY = "h.target." + getQueryProperty(); + @Rule public ExpectedException thrown = ExpectedException.none(); @PersistenceContext EntityManager entityManager; @@ -106,12 +108,12 @@ public class PartTreeJpaQueryIntegrationTests { Query query = jpaQuery.createQuery(new Object[] { "Matthews", new PageRequest(0, 1) }); - HibernateQuery hibernateQuery = getValue(query, "h.target." + (isHibernate43() ? "jpqlQuery" : "val$jpaqlQuery")); + HibernateQuery hibernateQuery = getValue(query, PROPERTY); assertThat(hibernateQuery.getHibernateQuery().getQueryString(), endsWith("firstname=:param0")); query = jpaQuery.createQuery(new Object[] { null, new PageRequest(0, 1) }); - hibernateQuery = getValue(query, "h.target." + (isHibernate43() ? "jpqlQuery" : "val$jpaqlQuery")); + hibernateQuery = getValue(query, PROPERTY); assertThat(hibernateQuery.getHibernateQuery().getQueryString(), endsWith("firstname is null")); } @@ -141,10 +143,18 @@ public class PartTreeJpaQueryIntegrationTests { return (T) result; } + private static String getQueryProperty() { + return isHibernate43() || isHibernate5() ? "jpqlQuery" : "val$jpaqlQuery"; + } + private static boolean isHibernate43() { return Version.getVersionString().startsWith("4.3"); } + private static boolean isHibernate5() { + return Version.getVersionString().startsWith("5."); + } + interface UserRepository extends Repository { Page findByFirstname(String firstname, Pageable pageable); diff --git a/src/test/resources/eclipselink.xml b/src/test/resources/eclipselink.xml index 1df967354..06190203d 100644 --- a/src/test/resources/eclipselink.xml +++ b/src/test/resources/eclipselink.xml @@ -6,7 +6,7 @@ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> - + org.hsqldb.jdbcDriver