Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/querydsl-5.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
velo committed Aug 2, 2024
2 parents 7218ed2 + 7ccfbfc commit 5907637
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 54 deletions.
8 changes: 4 additions & 4 deletions querydsl-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
<packaging>pom</packaging>
<name>Querydsl - Examples</name>

<properties>
<main.java.version>17</main.java.version>
</properties>

<modules>
<module>querydsl-example-sql-guice</module>
<module>querydsl-example-sql-spring</module>
Expand All @@ -31,6 +27,10 @@
<module>querydsl-example-r2dbc-sql-codegen</module>
</modules>

<properties>
<main.java.version>17</main.java.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
package com.querydsl.core.group;

import com.querydsl.core.FetchableQuery;
import com.querydsl.core.Tuple;
import com.querydsl.core.types.Expression;
import com.querydsl.core.types.FactoryExpression;
import com.querydsl.core.types.FactoryExpressionUtils;
import com.querydsl.core.types.Projections;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects;
import java.util.Map;

/**
* Provides aggregated results as a list
Expand All @@ -32,44 +29,27 @@
*/
public class GroupByList<K, V> extends AbstractGroupByTransformer<K, List<V>> {

private final GroupByMap<K, V> mapTransformer;

GroupByList(Expression<K> key, Expression<?>... expressions) {
super(key, expressions);
mapTransformer =
new GroupByMap<K, V>(key, expressions) {
@Override
protected Map<K, V> transform(Map<K, Group> groups) {
var results = new LinkedHashMap<K, V>((int) Math.ceil(groups.size() / 0.75), 0.75f);
for (var entry : groups.entrySet()) {
results.put(entry.getKey(), GroupByList.this.transform(entry.getValue()));
}
return results;
}
};
}

@Override
public List<V> transform(FetchableQuery<?, ?> query) {
// create groups
FactoryExpression<Tuple> expr = FactoryExpressionUtils.wrap(Projections.tuple(expressions));
var hasGroups = false;
for (Expression<?> e : expr.getArgs()) {
hasGroups |= e instanceof GroupExpression;
}
if (hasGroups) {
expr = withoutGroupExpressions(expr);
}
final var iter = query.select(expr).iterate();

List<V> list = new ArrayList<>();
GroupImpl group = null;
K groupId = null;
while (iter.hasNext()) {
@SuppressWarnings("unchecked") // This type is mandated by the key type
var row = (K[]) iter.next().toArray();
if (group == null) {
group = new GroupImpl(groupExpressions, maps);
groupId = row[0];
} else if (!Objects.equals(groupId, row[0])) {
list.add(transform(group));
group = new GroupImpl(groupExpressions, maps);
groupId = row[0];
}
group.add(row);
}
if (group != null) {
list.add(transform(group));
}
iter.close();
return list;
var result = mapTransformer.transform(query);
return new ArrayList<V>(result.values());
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public T newInstance(Object... args) {
}

private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
ois.readObject();
ois.defaultReadObject();
try {
var constructor = ConstructorExpression.class.getDeclaredField("constructor");
constructor.setAccessible(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,43 @@ public void map3() {

Object postId = null;
Map<Integer, Map<Integer, String>> posts = null;
List<Map<Integer, Map<Integer, String>>> expected = new LinkedList<>();
var expected = new LinkedList<Map<Integer, Map<Integer, String>>>();
for (Iterator<Tuple> iterator = MAP3_RESULTS.iterate(); iterator.hasNext(); ) {
var tuple = iterator.next();
var array = tuple.toArray();

if (posts == null || !(postId == array[0] || postId != null && postId.equals(array[0]))) {
posts = new LinkedHashMap<>();
expected.add(posts);
posts = findPostsById(expected, array[0]);
if (posts == null) {
posts = new LinkedHashMap<Integer, Map<Integer, String>>();
expected.add(posts);
}
}
postId = array[0];
@SuppressWarnings("unchecked")
var pair = (Pair<Integer, Pair<Integer, String>>) array[1];
var first = pair.getFirst();
var comments = posts.computeIfAbsent(first, k -> new LinkedHashMap<Integer, String>());
var comments = posts.get(first);
if (comments == null) {
comments = new LinkedHashMap<Integer, String>();
posts.put(first, comments);
}
var second = pair.getSecond();
comments.put(second.getFirst(), second.getSecond());
}
assertThat(actual).hasToString(expected.toString());
}

private Map<Integer, Map<Integer, String>> findPostsById(
List<Map<Integer, Map<Integer, String>>> allPosts, Object postId) {
for (var posts : allPosts) {
if (posts.containsKey(postId)) {
return posts;
}
}
return null;
}

@Override
@Test
public void map4() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,18 @@ public void serializability() {
@Test
public void threadSafety() {
final ConstructorExpression<String> expr = Projections.constructor(String.class);
Runnable invoker =
new Runnable() {
@Override
public void run() {
expr.newInstance();
}
};
Runnable invoker = () -> expr.newInstance();
ThreadSafety.check(invoker, invoker);
}

@Test
public void constructorArgsShouldBeSerialized() {
var longArg = ConstantImpl.create(1L);
var stringArg = ConstantImpl.create("");
var projection =
new ConstructorExpression<ProjectionExample>(
ProjectionExample.class, new Class<?>[] {long.class, String.class}, longArg, stringArg);
var deserializationResult = Serialization.serialize(projection);
assertThat(deserializationResult).isEqualTo(projection);
}
}
1 change: 0 additions & 1 deletion querydsl-tooling/querydsl-kotlin-codegen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<version>2.0.1</version>
</dependency>

<dependency>
Expand Down

0 comments on commit 5907637

Please sign in to comment.