DATAJDBC-182 - Polishing.

Extracted method to maintain a single level of abstraction.
Added description to assertion that wasn't obvious to me.
Added JavaDoc on existing method.
Commented repository methods in test with issue ids to ease understanding the purpose of each method.
This commit is contained in:
Jens Schauder
2018-03-09 10:02:10 +01:00
parent 73fe1ca93b
commit 5f6a44d00a
3 changed files with 56 additions and 35 deletions

View File

@@ -56,18 +56,21 @@ class JdbcQueryLookupStrategy implements QueryLookupStrategy {
JdbcQueryMethod queryMethod = new JdbcQueryMethod(method, repositoryMetadata, projectionFactory);
Class<?> returnedObjectType = queryMethod.getReturnedObjectType();
RowMapper<?> rowMapper = null;
if (!queryMethod.isModifyingQuery()) {
rowMapper = context.getSimpleTypeHolder().isSimpleType(returnedObjectType)
? SingleColumnRowMapper.newInstance(returnedObjectType, conversionService)
: new EntityRowMapper<>( //
context.getRequiredPersistentEntity(returnedObjectType), //
conversionService, //
context, //
accessStrategy //
);
}
RowMapper<?> rowMapper = queryMethod.isModifyingQuery() ? null : createRowMapper(returnedObjectType);
return new JdbcRepositoryQuery(queryMethod, context, rowMapper);
}
private RowMapper<?> createRowMapper(Class<?> returnedObjectType) {
return context.getSimpleTypeHolder().isSimpleType(returnedObjectType)
? SingleColumnRowMapper.newInstance(returnedObjectType, conversionService)
: new EntityRowMapper<>( //
context.getRequiredPersistentEntity(returnedObjectType), //
conversionService, //
context, //
accessStrategy //
);
}
}

View File

@@ -24,6 +24,7 @@ import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.QueryMethod;
import org.springframework.lang.Nullable;
/**
* {@link QueryMethod} implementation that implements a method by executing the query from a {@link Query} annotation on
@@ -44,6 +45,12 @@ public class JdbcQueryMethod extends QueryMethod {
this.method = method;
}
/**
* Returns the annotated query if it exists.
*
* @return May be {@code null}.
*/
@Nullable
public String getAnnotatedQuery() {
Query queryAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, Query.class);