DATAJPA-1515 - Moved off Spring Data Commons' deprecations.

Related ticket: DATACMNS-1496.
This commit is contained in:
Oliver Drotbohm
2019-03-13 16:10:06 +01:00
parent 898889ea78
commit c04aee7196
5 changed files with 26 additions and 30 deletions

View File

@@ -36,7 +36,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.ExampleMatcher.PropertyValueTransformer;
import org.springframework.data.repository.core.support.ExampleMatcherAccessor;
import org.springframework.data.support.ExampleMatcherAccessor;
import org.springframework.data.util.DirectFieldAccessFallbackBeanWrapper;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.JpaSystemException;
@@ -62,12 +62,10 @@ public class QueryByExamplePredicateBuilder {
private static final Set<PersistentAttributeType> ASSOCIATION_TYPES;
static {
ASSOCIATION_TYPES = EnumSet.of(
PersistentAttributeType.MANY_TO_MANY,
PersistentAttributeType.MANY_TO_ONE,
PersistentAttributeType.ONE_TO_MANY,
PersistentAttributeType.ONE_TO_ONE
);
ASSOCIATION_TYPES = EnumSet.of(PersistentAttributeType.MANY_TO_MANY, //
PersistentAttributeType.MANY_TO_ONE, //
PersistentAttributeType.ONE_TO_MANY, //
PersistentAttributeType.ONE_TO_ONE);
}
/**

View File

@@ -81,12 +81,10 @@ public class JpaSort extends Sort {
this(Collections.<Order> emptyList(), direction, paths);
}
@SuppressWarnings("deprecation")
private JpaSort(List<Order> orders, @Nullable Direction direction, List<Path<?, ?>> paths) {
super(combine(orders, direction, paths));
}
@SuppressWarnings("deprecation")
private JpaSort(List<Order> orders) {
super(orders);
}

View File

@@ -26,8 +26,6 @@ import javax.persistence.metamodel.PluralAttribute;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.jpa.domain.JpaSort.JpaOrder;
import org.springframework.data.jpa.domain.JpaSort.Path;
@@ -81,66 +79,66 @@ public class JpaSortTests {
@Test // DATAJPA-12
public void sortBySinglePropertyWithDefaultSortDirection() {
assertThat(new JpaSort(path(User_.firstname)), hasItems(new Sort.Order("firstname")));
assertThat(new JpaSort(path(User_.firstname)), hasItems(Order.asc("firstname")));
}
@Test // DATAJPA-12
public void sortByMultiplePropertiesWithDefaultSortDirection() {
assertThat(new JpaSort(User_.firstname, User_.lastname), hasItems(new Order("firstname"), new Order("lastname")));
assertThat(new JpaSort(User_.firstname, User_.lastname), hasItems(Order.asc("firstname"), Order.asc("lastname")));
}
@Test // DATAJPA-12
public void sortByMultiplePropertiesWithDescSortDirection() {
assertThat(new JpaSort(DESC, User_.firstname, User_.lastname),
hasItems(new Order(DESC, "firstname"), new Order(Direction.DESC, "lastname")));
hasItems(new Order(DESC, "firstname"), Order.desc("lastname")));
}
@Test // DATAJPA-12
public void combiningSortByMultipleProperties() {
assertThat(new JpaSort(User_.firstname).and(new JpaSort(User_.lastname)),
hasItems(new Order("firstname"), new Order("lastname")));
hasItems(Order.asc("firstname"), Order.asc("lastname")));
}
@Test // DATAJPA-12
public void combiningSortByMultiplePropertiesWithDifferentSort() {
assertThat(new JpaSort(User_.firstname).and(new JpaSort(DESC, User_.lastname)),
hasItems(new Order("firstname"), new Order(DESC, "lastname")));
hasItems(Order.asc("firstname"), Order.desc("lastname")));
}
@Test // DATAJPA-12
public void combiningSortByNestedEmbeddedProperty() {
assertThat(new JpaSort(path(User_.address).dot(Address_.streetName)), hasItems(new Order("address.streetName")));
assertThat(new JpaSort(path(User_.address).dot(Address_.streetName)), hasItems(Order.asc("address.streetName")));
}
@Test // DATAJPA-12
public void buildJpaSortFromJpaMetaModelSingleAttribute() {
assertThat(new JpaSort(ASC, path(User_.firstname)), //
hasItems(new Order("firstname")));
hasItems(Order.asc("firstname")));
}
@Test // DATAJPA-12
public void buildJpaSortFromJpaMetaModelNestedAttribute() {
assertThat(new JpaSort(ASC, path(MailMessage_.mailSender).dot(MailSender_.name)), //
hasItems(new Order("mailSender.name")));
hasItems(Order.asc("mailSender.name")));
}
@Test // DATAJPA-702
public void combiningSortByMultiplePropertiesWithDifferentSortUsingSimpleAnd() {
assertThat(new JpaSort(User_.firstname).and(DESC, User_.lastname),
contains(new Order("firstname"), new Order(DESC, "lastname")));
contains(Order.asc("firstname"), Order.desc("lastname")));
}
@Test // DATAJPA-702
public void combiningSortByMultiplePathsWithDifferentSortUsingSimpleAnd() {
assertThat(new JpaSort(User_.firstname).and(DESC, path(MailMessage_.mailSender).dot(MailSender_.name)),
contains(new Order("firstname"), new Order(DESC, "mailSender.name")));
contains(Order.asc("firstname"), Order.desc("mailSender.name")));
}
@Test(expected = IllegalArgumentException.class) // DATAJPA-702
@@ -165,7 +163,7 @@ public class JpaSortTests {
JpaSort sort = JpaSort.unsafe(DESC, "foo.bar");
assertThat(sort, hasItem(new Order(DESC, "foo.bar")));
assertThat(sort, hasItem(Order.desc("foo.bar")));
assertThat(sort.getOrderFor("foo.bar"), is(instanceOf(JpaOrder.class)));
}
@@ -174,7 +172,7 @@ public class JpaSortTests {
JpaSort sort = JpaSort.unsafe(DESC, "foo.bar", "spring.data");
assertThat(sort, hasItems(new Order(DESC, "foo.bar"), new Order(DESC, "spring.data")));
assertThat(sort, hasItems(Order.desc("foo.bar"), Order.desc("spring.data")));
assertThat(sort.getOrderFor("foo.bar"), is(instanceOf(JpaOrder.class)));
assertThat(sort.getOrderFor("spring.data"), is(instanceOf(JpaOrder.class)));
}

View File

@@ -52,6 +52,8 @@ import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.ExampleMatcher.GenericPropertyMatcher;
import org.springframework.data.domain.ExampleMatcher.StringMatcher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
@@ -2119,8 +2121,8 @@ public class UserRepositoryTests {
flushTestUsers();
Page<User> firstPage = repository.findByNativeNamedQueryWithPageable(new PageRequest(0, 3));
Page<User> secondPage = repository.findByNativeNamedQueryWithPageable(new PageRequest(1, 3));
Page<User> firstPage = repository.findByNativeNamedQueryWithPageable(PageRequest.of(0, 3));
Page<User> secondPage = repository.findByNativeNamedQueryWithPageable(PageRequest.of(1, 3));
SoftAssertions softly = new SoftAssertions();
@@ -2145,8 +2147,8 @@ public class UserRepositoryTests {
flushTestUsers();
Page<String> firstPage = repository.findByNativeQueryWithPageable(new PageRequest(0, 3));
Page<String> secondPage = repository.findByNativeQueryWithPageable(new PageRequest(1, 3));
Page<String> firstPage = repository.findByNativeQueryWithPageable(PageRequest.of(0, 3));
Page<String> secondPage = repository.findByNativeQueryWithPageable(PageRequest.of(1, 3));
SoftAssertions softly = new SoftAssertions();

View File

@@ -162,14 +162,14 @@ public class QueryUtilsIntegrationTests {
@Test // DATAJPA-476
public void traversesPluralAttributeCorrectly() {
doInMerchantContext(((emf) -> {
doInMerchantContext((emf) -> {
CriteriaBuilder builder = emf.createEntityManager().getCriteriaBuilder();
CriteriaQuery<Merchant> query = builder.createQuery(Merchant.class);
Root<Merchant> root = query.from(Merchant.class);
QueryUtils.toExpressionRecursively(root, PropertyPath.from("employeesCredentialsUid", Merchant.class));
}));
});
}
public void doInMerchantContext(Consumer<EntityManagerFactory> emfConsumer) {
@@ -217,7 +217,7 @@ public class QueryUtilsIntegrationTests {
Root<User> root = query.from(User.class);
Join<User, User> join = root.join("manager", JoinType.LEFT);
Sort sort = new Sort(Direction.ASC, "age");
Sort sort = Sort.by(Direction.ASC, "age");
List<javax.persistence.criteria.Order> orders = QueryUtils.toOrders(sort, join, builder);