Skip to content

Commit

Permalink
Merge branch 'querydsl-7.0' into maven-4
Browse files Browse the repository at this point in the history
  • Loading branch information
velo authored Dec 13, 2024
2 parents cbd056c + c7aff10 commit eafd715
Show file tree
Hide file tree
Showing 168 changed files with 324 additions and 12,076 deletions.
8 changes: 5 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
</distributionManagement>

<properties>
<!-- removing old modules on 7.0 release -->
<japicmp.skip>true</japicmp.skip>

<failIfNoTests>false</failIfNoTests>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.homepage>http://www.querydsl.com</project.homepage>
Expand All @@ -105,7 +108,7 @@
<ecj.version>3.33.0</ecj.version>
<jdo.version>3.2.1</jdo.version>
<springboot.version>3.4.0</springboot.version>
<spring.version>6.2.0</spring.version>
<spring.version>6.2.1</spring.version>

<!-- SQL deps -->
<db2.version>12.1.0.0</db2.version>
Expand Down Expand Up @@ -135,7 +138,6 @@
<mvn.version>4.0.0-rc-1</mvn.version>
<guava.version>33.3.1-jre</guava.version>
<codegen.version>0.6.8</codegen.version>
<mysema.lang.version>0.2.4</mysema.lang.version>
<byte-buddy.version>1.15.10</byte-buddy.version>
<slf4j.version>2.0.16</slf4j.version>
<surefire.version>3.5.2</surefire.version>
Expand Down Expand Up @@ -1009,7 +1011,7 @@
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>5.46.2</version>
<version>5.46.3</version>

<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
package com.querydsl.example.ksp

import jakarta.persistence.Entity
import jakarta.persistence.Enumerated
import jakarta.persistence.EnumType
import jakarta.persistence.Id
import jakarta.persistence.ManyToOne

@Entity
class Cat(
@Id
val id: Int,
val name: String,
val isTailUpright: Boolean
val isTailUpright: Boolean,
val fluffiness: String? = null,

@ManyToOne
val owner: Person? = null,

@Enumerated(EnumType.STRING)
val catType: CatType? = CatType.HOUSE,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.querydsl.example.ksp

enum class CatType {
HOUSE,
MAINE_COON
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package com.querydsl.example.ksp

import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.OneToMany

@Entity
class Person(
@Id
val id: Int,
val name: String,

@OneToMany(mappedBy = "owner")
val cats: List<Cat>? = null,
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import com.querydsl.example.ksp.Cat
import com.querydsl.example.ksp.CatType
import com.querydsl.example.ksp.Person
import com.querydsl.example.ksp.QCat
import com.querydsl.example.ksp.QPerson
Expand Down Expand Up @@ -40,15 +41,48 @@ class Tests {
}
}

@Test
fun `create cat with owner` () {
val emf = initialize()

run {
val em = emf.createEntityManager()
em.transaction.begin()
val catOwner = Person(425, "Percy Bysshe Catownerly")
em.persist(catOwner)
em.persist(Cat(103, "Samuel Taylor Cattingridge", false, "Not so fluffy", catOwner, CatType.MAINE_COON))
em.transaction.commit()
em.close()
}

run {
val em = emf.createEntityManager()
val queryFactory = JPAQueryFactory(em)
val q = QCat.cat
val catWithOwner = queryFactory
.selectFrom(q)
.where(q.name.eq("Samuel Taylor Cattingridge"))
.fetchOne()
if (catWithOwner == null) {
fail<Any>("No owned cat was returned")
} else {
assertThat(catWithOwner.id).isEqualTo(103)
assertThat(catWithOwner.catType).isEqualTo(CatType.MAINE_COON)
assertThat(catWithOwner.owner?.id).isEqualTo(425)
}
em.close()
}
}

@Test
fun `filter entities`() {
val emf = initialize()

run {
val em = emf.createEntityManager()
em.transaction.begin()
em.persist(Cat(100, "Neville Furbottom", true))
em.persist(Cat(101, "Edgar Allan Paw", true))
em.persist(Cat(100, "Neville Furbottom", true, "Quite Fluffy"))
em.persist(Cat(101, "Edgar Allan Paw", true, null))
em.persist(Cat(102, "Admiral Meowington", false))
em.transaction.commit()
em.close()
Expand All @@ -66,6 +100,13 @@ class Tests {
assertThat(animals.size).isEqualTo(2)
assertThat(animals).contains("Neville Furbottom")
assertThat(animals).contains("Edgar Allan Paw")
val quiteFluffyAnimals = queryFactory
.selectFrom(q)
.where(q.fluffiness.eq("Quite Fluffy"))
.fetch()
.map { it.name }
assertThat(quiteFluffyAnimals.size).isEqualTo(1)
assertThat(quiteFluffyAnimals).contains("Neville Furbottom")
em.close()
}
}
Expand Down
5 changes: 3 additions & 2 deletions querydsl-libraries/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@
<exclude>org.hibernate:hibernate-envers:*:*:compile</exclude>
<exclude>org.hibernate.validator:hibernate-validator:*:*:compile</exclude>
<exclude>org.eclipse.persistence:eclipselink:*:*:compile</exclude>
<exclude>org.datanucleus:javax.jdo:*:*:compile</exclude>
<exclude>org.springframework.roo:org.springframework.roo.annotations:*:*:compile</exclude>
<exclude>org.mongodb.morphia:morphia:*:*:compile</exclude>
<exclude>org.joda:joda-money:*:*:compile</exclude>
<exclude>org.batoo.jpa:batoo-jpa:*:*:compile</exclude>
Expand All @@ -112,6 +110,9 @@
<exclude>jakarta.xml.bind:jakarta.xml.bind-api:*:*:compile</exclude>
<!-- Ban any API's that were moved to jakarta -->
<exclude>javax.*:*:*:*:*</exclude>
<!-- Ban libraries that support was dropped -->
<exclude>org.datanucleus:javax.jdo:*:*:*</exclude>
<exclude>org.springframework.roo:org.springframework.roo.annotations:*:*:compile</exclude>
<!-- The following database drivers should be in test scope -->
<exclude>org.hsqldb:hsqldb:*:*:compile</exclude>
<exclude>com.h2database:h2:*:*:compile</exclude>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
*/
package com.querydsl.collections;

import com.mysema.commons.lang.CloseableIterator;
import com.mysema.commons.lang.IteratorAdapter;
import com.querydsl.core.CloseableIterator;
import com.querydsl.core.FetchableQuery;
import com.querydsl.core.JoinType;
import com.querydsl.core.NonUniqueResultException;
Expand Down Expand Up @@ -180,7 +179,7 @@ public <P> Q leftJoin(MapExpression<?, P> target, Path<P> alias) {
public CloseableIterator<T> iterate() {
@SuppressWarnings("unchecked") // This is the built type
var projection = (Expression<T>) queryMixin.getMetadata().getProjection();
return new IteratorAdapter<>(fetch().iterator());
return CloseableIterator.of(fetch().iterator());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
*/
package com.querydsl.collections;

import com.mysema.commons.lang.IteratorAdapter;
import com.querydsl.codegen.utils.Evaluator;
import com.querydsl.core.CloseableIterator;
import com.querydsl.core.JoinExpression;
import com.querydsl.core.JoinType;
import com.querydsl.core.QueryMetadata;
Expand Down Expand Up @@ -166,7 +166,7 @@ private List evaluateSingleSource(
if (iterable instanceof List<?> list1) {
list = list1;
} else {
list = IteratorAdapter.asList(iterable.iterator());
list = CloseableIterator.asList(iterable.iterator());
}

// from & where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;

import com.mysema.commons.lang.CloseableIterator;
import com.querydsl.core.CloseableIterator;
import com.querydsl.core.FetchableQuery;
import com.querydsl.core.ResultTransformer;
import com.querydsl.core.annotations.QueryEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.mysema.commons.lang.IteratorAdapter;
import com.querydsl.core.CloseableIterator;
import com.querydsl.core.QueryModifiers;
import com.querydsl.core.QueryResults;
import com.querydsl.core.types.dsl.Expressions;
Expand Down Expand Up @@ -55,7 +55,8 @@ private void assertResultSize(int total, int size, QueryModifiers modifiers) {
assertThat(createQuery(modifiers).fetchCount()).isEqualTo(total);

// via iterator
assertThat(IteratorAdapter.asList(createQuery(modifiers).select(var).iterate())).hasSize(size);
assertThat(CloseableIterator.asList(createQuery(modifiers).select(var).iterate()))
.hasSize(size);
}

private CollQuery<?> createQuery(QueryModifiers modifiers) {
Expand Down
5 changes: 0 additions & 5 deletions querydsl-libraries/querydsl-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
<artifactId>annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mysema.commons</groupId>
<artifactId>mysema-commons-lang</artifactId>
<version>${mysema.lang.version}</version>
</dependency>
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.querydsl.core;

import java.util.Iterator;
import java.util.List;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

public interface CloseableIterator<T> extends Iterator<T>, AutoCloseable {

@Override
void close();

public static <E> List<E> asList(CloseableIterator<E> iterator) {
try (iterator) {
return StreamSupport.stream(
Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false)
.collect(Collectors.toList());
}
}

public static <E> CloseableIterator<E> of(Iterator<E> iterator) {
return of(iterator, () -> {});
}

public static <E> CloseableIterator<E> of(CloseableIterator<E> iterator) {
return of(iterator, iterator);
}

public static <E> CloseableIterator<E> of(Iterator<E> iterator, AutoCloseable closeable) {
return new CloseableIterator<E>() {

@Override
public boolean hasNext() {
return iterator.hasNext();
}

@Override
public E next() {
return iterator.next();
}

@Override
public void close() {
try {
closeable.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
}

public static <E> List<E> asList(Iterator<E> iterator) {
return asList(of(iterator));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
package com.querydsl.core;

import com.mysema.commons.lang.CloseableIterator;
import java.util.List;
import java.util.Spliterator;
import java.util.Spliterators;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.querydsl.core;

public record Pair<F, S>(F first, S second) {

@Deprecated
public F getFirst() {
return first();
}

@Deprecated
public S getSecond() {
return second();
}

public static <T, U> Pair<T, U> of(T key, U value) {
return new Pair<>(key, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package com.querydsl.core.group;

import com.mysema.commons.lang.Pair;
import com.querydsl.core.Pair;
import java.io.Serial;
import java.util.Comparator;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package com.querydsl.core.group;

import com.mysema.commons.lang.Pair;
import com.querydsl.core.Pair;
import com.querydsl.core.ResultTransformer;
import com.querydsl.core.types.Expression;
import com.querydsl.core.types.Projections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package com.querydsl.core.group;

import com.mysema.commons.lang.CloseableIterator;
import com.querydsl.core.CloseableIterator;
import com.querydsl.core.ResultTransformer;
import com.querydsl.core.types.Expression;
import com.querydsl.core.types.FactoryExpression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import static com.querydsl.core.util.TupleUtils.toTuple;

import com.mysema.commons.lang.CloseableIterator;
import com.querydsl.core.CloseableIterator;
import com.querydsl.core.FetchableQuery;
import com.querydsl.core.Tuple;
import com.querydsl.core.types.Expression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package com.querydsl.core.group;

import com.mysema.commons.lang.Pair;
import com.querydsl.core.Pair;
import com.querydsl.core.types.ConstructorExpression;
import com.querydsl.core.types.Expression;
import java.io.Serial;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
*/
package com.querydsl.core.support;

import com.mysema.commons.lang.CloseableIterator;
import com.mysema.commons.lang.IteratorAdapter;
import com.querydsl.core.CloseableIterator;
import com.querydsl.core.Fetchable;
import com.querydsl.core.FetchableQuery;
import com.querydsl.core.NonUniqueResultException;
Expand All @@ -40,7 +39,7 @@ public FetchableQueryBase(QueryMixin<Q> queryMixin) {

@Override
public List<T> fetch() {
return IteratorAdapter.asList(iterate());
return CloseableIterator.asList(iterate());
}

@Override
Expand Down
Loading

0 comments on commit eafd715

Please sign in to comment.