From 9fa51744d7a7b480a7cac25acaf0bb9bbeabf58a Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Mon, 14 Dec 2015 20:53:55 +0100 Subject: [PATCH] DATACOUCH-181 - Adapted to API changes in Spring Data Commons. Related ticket: DATACMNS-89. --- .../query/CouchbaseQueryMethod.java | 29 +++++++------------ .../support/CouchbaseRepositoryFactory.java | 14 +++++++-- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/springframework/data/couchbase/repository/query/CouchbaseQueryMethod.java b/src/main/java/org/springframework/data/couchbase/repository/query/CouchbaseQueryMethod.java index 5442c663..9ad5cc55 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/query/CouchbaseQueryMethod.java +++ b/src/main/java/org/springframework/data/couchbase/repository/query/CouchbaseQueryMethod.java @@ -1,5 +1,5 @@ /* - * Copyright 2013, 2014 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. @@ -16,15 +16,13 @@ package org.springframework.data.couchbase.repository.query; -import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity; -import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty; +import java.lang.reflect.Method; + import org.springframework.data.couchbase.core.view.View; -import org.springframework.data.mapping.context.MappingContext; +import org.springframework.data.projection.ProjectionFactory; import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.data.repository.query.QueryMethod; -import java.lang.reflect.Method; - /** * Represents a query method with couchbase extensions. * @@ -32,15 +30,11 @@ import java.lang.reflect.Method; */ public class CouchbaseQueryMethod extends QueryMethod { - private final Method method; - private final MappingContext, CouchbasePersistentProperty> mappingContext; + private final View viewAnnotation; - public CouchbaseQueryMethod(Method method, RepositoryMetadata metadata, - MappingContext, CouchbasePersistentProperty> mappingContext) { - super(method, metadata); - - this.method = method; - this.mappingContext = mappingContext; + public CouchbaseQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory) { + super(method, metadata, factory); + this.viewAnnotation = method.getAnnotation(View.class); } /** @@ -53,14 +47,11 @@ public class CouchbaseQueryMethod extends QueryMethod { } /** - * Returns the @View annoation if set, null otherwise. + * Returns the @View annotation if set, null otherwise. * * @return the view annotation of present. */ public View getViewAnnotation() { - return method.getAnnotation(View.class); + return viewAnnotation; } - - - } diff --git a/src/main/java/org/springframework/data/couchbase/repository/support/CouchbaseRepositoryFactory.java b/src/main/java/org/springframework/data/couchbase/repository/support/CouchbaseRepositoryFactory.java index 4371c475..fef09f85 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/support/CouchbaseRepositoryFactory.java +++ b/src/main/java/org/springframework/data/couchbase/repository/support/CouchbaseRepositoryFactory.java @@ -24,6 +24,7 @@ import org.springframework.data.couchbase.repository.query.CouchbaseQueryMethod; import org.springframework.data.couchbase.repository.query.ViewBasedCouchbaseQuery; import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mapping.model.MappingException; +import org.springframework.data.projection.ProjectionFactory; import org.springframework.data.repository.core.NamedQueries; import org.springframework.data.repository.core.RepositoryInformation; import org.springframework.data.repository.core.RepositoryMetadata; @@ -128,9 +129,16 @@ public class CouchbaseRepositoryFactory extends RepositoryFactorySupport { * Currently, only views are supported. N1QL support to be added. */ private class CouchbaseQueryLookupStrategy implements QueryLookupStrategy { - @Override - public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, NamedQueries namedQueries) { - CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod(method, metadata, mappingContext); + + /* + * (non-Javadoc) + * @see org.springframework.data.repository.query.QueryLookupStrategy#resolveQuery(java.lang.reflect.Method, org.springframework.data.repository.core.RepositoryMetadata, org.springframework.data.projection.ProjectionFactory, org.springframework.data.repository.core.NamedQueries) + */ + @Override + public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, + NamedQueries namedQueries) { + + CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod(method, metadata, factory); return new ViewBasedCouchbaseQuery(queryMethod, couchbaseOperations); } }