Skip to content

Commit

Permalink
DATAJPA-1131 - Adopt to changed AnnotationUtils.getValue(…) behavior.
Browse files Browse the repository at this point in the history
Related ticket: SPR-15540.
  • Loading branch information
mp911de committed Jun 7, 2017
1 parent d70a804 commit 0d3c5af
Showing 1 changed file with 28 additions and 26 deletions.
Expand Up @@ -22,6 +22,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import javax.persistence.LockModeType;
Expand All @@ -45,10 +46,11 @@

/**
* JPA specific extension of {@link QueryMethod}.
*
*
* @author Oliver Gierke
* @author Thomas Darimont
* @author Christoph Strobl
* @author Mark Paluch
*/
public class JpaQueryMethod extends QueryMethod {

Expand Down Expand Up @@ -78,7 +80,7 @@ public class JpaQueryMethod extends QueryMethod {

/**
* Creates a {@link JpaQueryMethod}.
*
*
* @param method must not be {@literal null}
* @param extractor must not be {@literal null}
* @param metadata must not be {@literal null}
Expand Down Expand Up @@ -122,7 +124,7 @@ private void assertParameterNamesInAnnotatedQuery() {
}
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.repository.query.QueryMethod#getEntityInformation()
*/
Expand All @@ -134,7 +136,7 @@ public JpaEntityMetadata<?> getEntityInformation() {

/**
* Returns whether the finder is a modifying one.
*
*
* @return
*/
@Override
Expand All @@ -145,7 +147,7 @@ public boolean isModifyingQuery() {

/**
* Returns all {@link QueryHint}s annotated at this class. Note, that {@link QueryHints}
*
*
* @return
*/
List<QueryHint> getHints() {
Expand All @@ -162,18 +164,19 @@ List<QueryHint> getHints() {

/**
* Returns the {@link LockModeType} to be used for the query.
*
*
* @return
*/
LockModeType getLockModeType() {

Lock annotation = AnnotatedElementUtils.findMergedAnnotation(method, Lock.class);
return (LockModeType) AnnotationUtils.getValue(annotation);
return (LockModeType) Optional.ofNullable(AnnotatedElementUtils.findMergedAnnotation(method, Lock.class)) //
.map(AnnotationUtils::getValue) //
.orElse(null);
}

/**
* Returns the {@link EntityGraph} to be used for the query.
*
*
* @return
* @since 1.6
*/
Expand All @@ -186,7 +189,7 @@ JpaEntityGraph getEntityGraph() {
/**
* Returns whether the potentially configured {@link QueryHint}s shall be applied when triggering the count query for
* pagination.
*
*
* @return
*/
boolean applyHintsToCountQuery() {
Expand All @@ -197,7 +200,7 @@ boolean applyHintsToCountQuery() {

/**
* Returns the {@link QueryExtractor}.
*
*
* @return
*/
QueryExtractor getQueryExtractor() {
Expand All @@ -207,7 +210,7 @@ QueryExtractor getQueryExtractor() {

/**
* Returns the actual return type of the method.
*
*
* @return
*/
Class<?> getReturnType() {
Expand All @@ -218,7 +221,7 @@ Class<?> getReturnType() {
/**
* Returns the query string declared in a {@link Query} annotation or {@literal null} if neither the annotation found
* nor the attribute was specified.
*
*
* @return
*/
String getAnnotatedQuery() {
Expand All @@ -230,7 +233,7 @@ String getAnnotatedQuery() {
/**
* Returns the countQuery string declared in a {@link Query} annotation or {@literal null} if neither the annotation
* found nor the attribute was specified.
*
*
* @return
*/
String getCountQuery() {
Expand All @@ -242,7 +245,7 @@ String getCountQuery() {
/**
* Returns the count query projection string declared in a {@link Query} annotation or {@literal null} if neither the
* annotation found nor the attribute was specified.
*
*
* @return
* @since 1.6
*/
Expand All @@ -254,14 +257,14 @@ String getCountQueryProjection() {

/**
* Returns whether the backing query is a native one.
*
*
* @return
*/
boolean isNativeQuery() {
return getAnnotationValue("nativeQuery", Boolean.class).booleanValue();
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.repository.query.QueryMethod#getNamedQueryName()
*/
Expand All @@ -274,7 +277,7 @@ public String getNamedQueryName() {

/**
* Returns the name of the {@link NamedQuery} that shall be used for count queries.
*
*
* @return
*/
String getNamedCountQueryName() {
Expand All @@ -285,7 +288,7 @@ String getNamedCountQueryName() {

/**
* Returns whether we should clear automatically for modifying queries.
*
*
* @return
*/
boolean getClearAutomatically() {
Expand All @@ -295,10 +298,9 @@ boolean getClearAutomatically() {
/**
* Returns the {@link Query} annotation's attribute casted to the given type or default value if no annotation
* available.
*
*
* @param attribute
* @param type
* @param defaultValue
* @return
*/
private <T> T getAnnotationValue(String attribute, Class<T> type) {
Expand All @@ -316,7 +318,7 @@ private <T> T getMergedOrDefaultAnnotationValue(String attribute, Class annotati
return targetType.cast(AnnotationUtils.getValue(annotation, attribute));
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.repository.query.QueryMethod#createParameters(java.lang.reflect.Method)
*/
Expand All @@ -325,7 +327,7 @@ protected JpaParameters createParameters(Method method) {
return new JpaParameters(method);
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.repository.query.QueryMethod#getParameters()
*/
Expand All @@ -334,7 +336,7 @@ public JpaParameters getParameters() {
return (JpaParameters) super.getParameters();
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.repository.query.QueryMethod#isCollectionQuery()
*/
Expand All @@ -345,7 +347,7 @@ public boolean isCollectionQuery() {

/**
* Return {@literal true} if the method contains a {@link Procedure} annotation.
*
*
* @return
*/
public boolean isProcedureQuery() {
Expand All @@ -355,7 +357,7 @@ public boolean isProcedureQuery() {
/**
* Returns a new {@link StoredProcedureAttributes} representing the stored procedure meta-data for this
* {@link JpaQueryMethod}.
*
*
* @return
*/
StoredProcedureAttributes getProcedureAttributes() {
Expand Down

0 comments on commit 0d3c5af

Please sign in to comment.