Allow non-exact argument type matching for DynamicProxyable. (#1819)

Allow non-exact (isAssignableFrom) argument matching for methods
called by DyanmicProxyable. If there are exactly two candidates,
and one returns an Iterable and the other returns a List, use
the method that returns the List.  This is due to
CouchbaseRepository defining findAll() methods as List<?>, while
PagingAndSortyRepository defines findAll() to return an Iterable.
This needs to be addressed separately.

Closes #1818.
This commit is contained in:
Michael Reiche
2023-09-11 19:13:55 -07:00
committed by GitHub
parent 51324655fd
commit 62bee5cfb4
4 changed files with 182 additions and 3 deletions

View File

@@ -16,13 +16,15 @@
package org.springframework.data.couchbase.domain;
import java.util.Collection;
import java.util.List;
import org.springframework.data.couchbase.repository.CouchbaseRepository;
import org.springframework.data.couchbase.repository.DynamicProxyable;
import org.springframework.data.couchbase.repository.Query;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@@ -39,4 +41,5 @@ public interface AirlineRepository extends CouchbaseRepository<Airline, String>,
@Query("select meta().id as _ID, meta().cas as _CAS, #{#n1ql.bucket}.* from #{#n1ql.bucket} where #{#n1ql.filter} and (name = $1)")
List<Airline> getByName_3x(@Param("airline_name") String airlineName);
Page<Airline> findByHqCountryIn(@Param("hqCountry") Collection<String> hqCountry, Pageable pageable);
}

View File

@@ -66,6 +66,7 @@ import org.springframework.data.couchbase.core.query.N1QLExpression;
import org.springframework.data.couchbase.core.query.QueryCriteria;
import org.springframework.data.couchbase.domain.Address;
import org.springframework.data.couchbase.domain.AirlineRepository;
import org.springframework.data.couchbase.domain.Airline;
import org.springframework.data.couchbase.domain.Airport;
import org.springframework.data.couchbase.domain.AirportJsonValue;
import org.springframework.data.couchbase.domain.AirportJsonValueRepository;
@@ -292,6 +293,23 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
}
@Test
void issuePageableDynamicProxyParameter() {
Airline airline = null;
try {
airline = new Airline("airline::USA", "US Air", "US");
airlineRepository.withScope("_default").save(airline);
java.util.Collection<String> countries = new LinkedList<String>();
countries.add(airline.getHqCountry());
Pageable pageable = PageRequest.of(0, 1, Sort.by("hqCountry"));
Page<Airline> airports2 = airlineRepository.withScope("_default").withOptions(QueryOptions.queryOptions().scanConsistency(REQUEST_PLUS)).findByHqCountryIn(countries, pageable);
assertEquals(1, airports2.getTotalElements());
} finally {
airlineRepository.withScope("_default").delete(airline);
}
}
@Test
void findBySimpleProperty() {
Airport vie = null;