Skip to content

Commit c41d710

Browse files
committed
Merge branch 'datacouch_1288_querydsl_support' of github.com:spring-projects/spring-data-couchbase into datacouch_1288_querydsl_support
2 parents 64724cd + 5a8d65c commit c41d710

26 files changed

+570
-448
lines changed

pom.xml

+8-23
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
<couchbase.osgi>3.2.5</couchbase.osgi>
2323
<springdata.commons>2.7.0-SNAPSHOT</springdata.commons>
2424
<java-module-name>spring.data.couchbase</java-module-name>
25-
<apt>1.1.3</apt>
26-
<querydsl>5.0.0</querydsl>
27-
<mysema.querydsl>3.7.4</mysema.querydsl>
2825
</properties>
2926

3027
<dependencyManagement>
@@ -45,6 +42,7 @@
4542
<groupId>com.querydsl</groupId>
4643
<artifactId>querydsl-apt</artifactId>
4744
<version>${querydsl}</version>
45+
<scope>provided</scope>
4846
</dependency>
4947

5048
<dependency>
@@ -170,10 +168,9 @@
170168
<groupId>javax.annotation</groupId>
171169
<artifactId>javax.annotation-api</artifactId>
172170
<version>${javax-annotation-api}</version>
171+
<scope>test</scope>
173172
</dependency>
174173

175-
<!-- -addmods java.annotations.common -->
176-
177174
<dependency>
178175
<groupId>org.apache.openwebbeans</groupId>
179176
<artifactId>openwebbeans-se</artifactId>
@@ -223,6 +220,12 @@
223220
<version>4.0.3</version>
224221
<scope>test</scope>
225222
</dependency>
223+
<dependency>
224+
<groupId>ch.qos.logback</groupId>
225+
<artifactId>logback-classic</artifactId>
226+
<version>1.2.10</version>
227+
<scope>test</scope>
228+
</dependency>
226229

227230
</dependencies>
228231

@@ -333,24 +336,6 @@
333336
</execution>
334337
</executions>
335338
</plugin>
336-
<plugin>
337-
<groupId>org.codehaus.mojo</groupId>
338-
<artifactId>build-helper-maven-plugin</artifactId>
339-
<version>3.0.0</version>
340-
<executions>
341-
<execution>
342-
<phase>generate-test-sources</phase>
343-
<goals>
344-
<goal>add-source</goal>
345-
</goals>
346-
<configuration>
347-
<sources>
348-
<source>target/generated-test-sources</source>
349-
</sources>
350-
</configuration>
351-
</execution>
352-
</executions>
353-
</plugin>
354339
</plugins>
355340
</build>
356341
</project>

src/main/java/com/querydsl/couchbase/document/AbstractCouchbaseQueryDSL.java renamed to src/main/java/com/querydsl/couchbase/document/AbstractCouchbaseQuery.java

+21-29
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222
import java.util.Map;
2323

24+
import com.querydsl.core.types.dsl.CollectionPathBase;
2425
import org.jetbrains.annotations.Nullable;
2526
import org.springframework.data.couchbase.core.mapping.CouchbaseDocument;
2627
import org.springframework.data.couchbase.core.query.QueryCriteriaDefinition;
@@ -47,43 +48,38 @@
4748
* @author Michael Reiche
4849
*/
4950

50-
public abstract class AbstractCouchbaseQueryDSL<Q extends AbstractCouchbaseQueryDSL<Q>> implements SimpleQuery<Q> {
51+
public abstract class AbstractCouchbaseQuery<Q extends AbstractCouchbaseQuery<Q>> implements SimpleQuery<Q> {
5152
private final CouchbaseDocumentSerializer serializer;
5253
private final QueryMixin<Q> queryMixin;// = new QueryMixin(this, new DefaultQueryMetadata(), false);
53-
// TODO private ReadPreference readPreference;
5454

55-
public AbstractCouchbaseQueryDSL(CouchbaseDocumentSerializer serializer) {
55+
public AbstractCouchbaseQuery(CouchbaseDocumentSerializer serializer) {
5656
this.serializer = serializer;
5757
@SuppressWarnings("unchecked") // Q is this plus subclass
5858
Q query = (Q) this;
5959
this.queryMixin = new QueryMixin<Q>(query, new DefaultQueryMetadata(), false);
6060
}
6161

6262
/**
63-
* mongodb uses createQuery(Predicate filter) where the serializer creates the 'query' <br>
64-
* and then uses the result to create a BasicQuery with queryObject = result <br>
6563
* Couchbase Query has a 'criteria' which is a <br>
6664
* List<QueryCriteriaDefinition> criteria <br>
6765
* so we could create a List&lt;QueryCriteriaDefinition&gt; or an uber QueryCriteria that combines <br>
6866
* all the sub QueryDefinitions in the filter.
6967
*/
7068
protected QueryCriteriaDefinition createCriteria(Predicate predicate) {
71-
// mongodb uses createQuery(Predicate filter) where the serializer creates the 'queryObject' of the BasicQuery
7269
return predicate != null ? (QueryCriteriaDefinition) this.serializer.handle(predicate) : null;
7370
}
7471

75-
// TODO - need later
76-
// public <T> JoinBuilder<Q, T> join(Path<T> ref, Path<T> target) {
77-
// return new JoinBuilder(this.queryMixin, ref, target);
78-
// }
72+
public <T> JoinBuilder<Q, T> join(Path<T> ref, Path<T> target) {
73+
return new JoinBuilder(this.queryMixin, ref, target);
74+
}
7975

80-
// public <T> JoinBuilder<Q, T> join(CollectionPathBase<?, T, ?> ref, Path<T> target) {
81-
// return new JoinBuilder(this.queryMixin, ref, target);
82-
// }
76+
public <T> JoinBuilder<Q, T> join(CollectionPathBase<?, T, ?> ref, Path<T> target) {
77+
return new JoinBuilder(this.queryMixin, ref, target);
78+
}
8379

84-
// public <T> AnyEmbeddedBuilder<Q> anyEmbedded(Path<? extends Collection<T>> collection, Path<T> target) {
85-
// return new AnyEmbeddedBuilder(this.queryMixin, collection);
86-
// }
80+
public <T> AnyEmbeddedBuilder<Q> anyEmbedded(Path<? extends Collection<T>> collection, Path<T> target) {
81+
return new AnyEmbeddedBuilder(this.queryMixin, collection);
82+
}
8783

8884
@Nullable
8985
protected Predicate createFilter(QueryMetadata metadata) {
@@ -107,12 +103,13 @@ protected Predicate createJoinFilter(QueryMetadata metadata) {
107103
Path<?> target = (Path) ((Operation) join.getTarget()).getArg(1);
108104
Predicate extraFilters = (Predicate) predicates.get(target.getRoot());
109105
Predicate filter = ExpressionUtils.allOf(new Predicate[] { join.getCondition(), extraFilters });
110-
List<? extends Object> ids = this.getIds(target.getType(), filter);
106+
List<? extends Object> ids = this.getIds(source, target, filter);
111107
if (ids.isEmpty()) {
112-
throw new AbstractCouchbaseQueryDSL.NoResults();
108+
throw new AbstractCouchbaseQuery.NoResults();
113109
}
114110

115-
Path<?> path = ExpressionUtils.path(String.class, source, "$id");
111+
Path<?> path = ExpressionUtils.path(String.class, source, "id");
112+
path = ExpressionUtils.path(String.class, "meta().id");
116113
predicates.merge(source.getRoot(),
117114
ExpressionUtils.in(path, (Collection) ids/* TODO was just ids without casting to Collection */),
118115
ExpressionUtils::and);
@@ -126,7 +123,10 @@ private Predicate allOf(Collection<Predicate> predicates) {
126123
return predicates != null ? ExpressionUtils.allOf(predicates) : null;
127124
}
128125

129-
protected abstract List<Object> getIds(Class<?> var1, Predicate var2);
126+
//protected abstract List<Object> getIds(Class<?> var1, Predicate var2);
127+
128+
protected abstract List<Object> getIds(Path<?> source, Path<?> target, Predicate var2);
129+
130130

131131
public Q distinct() {
132132
return this.queryMixin.distinct();
@@ -182,13 +182,9 @@ protected Map<String, String> createProjection(Expression<?> projection) {
182182
}
183183

184184
protected CouchbaseDocument createQuery(@Nullable Predicate predicate) {
185-
return predicate != null ? (CouchbaseDocument) this.serializer.handle(predicate) : new CouchbaseDocument();
185+
return predicate != null ? new CouchbaseDocument(this.serializer.handle(predicate).toString()) : new CouchbaseDocument();
186186
}
187187

188-
// public void setReadPreference(ReadPreference readPreference) {
189-
// this.readPreference = readPreference;
190-
// }
191-
192188
protected QueryMixin<Q> getQueryMixin() {
193189
return this.queryMixin;
194190
}
@@ -197,10 +193,6 @@ protected CouchbaseDocumentSerializer getSerializer() {
197193
return this.serializer;
198194
}
199195

200-
// protected ReadPreference getReadPreference() {
201-
// return this.readPreference;
202-
// }
203-
204196
public CouchbaseDocument asDocument() {
205197
return this.createQuery(this.queryMixin.getMetadata().getWhere());
206198
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// Source code recreated from a .class file by IntelliJ IDEA
3+
// (powered by FernFlower decompiler)
4+
//
5+
6+
package com.querydsl.couchbase.document;
7+
8+
import com.querydsl.core.support.QueryMixin;
9+
import com.querydsl.core.types.Expression;
10+
import com.querydsl.core.types.ExpressionUtils;
11+
import com.querydsl.core.types.Path;
12+
import com.querydsl.core.types.Predicate;
13+
import java.util.Collection;
14+
15+
public class AnyEmbeddedBuilder<Q extends AbstractCouchbaseQuery<Q>> {
16+
private final QueryMixin<Q> queryMixin;
17+
private final Path<? extends Collection<?>> collection;
18+
19+
public AnyEmbeddedBuilder(QueryMixin<Q> queryMixin, Path<? extends Collection<?>> collection) {
20+
this.queryMixin = queryMixin;
21+
this.collection = collection;
22+
}
23+
24+
public Q on(Predicate... conditions) {
25+
return this.queryMixin.where(ExpressionUtils.predicate(CouchbaseOps.ELEM_MATCH, new Expression[]{this.collection, ExpressionUtils.allOf(conditions)}));
26+
}
27+
}

0 commit comments

Comments
 (0)