From 831cf83658769f7301843d6063de59c97fc4af8b Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Fri, 11 May 2012 21:18:53 +0200 Subject: [PATCH] Removed FindBugs glitches discovered through Sonar. --- .../data/jpa/repository/JpaRepository.java | 18 ++++--------- .../data/jpa/repository/Query.java | 12 ++++----- .../SimpleJpaRepositoryConfiguration.java | 3 +-- .../query/CriteriaQueryParameterBinder.java | 8 +++--- .../jpa/repository/query/JpaQueryCreator.java | 18 +++++++------ .../repository/query/JpaQueryExecution.java | 10 +++---- .../query/JpaQueryLookupStrategy.java | 12 ++++----- .../jpa/repository/query/JpaQueryMethod.java | 2 +- .../data/jpa/repository/query/NamedQuery.java | 7 +++-- .../query/ParameterMetadataProvider.java | 7 ++--- .../jpa/repository/query/SimpleJpaQuery.java | 12 ++++----- .../JpaMetamodelEntityInformation.java | 9 +++---- .../support/JpaRepositoryFactoryBean.java | 7 +++-- .../jpa/repository/support/QuerydslUtils.java | 4 +++ .../support/SimpleJpaRepository.java | 5 ++-- ...hScanningPersistenceUnitPostProcessor.java | 7 +++-- .../MergingPersistenceUnitManager.java | 26 ++++++++++++------- 17 files changed, 81 insertions(+), 86 deletions(-) diff --git a/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java index 2939404b1..1d25e87d3 100644 --- a/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/JpaRepository.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 @@ package org.springframework.data.jpa.repository; 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 @@ public interface JpaRepository extends PagingAndSort /* * (non-Javadoc) - * - * @see org.springframework.data.repository.Repository#findAll() + * @see org.springframework.data.repository.CrudRepository#findAll() */ List 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 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) */ List save(Iterable entities); @@ -69,7 +61,7 @@ public interface JpaRepository extends PagingAndSort /** * 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 */ diff --git a/src/main/java/org/springframework/data/jpa/repository/Query.java b/src/main/java/org/springframework/data/jpa/repository/Query.java index 736ec5e9b..d2789a011 100644 --- a/src/main/java/org/springframework/data/jpa/repository/Query.java +++ b/src/main/java/org/springframework/data/jpa/repository/Query.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. @@ -21,8 +21,6 @@ import java.lang.annotation.Retention; 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 @@ public @interface Query { 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 diff --git a/src/main/java/org/springframework/data/jpa/repository/config/SimpleJpaRepositoryConfiguration.java b/src/main/java/org/springframework/data/jpa/repository/config/SimpleJpaRepositoryConfiguration.java index 2cca4f3df..5597a4bc4 100644 --- a/src/main/java/org/springframework/data/jpa/repository/config/SimpleJpaRepositoryConfiguration.java +++ b/src/main/java/org/springframework/data/jpa/repository/config/SimpleJpaRepositoryConfiguration.java @@ -128,8 +128,7 @@ public class SimpleJpaRepositoryConfiguration extends } } - static interface JpaRepositoryConfiguration extends - SingleRepositoryConfigInformation { + interface JpaRepositoryConfiguration extends SingleRepositoryConfigInformation { String getEntityManagerFactoryRef(); } diff --git a/src/main/java/org/springframework/data/jpa/repository/query/CriteriaQueryParameterBinder.java b/src/main/java/org/springframework/data/jpa/repository/query/CriteriaQueryParameterBinder.java index 11cdf3f81..6b300571e 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/CriteriaQueryParameterBinder.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/CriteriaQueryParameterBinder.java @@ -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,7 +18,6 @@ package org.springframework.data.jpa.repository.query; 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; @@ -26,7 +25,8 @@ 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 @@ class CriteriaQueryParameterBinder extends ParameterBinder { /** * Creates a new {@link CriteriaQueryParameterBinder} for the given {@link Parameters}, values and some - * {@link ParameterExpression}. + * {@link javax.persistence.criteria.ParameterExpression}. * * @param parameters */ diff --git a/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java b/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java index 92e51414a..0642b621f 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.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. @@ -24,7 +24,6 @@ import java.util.List; 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 class JpaQueryCreator extends AbstractQueryCreator, } /** - * 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 @@ public class JpaQueryCreator extends AbstractQueryCreator, @SuppressWarnings({ "rawtypes" }) private Expression getComparablePath(Root root, Part part) { - return getTypedPath(root, part, Comparable.class); + return getTypedPath(root, part); } - private Expression getTypedPath(Root root, Part part, Class type) { + private Expression getTypedPath(Root root, Part part) { return toExpressionRecursively(root, part.getProperty()); } @@ -228,14 +227,17 @@ public class JpaQueryCreator extends AbstractQueryCreator, case CONTAINING: case LIKE: case NOT_LIKE: - Expression propertyExpression = upperIfIgnoreCase(getTypedPath(root, part, String.class)); + Expression stringPath = getTypedPath(root, part); + Expression propertyExpression = upperIfIgnoreCase(stringPath); Expression 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 truePath = getTypedPath(root, part); + return builder.isTrue(truePath); case FALSE: - return builder.isFalse(getTypedPath(root, part, Boolean.class)); + Expression falsePath = getTypedPath(root, part); + return builder.isFalse(falsePath); case SIMPLE_PROPERTY: ParameterMetadata expression = provider.next(part); return expression.isIsNullParameter() ? path.isNull() : builder.equal(upperIfIgnoreCase(path), diff --git a/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryExecution.java b/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryExecution.java index 2aaf0d01b..953cf92e4 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryExecution.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryExecution.java @@ -23,18 +23,17 @@ import javax.persistence.NoResultException; 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 @@ public abstract class JpaQueryExecution { } /** - * 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 { diff --git a/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryLookupStrategy.java b/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryLookupStrategy.java index 52ed560bb..b92dc5150 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryLookupStrategy.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryLookupStrategy.java @@ -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 java.lang.reflect.Method; 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 @@ public final class JpaQueryLookupStrategy { } /** - * {@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 */ diff --git a/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryMethod.java b/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryMethod.java index bbd97dc6f..243875b6f 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryMethod.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryMethod.java @@ -69,7 +69,7 @@ public class JpaQueryMethod extends QueryMethod { assertParameterNamesInAnnotatedQuery(); } - private final void assertParameterNamesInAnnotatedQuery() { + private void assertParameterNamesInAnnotatedQuery() { String annotatedQuery = getAnnotatedQuery(); diff --git a/src/main/java/org/springframework/data/jpa/repository/query/NamedQuery.java b/src/main/java/org/springframework/data/jpa/repository/query/NamedQuery.java index bb51af54d..2717e913a 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/NamedQuery.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/NamedQuery.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. @@ -23,7 +23,6 @@ import org.slf4j.Logger; 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 @@ final class NamedQuery extends AbstractJpaQuery { * @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 @@ final class NamedQuery extends AbstractJpaQuery { } /** - * 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 diff --git a/src/main/java/org/springframework/data/jpa/repository/query/ParameterMetadataProvider.java b/src/main/java/org/springframework/data/jpa/repository/query/ParameterMetadataProvider.java index ddf15ddca..6778b2d4a 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/ParameterMetadataProvider.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/ParameterMetadataProvider.java @@ -7,7 +7,6 @@ import java.util.Collections; 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 @@ class ParameterMetadataProvider { } /** - * 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()); diff --git a/src/main/java/org/springframework/data/jpa/repository/query/SimpleJpaQuery.java b/src/main/java/org/springframework/data/jpa/repository/query/SimpleJpaQuery.java index 20b1aacd1..eec317190 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/SimpleJpaQuery.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/SimpleJpaQuery.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. @@ -24,12 +24,12 @@ import org.slf4j.LoggerFactory; 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 @@ final class SimpleJpaQuery extends AbstractJpaQuery { } /** - * 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 diff --git a/src/main/java/org/springframework/data/jpa/repository/support/JpaMetamodelEntityInformation.java b/src/main/java/org/springframework/data/jpa/repository/support/JpaMetamodelEntityInformation.java index df763ef78..805951645 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/JpaMetamodelEntityInformation.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/JpaMetamodelEntityInformation.java @@ -29,10 +29,8 @@ import javax.persistence.metamodel.SingularAttribute; 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 @@ import org.springframework.util.ReflectionUtils; * * @author Oliver Gierke */ -public class JpaMetamodelEntityInformation extends JpaEntityInformationSupport - implements JpaEntityInformation { +public class JpaMetamodelEntityInformation extends JpaEntityInformationSupport { private final IdMetadata idMetadata; @@ -187,7 +184,7 @@ public class JpaMetamodelEntityInformation extends J * @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 class JpaMetamodelEntityInformation extends J * @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) { diff --git a/src/main/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactoryBean.java b/src/main/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactoryBean.java index 24eb98ff9..365c8c9f5 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactoryBean.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactoryBean.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. @@ -20,15 +20,14 @@ import java.io.Serializable; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; -import org.springframework.beans.factory.FactoryBean; import org.springframework.data.repository.Repository; import org.springframework.data.repository.core.support.RepositoryFactorySupport; import org.springframework.data.repository.core.support.TransactionalRepositoryFactoryBeanSupport; import org.springframework.util.Assert; /** - * Special adapter for Springs {@link FactoryBean} interface to allow easy setup of repository factories via Spring - * configuration. + * Special adapter for Springs {@link org.springframework.beans.factory.FactoryBean} interface to allow easy setup of + * repository factories via Spring configuration. * * @author Oliver Gierke * @author Eberhard Wolff diff --git a/src/main/java/org/springframework/data/jpa/repository/support/QuerydslUtils.java b/src/main/java/org/springframework/data/jpa/repository/support/QuerydslUtils.java index efbf8bc5c..c3efe73f3 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/QuerydslUtils.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/QuerydslUtils.java @@ -30,6 +30,10 @@ import com.mysema.query.jpa.impl.JPAQuery; */ class QuerydslUtils { + private QuerydslUtils() { + + } + /** * Creates the {@link JPQLQuery} instance based on the given {@link EntityManager} and {@link PersistenceProvider}. * diff --git a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java index 48390cbc2..4ba254e14 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java @@ -40,13 +40,12 @@ import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.repository.CrudRepository; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; /** - * Default implementation of the {@link CrudRepository} interface. This will offer you a more sophisticated interface - * than the plain {@link EntityManager} . + * Default implementation of the {@link org.springframework.data.repository.CrudRepository} interface. This will offer + * you a more sophisticated interface than the plain {@link EntityManager} . * * @author Oliver Gierke * @author Eberhard Wolff diff --git a/src/main/java/org/springframework/data/jpa/support/ClasspathScanningPersistenceUnitPostProcessor.java b/src/main/java/org/springframework/data/jpa/support/ClasspathScanningPersistenceUnitPostProcessor.java index b4a2d275a..bc7c908a4 100644 --- a/src/main/java/org/springframework/data/jpa/support/ClasspathScanningPersistenceUnitPostProcessor.java +++ b/src/main/java/org/springframework/data/jpa/support/ClasspathScanningPersistenceUnitPostProcessor.java @@ -23,7 +23,6 @@ import java.util.Set; import javax.persistence.Entity; import javax.persistence.MappedSuperclass; -import javax.persistence.PersistenceUnit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,8 +41,8 @@ import org.springframework.util.StringUtils; /** * {@link PersistenceUnitPostProcessor} that will scan for classes annotated with {@link Entity} or - * {@link MappedSuperclass} and add them to the {@link PersistenceUnit} post prcessed. Beyond that JPA XML mapping files - * can be scanned as well by configuring a file name pattern. + * {@link MappedSuperclass} and add them to the {@link javax.persistence.PersistenceUnit} post prcessed. Beyond that JPA + * XML mapping files can be scanned as well by configuring a file name pattern. * * @author Oliver Gierke */ @@ -135,7 +134,7 @@ public class ClasspathScanningPersistenceUnitPostProcessor implements Persistenc try { mappingFileUris.add(resource.getURI().toString()); } catch (IOException e) { - throw new IllegalStateException(String.format("Couldn't get URI for %s!", resource.toString(), e)); + throw new IllegalStateException(String.format("Couldn't get URI for %s!", resource.toString()), e); } } diff --git a/src/main/java/org/springframework/data/jpa/support/MergingPersistenceUnitManager.java b/src/main/java/org/springframework/data/jpa/support/MergingPersistenceUnitManager.java index cab20a70d..36ffdcfa8 100644 --- a/src/main/java/org/springframework/data/jpa/support/MergingPersistenceUnitManager.java +++ b/src/main/java/org/springframework/data/jpa/support/MergingPersistenceUnitManager.java @@ -15,6 +15,7 @@ */ package org.springframework.data.jpa.support; +import java.net.URISyntaxException; import java.net.URL; import javax.persistence.spi.PersistenceUnitInfo; @@ -33,7 +34,7 @@ import org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo; */ public class MergingPersistenceUnitManager extends DefaultPersistenceUnitManager { - private static final Logger log = LoggerFactory.getLogger(MergingPersistenceUnitManager.class); + private static final Logger LOG = LoggerFactory.getLogger(MergingPersistenceUnitManager.class); /* * (non-Javadoc) @@ -72,21 +73,21 @@ public class MergingPersistenceUnitManager extends DefaultPersistenceUnitManager for (URL url : oldPui.getJarFileUrls()) { if (!pui.getJarFileUrls().contains(url)) { - log.debug("Adding JAR file URL {} to persistence unit {}.", url, persistenceUnitName); + LOG.debug("Adding JAR file URL {} to persistence unit {}.", url, persistenceUnitName); pui.addJarFileUrl(url); } } for (String className : oldPui.getManagedClassNames()) { if (!pui.getManagedClassNames().contains(className)) { - log.debug("Adding class {} to PersistenceUnit {}", className, persistenceUnitName); + LOG.debug("Adding class {} to PersistenceUnit {}", className, persistenceUnitName); pui.addManagedClassName(className); } } for (String mappingFileName : oldPui.getMappingFileNames()) { if (!pui.getMappingFileNames().contains(mappingFileName)) { - log.debug("Adding mapping file to persistence unit {}.", mappingFileName, persistenceUnitName); + LOG.debug("Adding mapping file to persistence unit {}.", mappingFileName, persistenceUnitName); pui.addMappingFileName(mappingFileName); } } @@ -94,12 +95,19 @@ public class MergingPersistenceUnitManager extends DefaultPersistenceUnitManager URL newUrl = pui.getPersistenceUnitRootUrl(); URL oldUrl = oldPui.getPersistenceUnitRootUrl(); - boolean hasNewRootUrl = newUrl != null; - boolean rootUrlsDiffer = hasNewRootUrl && !newUrl.equals(oldUrl); - boolean urlNotInJarUrls = hasNewRootUrl && !pui.getJarFileUrls().contains(oldUrl); + if (oldUrl == null || newUrl == null) { + return; + } - if (hasNewRootUrl && rootUrlsDiffer && urlNotInJarUrls) { - pui.addJarFileUrl(oldUrl); + try { + boolean rootUrlsDiffer = !newUrl.toURI().equals(oldUrl.toURI()); + boolean urlNotInJarUrls = !pui.getJarFileUrls().contains(oldUrl); + + if (rootUrlsDiffer && urlNotInJarUrls) { + pui.addJarFileUrl(oldUrl); + } + } catch (URISyntaxException ex) { + throw new RuntimeException(ex); } } }