Permalink
Browse files

Removed FindBugs glitches discovered through Sonar.

  • Loading branch information...
1 parent 400d37a commit 831cf83658769f7301843d6063de59c97fc4af8b @olivergierke olivergierke committed May 11, 2012
Showing with 81 additions and 86 deletions.
  1. +5 −13 src/main/java/org/springframework/data/jpa/repository/JpaRepository.java
  2. +5 −7 src/main/java/org/springframework/data/jpa/repository/Query.java
  3. +1 −2 src/main/java/org/springframework/data/jpa/repository/config/SimpleJpaRepositoryConfiguration.java
  4. +4 −4 src/main/java/org/springframework/data/jpa/repository/query/CriteriaQueryParameterBinder.java
  5. +10 −8 src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java
  6. +5 −5 src/main/java/org/springframework/data/jpa/repository/query/JpaQueryExecution.java
  7. +5 −7 src/main/java/org/springframework/data/jpa/repository/query/JpaQueryLookupStrategy.java
  8. +1 −1 src/main/java/org/springframework/data/jpa/repository/query/JpaQueryMethod.java
  9. +3 −4 src/main/java/org/springframework/data/jpa/repository/query/NamedQuery.java
  10. +4 −3 src/main/java/org/springframework/data/jpa/repository/query/ParameterMetadataProvider.java
  11. +6 −6 src/main/java/org/springframework/data/jpa/repository/query/SimpleJpaQuery.java
  12. +3 −6 src/main/java/org/springframework/data/jpa/repository/support/JpaMetamodelEntityInformation.java
  13. +3 −4 src/main/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactoryBean.java
  14. +4 −0 src/main/java/org/springframework/data/jpa/repository/support/QuerydslUtils.java
  15. +2 −3 src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java
  16. +3 −4 ...main/java/org/springframework/data/jpa/support/ClasspathScanningPersistenceUnitPostProcessor.java
  17. +17 −9 src/main/java/org/springframework/data/jpa/support/MergingPersistenceUnitManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2008-2011 the original author or authors.
+ * Copyright 2008-2012 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.
@@ -18,8 +18,6 @@
import java.io.Serializable;
import java.util.List;
-import javax.persistence.EntityManager;
-
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.PagingAndSortingRepository;
@@ -32,25 +30,19 @@
/*
* (non-Javadoc)
- *
- * @see org.springframework.data.repository.Repository#findAll()
+ * @see org.springframework.data.repository.CrudRepository#findAll()
*/
List<T> findAll();
/*
* (non-Javadoc)
- *
- * @see
- * org.springframework.data.repository.PagingAndSortingRepository#findAll
- * (org.springframework.data.domain.Sort)
+ * @see org.springframework.data.repository.PagingAndSortingRepository#findAll(org.springframework.data.domain.Sort)
*/
List<T> findAll(Sort sort);
/*
* (non-Javadoc)
- *
- * @see
- * org.springframework.data.repository.Repository#save(java.lang.Iterable)
+ * @see org.springframework.data.repository.CrudRepository#save(java.lang.Iterable)
*/
<S extends T> List<S> save(Iterable<S> entities);
@@ -69,7 +61,7 @@
/**
* Deletes the given entities in a batch which means it will create a single {@link Query}. Assume that we will clear
- * the {@link EntityManager} after the call.
+ * the {@link javax.persistence.EntityManager} after the call.
*
* @param entities
*/
@@ -1,5 +1,5 @@
/*
- * Copyright 2008-2011 the original author or authors.
+ * Copyright 2008-2012 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.
@@ -21,8 +21,6 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import javax.persistence.NamedQuery;
-
/**
* Annotation to declare finder queries directly on repository methods.
*
@@ -50,14 +48,14 @@
boolean nativeQuery() default false;
/**
- * The named query to be used. If not defined, a NamedQuery with name of {@code $ domainClass}.${queryMethodName}}
- * will be used.
+ * The named query to be used. If not defined, a {@link javax.persistence.NamedQuery} with name of
+ * {@code $ domainClass}.${queryMethodName}} will be used.
*/
String name() default "";
/**
- * Returns the name of the {@link NamedQuery} to be used to execute count queries when pagination is used. Will
- * default to the named query name configured suffixed by {@code .count}.
+ * Returns the name of the {@link javax.persistence.NamedQuery} to be used to execute count queries when pagination is
+ * used. Will default to the named query name configured suffixed by {@code .count}.
*
* @see #name()
* @return
@@ -128,8 +128,7 @@ public String getEntityManagerFactoryRef() {
}
}
- static interface JpaRepositoryConfiguration extends
- SingleRepositoryConfigInformation<SimpleJpaRepositoryConfiguration> {
+ interface JpaRepositoryConfiguration extends SingleRepositoryConfigInformation<SimpleJpaRepositoryConfiguration> {
String getEntityManagerFactoryRef();
}
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 the original author or authors.
+ * Copyright 2011-2012 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.
@@ -18,15 +18,15 @@
import java.util.Iterator;
import javax.persistence.Query;
-import javax.persistence.criteria.ParameterExpression;
import org.springframework.data.jpa.repository.query.ParameterMetadataProvider.ParameterMetadata;
import org.springframework.data.repository.query.Parameter;
import org.springframework.data.repository.query.Parameters;
import org.springframework.util.Assert;
/**
- * Special {@link ParameterBinder} that uses {@link ParameterExpression}s to bind query parameters.
+ * Special {@link ParameterBinder} that uses {@link javax.persistence.criteria.ParameterExpression}s to bind query
+ * parameters.
*
* @author Oliver Gierke
*/
@@ -36,7 +36,7 @@
/**
* Creates a new {@link CriteriaQueryParameterBinder} for the given {@link Parameters}, values and some
- * {@link ParameterExpression}.
+ * {@link javax.persistence.criteria.ParameterExpression}.
*
* @param parameters
*/
@@ -1,5 +1,5 @@
/*
- * Copyright 2008-2011 the original author or authors.
+ * Copyright 2008-2012 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.
@@ -24,7 +24,6 @@
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Expression;
-import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
@@ -69,7 +68,7 @@ public JpaQueryCreator(PartTree tree, Class<?> domainClass, CriteriaBuilder buil
}
/**
- * Returns all {@link ParameterExpression} created when creating the query.
+ * Returns all {@link javax.persistence.criteria.ParameterExpression} created when creating the query.
*
* @return the parameterExpressions
*/
@@ -155,10 +154,10 @@ private Predicate toPredicate(Part part, Root<?> root) {
@SuppressWarnings({ "rawtypes" })
private Expression<? extends Comparable> getComparablePath(Root<?> root, Part part) {
- return getTypedPath(root, part, Comparable.class);
+ return getTypedPath(root, part);
}
- private <T> Expression<T> getTypedPath(Root<?> root, Part part, Class<T> type) {
+ private <T> Expression<T> getTypedPath(Root<?> root, Part part) {
return toExpressionRecursively(root, part.getProperty());
}
@@ -228,14 +227,17 @@ public Predicate build() {
case CONTAINING:
case LIKE:
case NOT_LIKE:
- Expression<String> propertyExpression = upperIfIgnoreCase(getTypedPath(root, part, String.class));
+ Expression<String> stringPath = getTypedPath(root, part);
+ Expression<String> propertyExpression = upperIfIgnoreCase(stringPath);
Expression<String> parameterExpression = upperIfIgnoreCase(provider.next(part, String.class).getExpression());
Predicate like = builder.like(propertyExpression, parameterExpression);
return part.getType() == Type.NOT_LIKE ? like.not() : like;
case TRUE:
- return builder.isTrue(getTypedPath(root, part, Boolean.class));
+ Expression<Boolean> truePath = getTypedPath(root, part);
+ return builder.isTrue(truePath);
case FALSE:
- return builder.isFalse(getTypedPath(root, part, Boolean.class));
+ Expression<Boolean> falsePath = getTypedPath(root, part);
+ return builder.isFalse(falsePath);
case SIMPLE_PROPERTY:
ParameterMetadata<Object> expression = provider.next(part);
return expression.isIsNullParameter() ? path.isNull() : builder.equal(upperIfIgnoreCase(path),
@@ -23,18 +23,17 @@
import javax.persistence.Query;
import javax.persistence.TypedQuery;
-import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.query.ParameterAccessor;
import org.springframework.data.repository.query.Parameters;
import org.springframework.data.repository.query.ParametersParameterAccessor;
-import org.springframework.data.repository.query.QueryMethod;
import org.springframework.util.Assert;
/**
- * Set of classes to contain query execution strategies. Depending (mostly) on the return type of a {@link QueryMethod}
- * a {@link AbstractStringBasedJpaQuery} can be executed in various flavours.
+ * Set of classes to contain query execution strategies. Depending (mostly) on the return type of a
+ * {@link org.springframework.data.repository.query.QueryMethod} a {@link AbstractStringBasedJpaQuery} can be executed
+ * in various flavours.
*
* @author Oliver Gierke
*/
@@ -80,7 +79,8 @@ protected Object doExecute(AbstractJpaQuery query, Object[] values) {
}
/**
- * Executes the {@link AbstractStringBasedJpaQuery} to return a {@link Page} of entities.
+ * Executes the {@link AbstractStringBasedJpaQuery} to return a {@link org.springframework.data.domain.Page} of
+ * entities.
*/
static class PagedExecution extends JpaQueryExecution {
@@ -1,9 +1,7 @@
/*
- * Copyright 2008-2011 the original author or authors.
+ * Copyright 2008-2012 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "Li
-import org.springframework.data.repository.core.NamedQueries;
-cense");
+ * 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
*
@@ -21,7 +19,6 @@
import javax.persistence.EntityManager;
-import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.core.NamedQueries;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.QueryLookupStrategy;
@@ -138,8 +135,9 @@ protected RepositoryQuery resolveQuery(JpaQueryMethod method, EntityManager em,
}
/**
- * {@link QueryLookupStrategy} to try to detect a declared query first ( {@link Query}, JPA named query). In case none
- * is found we fall back on query creation.
+ * {@link QueryLookupStrategy} to try to detect a declared query first (
+ * {@link org.springframework.data.jpa.repository.Query}, JPA named query). In case none is found we fall back on
+ * query creation.
*
* @author Oliver Gierke
*/
@@ -69,7 +69,7 @@ public JpaQueryMethod(Method method, RepositoryMetadata metadata, QueryExtractor
assertParameterNamesInAnnotatedQuery();
}
- private final void assertParameterNamesInAnnotatedQuery() {
+ private void assertParameterNamesInAnnotatedQuery() {
String annotatedQuery = getAnnotatedQuery();
@@ -1,5 +1,5 @@
/*
- * Copyright 2008-2011 the original author or authors.
+ * Copyright 2008-2012 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.
@@ -23,7 +23,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.data.repository.query.Parameters;
import org.springframework.data.repository.query.QueryCreationException;
-import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.repository.query.RepositoryQuery;
/**
@@ -85,7 +84,7 @@ private NamedQuery(JpaQueryMethod method, EntityManager em) {
* @param em
* @return
*/
- private static final boolean hasNamedQuery(EntityManager em, String queryName) {
+ private static boolean hasNamedQuery(EntityManager em, String queryName) {
try {
em.createNamedQuery(queryName);
@@ -97,7 +96,7 @@ private static final boolean hasNamedQuery(EntityManager em, String queryName) {
}
/**
- * Looks up a named query for the given {@link QueryMethod}.
+ * Looks up a named query for the given {@link org.springframework.data.repository.query.QueryMethod}.
*
* @param method
* @return
@@ -7,7 +7,6 @@
import java.util.Iterator;
import java.util.List;
-import javax.persistence.Query;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.ParameterExpression;
@@ -147,13 +146,15 @@ public boolean isIsNullParameter() {
}
/**
- * Prepares the object before it's actually bound to the {@link Query}.
+ * Prepares the object before it's actually bound to the {@link javax.persistence.Query;}.
*
- * @param parameter
+ * @param parameter must not be {@literal null}.
* @return
*/
public Object prepare(Object parameter) {
+ Assert.notNull(parameter);
+
switch (type) {
case STARTING_WITH:
return String.format("%s%%", parameter.toString());
@@ -1,5 +1,5 @@
/*
- * Copyright 2008-2011 the original author or authors.
+ * Copyright 2008-2012 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.
@@ -24,12 +24,12 @@
import org.springframework.data.repository.query.ParameterAccessor;
import org.springframework.data.repository.query.Parameters;
import org.springframework.data.repository.query.ParametersParameterAccessor;
-import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.repository.query.RepositoryQuery;
/**
- * {@link RepositoryQuery} implementation that inspects a {@link QueryMethod} for the existanve of an
- * {@link org.springframework.data.jpa.repository.Query} annotation and creates a JPA {@link Query} from it.
+ * {@link RepositoryQuery} implementation that inspects a {@link org.springframework.data.repository.query.QueryMethod}
+ * for the existanve of an {@link org.springframework.data.jpa.repository.Query} annotation and creates a JPA
+ * {@link Query} from it.
*
* @author Oliver Gierke
*/
@@ -110,8 +110,8 @@ public Query doCreateQuery(Object[] values) {
}
/**
- * Creates a {@link RepositoryQuery} from the given {@link QueryMethod} that is potentially annotated with
- * {@link org.springframework.data.jpa.repository.Query}.
+ * Creates a {@link RepositoryQuery} from the given {@link org.springframework.data.repository.query.QueryMethod} that
+ * is potentially annotated with {@link org.springframework.data.jpa.repository.Query}.
*
* @param queryMethod
* @param em
@@ -29,10 +29,8 @@
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
-import org.springframework.beans.BeansException;
import org.springframework.beans.NotReadablePropertyException;
import org.springframework.beans.NotWritablePropertyException;
-import org.springframework.data.repository.core.EntityInformation;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
@@ -41,8 +39,7 @@
*
* @author Oliver Gierke
*/
-public class JpaMetamodelEntityInformation<T, ID extends Serializable> extends JpaEntityInformationSupport<T, ID>
- implements JpaEntityInformation<T, ID> {
+public class JpaMetamodelEntityInformation<T, ID extends Serializable> extends JpaEntityInformationSupport<T, ID> {
private final IdMetadata<T> idMetadata;
@@ -187,7 +184,7 @@ public DirectFieldAccessFallbackBeanWrapper(Class<?> type) {
* @see org.springframework.beans.BeanWrapperImpl#getPropertyValue(java.lang.String)
*/
@Override
- public Object getPropertyValue(String propertyName) throws BeansException {
+ public Object getPropertyValue(String propertyName) {
try {
return super.getPropertyValue(propertyName);
} catch (NotReadablePropertyException e) {
@@ -202,7 +199,7 @@ public Object getPropertyValue(String propertyName) throws BeansException {
* @see org.springframework.beans.BeanWrapperImpl#setPropertyValue(java.lang.String, java.lang.Object)
*/
@Override
- public void setPropertyValue(String propertyName, Object value) throws BeansException {
+ public void setPropertyValue(String propertyName, Object value) {
try {
super.setPropertyValue(propertyName, value);
} catch (NotWritablePropertyException e) {
Oops, something went wrong.

0 comments on commit 831cf83

Please sign in to comment.