-
Notifications
You must be signed in to change notification settings - Fork 192
Fix 1441 in 4_4_x - scope and collection not considered in repo delete. #1465
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2020-2021 the original author or authors. | ||
* Copyright 2020-2022 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. | ||
|
@@ -19,6 +19,7 @@ | |
import org.springframework.data.couchbase.core.ReactiveCouchbaseOperations; | ||
import org.springframework.data.couchbase.core.ReactiveFindByQueryOperation; | ||
import org.springframework.data.couchbase.core.ReactiveFindByQueryOperation.ReactiveFindByQuery; | ||
import org.springframework.data.couchbase.core.ReactiveRemoveByQueryOperation.ReactiveRemoveByQuery; | ||
import org.springframework.data.couchbase.core.query.Query; | ||
import org.springframework.data.couchbase.repository.query.ReactiveCouchbaseQueryExecution.DeleteExecution; | ||
import org.springframework.data.couchbase.repository.query.ReactiveCouchbaseQueryExecution.ResultProcessingExecution; | ||
|
@@ -41,7 +42,8 @@ | |
public abstract class AbstractReactiveCouchbaseQuery extends AbstractCouchbaseQueryBase<ReactiveCouchbaseOperations> | ||
implements RepositoryQuery { | ||
|
||
private final ReactiveFindByQuery<?> findOperationWithProjection; | ||
private final ReactiveFindByQuery<?> findOp; | ||
private final ReactiveRemoveByQuery<?> removeOp; | ||
|
||
/** | ||
* Creates a new {@link AbstractReactiveCouchbaseQuery} from the given {@link ReactiveCouchbaseQueryMethod} and | ||
|
@@ -62,9 +64,10 @@ public AbstractReactiveCouchbaseQuery(ReactiveCouchbaseQueryMethod method, React | |
|
||
EntityMetadata<?> metadata = method.getEntityInformation(); | ||
Class<?> type = metadata.getJavaType(); | ||
ReactiveFindByQuery<?> findOp = operations.findByQuery(type); | ||
findOp = (ReactiveFindByQuery<?>) (findOp.inScope(method.getScope()).inCollection(method.getCollection())); | ||
this.findOperationWithProjection = findOp; | ||
this.findOp = (ReactiveFindByQuery<?>) (operations.findByQuery(type).inScope(method.getScope()) | ||
.inCollection(method.getCollection())); | ||
this.removeOp = (ReactiveRemoveByQuery<?>) (operations.removeByQuery(type).inScope(method.getScope()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can it be casted to findBy and RemoveBy at the same time? |
||
.inCollection(method.getCollection())); | ||
} | ||
|
||
/** | ||
|
@@ -83,10 +86,8 @@ protected Object doExecute(CouchbaseQueryMethod method, ResultProcessor processo | |
// query = applyAnnotatedCollationIfPresent(query, accessor); // not yet implemented | ||
query = applyQueryMetaAttributesIfPresent(query, typeToRead); | ||
|
||
ReactiveFindByQuery<?> find = findOperationWithProjection; | ||
|
||
ReactiveCouchbaseQueryExecution execution = getExecution(accessor, | ||
new ResultProcessingConverter<>(processor, getOperations(), getInstantiators()), find); | ||
new ResultProcessingConverter<>(processor, getOperations(), getInstantiators()), findOp); | ||
return execution.execute(query, processor.getReturnedType().getDomainType(), typeToRead, null); | ||
} | ||
|
||
|
@@ -113,7 +114,7 @@ private ReactiveCouchbaseQueryExecution getExecutionToWrap(ParameterAccessor acc | |
ReactiveFindByQuery<?> operation) { | ||
|
||
if (isDeleteQuery()) { | ||
return new DeleteExecution(getOperations(), getQueryMethod()); | ||
return new DeleteExecution(removeOp); | ||
} else if (isTailable(getQueryMethod())) { | ||
return (q, t, r, c) -> operation.as(r).matching(q.with(accessor.getPageable())).all(); // s/b tail() instead of | ||
// all() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2022 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.couchbase.domain; | ||
|
||
import org.springframework.data.couchbase.repository.Collection; | ||
|
||
/** | ||
* AirportRepository with collection annotation | ||
* | ||
* @author Michael Reiche | ||
*/ | ||
@Collection("my_collection2") | ||
public interface AirportRepositoryAnnotated extends AirportRepository {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2022 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.couchbase.domain; | ||
|
||
import org.springframework.data.couchbase.repository.Collection; | ||
|
||
/** | ||
* AirportRepository with collection annotation | ||
* | ||
* @author Michael Reiche | ||
*/ | ||
@Collection("my_collection2") | ||
public interface ReactiveAirportRepositoryAnnotated extends ReactiveAirportRepository{} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,7 @@ public class ReactiveCouchbaseRepositoryKeyValueIntegrationTests extends Cluster | |
|
||
@Autowired ReactiveUserRepository userRepository; | ||
|
||
@Autowired ReactiveAirportRepository airportRepository; | ||
@Autowired ReactiveAirportRepository reactiveAirportRepository; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to rename the ReactiveAiportRepository to exactly match the bean-name for disambiguation - as the ReactiveAirportRepositoryAnnotated is also a ReactiveAirportRepository. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
@Autowired ReactiveAirlineRepository airlineRepository; | ||
|
||
|
@@ -108,13 +108,13 @@ void findByIdAudited() { | |
Airport vie = null; | ||
try { | ||
vie = new Airport("airports::vie", "vie", "low2"); | ||
Airport saved = airportRepository.save(vie).block(); | ||
Airport airport1 = airportRepository.findById(saved.getId()).block(); | ||
Airport saved = reactiveAirportRepository.save(vie).block(); | ||
Airport airport1 = reactiveAirportRepository.findById(saved.getId()).block(); | ||
assertEquals(airport1, saved); | ||
assertEquals(saved.getCreatedBy(), ReactiveNaiveAuditorAware.AUDITOR); // ReactiveNaiveAuditorAware will provide | ||
// this | ||
} finally { | ||
airportRepository.delete(vie).block(); | ||
reactiveAirportRepository.delete(vie).block(); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as comment below, is it possible that not both casts are possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand the comment correctly - both are fine. the first one is operations.findByQuery(), the second is operations.removeByQuery(). I'm actually not sure why a cast is even required - because ExecutableRemoveByQuery (eventually) extends the type returned by withCollection() (RemoveByQueryWithOptions).