Skip to content

Commit f1df93f

Browse files
babltigamikereiche
authored andcommitted
Fixed issue with querying documents annotated with @Collection with QuerydslPredicateExecutor. (#1867)
Closes #1866
1 parent d73eecd commit f1df93f

File tree

5 files changed

+724
-4
lines changed

5 files changed

+724
-4
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.springframework.data.couchbase.core.CouchbaseOperations;
2828
import org.springframework.data.couchbase.core.ExecutableFindByQueryOperation;
29+
import org.springframework.data.couchbase.core.query.OptionsBuilder;
2930
import org.springframework.data.couchbase.core.query.Query;
3031
import org.springframework.data.domain.Page;
3132
import org.springframework.data.domain.PageImpl;
@@ -42,9 +43,11 @@
4243
import com.querydsl.core.types.Expression;
4344
import com.querydsl.core.types.OrderSpecifier;
4445
import com.querydsl.core.types.Predicate;
46+
import org.springframework.util.StringUtils;
4547

4648
/**
4749
* @author Michael Reiche
50+
* @author Tigran Babloyan
4851
*/
4952
public class SpringDataCouchbaseQuery<T> extends SpringDataCouchbaseQuerySupport<SpringDataCouchbaseQuery<T>>
5053
implements Fetchable<T> {
@@ -61,7 +64,7 @@ public class SpringDataCouchbaseQuery<T> extends SpringDataCouchbaseQuerySupport
6164
* @param type must not be {@literal null}.
6265
*/
6366
public SpringDataCouchbaseQuery(CouchbaseOperations operations, Class<? extends T> type) {
64-
this(operations, type, DEFAULT_COLLECTION);
67+
this(operations, type, OptionsBuilder.getCollectionFrom(type));
6568
}
6669

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

98101
/*
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2012-2023 the original author or authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.couchbase.domain;
17+
18+
import org.springframework.data.annotation.Id;
19+
import org.springframework.data.annotation.PersistenceConstructor;
20+
import org.springframework.data.couchbase.core.index.CompositeQueryIndex;
21+
import org.springframework.data.couchbase.core.index.QueryIndexed;
22+
import org.springframework.data.couchbase.core.mapping.Document;
23+
import org.springframework.data.couchbase.repository.Collection;
24+
import org.springframework.data.couchbase.repository.Scope;
25+
import org.springframework.data.couchbase.util.CollectionAwareDefaultScopeIntegrationTests;
26+
27+
@Document
28+
@Collection(CollectionAwareDefaultScopeIntegrationTests.otherCollection)
29+
@Scope(CollectionAwareDefaultScopeIntegrationTests.otherScope)
30+
public class AirlineCollectioned extends ComparableEntity {
31+
@Id String id;
32+
33+
@QueryIndexed String name;
34+
35+
String hqCountry;
36+
37+
@PersistenceConstructor
38+
public AirlineCollectioned(String id, String name, String hqCountry) {
39+
this.id = id;
40+
this.name = name;
41+
this.hqCountry = hqCountry;
42+
}
43+
44+
public String getId() {
45+
return id;
46+
}
47+
48+
public String getName() {
49+
return name;
50+
}
51+
52+
public String getHqCountry() {
53+
return hqCountry;
54+
}
55+
56+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2017-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.data.couchbase.domain;
18+
19+
import org.springframework.data.couchbase.repository.CouchbaseRepository;
20+
import org.springframework.data.couchbase.repository.DynamicProxyable;
21+
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
22+
import org.springframework.stereotype.Repository;
23+
24+
/**
25+
* @author Michael Reiche
26+
*/
27+
@Repository
28+
public interface AirlineCollectionedRepository extends CouchbaseRepository<AirlineCollectioned, String>,
29+
QuerydslPredicateExecutor<AirlineCollectioned>, DynamicProxyable<AirlineCollectionedRepository> {
30+
}

0 commit comments

Comments
 (0)