DATAJPA-1333 - Minor performance improvements.

Original pull request: #269.
This commit is contained in:
stsypanov
2018-04-23 22:39:22 +03:00
committed by Jens Schauder
parent e68f06999b
commit 644fc73da7
7 changed files with 19 additions and 16 deletions

View File

@@ -16,8 +16,7 @@
package org.springframework.data.jpa.convert;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.EnumSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
@@ -63,8 +62,12 @@ public class QueryByExamplePredicateBuilder {
private static final Set<PersistentAttributeType> ASSOCIATION_TYPES;
static {
ASSOCIATION_TYPES = new HashSet<>(Arrays.asList(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
);
}
/**
@@ -94,7 +97,7 @@ public class QueryByExamplePredicateBuilder {
return predicates.iterator().next();
}
Predicate[] array = predicates.toArray(new Predicate[predicates.size()]);
Predicate[] array = predicates.toArray(new Predicate[0]);
return matcher.isAllMatching() ? cb.and(array) : cb.or(array);
}

View File

@@ -189,7 +189,7 @@ public class JpaSort extends Sort {
public static <A extends Attribute<T, S>, T, S> Path<T, S> path(A attribute) {
Assert.notNull(attribute, "Attribute must not be null!");
return new Path<T, S>(Arrays.asList(attribute));
return new Path<>(Collections.singletonList(attribute));
}
/**
@@ -201,7 +201,7 @@ public class JpaSort extends Sort {
public static <P extends PluralAttribute<T, ?, S>, T, S> Path<T, S> path(P attribute) {
Assert.notNull(attribute, "Attribute must not be null!");
return new Path<T, S>(Arrays.asList(attribute));
return new Path<>(Collections.singletonList(attribute));
}
/**
@@ -241,7 +241,7 @@ public class JpaSort extends Sort {
Assert.notEmpty(properties, "Properties must not be empty!");
List<Order> orders = new ArrayList<Order>();
List<Order> orders = new ArrayList<>(properties.size());
for (String property : properties) {
orders.add(new JpaOrder(direction, property));
@@ -385,7 +385,7 @@ public class JpaSort extends Sort {
Assert.notEmpty(properties, "Properties must not be empty!");
Assert.noNullElements(properties, "Properties must not contain null values!");
List<Order> orders = new ArrayList<Order>();
List<Order> orders = new ArrayList<>(properties.length);
for (String property : properties) {
orders.add(new JpaOrder(getDirection(), property, getNullHandling(), isIgnoreCase(), this.unsafe));

View File

@@ -360,7 +360,7 @@ public abstract class AbstractJpaQuery implements RepositoryQuery {
@Override
public boolean containsValue(Object value) {
return Arrays.stream(tuple.toArray()).anyMatch(v -> v.equals(value));
return Arrays.asList(tuple.toArray()).contains(value);
}
/**

View File

@@ -120,7 +120,7 @@ class ParameterMetadataProvider {
@SuppressWarnings("unchecked")
public <T> ParameterMetadata<T> next(Part part) {
Assert.isTrue(parameters.hasNext(), String.format("No parameter available for part %s.", part));
Assert.isTrue(parameters.hasNext(), () -> String.format("No parameter available for part %s.", part));
Parameter parameter = parameters.next();
return (ParameterMetadata<T>) next(part, parameter.getType(), parameter);

View File

@@ -146,7 +146,7 @@ public class Querydsl {
private <T> JPQLQuery<T> addOrderByFrom(QSort qsort, JPQLQuery<T> query) {
List<OrderSpecifier<?>> orderSpecifiers = qsort.getOrderSpecifiers();
return query.orderBy(orderSpecifiers.toArray(new OrderSpecifier[orderSpecifiers.size()]));
return query.orderBy(orderSpecifiers.toArray(new OrderSpecifier[0]));
}
/**

View File

@@ -728,12 +728,12 @@ public class SimpleJpaRepository<T, ID> implements JpaRepository<T, ID>, JpaSpec
* @param query must not be {@literal null}.
* @return
*/
private static Long executeCountQuery(TypedQuery<Long> query) {
private static long executeCountQuery(TypedQuery<Long> query) {
Assert.notNull(query, "TypedQuery must not be null!");
List<Long> totals = query.getResultList();
Long total = 0L;
long total = 0L;
for (Long element : totals) {
total += element == null ? 0 : element;

View File

@@ -72,8 +72,8 @@ public class BeanDefinitionUtils {
*/
public static Iterable<String> getEntityManagerFactoryBeanNames(ListableBeanFactory beanFactory) {
Set<String> names = new HashSet<String>();
names.addAll(asList(beanNamesForTypeIncludingAncestors(beanFactory, EntityManagerFactory.class, true, false)));
String[] beanNames = beanNamesForTypeIncludingAncestors(beanFactory, EntityManagerFactory.class, true, false);
Set<String> names = new HashSet<>(asList(beanNames));
for (String factoryBeanName : beanNamesForTypeIncludingAncestors(beanFactory,
AbstractEntityManagerFactoryBean.class, true, false)) {