Skip to content

Commit 0983e66

Browse files
committed
Revert "Omit annotations from the repository and domaintype in CrudMethodMetadata. (#1170)"
This reverts commit 99414aa.
1 parent 99414aa commit 0983e66

File tree

3 files changed

+10
-23
lines changed

3 files changed

+10
-23
lines changed

src/main/java/org/springframework/data/couchbase/repository/support/CrudMethodMetadataPostProcessor.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public Object invoke(MethodInvocation invocation) throws Throwable {
145145
currentInvocation.set(invocation);
146146

147147
try {
148+
148149
CrudMethodMetadata metadata = (CrudMethodMetadata) TransactionSynchronizationManager.getResource(method);
149150

150151
if (metadata != null) {
@@ -155,7 +156,7 @@ public Object invoke(MethodInvocation invocation) throws Throwable {
155156

156157
if (methodMetadata == null) {
157158

158-
methodMetadata = new DefaultCrudMethodMetadata(method);
159+
methodMetadata = new DefaultCrudMethodMetadata(method, repositoryInformation);
159160
CrudMethodMetadata tmp = metadataCache.putIfAbsent(method, methodMetadata);
160161

161162
if (tmp != null) {
@@ -186,6 +187,7 @@ private static class DefaultCrudMethodMetadata implements CrudMethodMetadata {
186187

187188
private final Method method;
188189
private final ScanConsistency scanConsistency;
190+
private final RepositoryInformation repositoryInformation;
189191
private final String scope;
190192
private final String collection;
191193

@@ -196,9 +198,10 @@ private static class DefaultCrudMethodMetadata implements CrudMethodMetadata {
196198
*
197199
* @param method must not be {@literal null}.
198200
*/
199-
DefaultCrudMethodMetadata(Method method) {
201+
DefaultCrudMethodMetadata(Method method, RepositoryInformation repositoryInformation) {
200202
Assert.notNull(method, "Method must not be null!");
201203
this.method = method;
204+
this.repositoryInformation = repositoryInformation;
202205
String n = method.getName();
203206
// internal methods
204207
if (n.equals("getEntityInformation") || n.equals("getOperations") || n.equals("withOptions")
@@ -209,7 +212,8 @@ private static class DefaultCrudMethodMetadata implements CrudMethodMetadata {
209212
return;
210213
}
211214

212-
AnnotatedElement[] annotated = new AnnotatedElement[] { method, method.getDeclaringClass()};
215+
AnnotatedElement[] annotated = new AnnotatedElement[] { method, method.getDeclaringClass(),
216+
repositoryInformation.getRepositoryInterface(), repositoryInformation.getDomainType() };
213217
this.scanConsistency = OptionsBuilder.annotation(ScanConsistency.class, "query", QueryScanConsistency.NOT_BOUNDED,
214218
annotated);
215219
this.scope = OptionsBuilder.annotationString(Scope.class, CollectionIdentifier.DEFAULT_SCOPE, annotated);

src/test/java/org/springframework/data/couchbase/domain/UserColRepository.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@
3838
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
3939
public interface UserColRepository extends CouchbaseRepository<UserCol, String>, DynamicProxyable<UserColRepository> {
4040

41-
// CouchbaseRepositoryQueryCollectionIntegrationTests.testScopeCollectionAnnotationSwap() relies on this
42-
// being commented out.
43-
//<S extends UserCol> S save(S var1);
41+
<S extends UserCol> S save(S var1);
4442

4543
List<UserCol> findByFirstname(String firstname);
4644

src/test/java/org/springframework/data/couchbase/repository/query/CouchbaseRepositoryQueryCollectionIntegrationTests.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.data.couchbase.repository.query;
1717

18-
import static com.couchbase.client.core.io.CollectionIdentifier.DEFAULT_SCOPE;
1918
import static org.junit.jupiter.api.Assertions.assertEquals;
2019
import static org.junit.jupiter.api.Assertions.assertThrows;
2120

@@ -179,7 +178,7 @@ public void testScopeCollectionAnnotation() {
179178
// scope
180179
List<UserCol> found = userColRepository.withCollection(otherCollection).findByFirstname(user.getFirstname());
181180
assertEquals(saved, found.get(0), "should have found what was saved");
182-
List<UserCol> notfound = userColRepository.withScope(DEFAULT_SCOPE)
181+
List<UserCol> notfound = userColRepository.withScope(CollectionIdentifier.DEFAULT_SCOPE)
183182
.withCollection(CollectionIdentifier.DEFAULT_COLLECTION).findByFirstname(user.getFirstname());
184183
assertEquals(0, notfound.size(), "should not have found what was saved");
185184
} finally {
@@ -189,20 +188,6 @@ public void testScopeCollectionAnnotation() {
189188
}
190189
}
191190

192-
@Test
193-
public void testScopeCollectionAnnotationSwap() {
194-
// UserCol annotation scope is other_scope, collection is other_collection
195-
// airportRepository relies on Config.setScopeName(scopeName) ("my_scope") from CollectionAwareIntegrationTests.
196-
// using airportRepository without specified a collection should fail.
197-
// This test ensures that airportRepository.save(airport) doesn't get the
198-
// collection from CrudMethodMetadata of UserCol.save()
199-
UserCol userCol = new UserCol("1", "Dave", "Wilson");
200-
Airport airport = new Airport("3", "myIata", "myIcao");
201-
UserCol savedCol = userColRepository.save(userCol); // uses UserCol annotation scope, populates CrudMethodMetadata
202-
userColRepository.delete(userCol); // uses UserCol annotation scope, populates CrudMethodMetadata
203-
assertThrows(IllegalStateException.class, () -> airportRepository.save(airport));
204-
}
205-
206191
// template default scope is my_scope
207192
// UserCol annotation scope is other_scope
208193
@Test
@@ -213,7 +198,7 @@ public void testScopeCollectionRepoWith() {
213198
List<UserCol> found = userColRepository.withScope(scopeName).withCollection(collectionName)
214199
.findByFirstname(user.getFirstname());
215200
assertEquals(saved, found.get(0), "should have found what was saved");
216-
List<UserCol> notfound = userColRepository.withScope(DEFAULT_SCOPE)
201+
List<UserCol> notfound = userColRepository.withScope(CollectionIdentifier.DEFAULT_SCOPE)
217202
.withCollection(CollectionIdentifier.DEFAULT_COLLECTION).findByFirstname(user.getFirstname());
218203
assertEquals(0, notfound.size(), "should not have found what was saved");
219204
userColRepository.withScope(scopeName).withCollection(collectionName).delete(user);

0 commit comments

Comments
 (0)