Skip to content

scope and collection annotations on repository are not considered during execution. #1441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mikereiche opened this issue May 18, 2022 · 2 comments · Fixed by #1467
Closed
Assignees
Labels
type: bug A general bug

Comments

@mikereiche
Copy link
Collaborator

mikereiche commented May 18, 2022

The issue is that although the collection name (contact) is being used as the keyspace, the query_context of default:. is not being specified as an option.

Customer has a question on using #{#n1ql.delete} -- they're not getting the expected scope/collection in the generated N1QL. What are they doing wrong?
@repository
@scope("contacts")
@Collection("contact")
public interface ContactRepository extends CouchbaseRepository<Contact, String> {
@query("#{#n1ql.delete} WHERE status = $1 AND updateTime < $2 AND #{#n1ql.filter} LIMIT 1")
void deleteInactiveContacts(final ContactStatus status, final long updateTime);
}
com.couchbase.client.core.error.IndexFailureException: The server reported an issue with the underlying index {"completed":true,"coreId":"0x740bdb3700000001","errors":[{"code":12003,"message":"Keyspace not found in CB datastore: default:contact - cause: No bucket named contact"}],"idempotent":false,"lastDispatchedFrom":"y.y.y.y:49272","lastDispatchedTo":"x.x.x.x:8093","requestId":479,"requestType":"QueryRequest","retried":0,"service":{"operationId":"4ed7e8c5-a356-40c7-ab5b-77b0b9fafcca","statement":"DELETE FROM contact WHERE status = $1 AND updateTime < $2 AND _class = "com.xxx.Contact" LIMIT 1","type":"query"},"timeoutMs":75000,"timings":{"dispatchMicros":862708,"totalDispatchMicros":862708,"totalMicros":967676}}

@mikereiche
Copy link
Collaborator Author

@Test
void stringDeleteCollectionTest() throws Exception {
	Airport airport = new Airport("airports::vie", "vie", "lowx");
	Airport otherAirport = new Airport("airports::xxx", "xxx", "lxxx");
	try {
		airportRepository.withScope("my_scope").withCollection("my_collection").deleteById(airport.getId());
	}catch(DataRetrievalFailureException drfe){}
	try {
		airportRepository.withScope("my_scope").withCollection("my_collection").deleteById(otherAirport.getId());
	}catch(DataRetrievalFailureException drfe){}
	try {
		airportRepository.withScope("my_scope").withCollection("my_collection").save(airport);
		airportRepository.withScope("my_scope").withCollection("my_collection").save(otherAirport);
		assertEquals(1,
				airportRepository./*withScope("my_scope").withCollection("my_collection").*/deleteByIata("vie").size());
	} catch (Exception e) {
		e.printStackTrace();
		throw e;
	} finally {
		airportRepository.withScope("my_scope").withCollection("my_collection").deleteById(otherAirport.getId());
	}
}

@mikereiche mikereiche self-assigned this May 23, 2022
@mikereiche mikereiche added the type: bug A general bug label May 23, 2022
@mikereiche mikereiche added this to the 4.4.1 (2021.2.1) milestone May 23, 2022
@mikereiche
Copy link
Collaborator Author

mikereiche commented May 25, 2022

work-around to to specify scope and collection elsewhere. Scope can be specified in the implementation of AbstractCouchbaseConfiguration (getScope()), as an annotation on the entity class or on the repository as myRepo.withScope(scopeName).deleteInactiveContacts(...)
Collection can be specified on all those places except the configuration.

mikereiche added a commit that referenced this issue Jun 17, 2022
The scope and collection from the repository annotation are associated with
the method call by CrudMethodMetadataProcessor. This will also need #1445 to
work.

Closes #1441.
mikereiche added a commit that referenced this issue Jun 17, 2022
mikereiche added a commit that referenced this issue Jun 17, 2022
The scope and collection from the repository annotation are associated with
the method call by CrudMethodMetadataProcessor. This will also need #1445 to
work.

Closes #1441.
mikereiche added a commit that referenced this issue Jun 17, 2022
mikereiche added a commit that referenced this issue Jun 17, 2022
The scope and collection from the repository annotation are associated with
the method call by CrudMethodMetadataProcessor. This will also need #1445 to
work.

Closes #1441.
mikereiche added a commit that referenced this issue Jun 17, 2022
mikereiche added a commit that referenced this issue Jun 17, 2022
The scope and collection from the repository annotation are associated with
the method call by CrudMethodMetadataProcessor. This will also need #1445 to
work.

Closes #1441.
mikereiche added a commit that referenced this issue Jun 17, 2022
mikereiche added a commit that referenced this issue Jun 17, 2022
The scope and collection repository annotations were not being
passed on to derived and @query remove operations.

The handling of scope and collection annotations has been reworked in:

1) CrudMethodMetadataProcessor
2) All the *OperationSuppport constructors - the initial scope and collection is
taken from the domainEntity class.
3) PseudoArgs
4) AbstractCouchbaseQuery/AbstractReactiveCouchbaseQuery add the scope/collection
to the remove operation (analogous to the find Operation).
5) Scope/Collection is passed as args to the execute() method - even though this
is redundant at the moment.

Closes #1441.
mikereiche added a commit that referenced this issue Jun 17, 2022
The scope and collection repository annotations were not being
passed on to derived and @query remove operations.

The handling of scope and collection annotations has been reworked in:

1) CrudMethodMetadataProcessor
2) All the *OperationSuppport constructors - the initial scope and collection is
taken from the domainEntity class.
3) PseudoArgs
4) AbstractCouchbaseQuery/AbstractReactiveCouchbaseQuery add the scope/collection
to the remove operation (analogous to the find Operation).
5) Scope/Collection is passed as args to the execute() method - even though this
is redundant at the moment.

Closes #1441.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment