Removed FindBugs glitches discovered through Sonar.
This commit is contained in:
@@ -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<T, ID extends Serializable> extends PagingAndSort
|
||||
|
||||
/*
|
||||
* (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 @@ public interface JpaRepository<T, ID extends Serializable> 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
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -128,8 +128,7 @@ public class SimpleJpaRepositoryConfiguration extends
|
||||
}
|
||||
}
|
||||
|
||||
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,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
|
||||
*/
|
||||
|
||||
@@ -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<CriteriaQuery<Object>,
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<CriteriaQuery<Object>,
|
||||
@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 class JpaQueryCreator extends AbstractQueryCreator<CriteriaQuery<Object>,
|
||||
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.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 {
|
||||
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -69,7 +69,7 @@ public class JpaQueryMethod extends QueryMethod {
|
||||
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.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
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<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 class JpaMetamodelEntityInformation<T, ID extends Serializable> 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<T, ID extends Serializable> 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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}.
|
||||
*
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user