|
1 | 1 | /*
|
2 |
| - * Copyright 2011-2013 the original author or authors. |
| 2 | + * Copyright 2011-2015 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License
|
5 | 5 | import org.springframework.aop.framework.Advised;
|
|
59 | 59 | @ContextConfiguration("classpath:infrastructure.xml")
|
60 | 60 | public class PartTreeJpaQueryIntegrationTests {
|
61 | 61 |
|
| 62 | + private static String PROPERTY = "h.target." + getQueryProperty(); |
| 63 | + |
62 | 64 | @Rule public ExpectedException thrown = ExpectedException.none();
|
63 | 65 |
|
64 | 66 | @PersistenceContext EntityManager entityManager;
|
@@ -106,12 +108,12 @@ public void recreatesQueryIfNullValueIsGiven() throws Exception {
|
106 | 108 |
|
107 | 109 | Query query = jpaQuery.createQuery(new Object[] { "Matthews", new PageRequest(0, 1) });
|
108 | 110 |
|
109 |
| - HibernateQuery hibernateQuery = getValue(query, "h.target." + (isHibernate43() ? "jpqlQuery" : "val$jpaqlQuery")); |
| 111 | + HibernateQuery hibernateQuery = getValue(query, PROPERTY); |
110 | 112 | assertThat(hibernateQuery.getHibernateQuery().getQueryString(), endsWith("firstname=:param0"));
|
111 | 113 |
|
112 | 114 | query = jpaQuery.createQuery(new Object[] { null, new PageRequest(0, 1) });
|
113 | 115 |
|
114 |
| - hibernateQuery = getValue(query, "h.target." + (isHibernate43() ? "jpqlQuery" : "val$jpaqlQuery")); |
| 116 | + hibernateQuery = getValue(query, PROPERTY); |
115 | 117 | assertThat(hibernateQuery.getHibernateQuery().getQueryString(), endsWith("firstname is null"));
|
116 | 118 | }
|
117 | 119 |
|
@@ -141,10 +143,18 @@ private static <T> T getValue(Object source, String path) {
|
141 | 143 | return (T) result;
|
142 | 144 | }
|
143 | 145 |
|
| 146 | + private static String getQueryProperty() { |
| 147 | + return isHibernate43() || isHibernate5() ? "jpqlQuery" : "val$jpaqlQuery"; |
| 148 | + } |
| 149 | + |
144 | 150 | private static boolean isHibernate43() {
|
145 | 151 | return Version.getVersionString().startsWith("4.3");
|
146 | 152 | }
|
147 | 153 |
|
| 154 | + private static boolean isHibernate5() { |
| 155 | + return Version.getVersionString().startsWith("5."); |
| 156 | + } |
| 157 | + |
148 | 158 | interface UserRepository extends Repository<User, Long> {
|
149 | 159 |
|
150 | 160 | Page<User> findByFirstname(String firstname, Pageable pageable);
|
|
0 commit comments