diff --git a/src/main/java/org/springframework/data/repository/augment/AbstractSoftDeleteQueryAugmentor.java b/src/main/java/org/springframework/data/repository/augment/AbstractSoftDeleteQueryAugmentor.java index 27d73da88..5534102a9 100644 --- a/src/main/java/org/springframework/data/repository/augment/AbstractSoftDeleteQueryAugmentor.java +++ b/src/main/java/org/springframework/data/repository/augment/AbstractSoftDeleteQueryAugmentor.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ import org.springframework.data.util.DirectFieldAccessFallbackBeanWrapper; /** * Base class to implement a {@link QueryAugmentor} to soft-delete entities. * - * @since 1.9 + * @since 1.11 * @author Oliver Gierke */ public abstract class AbstractSoftDeleteQueryAugmentor, N extends QueryContext, U extends UpdateContext> diff --git a/src/main/java/org/springframework/data/repository/augment/AnnotationBasedQueryAugmentor.java b/src/main/java/org/springframework/data/repository/augment/AnnotationBasedQueryAugmentor.java index 18f9cc123..60d3143f0 100644 --- a/src/main/java/org/springframework/data/repository/augment/AnnotationBasedQueryAugmentor.java +++ b/src/main/java/org/springframework/data/repository/augment/AnnotationBasedQueryAugmentor.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,8 +31,12 @@ import org.springframework.data.repository.core.EntityMetadata; * {@link #prepareQuery(QueryContext, Annotation)} and {@link #prepareUpdate(UpdateContext, Annotation)} methods. Opts * out of augmentation in case the annotation cannot be found on the method invoked or in the type. * - * @since 1.9 + * @since 1.11 * @author Oliver Gierke + * @param T the annotation type + * @param Q the {@link QueryContext} type to be used for store specific queries. + * @param N the {@link QueryContext} type to be used to native queries. + * @param U the {@link UpdateContext} type to be used. */ public abstract class AnnotationBasedQueryAugmentor, N extends QueryContext, U extends UpdateContext> implements QueryAugmentor { diff --git a/src/main/java/org/springframework/data/repository/augment/MethodMetadata.java b/src/main/java/org/springframework/data/repository/augment/MethodMetadata.java index e5e74548b..ffe94b2d1 100644 --- a/src/main/java/org/springframework/data/repository/augment/MethodMetadata.java +++ b/src/main/java/org/springframework/data/repository/augment/MethodMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import org.springframework.data.repository.CrudRepository; /** * Interface to abstract {@link MethodMetadata} to be looked up for the repository method invoked. * - * @see 1.9 + * @see 1.11 * @author Oliver Gierke */ public interface MethodMetadata { diff --git a/src/main/java/org/springframework/data/repository/augment/QueryAugmentationEngine.java b/src/main/java/org/springframework/data/repository/augment/QueryAugmentationEngine.java index fdee43ef0..1f1c3effe 100644 --- a/src/main/java/org/springframework/data/repository/augment/QueryAugmentationEngine.java +++ b/src/main/java/org/springframework/data/repository/augment/QueryAugmentationEngine.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ import org.springframework.util.MultiValueMap; * Wrapper for a collection of {@link QueryAugmentor}s. Groups them by the context type they're referring to for the * appropriate invocation later on. * - * @since 1.9 + * @since 1.11 * @author Oliver Gierke */ public class QueryAugmentationEngine { @@ -125,7 +125,8 @@ public class QueryAugmentationEngine { return invokeAugmentor(new AugmentorInvoker() { @SuppressWarnings("unchecked") - public T invokeAugmentor(QueryAugmentor, QueryContext, UpdateContext> augmentor, T context) { + public T invokeAugmentor(QueryAugmentor, QueryContext, UpdateContext> augmentor, + T context) { return (T) augmentor.augmentNativeQuery(context, methodMetadata); } }, context); @@ -140,7 +141,8 @@ public class QueryAugmentationEngine { return invokeAugmentor(new AugmentorInvoker() { @SuppressWarnings("unchecked") - public N invokeAugmentor(QueryAugmentor, QueryContext, UpdateContext> augmentor, N context) { + public N invokeAugmentor(QueryAugmentor, QueryContext, UpdateContext> augmentor, + N context) { return (N) augmentor.augmentQuery(context, methodMetadata); } }, context); @@ -156,7 +158,8 @@ public class QueryAugmentationEngine { return invokeAugmentor(new AugmentorInvoker() { @SuppressWarnings("unchecked") - public U invokeAugmentor(QueryAugmentor, QueryContext, UpdateContext> augmentor, U context) { + public U invokeAugmentor(QueryAugmentor, QueryContext, UpdateContext> augmentor, + U context) { return (U) augmentor.augmentUpdate(context, methodMetadata); } }, context); @@ -167,8 +170,8 @@ public class QueryAugmentationEngine { Assert.notNull(context, "UpdateContext must not be null!"); T augmentedContext = context; - for (QueryAugmentor, QueryContext, UpdateContext> augmentor : augmentors.get(context - .getClass())) { + for (QueryAugmentor, QueryContext, UpdateContext> augmentor : augmentors + .get(context.getClass())) { LOGGER.debug("Invoking augmentor {} for context {}", augmentor, context); augmentedContext = invoker.invokeAugmentor(augmentor, augmentedContext); diff --git a/src/main/java/org/springframework/data/repository/augment/QueryAugmentationEngineAware.java b/src/main/java/org/springframework/data/repository/augment/QueryAugmentationEngineAware.java index 24ccfa363..53179e304 100644 --- a/src/main/java/org/springframework/data/repository/augment/QueryAugmentationEngineAware.java +++ b/src/main/java/org/springframework/data/repository/augment/QueryAugmentationEngineAware.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import org.springframework.data.repository.core.support.RepositoryFactorySupport * Injection interface to express the dependency to a {@link QueryAugmentationEngine}. Usually implemented by repository * implementations. The {@link RepositoryFactorySupport} base class will inject the {@link QueryAugmentationEngine}. * - * @since 1.9 + * @since 1.11 * @author Oliver Gierke */ public interface QueryAugmentationEngineAware { diff --git a/src/main/java/org/springframework/data/repository/augment/QueryAugmentor.java b/src/main/java/org/springframework/data/repository/augment/QueryAugmentor.java index 85c5aa95c..8fa9247ea 100644 --- a/src/main/java/org/springframework/data/repository/augment/QueryAugmentor.java +++ b/src/main/java/org/springframework/data/repository/augment/QueryAugmentor.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +21,13 @@ import org.springframework.data.repository.core.EntityMetadata; /** * SPI to abstract components that want to augment queries executed by the repositories. * - * @since 1.9 + * @since 1.11 * @author Oliver Gierke + * @param Q the {@link QueryContext} type to be used for store specific queries. + * @param N the {@link QueryContext} type to be used to native queries. + * @param U the {@link UpdateContext} type to be used. */ -public interface QueryAugmentor, N extends QueryContext, S extends UpdateContext> { +public interface QueryAugmentor, N extends QueryContext, U extends UpdateContext> { /** * Determines whether the implementation is interested in augmentation at all. The implementations can expect to only @@ -39,26 +42,26 @@ public interface QueryAugmentor, N extends QueryContex */ boolean supports(MethodMetadata method, QueryMode queryMode, EntityMetadata entityMetadata); - N augmentNativeQuery(N query, MethodMetadata methodMetadata); + N augmentNativeQuery(N context, MethodMetadata methodMetadata); /** * Augments the query by either adding further constraints to it or entirely replacing it. Clients will use * {@link QueryContext#getQuery()} proceeding with the query execution. * - * @param query the query context of the query about to be executed. + * @param context the query context of the query about to be executed. * @param methodMetadata metadata about the repository method being invoked. * @return must not be {@literal null}. */ - Q augmentQuery(Q query, MethodMetadata methodMetadata); + Q augmentQuery(Q context, MethodMetadata methodMetadata); /** * Augments the update about to be executed. Implementations can prevent the original update from being executed by * returning null. * - * @param update the update context of the update about to be executed + * @param context the update context of the update about to be executed * @param methodMetadata metadata about the repository method being invoked. * @return the update to continue to work with or {@literal null} in case the implementation already executed custom * update and wants to prevent the execution of the original update. */ - S augmentUpdate(S update, MethodMetadata methodMetadata); + U augmentUpdate(U context, MethodMetadata methodMetadata); } diff --git a/src/main/java/org/springframework/data/repository/augment/QueryContext.java b/src/main/java/org/springframework/data/repository/augment/QueryContext.java index 3643151d7..72f49782f 100644 --- a/src/main/java/org/springframework/data/repository/augment/QueryContext.java +++ b/src/main/java/org/springframework/data/repository/augment/QueryContext.java @@ -57,7 +57,17 @@ public class QueryContext { /** * To be used for the execution of the additional count query to be executed when paging. */ - COUNT_FOR_PAGING; + COUNT_FOR_PAGING, + + /** + * To be used for the execution of queries that precede an update. + */ + FOR_UPDATE, + + /** + * To be used for the execution of queries that precede a delete. + */ + FOR_DELETE; /** * Returns whether the {@link QueryMode} is one of the given ones. diff --git a/src/main/java/org/springframework/data/repository/augment/UpdateContext.java b/src/main/java/org/springframework/data/repository/augment/UpdateContext.java index c09ad9d9a..63f64a5ea 100644 --- a/src/main/java/org/springframework/data/repository/augment/UpdateContext.java +++ b/src/main/java/org/springframework/data/repository/augment/UpdateContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import org.springframework.util.Assert; /** * Context to be handed around for update executions. * - * @since 1.9 + * @since 1.11 * @author Oliver Gierke */ public class UpdateContext { @@ -28,7 +28,7 @@ public class UpdateContext { /** * The mode of the update execution. * - * @since 1.9 + * @since 1.11 * @author Oliver Gierke */ public static enum UpdateMode {