Skip to content

Commit b417c0e

Browse files
committed
Merge remote-tracking branch 'origin/master' into querydsl-7.0
2 parents 27c49e9 + e9c767c commit b417c0e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+356
-299
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ jobs:
292292
working_directory: ~/querydsl
293293
docker:
294294
- image: velo/toolchains-4-ci-builds:latest
295-
- image: mongo:3.6.1
295+
- image: mongo:8.0.9
296296
steps:
297297
- checkout
298298
- restore_cache:

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ services:
5656
start_period: 60s
5757

5858
mongo:
59-
image: mongo:4
59+
image: mongo:8.0.9
6060
ports:
6161
- "27017:27017"
6262

pom.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@
116116
<hsqldb.version>2.7.4</hsqldb.version>
117117
<h2.version>2.3.232</h2.version>
118118
<postgresql.version>42.7.5</postgresql.version>
119-
<oracle.version>23.7.0.25.01</oracle.version>
119+
<oracle.version>23.8.0.25.04</oracle.version>
120120
<mysql.version>9.3.0</mysql.version>
121121
<mssql.version>12.10.0.jre8</mssql.version>
122122
<cubrid.version>9.3.9.0002</cubrid.version>
123123
<sqlite.version>3.49.1.0</sqlite.version>
124124
<teradata.version>13.10.00.35</teradata.version>
125125
<firebird.version>5.0.7.java11</firebird.version>
126-
<mongodb.version>3.12.14</mongodb.version>
126+
<mongodb.version>5.5.0</mongodb.version>
127127

128128
<r2dbc.version>1.0.0.RELEASE</r2dbc.version>
129129

@@ -143,7 +143,7 @@
143143
<surefire.version>3.5.3</surefire.version>
144144
<animal-sniffer.version>1.24</animal-sniffer.version>
145145
<h2gis.version>2.2.3</h2gis.version>
146-
<morphia.version>1.3.2</morphia.version>
146+
<morphia.version>2.5.0</morphia.version>
147147
<jmh.version>1.37</jmh.version>
148148
<kotlin.version>2.1.20</kotlin.version>
149149
<ksp.version>2.1.20-2.0.1</ksp.version>
@@ -456,7 +456,7 @@
456456
<configuration>
457457
<parameter>
458458
<excludes>
459-
<exclude>com.querydsl.core.annotations.QueryProjection</exclude>
459+
<exclude>com.querydsl.core.annotations.QueryProjection</exclude>
460460
</excludes>
461461
<ignoreMissingOldVersion>true</ignoreMissingOldVersion>
462462
<onlyModified>true</onlyModified>
@@ -1037,18 +1037,18 @@
10371037
<plugin>
10381038
<groupId>org.openrewrite.maven</groupId>
10391039
<artifactId>rewrite-maven-plugin</artifactId>
1040-
<version>6.7.0</version>
1040+
<version>6.8.0</version>
10411041

10421042
<dependencies>
10431043
<dependency>
10441044
<groupId>org.openrewrite.recipe</groupId>
10451045
<artifactId>rewrite-testing-frameworks</artifactId>
1046-
<version>3.7.0</version>
1046+
<version>3.8.0</version>
10471047
</dependency>
10481048
<dependency>
10491049
<groupId>org.openrewrite.recipe</groupId>
10501050
<artifactId>rewrite-migrate-java</artifactId>
1051-
<version>3.8.0</version>
1051+
<version>3.9.0</version>
10521052
</dependency>
10531053
</dependencies>
10541054

querydsl-examples/querydsl-example-jpa-quarkus/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<name>Querydsl example - JPA Quarkus</name>
1313

1414
<properties>
15-
<quarkus.version>3.22.1</quarkus.version>
15+
<quarkus.version>3.22.2</quarkus.version>
1616
</properties>
1717

1818
<dependencyManagement>

querydsl-libraries/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
<exclude>org.hibernate:hibernate-envers:*:*:compile</exclude>
9999
<exclude>org.hibernate.validator:hibernate-validator:*:*:compile</exclude>
100100
<exclude>org.eclipse.persistence:eclipselink:*:*:compile</exclude>
101-
<exclude>org.mongodb.morphia:morphia:*:*:compile</exclude>
101+
<exclude>dev.morphia:core:*:*:compile</exclude>
102102
<exclude>org.joda:joda-money:*:*:compile</exclude>
103103
<exclude>org.batoo.jpa:batoo-jpa:*:*:compile</exclude>
104104
<exclude>jakarta.annotation:jakarta.annotation-api:*:*:compile</exclude>

querydsl-libraries/querydsl-mongodb/pom.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
<description>Mongodb support for Querydsl</description>
1414

1515
<properties>
16+
<japicmp.skip>true</japicmp.skip>
1617
<osgi.import.package>com.mongodb;version="0.0.0",
17-
org.mongodb.morphia.*;version="1.3.2",
18+
dev.morphia.*;version="1.6.1",
1819
org.bson.*;version="0.0.0",
1920
${osgi.import.package.root}</osgi.import.package>
2021
</properties>
@@ -27,12 +28,17 @@
2728
</dependency>
2829
<dependency>
2930
<groupId>org.mongodb</groupId>
30-
<artifactId>mongo-java-driver</artifactId>
31+
<artifactId>mongodb-driver-sync</artifactId>
3132
<version>${mongodb.version}</version>
3233
</dependency>
3334
<dependency>
34-
<groupId>org.mongodb.morphia</groupId>
35-
<artifactId>morphia</artifactId>
35+
<groupId>org.mongodb</groupId>
36+
<artifactId>mongodb-driver-legacy</artifactId>
37+
<version>${mongodb.version}</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>dev.morphia.morphia</groupId>
41+
<artifactId>morphia-core</artifactId>
3642
<version>${morphia.version}</version>
3743
<scope>provided</scope>
3844
<optional>true</optional>

querydsl-libraries/querydsl-mongodb/src/main/java/com/querydsl/mongodb/AbstractMongodbQuery.java

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
package com.querydsl.mongodb;
1515

1616
import com.mongodb.BasicDBObject;
17-
import com.mongodb.DBCollection;
18-
import com.mongodb.DBCursor;
19-
import com.mongodb.DBObject;
2017
import com.mongodb.ReadPreference;
18+
import com.mongodb.client.FindIterable;
19+
import com.mongodb.client.MongoCollection;
2120
import com.querydsl.core.CloseableIterator;
2221
import com.querydsl.core.DefaultQueryMetadata;
2322
import com.querydsl.core.Fetchable;
@@ -44,6 +43,7 @@
4443
import java.util.List;
4544
import java.util.Map;
4645
import java.util.function.Function;
46+
import org.bson.conversions.Bson;
4747
import org.jetbrains.annotations.Nullable;
4848

4949
/**
@@ -64,22 +64,22 @@ private static class NoResults extends RuntimeException {}
6464

6565
private final QueryMixin<Q> queryMixin;
6666

67-
private final DBCollection collection;
67+
private final MongoCollection collection;
6868

69-
private final Function<DBObject, K> transformer;
69+
private final Function<K, Object> transformer;
7070

7171
private ReadPreference readPreference;
7272

7373
/**
7474
* Create a new MongodbQuery instance
7575
*
7676
* @param collection collection
77-
* @param transformer result transformer
77+
* @param transformer id transformer
7878
* @param serializer serializer
7979
*/
8080
@SuppressWarnings("unchecked")
8181
public AbstractMongodbQuery(
82-
DBCollection collection, Function<DBObject, K> transformer, MongodbSerializer serializer) {
82+
MongoCollection collection, Function<K, Object> transformer, MongodbSerializer serializer) {
8383
@SuppressWarnings("unchecked") // Q is this plus subclass
8484
var query = (Q) this;
8585
this.queryMixin = new QueryMixin<>(query, new DefaultQueryMetadata(), false);
@@ -122,7 +122,7 @@ public <T> AnyEmbeddedBuilder<Q, K> anyEmbedded(
122122
return new AnyEmbeddedBuilder<>(queryMixin, collection);
123123
}
124124

125-
protected abstract DBCollection getCollection(Class<?> type);
125+
protected abstract MongoCollection getCollection(Class<?> type);
126126

127127
@Nullable
128128
protected Predicate createFilter(QueryMetadata metadata) {
@@ -164,16 +164,15 @@ protected List<Object> getIds(Class<?> targetType, Predicate condition) {
164164
// TODO : fetch only ids
165165
var cursor =
166166
createCursor(
167-
collection,
168-
condition,
169-
null,
170-
QueryModifiers.EMPTY,
171-
Collections.<OrderSpecifier<?>>emptyList());
167+
collection,
168+
condition,
169+
null,
170+
QueryModifiers.EMPTY,
171+
Collections.<OrderSpecifier<?>>emptyList())
172+
.cursor();
172173
if (cursor.hasNext()) {
173-
List<Object> ids = new ArrayList<>(cursor.count());
174-
for (DBObject obj : cursor) {
175-
ids.add(obj.get("_id"));
176-
}
174+
List<Object> ids = new ArrayList<>();
175+
cursor.forEachRemaining(document -> ids.add(transformer.apply(document)));
177176
return ids;
178177
} else {
179178
return Collections.emptyList();
@@ -236,7 +235,7 @@ public CloseableIterator<K> iterate(Path<?>... paths) {
236235

237236
@Override
238237
public CloseableIterator<K> iterate() {
239-
final var cursor = createCursor();
238+
final var cursor = createCursor().cursor();
240239
return new CloseableIterator<>() {
241240
@Override
242241
public boolean hasNext() {
@@ -245,7 +244,7 @@ public boolean hasNext() {
245244

246245
@Override
247246
public K next() {
248-
return transformer.apply(cursor.next());
247+
return cursor.next();
249248
}
250249

251250
@Override
@@ -272,16 +271,16 @@ public List<K> fetch() {
272271
try {
273272
var cursor = createCursor();
274273
List<K> results = new ArrayList<>();
275-
for (DBObject dbObject : cursor) {
276-
results.add(transformer.apply(dbObject));
274+
for (K dbObject : cursor) {
275+
results.add(dbObject);
277276
}
278277
return results;
279278
} catch (NoResults ex) {
280279
return Collections.emptyList();
281280
}
282281
}
283282

284-
protected DBCursor createCursor() {
283+
protected FindIterable<K> createCursor() {
285284
var metadata = queryMixin.getMetadata();
286285
Predicate filter = createFilter(metadata);
287286
return createCursor(
@@ -292,13 +291,19 @@ protected DBCursor createCursor() {
292291
metadata.getOrderBy());
293292
}
294293

295-
protected DBCursor createCursor(
296-
DBCollection collection,
294+
protected FindIterable<K> createCursor(
295+
MongoCollection collection,
297296
@Nullable Predicate where,
298297
Expression<?> projection,
299298
QueryModifiers modifiers,
300299
List<OrderSpecifier<?>> orderBy) {
301-
var cursor = collection.find(createQuery(where), createProjection(projection));
300+
var cursor =
301+
readPreference != null
302+
? collection
303+
.withReadPreference(readPreference)
304+
.find(createQuery(where))
305+
.projection(createProjection(projection))
306+
: collection.find(createQuery(where)).projection(createProjection(projection));
302307
Integer limit = modifiers.getLimitAsInteger();
303308
Integer offset = modifiers.getOffsetAsInteger();
304309
if (limit != null) {
@@ -310,15 +315,12 @@ protected DBCursor createCursor(
310315
if (orderBy.size() > 0) {
311316
cursor.sort(serializer.toSort(orderBy));
312317
}
313-
if (readPreference != null) {
314-
cursor.setReadPreference(readPreference);
315-
}
316318
return cursor;
317319
}
318320

319-
private DBObject createProjection(Expression<?> projection) {
321+
private Bson createProjection(Expression<?> projection) {
320322
if (projection instanceof FactoryExpression) {
321-
DBObject obj = new BasicDBObject();
323+
var obj = new BasicDBObject();
322324
for (Object expr : ((FactoryExpression) projection).getArgs()) {
323325
if (expr instanceof Expression) {
324326
obj.put((String) serializer.handle((Expression) expr), 1);
@@ -343,9 +345,9 @@ public K fetchFirst(Path<?>... paths) {
343345
@Override
344346
public K fetchFirst() {
345347
try {
346-
var c = createCursor().limit(1);
348+
var c = createCursor().limit(1).cursor();
347349
if (c.hasNext()) {
348-
return transformer.apply(c.next());
350+
return c.next();
349351
} else {
350352
return null;
351353
}
@@ -372,9 +374,9 @@ public K fetchOne() throws NonUniqueResultException {
372374
if (limit == null) {
373375
limit = 2L;
374376
}
375-
var c = createCursor().limit(limit.intValue());
377+
var c = createCursor().limit(limit.intValue()).cursor();
376378
if (c.hasNext()) {
377-
var rv = transformer.apply(c.next());
379+
var rv = c.next();
378380
if (c.hasNext()) {
379381
throw new NonUniqueResultException();
380382
}
@@ -416,15 +418,15 @@ public QueryResults<K> fetchResults() {
416418
public long fetchCount() {
417419
try {
418420
Predicate filter = createFilter(queryMixin.getMetadata());
419-
return collection.count(createQuery(filter));
421+
return collection.countDocuments(createQuery(filter));
420422
} catch (NoResults ex) {
421423
return 0L;
422424
}
423425
}
424426

425-
private DBObject createQuery(@Nullable Predicate predicate) {
427+
private Bson createQuery(@Nullable Predicate predicate) {
426428
if (predicate != null) {
427-
return (DBObject) serializer.handle(predicate);
429+
return (Bson) serializer.handle(predicate);
428430
} else {
429431
return new BasicDBObject();
430432
}
@@ -444,7 +446,7 @@ public void setReadPreference(ReadPreference readPreference) {
444446
*
445447
* @return
446448
*/
447-
public DBObject asDBObject() {
449+
public Bson asDBObject() {
448450
return createQuery(queryMixin.getMetadata().getWhere());
449451
}
450452

querydsl-libraries/querydsl-mongodb/src/main/java/com/querydsl/mongodb/MongodbSerializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.Map;
3939
import java.util.regex.Pattern;
4040
import org.bson.BSONObject;
41+
import org.bson.conversions.Bson;
4142
import org.bson.types.ObjectId;
4243

4344
/**
@@ -52,7 +53,7 @@ public Object handle(Expression<?> expression) {
5253
return expression.accept(this, null);
5354
}
5455

55-
public DBObject toSort(List<OrderSpecifier<?>> orderBys) {
56+
public Bson toSort(List<OrderSpecifier<?>> orderBys) {
5657
var sort = new BasicDBObject();
5758
for (OrderSpecifier<?> orderBy : orderBys) {
5859
Object key = orderBy.getTarget().accept(this, null);

querydsl-libraries/querydsl-mongodb/src/main/java/com/querydsl/mongodb/document/AbstractFetchableMongodbQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public QueryResults<K> fetchResults() {
227227
public long fetchCount() {
228228
try {
229229
Predicate filter = createFilter(getQueryMixin().getMetadata());
230-
return collection.count(createQuery(filter));
230+
return collection.countDocuments(createQuery(filter));
231231
} catch (NoResults ex) {
232232
return 0L;
233233
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.querydsl.mongodb.document;
2+
3+
import dev.morphia.Datastore;
4+
import dev.morphia.mapping.Mapper;
5+
import dev.morphia.mapping.codec.writer.DocumentWriter;
6+
import org.bson.Document;
7+
import org.bson.codecs.configuration.CodecRegistry;
8+
9+
public class DocumentUtils {
10+
public static Document getAsDocument(Datastore morphia, Object value) {
11+
Mapper mapper = morphia.getMapper();
12+
CodecRegistry codecRegistry = morphia.getCodecRegistry();
13+
return DocumentWriter.encode(value, mapper, codecRegistry);
14+
}
15+
}

0 commit comments

Comments
 (0)