From 7126b11173e1d0e46fd8e1fd04ec4c4013e1c0c7 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 1 Sep 2011 18:15:09 +0200 Subject: [PATCH] Formatting. --- .../springframework/data/annotation/Id.java | 2 +- .../data/annotation/Persistent.java | 7 +- .../data/annotation/Reference.java | 5 +- .../data/authentication/UserCredentials.java | 8 +- .../data/domain/Auditable.java | 33 +- .../data/domain/AuditorAware.java | 7 +- .../org/springframework/data/domain/Page.java | 46 +-- .../springframework/data/domain/PageImpl.java | 35 +- .../data/domain/PageRequest.java | 35 +- .../springframework/data/domain/Pageable.java | 16 +- .../data/domain/Persistable.java | 8 +- .../org/springframework/data/domain/Sort.java | 2 +- .../data/mapping/Association.java | 1 - .../data/mapping/AssociationHandler.java | 4 +- .../data/mapping/PersistentProperty.java | 12 +- .../data/mapping/PreferredConstructor.java | 9 +- .../data/mapping/PropertyHandler.java | 6 +- .../data/mapping/context/MappingContext.java | 31 +- .../mapping/context/MappingContextAware.java | 5 +- .../MappingContextAwareBeanPostProcessor.java | 2 +- .../mapping/event/MappingContextEvent.java | 3 +- .../model/AbstractPersistentProperty.java | 2 +- .../AnnotationBasedPersistentProperty.java | 15 +- .../mapping/model/BasicPersistentEntity.java | 22 +- .../data/mapping/model/BeanWrapper.java | 5 +- .../model/IllegalMappingException.java | 2 +- .../model/MutablePersistentEntity.java | 18 +- .../mapping/model/ParameterValueProvider.java | 2 +- .../model/PreferredConstructorDiscoverer.java | 22 +- .../data/mapping/model/SimpleTypeHolder.java | 22 +- .../SpELAwareParameterValueProvider.java | 7 +- ...AbstractConstructorEntityInstantiator.java | 55 ++-- .../data/persistence/ChangeSet.java | 2 +- .../data/persistence/ChangeSetBacked.java | 3 +- .../persistence/ChangeSetConfiguration.java | 4 +- .../data/persistence/ChangeSetPersister.java | 17 +- .../persistence/ChangeSetSynchronizer.java | 7 +- .../data/persistence/EntityInstantiator.java | 9 +- .../data/persistence/HashMapChangeSet.java | 2 +- .../data/persistence/StateBackedCreator.java | 4 +- .../data/persistence/StateProvider.java | 3 +- .../data/querydsl/EntityPathResolver.java | 2 +- .../querydsl/QueryDslPredicateExecutor.java | 81 +++-- .../data/querydsl/QueryDslUtils.java | 1 - .../querydsl/SimpleEntityPathResolver.java | 60 ++-- .../data/repository/CrudRepository.java | 35 +- .../data/repository/NoRepositoryBean.java | 16 +- .../PagingAndSortingRepository.java | 18 +- .../data/repository/RepositoryDefinition.java | 2 +- ...tractRepositoryConfigDefinitionParser.java | 298 +++++++----------- .../AutomaticRepositoryConfigInformation.java | 21 +- .../CommonRepositoryConfigInformation.java | 28 +- .../GlobalRepositoryConfigInformation.java | 24 +- .../ManualRepositoryConfigInformation.java | 37 +-- .../NamedQueriesBeanDefinitionParser.java | 26 +- ...DelegatingRepositoryConfigInformation.java | 28 +- .../repository/config/RepositoryConfig.java | 60 ++-- .../SingleRepositoryConfigInformation.java | 32 +- .../repository/config/TypeFilterParser.java | 113 +++---- .../repository/core/EntityInformation.java | 12 +- .../data/repository/core/EntityMetadata.java | 4 +- .../data/repository/core/NamedQueries.java | 2 +- .../core/RepositoryInformation.java | 29 +- .../repository/core/RepositoryMetadata.java | 15 +- .../support/AbstractEntityInformation.java | 18 +- .../support/AnnotationRepositoryMetadata.java | 10 +- .../support/DefaultRepositoryInformation.java | 36 +-- .../support/DefaultRepositoryMetadata.java | 21 +- .../support/PersistableEntityInformation.java | 12 +- .../support/PropertiesBasedNamedQueries.java | 12 +- .../core/support/QueryCreationListener.java | 8 +- .../support/RepositoryFactoryBeanSupport.java | 31 +- .../support/RepositoryFactoryInformation.java | 11 +- .../support/RepositoryFactorySupport.java | 191 ++++------- .../support/RepositoryProxyPostProcessor.java | 12 +- ...sactionalRepositoryFactoryBeanSupport.java | 47 +-- ...sactionalRepositoryProxyPostProcessor.java | 199 ++++++------ .../data/repository/query/Param.java | 6 +- .../data/repository/query/Parameter.java | 63 ++-- .../repository/query/ParameterAccessor.java | 39 +-- .../query/ParameterOutOfBoundsException.java | 12 +- .../data/repository/query/Parameters.java | 105 +++--- .../query/ParametersParameterAccessor.java | 28 +- .../query/QueryCreationException.java | 39 +-- .../repository/query/QueryLookupStrategy.java | 11 +- .../data/repository/query/QueryMethod.java | 78 ++--- .../repository/query/RepositoryQuery.java | 9 +- .../query/parser/AbstractQueryCreator.java | 6 +- .../repository/query/parser/PartTree.java | 8 +- .../repository/query/parser/Property.java | 91 ++---- .../support/DomainClassConverter.java | 60 ++-- .../support/DomainClassPropertyEditor.java | 49 +-- .../DomainClassPropertyEditorRegistrar.java | 48 +-- .../data/repository/util/ClassUtils.java | 2 +- .../data/repository/util/TxUtils.java | 5 +- ...geSetBackedTransactionSynchronization.java | 6 +- .../NaiveDoubleTransactionManager.java | 3 +- .../data/util/ClassTypeInformation.java | 11 +- .../data/util/GenericTypeResolver.java | 121 +++---- .../util/ParameterizedTypeInformation.java | 21 +- .../data/util/TypeDiscoverer.java | 63 ++-- .../data/util/TypeInformation.java | 26 +- .../util/TypeVariableTypeInformation.java | 19 +- .../data/web/PageableArgumentResolver.java | 145 +++------ .../data/web/PageableDefaults.java | 15 +- 105 files changed, 1215 insertions(+), 1926 deletions(-) diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/annotation/Id.java b/spring-data-commons-core/src/main/java/org/springframework/data/annotation/Id.java index 3a8decceb..e3ed02b2f 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/annotation/Id.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/annotation/Id.java @@ -25,6 +25,6 @@ import java.lang.annotation.Target; * @author J. Brisbin */ @Retention(RetentionPolicy.RUNTIME) -@Target(value = {ElementType.FIELD}) +@Target(value = { ElementType.FIELD }) public @interface Id { } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/annotation/Persistent.java b/spring-data-commons-core/src/main/java/org/springframework/data/annotation/Persistent.java index 8c94efb85..2821f9481 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/annotation/Persistent.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/annotation/Persistent.java @@ -25,11 +25,6 @@ import java.lang.annotation.Target; * @author J. Brisbin */ @Retention(RetentionPolicy.RUNTIME) -@Target(value = { - ElementType.TYPE, - ElementType.ANNOTATION_TYPE, - ElementType.FIELD, - ElementType.PARAMETER -}) +@Target(value = { ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.PARAMETER }) public @interface Persistent { } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/annotation/Reference.java b/spring-data-commons-core/src/main/java/org/springframework/data/annotation/Reference.java index 9ac33e012..19317b806 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/annotation/Reference.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/annotation/Reference.java @@ -25,9 +25,6 @@ import java.lang.annotation.Target; * @author Jon Brisbin */ @Retention(RetentionPolicy.RUNTIME) -@Target({ - ElementType.ANNOTATION_TYPE, - ElementType.FIELD -}) +@Target({ ElementType.ANNOTATION_TYPE, ElementType.FIELD }) public @interface Reference { } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/authentication/UserCredentials.java b/spring-data-commons-core/src/main/java/org/springframework/data/authentication/UserCredentials.java index 7861706b4..b83f8f331 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/authentication/UserCredentials.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/authentication/UserCredentials.java @@ -67,7 +67,7 @@ public class UserCredentials { */ @Override public boolean equals(Object obj) { - + if (obj == this) { return true; } @@ -88,12 +88,12 @@ public class UserCredentials { */ @Override public int hashCode() { - + int result = 17; - + result += 31 * ObjectUtils.nullSafeHashCode(username); result += 31 * ObjectUtils.nullSafeHashCode(password); - + return result; } } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/domain/Auditable.java b/spring-data-commons-core/src/main/java/org/springframework/data/domain/Auditable.java index ec46019e0..3867f4a2a 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/domain/Auditable.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/domain/Auditable.java @@ -19,13 +19,11 @@ import java.io.Serializable; import org.joda.time.DateTime; - /** - * Interface for auditable entities. Allows storing and retrieving creation and - * modification information. The changing instance (typically some user) is to - * be defined by a generics definition. - * - * @param the auditing type. Typically some kind of user. + * Interface for auditable entities. Allows storing and retrieving creation and modification information. The changing + * instance (typically some user) is to be defined by a generics definition. + * + * @param the auditing type. Typically some kind of user. * @param the type of the auditing type's idenifier * @author Oliver Gierke */ @@ -33,63 +31,56 @@ public interface Auditable extends Persistable { /** * Returns the user who created this entity. - * + * * @return the createdBy */ U getCreatedBy(); - /** * Sets the user who created this entity. - * + * * @param createdBy the creating entity to set */ void setCreatedBy(final U createdBy); - /** * Returns the creation date of the entity. - * + * * @return the createdDate */ DateTime getCreatedDate(); - /** * Sets the creation date of the entity. - * + * * @param creationDate the creation date to set */ void setCreatedDate(final DateTime creationDate); - /** * Returns the user who modified the entity lastly. - * + * * @return the lastModifiedBy */ U getLastModifiedBy(); - /** * Sets the user who modified the entity lastly. - * + * * @param lastModifiedBy the last modifying entity to set */ void setLastModifiedBy(final U lastModifiedBy); - /** * Returns the date of the last modification. - * + * * @return the lastModifiedDate */ DateTime getLastModifiedDate(); - /** * Sets the date of the last modification. - * + * * @param lastModifiedDate the date of the last modification to set */ void setLastModifiedDate(final DateTime lastModifiedDate); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/domain/AuditorAware.java b/spring-data-commons-core/src/main/java/org/springframework/data/domain/AuditorAware.java index 83869166e..552f3619f 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/domain/AuditorAware.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/domain/AuditorAware.java @@ -16,9 +16,8 @@ package org.springframework.data.domain; /** - * Interface for components that are aware of the application's current auditor. - * This will be some kind of user mostly. - * + * Interface for components that are aware of the application's current auditor. This will be some kind of user mostly. + * * @param the type of the auditing instance * @author Oliver Gierke */ @@ -26,7 +25,7 @@ public interface AuditorAware { /** * Returns the current auditor of the application. - * + * * @return the current auditor */ T getCurrentAuditor(); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/domain/Page.java b/spring-data-commons-core/src/main/java/org/springframework/data/domain/Page.java index ddab1aee7..7da21052c 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/domain/Page.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/domain/Page.java @@ -18,89 +18,78 @@ package org.springframework.data.domain; import java.util.Iterator; import java.util.List; - /** - * A page is a sublist of a list of objects. It allows gain information about - * the position of it in the containing entire list. - * + * A page is a sublist of a list of objects. It allows gain information about the position of it in the containing + * entire list. + * * @param * @author Oliver Gierke */ public interface Page extends Iterable { /** - * Returns the number of the current page. Is always positive and less that - * {@code Page#getTotalPages()}. - * + * Returns the number of the current page. Is always positive and less that {@code Page#getTotalPages()}. + * * @return the number of the current page */ int getNumber(); - /** * Returns the size of the page. - * + * * @return the size of the page */ int getSize(); - /** * Returns the number of total pages. - * + * * @return the number of toral pages */ int getTotalPages(); - /** * Returns the number of elements currently on this page. - * + * * @return the number of elements currently on this page */ int getNumberOfElements(); - /** * Returns the total amount of elements. - * + * * @return the total amount of elements */ long getTotalElements(); - /** * Returns if there is a previous page. - * + * * @return if there is a previous page */ boolean hasPreviousPage(); - /** * Returns whether the current page is the first one. - * + * * @return */ boolean isFirstPage(); - /** * Returns if there is a next page. - * + * * @return if there is a next page */ boolean hasNextPage(); - /** * Returns whether the current page is the last one. - * + * * @return */ boolean isLastPage(); - /* * (non-Javadoc) * @@ -108,26 +97,23 @@ public interface Page extends Iterable { */ Iterator iterator(); - /** * Returns the page content as {@link List}. - * + * * @return */ List getContent(); - /** * Returns whether the {@link Page} has content at all. - * + * * @return */ boolean hasContent(); - /** * Returns the sorting parameters for the page. - * + * * @return */ Sort getSort(); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/domain/PageImpl.java b/spring-data-commons-core/src/main/java/org/springframework/data/domain/PageImpl.java index 675bab8b3..f3e0e8636 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/domain/PageImpl.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/domain/PageImpl.java @@ -21,10 +21,9 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; - /** * Basic {@code Page} implementation. - * + * * @param the type of which the page consists. * @author Oliver Gierke */ @@ -36,13 +35,12 @@ public class PageImpl implements Page, Serializable { private final Pageable pageable; private final long total; - /** * Constructor of {@code PageImpl}. - * - * @param content the content of this page + * + * @param content the content of this page * @param pageable the paging information - * @param total the total amount of items available + * @param total the total amount of items available */ public PageImpl(List content, Pageable pageable, long total) { @@ -55,11 +53,10 @@ public class PageImpl implements Page, Serializable { this.pageable = pageable; } - /** - * Creates a new {@link PageImpl} with the given content. This will result - * in the created {@link Page} being identical to the entire {@link List}. - * + * Creates a new {@link PageImpl} with the given content. This will result in the created {@link Page} being identical + * to the entire {@link List}. + * * @param content */ public PageImpl(List content) { @@ -67,7 +64,6 @@ public class PageImpl implements Page, Serializable { this(content, null, (null == content) ? 0 : content.size()); } - /* * (non-Javadoc) * @@ -78,7 +74,6 @@ public class PageImpl implements Page, Serializable { return pageable == null ? 0 : pageable.getPageNumber(); } - /* * (non-Javadoc) * @@ -89,7 +84,6 @@ public class PageImpl implements Page, Serializable { return pageable == null ? 0 : pageable.getPageSize(); } - /* * (non-Javadoc) * @@ -100,7 +94,6 @@ public class PageImpl implements Page, Serializable { return getSize() == 0 ? 0 : (int) Math.ceil((double) total / (double) getSize()); } - /* * (non-Javadoc) * @@ -111,7 +104,6 @@ public class PageImpl implements Page, Serializable { return content.size(); } - /* * (non-Javadoc) * @@ -122,7 +114,6 @@ public class PageImpl implements Page, Serializable { return total; } - /* * (non-Javadoc) * @@ -133,7 +124,6 @@ public class PageImpl implements Page, Serializable { return getNumber() > 0; } - /* * (non-Javadoc) * @@ -144,7 +134,6 @@ public class PageImpl implements Page, Serializable { return !hasPreviousPage(); } - /* * (non-Javadoc) * @@ -155,7 +144,6 @@ public class PageImpl implements Page, Serializable { return ((getNumber() + 1) * getSize()) < total; } - /* * (non-Javadoc) * @@ -166,7 +154,6 @@ public class PageImpl implements Page, Serializable { return !hasNextPage(); } - /* * (non-Javadoc) * @@ -177,7 +164,6 @@ public class PageImpl implements Page, Serializable { return content.iterator(); } - /* * (non-Javadoc) * @@ -198,7 +184,6 @@ public class PageImpl implements Page, Serializable { return !content.isEmpty(); } - /* * (non-Javadoc) * @@ -209,7 +194,6 @@ public class PageImpl implements Page, Serializable { return pageable == null ? null : pageable.getSort(); } - /* * (non-Javadoc) * @@ -224,11 +208,9 @@ public class PageImpl implements Page, Serializable { contentType = content.get(0).getClass().getName(); } - return String.format("Page %s of %d containing %s instances", - getNumber(), getTotalPages(), contentType); + return String.format("Page %s of %d containing %s instances", getNumber(), getTotalPages(), contentType); } - /* * (non-Javadoc) * @@ -254,7 +236,6 @@ public class PageImpl implements Page, Serializable { return totalEqual && contentEqual && pageableEqual; } - /* * (non-Javadoc) * diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/domain/PageRequest.java b/spring-data-commons-core/src/main/java/org/springframework/data/domain/PageRequest.java index 7427d6d54..507d36327 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/domain/PageRequest.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/domain/PageRequest.java @@ -19,10 +19,9 @@ import java.io.Serializable; import org.springframework.data.domain.Sort.Direction; - /** * Basic Java Bean implementation of {@code Pageable}. - * + * * @author Oliver Gierke */ public class PageRequest implements Pageable, Serializable { @@ -33,11 +32,10 @@ public class PageRequest implements Pageable, Serializable { private final int size; private final Sort sort; - /** - * Creates a new {@link PageRequest}. Pages are zero indexed, thus providing - * 0 for {@code page} will return the first page. - * + * Creates a new {@link PageRequest}. Pages are zero indexed, thus providing 0 for {@code page} will return the first + * page. + * * @param size * @param page */ @@ -46,25 +44,22 @@ public class PageRequest implements Pageable, Serializable { this(page, size, null); } - /** * Creates a new {@link PageRequest} with sort parameters applied. - * + * * @param page * @param size * @param direction * @param properties */ - public PageRequest(int page, int size, Direction direction, - String... properties) { + public PageRequest(int page, int size, Direction direction, String... properties) { this(page, size, new Sort(direction, properties)); } - /** * Creates a new {@link PageRequest} with sort parameters applied. - * + * * @param page * @param size * @param sort @@ -72,13 +67,11 @@ public class PageRequest implements Pageable, Serializable { public PageRequest(int page, int size, Sort sort) { if (0 > page) { - throw new IllegalArgumentException( - "Page index must not be less than zero!"); + throw new IllegalArgumentException("Page index must not be less than zero!"); } if (0 >= size) { - throw new IllegalArgumentException( - "Page size must not be less than or equal to zero!"); + throw new IllegalArgumentException("Page size must not be less than or equal to zero!"); } this.page = page; @@ -86,7 +79,6 @@ public class PageRequest implements Pageable, Serializable { this.sort = sort; } - /* * (non-Javadoc) * @@ -97,7 +89,6 @@ public class PageRequest implements Pageable, Serializable { return size; } - /* * (non-Javadoc) * @@ -108,7 +99,6 @@ public class PageRequest implements Pageable, Serializable { return page; } - /* * (non-Javadoc) * @@ -119,7 +109,6 @@ public class PageRequest implements Pageable, Serializable { return page * size; } - /* * (non-Javadoc) * @@ -130,7 +119,6 @@ public class PageRequest implements Pageable, Serializable { return sort; } - /* * (non-Javadoc) * @@ -152,14 +140,11 @@ public class PageRequest implements Pageable, Serializable { boolean pageEqual = this.page == that.page; boolean sizeEqual = this.size == that.size; - boolean sortEqual = - this.sort == null ? that.sort == null : this.sort - .equals(that.sort); + boolean sortEqual = this.sort == null ? that.sort == null : this.sort.equals(that.sort); return pageEqual && sizeEqual && sortEqual; } - /* * (non-Javadoc) * diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/domain/Pageable.java b/spring-data-commons-core/src/main/java/org/springframework/data/domain/Pageable.java index 655d905b7..ed0511702 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/domain/Pageable.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/domain/Pageable.java @@ -17,39 +17,35 @@ package org.springframework.data.domain; /** * Abstract interface for pagination information. - * + * * @author Oliver Gierke */ public interface Pageable { /** * Returns the page to be returned. - * + * * @return the page to be returned. */ int getPageNumber(); - /** * Returns the number of items to be returned. - * + * * @return the number of items of that page */ int getPageSize(); - /** - * Returns the offset to be taken according to the underlying page and page - * size. - * + * Returns the offset to be taken according to the underlying page and page size. + * * @return the offset to be taken */ int getOffset(); - /** * Returns the sorting parameters. - * + * * @return */ Sort getSort(); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/domain/Persistable.java b/spring-data-commons-core/src/main/java/org/springframework/data/domain/Persistable.java index 21e89db11..09ab2c1b7 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/domain/Persistable.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/domain/Persistable.java @@ -17,10 +17,9 @@ package org.springframework.data.domain; import java.io.Serializable; - /** * Simple interface for entities. - * + * * @param the type of the identifier * @author Oliver Gierke */ @@ -28,15 +27,14 @@ public interface Persistable extends Serializable { /** * Returns the id of the entity. - * + * * @return the id */ ID getId(); - /** * Returns if the {@code Persistable} is new or was persisted already. - * + * * @return if the object is new */ boolean isNew(); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/domain/Sort.java b/spring-data-commons-core/src/main/java/org/springframework/data/domain/Sort.java index 9481e73e4..f41e07b35 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/domain/Sort.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/domain/Sort.java @@ -342,7 +342,7 @@ public class Sort implements Iterable> { - + /** * Processes the given {@link Association}. * diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PersistentProperty.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PersistentProperty.java index 5f583b235..5343a49ab 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PersistentProperty.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PersistentProperty.java @@ -18,14 +18,14 @@ public interface PersistentProperty

> { /** * The name of the property - * + * * @return The property name */ String getName(); /** * The type of the property - * + * * @return The property type */ Class getType(); @@ -55,7 +55,7 @@ public interface PersistentProperty

> { /** * Returns whether the property has to be regarded as entity which means its type will be also be considered to be a * {@link PersistentEntity}. - * + * * @return */ boolean isEntity(); @@ -63,21 +63,21 @@ public interface PersistentProperty

> { /** * Returns the component type of the type if it is a {@link Collection}. Will return the type of the key if the * property is a {@link Map}. - * + * * @return the component type, the map's key type or {@literal null} if neither {@link Collection} nor {@link Map}. */ Class getComponentType(); /** * Returns the raw type as it's pulled from from the reflected property. - * + * * @return the raw type of the property. */ Class getRawType(); /** * Returns the type of the values if the property is a {@link Map}. - * + * * @return the map's value type or {@literal null} if no {@link Map} */ Class getMapValueType(); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PreferredConstructor.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PreferredConstructor.java index ce4bf7ae3..09a5bbe64 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PreferredConstructor.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PreferredConstructor.java @@ -44,10 +44,10 @@ public class PreferredConstructor { * @param parameters */ public PreferredConstructor(Constructor constructor, Parameter... parameters) { - + Assert.notNull(constructor); Assert.notNull(parameters); - + ReflectionUtils.makeAccessible(constructor); this.constructor = constructor; this.parameters = Arrays.asList(parameters); @@ -70,7 +70,7 @@ public class PreferredConstructor { public Iterable> getParameters() { return parameters; } - + /** * Returns whether the constructor has {@link Parameter}s. * @@ -103,8 +103,7 @@ public class PreferredConstructor { /** * Value object to represent constructor parameters. * - * @param - * the type of the paramter + * @param the type of the paramter * @author Oliver Gierke */ public static class Parameter { diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PropertyHandler.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PropertyHandler.java index c1ffb17fe..bdfa649dc 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PropertyHandler.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PropertyHandler.java @@ -16,9 +16,9 @@ package org.springframework.data.mapping; /** - * Callback interface to do something with all plain {@link PersistentProperty} - * instances except associations and transient properties. - * + * Callback interface to do something with all plain {@link PersistentProperty} instances except associations + * and transient properties. + * * @author Jon Brisbin */ public interface PropertyHandler

> { diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContext.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContext.java index 6be0095a6..663882294 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContext.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContext.java @@ -23,16 +23,22 @@ import org.springframework.data.util.TypeInformation; import org.springframework.validation.Validator; /** - *

This interface defines the overall context including all known - * PersistentEntity instances and methods to obtain instances on demand

+ *

+ * This interface defines the overall context including all known PersistentEntity instances and methods to obtain + * instances on demand + *

*

- *

This interface is used internally to establish associations - * between entities and also at runtime to obtain entities by name

+ *

+ * This interface is used internally to establish associations between entities and also at runtime to obtain entities + * by name + *

*

- *

The generic type parameters T & R are used to specify the - * mapped form of a class (example Table) and property (example Column) respectively.

+ *

+ * The generic type parameters T & R are used to specify the mapped form of a class (example Table) and property + * (example Column) respectively. + *

*

- * + * * @author Graeme Rocher * @author Jon Brisbin * @author Oliver Gierke @@ -41,7 +47,7 @@ public interface MappingContext, P extends Pers /** * Returns all {@link PersistentEntity}s held in the context. - * + * * @return */ Collection getPersistentEntities(); @@ -56,7 +62,7 @@ public interface MappingContext, P extends Pers /** * Returns a {@link PersistentEntity} for the given {@link TypeInformation}. - * + * * @param type * @return */ @@ -66,7 +72,7 @@ public interface MappingContext, P extends Pers * Returns all {@link PersistentProperty}s for the given path expression based on the given root {@link Class}. Path * expression are dot separated, e.g. {@code person.firstname}. * - * @param + * @param * @param type * @param path * @return @@ -74,9 +80,8 @@ public interface MappingContext, P extends Pers Iterable

getPersistentPropertyPath(Class type, String path); /** - * Obtains a validator for the given entity - * TODO: Why do we need validators at the {@link MappingContext}? - * + * Obtains a validator for the given entity TODO: Why do we need validators at the {@link MappingContext}? + * * @param entity The entity * @return A validator or null if none exists for the given entity */ diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAware.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAware.java index 0959d5a79..b3c5980d1 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAware.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAware.java @@ -16,17 +16,16 @@ package org.springframework.data.mapping.context; - /** * An interface to make beans aware of the active MappingContext in the current ApplicationContext. - * + * * @author Jon Brisbin */ public interface MappingContextAware { /** * The active MappingContext for the environment. - * + * * @param mappingContext */ void setMappingContext(MappingContext mappingContext); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAwareBeanPostProcessor.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAwareBeanPostProcessor.java index 98fc92974..dee4e921a 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAwareBeanPostProcessor.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAwareBeanPostProcessor.java @@ -27,7 +27,7 @@ import org.springframework.context.ApplicationContextAware; * BeanPostProcessor to make Spring beans aware of the current MappingContext. If a MappingContext exists with the * default bean name ("mappingContext"), then that bean is used. If there is no MappingContext registered under the * default bean name, then the first MappingContext it finds is the one it chooses. - * + * * @author Jon Brisbin */ public class MappingContextAwareBeanPostProcessor implements BeanPostProcessor, ApplicationContextAware { diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/event/MappingContextEvent.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/event/MappingContextEvent.java index 96968b57b..911b7cdd0 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/event/MappingContextEvent.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/event/MappingContextEvent.java @@ -24,7 +24,8 @@ import org.springframework.data.util.TypeInformation; /** * @author Jon Brisbin */ -public class MappingContextEvent, P extends PersistentProperty

> extends ApplicationEvent { +public class MappingContextEvent, P extends PersistentProperty

> extends + ApplicationEvent { private static final long serialVersionUID = 1336466833846092490L; private TypeInformation typeInformation; diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java index 251a148fa..208b6e61f 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java @@ -32,7 +32,7 @@ import org.springframework.util.Assert; /** * Simple impementation of {@link PersistentProperty}. - * + * * @author Jon Brisbin * @author Oliver Gierke */ diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java index d76f3c86b..30ae7385d 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java @@ -28,24 +28,25 @@ import org.springframework.data.mapping.Association; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentProperty; - /** * Special {@link PersistentProperty} that takes annotations at a property into account. - * + * * @author Oliver Gierke */ -public abstract class AnnotationBasedPersistentProperty

> extends AbstractPersistentProperty

{ +public abstract class AnnotationBasedPersistentProperty

> extends + AbstractPersistentProperty

{ private final Value value; /** * Creates a new {@link AnnotationBasedPersistentProperty}. - * + * * @param field * @param propertyDescriptor * @param owner */ - public AnnotationBasedPersistentProperty(Field field, PropertyDescriptor propertyDescriptor, PersistentEntity owner, SimpleTypeHolder simpleTypeHolder) { + public AnnotationBasedPersistentProperty(Field field, PropertyDescriptor propertyDescriptor, + PersistentEntity owner, SimpleTypeHolder simpleTypeHolder) { super(field, propertyDescriptor, owner, simpleTypeHolder); this.value = field.getAnnotation(Value.class); @@ -55,7 +56,7 @@ public abstract class AnnotationBasedPersistentProperty

* @author Oliver Gierke */ @@ -41,19 +41,18 @@ public class BasicPersistentEntity> implement private final TypeInformation information; private final Set

properties; private final Set> associations; - - private P idProperty; + private P idProperty; /** * Creates a new {@link BasicPersistentEntity} from the given {@link TypeInformation}. - * + * * @param information must not be {@literal null}. */ public BasicPersistentEntity(TypeInformation information) { this(information, null); } - + /** * Creates a new {@link BasicPersistentEntity} for the given {@link TypeInformation} and {@link Comparator}. The given * {@link Comparator} will be used to define the order of the {@link PersistentProperty} instances added to the @@ -124,13 +123,13 @@ public class BasicPersistentEntity> implement * @see org.springframework.data.mapping.PersistentEntity#getPersistentProperty(java.lang.String) */ public P getPersistentProperty(String name) { - + for (P property : properties) { if (property.getName().equals(name)) { return property; } } - + return null; } @@ -180,16 +179,17 @@ public class BasicPersistentEntity> implement public void verify() { } - + /** * Simple {@link Comparator} adaptor to delegate ordering to the inverse properties of the association. * * @author Oliver Gierke */ - private static final class AssociationComparator

> implements Comparator> { - + private static final class AssociationComparator

> implements + Comparator> { + private final Comparator

delegate; - + public AssociationComparator(Comparator

delegate) { Assert.notNull(delegate); this.delegate = delegate; diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BeanWrapper.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BeanWrapper.java index b39ae7411..cb8e9813c 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BeanWrapper.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BeanWrapper.java @@ -173,8 +173,7 @@ public class BeanWrapper, T> { * @throws IllegalAccessException * @throws InvocationTargetException */ - public Object getProperty(PersistentProperty property) - throws IllegalAccessException, InvocationTargetException { + public Object getProperty(PersistentProperty property) throws IllegalAccessException, InvocationTargetException { return getProperty(property, property.getType(), false); } @@ -201,7 +200,7 @@ public class BeanWrapper, T> { ReflectionUtils.makeAccessible(getter); obj = ReflectionUtils.invokeMethod(getter, bean); } - + return getPotentiallyConvertedValue(obj, type); } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/IllegalMappingException.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/IllegalMappingException.java index bd96b96dc..2564e9093 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/IllegalMappingException.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/IllegalMappingException.java @@ -16,7 +16,7 @@ package org.springframework.data.mapping.model; /** * Thrown when an error occurs reading the mapping between object and datastore - * + * * @author Graeme Rocher * @since 1.0 */ diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MutablePersistentEntity.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MutablePersistentEntity.java index 36d8aafcf..b91136a5f 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MutablePersistentEntity.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MutablePersistentEntity.java @@ -19,41 +19,37 @@ import org.springframework.data.mapping.Association; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentProperty; - - /** * Interface capturing mutator methods for {@link PersistentEntity}s. - * + * * @author Oliver Gierke */ -public interface MutablePersistentEntity> - extends PersistentEntity { +public interface MutablePersistentEntity> extends PersistentEntity { /** * Sets the id property for the entity. - * + * * @param property */ void setIdProperty(P property); /** * Adds a {@link PersistentProperty} to the entity. - * + * * @param property */ void addPersistentProperty(P property); /** * Adds an {@link Association} to the entity. - * + * * @param association */ void addAssociation(Association

association); /** - * Callback method to trigger validation of the {@link PersistentEntity}. As - * {@link MutablePersistentEntity} is not immutable there might be some - * verification steps necessary after the object has reached is final state. + * Callback method to trigger validation of the {@link PersistentEntity}. As {@link MutablePersistentEntity} is not + * immutable there might be some verification steps necessary after the object has reached is final state. */ void verify(); } \ No newline at end of file diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/ParameterValueProvider.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/ParameterValueProvider.java index cef28ce34..3d1fadde1 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/ParameterValueProvider.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/ParameterValueProvider.java @@ -20,7 +20,7 @@ import org.springframework.data.mapping.PreferredConstructor.Parameter; /** * Callback interface to lookup values for a given {@link Parameter}. - * + * * @author Oliver Gierke */ public interface ParameterValueProvider { diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java index 85a4feeaa..137c22c7b 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java @@ -26,16 +26,14 @@ import org.springframework.data.mapping.PreferredConstructor.Parameter; import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; - /** * Helper class to find a {@link PreferredConstructor}. - * + * * @author Oliver Gierke */ public class PreferredConstructorDiscoverer { - private final ParameterNameDiscoverer nameDiscoverer = - new LocalVariableTableParameterNameDiscoverer(); + private final ParameterNameDiscoverer nameDiscoverer = new LocalVariableTableParameterNameDiscoverer(); private PreferredConstructor constructor; @@ -45,7 +43,7 @@ public class PreferredConstructorDiscoverer { /** * Creates a new {@link PreferredConstructorDiscoverer} for the given type. - * + * * @param owningType */ protected PreferredConstructorDiscoverer(TypeInformation owningType) { @@ -56,8 +54,7 @@ public class PreferredConstructorDiscoverer { for (Constructor constructor : rawOwningType.getDeclaredConstructors()) { - PreferredConstructor preferredConstructor = - buildPreferredConstructor(constructor, owningType); + PreferredConstructor preferredConstructor = buildPreferredConstructor(constructor, owningType); // Explicitly defined constructor trumps all if (preferredConstructor.isExplicitlyAnnotated()) { @@ -82,10 +79,9 @@ public class PreferredConstructorDiscoverer { } } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private PreferredConstructor buildPreferredConstructor( - Constructor constructor, TypeInformation typeInformation) { + @SuppressWarnings({ "unchecked", "rawtypes" }) + private PreferredConstructor buildPreferredConstructor(Constructor constructor, + TypeInformation typeInformation) { List> parameterTypes = typeInformation.getParameterTypes(constructor); @@ -106,11 +102,9 @@ public class PreferredConstructorDiscoverer { parameters[i] = new Parameter(name, type, annotations); } - return new PreferredConstructor((Constructor) constructor, - parameters); + return new PreferredConstructor((Constructor) constructor, parameters); } - public PreferredConstructor getConstructor() { return constructor; } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/SimpleTypeHolder.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/SimpleTypeHolder.java index 950b9ab31..a508a7ce9 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/SimpleTypeHolder.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/SimpleTypeHolder.java @@ -25,11 +25,11 @@ import org.springframework.util.Assert; /** * Simple container to hold a set of types to be considered simple types. - * + * * @author Oliver Gierke */ public class SimpleTypeHolder { - + private static final Set> DEFAULTS = new HashSet>(); static { @@ -63,11 +63,11 @@ public class SimpleTypeHolder { DEFAULTS.add(Class.class); DEFAULTS.add(Number.class); } - + private final Set> simpleTypes; - + /** - * Creates a new {@link SimpleTypeHolder} containing the default types. + * Creates a new {@link SimpleTypeHolder} containing the default types. * * @see #SimpleTypeHolder(Set, boolean) */ @@ -84,10 +84,10 @@ public class SimpleTypeHolder { * @param registerDefaults */ public SimpleTypeHolder(Set> customSimpleTypes, boolean registerDefaults) { - + Assert.notNull(customSimpleTypes); this.simpleTypes = new HashSet>(customSimpleTypes); - + if (registerDefaults) { this.simpleTypes.addAll(DEFAULTS); } @@ -100,14 +100,14 @@ public class SimpleTypeHolder { * @param source must not be {@literal null} */ public SimpleTypeHolder(Set> customSimpleTypes, SimpleTypeHolder source) { - + Assert.notNull(customSimpleTypes); Assert.notNull(source); - + this.simpleTypes = new HashSet>(customSimpleTypes); this.simpleTypes.addAll(source.simpleTypes); } - + /** * Returns whether the given type is considered a simple one. * @@ -118,7 +118,7 @@ public class SimpleTypeHolder { Assert.notNull(type); if (Object.class.equals(type)) { return true; - } + } for (Class clazz : simpleTypes) { if (type == clazz || clazz.isAssignableFrom(type)) { return true; diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/SpELAwareParameterValueProvider.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/SpELAwareParameterValueProvider.java index 1b6d2ca9f..73f09c9da 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/SpELAwareParameterValueProvider.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/SpELAwareParameterValueProvider.java @@ -28,12 +28,13 @@ import org.springframework.util.Assert; * @author Oliver Gierke */ public class SpELAwareParameterValueProvider implements ParameterValueProvider { - + private final SpelExpressionParser parser; private final EvaluationContext context; - + /** - * Creates a new {@link SpELAwareParameterValueProvider} from the given {@link SpelExpressionParser} and {@link EvaluationContext}. + * Creates a new {@link SpELAwareParameterValueProvider} from the given {@link SpelExpressionParser} and + * {@link EvaluationContext}. * * @param parser must not be {@literal null} * @param context must not be {@literal null} diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/persistence/AbstractConstructorEntityInstantiator.java b/spring-data-commons-core/src/main/java/org/springframework/data/persistence/AbstractConstructorEntityInstantiator.java index 9e6aadd62..d55668ee8 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/persistence/AbstractConstructorEntityInstantiator.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/persistence/AbstractConstructorEntityInstantiator.java @@ -11,12 +11,12 @@ import org.springframework.util.ClassUtils; import sun.reflect.ReflectionFactory; /** - * Try for a constructor taking state: failing that, try a no-arg - * constructor and then setUnderlyingNode(). - * + * Try for a constructor taking state: failing that, try a no-arg constructor and then setUnderlyingNode(). + * * @author Rod Johnson */ -public abstract class AbstractConstructorEntityInstantiator implements EntityInstantiator { +public abstract class AbstractConstructorEntityInstantiator implements + EntityInstantiator { private final Log log = LogFactory.getLog(getClass()); private final Map, StateBackedCreator> cache = new HashMap, StateBackedCreator>(); @@ -24,10 +24,12 @@ public abstract class AbstractConstructorEntityInstantiator T createEntityFromState(STATE n, Class c) { try { StateBackedCreator creator = (StateBackedCreator) cache.get(c); - if (creator != null) return creator.create(n, c); + if (creator != null) + return creator.create(n, c); synchronized (cache) { creator = (StateBackedCreator) cache.get(c); - if (creator != null) return creator.create(n, c); + if (creator != null) + return creator.create(n, c); Class stateClass = (Class) n.getClass(); creator = createInstantiator(c, stateClass); cache.put(c, creator); @@ -42,20 +44,24 @@ public abstract class AbstractConstructorEntityInstantiator, StateBackedCreator> instantiators) { + public void setInstantiators( + Map, StateBackedCreator> instantiators) { this.cache.putAll(instantiators); } - protected StateBackedCreator createInstantiator(Class type, final Class stateType) { + protected StateBackedCreator createInstantiator(Class type, + final Class stateType) { StateBackedCreator creator = stateTakingConstructorInstantiator(type, stateType); - if (creator != null) return creator; + if (creator != null) + return creator; creator = emptyConstructorStateSettingInstantiator(type, stateType); - if (creator != null) return creator; + if (creator != null) + return creator; return createFailingInstantiator(stateType); } - protected StateBackedCreator createFailingInstantiator(final Class stateType) { + protected StateBackedCreator createFailingInstantiator( + final Class stateType) { return new StateBackedCreator() { public T create(STATE n, Class c) throws Exception { throw new IllegalArgumentException(getFailingMessageForClass(c, stateType)); @@ -64,13 +70,15 @@ public abstract class AbstractConstructorEntityInstantiator entityClass, Class stateClass) { - return getClass().getSimpleName() + ": entity " + entityClass + - " must have either a constructor taking [" + stateClass + "] or a no-arg constructor and state setter."; + return getClass().getSimpleName() + ": entity " + entityClass + " must have either a constructor taking [" + + stateClass + "] or a no-arg constructor and state setter."; } - private StateBackedCreator emptyConstructorStateSettingInstantiator(Class type, Class stateType) { + private StateBackedCreator emptyConstructorStateSettingInstantiator( + Class type, Class stateType) { final Constructor constructor = getNoArgConstructor(type); - if (constructor == null) return null; + if (constructor == null) + return null; log.info("Using " + type + " no-arg constructor"); @@ -88,7 +96,8 @@ public abstract class AbstractConstructorEntityInstantiator StateBackedCreator createWithoutConstructorInvocation(final Class type, Class stateType) { + protected StateBackedCreator createWithoutConstructorInvocation( + final Class type, Class stateType) { ReflectionFactory rf = ReflectionFactory.getReflectionFactory(); Constructor objectConstructor = getDeclaredConstructor(Object.class); final Constructor serializationConstructor = rf.newConstructorForSerialization(type, objectConstructor); @@ -101,17 +110,19 @@ public abstract class AbstractConstructorEntityInstantiator Constructor getNoArgConstructor(Class type) { Constructor constructor = ClassUtils.getConstructorIfAvailable(type); - if (constructor != null) return constructor; + if (constructor != null) + return constructor; return getDeclaredConstructor(type); } - protected StateBackedCreator stateTakingConstructorInstantiator(Class type, Class stateType) { + protected StateBackedCreator stateTakingConstructorInstantiator( + Class type, Class stateType) { Class stateInterface = (Class) stateType.getInterfaces()[0]; final Constructor constructor = ClassUtils.getConstructorIfAvailable(type, stateInterface); - if (constructor == null) return null; + if (constructor == null) + return null; log.info("Using " + type + " constructor taking " + stateInterface); return new StateBackedCreator() { @@ -133,7 +144,7 @@ public abstract class AbstractConstructorEntityInstantiator { return changeSetManager; } - public void setChangeSetManager( - ChangeSetSynchronizer changeSetManager) { + public void setChangeSetManager(ChangeSetSynchronizer changeSetManager) { this.changeSetManager = changeSetManager; } - } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/persistence/ChangeSetPersister.java b/spring-data-commons-core/src/main/java/org/springframework/data/persistence/ChangeSetPersister.java index 8984fbd63..130942427 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/persistence/ChangeSetPersister.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/persistence/ChangeSetPersister.java @@ -3,9 +3,8 @@ package org.springframework.data.persistence; import org.springframework.dao.DataAccessException; /** - * Interface to be implemented by classes that can synchronize - * between data stores and ChangeSets. - * + * Interface to be implemented by classes that can synchronize between data stores and ChangeSets. + * * @param entity key * @author Rod Johnson */ @@ -18,11 +17,12 @@ public interface ChangeSetPersister { /** * TODO how to tell when not found? throw exception? */ - void getPersistentState(Class entityClass, K key, ChangeSet changeSet) throws DataAccessException, NotFoundException; + void getPersistentState(Class entityClass, K key, ChangeSet changeSet) + throws DataAccessException, NotFoundException; /** * Return id - * + * * @param entity * @param cs * @return @@ -32,17 +32,16 @@ public interface ChangeSetPersister { /** * Return key - * + * * @param entity - * @param cs Key may be null if not persistent + * @param cs Key may be null if not persistent * @return * @throws DataAccessException */ K persistState(ChangeSetBacked entity, ChangeSet cs) throws DataAccessException; /** - * Exception thrown in alternate control flow if getPersistentState - * finds no entity data. + * Exception thrown in alternate control flow if getPersistentState finds no entity data. */ class NotFoundException extends Exception { diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/persistence/ChangeSetSynchronizer.java b/spring-data-commons-core/src/main/java/org/springframework/data/persistence/ChangeSetSynchronizer.java index 43da163ab..506f238fe 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/persistence/ChangeSetSynchronizer.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/persistence/ChangeSetSynchronizer.java @@ -5,9 +5,8 @@ import java.util.Map; import org.springframework.dao.DataAccessException; /** - * Interface to be implemented by classes that can synchronize - * between entities and ChangeSets. - * + * Interface to be implemented by classes that can synchronize between entities and ChangeSets. + * * @param * @author Rod Johnson */ @@ -17,7 +16,7 @@ public interface ChangeSetSynchronizer { /** * Take all entity fields into a changeSet. - * + * * @param entity * @return * @throws DataAccessException diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/persistence/EntityInstantiator.java b/spring-data-commons-core/src/main/java/org/springframework/data/persistence/EntityInstantiator.java index 5af972cfc..e0df05a43 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/persistence/EntityInstantiator.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/persistence/EntityInstantiator.java @@ -1,12 +1,9 @@ package org.springframework.data.persistence; - /** - * Interface to be implemented by classes that can instantiate and - * configure entities. - * The framework must do this when creating objects resulting from finders, - * even when there may be no no-arg constructor supplied by the user. - * + * Interface to be implemented by classes that can instantiate and configure entities. The framework must do this when + * creating objects resulting from finders, even when there may be no no-arg constructor supplied by the user. + * * @author Rod Johnson */ public interface EntityInstantiator { diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/persistence/HashMapChangeSet.java b/spring-data-commons-core/src/main/java/org/springframework/data/persistence/HashMapChangeSet.java index 391da33aa..1e8101dc4 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/persistence/HashMapChangeSet.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/persistence/HashMapChangeSet.java @@ -8,7 +8,7 @@ import org.springframework.core.convert.ConversionService; /** * Simple ChangeSet implementation backed by a HashMap. - * + * * @author Thomas Risberg * @author Rod Johnson */ diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/persistence/StateBackedCreator.java b/spring-data-commons-core/src/main/java/org/springframework/data/persistence/StateBackedCreator.java index 32978e302..33af6c2a9 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/persistence/StateBackedCreator.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/persistence/StateBackedCreator.java @@ -3,8 +3,8 @@ package org.springframework.data.persistence; /** * encapsulates the instantiator of state-backed classes and populating them with the provided state. *

- * Can be implemented and registered with the concrete AbstractConstructorEntityInstantiator to provide - * non reflection bases instantiaton for domain classes + * Can be implemented and registered with the concrete AbstractConstructorEntityInstantiator to provide non reflection + * bases instantiaton for domain classes */ public interface StateBackedCreator { T create(STATE n, Class c) throws Exception; diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/persistence/StateProvider.java b/spring-data-commons-core/src/main/java/org/springframework/data/persistence/StateProvider.java index 6c12672f6..264ae81b4 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/persistence/StateProvider.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/persistence/StateProvider.java @@ -12,7 +12,8 @@ public abstract class StateProvider { public static void setUnderlyingState(STATE state) { if (stateHolder.get() != null) - throw new IllegalStateException("StateHolder already contains state " + stateHolder.get() + " in thread " + Thread.currentThread()); + throw new IllegalStateException("StateHolder already contains state " + stateHolder.get() + " in thread " + + Thread.currentThread()); stateHolder.set(state); } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/EntityPathResolver.java b/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/EntityPathResolver.java index 03ecfeab3..d77015ce4 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/EntityPathResolver.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/EntityPathResolver.java @@ -19,7 +19,7 @@ import com.mysema.query.types.EntityPath; /** * Strategy interface to abstract the ways to translate an plain domain class into a {@link EntityPath}. - * + * * @author Oliver Gierke */ public interface EntityPathResolver { diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/QueryDslPredicateExecutor.java b/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/QueryDslPredicateExecutor.java index cdad97152..54dc33723 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/QueryDslPredicateExecutor.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/QueryDslPredicateExecutor.java @@ -21,7 +21,6 @@ import org.springframework.data.domain.Pageable; import com.mysema.query.types.OrderSpecifier; import com.mysema.query.types.Predicate; - /** * Interface to allow execution of QueryDsl {@link Predicate} instances. * @@ -29,51 +28,45 @@ import com.mysema.query.types.Predicate; */ public interface QueryDslPredicateExecutor { - /** - * Returns a single entity matching the given {@link Predicate}. - * - * @param spec - * @return - */ - T findOne(Predicate predicate); + /** + * Returns a single entity matching the given {@link Predicate}. + * + * @param spec + * @return + */ + T findOne(Predicate predicate); + /** + * Returns all entities matching the given {@link Predicate}. + * + * @param spec + * @return + */ + Iterable findAll(Predicate predicate); - /** - * Returns all entities matching the given {@link Predicate}. - * - * @param spec - * @return - */ - Iterable findAll(Predicate predicate); + /** + * Returns all entities matching the given {@link Predicate} applying the given {@link OrderSpecifier}s. + * + * @param predicate + * @param orders + * @return + */ + Iterable findAll(Predicate predicate, OrderSpecifier... orders); + /** + * Returns a {@link Page} of entities matching the given {@link Predicate}. + * + * @param predicate + * @param pageable + * @return + */ + Page findAll(Predicate predicate, Pageable pageable); - /** - * Returns all entities matching the given {@link Predicate} applying the - * given {@link OrderSpecifier}s. - * - * @param predicate - * @param orders - * @return - */ - Iterable findAll(Predicate predicate, OrderSpecifier... orders); - - - /** - * Returns a {@link Page} of entities matching the given {@link Predicate}. - * - * @param predicate - * @param pageable - * @return - */ - Page findAll(Predicate predicate, Pageable pageable); - - - /** - * Returns the number of instances that the given {@link Predicate} will - * return. - * - * @param predicate the {@link Predicate} to count instances for - * @return the number of instances - */ - long count(Predicate predicate); + /** + * Returns the number of instances that the given {@link Predicate} will return. + * + * @param predicate the {@link Predicate} to count instances for + * @return the number of instances + */ + long count(Predicate predicate); } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/QueryDslUtils.java b/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/QueryDslUtils.java index 29dba9819..6d9cfaf95 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/QueryDslUtils.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/QueryDslUtils.java @@ -15,7 +15,6 @@ */ package org.springframework.data.querydsl; - /** * @author Oliver Gierke */ diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/SimpleEntityPathResolver.java b/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/SimpleEntityPathResolver.java index c31dd2758..a5e837dca 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/SimpleEntityPathResolver.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/SimpleEntityPathResolver.java @@ -23,27 +23,23 @@ import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; /** - * Simple implementation of {@link EntityPathResolver} to lookup a query - * class by reflection and using the static field of the same type. - * + * Simple implementation of {@link EntityPathResolver} to lookup a query class by reflection and using the static field + * of the same type. + * * @author Oliver Gierke */ public enum SimpleEntityPathResolver implements EntityPathResolver { INSTANCE; - private static final String NO_CLASS_FOUND_TEMPLATE = - "Did not find a query class %s for domain class %s!"; - private static final String NO_FIELD_FOUND_TEMPLATE = - "Did not find a static field of the same type in %s!"; - + private static final String NO_CLASS_FOUND_TEMPLATE = "Did not find a query class %s for domain class %s!"; + private static final String NO_FIELD_FOUND_TEMPLATE = "Did not find a static field of the same type in %s!"; /** - * Creates an {@link EntityPath} instance for the given domain class. - * Tries to lookup a class matching the naming convention (prepend Q to - * the simple name of the class, same package) and find a static field - * of the same type in it. - * + * Creates an {@link EntityPath} instance for the given domain class. Tries to lookup a class matching the naming + * convention (prepend Q to the simple name of the class, same package) and find a static field of the same type in + * it. + * * @param domainClass * @return */ @@ -53,31 +49,24 @@ public enum SimpleEntityPathResolver implements EntityPathResolver { String pathClassName = getQueryClassName(domainClass); try { - Class pathClass = - ClassUtils.forName(pathClassName, - SimpleEntityPathResolver.class.getClassLoader()); + Class pathClass = ClassUtils.forName(pathClassName, SimpleEntityPathResolver.class.getClassLoader()); Field field = getStaticFieldOfType(pathClass); if (field == null) { - throw new IllegalStateException(String.format( - NO_FIELD_FOUND_TEMPLATE, pathClass)); + throw new IllegalStateException(String.format(NO_FIELD_FOUND_TEMPLATE, pathClass)); } else { - return (EntityPath) ReflectionUtils - .getField(field, null); + return (EntityPath) ReflectionUtils.getField(field, null); } } catch (ClassNotFoundException e) { - throw new IllegalArgumentException(String.format( - NO_CLASS_FOUND_TEMPLATE, pathClassName, - domainClass.getName()), e); + throw new IllegalArgumentException(String.format(NO_CLASS_FOUND_TEMPLATE, pathClassName, domainClass.getName()), + e); } } - /** - * Returns the first static field of the given type inside the given - * type. - * + * Returns the first static field of the given type inside the given type. + * * @param type * @return */ @@ -94,30 +83,25 @@ public enum SimpleEntityPathResolver implements EntityPathResolver { } Class superclass = type.getSuperclass(); - return Object.class.equals(superclass) ? null - : getStaticFieldOfType(superclass); + return Object.class.equals(superclass) ? null : getStaticFieldOfType(superclass); } - /** * Returns the name of the query class for the given domain class. - * + * * @param domainClass * @return */ private String getQueryClassName(Class domainClass) { String simpleClassName = ClassUtils.getShortName(domainClass); - return String.format("%s.Q%s%s", - domainClass.getPackage().getName(), - getClassBase(simpleClassName), domainClass.getSimpleName()); + return String.format("%s.Q%s%s", domainClass.getPackage().getName(), getClassBase(simpleClassName), + domainClass.getSimpleName()); } - /** - * Analyzes the short class name and potentially returns the outer - * class. - * + * Analyzes the short class name and potentially returns the outer class. + * * @param shortName * @return */ diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/CrudRepository.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/CrudRepository.java index 9bbb1bd68..146e0c242 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/CrudRepository.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/CrudRepository.java @@ -17,10 +17,9 @@ package org.springframework.data.repository; import java.io.Serializable; - /** * Interface for generic CRUD operations on a repository for a specific type. - * + * * @author Oliver Gierke * @author Eberhard Wolff */ @@ -28,61 +27,54 @@ import java.io.Serializable; public interface CrudRepository extends Repository { /** - * Saves a given entity. Use the returned instance for further operations as - * the save operation might have changed the entity instance completely. - * + * Saves a given entity. Use the returned instance for further operations as the save operation might have changed the + * entity instance completely. + * * @param entity * @return the saved entity */ T save(T entity); - /** * Saves all given entities. - * + * * @param entities * @return */ Iterable save(Iterable entities); - /** * Retrives an entity by its primary key. - * + * * @param id - * @return the entity with the given primary key or {@code null} if none - * found + * @return the entity with the given primary key or {@code null} if none found * @throws IllegalArgumentException if primaryKey is {@code null} */ T findOne(ID id); - /** * Returns whether an entity with the given id exists. - * + * * @param id * @return true if an entity with the given id exists, alse otherwise * @throws IllegalArgumentException if primaryKey is {@code null} */ boolean exists(ID id); - /** * Returns all instances of the type. - * + * * @return all entities */ Iterable findAll(); - /** * Returns the number of entities available. - * + * * @return the number of entities */ long count(); - /** * Deletes the entity with the given id. * @@ -90,23 +82,20 @@ public interface CrudRepository extends Repository entities); - /** * Deletes all entities managed by the repository. */ diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/NoRepositoryBean.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/NoRepositoryBean.java index c29fbf0ff..db7005a67 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/NoRepositoryBean.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/NoRepositoryBean.java @@ -21,17 +21,15 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; - /** - * Annotation to exclude repository interfaces from being picked up and thus in - * consequence getting an instance being created. + * Annotation to exclude repository interfaces from being picked up and thus in consequence getting an instance being + * created. *

- * This will typically be used when providing an extended base interface for all - * repositories in combination with a custom repository base class to implement - * methods declared in that intermediate interface. In this case you typically - * derive your concrete repository interfaces from the intermediate one but - * don't want to create a Spring bean for the intermediate interface. - * + * This will typically be used when providing an extended base interface for all repositories in combination with a + * custom repository base class to implement methods declared in that intermediate interface. In this case you typically + * derive your concrete repository interfaces from the intermediate one but don't want to create a Spring bean for the + * intermediate interface. + * * @author Oliver Gierke */ @Retention(RetentionPolicy.RUNTIME) diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/PagingAndSortingRepository.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/PagingAndSortingRepository.java index bd760101f..3a4b2d206 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/PagingAndSortingRepository.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/PagingAndSortingRepository.java @@ -21,33 +21,29 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; - /** - * Extension of {@link CrudRepository} to provide additional methods to retrieve - * entities using the pagination and sorting abstraction. - * + * Extension of {@link CrudRepository} to provide additional methods to retrieve entities using the pagination and + * sorting abstraction. + * * @author Oliver Gierke * @see Sort * @see Pageable * @see Page */ @NoRepositoryBean -public interface PagingAndSortingRepository extends - CrudRepository { +public interface PagingAndSortingRepository extends CrudRepository { /** * Returns all entities sorted by the given options. - * + * * @param sort * @return all entities sorted by the given options */ Iterable findAll(Sort sort); - /** - * Returns a {@link Page} of entities meeting the paging restriction - * provided in the {@code Pageable} object. - * + * Returns a {@link Page} of entities meeting the paging restriction provided in the {@code Pageable} object. + * * @param pageable * @return a page of entities */ diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/RepositoryDefinition.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/RepositoryDefinition.java index cf24fb89f..c099d442f 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/RepositoryDefinition.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/RepositoryDefinition.java @@ -43,7 +43,7 @@ public @interface RepositoryDefinition { * @return */ Class domainClass(); - + /** * The id class of the entity the repository manages. Equivalent to the ID type parameter in {@link Repository}. * diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/AbstractRepositoryConfigDefinitionParser.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/AbstractRepositoryConfigDefinitionParser.java index d79cd1453..817f8f7d9 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/AbstractRepositoryConfigDefinitionParser.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/AbstractRepositoryConfigDefinitionParser.java @@ -49,25 +49,19 @@ import org.springframework.data.repository.RepositoryDefinition; import org.springframework.util.StringUtils; import org.w3c.dom.Element; - /** - * Base class to implement repository namespaces. These will typically consist - * of a main XML element potentially having child elements. The parser will wrap - * the XML element into a {@link GlobalRepositoryConfigInformation} object and - * allow either manual configuration or automatic detection of repository - * interfaces. - * + * Base class to implement repository namespaces. These will typically consist of a main XML element potentially having + * child elements. The parser will wrap the XML element into a {@link GlobalRepositoryConfigInformation} object and + * allow either manual configuration or automatic detection of repository interfaces. + * * @author Oliver Gierke */ public abstract class AbstractRepositoryConfigDefinitionParser, T extends SingleRepositoryConfigInformation> implements BeanDefinitionParser { - private static final Log LOG = LogFactory.getLog( - AbstractRepositoryConfigDefinitionParser.class); - - private static final String REPOSITORY_INTERFACE_POST_PROCESSOR = - "org.springframework.data.repository.core.support.RepositoryInterfaceAwareBeanPostProcessor"; + private static final Log LOG = LogFactory.getLog(AbstractRepositoryConfigDefinitionParser.class); + private static final String REPOSITORY_INTERFACE_POST_PROCESSOR = "org.springframework.data.repository.core.support.RepositoryInterfaceAwareBeanPostProcessor"; /* * (non-Javadoc) @@ -97,11 +91,9 @@ public abstract class AbstractRepositoryConfigDefinitionParser repositoryInterfaces = - getRepositoryInterfacesForAutoConfig(config, resourceLoader, - parser.getReaderContext()); + Set repositoryInterfaces = getRepositoryInterfacesForAutoConfig(config, resourceLoader, + parser.getReaderContext()); for (String repositoryInterface : repositoryInterfaces) { - registerGenericRepositoryFactoryBean( - parser, - config.getAutoconfigRepositoryInformation(repositoryInterface)); + registerGenericRepositoryFactoryBean(parser, config.getAutoconfigRepositoryInformation(repositoryInterface)); } } + private Set getRepositoryInterfacesForAutoConfig(S config, ResourceLoader loader, ReaderContext reader) { - private Set getRepositoryInterfacesForAutoConfig(S config, - ResourceLoader loader, ReaderContext reader) { - - ClassPathScanningCandidateComponentProvider scanner = - new RepositoryComponentProvider( - config.getRepositoryBaseInterface()); + ClassPathScanningCandidateComponentProvider scanner = new RepositoryComponentProvider( + config.getRepositoryBaseInterface()); scanner.setResourceLoader(loader); - TypeFilterParser parser = - new TypeFilterParser(loader.getClassLoader(), reader); + TypeFilterParser parser = new TypeFilterParser(loader.getClassLoader(), reader); parser.parseFilters(config.getSource(), scanner); - Set findCandidateComponents = - scanner.findCandidateComponents(config.getBasePackage()); + Set findCandidateComponents = scanner.findCandidateComponents(config.getBasePackage()); Set interfaceNames = new HashSet(); for (BeanDefinition definition : findCandidateComponents) { @@ -148,21 +131,17 @@ public abstract class AbstractRepositoryConfigDefinitionParser definitions = - provider.findCandidateComponents(config.getBasePackage()); + Set definitions = provider.findCandidateComponents(config.getBasePackage()); - return (0 == definitions.size() ? null - : (AbstractBeanDefinition) definitions.iterator().next()); + return (0 == definitions.size() ? null : (AbstractBeanDefinition) definitions.iterator().next()); } - /** - * Callback to register additional bean definitions for a - * {@literal repositories} root node. This usually includes beans you have - * to set up once independently of the number of repositories to be created. - * Will be called before any repositories bean definitions have been - * registered. - * + * Callback to register additional bean definitions for a {@literal repositories} root node. This usually includes + * beans you have to set up once independently of the number of repositories to be created. Will be called before any + * repositories bean definitions have been registered. + * * @param registry * @param source */ - protected void registerBeansForRoot(BeanDefinitionRegistry registry, - Object source) { + protected void registerBeansForRoot(BeanDefinitionRegistry registry, Object source) { - AbstractBeanDefinition definition = - BeanDefinitionBuilder.rootBeanDefinition( - REPOSITORY_INTERFACE_POST_PROCESSOR) - .getBeanDefinition(); + AbstractBeanDefinition definition = BeanDefinitionBuilder.rootBeanDefinition(REPOSITORY_INTERFACE_POST_PROCESSOR) + .getBeanDefinition(); registerWithSourceAndGeneratedBeanName(registry, definition, source); } - /** - * Returns whether the given {@link BeanDefinitionRegistry} already contains - * a bean of the given type assuming the bean name has been autogenerated. - * + * Returns whether the given {@link BeanDefinitionRegistry} already contains a bean of the given type assuming the + * bean name has been autogenerated. + * * @param type * @param registry * @return */ - protected static boolean hasBean(Class type, - BeanDefinitionRegistry registry) { + protected static boolean hasBean(Class type, BeanDefinitionRegistry registry) { - String name = - String.format("%s%s0", type.getName(), - GENERATED_BEAN_NAME_SEPARATOR); + String name = String.format("%s%s0", type.getName(), GENERATED_BEAN_NAME_SEPARATOR); return registry.containsBeanDefinition(name); } - /** - * Sets the given source on the given {@link AbstractBeanDefinition} and - * registers it inside the given {@link BeanDefinitionRegistry}. - * + * Sets the given source on the given {@link AbstractBeanDefinition} and registers it inside the given + * {@link BeanDefinitionRegistry}. + * * @param registry * @param bean * @param source * @return */ - protected static String registerWithSourceAndGeneratedBeanName( - BeanDefinitionRegistry registry, AbstractBeanDefinition bean, - Object source) { + protected static String registerWithSourceAndGeneratedBeanName(BeanDefinitionRegistry registry, + AbstractBeanDefinition bean, Object source) { bean.setSource(source); @@ -402,18 +336,16 @@ public abstract class AbstractRepositoryConfigDefinitionParser repositoryInterface) { @@ -424,7 +356,6 @@ public abstract class AbstractRepositoryConfigDefinitionParser targetType) { @@ -465,7 +391,6 @@ public abstract class AbstractRepositoryConfigDefinitionParserThe matching logic mirrors that of Class.isAnnotationPresent(). - * + * A simple filter which matches classes with a given annotation, checking inherited annotations as well. + * + *

+ * The matching logic mirrors that of Class.isAnnotationPresent(). + * * @author Mark Fisher * @author Ramnivas Laddad * @author Juergen Hoeller @@ -503,13 +426,11 @@ public abstract class AbstractRepositoryConfigDefinitionParserconsiderMetaAnnotations' argument. The filter will - * not match interfaces. + * Create a new AnnotationTypeFilter for the given annotation type. This filter will also match meta-annotations. + * To disable the meta-annotation matching, use the constructor that accepts a ' + * considerMetaAnnotations' argument. The filter will not match interfaces. + * * @param annotationType the annotation type to match */ public AnnotationTypeFilter(Class annotationType) { @@ -517,8 +438,8 @@ public abstract class AbstractRepositoryConfigDefinitionParser annotationType, boolean considerMetaAnnotations, boolean considerInterfaces) { + public AnnotationTypeFilter(Class annotationType, boolean considerMetaAnnotations, + boolean considerInterfaces) { super(annotationType.isAnnotationPresent(Inherited.class), considerInterfaces); this.annotationType = annotationType; this.considerMetaAnnotations = considerMetaAnnotations; } - @Override protected boolean matchSelf(MetadataReader metadataReader) { AnnotationMetadata metadata = metadataReader.getAnnotationMetadata(); - return metadata.hasAnnotation(this.annotationType.getName()) || - (this.considerMetaAnnotations && metadata.hasMetaAnnotation(this.annotationType.getName())); + return metadata.hasAnnotation(this.annotationType.getName()) + || (this.considerMetaAnnotations && metadata.hasMetaAnnotation(this.annotationType.getName())); } @Override protected Boolean matchSuperClass(String superClassName) { if (Object.class.getName().equals(superClassName)) { return Boolean.FALSE; - } - else if (superClassName.startsWith("java.")) { + } else if (superClassName.startsWith("java.")) { try { Class clazz = getClass().getClassLoader().loadClass(superClassName); return (clazz.getAnnotation(this.annotationType) != null); - } - catch (ClassNotFoundException ex) { + } catch (ClassNotFoundException ex) { // Class not found - can't determine a match that way. } } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/AutomaticRepositoryConfigInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/AutomaticRepositoryConfigInformation.java index fb045edd9..2f2079887 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/AutomaticRepositoryConfigInformation.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/AutomaticRepositoryConfigInformation.java @@ -20,24 +20,21 @@ import static org.springframework.util.StringUtils.*; import org.springframework.util.Assert; - /** - * A {@link SingleRepositoryConfigInformation} implementation that is not backed - * by an XML element but by a scanned interface. As this is derived from the - * parent, most of the lookup logic is delegated to the parent as well. - * + * A {@link SingleRepositoryConfigInformation} implementation that is not backed by an XML element but by a scanned + * interface. As this is derived from the parent, most of the lookup logic is delegated to the parent as well. + * * @author Oliver Gierke */ -public class AutomaticRepositoryConfigInformation - extends ParentDelegatingRepositoryConfigInformation { +public class AutomaticRepositoryConfigInformation extends + ParentDelegatingRepositoryConfigInformation { private final String interfaceName; - /** - * Creates a new {@link AutomaticRepositoryConfigInformation} for the given - * interface name and {@link CommonRepositoryConfigInformation} parent. - * + * Creates a new {@link AutomaticRepositoryConfigInformation} for the given interface name and + * {@link CommonRepositoryConfigInformation} parent. + * * @param interfaceName * @param parent */ @@ -48,7 +45,6 @@ public class AutomaticRepositoryConfigInformation> - extends CommonRepositoryConfigInformation { +public interface GlobalRepositoryConfigInformation> extends + CommonRepositoryConfigInformation { /** * Returns the - * + * * @param interfaceName * @return */ T getAutoconfigRepositoryInformation(String interfaceName); - /** - * Returns all {@link SingleRepositoryConfigInformation} instances used for - * manual configuration. - * + * Returns all {@link SingleRepositoryConfigInformation} instances used for manual configuration. + * * @return */ Iterable getSingleRepositoryConfigInformations(); - /** - * Returns whether to consider manual configuration. If this returns true, - * clients should use {@link #getSingleRepositoryConfigInformations()} to - * lookup configuration information for individual repository beans. - * + * Returns whether to consider manual configuration. If this returns true, clients should use + * {@link #getSingleRepositoryConfigInformations()} to lookup configuration information for individual repository + * beans. + * * @return */ boolean configureManually(); - /** * Returns the base interface to use - * + * * @return */ Class getRepositoryBaseInterface(); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/ManualRepositoryConfigInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/ManualRepositoryConfigInformation.java index 0221504d7..50c220268 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/ManualRepositoryConfigInformation.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/ManualRepositoryConfigInformation.java @@ -20,20 +20,18 @@ import static org.springframework.util.StringUtils.*; import org.springframework.data.repository.query.QueryLookupStrategy.Key; import org.w3c.dom.Element; - /** * Configuration information for manual repository configuration. - * + * * @author Oliver Gierke */ -public class ManualRepositoryConfigInformation - extends ParentDelegatingRepositoryConfigInformation { +public class ManualRepositoryConfigInformation extends + ParentDelegatingRepositoryConfigInformation { private static final String CUSTOM_IMPL_REF = "custom-impl-ref"; private Element element; - /** * @param parent */ @@ -43,7 +41,6 @@ public class ManualRepositoryConfigInformation @@ -34,11 +32,10 @@ public abstract class ParentDelegatingRepositoryConfigInformation, S extends CommonRepositoryConfigInformation> @@ -41,35 +39,29 @@ public abstract class RepositoryConfig 0; } - /* * (non-Javadoc) * @@ -105,14 +95,11 @@ public abstract class RepositoryConfig getRepositoryBaseInterface() { - return Repository.class; + return Repository.class; } - private Collection getRepositoryElements() { NodeList nodes = element.getChildNodes(); @@ -217,14 +196,11 @@ public abstract class RepositoryConfig - extends CommonRepositoryConfigInformation { +public interface SingleRepositoryConfigInformation extends + CommonRepositoryConfigInformation { /** * Returns the bean name to be used for the repository. - * + * * @return */ String getBeanId(); - /** * Returns the name of the repository interface. - * + * * @return */ String getInterfaceName(); - /** - * Returns the class name of a possible custom repository implementation - * class to detect. - * + * Returns the class name of a possible custom repository implementation class to detect. + * * @return */ String getImplementationClassName(); - /** - * Returns the bean name a possibly found custom implementation shall be - * registered under. - * + * Returns the bean name a possibly found custom implementation shall be registered under. + * * @return */ String getImplementationBeanName(); - /** * Returns the bean reference to the custom repository implementation. - * + * * @return */ String getCustomImplementationRef(); - /** * Returns whether to try to autodetect a custom implementation. - * + * * @return */ boolean autodetectCustomImplementation(); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/TypeFilterParser.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/TypeFilterParser.java index 80b6aa6da..47da2f85d 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/TypeFilterParser.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/TypeFilterParser.java @@ -31,12 +31,10 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; - /** - * Parser to populate the given - * {@link ClassPathScanningCandidateComponentProvider} with {@link TypeFilter}s - * parsed from the given {@link Element}'s children. - * + * Parser to populate the given {@link ClassPathScanningCandidateComponentProvider} with {@link TypeFilter}s parsed from + * the given {@link Element}'s children. + * * @author Oliver Gierke */ class TypeFilterParser { @@ -47,11 +45,9 @@ class TypeFilterParser { private final ClassLoader classLoader; private final ReaderContext readerContext; - /** - * Creates a new {@link TypeFilterParser} with the given {@link ClassLoader} - * and {@link ReaderContext}. - * + * Creates a new {@link TypeFilterParser} with the given {@link ClassLoader} and {@link ReaderContext}. + * * @param classLoader * @param readerContext */ @@ -61,26 +57,20 @@ class TypeFilterParser { this.readerContext = readerContext; } - /** - * Parses include and exclude filters form the given {@link Element}'s child - * elements and populates the given - * {@link ClassPathScanningCandidateComponentProvider} with the according - * {@link TypeFilter}s. - * + * Parses include and exclude filters form the given {@link Element}'s child elements and populates the given + * {@link ClassPathScanningCandidateComponentProvider} with the according {@link TypeFilter}s. + * * @param element * @param scanner */ - public void parseFilters(Element element, - ClassPathScanningCandidateComponentProvider scanner) { + public void parseFilters(Element element, ClassPathScanningCandidateComponentProvider scanner) { parseTypeFilters(element, scanner, Type.INCLUDE); parseTypeFilters(element, scanner, Type.EXCLUDE); } - - private void parseTypeFilters(Element element, - ClassPathScanningCandidateComponentProvider scanner, Type type) { + private void parseTypeFilters(Element element, ClassPathScanningCandidateComponentProvider scanner, Type type) { NodeList nodeList = element.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { @@ -92,21 +82,16 @@ class TypeFilterParser { try { - type.addFilter( - createTypeFilter((Element) node, classLoader), - scanner); + type.addFilter(createTypeFilter((Element) node, classLoader), scanner); } catch (RuntimeException e) { - readerContext.error(e.getMessage(), - readerContext.extractSource(element), e.getCause()); + readerContext.error(e.getMessage(), readerContext.extractSource(element), e.getCause()); } } } } - - protected TypeFilter createTypeFilter(Element element, - ClassLoader classLoader) { + protected TypeFilter createTypeFilter(Element element, ClassLoader classLoader) { String filterType = element.getAttribute(FILTER_TYPE_ATTRIBUTE); String expression = element.getAttribute(FILTER_EXPRESSION_ATTRIBUTE); @@ -117,16 +102,14 @@ class TypeFilterParser { return filter.getFilter(expression, classLoader); } catch (ClassNotFoundException ex) { - throw new FatalBeanException("Type filter class not found: " - + expression, ex); + throw new FatalBeanException("Type filter class not found: " + expression, ex); } } /** - * Enum representing all the filter types available for {@code include} and - * {@code exclude} elements. This acts as factory for {@link TypeFilter} - * instances. - * + * Enum representing all the filter types available for {@code include} and {@code exclude} elements. This acts as + * factory for {@link TypeFilter} instances. + * * @author Oliver Gierke * @see #getFilter(String, ClassLoader) */ @@ -135,29 +118,24 @@ class TypeFilterParser { ANNOTATION { @Override @SuppressWarnings("unchecked") - public TypeFilter getFilter(String expression, - ClassLoader classLoader) throws ClassNotFoundException { + public TypeFilter getFilter(String expression, ClassLoader classLoader) throws ClassNotFoundException { - return new AnnotationTypeFilter( - (Class) classLoader.loadClass(expression)); + return new AnnotationTypeFilter((Class) classLoader.loadClass(expression)); } }, ASSIGNABLE { @Override - public TypeFilter getFilter(String expression, - ClassLoader classLoader) throws ClassNotFoundException { + public TypeFilter getFilter(String expression, ClassLoader classLoader) throws ClassNotFoundException { - return new AssignableTypeFilter( - classLoader.loadClass(expression)); + return new AssignableTypeFilter(classLoader.loadClass(expression)); } }, ASPECTJ { @Override - public TypeFilter getFilter(String expression, - ClassLoader classLoader) { + public TypeFilter getFilter(String expression, ClassLoader classLoader) { return new AspectJTypeFilter(expression, classLoader); } @@ -166,8 +144,7 @@ class TypeFilterParser { REGEX { @Override - public TypeFilter getFilter(String expression, - ClassLoader classLoader) { + public TypeFilter getFilter(String expression, ClassLoader classLoader) { return new RegexPatternTypeFilter(Pattern.compile(expression)); } @@ -176,40 +153,33 @@ class TypeFilterParser { CUSTOM { @Override - public TypeFilter getFilter(String expression, - ClassLoader classLoader) throws ClassNotFoundException { + public TypeFilter getFilter(String expression, ClassLoader classLoader) throws ClassNotFoundException { Class filterClass = classLoader.loadClass(expression); if (!TypeFilter.class.isAssignableFrom(filterClass)) { - throw new IllegalArgumentException( - "Class is not assignable to [" - + TypeFilter.class.getName() + "]: " - + expression); + throw new IllegalArgumentException("Class is not assignable to [" + TypeFilter.class.getName() + "]: " + + expression); } return (TypeFilter) BeanUtils.instantiateClass(filterClass); } }; /** - * Returns the {@link TypeFilter} for the given expression and - * {@link ClassLoader}. - * + * Returns the {@link TypeFilter} for the given expression and {@link ClassLoader}. + * * @param expression * @param classLoader * @return * @throws ClassNotFoundException */ - abstract TypeFilter getFilter(String expression, ClassLoader classLoader) - throws ClassNotFoundException; - + abstract TypeFilter getFilter(String expression, ClassLoader classLoader) throws ClassNotFoundException; /** * Returns the {@link FilterType} for the given type as {@link String}. - * + * * @param typeString * @return - * @throws IllegalArgumentException if no {@link FilterType} could be - * found for the given argument. + * @throws IllegalArgumentException if no {@link FilterType} could be found for the given argument. */ static FilterType fromString(String typeString) { @@ -219,8 +189,7 @@ class TypeFilterParser { } } - throw new IllegalArgumentException("Unsupported filter type: " - + typeString); + throw new IllegalArgumentException("Unsupported filter type: " + typeString); } } @@ -228,8 +197,7 @@ class TypeFilterParser { INCLUDE("include-filter") { @Override - public void addFilter(TypeFilter filter, - ClassPathScanningCandidateComponentProvider scanner) { + public void addFilter(TypeFilter filter, ClassPathScanningCandidateComponentProvider scanner) { scanner.addIncludeFilter(filter); } @@ -237,8 +205,7 @@ class TypeFilterParser { }, EXCLUDE("exclude-filter") { @Override - public void addFilter(TypeFilter filter, - ClassPathScanningCandidateComponentProvider scanner) { + public void addFilter(TypeFilter filter, ClassPathScanningCandidateComponentProvider scanner) { scanner.addExcludeFilter(filter); } @@ -246,17 +213,15 @@ class TypeFilterParser { private String elementName; - private Type(String elementName) { this.elementName = elementName; } - /** - * Returns the {@link Element} if the given {@link Node} is an - * {@link Element} and it's name equals the one of the type. - * + * Returns the {@link Element} if the given {@link Node} is an {@link Element} and it's name equals the one of the + * type. + * * @param node * @return */ @@ -272,8 +237,6 @@ class TypeFilterParser { return null; } - - abstract void addFilter(TypeFilter filter, - ClassPathScanningCandidateComponentProvider scanner); + abstract void addFilter(TypeFilter filter, ClassPathScanningCandidateComponentProvider scanner); } } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/EntityInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/EntityInformation.java index 2fff84441..bb05a7774 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/EntityInformation.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/EntityInformation.java @@ -18,25 +18,23 @@ package org.springframework.data.repository.core; import java.io.Serializable; /** - * Extension of {@link EntityMetadata} to add functionality to query information - * of entity instances. - * + * Extension of {@link EntityMetadata} to add functionality to query information of entity instances. + * * @author Oliver Gierke */ public interface EntityInformation extends EntityMetadata { /** * Returns whether the given entity is considered to be new. - * + * * @param entity must never be {@literal null} * @return */ boolean isNew(T entity); - /** * Returns the id of the given entity. - * + * * @param entity must never be {@literal null} * @return */ @@ -44,7 +42,7 @@ public interface EntityInformation extends EntityMet /** * Returns the type of the id of the entity. - * + * * @return */ Class getIdType(); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/EntityMetadata.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/EntityMetadata.java index 02d5199ce..f0d89c852 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/EntityMetadata.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/EntityMetadata.java @@ -17,14 +17,14 @@ package org.springframework.data.repository.core; /** * Metadata for entity types. - * + * * @author Oliver Gierke */ public interface EntityMetadata { /** * Returns the actual domain class type. - * + * * @return */ Class getJavaType(); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/NamedQueries.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/NamedQueries.java index 829f68fe8..9894cbba8 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/NamedQueries.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/NamedQueries.java @@ -17,7 +17,7 @@ package org.springframework.data.repository.core; /** * Abstraction of a map of {@link NamedQueries} that can be looked up by their names. - * + * * @author Oliver Gierke */ public interface NamedQueries { diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/RepositoryInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/RepositoryInformation.java index 9da893ad1..37d120f0b 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/RepositoryInformation.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/RepositoryInformation.java @@ -19,55 +19,48 @@ import java.lang.reflect.Method; /** * Aditional repository specific information - * + * * @author Oliver Gierke */ public interface RepositoryInformation extends RepositoryMetadata { /** * Returns the base class to be used to create the proxy backing instance. - * + * * @return */ Class getRepositoryBaseClass(); - /** - * Returns if the configured repository interface has custom methods, that - * might have to be delegated to a custom implementation. This is used to - * verify repository configuration. - * + * Returns if the configured repository interface has custom methods, that might have to be delegated to a custom + * implementation. This is used to verify repository configuration. + * * @return */ boolean hasCustomMethod(); - /** * Returns whether the given method is a custom repository method. - * + * * @param method * @param baseClass * @return */ boolean isCustomMethod(Method method); - /** * Returns all methods considered to be query methods. - * + * * @param repositoryInterface * @return */ Iterable getQueryMethods(); - /** - * Returns the target class method that is backing the given method. This can - * be necessary if a repository interface redeclares a method of the core - * repository interface (e.g. for transaction behaviour customization). - * Returns the method itself if the target class does not implement the given - * method. - * + * Returns the target class method that is backing the given method. This can be necessary if a repository interface + * redeclares a method of the core repository interface (e.g. for transaction behaviour customization). Returns the + * method itself if the target class does not implement the given method. + * * @param method * @return */ diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/RepositoryMetadata.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/RepositoryMetadata.java index 090e28ebe..27defe2d2 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/RepositoryMetadata.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/RepositoryMetadata.java @@ -15,35 +15,32 @@ */ package org.springframework.data.repository.core; - /** * Metadata for repository interfaces. - * + * * @author Oliver Gierke */ public interface RepositoryMetadata { /** * Returns the id class the given class is declared for. - * + * * @param clazz - * @return the id class of the entity managed by the repository for or - * {@code null} if none found. + * @return the id class of the entity managed by the repository for or {@code null} if none found. */ Class getIdClass(); /** * Returns the domain class the repository is declared for. - * + * * @param clazz - * @return the domain class the repository is handling or {@code null} if - * none found. + * @return the domain class the repository is handling or {@code null} if none found. */ Class getDomainClass(); /** * Returns the repository interface. - * + * * @return */ Class getRepositoryInterface(); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/AbstractEntityInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/AbstractEntityInformation.java index 255d8049a..d297c1b66 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/AbstractEntityInformation.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/AbstractEntityInformation.java @@ -20,23 +20,19 @@ import java.io.Serializable; import org.springframework.data.repository.core.EntityInformation; import org.springframework.util.Assert; - /** - * Base class for implementations of {@link EntityInformation}. Considers an - * entity to be new whenever {@link #getId(Object)} returns {@literal null}. - * + * Base class for implementations of {@link EntityInformation}. Considers an entity to be new whenever + * {@link #getId(Object)} returns {@literal null}. + * * @author Oliver Gierke */ -public abstract class AbstractEntityInformation implements - EntityInformation { +public abstract class AbstractEntityInformation implements EntityInformation { private final Class domainClass; - /** - * Creates a new {@link AbstractEntityInformation} from the given domain - * class. - * + * Creates a new {@link AbstractEntityInformation} from the given domain class. + * * @param domainClass */ public AbstractEntityInformation(Class domainClass) { @@ -45,7 +41,6 @@ public abstract class AbstractEntityInformation impl this.domainClass = domainClass; } - /* * (non-Javadoc) * @@ -58,7 +53,6 @@ public abstract class AbstractEntityInformation impl return getId(entity) == null; } - /* * (non-Javadoc) * diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java index 7e40814c7..3e6cf1431 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java @@ -20,18 +20,18 @@ import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.util.Assert; /** - * {@link RepositoryMetadata} implementation inspecting the given repository interface for a {@link RepositoryDefinition} - * annotation. + * {@link RepositoryMetadata} implementation inspecting the given repository interface for a + * {@link RepositoryDefinition} annotation. * * @author Oliver Gierke */ public class AnnotationRepositoryMetadata implements RepositoryMetadata { - + private static final String NO_ANNOTATION_FOUND = String.format("Interface must be annotated with @%s!", RepositoryDefinition.class.getName()); - + private final Class repositoryInterface; - + public AnnotationRepositoryMetadata(Class repositoryInterface) { Assert.notNull(repositoryInterface, "Repository interface must not be null!"); Assert.isTrue(repositoryInterface.isAnnotationPresent(RepositoryDefinition.class), NO_ANNOTATION_FOUND); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java index c68dce21b..c72e4fa2c 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java @@ -34,7 +34,7 @@ import org.springframework.util.Assert; /** * Default implementation of {@link RepositoryInformation}. - * + * * @author Oliver Gierke */ class DefaultRepositoryInformation implements RepositoryInformation { @@ -52,12 +52,13 @@ class DefaultRepositoryInformation implements RepositoryInformation { /** * Creates a new {@link DefaultRepositoryMetadata} for the given repository interface and repository base class. - * + * * @param metadata * @param repositoryBaseClass * @param customImplementationClass */ - public DefaultRepositoryInformation(RepositoryMetadata metadata, Class repositoryBaseClass, Class customImplementationClass) { + public DefaultRepositoryInformation(RepositoryMetadata metadata, Class repositoryBaseClass, + Class customImplementationClass) { Assert.notNull(metadata); Assert.notNull(repositoryBaseClass); @@ -104,18 +105,18 @@ class DefaultRepositoryInformation implements RepositoryInformation { * @see org.springframework.data.repository.support.RepositoryInformation#getTargetClassMethod(java.lang.reflect.Method) */ public Method getTargetClassMethod(Method method) { - + if (methodCache.containsKey(method)) { return methodCache.get(method); } - + Method result = getTargetClassMethod(method, customImplementationClass); - + if (!result.equals(method)) { methodCache.put(method, result); return result; } - + result = getTargetClassMethod(method, repositoryBaseClass); methodCache.put(method, result); return result; @@ -123,14 +124,14 @@ class DefaultRepositoryInformation implements RepositoryInformation { /** * Returns whether the given method is considered to be a repository base class method. - * + * * @param method * @return */ private boolean isTargetClassMethod(Method method, Class targetType) { Assert.notNull(method); - + if (targetType == null) { return false; } @@ -141,7 +142,6 @@ class DefaultRepositoryInformation implements RepositoryInformation { return !method.equals(getTargetClassMethod(method, targetType)); } - /* * (non-Javadoc) @@ -167,10 +167,10 @@ class DefaultRepositoryInformation implements RepositoryInformation { public boolean isCustomMethod(Method method) { return isTargetClassMethod(method, customImplementationClass); } - + /** * Returns whether the given method is a method covered by the base implementation. - * + * * @param method * @return */ @@ -180,15 +180,15 @@ class DefaultRepositoryInformation implements RepositoryInformation { /** * Returns the given target class' method if the given method (declared in the repository interface) was also declared - * at the target class. Returns the given method if the given base class does not declare the method given. - * Takes generics into account. - * + * at the target class. Returns the given method if the given base class does not declare the method given. Takes + * generics into account. + * * @param method must not be {@literal null} * @param baseClass * @return */ Method getTargetClassMethod(Method method, Class baseClass) { - + if (baseClass == null) { return method; } @@ -241,7 +241,7 @@ class DefaultRepositoryInformation implements RepositoryInformation { /** * Checks the given method's parameters to match the ones of the given base class method. Matches generic arguments * agains the ones bound in the given repository interface. - * + * * @param method * @param baseClassMethod * @return @@ -276,7 +276,7 @@ class DefaultRepositoryInformation implements RepositoryInformation { * Checks whether the given parameter type matches the generic type of the given parameter. Thus when {@literal PK} is * declared, the method ensures that given method parameter is the primary key type declared in the given repository * interface e.g. - * + * * @param name * @param parameterType * @return diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java index 7b8610602..3f62131fc 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java @@ -22,8 +22,8 @@ import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.util.Assert; /** - * Default implementation of {@link RepositoryMetadata}. Will inspect generic types of - * {@link Repository} to find out about domain and id class. + * Default implementation of {@link RepositoryMetadata}. Will inspect generic types of {@link Repository} to find out + * about domain and id class. * * @author Oliver Gierke */ @@ -31,11 +31,9 @@ public class DefaultRepositoryMetadata implements RepositoryMetadata { private final Class repositoryInterface; - /** - * Creates a new {@link DefaultRepositoryMetadata} for the given repository - * interface. - * + * Creates a new {@link DefaultRepositoryMetadata} for the given repository interface. + * * @param repositoryInterface */ public DefaultRepositoryMetadata(Class repositoryInterface) { @@ -45,7 +43,6 @@ public class DefaultRepositoryMetadata implements RepositoryMetadata { this.repositoryInterface = repositoryInterface; } - /* * (non-Javadoc) * @see org.springframework.data.repository.support.RepositoryMetadata#getRepositoryInterface() @@ -55,27 +52,23 @@ public class DefaultRepositoryMetadata implements RepositoryMetadata { return repositoryInterface; } - /* * (non-Javadoc) * @see org.springframework.data.repository.support.RepositoryMetadata#getDomainClass() */ public Class getDomainClass() { - - Class[] arguments = - resolveTypeArguments(repositoryInterface, Repository.class); + + Class[] arguments = resolveTypeArguments(repositoryInterface, Repository.class); return arguments == null ? null : arguments[0]; } - /* * (non-Javadoc) * @see org.springframework.data.repository.support.RepositoryMetadata#getIdClass() */ public Class getIdClass() { - Class[] arguments = - resolveTypeArguments(repositoryInterface, Repository.class); + Class[] arguments = resolveTypeArguments(repositoryInterface, Repository.class); return arguments == null ? null : arguments[1]; } } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/PersistableEntityInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/PersistableEntityInformation.java index 78db0d032..bb55c2ee6 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/PersistableEntityInformation.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/PersistableEntityInformation.java @@ -21,12 +21,10 @@ import org.springframework.core.GenericTypeResolver; import org.springframework.data.domain.Persistable; import org.springframework.data.repository.core.EntityMetadata; - /** - * Implementation of {@link EntityMetadata} that assumes the entity handled - * implements {@link Persistable} and uses {@link Persistable#isNew()} for the - * {@link #isNew(Object)} check. - * + * Implementation of {@link EntityMetadata} that assumes the entity handled implements {@link Persistable} and uses + * {@link Persistable#isNew()} for the {@link #isNew(Object)} check. + * * @author Oliver Gierke */ public class PersistableEntityInformation, ID extends Serializable> extends @@ -36,7 +34,7 @@ public class PersistableEntityInformation, ID extends /** * Creates a new {@link PersistableEntityInformation}. - * + * * @param domainClass */ @SuppressWarnings("unchecked") @@ -46,7 +44,6 @@ public class PersistableEntityInformation, ID extends this.idClass = (Class) GenericTypeResolver.resolveTypeArgument(domainClass, Persistable.class); } - /* * (non-Javadoc) * @@ -60,7 +57,6 @@ public class PersistableEntityInformation, ID extends return entity.isNew(); } - /* * (non-Javadoc) * diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/PropertiesBasedNamedQueries.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/PropertiesBasedNamedQueries.java index a070b412c..04dff922e 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/PropertiesBasedNamedQueries.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/PropertiesBasedNamedQueries.java @@ -22,15 +22,15 @@ import org.springframework.util.Assert; /** * {@link NamedQueries} implementation backed by a {@link Properties} instance. - * + * * @author Oliver Gierke */ public class PropertiesBasedNamedQueries implements NamedQueries { - - public static NamedQueries EMPTY = new PropertiesBasedNamedQueries(new Properties()); + + public static NamedQueries EMPTY = new PropertiesBasedNamedQueries(new Properties()); private final Properties properties; - + /** * Creates a new {@link PropertiesBasedNamedQueries} for the given {@link Properties} instance. * @@ -40,14 +40,14 @@ public class PropertiesBasedNamedQueries implements NamedQueries { Assert.notNull(properties); this.properties = properties; } - + /* (non-Javadoc) * @see org.springframework.data.repository.core.NamedQueries#hasNamedQuery(java.lang.String) */ public boolean hasQuery(String queryName) { return properties.containsKey(queryName); } - + /* (non-Javadoc) * @see org.springframework.data.repository.core.NamedQueries#getNamedQuery(java.lang.String) */ diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/QueryCreationListener.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/QueryCreationListener.java index 092d894e3..879517562 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/QueryCreationListener.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/QueryCreationListener.java @@ -17,18 +17,16 @@ package org.springframework.data.repository.core.support; import org.springframework.data.repository.query.RepositoryQuery; - /** - * Callback for listeners that want to execute functionality on - * {@link RepositoryQuery} creation. - * + * Callback for listeners that want to execute functionality on {@link RepositoryQuery} creation. + * * @author Oliver Gierke */ public interface QueryCreationListener { /** * Will be invoked just after the {@link RepositoryQuery} was created. - * + * * @param query */ void onCreation(T query); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java index 1a4b3d277..f098f0c71 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java @@ -28,16 +28,15 @@ import org.springframework.data.repository.query.QueryLookupStrategy; import org.springframework.data.repository.query.QueryLookupStrategy.Key; import org.springframework.util.Assert; - /** - * Adapter for Springs {@link FactoryBean} interface to allow easy setup of - * repository factories via Spring configuration. - * + * Adapter for Springs {@link FactoryBean} interface to allow easy setup of repository factories via Spring + * configuration. + * * @param the type of the repository * @author Oliver Gierke */ -public abstract class RepositoryFactoryBeanSupport, S, ID extends Serializable> - implements InitializingBean, RepositoryFactoryInformation, FactoryBean { +public abstract class RepositoryFactoryBeanSupport, S, ID extends Serializable> implements + InitializingBean, RepositoryFactoryInformation, FactoryBean { private RepositoryFactorySupport factory; @@ -46,10 +45,9 @@ public abstract class RepositoryFactoryBeanSupport, private Object customImplementation; private NamedQueries namedQueries; - /** * Setter to inject the repository interface to implement. - * + * * @param repositoryInterface the repository interface to set */ @Required @@ -59,10 +57,9 @@ public abstract class RepositoryFactoryBeanSupport, this.repositoryInterface = repositoryInterface; } - /** * Set the {@link QueryLookupStrategy.Key} to be used. - * + * * @param queryLookupStrategyKey */ public void setQueryLookupStrategyKey(Key queryLookupStrategyKey) { @@ -70,10 +67,9 @@ public abstract class RepositoryFactoryBeanSupport, this.queryLookupStrategyKey = queryLookupStrategyKey; } - /** * Setter to inject a custom repository implementation. - * + * * @param customImplementation */ public void setCustomImplementation(Object customImplementation) { @@ -81,7 +77,6 @@ public abstract class RepositoryFactoryBeanSupport, this.customImplementation = customImplementation; } - /** * Setter to inject a {@link NamedQueries} instance. * @@ -101,7 +96,6 @@ public abstract class RepositoryFactoryBeanSupport, return (EntityInformation) factory.getEntityInformation(repositoryMetadata.getDomainClass()); } - /* (non-Javadoc) * @see org.springframework.data.repository.support.RepositoryFactoryInformation#getRepositoryInterface() */ @@ -120,7 +114,6 @@ public abstract class RepositoryFactoryBeanSupport, return factory.getRepository(repositoryInterface, customImplementation); } - /* * (non-Javadoc) * @@ -129,11 +122,9 @@ public abstract class RepositoryFactoryBeanSupport, @SuppressWarnings("unchecked") public Class getObjectType() { - return (Class) (null == repositoryInterface ? Repository.class - : repositoryInterface); + return (Class) (null == repositoryInterface ? Repository.class : repositoryInterface); } - /* * (non-Javadoc) * @@ -144,7 +135,6 @@ public abstract class RepositoryFactoryBeanSupport, return true; } - /* * (non-Javadoc) * @@ -158,10 +148,9 @@ public abstract class RepositoryFactoryBeanSupport, this.factory.setNamedQueries(namedQueries); } - /** * Create the actual {@link RepositoryFactorySupport} instance. - * + * * @return */ protected abstract RepositoryFactorySupport createRepositoryFactory(); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryInformation.java index 54bee11d9..30e67e096 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryInformation.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryInformation.java @@ -20,26 +20,23 @@ import java.io.Serializable; import org.springframework.data.repository.Repository; import org.springframework.data.repository.core.EntityInformation; - /** - * Interface for components that can provide {@link EntityInformation} this - * interface - * + * Interface for components that can provide {@link EntityInformation} this interface + * * @author Oliver Gierke */ public interface RepositoryFactoryInformation { /** * Returns {@link EntityInformation} the repository factory is using. - * + * * @return */ EntityInformation getEntityInformation(); - /** * Returns the interface of the {@link Repository} the factory will create. - * + * * @return */ Class> getRepositoryInterface(); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java index 4e2b562af..3ab915fe2 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java @@ -40,35 +40,30 @@ import org.springframework.data.repository.query.QueryLookupStrategy.Key; import org.springframework.data.repository.util.ClassUtils; import org.springframework.util.Assert; - /** - * Factory bean to create instances of a given repository interface. Creates a - * proxy implementing the configured repository interface and apply an advice - * handing the control to the {@code QueryExecuterMethodInterceptor}. Query - * detection strategy can be configured by setting - * {@link QueryLookupStrategy.Key}. - * + * Factory bean to create instances of a given repository interface. Creates a proxy implementing the configured + * repository interface and apply an advice handing the control to the {@code QueryExecuterMethodInterceptor}. Query + * detection strategy can be configured by setting {@link QueryLookupStrategy.Key}. + * * @author Oliver Gierke */ public abstract class RepositoryFactorySupport { - private final List postProcessors = - new ArrayList(); + private final List postProcessors = new ArrayList(); private QueryLookupStrategy.Key queryLookupStrategyKey; - private List> queryPostProcessors = - new ArrayList>(); + private List> queryPostProcessors = new ArrayList>(); private NamedQueries namedQueries = PropertiesBasedNamedQueries.EMPTY; /** * Sets the strategy of how to lookup a query to execute finders. - * + * * @param queryLookupStrategy the createFinderQueries to set */ public void setQueryLookupStrategyKey(Key key) { this.queryLookupStrategyKey = key; } - + /** * Configures a {@link NamedQueries} instance to be handed to the {@link QueryLookupStrategy} for query creation. * @@ -78,12 +73,10 @@ public abstract class RepositoryFactorySupport { this.namedQueries = namedQueries == null ? PropertiesBasedNamedQueries.EMPTY : namedQueries; } - /** - * Adds a {@link QueryCreationListener} to the factory to plug in - * functionality triggered right after creation of {@link RepositoryQuery} - * instances. - * + * Adds a {@link QueryCreationListener} to the factory to plug in functionality triggered right after creation of + * {@link RepositoryQuery} instances. + * * @param listener */ public void addQueryCreationListener(QueryCreationListener listener) { @@ -92,50 +85,42 @@ public abstract class RepositoryFactorySupport { this.queryPostProcessors.add(listener); } - /** - * Adds {@link RepositoryProxyPostProcessor}s to the factory to allow - * manipulation of the {@link ProxyFactory} before the proxy gets created. - * Note that the {@link QueryExecutorMethodInterceptor} will be added to the - * proxy after the {@link RepositoryProxyPostProcessor}s are - * considered. - * + * Adds {@link RepositoryProxyPostProcessor}s to the factory to allow manipulation of the {@link ProxyFactory} before + * the proxy gets created. Note that the {@link QueryExecutorMethodInterceptor} will be added to the proxy + * after the {@link RepositoryProxyPostProcessor}s are considered. + * * @param processor */ - public void addRepositoryProxyPostProcessor( - RepositoryProxyPostProcessor processor) { + public void addRepositoryProxyPostProcessor(RepositoryProxyPostProcessor processor) { Assert.notNull(processor); this.postProcessors.add(processor); } - /** * Returns a repository instance for the given interface. - * + * * @param * @param repositoryInterface * @return */ - public > T getRepository( - Class repositoryInterface) { + public > T getRepository(Class repositoryInterface) { return getRepository(repositoryInterface, null); } - /** - * Returns a repository instance for the given interface backed by an - * instance providing implementation logic for custom logic. - * + * Returns a repository instance for the given interface backed by an instance providing implementation logic for + * custom logic. + * * @param * @param repositoryInterface * @param customImplementation * @return */ - @SuppressWarnings({"unchecked"}) - public T getRepository(Class repositoryInterface, - Object customImplementation) { + @SuppressWarnings({ "unchecked" }) + public T getRepository(Class repositoryInterface, Object customImplementation) { RepositoryMetadata metadata = getRepositoryMetadata(repositoryInterface); Class customImplementationClass = null == customImplementation ? null : customImplementation.getClass(); @@ -148,21 +133,20 @@ public abstract class RepositoryFactorySupport { // Create proxy ProxyFactory result = new ProxyFactory(); result.setTarget(target); - result.setInterfaces(new Class[]{repositoryInterface}); + result.setInterfaces(new Class[] { repositoryInterface }); for (RepositoryProxyPostProcessor processor : postProcessors) { processor.postProcess(result); } - result.addAdvice(new QueryExecutorMethodInterceptor(information, - customImplementation, target)); + result.addAdvice(new QueryExecutorMethodInterceptor(information, customImplementation, target)); return (T) result.getProxy(); } /** * Returns the {@link RepositoryMetadata} for the given repository interface. - * + * * @param repositoryInterface * @return */ @@ -171,10 +155,9 @@ public abstract class RepositoryFactorySupport { : new AnnotationRepositoryMetadata(repositoryInterface); } - /** * Returns the {@link RepositoryInformation} for the given repository interface. - * + * * @param repositoryInterface * @param customImplementationClass * @return @@ -183,41 +166,36 @@ public abstract class RepositoryFactorySupport { return new DefaultRepositoryInformation(metadata, getRepositoryBaseClass(metadata), customImplementationClass); } - /** * Returns the {@link EntityInformation} for the given domain class. - * - * @param the entity type - * @param the id type + * + * @param the entity type + * @param the id type * @param domainClass * @return */ public abstract EntityInformation getEntityInformation(Class domainClass); - /** * Create a repository instance as backing for the query proxy. - * + * * @param metadata * @return */ protected abstract Object getTargetRepository(RepositoryMetadata metadata); - /** * Returns the base class backing the actual repository instance. Make sure - * {@link #getTargetRepository(RepositoryMetadata)} returns an instance of - * this class. - * + * {@link #getTargetRepository(RepositoryMetadata)} returns an instance of this class. + * * @param metadata * @return */ - protected abstract Class getRepositoryBaseClass( - RepositoryMetadata metadata); + protected abstract Class getRepositoryBaseClass(RepositoryMetadata metadata); /** * Returns the {@link QueryLookupStrategy} for the given {@link Key}. - * + * * @param key can be {@literal null} * @return the {@link QueryLookupStrategy} to use or {@literal null} if no queries should be looked up. */ @@ -225,24 +203,19 @@ public abstract class RepositoryFactorySupport { return null; } - /** - * Validates the given repository interface as well as the given custom - * implementation. - * + * Validates the given repository interface as well as the given custom implementation. + * * @param repositoryInformation * @param customImplementation */ - private void validate(RepositoryInformation repositoryInformation, - Object customImplementation) { + private void validate(RepositoryInformation repositoryInformation, Object customImplementation) { - if (null == customImplementation - && repositoryInformation.hasCustomMethod()) { + if (null == customImplementation && repositoryInformation.hasCustomMethod()) { - throw new IllegalArgumentException( - String.format( - "You have custom methods in %s but not provided a custom implementation!", - repositoryInformation.getRepositoryInterface())); + throw new IllegalArgumentException(String.format( + "You have custom methods in %s but not provided a custom implementation!", + repositoryInformation.getRepositoryInterface())); } validate(repositoryInformation); @@ -253,77 +226,63 @@ public abstract class RepositoryFactorySupport { } /** - * This {@code MethodInterceptor} intercepts calls to methods of the custom - * implementation and delegates the to it if configured. Furthermore it - * resolves method calls to finders and triggers execution of them. You can - * rely on having a custom repository implementation instance set if this - * returns true. - * + * This {@code MethodInterceptor} intercepts calls to methods of the custom implementation and delegates the to it if + * configured. Furthermore it resolves method calls to finders and triggers execution of them. You can rely on having + * a custom repository implementation instance set if this returns true. + * * @author Oliver Gierke */ public class QueryExecutorMethodInterceptor implements MethodInterceptor { - private final Map queries = - new ConcurrentHashMap(); + private final Map queries = new ConcurrentHashMap(); private final Object customImplementation; private final RepositoryInformation repositoryInformation; private final Object target; - /** - * Creates a new {@link QueryExecutorMethodInterceptor}. Builds a model - * of {@link QueryMethod}s to be invoked on execution of repository - * interface methods. + * Creates a new {@link QueryExecutorMethodInterceptor}. Builds a model of {@link QueryMethod}s to be invoked on + * execution of repository interface methods. */ - public QueryExecutorMethodInterceptor( - RepositoryInformation repositoryInformation, - Object customImplementation, Object target) { + public QueryExecutorMethodInterceptor(RepositoryInformation repositoryInformation, Object customImplementation, + Object target) { this.repositoryInformation = repositoryInformation; this.customImplementation = customImplementation; this.target = target; - QueryLookupStrategy lookupStrategy = - getQueryLookupStrategy(queryLookupStrategyKey); + QueryLookupStrategy lookupStrategy = getQueryLookupStrategy(queryLookupStrategyKey); if (lookupStrategy == null) { if (repositoryInformation.hasCustomMethod()) { - throw new IllegalStateException( - "You have defined query method in the repository but " + - "you don't have no query lookup strategy defined. The " + - "infrastructure apparently does not support query methods!"); + throw new IllegalStateException("You have defined query method in the repository but " + + "you don't have no query lookup strategy defined. The " + + "infrastructure apparently does not support query methods!"); } return; } for (Method method : repositoryInformation.getQueryMethods()) { - RepositoryQuery query = - lookupStrategy.resolveQuery(method, repositoryInformation, namedQueries); + RepositoryQuery query = lookupStrategy.resolveQuery(method, repositoryInformation, namedQueries); invokeListeners(query); queries.put(method, query); } } - - @SuppressWarnings({"rawtypes", "unchecked"}) + @SuppressWarnings({ "rawtypes", "unchecked" }) private void invokeListeners(RepositoryQuery query) { for (QueryCreationListener listener : queryPostProcessors) { - Class typeArgument = - GenericTypeResolver.resolveTypeArgument( - listener.getClass(), - QueryCreationListener.class); - if (typeArgument != null - && typeArgument.isAssignableFrom(query.getClass())) { + Class typeArgument = GenericTypeResolver.resolveTypeArgument(listener.getClass(), + QueryCreationListener.class); + if (typeArgument != null && typeArgument.isAssignableFrom(query.getClass())) { listener.onCreation(query); } } } - /* * (non-Javadoc) * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation) @@ -335,8 +294,7 @@ public abstract class RepositoryFactorySupport { if (isCustomMethodInvocation(invocation)) { Method actualMethod = repositoryInformation.getTargetClassMethod(method); makeAccessible(actualMethod); - return executeMethodOn(customImplementation, actualMethod, - invocation.getArguments()); + return executeMethodOn(customImplementation, actualMethod, invocation.getArguments()); } if (hasQueryFor(method)) { @@ -346,23 +304,19 @@ public abstract class RepositoryFactorySupport { // Lookup actual method as it might be redeclared in the interface // and we have to use the repository instance nevertheless Method actualMethod = repositoryInformation.getTargetClassMethod(method); - return executeMethodOn(target, actualMethod, - invocation.getArguments()); + return executeMethodOn(target, actualMethod, invocation.getArguments()); } - /** - * Executes the given method on the given target. Correctly unwraps - * exceptions not caused by the reflection magic. - * + * Executes the given method on the given target. Correctly unwraps exceptions not caused by the reflection magic. + * * @param target * @param method * @param parameters * @return * @throws Throwable */ - private Object executeMethodOn(Object target, Method method, - Object[] parameters) throws Throwable { + private Object executeMethodOn(Object target, Method method, Object[] parameters) throws Throwable { try { return method.invoke(target, parameters); @@ -373,11 +327,9 @@ public abstract class RepositoryFactorySupport { throw new IllegalStateException("Should not occur!"); } - /** - * Returns whether we know of a query to execute for the given - * {@link Method}; - * + * Returns whether we know of a query to execute for the given {@link Method}; + * * @param method * @return */ @@ -386,11 +338,10 @@ public abstract class RepositoryFactorySupport { return queries.containsKey(method); } - /** - * Returns whether the given {@link MethodInvocation} is considered to - * be targeted as an invocation of a custom method. - * + * Returns whether the given {@link MethodInvocation} is considered to be targeted as an invocation of a custom + * method. + * * @param method * @return */ @@ -399,8 +350,6 @@ public abstract class RepositoryFactorySupport { if (null == customImplementation) { return false; } - - return repositoryInformation.isCustomMethod(invocation.getMethod()); } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryProxyPostProcessor.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryProxyPostProcessor.java index d21f40d33..c17020026 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryProxyPostProcessor.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryProxyPostProcessor.java @@ -17,19 +17,17 @@ package org.springframework.data.repository.core.support; import org.springframework.aop.framework.ProxyFactory; - /** - * Callback interface used during repository proxy creation. Allows manipulating - * the {@link ProxyFactory} creating the repository. - * + * Callback interface used during repository proxy creation. Allows manipulating the {@link ProxyFactory} creating the + * repository. + * * @author Oliver Gierke */ public interface RepositoryProxyPostProcessor { /** - * Manipulates the {@link ProxyFactory}, e.g. add further interceptors to - * it. - * + * Manipulates the {@link ProxyFactory}, e.g. add further interceptors to it. + * * @param factory */ void postProcess(ProxyFactory factory); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/TransactionalRepositoryFactoryBeanSupport.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/TransactionalRepositoryFactoryBeanSupport.java index cfcb968ee..84846fd1b 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/TransactionalRepositoryFactoryBeanSupport.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/TransactionalRepositoryFactoryBeanSupport.java @@ -25,13 +25,11 @@ import org.springframework.data.repository.util.TxUtils; import org.springframework.transaction.interceptor.TransactionInterceptor; import org.springframework.util.Assert; - /** - * Extension of {@link RepositoryFactoryBeanSupport} to add transactional - * capabilities to the repository proxy. Will register a - * {@link TransactionalRepositoryProxyPostProcessor} that in turn adds a - * {@link TransactionInterceptor} to the repository proxy to be created. - * + * Extension of {@link RepositoryFactoryBeanSupport} to add transactional capabilities to the repository proxy. Will + * register a {@link TransactionalRepositoryProxyPostProcessor} that in turn adds a {@link TransactionInterceptor} to + * the repository proxy to be created. + * * @author Oliver Gierke */ public abstract class TransactionalRepositoryFactoryBeanSupport, S, ID extends Serializable> @@ -40,32 +38,23 @@ public abstract class TransactionalRepositoryFactoryBeanSupport). - - + /** - * Implementation of the - * {@link org.springframework.transaction.interceptor.TransactionAttributeSource} - * interface for working with transaction metadata in JDK 1.5+ annotation format. - * - *

This class reads Spring's JDK 1.5+ {@link Transactional} annotation and - * exposes corresponding transaction attributes to Spring's transaction infrastructure. - * Also supports EJB3's {@link javax.ejb.TransactionAttribute} annotation (if present). - * This class may also serve as base class for a custom TransactionAttributeSource, - * or get customized through {@link TransactionAnnotationParser} strategies. - * + * Implementation of the {@link org.springframework.transaction.interceptor.TransactionAttributeSource} interface for + * working with transaction metadata in JDK 1.5+ annotation format. + * + *

+ * This class reads Spring's JDK 1.5+ {@link Transactional} annotation and exposes corresponding transaction + * attributes to Spring's transaction infrastructure. Also supports EJB3's {@link javax.ejb.TransactionAttribute} + * annotation (if present). This class may also serve as base class for a custom TransactionAttributeSource, or get + * customized through {@link TransactionAnnotationParser} strategies. + * * @author Colin Sampaleanu * @author Juergen Hoeller * @since 1.2 @@ -125,34 +115,31 @@ class TransactionalRepositoryProxyPostProcessor implements * @see org.springframework.transaction.interceptor.TransactionInterceptor#setTransactionAttributeSource * @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean#setTransactionAttributeSource */ - static class CustomAnnotationTransactionAttributeSource extends AbstractFallbackTransactionAttributeSource - implements Serializable { + static class CustomAnnotationTransactionAttributeSource extends AbstractFallbackTransactionAttributeSource implements + Serializable { - private static final long serialVersionUID = 4841944452113159864L; - private static final boolean ejb3Present = ClassUtils.isPresent( - "javax.ejb.TransactionAttribute", CustomAnnotationTransactionAttributeSource.class.getClassLoader()); + private static final long serialVersionUID = 4841944452113159864L; + private static final boolean ejb3Present = ClassUtils.isPresent("javax.ejb.TransactionAttribute", + CustomAnnotationTransactionAttributeSource.class.getClassLoader()); private final boolean publicMethodsOnly; private final Set annotationParsers; - /** - * Create a default AnnotationTransactionAttributeSource, supporting - * public methods that carry the Transactional annotation - * or the EJB3 {@link javax.ejb.TransactionAttribute} annotation. + * Create a default AnnotationTransactionAttributeSource, supporting public methods that carry the + * Transactional annotation or the EJB3 {@link javax.ejb.TransactionAttribute} annotation. */ public CustomAnnotationTransactionAttributeSource() { this(true); } /** - * Create a custom AnnotationTransactionAttributeSource, supporting - * public methods that carry the Transactional annotation - * or the EJB3 {@link javax.ejb.TransactionAttribute} annotation. - * @param publicMethodsOnly whether to support public methods that carry - * the Transactional annotation only (typically for use - * with proxy-based AOP), or protected/private methods as well - * (typically used with AspectJ class weaving) + * Create a custom AnnotationTransactionAttributeSource, supporting public methods that carry the + * Transactional annotation or the EJB3 {@link javax.ejb.TransactionAttribute} annotation. + * + * @param publicMethodsOnly whether to support public methods that carry the Transactional annotation + * only (typically for use with proxy-based AOP), or protected/private methods as well (typically used with + * AspectJ class weaving) */ public CustomAnnotationTransactionAttributeSource(boolean publicMethodsOnly) { this.publicMethodsOnly = publicMethodsOnly; @@ -165,6 +152,7 @@ class TransactionalRepositoryProxyPostProcessor implements /** * Create a custom AnnotationTransactionAttributeSource. + * * @param annotationParser the TransactionAnnotationParser to use */ public CustomAnnotationTransactionAttributeSource(TransactionAnnotationParser annotationParser) { @@ -175,6 +163,7 @@ class TransactionalRepositoryProxyPostProcessor implements /** * Create a custom AnnotationTransactionAttributeSource. + * * @param annotationParsers the TransactionAnnotationParsers to use */ public CustomAnnotationTransactionAttributeSource(Set annotationParsers) { @@ -183,7 +172,6 @@ class TransactionalRepositoryProxyPostProcessor implements this.annotationParsers = annotationParsers; } - @Override protected TransactionAttribute findTransactionAttribute(Method method) { return determineTransactionAttribute(method); @@ -196,14 +184,15 @@ class TransactionalRepositoryProxyPostProcessor implements /** * Determine the transaction attribute for the given method or class. - *

This implementation delegates to configured - * {@link TransactionAnnotationParser TransactionAnnotationParsers} - * for parsing known annotations into Spring's metadata attribute class. - * Returns null if it's not transactional. - *

Can be overridden to support custom annotations that carry transaction metadata. + *

+ * This implementation delegates to configured {@link TransactionAnnotationParser TransactionAnnotationParsers} for + * parsing known annotations into Spring's metadata attribute class. Returns null if it's not + * transactional. + *

+ * Can be overridden to support custom annotations that carry transaction metadata. + * * @param ae the annotated method or class - * @return TransactionAttribute the configured transaction attribute, - * or null if none was found + * @return TransactionAttribute the configured transaction attribute, or null if none was found */ protected TransactionAttribute determineTransactionAttribute(AnnotatedElement ae) { for (TransactionAnnotationParser annotationParser : this.annotationParsers) { @@ -223,23 +212,22 @@ class TransactionalRepositoryProxyPostProcessor implements return this.publicMethodsOnly; } } - + /** - * Abstract implementation of {@link TransactionAttributeSource} that caches - * attributes for methods and implements a fallback policy: 1. specific target - * method; 2. target class; 3. declaring method; 4. declaring class/interface. - * - *

Defaults to using the target class's transaction attribute if none is - * associated with the target method. Any transaction attribute associated with - * the target method completely overrides a class transaction attribute. - * If none found on the target class, the interface that the invoked method - * has been called through (in case of a JDK proxy) will be checked. - * - *

This implementation caches attributes by method after they are first used. - * If it is ever desirable to allow dynamic changing of transaction attributes - * (which is very unlikely), caching could be made configurable. Caching is + * Abstract implementation of {@link TransactionAttributeSource} that caches attributes for methods and implements a + * fallback policy: 1. specific target method; 2. target class; 3. declaring method; 4. declaring class/interface. + * + *

+ * Defaults to using the target class's transaction attribute if none is associated with the target method. Any + * transaction attribute associated with the target method completely overrides a class transaction attribute. If none + * found on the target class, the interface that the invoked method has been called through (in case of a JDK proxy) + * will be checked. + * + *

+ * This implementation caches attributes by method after they are first used. If it is ever desirable to allow dynamic + * changing of transaction attributes (which is very unlikely), caching could be made configurable. Caching is * desirable because of the cost of evaluating rollback rules. - * + * * @author Rod Johnson * @author Juergen Hoeller * @since 1.1 @@ -247,34 +235,35 @@ class TransactionalRepositoryProxyPostProcessor implements abstract static class AbstractFallbackTransactionAttributeSource implements TransactionAttributeSource { /** - * Canonical value held in cache to indicate no transaction attribute was - * found for this method, and we don't need to look again. + * Canonical value held in cache to indicate no transaction attribute was found for this method, and we don't need + * to look again. */ private final static TransactionAttribute NULL_TRANSACTION_ATTRIBUTE = new DefaultTransactionAttribute(); - /** * Logger available to subclasses. - *

As this base class is not marked Serializable, the logger will be recreated - * after serialization - provided that the concrete subclass is Serializable. + *

+ * As this base class is not marked Serializable, the logger will be recreated after serialization - provided that + * the concrete subclass is Serializable. */ protected final Log logger = LogFactory.getLog(getClass()); /** * Cache of TransactionAttributes, keyed by DefaultCacheKey (Method + target Class). - *

As this base class is not marked Serializable, the cache will be recreated - * after serialization - provided that the concrete subclass is Serializable. + *

+ * As this base class is not marked Serializable, the cache will be recreated after serialization - provided that + * the concrete subclass is Serializable. */ final Map attributeCache = new ConcurrentHashMap(); - /** * Determine the transaction attribute for this method invocation. - *

Defaults to the class's transaction attribute if no method attribute is found. + *

+ * Defaults to the class's transaction attribute if no method attribute is found. + * * @param method the method for the current invocation (never null) * @param targetClass the target class for this invocation (may be null) - * @return TransactionAttribute for this method, or null if the method - * is not transactional + * @return TransactionAttribute for this method, or null if the method is not transactional */ public TransactionAttribute getTransactionAttribute(Method method, Class targetClass) { // First, see if we have a cached value. @@ -285,19 +274,16 @@ class TransactionalRepositoryProxyPostProcessor implements // or an actual transaction attribute. if (cached == NULL_TRANSACTION_ATTRIBUTE) { return null; - } - else { + } else { return (TransactionAttribute) cached; } - } - else { + } else { // We need to work it out. TransactionAttribute txAtt = computeTransactionAttribute(method, targetClass); // Put it in the cache. if (txAtt == null) { this.attributeCache.put(cacheKey, NULL_TRANSACTION_ATTRIBUTE); - } - else { + } else { if (logger.isDebugEnabled()) { logger.debug("Adding transactional method '" + method.getName() + "' with attribute: " + txAtt); } @@ -309,8 +295,10 @@ class TransactionalRepositoryProxyPostProcessor implements /** * Determine a cache key for the given method and target class. - *

Must not produce same key for overloaded methods. - * Must produce same key for different instances of the same method. + *

+ * Must not produce same key for overloaded methods. Must produce same key for different instances of the same + * method. + * * @param method the method (never null) * @param targetClass the target class (may be null) * @return the cache key (never null) @@ -322,6 +310,7 @@ class TransactionalRepositoryProxyPostProcessor implements /** * Same signature as {@link #getTransactionAttribute}, but doesn't cache the result. * {@link #getTransactionAttribute} is effectively a caching decorator for this method. + * * @see #getTransactionAttribute */ private TransactionAttribute computeTransactionAttribute(Method method, Class targetClass) { @@ -337,7 +326,7 @@ class TransactionalRepositoryProxyPostProcessor implements Method specificMethod = ClassUtils.getMostSpecificMethod(method, userClass); // If we are dealing with method with generic parameters, find the original method. specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod); - + TransactionAttribute txAtt = null; if (specificMethod != method) { @@ -348,13 +337,13 @@ class TransactionalRepositoryProxyPostProcessor implements } // Last fallback is the class of the original method. txAtt = findTransactionAttribute(method.getDeclaringClass()); - + if (txAtt != null) { return txAtt; } } - - // Start: Implementation class check block + + // Start: Implementation class check block // First try is the method in the target class. txAtt = findTransactionAttribute(specificMethod); @@ -367,40 +356,36 @@ class TransactionalRepositoryProxyPostProcessor implements if (txAtt != null) { return txAtt; } - + // End: Implementation class check block return null; } - /** - * Subclasses need to implement this to return the transaction attribute - * for the given method, if any. + * Subclasses need to implement this to return the transaction attribute for the given method, if any. + * * @param method the method to retrieve the attribute for - * @return all transaction attribute associated with this method - * (or null if none) + * @return all transaction attribute associated with this method (or null if none) */ protected abstract TransactionAttribute findTransactionAttribute(Method method); /** - * Subclasses need to implement this to return the transaction attribute - * for the given class, if any. + * Subclasses need to implement this to return the transaction attribute for the given class, if any. + * * @param clazz the class to retrieve the attribute for - * @return all transaction attribute associated with this class - * (or null if none) + * @return all transaction attribute associated with this class (or null if none) */ protected abstract TransactionAttribute findTransactionAttribute(Class clazz); - /** * Should only public methods be allowed to have transactional semantics? - *

The default implementation returns false. + *

+ * The default implementation returns false. */ protected boolean allowPublicMethodsOnly() { return false; } - /** * Default cache key for the TransactionAttribute cache. */ @@ -424,8 +409,8 @@ class TransactionalRepositoryProxyPostProcessor implements return false; } DefaultCacheKey otherKey = (DefaultCacheKey) other; - return (this.method.equals(otherKey.method) && - ObjectUtils.nullSafeEquals(this.targetClass, otherKey.targetClass)); + return (this.method.equals(otherKey.method) && ObjectUtils.nullSafeEquals(this.targetClass, + otherKey.targetClass)); } @Override diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/Param.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/Param.java index a8c0a5848..966aaad22 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/Param.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/Param.java @@ -21,11 +21,9 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; - /** - * Annotation to bind let method parameters be bound to a query via a named - * parameter. - * + * Annotation to bind let method parameters be bound to a query via a named parameter. + * * @author Oliver Gierke */ @Target(ElementType.PARAMETER) diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/Parameter.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/Parameter.java index d8d267caf..a2cd64fff 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/Parameter.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/Parameter.java @@ -26,23 +26,18 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.util.Assert; - /** - * Class to abstract a single parameter of a query method. It is held in the - * context of a {@link Parameters} instance. - * + * Class to abstract a single parameter of a query method. It is held in the context of a {@link Parameters} instance. + * * @author Oliver Gierke */ public class Parameter { @SuppressWarnings("unchecked") - static final List> TYPES = Arrays.asList(Pageable.class, - Sort.class); + static final List> TYPES = Arrays.asList(Pageable.class, Sort.class); - private static final String PARAM_ON_SPECIAL = format( - "You must not user @%s on a parameter typed %s or %s", - Param.class.getSimpleName(), Pageable.class.getSimpleName(), - Sort.class.getSimpleName()); + private static final String PARAM_ON_SPECIAL = format("You must not user @%s on a parameter typed %s or %s", + Param.class.getSimpleName(), Pageable.class.getSimpleName(), Sort.class.getSimpleName()); private static final String NAMED_PARAMETER_TEMPLATE = ":%s"; private static final String POSITION_PARAMETER_TEMPLATE = "?%s"; @@ -50,9 +45,9 @@ public class Parameter { private final MethodParameter parameter; /** - * Creates a new {@link Parameter} for the given type, {@link Annotation}s, - * positioned at the given index inside the given {@link Parameters}. - * + * Creates a new {@link Parameter} for the given type, {@link Annotation}s, positioned at the given index inside the + * given {@link Parameters}. + * * @param type * @param parameters * @param index @@ -69,10 +64,9 @@ public class Parameter { } } - /** * Returns whether the {@link Parameter} is the first one. - * + * * @return */ boolean isFirst() { @@ -80,10 +74,9 @@ public class Parameter { return getIndex() == 0; } - /** * Returns whether the parameter is a special parameter. - * + * * @param index * @return * @see #TYPES @@ -93,10 +86,9 @@ public class Parameter { return TYPES.contains(parameter.getParameterType()); } - /** * Returns whether the {@link Parameter} is to be bound to a query. - * + * * @return */ public boolean isBindable() { @@ -104,11 +96,9 @@ public class Parameter { return !isSpecialParameter(); } - /** - * Returns the placeholder to be used for the parameter. Can either be a - * named one or positional. - * + * Returns the placeholder to be used for the parameter. Can either be a named one or positional. + * * @param index * @return */ @@ -121,11 +111,9 @@ public class Parameter { } } - /** - * Returns the position index the parameter is bound to in the context of - * its surrounding {@link Parameters}. - * + * Returns the position index the parameter is bound to in the context of its surrounding {@link Parameters}. + * * @return */ public int getIndex() { @@ -133,10 +121,9 @@ public class Parameter { return parameter.getParameterIndex(); } - /** * Returns whether the parameter is annotated with {@link Param}. - * + * * @param index * @return */ @@ -145,11 +132,9 @@ public class Parameter { return !isSpecialParameter() && getName() != null; } - /** - * Returns the name of the parameter (through {@link Param} annotation) or - * null if none can be found. - * + * Returns the name of the parameter (through {@link Param} annotation) or null if none can be found. + * * @return */ public String getName() { @@ -157,7 +142,6 @@ public class Parameter { return annotation == null ? parameter.getParameterName() : annotation.value(); } - /** * Returns the type of the {@link Parameter}. * @@ -166,7 +150,7 @@ public class Parameter { public Class getType() { return parameter.getParameterType(); } - + /* * (non-Javadoc) * @see java.lang.Object#toString() @@ -174,14 +158,12 @@ public class Parameter { @Override public String toString() { - return format("%s:%s", isNamedParameter() ? getName() : "#" + getIndex(), - getType().getName()); + return format("%s:%s", isNamedParameter() ? getName() : "#" + getIndex(), getType().getName()); } - /** * Returns whether the {@link Parameter} is a {@link Pageable} parameter. - * + * * @return */ boolean isPageable() { @@ -189,10 +171,9 @@ public class Parameter { return Pageable.class.isAssignableFrom(getType()); } - /** * Returns whether the {@link Parameter} is a {@link Sort} parameter. - * + * * @return */ boolean isSort() { diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/ParameterAccessor.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/ParameterAccessor.java index bb46f977c..fd25a2adc 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/ParameterAccessor.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/ParameterAccessor.java @@ -20,53 +20,42 @@ import java.util.Iterator; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; - /** - * Interface to access method parameters. Allows dedicated access to parameters - * of special types - * + * Interface to access method parameters. Allows dedicated access to parameters of special types + * * @author Oliver Gierke */ public interface ParameterAccessor extends Iterable { /** - * Returns the {@link Pageable} of the parameters, if available. Returns - * {@code null} otherwise. - * + * Returns the {@link Pageable} of the parameters, if available. Returns {@code null} otherwise. + * * @return */ Pageable getPageable(); - /** - * Returns the sort instance to be used for query creation. Will use a - * {@link Sort} parameter if available or the {@link Sort} contained in a - * {@link Pageable} if available. Returns {@code null} if no {@link Sort} - * can be found. - * + * Returns the sort instance to be used for query creation. Will use a {@link Sort} parameter if available or the + * {@link Sort} contained in a {@link Pageable} if available. Returns {@code null} if no {@link Sort} can be found. + * * @return */ Sort getSort(); - /** - * Returns the bindable value with the given index. Bindable means, that - * {@link Pageable} and {@link Sort} values are skipped without noticed in - * the index. For a method signature taking {@link String}, {@link Pageable} - * , {@link String}, {@code #getBindableParameter(1)} would return the - * second {@link String} value. - * + * Returns the bindable value with the given index. Bindable means, that {@link Pageable} and {@link Sort} values are + * skipped without noticed in the index. For a method signature taking {@link String}, {@link Pageable} , + * {@link String}, {@code #getBindableParameter(1)} would return the second {@link String} value. + * * @param index * @return */ Object getBindableValue(int index); - /** - * Returns an iterator over all bindable parameters. This means - * parameters implementing {@link Pageable} or {@link Sort} will not be - * included in this {@link Iterator}. - * + * Returns an iterator over all bindable parameters. This means parameters implementing {@link Pageable} or + * {@link Sort} will not be included in this {@link Iterator}. + * * @return */ Iterator iterator(); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/ParameterOutOfBoundsException.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/ParameterOutOfBoundsException.java index 485209cd0..a9aace076 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/ParameterOutOfBoundsException.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/ParameterOutOfBoundsException.java @@ -16,20 +16,18 @@ package org.springframework.data.repository.query; /** - * Exception to be thrown when trying to access a {@link Parameter} with an - * invalid index inside a {@link Parameters} instance. - * + * Exception to be thrown when trying to access a {@link Parameter} with an invalid index inside a {@link Parameters} + * instance. + * * @author Oliver Gierke */ public class ParameterOutOfBoundsException extends RuntimeException { private static final long serialVersionUID = 8433209953653278886L; - /** - * Creates a new {@link ParameterOutOfBoundsException} with the given - * exception as cause. - * + * Creates a new {@link ParameterOutOfBoundsException} with the given exception as cause. + * * @param cause */ public ParameterOutOfBoundsException(Throwable cause) { diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/Parameters.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/Parameters.java index 9e2054e05..88f64ba9b 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/Parameters.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/Parameters.java @@ -28,37 +28,29 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.util.Assert; - /** - * Abstracts method parameters that have to be bound to query parameters or - * applied to the query independently. - * + * Abstracts method parameters that have to be bound to query parameters or applied to the query independently. + * * @author Oliver Gierke */ public class Parameters implements Iterable { @SuppressWarnings("unchecked") - public static final List> TYPES = Arrays.asList(Pageable.class, - Sort.class); + public static final List> TYPES = Arrays.asList(Pageable.class, Sort.class); - private static final String ALL_OR_NOTHING = - String.format( - "Either use @%s " - + "on all parameters except %s and %s typed once, or none at all!", - Param.class.getSimpleName(), - Pageable.class.getSimpleName(), Sort.class.getSimpleName()); + private static final String ALL_OR_NOTHING = String.format("Either use @%s " + + "on all parameters except %s and %s typed once, or none at all!", Param.class.getSimpleName(), + Pageable.class.getSimpleName(), Sort.class.getSimpleName()); private final int pageableIndex; private final int sortIndex; private final List parameters; - private final ParameterNameDiscoverer discoverer = - new LocalVariableTableParameterNameDiscoverer(); - + private final ParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer(); /** * Creates a new instance of {@link Parameters}. - * + * * @param method */ public Parameters(Method method) { @@ -81,11 +73,9 @@ public class Parameters implements Iterable { assertEitherAllParamAnnotatedOrNone(); } - /** - * Creates a new {@link Parameters} instance with the given - * {@link Parameter}s put into new context. - * + * Creates a new {@link Parameters} instance with the given {@link Parameter}s put into new context. + * * @param originals */ private Parameters(List originals) { @@ -107,16 +97,14 @@ public class Parameters implements Iterable { this.pageableIndex = pageableIndexTemp; this.sortIndex = sortIndexTemp; } - + protected Parameter createParameter(MethodParameter parameter) { return new Parameter(parameter); } - /** - * Returns whether the method the {@link Parameters} was created for - * contains a {@link Pageable} argument. - * + * Returns whether the method the {@link Parameters} was created for contains a {@link Pageable} argument. + * * @return */ public boolean hasPageableParameter() { @@ -124,12 +112,10 @@ public class Parameters implements Iterable { return pageableIndex != -1; } - /** - * Returns the index of the {@link Pageable} {@link Method} parameter if - * available. Will return {@literal -1} if there is no {@link Pageable} - * argument in the {@link Method}'s parameter list. - * + * Returns the index of the {@link Pageable} {@link Method} parameter if available. Will return {@literal -1} if there + * is no {@link Pageable} argument in the {@link Method}'s parameter list. + * * @return the pageableIndex */ public int getPageableIndex() { @@ -137,12 +123,10 @@ public class Parameters implements Iterable { return pageableIndex; } - /** - * Returns the index of the {@link Sort} {@link Method} parameter if - * available. Will return {@literal -1} if there is no {@link Sort} argument - * in the {@link Method}'s parameter list. - * + * Returns the index of the {@link Sort} {@link Method} parameter if available. Will return {@literal -1} if there is + * no {@link Sort} argument in the {@link Method}'s parameter list. + * * @return */ public int getSortIndex() { @@ -150,33 +134,29 @@ public class Parameters implements Iterable { return sortIndex; } - /** - * Returns whether the method the {@link Parameters} was created for - * contains a {@link Sort} argument. - * + * Returns whether the method the {@link Parameters} was created for contains a {@link Sort} argument. + * * @return */ public boolean hasSortParameter() { return sortIndex != -1; } - - + /** * Returns whether we potentially find a {@link Sort} parameter in the parameters. * * @return */ public boolean potentiallySortsDynamically() { - + return hasSortParameter() || hasPageableParameter(); } - /** * Returns the parameter with the given index. - * + * * @param index * @return */ @@ -189,10 +169,9 @@ public class Parameters implements Iterable { } } - /** * Returns whether we have a parameter at the given position. - * + * * @param position * @return */ @@ -205,11 +184,9 @@ public class Parameters implements Iterable { } } - /** - * Returns whether the method signature contains one of the special - * parameters ({@link Pageable}, {@link Sort}). - * + * Returns whether the method signature contains one of the special parameters ({@link Pageable}, {@link Sort}). + * * @return */ public boolean hasSpecialParameter() { @@ -217,10 +194,9 @@ public class Parameters implements Iterable { return hasSortParameter() || hasPageableParameter(); } - /** * Returns the number of parameters. - * + * * @return */ public int getNumberOfParameters() { @@ -228,11 +204,9 @@ public class Parameters implements Iterable { return parameters.size(); } - /** - * Returns a {@link Parameters} instance with effectively all special - * parameters removed. - * + * Returns a {@link Parameters} instance with effectively all special parameters removed. + * * @return * @see Parameter#TYPES * @see Parameter#isSpecialParameter() @@ -251,13 +225,11 @@ public class Parameters implements Iterable { return new Parameters(bindables); } - /** - * Returns a bindable parameter with the given index. So for a method with a - * signature of {@code (Pageable pageable, String name)} a call to - * {@code #getBindableParameter(0)} will return the {@link String} + * Returns a bindable parameter with the given index. So for a method with a signature of + * {@code (Pageable pageable, String name)} a call to {@code #getBindableParameter(0)} will return the {@link String} * parameter. - * + * * @param bindableIndex * @return */ @@ -266,11 +238,10 @@ public class Parameters implements Iterable { return getBindableParameters().getParameter(bindableIndex); } - /** - * Asserts that either all of the non special parameters ({@link Pageable}, - * {@link Sort}) are annotated with {@link Param} or none of them is. - * + * Asserts that either all of the non special parameters ({@link Pageable}, {@link Sort}) are annotated with + * {@link Param} or none of them is. + * * @param method */ private void assertEitherAllParamAnnotatedOrNone() { @@ -288,10 +259,9 @@ public class Parameters implements Iterable { } } - /** * Returns whether the given type is a bindable parameter. - * + * * @param type * @return */ @@ -300,7 +270,6 @@ public class Parameters implements Iterable { return !TYPES.contains(type); } - /* * (non-Javadoc) * diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/ParametersParameterAccessor.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/ParametersParameterAccessor.java index d44a288db..945529081 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/ParametersParameterAccessor.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/ParametersParameterAccessor.java @@ -21,11 +21,9 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.util.Assert; - /** - * {@link ParameterAccessor} implementation using a {@link Parameters} instance - * to find special parameters. - * + * {@link ParameterAccessor} implementation using a {@link Parameters} instance to find special parameters. + * * @author Oliver Gierke */ public class ParametersParameterAccessor implements ParameterAccessor { @@ -33,10 +31,9 @@ public class ParametersParameterAccessor implements ParameterAccessor { private final Parameters parameters; private final Object[] values; - /** * Creates a new {@link ParametersParameterAccessor}. - * + * * @param parameters * @param values */ @@ -45,14 +42,12 @@ public class ParametersParameterAccessor implements ParameterAccessor { Assert.notNull(parameters); Assert.notNull(values); - Assert.isTrue(parameters.getNumberOfParameters() == values.length, - "Invalid number of parameters given!"); + Assert.isTrue(parameters.getNumberOfParameters() == values.length, "Invalid number of parameters given!"); this.parameters = parameters; this.values = values.clone(); } - /* * (non-Javadoc) * @see org.springframework.data.repository.query.ParameterAccessor#getPageable() @@ -66,7 +61,6 @@ public class ParametersParameterAccessor implements ParameterAccessor { return (Pageable) values[parameters.getPageableIndex()]; } - /* * (non-Javadoc) * @see org.springframework.data.repository.query.ParameterAccessor#getSort() @@ -83,7 +77,7 @@ public class ParametersParameterAccessor implements ParameterAccessor { return null; } - + /** * Returns the value with the given index. * @@ -95,7 +89,6 @@ public class ParametersParameterAccessor implements ParameterAccessor { return (T) values[index]; } - /* * (non-Javadoc) * @see org.springframework.data.repository.query.ParameterAccessor#getBindableValue(int) @@ -105,7 +98,6 @@ public class ParametersParameterAccessor implements ParameterAccessor { return values[parameters.getBindableParameter(index).getIndex()]; } - /* * (non-Javadoc) * @see org.springframework.data.repository.query.ParameterAccessor#iterator() @@ -116,19 +108,17 @@ public class ParametersParameterAccessor implements ParameterAccessor { } /** - * Iterator class to allow traversing all bindable parameters inside the - * accessor. - * + * Iterator class to allow traversing all bindable parameters inside the accessor. + * * @author Oliver Gierke */ private class BindableParameterIterator implements Iterator { private int currentIndex = 0; - /** * Returns the next bindable parameter. - * + * * @return */ public Object next() { @@ -136,7 +126,6 @@ public class ParametersParameterAccessor implements ParameterAccessor { return getBindableValue(currentIndex++); } - /* * (non-Javadoc) * @see java.util.Iterator#hasNext() @@ -146,7 +135,6 @@ public class ParametersParameterAccessor implements ParameterAccessor { return values.length > currentIndex; } - /* * (non-Javadoc) * @see java.util.Iterator#remove() diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryCreationException.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryCreationException.java index 92ff845c8..a402b374a 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryCreationException.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryCreationException.java @@ -16,21 +16,18 @@ package org.springframework.data.repository.query; /** - * Exception to be thrown if a query cannot be created from a - * {@link QueryMethod}. - * + * Exception to be thrown if a query cannot be created from a {@link QueryMethod}. + * * @author Oliver Gierke */ public final class QueryCreationException extends RuntimeException { private static final long serialVersionUID = -1238456123580L; - private static final String MESSAGE_TEMPLATE = - "Could not create query for method %s! Could not find property %s on domain class %s."; - + private static final String MESSAGE_TEMPLATE = "Could not create query for method %s! Could not find property %s on domain class %s."; /** * Creates a new {@link QueryCreationException}. - * + * * @param method */ private QueryCreationException(String message) { @@ -38,47 +35,39 @@ public final class QueryCreationException extends RuntimeException { super(message); } - /** * Rejects the given domain class property. - * + * * @param method * @param propertyName * @return */ - public static QueryCreationException invalidProperty(QueryMethod method, - String propertyName) { + public static QueryCreationException invalidProperty(QueryMethod method, String propertyName) { - return new QueryCreationException(String.format(MESSAGE_TEMPLATE, - method, propertyName, method.getDomainClass().getName())); + return new QueryCreationException(String.format(MESSAGE_TEMPLATE, method, propertyName, method.getDomainClass() + .getName())); } - /** * Creates a new {@link QueryCreationException}. - * + * * @param method * @param message * @return */ - public static QueryCreationException create(QueryMethod method, - String message) { + public static QueryCreationException create(QueryMethod method, String message) { - return new QueryCreationException(String.format( - "Could not create query for %s! Reason: %s", method, message)); + return new QueryCreationException(String.format("Could not create query for %s! Reason: %s", method, message)); } - /** - * Creates a new {@link QueryCreationException} for the given - * {@link QueryMethod} and {@link Throwable} as cause. - * + * Creates a new {@link QueryCreationException} for the given {@link QueryMethod} and {@link Throwable} as cause. + * * @param method * @param cause * @return */ - public static QueryCreationException create(QueryMethod method, - Throwable cause) { + public static QueryCreationException create(QueryMethod method, Throwable cause) { return create(method, cause.getMessage()); } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryLookupStrategy.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryLookupStrategy.java index 9b9f7d4aa..35c86413d 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryLookupStrategy.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryLookupStrategy.java @@ -22,10 +22,9 @@ import org.springframework.data.repository.core.NamedQueries; import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.util.StringUtils; - /** * Strategy interface for which way to lookup {@link RepositoryQuery}s. - * + * * @author Oliver Gierke */ public interface QueryLookupStrategy { @@ -36,7 +35,7 @@ public interface QueryLookupStrategy { /** * Returns a strategy key from the given XML value. - * + * * @param xml * @return a strategy key from the given XML value */ @@ -50,11 +49,9 @@ public interface QueryLookupStrategy { } } - /** - * Resolves a {@link RepositoryQuery} from the given {@link QueryMethod} - * that can be executed afterwards. - * + * Resolves a {@link RepositoryQuery} from the given {@link QueryMethod} that can be executed afterwards. + * * @param method * @param metadata * @param namedQueries diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryMethod.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryMethod.java index e4ad7d057..e2825feab 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryMethod.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryMethod.java @@ -28,12 +28,10 @@ import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.data.repository.util.ClassUtils; import org.springframework.util.Assert; - /** - * Abstraction of a method that is designated to execute a finder query. - * Enriches the standard {@link Method} interface with specific information that - * is necessary to construct {@link RepositoryQuery}s for the method. - * + * Abstraction of a method that is designated to execute a finder query. Enriches the standard {@link Method} interface + * with specific information that is necessary to construct {@link RepositoryQuery}s for the method. + * * @author Oliver Gierke */ public class QueryMethod { @@ -42,11 +40,10 @@ public class QueryMethod { private final Method method; private final Parameters parameters; - /** - * Creates a new {@link QueryMethod} from the given parameters. Looks up the - * correct query to use for following invocations of the method given. - * + * Creates a new {@link QueryMethod} from the given parameters. Looks up the correct query to use for following + * invocations of the method given. + * * @param method must not be {@literal null} * @param metadata must not be {@literal null} */ @@ -57,46 +54,43 @@ public class QueryMethod { for (Class type : Parameters.TYPES) { if (getNumberOfOccurences(method, type) > 1) { - throw new IllegalStateException(String.format( - "Method must only one argument of type %s!", - type.getSimpleName())); + throw new IllegalStateException( + String.format("Method must only one argument of type %s!", type.getSimpleName())); } } if (hasParameterOfType(method, Pageable.class)) { assertReturnTypeAssignable(method, Page.class, List.class); if (hasParameterOfType(method, Sort.class)) { - throw new IllegalStateException( - "Method must not have Pageable *and* Sort parameter. " - + "Use sorting capabilities on Pageble instead!"); + throw new IllegalStateException("Method must not have Pageable *and* Sort parameter. " + + "Use sorting capabilities on Pageble instead!"); } } this.method = method; this.parameters = createParameters(method); this.metadata = metadata; - + Assert.notNull(this.parameters); - + if (isPageQuery()) { Assert.isTrue(this.parameters.hasPageableParameter(), "Paging query needs to have a Pageable parameter!"); } } - + /** * Creates a {@link Parameters} instance. * * @param method - * @return must not return {@literal null}. + * @return must not return {@literal null}. */ protected Parameters createParameters(Method method) { return new Parameters(method); } - /** * Returns the method's name. - * + * * @return */ public String getName() { @@ -104,7 +98,6 @@ public class QueryMethod { return method.getName(); } - @SuppressWarnings("rawtypes") public EntityMetadata getEntityInformation() { @@ -117,19 +110,16 @@ public class QueryMethod { }; } - - /** - * Returns the name of the named query this method belongs to. - * - * @return - */ - public String getNamedQueryName() { + /** + * Returns the name of the named query this method belongs to. + * + * @return + */ + public String getNamedQueryName() { - Class domainClass = getDomainClass(); - return String.format("%s.%s", domainClass.getSimpleName(), - method.getName()); - } - + Class domainClass = getDomainClass(); + return String.format("%s.%s", domainClass.getSimpleName(), method.getName()); + } protected Class getDomainClass() { @@ -140,11 +130,9 @@ public class QueryMethod { : repositoryDomainClass; } - /** - * Returns whether the finder will actually return a collection of entities - * or a single one. - * + * Returns whether the finder will actually return a collection of entities or a single one. + * * @return */ public boolean isCollectionQuery() { @@ -153,30 +141,25 @@ public class QueryMethod { return !isPageQuery() && org.springframework.util.ClassUtils.isAssignable(Iterable.class, returnType); } - /** * Returns whether the finder will return a {@link Page} of results. - * + * * @return */ public boolean isPageQuery() { Class returnType = method.getReturnType(); - return org.springframework.util.ClassUtils.isAssignable(Page.class, - returnType); + return org.springframework.util.ClassUtils.isAssignable(Page.class, returnType); } - public boolean isModifyingQuery() { return false; } - /** - * Returns the {@link Parameters} wrapper to gain additional information - * about {@link Method} parameters. - * + * Returns the {@link Parameters} wrapper to gain additional information about {@link Method} parameters. + * * @return */ public Parameters getParameters() { @@ -184,7 +167,6 @@ public class QueryMethod { return parameters; } - /* * (non-Javadoc) * diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/RepositoryQuery.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/RepositoryQuery.java index 71cf7c190..33d5d208d 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/RepositoryQuery.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/RepositoryQuery.java @@ -15,28 +15,25 @@ */ package org.springframework.data.repository.query; - - /** * Interface for a query abstraction. - * + * * @author Oliver Gierke */ public interface RepositoryQuery { /** * Executes the {@link RepositoryQuery} with the given parameters. - * + * * @param store * @param parameters * @return */ public Object execute(Object[] parameters); - /** * Returns the - * + * * @return */ public QueryMethod getQueryMethod(); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/AbstractQueryCreator.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/AbstractQueryCreator.java index 4fee1ec93..1c0baba08 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/AbstractQueryCreator.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/AbstractQueryCreator.java @@ -72,7 +72,7 @@ public abstract class AbstractQueryCreator { Sort dynamicSort = parameters != null ? parameters.getSort() : null; return createQuery(dynamicSort); } - + /** * Creates the actual query object applying the given {@link Sort} parameter. Use this method in case you haven't * provided a {@link ParameterAccessor} in the first place but want to apply dynamic sorting nevertheless. @@ -81,10 +81,10 @@ public abstract class AbstractQueryCreator { * @return */ public T createQuery(Sort dynamicSort) { - + Sort staticSort = tree.getSort(); Sort sort = staticSort != null ? staticSort.and(dynamicSort) : dynamicSort; - + return complete(createCriteria(tree), sort); } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/PartTree.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/PartTree.java index d5a18e015..e5ba147df 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/PartTree.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/PartTree.java @@ -213,11 +213,11 @@ public class PartTree implements Iterable { predicate = detectAndSetAllIgnoreCase(predicate); String[] parts = split(predicate, ORDER_BY); - + if (parts.length > 2) { throw new IllegalArgumentException("OrderBy must not be used more than once in a method name!"); } - + buildTree(parts[0], domainClass); this.orderBySource = parts.length == 2 ? new OrderBySource(parts[1], domainClass) : null; } @@ -225,12 +225,12 @@ public class PartTree implements Iterable { private String detectAndSetAllIgnoreCase(String predicate) { Matcher matcher = ALL_IGNORE_CASE.matcher(predicate); - + if (matcher.find()) { alwaysIgnoreCase = true; predicate = predicate.substring(0, matcher.start()) + predicate.substring(matcher.end(), predicate.length()); } - + return predicate; } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/Property.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/Property.java index 1a5aa91ec..158a1eb01 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/Property.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/Property.java @@ -26,14 +26,13 @@ import org.springframework.data.util.TypeInformation; import org.springframework.util.Assert; import org.springframework.util.StringUtils; - /** * Abstraction of a {@link Property} of a domain class. - * + * * @author Oliver Gierke */ public class Property { - + private static final String DELIMITERS = "_\\."; private static final Pattern SPLITTER = Pattern.compile("(?:[%s]?([%s]*?[^%s]+))".replaceAll("%s", DELIMITERS)); private static final String ERROR_TEMPLATE = "No property %s found for type %s"; @@ -45,11 +44,9 @@ public class Property { private Property next; - /** - * Creates a leaf {@link Property} (no nested ones) with the given name inside the - * given owning type. - * + * Creates a leaf {@link Property} (no nested ones) with the given name inside the given owning type. + * * @param name * @param owningType */ @@ -73,8 +70,7 @@ public class Property { TypeInformation type = owningType.getProperty(propertyName); if (type == null) { - throw new IllegalArgumentException(String.format(ERROR_TEMPLATE, - propertyName, owningType.getType())); + throw new IllegalArgumentException(String.format(ERROR_TEMPLATE, propertyName, owningType.getType())); } this.owningType = owningType; @@ -84,10 +80,9 @@ public class Property { } /** - * Creates a {@link Property} with the given name inside the given owning - * type and tries to resolve the other {@link String} to create nested - * properties. - * + * Creates a {@link Property} with the given name inside the given owning type and tries to resolve the other + * {@link String} to create nested properties. + * * @param name * @param owningType * @param toTraverse @@ -112,7 +107,7 @@ public class Property { /** * Returns the name of the {@link Property}. - * + * * @return the name will never be {@literal null}. */ public String getName() { @@ -121,10 +116,9 @@ public class Property { } /** - * Returns the type of the property will return the plain resolved type for - * simple properties, the component type for any {@link Iterable} or the - * value type of a {@link java.util.Map} if the property is one. - * + * Returns the type of the property will return the plain resolved type for simple properties, the component type for + * any {@link Iterable} or the value type of a {@link java.util.Map} if the property is one. + * * @return */ public Class getType() { @@ -132,12 +126,10 @@ public class Property { return this.type.getType(); } - /** * Returns the next nested {@link Property}. - * - * @return the next nested {@link Property} or {@literal null} if no nested - * {@link Property} available. + * + * @return the next nested {@link Property} or {@literal null} if no nested {@link Property} available. * @see #hasNext() */ public Property next() { @@ -145,12 +137,10 @@ public class Property { return next; } - /** - * Returns whether there is a nested {@link Property}. If this returns - * {@literal true} you can expect {@link #next()} to return a non- - * {@literal null} value. - * + * Returns whether there is a nested {@link Property}. If this returns {@literal true} you can expect {@link #next()} + * to return a non- {@literal null} value. + * * @return */ public boolean hasNext() { @@ -158,10 +148,9 @@ public class Property { return next != null; } - /** * Returns the {@link Property} path in dot notation. - * + * * @return */ public String toDotPath() { @@ -173,10 +162,9 @@ public class Property { return getName(); } - /** * Returns whether the {@link Property} is actually a collection. - * + * * @return */ public boolean isCollection() { @@ -184,7 +172,6 @@ public class Property { return isCollection; } - /* * (non-Javadoc) * @@ -206,7 +193,6 @@ public class Property { return this.name.equals(that.name) && this.type.equals(type); } - /* * (non-Javadoc) * @@ -218,11 +204,9 @@ public class Property { return name.hashCode() + type.hashCode(); } - /** - * Extracts the {@link Property} chain from the given source {@link String} - * and type. - * + * Extracts the {@link Property} chain from the given source {@link String} and type. + * * @param source * @param type * @return @@ -233,10 +217,10 @@ public class Property { } private static Property from(String source, TypeInformation type) { - + List iteratorSource = new ArrayList(); Matcher matcher = SPLITTER.matcher("_" + source); - + while (matcher.find()) { iteratorSource.add(matcher.group(1)); } @@ -258,11 +242,9 @@ public class Property { return result; } - /** - * Creates a new {@link Property} as subordinary of the given - * {@link Property}. - * + * Creates a new {@link Property} as subordinary of the given {@link Property}. + * * @param source * @param base * @return @@ -274,15 +256,12 @@ public class Property { return property; } - /** - * Factory method to create a new {@link Property} for the given - * {@link String} and owning type. It will inspect the given source for - * camel-case parts and traverse the {@link String} along its parts starting - * with the entire one and chewing off parts from the right side then. - * Whenever a valid property for the given class is found, the tail will be - * traversed for subordinary properties of the just found one and so on. - * + * Factory method to create a new {@link Property} for the given {@link String} and owning type. It will inspect the + * given source for camel-case parts and traverse the {@link String} along its parts starting with the entire one and + * chewing off parts from the right side then. Whenever a valid property for the given class is found, the tail will + * be traversed for subordinary properties of the just found one and so on. + * * @param source * @param type * @return @@ -292,13 +271,11 @@ public class Property { return create(source, type, ""); } - /** - * Tries to look up a chain of {@link Property}s by trying the givne source - * first. If that fails it will split the source apart at camel case borders - * (starting from the right side) and try to look up a {@link Property} from - * the calculated head and recombined new tail and additional tail. - * + * Tries to look up a chain of {@link Property}s by trying the givne source first. If that fails it will split the + * source apart at camel case borders (starting from the right side) and try to look up a {@link Property} from the + * calculated head and recombined new tail and additional tail. + * * @param source * @param type * @param addTail diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/DomainClassConverter.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/DomainClassConverter.java index 56558f3b1..01fb2f854 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/DomainClassConverter.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/DomainClassConverter.java @@ -32,27 +32,22 @@ import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.core.EntityInformation; import org.springframework.data.repository.core.support.RepositoryFactoryInformation; - /** - * {@link org.springframework.core.convert.converter.Converter} to convert - * arbitrary input into domain classes managed by Spring Data {@link CrudRepository} - * s. The implementation uses a {@link ConversionService} in turn to convert the - * source type into the domain class' id type which is then converted into a - * domain class object by using a {@link CrudRepository}. - * + * {@link org.springframework.core.convert.converter.Converter} to convert arbitrary input into domain classes managed + * by Spring Data {@link CrudRepository} s. The implementation uses a {@link ConversionService} in turn to convert the + * source type into the domain class' id type which is then converted into a domain class object by using a + * {@link CrudRepository}. + * * @author Oliver Gierke */ -public class DomainClassConverter implements ConditionalGenericConverter, - ApplicationContextAware { +public class DomainClassConverter implements ConditionalGenericConverter, ApplicationContextAware { - private final Map, CrudRepository> repositories = - new HashMap, CrudRepository>(); + private final Map, CrudRepository> repositories = new HashMap, CrudRepository>(); private final ConversionService service; - /** * Creates a new {@link DomainClassConverter}. - * + * * @param service */ public DomainClassConverter(ConversionService service) { @@ -60,7 +55,6 @@ public class DomainClassConverter implements ConditionalGenericConverter, this.service = service; } - /* * (non-Javadoc) * @@ -69,11 +63,9 @@ public class DomainClassConverter implements ConditionalGenericConverter, */ public Set getConvertibleTypes() { - return Collections.singleton(new ConvertiblePair(Object.class, - Object.class)); + return Collections.singleton(new ConvertiblePair(Object.class, Object.class)); } - /* * (non-Javadoc) * @@ -82,18 +74,15 @@ public class DomainClassConverter implements ConditionalGenericConverter, * .lang.Object, org.springframework.core.convert.TypeDescriptor, * org.springframework.core.convert.TypeDescriptor) */ - public Object convert(Object source, TypeDescriptor sourceType, - TypeDescriptor targetType) { + public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { - EntityInformation info = - getRepositoryForDomainType(targetType.getType()); + EntityInformation info = getRepositoryForDomainType(targetType.getType()); CrudRepository repository = repositories.get(info); Serializable id = service.convert(source, info.getIdType()); return repository.findOne(id); } - /* * (non-Javadoc) * @@ -104,8 +93,7 @@ public class DomainClassConverter implements ConditionalGenericConverter, */ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { - EntityInformation info = - getRepositoryForDomainType(targetType.getType()); + EntityInformation info = getRepositoryForDomainType(targetType.getType()); if (info == null) { return false; @@ -114,12 +102,9 @@ public class DomainClassConverter implements ConditionalGenericConverter, return service.canConvert(sourceType.getType(), info.getIdType()); } + private EntityInformation getRepositoryForDomainType(Class domainType) { - private EntityInformation getRepositoryForDomainType( - Class domainType) { - - for (EntityInformation information : repositories - .keySet()) { + for (EntityInformation information : repositories.keySet()) { if (domainType.equals(information.getJavaType())) { return information; @@ -129,7 +114,6 @@ public class DomainClassConverter implements ConditionalGenericConverter, return null; } - /* * (non-Javadoc) * @@ -137,21 +121,17 @@ public class DomainClassConverter implements ConditionalGenericConverter, * org.springframework.context.ApplicationContextAware#setApplicationContext * (org.springframework.context.ApplicationContext) */ - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({ "unchecked", "rawtypes" }) public void setApplicationContext(ApplicationContext context) { - Collection providers = - BeanFactoryUtils.beansOfTypeIncludingAncestors(context, - RepositoryFactoryInformation.class).values(); + Collection providers = BeanFactoryUtils.beansOfTypeIncludingAncestors(context, + RepositoryFactoryInformation.class).values(); for (RepositoryFactoryInformation entry : providers) { - EntityInformation metadata = - entry.getEntityInformation(); - Class> objectType = - entry.getRepositoryInterface(); - CrudRepository repository = - BeanFactoryUtils.beanOfType(context, objectType); + EntityInformation metadata = entry.getEntityInformation(); + Class> objectType = entry.getRepositoryInterface(); + CrudRepository repository = BeanFactoryUtils.beanOfType(context, objectType); this.repositories.put(metadata, repository); } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/DomainClassPropertyEditor.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/DomainClassPropertyEditor.java index 4ec959f17..e63103a35 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/DomainClassPropertyEditor.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/DomainClassPropertyEditor.java @@ -26,31 +26,27 @@ import org.springframework.data.repository.core.EntityInformation; import org.springframework.util.Assert; import org.springframework.util.StringUtils; - /** - * Generic {@link PropertyEditor} to map entities handled by a - * {@link CrudRepository} to their id's and vice versa. - * + * Generic {@link PropertyEditor} to map entities handled by a {@link CrudRepository} to their id's and vice versa. + * * @author Oliver Gierke */ -public class DomainClassPropertyEditor extends - PropertyEditorSupport { +public class DomainClassPropertyEditor extends PropertyEditorSupport { private final CrudRepository repository; private final EntityInformation information; private final PropertyEditorRegistry registry; - /** - * Creates a new {@link DomainClassPropertyEditor} for the given - * {@link CrudRepository}, {@link EntityInformation} and {@link PropertyEditorRegistry}. - * + * Creates a new {@link DomainClassPropertyEditor} for the given {@link CrudRepository}, {@link EntityInformation} and + * {@link PropertyEditorRegistry}. + * * @param repository * @param information * @param registry */ public DomainClassPropertyEditor(CrudRepository repository, EntityInformation information, - PropertyEditorRegistry registry) { + PropertyEditorRegistry registry) { Assert.notNull(repository); Assert.notNull(registry); @@ -60,7 +56,6 @@ public class DomainClassPropertyEditor extends this.registry = registry; } - /* * (non-Javadoc) * @@ -77,7 +72,6 @@ public class DomainClassPropertyEditor extends setValue(repository.findOne(getId(idAsString))); } - /* * (non-Javadoc) * @@ -97,12 +91,10 @@ public class DomainClassPropertyEditor extends return id == null ? null : id.toString(); } - /** - * Looks up the id of the given entity using one of the - * {@link org.synyx.hades.dao.orm.GenericDaoSupport.IdAware} implementations - * of Hades. - * + * Looks up the id of the given entity using one of the {@link org.synyx.hades.dao.orm.GenericDaoSupport.IdAware} + * implementations of Hades. + * * @param entity * @return */ @@ -111,13 +103,11 @@ public class DomainClassPropertyEditor extends return information.getId(entity); } - /** - * Returns the actual typed id. Looks up an available customly registered - * {@link PropertyEditor} from the {@link PropertyEditorRegistry} before - * falling back on a {@link SimpleTypeConverter} to translate the - * {@link String} id into the type one. - * + * Returns the actual typed id. Looks up an available customly registered {@link PropertyEditor} from the + * {@link PropertyEditorRegistry} before falling back on a {@link SimpleTypeConverter} to translate the {@link String} + * id into the type one. + * * @param idAsString * @return */ @@ -133,11 +123,9 @@ public class DomainClassPropertyEditor extends return (ID) idEditor.getValue(); } - return new SimpleTypeConverter() - .convertIfNecessary(idAsString, idClass); + return new SimpleTypeConverter().convertIfNecessary(idAsString, idClass); } - /* * (non-Javadoc) * @@ -154,15 +142,12 @@ public class DomainClassPropertyEditor extends return false; } - DomainClassPropertyEditor that = - (DomainClassPropertyEditor) obj; + DomainClassPropertyEditor that = (DomainClassPropertyEditor) obj; - return this.repository.equals(that.repository) - && this.registry.equals(that.registry) + return this.repository.equals(that.repository) && this.registry.equals(that.registry) && this.information.equals(that.information); } - /* * (non-Javadoc) * diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/DomainClassPropertyEditorRegistrar.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/DomainClassPropertyEditorRegistrar.java index 0435ecbf7..290a08692 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/DomainClassPropertyEditorRegistrar.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/DomainClassPropertyEditorRegistrar.java @@ -30,15 +30,11 @@ import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.core.EntityInformation; import org.springframework.data.repository.core.support.RepositoryFactoryInformation; - /** - * Simple helper class to use Hades DAOs to provide - * {@link java.beans.PropertyEditor}s for domain classes. To get this working - * configure a - * {@link org.springframework.web.bind.support.ConfigurableWebBindingInitializer} - * for your - * {@link org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter} - * and register the {@link DomainClassPropertyEditorRegistrar} there: + * Simple helper class to use Hades DAOs to provide {@link java.beans.PropertyEditor}s for domain classes. To get this + * working configure a {@link org.springframework.web.bind.support.ConfigurableWebBindingInitializer} for your + * {@link org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter} and register the + * {@link DomainClassPropertyEditorRegistrar} there: * <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> * <property name="webBindingInitializer"> * <bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer"> @@ -48,19 +44,15 @@ import org.springframework.data.repository.core.support.RepositoryFactoryInforma * </bean> * </property> * </bean> - * Make sure this bean declaration is in the {@link ApplicationContext} - * created by the {@link DispatcherServlet} whereas the repositories need to be - * declared in the root + * Make sure this bean declaration is in the {@link ApplicationContext} created by the {@link DispatcherServlet} + * whereas the repositories need to be declared in the root * {@link org.springframework.web.context.WebApplicationContext}. - * + * * @author Oliver Gierke */ -public class DomainClassPropertyEditorRegistrar implements - PropertyEditorRegistrar, ApplicationContextAware { - - private final Map, CrudRepository> repositories = - new HashMap, CrudRepository>(); +public class DomainClassPropertyEditorRegistrar implements PropertyEditorRegistrar, ApplicationContextAware { + private final Map, CrudRepository> repositories = new HashMap, CrudRepository>(); /* * (non-Javadoc) @@ -77,15 +69,13 @@ public class DomainClassPropertyEditorRegistrar implements EntityInformation metadata = entry.getKey(); CrudRepository repository = entry.getValue(); - DomainClassPropertyEditor editor = - new DomainClassPropertyEditor( - repository, metadata, registry); + DomainClassPropertyEditor editor = new DomainClassPropertyEditor( + repository, metadata, registry); registry.registerCustomEditor(metadata.getJavaType(), editor); } } - /* * (non-Javadoc) * @@ -93,21 +83,17 @@ public class DomainClassPropertyEditorRegistrar implements * org.springframework.context.ApplicationContextAware#setApplicationContext * (org.springframework.context.ApplicationContext) */ - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({ "unchecked", "rawtypes" }) public void setApplicationContext(ApplicationContext context) { - Collection providers = - BeanFactoryUtils.beansOfTypeIncludingAncestors(context, - RepositoryFactoryInformation.class).values(); + Collection providers = BeanFactoryUtils.beansOfTypeIncludingAncestors(context, + RepositoryFactoryInformation.class).values(); for (RepositoryFactoryInformation information : providers) { - EntityInformation metadata = - information.getEntityInformation(); - Class> objectType = - information.getRepositoryInterface(); - CrudRepository repository = - BeanFactoryUtils.beanOfType(context, objectType); + EntityInformation metadata = information.getEntityInformation(); + Class> objectType = information.getRepositoryInterface(); + CrudRepository repository = BeanFactoryUtils.beanOfType(context, objectType); this.repositories.put(metadata, repository); } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/util/ClassUtils.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/util/ClassUtils.java index 77d30112e..58d4df382 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/util/ClassUtils.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/util/ClassUtils.java @@ -133,7 +133,7 @@ public abstract class ClassUtils { return; } } - + throw new IllegalStateException("Method has to have one of the following return types! " + Arrays.toString(types)); } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/util/TxUtils.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/util/TxUtils.java index 62fd13b6d..eda72e51d 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/util/TxUtils.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/util/TxUtils.java @@ -17,7 +17,7 @@ package org.springframework.data.repository.util; /** * Simple constants holder. - * + * * @author Oliver Gierke */ public abstract class TxUtils { @@ -26,6 +26,5 @@ public abstract class TxUtils { } - public static final String DEFAULT_TRANSACTION_MANAGER = - "transactionManager"; + public static final String DEFAULT_TRANSACTION_MANAGER = "transactionManager"; } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/transaction/ChangeSetBackedTransactionSynchronization.java b/spring-data-commons-core/src/main/java/org/springframework/data/transaction/ChangeSetBackedTransactionSynchronization.java index 564c639a0..d8239e213 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/transaction/ChangeSetBackedTransactionSynchronization.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/transaction/ChangeSetBackedTransactionSynchronization.java @@ -50,11 +50,13 @@ public class ChangeSetBackedTransactionSynchronization implements TransactionSyn } public void resume() { - throw new IllegalStateException("ChangedSetBackedTransactionSynchronization does not support transaction suspension currently."); + throw new IllegalStateException( + "ChangedSetBackedTransactionSynchronization does not support transaction suspension currently."); } public void suspend() { - throw new IllegalStateException("ChangedSetBackedTransactionSynchronization does not support transaction suspension currently."); + throw new IllegalStateException( + "ChangedSetBackedTransactionSynchronization does not support transaction suspension currently."); } } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/transaction/NaiveDoubleTransactionManager.java b/spring-data-commons-core/src/main/java/org/springframework/data/transaction/NaiveDoubleTransactionManager.java index 0dc840319..aed1f4bc0 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/transaction/NaiveDoubleTransactionManager.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/transaction/NaiveDoubleTransactionManager.java @@ -46,8 +46,7 @@ public class NaiveDoubleTransactionManager implements PlatformTransactionManager return new DefaultTransactionStatus(t, ts.isNewTransaction(), false, false, false, null); } - public TransactionStatus getTransaction(TransactionDefinition td) - throws TransactionException { + public TransactionStatus getTransaction(TransactionDefinition td) throws TransactionException { TransactionStatus atx = a.getTransaction(td); TransactionStatus btx = b.getTransaction(td); status.put(atx, btx); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/util/ClassTypeInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/util/ClassTypeInformation.java index af1877194..641d32cec 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/util/ClassTypeInformation.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/util/ClassTypeInformation.java @@ -26,7 +26,7 @@ import org.springframework.util.Assert; /** * Property information for a plain {@link Class}. - * + * * @author Oliver Gierke */ public class ClassTypeInformation extends TypeDiscoverer { @@ -35,7 +35,7 @@ public class ClassTypeInformation extends TypeDiscoverer { /** * Simple factory method to easily create new instances of {@link ClassTypeInformation}. - * + * * @param * @param type * @return @@ -43,7 +43,7 @@ public class ClassTypeInformation extends TypeDiscoverer { public static TypeInformation from(Class type) { return new ClassTypeInformation(type); } - + /** * Creates a {@link TypeInformation} from the given method's return type. * @@ -57,15 +57,14 @@ public class ClassTypeInformation extends TypeDiscoverer { /** * Creates {@link ClassTypeInformation} for the given type. - * + * * @param type */ public ClassTypeInformation(Class type) { this(type, GenericTypeResolver.getTypeVariableMap(type)); } - - @SuppressWarnings("rawtypes") + @SuppressWarnings("rawtypes") ClassTypeInformation(Class type, Map typeVariableMap) { super(type, typeVariableMap); this.type = type; diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/util/GenericTypeResolver.java b/spring-data-commons-core/src/main/java/org/springframework/data/util/GenericTypeResolver.java index 70481b86f..20e5edd8e 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/util/GenericTypeResolver.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/util/GenericTypeResolver.java @@ -32,14 +32,14 @@ import org.springframework.core.MethodParameter; import org.springframework.util.Assert; /** - * Copy of Spring's {@link org.springframework.core.GenericTypeResolver}. Needed - * until {@link #getTypeVariableMap(Class)} gets public. + * Copy of Spring's {@link org.springframework.core.GenericTypeResolver}. Needed until + * {@link #getTypeVariableMap(Class)} gets public. *

* TODO: remove that class, as soon as Spring 3.0.6 gets released. - * + * * @see SPR-8005 */ -@SuppressWarnings({"rawtypes", "unchecked"}) +@SuppressWarnings({ "rawtypes", "unchecked" }) abstract class GenericTypeResolver { /** @@ -50,19 +50,17 @@ abstract class GenericTypeResolver { /** * Determine the target type for the given parameter specification. - * + * * @param methodParam the method parameter specification * @return the corresponding generic parameter type */ public static Type getTargetType(MethodParameter methodParam) { Assert.notNull(methodParam, "MethodParameter must not be null"); if (methodParam.getConstructor() != null) { - return methodParam.getConstructor().getGenericParameterTypes()[methodParam - .getParameterIndex()]; + return methodParam.getConstructor().getGenericParameterTypes()[methodParam.getParameterIndex()]; } else { if (methodParam.getParameterIndex() >= 0) { - return methodParam.getMethod().getGenericParameterTypes()[methodParam - .getParameterIndex()]; + return methodParam.getMethod().getGenericParameterTypes()[methodParam.getParameterIndex()]; } else { return methodParam.getMethod().getGenericReturnType(); } @@ -70,15 +68,12 @@ abstract class GenericTypeResolver { } /** - * Resolve the single type argument of the given generic interface against the - * given target class which is assumed to implement the generic interface and - * possibly declare a concrete type for its type variable. - * - * @param clazz the target class to check against - * @param genericIfc the generic interface or superclass to resolve the type argument - * from - * @return the resolved type of the argument, or null if not - * resolvable + * Resolve the single type argument of the given generic interface against the given target class which is assumed to + * implement the generic interface and possibly declare a concrete type for its type variable. + * + * @param clazz the target class to check against + * @param genericIfc the generic interface or superclass to resolve the type argument from + * @return the resolved type of the argument, or null if not resolvable */ public static Class resolveTypeArgument(Class clazz, Class genericIfc) { Class[] typeArgs = resolveTypeArguments(clazz, genericIfc); @@ -86,31 +81,26 @@ abstract class GenericTypeResolver { return null; } if (typeArgs.length != 1) { - throw new IllegalArgumentException( - "Expected 1 type argument on generic interface [" - + genericIfc.getName() + "] but found " + typeArgs.length); + throw new IllegalArgumentException("Expected 1 type argument on generic interface [" + genericIfc.getName() + + "] but found " + typeArgs.length); } return typeArgs[0]; } /** - * Resolve the type arguments of the given generic interface against the given - * target class which is assumed to implement the generic interface and - * possibly declare concrete types for its type variables. - * - * @param clazz the target class to check against - * @param genericIfc the generic interface or superclass to resolve the type argument - * from - * @return the resolved type of each argument, with the array size matching - * the number of actual type arguments, or null if not - * resolvable + * Resolve the type arguments of the given generic interface against the given target class which is assumed to + * implement the generic interface and possibly declare concrete types for its type variables. + * + * @param clazz the target class to check against + * @param genericIfc the generic interface or superclass to resolve the type argument from + * @return the resolved type of each argument, with the array size matching the number of actual type arguments, or + * null if not resolvable */ public static Class[] resolveTypeArguments(Class clazz, Class genericIfc) { return doResolveTypeArguments(clazz, clazz, genericIfc); } - private static Class[] doResolveTypeArguments(Class ownerClass, - Class classToIntrospect, Class genericIfc) { + private static Class[] doResolveTypeArguments(Class ownerClass, Class classToIntrospect, Class genericIfc) { while (classToIntrospect != null) { if (genericIfc.isInterface()) { Type[] ifcs = classToIntrospect.getGenericInterfaces(); @@ -121,8 +111,7 @@ abstract class GenericTypeResolver { } } } else { - Class[] result = doResolveTypeArguments(ownerClass, - classToIntrospect.getGenericSuperclass(), genericIfc); + Class[] result = doResolveTypeArguments(ownerClass, classToIntrospect.getGenericSuperclass(), genericIfc); if (result != null) { return result; } @@ -132,8 +121,7 @@ abstract class GenericTypeResolver { return null; } - private static Class[] doResolveTypeArguments(Class ownerClass, Type ifc, - Class genericIfc) { + private static Class[] doResolveTypeArguments(Class ownerClass, Type ifc, Class genericIfc) { if (ifc instanceof ParameterizedType) { ParameterizedType paramIfc = (ParameterizedType) ifc; Type rawType = paramIfc.getRawType(); @@ -179,27 +167,24 @@ abstract class GenericTypeResolver { /** * Resolve the specified generic type against the given TypeVariable map. - * - * @param genericType the generic type to resolve + * + * @param genericType the generic type to resolve * @param typeVariableMap the TypeVariable Map to resolved against - * @return the type if it resolves to a Class, or Object.class - * otherwise + * @return the type if it resolves to a Class, or Object.class otherwise */ - static Class resolveType(Type genericType, - Map typeVariableMap) { + static Class resolveType(Type genericType, Map typeVariableMap) { Type rawType = getRawType(genericType, typeVariableMap); return (rawType instanceof Class ? (Class) rawType : Object.class); } /** * Determine the raw type for the given generic parameter type. - * - * @param genericType the generic type to resolve + * + * @param genericType the generic type to resolve * @param typeVariableMap the TypeVariable Map to resolved against * @return the resolved raw type */ - static Type getRawType(Type genericType, - Map typeVariableMap) { + static Type getRawType(Type genericType, Map typeVariableMap) { Type resolvedType = genericType; if (genericType instanceof TypeVariable) { TypeVariable tv = (TypeVariable) genericType; @@ -216,9 +201,8 @@ abstract class GenericTypeResolver { } /** - * Build a mapping of {@link TypeVariable#getName TypeVariable names} to - * concrete {@link Class} for the specified {@link Class}. Searches all super - * types, enclosing types and interfaces. + * Build a mapping of {@link TypeVariable#getName TypeVariable names} to concrete {@link Class} for the specified + * {@link Class}. Searches all super types, enclosing types and interfaces. */ static Map getTypeVariableMap(Class clazz) { Reference> ref = typeVariableCache.get(clazz); @@ -228,8 +212,7 @@ abstract class GenericTypeResolver { typeVariableMap = new HashMap(); // interfaces - extractTypeVariablesFromGenericInterfaces(clazz.getGenericInterfaces(), - typeVariableMap); + extractTypeVariablesFromGenericInterfaces(clazz.getGenericInterfaces(), typeVariableMap); // super class Type genericType = clazz.getGenericSuperclass(); @@ -239,8 +222,7 @@ abstract class GenericTypeResolver { ParameterizedType pt = (ParameterizedType) genericType; populateTypeMapFromParameterizedType(pt, typeVariableMap); } - extractTypeVariablesFromGenericInterfaces(type.getGenericInterfaces(), - typeVariableMap); + extractTypeVariablesFromGenericInterfaces(type.getGenericInterfaces(), typeVariableMap); genericType = type.getGenericSuperclass(); type = type.getSuperclass(); } @@ -256,8 +238,7 @@ abstract class GenericTypeResolver { type = type.getEnclosingClass(); } - typeVariableCache.put(clazz, new WeakReference>( - typeVariableMap)); + typeVariableCache.put(clazz, new WeakReference>(typeVariableMap)); } return typeVariableMap; @@ -278,31 +259,28 @@ abstract class GenericTypeResolver { return bound; } - private static void extractTypeVariablesFromGenericInterfaces( - Type[] genericInterfaces, Map typeVariableMap) { + private static void extractTypeVariablesFromGenericInterfaces(Type[] genericInterfaces, + Map typeVariableMap) { for (Type genericInterface : genericInterfaces) { if (genericInterface instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) genericInterface; populateTypeMapFromParameterizedType(pt, typeVariableMap); if (pt.getRawType() instanceof Class) { - extractTypeVariablesFromGenericInterfaces( - ((Class) pt.getRawType()).getGenericInterfaces(), typeVariableMap); + extractTypeVariablesFromGenericInterfaces(((Class) pt.getRawType()).getGenericInterfaces(), typeVariableMap); } } else if (genericInterface instanceof Class) { - extractTypeVariablesFromGenericInterfaces( - ((Class) genericInterface).getGenericInterfaces(), typeVariableMap); + extractTypeVariablesFromGenericInterfaces(((Class) genericInterface).getGenericInterfaces(), typeVariableMap); } } } /** - * Read the {@link TypeVariable TypeVariables} from the supplied - * {@link ParameterizedType} and add mappings corresponding to the - * {@link TypeVariable#getName TypeVariable name} -> concrete type to the - * supplied {@link Map}. + * Read the {@link TypeVariable TypeVariables} from the supplied {@link ParameterizedType} and add mappings + * corresponding to the {@link TypeVariable#getName TypeVariable name} -> concrete type to the supplied {@link Map}. *

* Consider this case: *

+ * *