Skip to content

QuerydslPredicateExecutor Does not Respect collection of the document. #1867

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

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.springframework.data.couchbase.core.CouchbaseOperations;
import org.springframework.data.couchbase.core.ExecutableFindByQueryOperation;
import org.springframework.data.couchbase.core.query.OptionsBuilder;
import org.springframework.data.couchbase.core.query.Query;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
Expand All @@ -42,9 +43,11 @@
import com.querydsl.core.types.Expression;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.Predicate;
import org.springframework.util.StringUtils;

/**
* @author Michael Reiche
* @author Tigran Babloyan
*/
public class SpringDataCouchbaseQuery<T> extends SpringDataCouchbaseQuerySupport<SpringDataCouchbaseQuery<T>>
implements Fetchable<T> {
Expand All @@ -61,7 +64,7 @@ public class SpringDataCouchbaseQuery<T> extends SpringDataCouchbaseQuerySupport
* @param type must not be {@literal null}.
*/
public SpringDataCouchbaseQuery(CouchbaseOperations operations, Class<? extends T> type) {
this(operations, type, DEFAULT_COLLECTION);
this(operations, type, OptionsBuilder.getCollectionFrom(type));
}

/**
Expand Down Expand Up @@ -92,7 +95,7 @@ public SpringDataCouchbaseQuery(CouchbaseOperations operations, Class<? extends
this.couchbaseOperations = operations;
this.queryCustomizer = queryCustomizer;
this.find = (ExecutableFindByQueryOperation.ExecutableFindByQuery<T>) couchbaseOperations.findByQuery(domainType)
.as(resultType1).inCollection(collectionName);
.as(resultType1).inCollection(StringUtils.hasText(collectionName) ? collectionName : DEFAULT_COLLECTION);
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2012-2023 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.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.couchbase.core.index.CompositeQueryIndex;
import org.springframework.data.couchbase.core.index.QueryIndexed;
import org.springframework.data.couchbase.core.mapping.Document;
import org.springframework.data.couchbase.repository.Collection;
import org.springframework.data.couchbase.repository.Scope;
import org.springframework.data.couchbase.util.CollectionAwareDefaultScopeIntegrationTests;

@Document
@Collection(CollectionAwareDefaultScopeIntegrationTests.otherCollection)
@Scope(CollectionAwareDefaultScopeIntegrationTests.otherScope)
public class AirlineCollectioned extends ComparableEntity {
@Id String id;

@QueryIndexed String name;

String hqCountry;

@PersistenceConstructor
public AirlineCollectioned(String id, String name, String hqCountry) {
this.id = id;
this.name = name;
this.hqCountry = hqCountry;
}

public String getId() {
return id;
}

public String getName() {
return name;
}

public String getHqCountry() {
return hqCountry;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2017-2023 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.CouchbaseRepository;
import org.springframework.data.couchbase.repository.DynamicProxyable;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.stereotype.Repository;

/**
* @author Michael Reiche
*/
@Repository
public interface AirlineCollectionedRepository extends CouchbaseRepository<AirlineCollectioned, String>,
QuerydslPredicateExecutor<AirlineCollectioned>, DynamicProxyable<AirlineCollectionedRepository> {
}
Loading