diff --git a/pom.xml b/pom.xml index 5ff61c212a..e9e6acc8b4 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 io.github.openfeign.querydsl querydsl-root - 6.11-SNAPSHOT + 7.0-SNAPSHOT pom Querydsl @@ -87,6 +87,9 @@ + + true + false UTF-8 http://www.querydsl.com @@ -96,13 +99,13 @@ -Xms256m -Xmx512m - 11 + 17 21 5.3 5.11.3 - 3.33.0 + 3.40.0 3.2.1 3.4.0 6.2.1 @@ -125,17 +128,16 @@ 1.0.0.RELEASE - 6.6.3.Final + 7.0.0.Beta1 8.0.2.Final - 4.0.4 - 3.1.0 + 5.0.0-B04 + 3.2.0 3.0.0 3.26.3 3.9.9 33.3.1-jre 0.6.8 - 0.2.4 1.15.11 2.0.16 3.5.2 @@ -1055,7 +1057,7 @@ true - org.openrewrite.java.migrate.Java8toJava11 + org.openrewrite.java.migrate.UpgradeToJava17 diff --git a/querydsl-docs/pom.xml b/querydsl-docs/pom.xml index 7d9bce5706..66f4186a73 100644 --- a/querydsl-docs/pom.xml +++ b/querydsl-docs/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-root - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-docs diff --git a/querydsl-examples/pom.xml b/querydsl-examples/pom.xml index 7819583403..0570ef0142 100644 --- a/querydsl-examples/pom.xml +++ b/querydsl-examples/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-root - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-examples @@ -27,10 +27,6 @@ querydsl-example-r2dbc-sql-codegen - - 17 - - diff --git a/querydsl-examples/querydsl-example-jpa-guice/pom.xml b/querydsl-examples/querydsl-example-jpa-guice/pom.xml index b9a0bffa28..2fda34b5de 100644 --- a/querydsl-examples/querydsl-example-jpa-guice/pom.xml +++ b/querydsl-examples/querydsl-example-jpa-guice/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-examples - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-example-jpa-guice diff --git a/querydsl-examples/querydsl-example-jpa-quarkus/pom.xml b/querydsl-examples/querydsl-example-jpa-quarkus/pom.xml index 847819dff2..b6c5e0b056 100644 --- a/querydsl-examples/querydsl-example-jpa-quarkus/pom.xml +++ b/querydsl-examples/querydsl-example-jpa-quarkus/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-examples - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-example-jpa-quarkus diff --git a/querydsl-examples/querydsl-example-jpa-spring/pom.xml b/querydsl-examples/querydsl-example-jpa-spring/pom.xml index d11843b154..fa0270708e 100755 --- a/querydsl-examples/querydsl-example-jpa-spring/pom.xml +++ b/querydsl-examples/querydsl-example-jpa-spring/pom.xml @@ -4,7 +4,7 @@ io.github.openfeign.querydsl querydsl-examples - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-example-jpa-spring diff --git a/querydsl-examples/querydsl-example-kotlin-codegen/pom.xml b/querydsl-examples/querydsl-example-kotlin-codegen/pom.xml index 0fe87b2583..3af4650097 100644 --- a/querydsl-examples/querydsl-example-kotlin-codegen/pom.xml +++ b/querydsl-examples/querydsl-example-kotlin-codegen/pom.xml @@ -4,7 +4,7 @@ io.github.openfeign.querydsl querydsl-examples - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-example-kotlin-codegen Querydsl example - Kotlin Codegen diff --git a/querydsl-examples/querydsl-example-kotlin-jpa/pom.xml b/querydsl-examples/querydsl-example-kotlin-jpa/pom.xml index 5ceef575df..29cf1084d6 100644 --- a/querydsl-examples/querydsl-example-kotlin-jpa/pom.xml +++ b/querydsl-examples/querydsl-example-kotlin-jpa/pom.xml @@ -4,7 +4,7 @@ io.github.openfeign.querydsl querydsl-examples - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-example-kotlin Querydsl example - Kotlin JPA diff --git a/querydsl-examples/querydsl-example-kotlin-mongodb/pom.xml b/querydsl-examples/querydsl-example-kotlin-mongodb/pom.xml index bb2763ffa5..cf737af589 100644 --- a/querydsl-examples/querydsl-example-kotlin-mongodb/pom.xml +++ b/querydsl-examples/querydsl-example-kotlin-mongodb/pom.xml @@ -4,7 +4,7 @@ io.github.openfeign.querydsl querydsl-examples - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-example-kotlin-mongodb Querydsl example - Kotlin MongoDB diff --git a/querydsl-examples/querydsl-example-r2dbc-sql-codegen/pom.xml b/querydsl-examples/querydsl-example-r2dbc-sql-codegen/pom.xml index ab979aad4b..0978f297aa 100644 --- a/querydsl-examples/querydsl-example-r2dbc-sql-codegen/pom.xml +++ b/querydsl-examples/querydsl-example-r2dbc-sql-codegen/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-examples - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-example-r2dbc-sql-codegen diff --git a/querydsl-examples/querydsl-example-sql-guice/pom.xml b/querydsl-examples/querydsl-example-sql-guice/pom.xml index 1956453719..2e59bf51be 100644 --- a/querydsl-examples/querydsl-example-sql-guice/pom.xml +++ b/querydsl-examples/querydsl-example-sql-guice/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-examples - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-example-sql-guice diff --git a/querydsl-examples/querydsl-example-sql-spring/pom.xml b/querydsl-examples/querydsl-example-sql-spring/pom.xml index 971a10c7be..da19927a03 100644 --- a/querydsl-examples/querydsl-example-sql-spring/pom.xml +++ b/querydsl-examples/querydsl-example-sql-spring/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-examples - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-example-sql-spring diff --git a/querydsl-libraries/pom.xml b/querydsl-libraries/pom.xml index 71279261b3..9fa800af9f 100644 --- a/querydsl-libraries/pom.xml +++ b/querydsl-libraries/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-root - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-libraries @@ -98,8 +98,6 @@ org.hibernate:hibernate-envers:*:*:compile org.hibernate.validator:hibernate-validator:*:*:compile org.eclipse.persistence:eclipselink:*:*:compile - org.datanucleus:javax.jdo:*:*:compile - org.springframework.roo:org.springframework.roo.annotations:*:*:compile org.mongodb.morphia:morphia:*:*:compile org.joda:joda-money:*:*:compile org.batoo.jpa:batoo-jpa:*:*:compile @@ -112,6 +110,9 @@ jakarta.xml.bind:jakarta.xml.bind-api:*:*:compile javax.*:*:*:*:* + + org.datanucleus:javax.jdo:*:*:* + org.springframework.roo:org.springframework.roo.annotations:*:*:compile org.hsqldb:hsqldb:*:*:compile com.h2database:h2:*:*:compile diff --git a/querydsl-libraries/querydsl-collections/pom.xml b/querydsl-libraries/querydsl-collections/pom.xml index 268473a342..87c3304c49 100644 --- a/querydsl-libraries/querydsl-collections/pom.xml +++ b/querydsl-libraries/querydsl-collections/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.11-SNAPSHOT + 7.0-SNAPSHOT io.github.openfeign.querydsl diff --git a/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/AbstractCollQuery.java b/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/AbstractCollQuery.java index 27e9639798..362bd8a68a 100644 --- a/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/AbstractCollQuery.java +++ b/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/AbstractCollQuery.java @@ -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; @@ -180,7 +179,7 @@ public

Q leftJoin(MapExpression target, Path

alias) { public CloseableIterator iterate() { @SuppressWarnings("unchecked") // This is the built type var projection = (Expression) queryMixin.getMetadata().getProjection(); - return new IteratorAdapter<>(fetch().iterator()); + return CloseableIterator.of(fetch().iterator()); } @Override diff --git a/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/DefaultQueryEngine.java b/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/DefaultQueryEngine.java index 4630999185..73be7ea9c5 100644 --- a/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/DefaultQueryEngine.java +++ b/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/DefaultQueryEngine.java @@ -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; @@ -163,10 +163,10 @@ private List evaluateSingleSource( final List> sources = Collections.>singletonList(source); final Iterable iterable = iterables.values().iterator().next(); List list; - if (iterable instanceof List) { - list = (List) iterable; + if (iterable instanceof List list1) { + list = list1; } else { - list = IteratorAdapter.asList(iterable.iterator()); + list = CloseableIterator.asList(iterable.iterator()); } // from & where diff --git a/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/MultiComparator.java b/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/MultiComparator.java index b973dcfca2..67b4a023b3 100644 --- a/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/MultiComparator.java +++ b/querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/MultiComparator.java @@ -15,6 +15,7 @@ import com.querydsl.codegen.utils.Evaluator; import com.querydsl.core.util.NullSafeComparableComparator; +import java.io.Serial; import java.io.Serializable; import java.util.Comparator; @@ -29,7 +30,7 @@ public class MultiComparator implements Comparator, Serializable { @SuppressWarnings("unchecked") private static final Comparator naturalOrder = new NullSafeComparableComparator(); - private static final long serialVersionUID = 1121416260773566299L; + @Serial private static final long serialVersionUID = 1121416260773566299L; private final boolean[] asc; @@ -45,8 +46,8 @@ public MultiComparator(Evaluator ev, boolean[] directions, boolean[] n @Override public int compare(T o1, T o2) { - if (o1 instanceof Object[]) { - return innerCompare(ev.evaluate((Object[]) o1), ev.evaluate((Object[]) o2)); + if (o1 instanceof Object[] objects) { + return innerCompare(ev.evaluate(objects), ev.evaluate((Object[]) o2)); } else { return innerCompare(ev.evaluate(o1), ev.evaluate(o2)); } diff --git a/querydsl-libraries/querydsl-collections/src/test/java/com/querydsl/collections/GroupBy3Test.java b/querydsl-libraries/querydsl-collections/src/test/java/com/querydsl/collections/GroupBy3Test.java index c41ef643b2..6abc6fd6f4 100644 --- a/querydsl-libraries/querydsl-collections/src/test/java/com/querydsl/collections/GroupBy3Test.java +++ b/querydsl-libraries/querydsl-collections/src/test/java/com/querydsl/collections/GroupBy3Test.java @@ -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; diff --git a/querydsl-libraries/querydsl-collections/src/test/java/com/querydsl/collections/PagingTest.java b/querydsl-libraries/querydsl-collections/src/test/java/com/querydsl/collections/PagingTest.java index 6bb473c85a..44f11d203c 100644 --- a/querydsl-libraries/querydsl-collections/src/test/java/com/querydsl/collections/PagingTest.java +++ b/querydsl-libraries/querydsl-collections/src/test/java/com/querydsl/collections/PagingTest.java @@ -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; @@ -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) { diff --git a/querydsl-libraries/querydsl-core/pom.xml b/querydsl-libraries/querydsl-core/pom.xml index b9cc4e6c5d..b4bcb6dd34 100644 --- a/querydsl-libraries/querydsl-core/pom.xml +++ b/querydsl-libraries/querydsl-core/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-core @@ -18,11 +18,6 @@ annotations provided - - com.mysema.commons - mysema-commons-lang - ${mysema.lang.version} - io.github.classgraph classgraph diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/BooleanBuilder.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/BooleanBuilder.java index a7b1d3edc4..52182c6fd9 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/BooleanBuilder.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/BooleanBuilder.java @@ -17,6 +17,7 @@ import com.querydsl.core.types.ExpressionUtils; import com.querydsl.core.types.Predicate; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.Objects; import org.jetbrains.annotations.Nullable; @@ -38,7 +39,7 @@ */ public final class BooleanBuilder implements Predicate, Cloneable { - private static final long serialVersionUID = -4129485177345542519L; + @Serial private static final long serialVersionUID = -4129485177345542519L; @Nullable private Predicate predicate; @@ -113,8 +114,8 @@ public BooleanBuilder clone() throws CloneNotSupportedException { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof BooleanBuilder) { - return Objects.equals(((BooleanBuilder) o).getValue(), predicate); + } else if (o instanceof BooleanBuilder builder) { + return Objects.equals(builder.getValue(), predicate); } else { return false; } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/CloseableIterator.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/CloseableIterator.java new file mode 100644 index 0000000000..bb96f837dc --- /dev/null +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/CloseableIterator.java @@ -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 extends Iterator, AutoCloseable { + + @Override + void close(); + + public static List asList(CloseableIterator iterator) { + try (iterator) { + return StreamSupport.stream( + Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false) + .collect(Collectors.toList()); + } + } + + public static CloseableIterator of(Iterator iterator) { + return of(iterator, () -> {}); + } + + public static CloseableIterator of(CloseableIterator iterator) { + return of(iterator, iterator); + } + + public static CloseableIterator of(Iterator iterator, AutoCloseable closeable) { + return new CloseableIterator() { + + @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 List asList(Iterator iterator) { + return asList(of(iterator)); + } +} diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/DefaultQueryMetadata.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/DefaultQueryMetadata.java index bd5cefe480..aa9a40204e 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/DefaultQueryMetadata.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/DefaultQueryMetadata.java @@ -28,6 +28,7 @@ import com.querydsl.core.types.Predicate; import com.querydsl.core.types.ValidatingVisitor; import com.querydsl.core.util.CollectionUtils; +import java.io.Serial; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -50,7 +51,7 @@ */ public class DefaultQueryMetadata implements QueryMetadata, Cloneable { - private static final long serialVersionUID = 317736313966701232L; + @Serial private static final long serialVersionUID = 317736313966701232L; private boolean distinct; @@ -158,7 +159,7 @@ private void addLastJoin() { public void addJoin(JoinType joinType, Expression expr) { addLastJoin(); if (!exprInJoins.contains(expr)) { - if (expr instanceof Path && ((Path) expr).getMetadata().isRoot()) { + if (expr instanceof Path path && path.getMetadata().isRoot()) { exprInJoins.add(expr); } else { validate(expr); @@ -378,8 +379,7 @@ public void setValidatingVisitor(ValidatingVisitor visitor) { @Override public boolean equals(Object o) { - if (o instanceof QueryMetadata) { - var q = (QueryMetadata) o; + if (o instanceof QueryMetadata q) { return q.getFlags().equals(flags) && q.getGroupBy().equals(groupBy) && Objects.equals(q.getHaving(), having) diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/EmptyMetadata.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/EmptyMetadata.java index 80dd643268..51dee85485 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/EmptyMetadata.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/EmptyMetadata.java @@ -17,6 +17,7 @@ import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.ParamExpression; import com.querydsl.core.types.Predicate; +import java.io.Serial; import java.util.Collections; import java.util.List; import java.util.Map; @@ -31,7 +32,7 @@ */ public final class EmptyMetadata implements QueryMetadata { - private static final long serialVersionUID = 134750105981272499L; + @Serial private static final long serialVersionUID = 134750105981272499L; public static final QueryMetadata DEFAULT = new EmptyMetadata(); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/Fetchable.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/Fetchable.java index eaa6432087..5b706a0776 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/Fetchable.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/Fetchable.java @@ -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; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/JoinExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/JoinExpression.java index 975521d1c2..d6f4f41c3d 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/JoinExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/JoinExpression.java @@ -17,6 +17,7 @@ import com.querydsl.core.types.Expression; import com.querydsl.core.types.Predicate; import com.querydsl.core.util.CollectionUtils; +import java.io.Serial; import java.io.Serializable; import java.util.Collections; import java.util.Objects; @@ -31,7 +32,7 @@ @Immutable public final class JoinExpression implements Serializable { - private static final long serialVersionUID = -1131755765747174886L; + @Serial private static final long serialVersionUID = -1131755765747174886L; @Nullable private final Predicate condition; @@ -107,8 +108,7 @@ public int hashCode() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof JoinExpression) { - var j = (JoinExpression) o; + } else if (o instanceof JoinExpression j) { return Objects.equals(condition, j.condition) && Objects.equals(target, j.target) && Objects.equals(type, j.type); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/JoinFlag.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/JoinFlag.java index c24348edd7..65a52631f4 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/JoinFlag.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/JoinFlag.java @@ -16,6 +16,7 @@ import com.querydsl.core.annotations.Immutable; import com.querydsl.core.types.Expression; import com.querydsl.core.types.ExpressionUtils; +import java.io.Serial; import java.io.Serializable; /** @@ -48,7 +49,7 @@ public enum Position { END } - private static final long serialVersionUID = -688265393547206465L; + @Serial private static final long serialVersionUID = -688265393547206465L; private final Expression flag; @@ -106,8 +107,8 @@ public int hashCode() { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof JoinFlag) { - return ((JoinFlag) obj).flag.equals(flag); + } else if (obj instanceof JoinFlag joinFlag) { + return joinFlag.flag.equals(flag); } else { return false; } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/NonUniqueResultException.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/NonUniqueResultException.java index f7969b2f78..f4e6f6e2e0 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/NonUniqueResultException.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/NonUniqueResultException.java @@ -13,6 +13,8 @@ */ package com.querydsl.core; +import java.io.Serial; + /** * {@code NonUniqueResultException} is thrown for query results where one result row is expected, * but multiple are retrieved. @@ -21,7 +23,7 @@ */ public class NonUniqueResultException extends QueryException { - private static final long serialVersionUID = -1757423191400510323L; + @Serial private static final long serialVersionUID = -1757423191400510323L; public NonUniqueResultException() { super("Only one result is allowed for fetchOne calls"); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/Pair.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/Pair.java new file mode 100644 index 0000000000..864ad82a21 --- /dev/null +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/Pair.java @@ -0,0 +1,18 @@ +package com.querydsl.core; + +public record Pair(F first, S second) { + + @Deprecated + public F getFirst() { + return first(); + } + + @Deprecated + public S getSecond() { + return second(); + } + + public static Pair of(T key, U value) { + return new Pair<>(key, value); + } +} diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryException.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryException.java index b1ffa4826b..2402528b49 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryException.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryException.java @@ -13,6 +13,8 @@ */ package com.querydsl.core; +import java.io.Serial; + /** * {@code QueryException} is thrown for exceptional query construction issues * @@ -20,7 +22,7 @@ */ public class QueryException extends RuntimeException { - private static final long serialVersionUID = 2345665389612058703L; + @Serial private static final long serialVersionUID = 2345665389612058703L; public QueryException(String msg) { super(msg); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryFlag.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryFlag.java index 4ae16e0031..8214f8c4d7 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryFlag.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryFlag.java @@ -15,6 +15,7 @@ import com.querydsl.core.types.Expression; import com.querydsl.core.types.ExpressionUtils; +import java.io.Serial; import java.io.Serializable; import java.util.Objects; @@ -25,7 +26,7 @@ */ public class QueryFlag implements Serializable { - private static final long serialVersionUID = -7131081607441961628L; + @Serial private static final long serialVersionUID = -7131081607441961628L; /** The different {@code QueryFlag} positions */ public enum Position { @@ -103,8 +104,7 @@ public int hashCode() { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof QueryFlag) { - var other = (QueryFlag) obj; + } else if (obj instanceof QueryFlag other) { return other.position.equals(position) && other.flag.equals(flag); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryModifiers.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryModifiers.java index 536141911e..9690f40042 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryModifiers.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryModifiers.java @@ -13,6 +13,7 @@ */ package com.querydsl.core; +import java.io.Serial; import java.io.Serializable; import java.util.List; import java.util.Objects; @@ -26,7 +27,7 @@ */ public final class QueryModifiers implements Serializable { - private static final long serialVersionUID = 2934344588433680339L; + @Serial private static final long serialVersionUID = 2934344588433680339L; /** No limit and not offset restriction */ public static final QueryModifiers EMPTY = new QueryModifiers(); @@ -120,8 +121,7 @@ public List subList(List list) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof QueryModifiers) { - var qm = (QueryModifiers) o; + } else if (o instanceof QueryModifiers qm) { return Objects.equals(qm.getLimit(), limit) && Objects.equals(qm.getOffset(), offset); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryResults.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryResults.java index c6344b0c1a..f41be50054 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryResults.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/QueryResults.java @@ -13,6 +13,7 @@ */ package com.querydsl.core; +import java.io.Serial; import java.io.Serializable; import java.util.Collections; import java.util.List; @@ -26,7 +27,7 @@ */ public final class QueryResults implements Serializable { - private static final long serialVersionUID = -4591506147471300909L; + @Serial private static final long serialVersionUID = -4591506147471300909L; private static final QueryResults EMPTY = new QueryResults<>(Collections.emptyList(), Long.MAX_VALUE, 0L, 0L); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/alias/Alias.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/alias/Alias.java index c17418e84f..0165678fce 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/alias/Alias.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/alias/Alias.java @@ -162,8 +162,8 @@ public final class Alias { final Object current = aliasFactory.getCurrentAndReset(); if (arg instanceof CollectionPath) { return (CollectionPath>) arg; // NOSONAR - } else if (arg instanceof ManagedObject) { - return (CollectionPath>) ((ManagedObject) arg).__mappedPath(); + } else if (arg instanceof ManagedObject object) { + return (CollectionPath>) object.__mappedPath(); } else { return (CollectionPath>) current; } @@ -242,8 +242,8 @@ public final class Alias { final Object current = aliasFactory.getCurrentAndReset(); if (arg instanceof ListPath) { return (ListPath>) arg; // NOSONAR - } else if (arg instanceof ManagedObject) { - return (ListPath>) ((ManagedObject) arg).__mappedPath(); + } else if (arg instanceof ManagedObject object) { + return (ListPath>) object.__mappedPath(); } else { return (ListPath>) current; } @@ -272,8 +272,8 @@ public final class Alias { final Object current = aliasFactory.getCurrentAndReset(); if (arg instanceof MapPath) { return (MapPath>) arg; // NOSONAR - } else if (arg instanceof ManagedObject) { - return (MapPath>) ((ManagedObject) arg).__mappedPath(); + } else if (arg instanceof ManagedObject object) { + return (MapPath>) object.__mappedPath(); } else { return (MapPath>) current; } @@ -291,8 +291,8 @@ public final class Alias { final Object current = aliasFactory.getCurrentAndReset(); if (arg instanceof SetPath) { return (SetPath>) arg; // NOSONAR - } else if (arg instanceof ManagedObject) { - return (SetPath>) ((ManagedObject) arg).__mappedPath(); + } else if (arg instanceof ManagedObject object) { + return (SetPath>) object.__mappedPath(); } else { return (SetPath>) current; } @@ -351,8 +351,8 @@ public final class Alias { final Object current = aliasFactory.getCurrentAndReset(); if (arg instanceof EntityPath) { return (EntityPathBase) arg; // NOSONAR - } else if (arg instanceof ManagedObject) { - return (EntityPathBase) ((ManagedObject) arg).__mappedPath(); + } else if (arg instanceof ManagedObject object) { + return (EntityPathBase) object.__mappedPath(); } else { return (EntityPathBase) current; } @@ -364,8 +364,8 @@ private static > P getPath(D arg) { final Object current = aliasFactory.getCurrentAndReset(); if (arg instanceof Path) { return (P) arg; - } else if (arg instanceof ManagedObject) { - return (P) ((ManagedObject) arg).__mappedPath(); + } else if (arg instanceof ManagedObject object) { + return (P) object.__mappedPath(); } else { return (P) current; } @@ -415,8 +415,8 @@ public static A alias(Class cl, String var) { @SuppressWarnings("unchecked") public static Expression getAny(D arg) { Object current = aliasFactory.getCurrentAndReset(); - if (arg instanceof ManagedObject) { - return (Expression) ((ManagedObject) arg).__mappedPath(); + if (arg instanceof ManagedObject object) { + return (Expression) object.__mappedPath(); } else if (current != null) { return (Expression) current; } else { diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/AbstractGroupByTransformer.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/AbstractGroupByTransformer.java index 63d9785695..834a8b825d 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/AbstractGroupByTransformer.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/AbstractGroupByTransformer.java @@ -74,13 +74,12 @@ protected AbstractGroupByTransformer(Expression key, Expression... express projection.add(key); for (Expression expr : expressions) { - if (expr instanceof GroupExpression) { - GroupExpression groupExpr = (GroupExpression) expr; + if (expr instanceof GroupExpression groupExpr) { groupExpressions.add(groupExpr); Expression colExpression = groupExpr.getExpression(); - if (colExpression instanceof Operation - && ((Operation) colExpression).getOperator() == Ops.ALIAS) { - projection.add(((Operation) colExpression).getArg(0)); + if (colExpression instanceof Operation operation + && operation.getOperator() == Ops.ALIAS) { + projection.add(operation.getArg(0)); } else { projection.add(colExpression); } @@ -100,8 +99,8 @@ protected static FactoryExpression withoutGroupExpressions( final FactoryExpression expr) { List> args = new ArrayList<>(expr.getArgs().size()); for (Expression arg : expr.getArgs()) { - if (arg instanceof GroupExpression) { - args.add(((GroupExpression) arg).getExpression()); + if (arg instanceof GroupExpression expression) { + args.add(expression.getExpression()); } else { args.add(arg); } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/AbstractGroupExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/AbstractGroupExpression.java index bc55dabd8d..d247d7aa5d 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/AbstractGroupExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/AbstractGroupExpression.java @@ -20,6 +20,7 @@ import com.querydsl.core.types.Visitor; import com.querydsl.core.types.dsl.DslExpression; import com.querydsl.core.types.dsl.Expressions; +import java.io.Serial; /** * A base class for GroupExpressions @@ -30,7 +31,7 @@ */ public abstract class AbstractGroupExpression implements GroupExpression { - private static final long serialVersionUID = 1509709546966783160L; + @Serial private static final long serialVersionUID = 1509709546966783160L; private final Class type; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GAvg.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GAvg.java index 2228a22c6c..74c349f0f4 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GAvg.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GAvg.java @@ -15,6 +15,7 @@ import com.querydsl.core.types.Expression; import com.querydsl.core.util.MathUtils; +import java.io.Serial; import java.math.BigDecimal; import java.math.MathContext; @@ -26,7 +27,7 @@ @SuppressWarnings("unchecked") public class GAvg extends AbstractGroupExpression { - private static final long serialVersionUID = 3518868612387641383L; + @Serial private static final long serialVersionUID = 3518868612387641383L; private final MathContext mathContext; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GList.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GList.java index 93ed96c321..4a21d37823 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GList.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GList.java @@ -14,6 +14,7 @@ package com.querydsl.core.group; import com.querydsl.core.types.Expression; +import java.io.Serial; import java.util.ArrayList; import java.util.List; @@ -24,7 +25,7 @@ */ public class GList extends AbstractGroupExpression> { - private static final long serialVersionUID = -5613861506383727078L; + @Serial private static final long serialVersionUID = -5613861506383727078L; public GList(Expression expr) { super(List.class, expr); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GMap.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GMap.java index 13b4ebf9ff..532a39bc3a 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GMap.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GMap.java @@ -13,7 +13,8 @@ */ 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; import java.util.LinkedHashMap; @@ -31,7 +32,7 @@ public abstract class GMap> extends AbstractGroupExpression, M> { - private static final long serialVersionUID = 7106389414200843920L; + @Serial private static final long serialVersionUID = 7106389414200843920L; GMap(QPair qpair) { super(Map.class, qpair); @@ -98,7 +99,7 @@ public M get() { public static class Mixin> extends AbstractGroupExpression, R> { - private static final long serialVersionUID = 1939989270493531116L; + @Serial private static final long serialVersionUID = 1939989270493531116L; private class GroupCollectorImpl implements GroupCollector, R> { diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GMax.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GMax.java index cdf56393d2..adb6659850 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GMax.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GMax.java @@ -14,6 +14,7 @@ package com.querydsl.core.group; import com.querydsl.core.types.Expression; +import java.io.Serial; /** * GMax @@ -22,7 +23,7 @@ */ public class GMax> extends AbstractGroupExpression { - private static final long serialVersionUID = 3815394663181131511L; + @Serial private static final long serialVersionUID = 3815394663181131511L; @SuppressWarnings("unchecked") public GMax(Expression expr) { diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GMin.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GMin.java index 04cb0203c7..430b8ffeab 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GMin.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GMin.java @@ -14,6 +14,7 @@ package com.querydsl.core.group; import com.querydsl.core.types.Expression; +import java.io.Serial; /** * GMin @@ -22,7 +23,7 @@ */ public class GMin> extends AbstractGroupExpression { - private static final long serialVersionUID = 8312168556148122576L; + @Serial private static final long serialVersionUID = 8312168556148122576L; @SuppressWarnings("unchecked") public GMin(Expression expr) { diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GOne.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GOne.java index 355b3488e6..2c5944c4d0 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GOne.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GOne.java @@ -14,6 +14,7 @@ package com.querydsl.core.group; import com.querydsl.core.types.Expression; +import java.io.Serial; /** * GOne @@ -22,7 +23,7 @@ */ public class GOne extends AbstractGroupExpression { - private static final long serialVersionUID = 3518868612387641383L; + @Serial private static final long serialVersionUID = 3518868612387641383L; @SuppressWarnings("unchecked") public GOne(Expression expr) { diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GSet.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GSet.java index 634f9b1fef..9273f7af33 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GSet.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GSet.java @@ -14,6 +14,7 @@ package com.querydsl.core.group; import com.querydsl.core.types.Expression; +import java.io.Serial; import java.util.Comparator; import java.util.LinkedHashSet; import java.util.Set; @@ -28,7 +29,7 @@ */ public abstract class GSet> extends AbstractGroupExpression { - private static final long serialVersionUID = -1575808026237160843L; + @Serial private static final long serialVersionUID = -1575808026237160843L; public static GSet> createLinked(Expression expr) { return new GSet<>(expr) { diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GSum.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GSum.java index 2d6fba91e5..f0567285b5 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GSum.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GSum.java @@ -15,6 +15,7 @@ import com.querydsl.core.types.Expression; import com.querydsl.core.util.MathUtils; +import java.io.Serial; import java.math.BigDecimal; /** @@ -24,7 +25,7 @@ */ public class GSum extends AbstractGroupExpression { - private static final long serialVersionUID = 3518868612387641383L; + @Serial private static final long serialVersionUID = 3518868612387641383L; @SuppressWarnings("unchecked") public GSum(Expression expr) { diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupBy.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupBy.java index 4f1d0f6de2..4030c189e6 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupBy.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupBy.java @@ -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; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupByBuilder.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupByBuilder.java index 8b68f1bc51..9c442fea89 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupByBuilder.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupByBuilder.java @@ -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; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupByIterate.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupByIterate.java index d7f0d8899b..3c34a379ba 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupByIterate.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupByIterate.java @@ -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; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupImpl.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupImpl.java index 9e813643ad..ff39e42244 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupImpl.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/GroupImpl.java @@ -50,9 +50,8 @@ public GroupImpl(List> columnDefinitions, List collector = coldef.createGroupCollector(); Expression coldefExpr = coldef.getExpression(); groupCollectorMap.put(coldefExpr, collector); - if (coldefExpr instanceof Operation - && ((Operation) coldefExpr).getOperator() == Ops.ALIAS) { - groupCollectorMap.put(((Operation) coldefExpr).getArg(1), collector); + if (coldefExpr instanceof Operation operation && operation.getOperator() == Ops.ALIAS) { + groupCollectorMap.put(operation.getArg(1), collector); } } groupCollectors.add(collector); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/MixinGroupExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/MixinGroupExpression.java index 066a4a7fdf..e0bfb22c42 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/MixinGroupExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/MixinGroupExpression.java @@ -13,6 +13,8 @@ */ package com.querydsl.core.group; +import java.io.Serial; + /** * {@code MixinGroupExpression} provides nesting support for {@link GroupExpression} instances * @@ -22,7 +24,7 @@ */ public class MixinGroupExpression extends AbstractGroupExpression { - private static final long serialVersionUID = -5419707469727395643L; + @Serial private static final long serialVersionUID = -5419707469727395643L; private class GroupCollectorImpl implements GroupCollector { diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/QPair.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/QPair.java index 4a929abaef..da09472666 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/QPair.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/group/QPair.java @@ -13,9 +13,10 @@ */ 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; /** * A pair of (Map) key and value @@ -26,7 +27,7 @@ */ public final class QPair extends ConstructorExpression> { - private static final long serialVersionUID = -1943990903548916056L; + @Serial private static final long serialVersionUID = -1943990903548916056L; public static QPair create(Expression key, Expression value) { return new QPair<>(key, value); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/CollectionAnyVisitor.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/CollectionAnyVisitor.java index 674b4d3725..3f8b172731 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/CollectionAnyVisitor.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/CollectionAnyVisitor.java @@ -48,8 +48,7 @@ public class CollectionAnyVisitor implements Visitor, Context> { private static Path replaceParent(Path path, Path parent) { var metadata = new PathMetadata(parent, path.getMetadata().getElement(), path.getMetadata().getPathType()); - if (path instanceof CollectionExpression) { - CollectionExpression col = (CollectionExpression) path; + if (path instanceof CollectionExpression col) { return Expressions.listPath(col.getParameter(0), SimplePath.class, metadata); } else { return ExpressionUtils.path(path.getType(), metadata); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ConstantHidingExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ConstantHidingExpression.java index 93b572775d..143b9e9d3d 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ConstantHidingExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ConstantHidingExpression.java @@ -22,6 +22,7 @@ import com.querydsl.core.types.Ops; import com.querydsl.core.types.Visitor; import com.querydsl.core.types.dsl.Expressions; +import java.io.Serial; import java.util.ArrayList; import java.util.List; import org.jetbrains.annotations.Nullable; @@ -34,7 +35,7 @@ */ public class ConstantHidingExpression extends FactoryExpressionBase { - private static final long serialVersionUID = -7834053123363933721L; + @Serial private static final long serialVersionUID = -7834053123363933721L; private final FactoryExpression expr; @@ -50,8 +51,8 @@ public ConstantHidingExpression(FactoryExpression expr) { for (var i = 0; i < template.length; i++) { Expression arg = expr.getArgs().get(i); Expression unwrapped = unwrap(arg); - if (unwrapped instanceof Constant) { - template[i] = ((Constant) unwrapped).getConstant(); + if (unwrapped instanceof Constant constant) { + template[i] = constant.getConstant(); } else if (unwrapped.equals(Expressions.TRUE)) { template[i] = Boolean.TRUE; } else if (unwrapped.equals(Expressions.FALSE)) { @@ -64,8 +65,8 @@ public ConstantHidingExpression(FactoryExpression expr) { private static Expression unwrap(Expression expr) { expr = ExpressionUtils.extract(expr); - if (expr instanceof Operation && ((Operation) expr).getOperator() == Ops.ALIAS) { - return ((Operation) expr).getArg(0); + if (expr instanceof Operation operation && operation.getOperator() == Ops.ALIAS) { + return operation.getArg(0); } return expr; } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/EnumConversion.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/EnumConversion.java index 38c7f03723..8049eefddd 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/EnumConversion.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/EnumConversion.java @@ -16,6 +16,7 @@ import com.querydsl.core.types.Expression; import com.querydsl.core.types.FactoryExpressionBase; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.Collections; import java.util.List; @@ -28,7 +29,7 @@ */ public class EnumConversion extends FactoryExpressionBase { - private static final long serialVersionUID = 7840412008633901748L; + @Serial private static final long serialVersionUID = 7840412008633901748L; private final List> exprs; @@ -61,8 +62,8 @@ public T newInstance(Object... args) { @SuppressWarnings("unchecked") // The expression type is an enum var rv = (T) Enum.valueOf(getType().asSubclass(Enum.class), args[0].toString()); return rv; - } else if (args[0] instanceof Number) { - return values[((Number) args[0]).intValue()]; + } else if (args[0] instanceof Number number) { + return values[number.intValue()]; } else { @SuppressWarnings("unchecked") var rv = (T) args[0]; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/FetchableQueryBase.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/FetchableQueryBase.java index c915a094c2..60703dd501 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/FetchableQueryBase.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/FetchableQueryBase.java @@ -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; @@ -40,7 +39,7 @@ public FetchableQueryBase(QueryMixin queryMixin) { @Override public List fetch() { - return IteratorAdapter.asList(iterate()); + return CloseableIterator.asList(iterate()); } @Override @@ -73,8 +72,7 @@ protected T uniqueResult(CloseableIterator it) { public final boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof SubQueryExpression) { - SubQueryExpression s = (SubQueryExpression) o; + } else if (o instanceof SubQueryExpression s) { return s.getMetadata().equals(queryMixin.getMetadata()); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/NumberConversion.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/NumberConversion.java index 22639bab31..86a8316ae4 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/NumberConversion.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/NumberConversion.java @@ -17,6 +17,7 @@ import com.querydsl.core.types.FactoryExpressionBase; import com.querydsl.core.types.Visitor; import com.querydsl.core.util.MathUtils; +import java.io.Serial; import java.util.Collections; import java.util.List; @@ -29,7 +30,7 @@ */ public class NumberConversion extends FactoryExpressionBase { - private static final long serialVersionUID = 7840412008633901748L; + @Serial private static final long serialVersionUID = 7840412008633901748L; private final List> exprs; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/NumberConversions.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/NumberConversions.java index 527dc207c0..476ce3c385 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/NumberConversions.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/NumberConversions.java @@ -18,6 +18,7 @@ import com.querydsl.core.types.FactoryExpressionBase; import com.querydsl.core.types.Visitor; import com.querydsl.core.util.MathUtils; +import java.io.Serial; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -31,7 +32,7 @@ */ public class NumberConversions extends FactoryExpressionBase { - private static final long serialVersionUID = -7834053123363933721L; + @Serial private static final long serialVersionUID = -7834053123363933721L; private final FactoryExpression expr; @@ -68,16 +69,16 @@ public T newInstance(Object... args) { for (var i = 0; i < args.length; i++) { Class type = expr.getArgs().get(i).getType(); if (Enum.class.isAssignableFrom(type) && !type.isInstance(args[i])) { - if (args[i] instanceof String) { - args[i] = Enum.valueOf((Class) type, (String) args[i]); - } else if (args[i] instanceof Number) { - args[i] = getValues((Class) type)[((Number) args[i]).intValue()]; + if (args[i] instanceof String string) { + args[i] = Enum.valueOf((Class) type, string); + } else if (args[i] instanceof Number number) { + args[i] = getValues((Class) type)[number.intValue()]; } - } else if (args[i] instanceof Number && !type.isInstance(args[i])) { + } else if (args[i] instanceof Number number && !type.isInstance(args[i])) { if (type.equals(Boolean.class)) { - args[i] = ((Number) args[i]).intValue() > 0; + args[i] = number.intValue() > 0; } else if (Number.class.isAssignableFrom(type)) { - args[i] = MathUtils.cast((Number) args[i], (Class) type); + args[i] = MathUtils.cast(number, (Class) type); } } } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/OrderedQueryMetadata.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/OrderedQueryMetadata.java index 89b56328ac..346f94c390 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/OrderedQueryMetadata.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/OrderedQueryMetadata.java @@ -17,6 +17,7 @@ import com.querydsl.core.JoinExpression; import com.querydsl.core.JoinType; import com.querydsl.core.types.Expression; +import java.io.Serial; import java.util.ArrayList; import java.util.List; @@ -28,7 +29,7 @@ */ public class OrderedQueryMetadata extends DefaultQueryMetadata { - private static final long serialVersionUID = 6326236143414219377L; + @Serial private static final long serialVersionUID = 6326236143414219377L; private List joins; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/PathsExtractor.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/PathsExtractor.java index 141cdd0aed..3df31f0361 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/PathsExtractor.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/PathsExtractor.java @@ -77,8 +77,8 @@ public Void visit(TemplateExpression expr, List> paths) { public Path visit(Collection exprs, List> paths) { for (Object e : exprs) { - if (e instanceof Expression) { - ((Expression) e).accept(this, paths); + if (e instanceof Expression expression) { + expression.accept(this, paths); } } return null; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/QueryBase.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/QueryBase.java index 67eb9fec17..5be6c4dd0e 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/QueryBase.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/QueryBase.java @@ -178,8 +178,7 @@ public

Q set(ParamExpression

param, P value) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof QueryBase) { - var q = (QueryBase) o; + } else if (o instanceof QueryBase q) { return q.queryMixin.equals(queryMixin); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/QueryMixin.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/QueryMixin.java index 0ad21f0fa2..e59b016f5b 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/QueryMixin.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/QueryMixin.java @@ -150,14 +150,14 @@ private Path normalizePath(Path expr) { @SuppressWarnings({"rawtypes", "unchecked"}) public Expression convert(Expression expr, Role role) { if (expandAnyPaths) { - if (expr instanceof Path) { - expr = (Expression) normalizePath((Path) expr); + if (expr instanceof Path path) { + expr = (Expression) normalizePath(path); } else if (expr != null) { expr = (Expression) expr.accept(replaceVisitor, null); } } - if (expr instanceof ProjectionRole) { - return convert(((ProjectionRole) expr).getProjection(), role); + if (expr instanceof ProjectionRole pr) { + return convert((pr).getProjection(), role); } else if (expr instanceof FactoryExpression && !(expr instanceof FactoryExpressionAdapter)) { return FactoryExpressionUtils.wrap((FactoryExpression) expr); @@ -437,8 +437,7 @@ public final T where(Predicate... o) { public final boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof QueryMixin) { - QueryMixin q = (QueryMixin) o; + } else if (o instanceof QueryMixin q) { return q.metadata.equals(metadata); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ReactiveFetchableQueryBase.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ReactiveFetchableQueryBase.java index 082a7e5430..0657a20470 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ReactiveFetchableQueryBase.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ReactiveFetchableQueryBase.java @@ -39,8 +39,7 @@ public Publisher transform(ReactiveResultTransformer transformer) { public final boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof SubQueryExpression) { - SubQueryExpression s = (SubQueryExpression) o; + } else if (o instanceof SubQueryExpression s) { return s.getMetadata().equals(queryMixin.getMetadata()); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ReplaceVisitor.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ReplaceVisitor.java index bd4664e235..8d293fbaf0 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ReplaceVisitor.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/ReplaceVisitor.java @@ -88,8 +88,8 @@ public Expression visit(Path expr, C context) { var metadata = expr.getMetadata(); Path parent = (Path) metadata.getParent().accept(this, context); var element = metadata.getElement(); - if (element instanceof Expression) { - element = ((Expression) element).accept(this, context); + if (element instanceof Expression expression) { + element = expression.accept(this, context); } if (parent.equals(metadata.getParent()) && Objects.equals(element, metadata.getElement())) { return expr; @@ -155,8 +155,8 @@ public Expression visit(SubQueryExpression expr, C context) { public Expression visit(TemplateExpression expr, C context) { ArrayList args = new ArrayList<>(); for (Object arg : expr.getArgs()) { - if (arg instanceof Expression) { - args.add(((Expression) arg).accept(this, context)); + if (arg instanceof Expression expression) { + args.add(expression.accept(this, context)); } else { args.add(arg); } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/SerializerBase.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/SerializerBase.java index 616a92bb07..8af04c3ac4 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/SerializerBase.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/support/SerializerBase.java @@ -116,8 +116,8 @@ public final S handle(Expression expr) { } public final S handle(Object arg) { - if (arg instanceof Expression) { - ((Expression) arg).accept(this, null); + if (arg instanceof Expression expression) { + expression.accept(this, null); } else { visitConstant(arg); } @@ -146,8 +146,8 @@ public final S handle(final String sep, final List> expr protected void handleTemplate(final Template template, final List args) { for (final Template.Element element : template.getElements()) { final var rv = element.convert(args); - if (rv instanceof Expression) { - ((Expression) rv).accept(this, null); + if (rv instanceof Expression expression) { + expression.accept(this, null); } else if (element.isString()) { builder.append(rv.toString()); } else { @@ -304,10 +304,9 @@ protected void visitOperation( var first = true; for (final Template.Element element : template.getElements()) { final var rv = element.convert(args); - if (rv instanceof Expression) { - final Expression expr = (Expression) rv; - if (precedence > -1 && expr instanceof Operation) { - var op = ((Operation) expr).getOperator(); + if (rv instanceof Expression expr) { + if (precedence > -1 && expr instanceof Operation operation) { + var op = operation.getOperator(); var opPrecedence = templates.getPrecedence(op); if (precedence < opPrecedence) { append("(").handle(expr).append(")"); @@ -328,9 +327,8 @@ protected void visitOperation( } } else if (strict) { throw new IllegalArgumentException( - String.format( - "No pattern found for %s. Make sure to register any custom functions with %s.", - operator, templates.getClass())); + "No pattern found for %s. Make sure to register any custom functions with %s." + .formatted(operator, templates.getClass())); } else { append(operator.toString()); append("("); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/AppendingFactoryExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/AppendingFactoryExpression.java index 62f2adc00a..91f58c8f96 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/AppendingFactoryExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/AppendingFactoryExpression.java @@ -13,6 +13,7 @@ */ package com.querydsl.core.types; +import java.io.Serial; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -21,7 +22,7 @@ class AppendingFactoryExpression extends FactoryExpressionBase { - private static final long serialVersionUID = -1337452521648394353L; + @Serial private static final long serialVersionUID = -1337452521648394353L; private final Expression base; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ArrayConstructorExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ArrayConstructorExpression.java index f322258b6c..6239ef1bdd 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ArrayConstructorExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ArrayConstructorExpression.java @@ -15,6 +15,7 @@ import com.querydsl.core.annotations.Immutable; import com.querydsl.core.util.CollectionUtils; +import java.io.Serial; import java.lang.reflect.Array; import java.util.Arrays; import java.util.List; @@ -30,7 +31,7 @@ @Immutable public class ArrayConstructorExpression extends FactoryExpressionBase { - private static final long serialVersionUID = 8667880104290226505L; + @Serial private static final long serialVersionUID = 8667880104290226505L; private final Class elementType; @@ -79,8 +80,7 @@ public List> getArgs() { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof FactoryExpression) { - FactoryExpression c = (FactoryExpression) obj; + } else if (obj instanceof FactoryExpression c) { return args.equals(c.getArgs()) && getType().equals(c.getType()); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ConstantImpl.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ConstantImpl.java index e0654d09f0..ce63dc1f19 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ConstantImpl.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ConstantImpl.java @@ -14,6 +14,7 @@ package com.querydsl.core.types; import com.querydsl.core.annotations.Immutable; +import java.io.Serial; /** * {@code ConstantImpl} is the default implementation of the {@link Constant} interface @@ -24,7 +25,7 @@ @Immutable public final class ConstantImpl extends ExpressionBase implements Constant { - private static final long serialVersionUID = -3898138057967814118L; + @Serial private static final long serialVersionUID = -3898138057967814118L; private static final int CACHE_SIZE = 256; @@ -144,8 +145,8 @@ public R accept(Visitor v, C context) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Constant) { - return ((Constant) o).getConstant().equals(constant); + } else if (o instanceof Constant constant1) { + return constant1.getConstant().equals(constant); } else { return false; } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ConstructorExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ConstructorExpression.java index 61fe66bf3b..b47e453b1e 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ConstructorExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ConstructorExpression.java @@ -20,6 +20,7 @@ import com.querydsl.core.annotations.Immutable; import java.io.IOException; import java.io.ObjectInputStream; +import java.io.Serial; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; @@ -47,7 +48,7 @@ @Immutable public class ConstructorExpression extends FactoryExpressionBase { - private static final long serialVersionUID = -602747921848073175L; + @Serial private static final long serialVersionUID = -602747921848073175L; private static Class[] getParameterTypes(Expression... args) { Class[] paramTypes = new Class[args.length]; @@ -115,8 +116,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof ConstructorExpression) { - ConstructorExpression c = (ConstructorExpression) obj; + } else if (obj instanceof ConstructorExpression c) { return Arrays.equals(parameterTypes, c.parameterTypes) && args.equals(c.args) && getType().equals(c.getType()); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ExpressionBase.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ExpressionBase.java index 6bd1613d1e..7a92e11c55 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ExpressionBase.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ExpressionBase.java @@ -13,6 +13,7 @@ */ package com.querydsl.core.types; +import java.io.Serial; import org.jetbrains.annotations.Nullable; /** @@ -23,7 +24,7 @@ */ public abstract class ExpressionBase implements Expression { - private static final long serialVersionUID = -8862014178653364345L; + @Serial private static final long serialVersionUID = -8862014178653364345L; private final Class type; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ExpressionException.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ExpressionException.java index 9c3d2775a9..1f35b780ba 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ExpressionException.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ExpressionException.java @@ -13,6 +13,8 @@ */ package com.querydsl.core.types; +import java.io.Serial; + /** * {@code ExpressionException} is thrown for {@link Expression} construction issues * @@ -20,7 +22,7 @@ */ public class ExpressionException extends RuntimeException { - private static final long serialVersionUID = 6031724386976562965L; + @Serial private static final long serialVersionUID = 6031724386976562965L; public ExpressionException(String msg) { super(msg); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ExpressionUtils.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ExpressionUtils.java index 7daab4481b..32fa19d86f 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ExpressionUtils.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ExpressionUtils.java @@ -548,8 +548,7 @@ public static Expression likeToRegex(Expression expr, boolean ma if (!like.equals(rv.toString())) { return ConstantImpl.create(rv.toString()); } - } else if (expr instanceof Operation) { - Operation o = (Operation) expr; + } else if (expr instanceof Operation o) { if (o.getOperator() == Ops.CONCAT) { var lhs = likeToRegex((Expression) o.getArg(0), false); var rhs = likeToRegex((Expression) o.getArg(1), false); @@ -628,8 +627,7 @@ public static Expression regexToLike(Expression expr) { if (!rv.toString().equals(str)) { return ConstantImpl.create(rv.toString()); } - } else if (expr instanceof Operation) { - Operation o = (Operation) expr; + } else if (expr instanceof Operation o) { if (o.getOperator() == Ops.CONCAT) { var lhs = regexToLike((Expression) o.getArg(0)); var rhs = regexToLike((Expression) o.getArg(1)); @@ -820,8 +818,8 @@ public static String createRootVariable(Path path) { * @return converted argument */ public static Expression toExpression(Object o) { - if (o instanceof Expression) { - return (Expression) o; + if (o instanceof Expression expression) { + return expression; } else { return ConstantImpl.create(o); } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/FactoryExpressionBase.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/FactoryExpressionBase.java index d1f5d9e40b..d339ca6987 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/FactoryExpressionBase.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/FactoryExpressionBase.java @@ -61,8 +61,8 @@ public R accept(Visitor v, @Nullable C context) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof FactoryExpressionWrapper) { - return expr.equals(((FactoryExpressionWrapper) o).expr); + } else if (o instanceof FactoryExpressionWrapper wrapper) { + return expr.equals(wrapper.expr); } else { return false; } @@ -86,8 +86,8 @@ public FactoryExpression skipNulls() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof FactoryExpression) { - return getClass().equals(o.getClass()) && getArgs().equals(((FactoryExpression) o).getArgs()); + } else if (o instanceof FactoryExpression expression) { + return getClass().equals(o.getClass()) && getArgs().equals(expression.getArgs()); } else { return false; } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/FactoryExpressionUtils.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/FactoryExpressionUtils.java index 4b5b495222..904e49e2da 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/FactoryExpressionUtils.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/FactoryExpressionUtils.java @@ -71,8 +71,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof FactoryExpression) { - FactoryExpression e = (FactoryExpression) o; + } else if (o instanceof FactoryExpression e) { return args.equals(e.getArgs()) && getType().equals(e.getType()); } else { return false; @@ -99,8 +98,8 @@ public static FactoryExpression wrap( public static FactoryExpression wrap(FactoryExpression expr) { for (Expression arg : expr.getArgs()) { - if (arg instanceof ProjectionRole) { - arg = ((ProjectionRole) arg).getProjection(); + if (arg instanceof ProjectionRole role) { + arg = role.getProjection(); } if (arg instanceof FactoryExpression) { return new FactoryExpressionAdapter<>(expr); @@ -112,11 +111,11 @@ public static FactoryExpression wrap(FactoryExpression expr) { private static List> expand(List> exprs) { List> rv = new ArrayList<>(exprs.size()); for (Expression expr : exprs) { - if (expr instanceof ProjectionRole) { - expr = ((ProjectionRole) expr).getProjection(); + if (expr instanceof ProjectionRole role) { + expr = role.getProjection(); } - if (expr instanceof FactoryExpression) { - rv.addAll(expand(((FactoryExpression) expr).getArgs())); + if (expr instanceof FactoryExpression expression) { + rv.addAll(expand(expression.getArgs())); } else { rv.add(expr); } @@ -127,11 +126,11 @@ private static List> expand(List> exprs) { private static int countArguments(FactoryExpression expr) { var counter = 0; for (Expression arg : expr.getArgs()) { - if (arg instanceof ProjectionRole) { - arg = ((ProjectionRole) arg).getProjection(); + if (arg instanceof ProjectionRole role) { + arg = role.getProjection(); } - if (arg instanceof FactoryExpression) { - counter += countArguments((FactoryExpression) arg); + if (arg instanceof FactoryExpression expression) { + counter += countArguments(expression); } else { counter++; } @@ -144,11 +143,10 @@ private static Object[] compress(List> exprs, Object[] args) { var offset = 0; for (var i = 0; i < exprs.size(); i++) { Expression expr = exprs.get(i); - if (expr instanceof ProjectionRole) { - expr = ((ProjectionRole) expr).getProjection(); + if (expr instanceof ProjectionRole role) { + expr = role.getProjection(); } - if (expr instanceof FactoryExpression) { - FactoryExpression fe = (FactoryExpression) expr; + if (expr instanceof FactoryExpression fe) { var fullArgsLength = countArguments(fe); var compressed = compress(fe.getArgs(), ArrayUtils.subarray(args, offset, offset + fullArgsLength)); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/MappingProjection.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/MappingProjection.java index 8adf19d065..377c3b33d1 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/MappingProjection.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/MappingProjection.java @@ -15,6 +15,7 @@ import com.querydsl.core.Tuple; import com.querydsl.core.annotations.Immutable; +import java.io.Serial; import java.util.List; import org.jetbrains.annotations.Nullable; @@ -37,7 +38,7 @@ @Immutable public abstract class MappingProjection extends FactoryExpressionBase { - private static final long serialVersionUID = -948494350919774466L; + @Serial private static final long serialVersionUID = -948494350919774466L; private final QTuple qTuple; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/MutableExpressionBase.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/MutableExpressionBase.java index 52a0042ac3..60ea7c4d8f 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/MutableExpressionBase.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/MutableExpressionBase.java @@ -13,6 +13,8 @@ */ package com.querydsl.core.types; +import java.io.Serial; + /** * {@code MutableExpressionBase} is the base class for mutable Expression implementations * @@ -21,7 +23,7 @@ */ public abstract class MutableExpressionBase implements Expression { - private static final long serialVersionUID = -6830426684911919114L; + @Serial private static final long serialVersionUID = -6830426684911919114L; private final Class type; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/NullExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/NullExpression.java index 20043ddaf3..051021d3ed 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/NullExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/NullExpression.java @@ -13,6 +13,7 @@ */ package com.querydsl.core.types; +import java.io.Serial; import java.util.Collections; /** @@ -25,7 +26,7 @@ public final class NullExpression extends TemplateExpressionImpl { private static final Template NULL_TEMPLATE = TemplateFactory.DEFAULT.create("null"); - private static final long serialVersionUID = -5311968198973316411L; + @Serial private static final long serialVersionUID = -5311968198973316411L; /** Default instance for an {@link java.lang.Object} typed NullExpression */ public static final NullExpression DEFAULT = new NullExpression<>(Object.class); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/OperationImpl.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/OperationImpl.java index 88902cd8fe..40ab0332d6 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/OperationImpl.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/OperationImpl.java @@ -16,6 +16,7 @@ import com.querydsl.core.annotations.Immutable; import com.querydsl.core.util.CollectionUtils; import com.querydsl.core.util.PrimitiveUtils; +import java.io.Serial; import java.util.Arrays; import java.util.List; import org.jetbrains.annotations.Unmodifiable; @@ -29,7 +30,7 @@ @Immutable public class OperationImpl extends ExpressionBase implements Operation { - private static final long serialVersionUID = 4796432056083507588L; + @Serial private static final long serialVersionUID = 4796432056083507588L; @Unmodifiable private final List> args; @@ -69,8 +70,7 @@ public final Operator getOperator() { public final boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Operation) { - Operation op = (Operation) o; + } else if (o instanceof Operation op) { return op.getOperator() == operator && op.getArgs().equals(args) && op.getType().equals(getType()); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/OrderSpecifier.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/OrderSpecifier.java index 8d4b79eb79..6a257866c1 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/OrderSpecifier.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/OrderSpecifier.java @@ -14,6 +14,7 @@ package com.querydsl.core.types; import com.querydsl.core.annotations.Immutable; +import java.io.Serial; import java.io.Serializable; /** @@ -25,7 +26,7 @@ @Immutable public class OrderSpecifier implements Serializable { - private static final long serialVersionUID = 3427652988262514678L; + @Serial private static final long serialVersionUID = 3427652988262514678L; /** Behaviour for order of null values */ public enum NullHandling { @@ -113,8 +114,7 @@ public String toString() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof OrderSpecifier) { - OrderSpecifier os = (OrderSpecifier) o; + } else if (o instanceof OrderSpecifier os) { return os.order.equals(order) && os.target.equals(target) && os.nullHandling.equals(nullHandling); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamExpressionImpl.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamExpressionImpl.java index 5a56220841..a07a5484c8 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamExpressionImpl.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamExpressionImpl.java @@ -14,6 +14,7 @@ package com.querydsl.core.types; import com.querydsl.core.annotations.Immutable; +import java.io.Serial; import java.util.UUID; /** @@ -25,7 +26,7 @@ @Immutable public class ParamExpressionImpl extends ExpressionBase implements ParamExpression { - private static final long serialVersionUID = -6872502615009012503L; + @Serial private static final long serialVersionUID = -6872502615009012503L; private final String name; @@ -52,8 +53,7 @@ public final R accept(Visitor v, C context) { public final boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof ParamExpression) { - ParamExpression other = (ParamExpression) o; + } else if (o instanceof ParamExpression other) { return other.getType().equals(getType()) && other.getName().equals(name) && other.isAnon() == anon; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamNotSetException.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamNotSetException.java index dfe57ddf27..f3718aea48 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamNotSetException.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamNotSetException.java @@ -13,6 +13,8 @@ */ package com.querydsl.core.types; +import java.io.Serial; + /** * {@code ParamNotSetException} is thrown when unbound parameters are found before query execution * @@ -20,7 +22,7 @@ */ public class ParamNotSetException extends RuntimeException { - private static final long serialVersionUID = 2019016965590576490L; + @Serial private static final long serialVersionUID = 2019016965590576490L; public ParamNotSetException(ParamExpression param) { super(param.getNotSetMessage()); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParameterizedPathImpl.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParameterizedPathImpl.java index a4a21bb5c1..af1d13f50a 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParameterizedPathImpl.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParameterizedPathImpl.java @@ -13,6 +13,8 @@ */ package com.querydsl.core.types; +import java.io.Serial; + /** * {@code ParameterizedPathImpl} represents {@link Path} instances with a parameterized generic type * @@ -20,7 +22,7 @@ */ public class ParameterizedPathImpl extends PathImpl implements ParameterizedExpression { - private static final long serialVersionUID = -498707460985111265L; + @Serial private static final long serialVersionUID = -498707460985111265L; private final Class[] parameterTypes; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamsVisitor.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamsVisitor.java index 8e781dba8c..157327eb46 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamsVisitor.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ParamsVisitor.java @@ -78,8 +78,8 @@ public Void visit(SubQueryExpression expr, QueryMetadata context) { @Override public Void visit(TemplateExpression expr, QueryMetadata context) { for (Object arg : expr.getArgs()) { - if (arg instanceof Expression) { - ((Expression) arg).accept(this, context); + if (arg instanceof Expression expression) { + expression.accept(this, context); } } return null; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathExtractor.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathExtractor.java index 4407d026a2..11ddcd94f2 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathExtractor.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathExtractor.java @@ -63,8 +63,8 @@ public Path visit(TemplateExpression expr, Void context) { private Path visit(List exprs) { for (Object e : exprs) { - if (e instanceof Expression) { - Path path = ((Expression) e).accept(this, null); + if (e instanceof Expression expression) { + Path path = expression.accept(this, null); if (path != null) { return path; } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathImpl.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathImpl.java index d68598132d..0b26fc66ea 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathImpl.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathImpl.java @@ -15,6 +15,7 @@ import com.querydsl.core.annotations.Immutable; import com.querydsl.core.util.ReflectionUtils; +import java.io.Serial; import java.lang.reflect.AnnotatedElement; import org.jetbrains.annotations.Nullable; @@ -27,7 +28,7 @@ @Immutable public class PathImpl extends ExpressionBase implements Path { - private static final long serialVersionUID = -2498447742798348162L; + @Serial private static final long serialVersionUID = -2498447742798348162L; private final PathMetadata metadata; @@ -53,8 +54,8 @@ protected PathImpl(Class type, Path parent, String property) { public final boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Path) { - return ((Path) o).getMetadata().equals(metadata); + } else if (o instanceof Path path) { + return path.getMetadata().equals(metadata); } else { return false; } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathMetadata.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathMetadata.java index ecee9e0c86..457bcaf19e 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathMetadata.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathMetadata.java @@ -14,6 +14,7 @@ package com.querydsl.core.types; import com.querydsl.core.annotations.Immutable; +import java.io.Serial; import java.io.Serializable; import java.util.Objects; import org.jetbrains.annotations.Nullable; @@ -26,7 +27,7 @@ @Immutable public final class PathMetadata implements Serializable { - private static final long serialVersionUID = -1055994185028970065L; + @Serial private static final long serialVersionUID = -1055994185028970065L; private final Object element; @@ -48,8 +49,7 @@ public PathMetadata(@Nullable Path parent, Object element, PathType type) { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof PathMetadata) { - var p = (PathMetadata) obj; + } else if (obj instanceof PathMetadata p) { return element.equals(p.element) && pathType == p.pathType && Objects.equals(parent, p.parent); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PredicateOperation.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PredicateOperation.java index e1d51f0868..6874fc2144 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PredicateOperation.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PredicateOperation.java @@ -14,6 +14,7 @@ package com.querydsl.core.types; import com.querydsl.core.annotations.Immutable; +import java.io.Serial; import java.util.List; import org.jetbrains.annotations.Nullable; @@ -25,7 +26,7 @@ @Immutable public final class PredicateOperation extends OperationImpl implements Predicate { - private static final long serialVersionUID = -5371430939203772072L; + @Serial private static final long serialVersionUID = -5371430939203772072L; @Nullable private transient volatile Predicate not; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PredicateTemplate.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PredicateTemplate.java index e554d668b9..e8d6dcbe74 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PredicateTemplate.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PredicateTemplate.java @@ -14,6 +14,7 @@ package com.querydsl.core.types; import com.querydsl.core.annotations.Immutable; +import java.io.Serial; import java.util.List; import org.jetbrains.annotations.Nullable; @@ -25,7 +26,7 @@ @Immutable public class PredicateTemplate extends TemplateExpressionImpl implements Predicate { - private static final long serialVersionUID = -5371430939203772072L; + @Serial private static final long serialVersionUID = -5371430939203772072L; @Nullable private transient volatile Predicate not; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QBean.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QBean.java index 57d5b5eedf..5bdfee0263 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QBean.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QBean.java @@ -18,6 +18,7 @@ import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; +import java.io.Serial; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -45,16 +46,14 @@ */ public class QBean extends FactoryExpressionBase { - private static final long serialVersionUID = -8210214512730989778L; + @Serial private static final long serialVersionUID = -8210214512730989778L; private static Map> createBindings(Expression... args) { Map> rv = new LinkedHashMap<>(); for (Expression expr : args) { - if (expr instanceof Path) { - Path path = (Path) expr; + if (expr instanceof Path path) { rv.put(path.getMetadata().getName(), expr); - } else if (expr instanceof Operation) { - Operation operation = (Operation) expr; + } else if (expr instanceof Operation operation) { if (operation.getOperator() == Ops.ALIAS && operation.getArg(1) instanceof Path) { Path path = (Path) operation.getArg(1); if (isCompoundExpression(operation.getArg(0))) { @@ -275,8 +274,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof QBean) { - QBean c = (QBean) obj; + } else if (obj instanceof QBean c) { return getArgs().equals(c.getArgs()) && getType().equals(c.getType()); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QList.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QList.java index ec82ca5cee..9f3b8a5fa6 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QList.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QList.java @@ -14,6 +14,7 @@ package com.querydsl.core.types; import com.querydsl.core.util.CollectionUtils; +import java.io.Serial; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -28,7 +29,7 @@ */ public class QList extends FactoryExpressionBase> { - private static final long serialVersionUID = -7545994090073480810L; + @Serial private static final long serialVersionUID = -7545994090073480810L; @Unmodifiable private final List> args; @@ -85,8 +86,7 @@ public List> getArgs() { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof FactoryExpression) { - FactoryExpression c = (FactoryExpression) obj; + } else if (obj instanceof FactoryExpression c) { return args.equals(c.getArgs()) && getType().equals(c.getType()); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QMap.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QMap.java index 6cec693164..cae52c67b7 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QMap.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QMap.java @@ -14,6 +14,7 @@ package com.querydsl.core.types; import com.querydsl.core.util.CollectionUtils; +import java.io.Serial; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -40,7 +41,7 @@ */ public class QMap extends FactoryExpressionBase, ?>> { - private static final long serialVersionUID = -7545994090073480810L; + @Serial private static final long serialVersionUID = -7545994090073480810L; @Unmodifiable private final List> args; @@ -97,8 +98,7 @@ public List> getArgs() { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof FactoryExpression) { - FactoryExpression c = (FactoryExpression) obj; + } else if (obj instanceof FactoryExpression c) { return args.equals(c.getArgs()) && getType().equals(c.getType()); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QTuple.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QTuple.java index 7e20b1ce5a..15f2011b49 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QTuple.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/QTuple.java @@ -16,6 +16,7 @@ import com.querydsl.core.Tuple; import com.querydsl.core.annotations.Immutable; import com.querydsl.core.util.CollectionUtils; +import java.io.Serial; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; @@ -58,8 +59,8 @@ private static Map, Integer> createBindings(List> ex Map, Integer> map = new LinkedHashMap<>(); for (var i = 0; i < exprs.size(); i++) { Expression e = exprs.get(i); - if (e instanceof Operation && ((Operation) e).getOperator() == Ops.ALIAS) { - map.put(((Operation) e).getArg(1), i); + if (e instanceof Operation operation && operation.getOperator() == Ops.ALIAS) { + map.put(operation.getArg(1), i); } map.put(e, i); } @@ -68,7 +69,7 @@ private static Map, Integer> createBindings(List> ex private final class TupleImpl implements Tuple, Serializable { - private static final long serialVersionUID = 6635924689293325950L; + @Serial private static final long serialVersionUID = 6635924689293325950L; private final Object[] a; @@ -107,8 +108,8 @@ public Object[] toArray() { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof Tuple) { - return Arrays.equals(a, ((Tuple) obj).toArray()); + } else if (obj instanceof Tuple tuple) { + return Arrays.equals(a, tuple.toArray()); } else { return false; } @@ -125,7 +126,7 @@ public String toString() { } } - private static final long serialVersionUID = -2640616030595420465L; + @Serial private static final long serialVersionUID = -2640616030595420465L; @Unmodifiable private final List> args; @@ -180,8 +181,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof FactoryExpression) { - FactoryExpression c = (FactoryExpression) obj; + } else if (obj instanceof FactoryExpression c) { return args.equals(c.getArgs()) && getType().equals(c.getType()); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/SimpleDTOProjection.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/SimpleDTOProjection.java index cb1e62ee61..a7c54d4981 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/SimpleDTOProjection.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/SimpleDTOProjection.java @@ -26,8 +26,8 @@ private List> generateExpressions( Field entityField = entity.getClass().getField(fieldName); if (entityField != null) { Object value = entityField.get(entity); - if (value instanceof Expression) { - expressions.add((Expression) value); + if (value instanceof Expression expression) { + expressions.add(expression); } } } catch (NoSuchFieldException | IllegalAccessException e) { diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/SubQueryExpressionImpl.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/SubQueryExpressionImpl.java index f7a4986c06..385c13c96b 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/SubQueryExpressionImpl.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/SubQueryExpressionImpl.java @@ -15,6 +15,7 @@ import com.querydsl.core.QueryMetadata; import com.querydsl.core.annotations.Immutable; +import java.io.Serial; /** * {@code SubQueryExpressionImpl} is the default implementation of the {@link SubQueryExpression} @@ -26,7 +27,7 @@ @Immutable public class SubQueryExpressionImpl extends ExpressionBase implements SubQueryExpression { - private static final long serialVersionUID = 6775967804458163L; + @Serial private static final long serialVersionUID = 6775967804458163L; private final QueryMetadata metadata; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/Template.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/Template.java index 249ffddb1b..9e9e454d04 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/Template.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/Template.java @@ -17,6 +17,7 @@ import com.querydsl.core.types.dsl.Expressions; import com.querydsl.core.util.CollectionUtils; import com.querydsl.core.util.MathUtils; +import java.io.Serial; import java.io.Serializable; import java.math.BigDecimal; import java.util.Collections; @@ -34,7 +35,7 @@ @Immutable public final class Template implements Serializable { - private static final long serialVersionUID = -1697705745769542204L; + @Serial private static final long serialVersionUID = -1697705745769542204L; private static final Set CONVERTIBLES = Collections.unmodifiableSet(EnumSet.of(Ops.ADD, Ops.SUB)); @@ -43,7 +44,7 @@ public final class Template implements Serializable { @Immutable public abstract static class Element implements Serializable { - private static final long serialVersionUID = 3396877288101929387L; + @Serial private static final long serialVersionUID = 3396877288101929387L; public abstract Object convert(List args); @@ -53,7 +54,7 @@ public abstract static class Element implements Serializable { /** Expression as string */ public static final class AsString extends Element { - private static final long serialVersionUID = -655362047873616197L; + @Serial private static final long serialVersionUID = -655362047873616197L; private final int index; @@ -88,7 +89,7 @@ public String toString() { /** Static text element */ public static final class StaticText extends Element { - private static final long serialVersionUID = -2791869625053368023L; + @Serial private static final long serialVersionUID = -2791869625053368023L; private final String text; @@ -122,7 +123,7 @@ public String toString() { /** Transformed expression */ public static final class Transformed extends Element { - private static final long serialVersionUID = 702677732175745567L; + @Serial private static final long serialVersionUID = 702677732175745567L; private final int index; @@ -159,7 +160,7 @@ public String toString() { /** Argument by index */ public static final class ByIndex extends Element { - private static final long serialVersionUID = 4711323946026029998L; + @Serial private static final long serialVersionUID = 4711323946026029998L; private final int index; @@ -173,8 +174,8 @@ public ByIndex(int index) { @Override public Object convert(final List args) { final Object arg = args.get(index); - if (arg instanceof Expression) { - return ExpressionUtils.extract((Expression) arg); + if (arg instanceof Expression expression) { + return ExpressionUtils.extract(expression); } else { return arg; } @@ -198,7 +199,7 @@ public String toString() { /** Math operation */ public static final class Operation extends Element { - private static final long serialVersionUID = 1400801176778801584L; + @Serial private static final long serialVersionUID = 1400801176778801584L; private final int index1, index2; @@ -223,20 +224,19 @@ public Object convert(List args) { Expression expr1 = asExpression(arg1); Expression expr2 = asExpression(arg2); - if (arg2 instanceof Number) { + if (arg2 instanceof Number number) { if (CONVERTIBLES.contains(operator) - && expr1 instanceof com.querydsl.core.types.Operation) { - var operation = (com.querydsl.core.types.Operation) expr1; + && expr1 instanceof com.querydsl.core.types.Operation operation) { if (CONVERTIBLES.contains(operation.getOperator()) && operation.getArg(1) instanceof Constant) { var num1 = ((Constant) operation.getArg(1)).getConstant(); Number num2; if (operator == operation.getOperator()) { - num2 = MathUtils.result(num1, (Number) arg2, Ops.ADD); + num2 = MathUtils.result(num1, number, Ops.ADD); } else if (operator == Ops.ADD) { - num2 = MathUtils.result((Number) arg2, num1, Ops.SUB); + num2 = MathUtils.result(number, num1, Ops.SUB); } else { - num2 = MathUtils.result(num1, (Number) arg2, Ops.SUB); + num2 = MathUtils.result(num1, number, Ops.SUB); } return ExpressionUtils.operation( expr1.getType(), operator, operation.getArg(0), Expressions.constant(num2)); @@ -262,7 +262,7 @@ public String toString() { /** Math operation with constant */ public static final class OperationConst extends Element { - private static final long serialVersionUID = 1400801176778801584L; + @Serial private static final long serialVersionUID = 1400801176778801584L; private final int index1; @@ -295,8 +295,8 @@ public Object convert(List args) { } else { Expression expr1 = asExpression(arg1); - if (CONVERTIBLES.contains(operator) && expr1 instanceof com.querydsl.core.types.Operation) { - var operation = (com.querydsl.core.types.Operation) expr1; + if (CONVERTIBLES.contains(operator) + && expr1 instanceof com.querydsl.core.types.Operation operation) { if (CONVERTIBLES.contains(operation.getOperator()) && operation.getArg(1) instanceof Constant) { var num1 = ((Constant) operation.getArg(1)).getConstant(); @@ -350,8 +350,8 @@ public String toString() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Template) { - return ((Template) o).template.equals(template); + } else if (o instanceof Template template1) { + return template1.template.equals(template); } else { return false; } @@ -363,23 +363,22 @@ public int hashCode() { } private static Number asNumber(Object arg) { - if (arg instanceof Number) { - return (Number) arg; - } else if (arg instanceof Constant) { - return (Number) ((Constant) arg).getConstant(); + if (arg instanceof Number number) { + return number; + } else if (arg instanceof Constant constant) { + return (Number) constant.getConstant(); } else { throw new IllegalArgumentException(arg.toString()); } } private static boolean isNumber(Object o) { - return o instanceof Number - || o instanceof Constant && ((Constant) o).getConstant() instanceof Number; + return o instanceof Number || o instanceof Constant c && c.getConstant() instanceof Number; } private static Expression asExpression(Object arg) { - if (arg instanceof Expression) { - return ExpressionUtils.extract((Expression) arg); + if (arg instanceof Expression expression) { + return ExpressionUtils.extract(expression); } else { return Expressions.constant(arg); } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/TemplateExpressionImpl.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/TemplateExpressionImpl.java index 6d48e69775..7e96303fe2 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/TemplateExpressionImpl.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/TemplateExpressionImpl.java @@ -15,6 +15,7 @@ import com.querydsl.core.annotations.Immutable; import com.querydsl.core.util.CollectionUtils; +import java.io.Serial; import java.util.Arrays; import java.util.List; import org.jetbrains.annotations.Unmodifiable; @@ -28,7 +29,7 @@ @Immutable public class TemplateExpressionImpl extends ExpressionBase implements TemplateExpression { - private static final long serialVersionUID = 6951623726800809083L; + @Serial private static final long serialVersionUID = 6951623726800809083L; @Unmodifiable private final List args; @@ -64,8 +65,7 @@ public final Template getTemplate() { public final boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof TemplateExpression) { - TemplateExpression c = (TemplateExpression) o; + } else if (o instanceof TemplateExpression c) { return c.getTemplate().equals(template) && c.getType().equals(getType()) && c.getArgs().equals(args); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/TemplateFactory.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/TemplateFactory.java index 3e07b0b9db..787cdb9dbd 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/TemplateFactory.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/TemplateFactory.java @@ -50,12 +50,14 @@ public class TemplateFactory { private static final Pattern elementPattern = Pattern.compile( - "\\{" - + "(%?%?)" - + "(\\d+)" - + "(?:([+-/*])(?:(\\d+)|'(-?\\d+(?:\\.\\d+)?)'))?" - + "([slu%]?%?)" - + "\\}"); + """ + \\{\ + (%?%?)\ + (\\d+)\ + (?:([+-/*])(?:(\\d+)|'(-?\\d+(?:\\.\\d+)?)'))?\ + ([slu%]?%?)\ + \\}\ + """); private final Map cache = Collections.synchronizedMap(new WeakHashMap<>()); @@ -67,8 +69,8 @@ public class TemplateFactory { public Object apply(Object arg) { if (arg instanceof Constant) { return ConstantImpl.create(apply(arg.toString()).toString()); - } else if (arg instanceof Expression) { - return ExpressionUtils.operation(String.class, Ops.LOWER, (Expression) arg); + } else if (arg instanceof Expression expression) { + return ExpressionUtils.operation(String.class, Ops.LOWER, expression); } else { return String.valueOf(arg).toLowerCase(); } @@ -81,8 +83,8 @@ public Object apply(Object arg) { public Object apply(Object arg) { if (arg instanceof Constant) { return ConstantImpl.create(apply(arg.toString()).toString()); - } else if (arg instanceof Expression) { - return ExpressionUtils.operation(String.class, Ops.UPPER, (Expression) arg); + } else if (arg instanceof Expression expression) { + return ExpressionUtils.operation(String.class, Ops.UPPER, expression); } else { return String.valueOf(arg).toUpperCase(); } @@ -95,8 +97,8 @@ public Object apply(Object arg) { public Object apply(Object arg) { if (arg instanceof Constant) { return ConstantImpl.create(apply(arg.toString()).toString()); - } else if (arg instanceof Expression) { - return ExpressionUtils.operation(String.class, Ops.CONCAT, (Expression) arg, PERCENT); + } else if (arg instanceof Expression expression) { + return ExpressionUtils.operation(String.class, Ops.CONCAT, expression, PERCENT); } else { return escapeForLike(String.valueOf(arg)) + "%"; } @@ -109,9 +111,9 @@ public Object apply(Object arg) { public Object apply(Object arg) { if (arg instanceof Constant) { return ConstantImpl.create(apply(arg.toString()).toString()); - } else if (arg instanceof Expression) { + } else if (arg instanceof Expression expression) { Expression concatenated = - ExpressionUtils.operation(String.class, Ops.CONCAT, (Expression) arg, PERCENT); + ExpressionUtils.operation(String.class, Ops.CONCAT, expression, PERCENT); return ExpressionUtils.operation(String.class, Ops.LOWER, concatenated); } else { return escapeForLike(String.valueOf(arg).toLowerCase()) + "%"; @@ -125,8 +127,8 @@ public Object apply(Object arg) { public Object apply(Object arg) { if (arg instanceof Constant) { return ConstantImpl.create(apply(arg.toString()).toString()); - } else if (arg instanceof Expression) { - return ExpressionUtils.operation(String.class, Ops.CONCAT, PERCENT, (Expression) arg); + } else if (arg instanceof Expression expression) { + return ExpressionUtils.operation(String.class, Ops.CONCAT, PERCENT, expression); } else { return "%" + escapeForLike(String.valueOf(arg)); } @@ -139,9 +141,9 @@ public Object apply(Object arg) { public Object apply(Object arg) { if (arg instanceof Constant) { return ConstantImpl.create(apply(arg.toString()).toString()); - } else if (arg instanceof Expression) { + } else if (arg instanceof Expression expression) { Expression concatenated = - ExpressionUtils.operation(String.class, Ops.CONCAT, PERCENT, (Expression) arg); + ExpressionUtils.operation(String.class, Ops.CONCAT, PERCENT, expression); return ExpressionUtils.operation(String.class, Ops.LOWER, concatenated); } else { return "%" + escapeForLike(String.valueOf(arg).toLowerCase()); @@ -155,9 +157,9 @@ public Object apply(Object arg) { public Object apply(Object arg) { if (arg instanceof Constant) { return ConstantImpl.create(apply(arg.toString()).toString()); - } else if (arg instanceof Expression) { + } else if (arg instanceof Expression expression) { Expression concatenated = - ExpressionUtils.operation(String.class, Ops.CONCAT, PERCENT, (Expression) arg); + ExpressionUtils.operation(String.class, Ops.CONCAT, PERCENT, expression); return ExpressionUtils.operation(String.class, Ops.CONCAT, concatenated, PERCENT); } else { return "%" + escapeForLike(String.valueOf(arg)) + "%"; @@ -171,9 +173,9 @@ public Object apply(Object arg) { public Object apply(Object arg) { if (arg instanceof Constant) { return ConstantImpl.create(apply(arg.toString()).toString()); - } else if (arg instanceof Expression) { + } else if (arg instanceof Expression expression) { Expression concatenated = - ExpressionUtils.operation(String.class, Ops.CONCAT, PERCENT, (Expression) arg); + ExpressionUtils.operation(String.class, Ops.CONCAT, PERCENT, expression); concatenated = ExpressionUtils.operation(String.class, Ops.CONCAT, concatenated, PERCENT); return ExpressionUtils.operation(String.class, Ops.LOWER, concatenated); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ToStringVisitor.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ToStringVisitor.java index 4a5614c7c7..af2ae936b5 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ToStringVisitor.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ToStringVisitor.java @@ -51,22 +51,22 @@ public String visit(FactoryExpression e, Templates templates) { @Override public String visit(Operation o, Templates templates) { - final Template template = templates.getTemplate(o.getOperator()); + final var template = templates.getTemplate(o.getOperator()); if (template != null) { final var precedence = templates.getPrecedence(o.getOperator()); final var builder = new StringBuilder(); for (Template.Element element : template.getElements()) { final var rv = element.convert(o.getArgs()); - if (rv instanceof Expression) { - if (precedence > -1 && rv instanceof Operation) { - if (precedence < templates.getPrecedence(((Operation) rv).getOperator())) { + if (rv instanceof Expression expression) { + if (precedence > -1 && rv instanceof Operation operation) { + if (precedence < templates.getPrecedence(operation.getOperator())) { builder.append("("); - builder.append(((Expression) rv).accept(this, templates)); + builder.append(operation.accept(this, templates)); builder.append(")"); continue; } } - builder.append(((Expression) rv).accept(this, templates)); + builder.append(expression.accept(this, templates)); } else { builder.append(rv.toString()); } @@ -90,14 +90,14 @@ public String visit(Path p, Templates templates) { final Path parent = p.getMetadata().getParent(); final var elem = p.getMetadata().getElement(); if (parent != null) { - Template pattern = templates.getTemplate(p.getMetadata().getPathType()); + var pattern = templates.getTemplate(p.getMetadata().getPathType()); if (pattern != null) { final List args = Arrays.asList(parent, elem); final var builder = new StringBuilder(); for (Template.Element element : pattern.getElements()) { var rv = element.convert(args); - if (rv instanceof Expression) { - builder.append(((Expression) rv).accept(this, templates)); + if (rv instanceof Expression expression) { + builder.append(expression.accept(this, templates)); } else { builder.append(rv.toString()); } @@ -121,8 +121,8 @@ public String visit(TemplateExpression expr, Templates templates) { final var builder = new StringBuilder(); for (Template.Element element : expr.getTemplate().getElements()) { var rv = element.convert(expr.getArgs()); - if (rv instanceof Expression) { - builder.append(((Expression) rv).accept(this, templates)); + if (rv instanceof Expression expression) { + builder.append(expression.accept(this, templates)); } else { builder.append(rv.toString()); } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ValidatingVisitor.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ValidatingVisitor.java index a706b05d6b..d90246503d 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ValidatingVisitor.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ValidatingVisitor.java @@ -16,6 +16,7 @@ import static com.querydsl.core.util.CollectionUtils.add; import com.querydsl.core.JoinExpression; +import java.io.Serial; import java.io.Serializable; import java.util.Set; @@ -27,7 +28,7 @@ public final class ValidatingVisitor implements Visitor>, Set>>, Serializable { - private static final long serialVersionUID = 691350069621050872L; + @Serial private static final long serialVersionUID = 691350069621050872L; public static final ValidatingVisitor DEFAULT = new ValidatingVisitor(); @@ -74,7 +75,7 @@ public Set> visit(ParamExpression expr, Set> know @Override public Set> visit(Path expr, Set> known) { if (!known.contains(expr.getRoot())) { - throw new IllegalArgumentException(String.format(errorTemplate, expr.getRoot())); + throw new IllegalArgumentException(errorTemplate.formatted(expr.getRoot())); } return known; } @@ -105,8 +106,8 @@ public Set> visit(SubQueryExpression expr, Set> k @Override public Set> visit(TemplateExpression expr, Set> known) { for (Object arg : expr.getArgs()) { - if (arg instanceof Expression) { - known = ((Expression) arg).accept(this, known); + if (arg instanceof Expression expression) { + known = expression.accept(this, known); } } return known; @@ -115,7 +116,7 @@ public Set> visit(TemplateExpression expr, Set> k private Set> visitJoins(Iterable joins, Set> known) { for (JoinExpression j : joins) { final Expression expr = j.getTarget(); - if (expr instanceof Path && ((Path) expr).getMetadata().isRoot()) { + if (expr instanceof Path path && path.getMetadata().isRoot()) { known = add(known, expr); } else { known = expr.accept(this, known); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ArrayPath.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ArrayPath.java index 03e8406626..d10a10384d 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ArrayPath.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ArrayPath.java @@ -22,6 +22,7 @@ import com.querydsl.core.types.PathMetadataFactory; import com.querydsl.core.types.Visitor; import com.querydsl.core.util.PrimitiveUtils; +import java.io.Serial; import java.lang.reflect.AnnotatedElement; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Range; @@ -35,7 +36,7 @@ */ public class ArrayPath extends SimpleExpression implements Path, ArrayExpression { - private static final long serialVersionUID = 7795049264874048226L; + @Serial private static final long serialVersionUID = 7795049264874048226L; private final Class componentType; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BeanPath.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BeanPath.java index 091cf34161..99506e2421 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BeanPath.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BeanPath.java @@ -23,6 +23,7 @@ import com.querydsl.core.types.PathMetadataFactory; import com.querydsl.core.types.PathType; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.InvocationTargetException; import java.util.Map; @@ -37,7 +38,7 @@ */ public class BeanPath extends SimpleExpression implements Path { - private static final long serialVersionUID = -1845524024957822731L; + @Serial private static final long serialVersionUID = -1845524024957822731L; private final Map, Object> casts = new ConcurrentHashMap<>(); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BooleanExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BooleanExpression.java index 241322f2a0..1c31d2d0c0 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BooleanExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BooleanExpression.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.Ops; import com.querydsl.core.types.Path; import com.querydsl.core.types.Predicate; +import java.io.Serial; import org.jetbrains.annotations.Nullable; /** @@ -29,7 +30,7 @@ */ public abstract class BooleanExpression extends LiteralExpression implements Predicate { - private static final long serialVersionUID = 3797956062512074164L; + @Serial private static final long serialVersionUID = 3797956062512074164L; @Nullable private transient volatile BooleanExpression eqTrue, eqFalse; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BooleanOperation.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BooleanOperation.java index bacafc436b..d848107e93 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BooleanOperation.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BooleanOperation.java @@ -20,6 +20,7 @@ import com.querydsl.core.types.Ops; import com.querydsl.core.types.PredicateOperation; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.Arrays; import java.util.List; @@ -30,7 +31,7 @@ */ public class BooleanOperation extends BooleanExpression implements Operation { - private static final long serialVersionUID = 7432281499861357581L; + @Serial private static final long serialVersionUID = 7432281499861357581L; private final PredicateOperation opMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BooleanPath.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BooleanPath.java index 97eac38b7f..50952a620b 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BooleanPath.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BooleanPath.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.PathMetadata; import com.querydsl.core.types.PathMetadataFactory; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.lang.reflect.AnnotatedElement; /** @@ -29,7 +30,7 @@ */ public class BooleanPath extends BooleanExpression implements Path { - private static final long serialVersionUID = 6590516706769430565L; + @Serial private static final long serialVersionUID = 6590516706769430565L; private final PathImpl pathMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BooleanTemplate.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BooleanTemplate.java index b19cb893d4..2cd37afafa 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BooleanTemplate.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BooleanTemplate.java @@ -18,6 +18,7 @@ import com.querydsl.core.types.Template; import com.querydsl.core.types.TemplateExpression; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.List; /** @@ -27,7 +28,7 @@ */ public class BooleanTemplate extends BooleanExpression implements TemplateExpression { - private static final long serialVersionUID = 5749369427497731719L; + @Serial private static final long serialVersionUID = 5749369427497731719L; private final PredicateTemplate templateMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CaseBuilder.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CaseBuilder.java index a6b9ea83ed..78bea33593 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CaseBuilder.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CaseBuilder.java @@ -158,20 +158,20 @@ public Initial(Predicate b) { @SuppressWarnings("unchecked") public Cases> then(Expression expr) { - if (expr instanceof Predicate) { - return (Cases) then((Predicate) expr); - } else if (expr instanceof StringExpression) { - return (Cases) then((StringExpression) expr); - } else if (expr instanceof NumberExpression) { - return then((NumberExpression) expr); - } else if (expr instanceof DateExpression) { - return then((DateExpression) expr); - } else if (expr instanceof DateTimeExpression) { - return then((DateTimeExpression) expr); - } else if (expr instanceof TimeExpression) { - return then((TimeExpression) expr); - } else if (expr instanceof ComparableExpression) { - return then((ComparableExpression) expr); + if (expr instanceof Predicate predicate) { + return (Cases) then(predicate); + } else if (expr instanceof StringExpression se) { + return (Cases) then(se); + } else if (expr instanceof NumberExpression ne) { + return then(ne); + } else if (expr instanceof DateExpression de) { + return then(de); + } else if (expr instanceof DateTimeExpression dte) { + return then(dte); + } else if (expr instanceof TimeExpression te) { + return then(te); + } else if (expr instanceof ComparableExpression ce) { + return then(ce); } else { return thenSimple(expr); } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CaseForEqBuilder.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CaseForEqBuilder.java index 25ac608961..87adfe554f 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CaseForEqBuilder.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CaseForEqBuilder.java @@ -76,20 +76,20 @@ public CaseForEqBuilder(Expression base, Expression other) { } public Cases> then(Expression expr) { - if (expr instanceof Predicate) { - return (Cases) then((Predicate) expr); - } else if (expr instanceof StringExpression) { - return (Cases) then((StringExpression) expr); - } else if (expr instanceof NumberExpression) { - return then((NumberExpression) expr); - } else if (expr instanceof DateExpression) { - return then((DateExpression) expr); - } else if (expr instanceof DateTimeExpression) { - return then((DateTimeExpression) expr); - } else if (expr instanceof TimeExpression) { - return then((TimeExpression) expr); - } else if (expr instanceof ComparableExpression) { - return then((ComparableExpression) expr); + if (expr instanceof Predicate p) { + return (Cases) then(p); + } else if (expr instanceof StringExpression se) { + return (Cases) then(se); + } else if (expr instanceof NumberExpression ne) { + return then(ne); + } else if (expr instanceof DateExpression de) { + return then(de); + } else if (expr instanceof DateTimeExpression dte) { + return then(dte); + } else if (expr instanceof TimeExpression te) { + return then(te); + } else if (expr instanceof ComparableExpression ce) { + return then(ce); } else { return thenSimple(expr); } diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Coalesce.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Coalesce.java index d423015dd8..37504120cb 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Coalesce.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Coalesce.java @@ -21,6 +21,7 @@ import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.Path; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.ArrayList; import java.util.List; @@ -37,7 +38,7 @@ @SuppressWarnings("unchecked") public class Coalesce extends MutableExpressionBase { - private static final long serialVersionUID = 445439522266250417L; + @Serial private static final long serialVersionUID = 445439522266250417L; private final List> exprs = new ArrayList<>(); @@ -145,8 +146,7 @@ private Expression getExpressionList() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Coalesce) { - Coalesce c = (Coalesce) o; + } else if (o instanceof Coalesce c) { return c.exprs.equals(exprs); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CollectionExpressionBase.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CollectionExpressionBase.java index 07a21a60c8..83bf80985e 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CollectionExpressionBase.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CollectionExpressionBase.java @@ -18,6 +18,7 @@ import com.querydsl.core.types.EntityPath; import com.querydsl.core.types.Expression; import com.querydsl.core.types.Ops; +import java.io.Serial; import java.util.Collection; import org.jetbrains.annotations.Nullable; @@ -32,7 +33,7 @@ public abstract class CollectionExpressionBase, E> extends DslExpression implements CollectionExpression { - private static final long serialVersionUID = 691230660037162054L; + @Serial private static final long serialVersionUID = 691230660037162054L; @Nullable private transient volatile BooleanExpression empty; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CollectionOperation.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CollectionOperation.java index 11cf212062..1bbea3a9ac 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CollectionOperation.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CollectionOperation.java @@ -18,6 +18,7 @@ import com.querydsl.core.types.OperationImpl; import com.querydsl.core.types.Operator; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -31,7 +32,7 @@ */ public class CollectionOperation extends CollectionExpressionBase, E> { - private static final long serialVersionUID = 3154315192589335574L; + @Serial private static final long serialVersionUID = 3154315192589335574L; private final Class elementType; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CollectionPath.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CollectionPath.java index f5d2d47b65..052b173a24 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CollectionPath.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CollectionPath.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.PathMetadata; import com.querydsl.core.types.PathMetadataFactory; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.lang.reflect.AnnotatedElement; import java.util.Collection; import org.jetbrains.annotations.Nullable; @@ -33,7 +34,7 @@ public class CollectionPath> extends CollectionPathBase, E, Q> { - private static final long serialVersionUID = -4982311799113762600L; + @Serial private static final long serialVersionUID = -4982311799113762600L; private final Class elementType; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CollectionPathBase.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CollectionPathBase.java index f8a474ca72..e953ac2f5c 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CollectionPathBase.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CollectionPathBase.java @@ -17,6 +17,7 @@ import com.querydsl.core.types.Path; import com.querydsl.core.types.PathImpl; import com.querydsl.core.types.PathMetadata; +import java.io.Serial; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Collection; @@ -34,7 +35,7 @@ public abstract class CollectionPathBase< C extends Collection, E, Q extends SimpleExpression> extends CollectionExpressionBase implements Path { - private static final long serialVersionUID = -9004995667633601298L; + @Serial private static final long serialVersionUID = -9004995667633601298L; @Nullable private transient volatile Constructor constructor; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableEntityPath.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableEntityPath.java index 80a4ae6849..d930fd4d9e 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableEntityPath.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableEntityPath.java @@ -16,6 +16,7 @@ import com.querydsl.core.types.EntityPath; import com.querydsl.core.types.Path; import com.querydsl.core.types.PathMetadata; +import java.io.Serial; /** * {@code ComparableEntityPath} extends the {@link ComparablePath} class to implement the EntityPath @@ -28,7 +29,7 @@ public class ComparableEntityPath extends ComparablePath implements EntityPath { - private static final long serialVersionUID = -7115848171352092315L; + @Serial private static final long serialVersionUID = -7115848171352092315L; protected ComparableEntityPath(Class type, Path parent, String property) { super(type, parent, property); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableExpression.java index 21808d7c16..dd8d2fbda4 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableExpression.java @@ -20,6 +20,7 @@ import com.querydsl.core.types.Ops; import com.querydsl.core.types.Path; import com.querydsl.core.types.SubQueryExpression; +import java.io.Serial; import org.jetbrains.annotations.Nullable; /** @@ -32,7 +33,7 @@ public abstract class ComparableExpression extends ComparableExpressionBase { - private static final long serialVersionUID = 5761359576767404270L; + @Serial private static final long serialVersionUID = 5761359576767404270L; public ComparableExpression(Expression mixin) { super(mixin); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableExpressionBase.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableExpressionBase.java index 565914274a..9b790ae197 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableExpressionBase.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableExpressionBase.java @@ -18,6 +18,7 @@ import com.querydsl.core.types.Ops; import com.querydsl.core.types.Order; import com.querydsl.core.types.OrderSpecifier; +import java.io.Serial; import org.jetbrains.annotations.Nullable; /** @@ -29,7 +30,7 @@ */ public abstract class ComparableExpressionBase extends SimpleExpression { - private static final long serialVersionUID = 1460921109546656911L; + @Serial private static final long serialVersionUID = 1460921109546656911L; @Nullable private transient volatile OrderSpecifier asc, desc; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableOperation.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableOperation.java index 1af893d674..811ed9b479 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableOperation.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableOperation.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.OperationImpl; import com.querydsl.core.types.Operator; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.Arrays; import java.util.List; @@ -31,7 +32,7 @@ public class ComparableOperation> extends ComparableExpression implements Operation { - private static final long serialVersionUID = 1129243977606098865L; + @Serial private static final long serialVersionUID = 1129243977606098865L; private final OperationImpl opMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparablePath.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparablePath.java index 2c184b5c14..2f92068bdf 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparablePath.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparablePath.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.PathMetadata; import com.querydsl.core.types.PathMetadataFactory; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.lang.reflect.AnnotatedElement; /** @@ -32,7 +33,7 @@ public class ComparablePath extends ComparableExpression implements Path { - private static final long serialVersionUID = -7434767743611671666L; + @Serial private static final long serialVersionUID = -7434767743611671666L; private final PathImpl pathMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableTemplate.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableTemplate.java index ca73015c45..4f08a59349 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableTemplate.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ComparableTemplate.java @@ -18,6 +18,7 @@ import com.querydsl.core.types.TemplateExpression; import com.querydsl.core.types.TemplateExpressionImpl; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.List; /** @@ -29,7 +30,7 @@ public class ComparableTemplate> extends ComparableExpression implements TemplateExpression { - private static final long serialVersionUID = -6292853402028813007L; + @Serial private static final long serialVersionUID = -6292853402028813007L; private final TemplateExpressionImpl templateMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateExpression.java index f0fb4247a0..2931a93739 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateExpression.java @@ -18,6 +18,7 @@ import com.querydsl.core.types.ExpressionUtils; import com.querydsl.core.types.Ops; import com.querydsl.core.types.Path; +import java.io.Serial; import java.util.Date; import org.jetbrains.annotations.Nullable; @@ -35,7 +36,7 @@ private static class Constants { private static final DateExpression CURRENT_DATE = currentDate(Date.class); } - private static final long serialVersionUID = 6054664454254721302L; + @Serial private static final long serialVersionUID = 6054664454254721302L; /** * Create an expression representing the current date as a {@code DateExpression} instance diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateOperation.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateOperation.java index 6bdcbf2851..b691e4d4ff 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateOperation.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateOperation.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.OperationImpl; import com.querydsl.core.types.Operator; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.Arrays; import java.util.List; @@ -31,7 +32,7 @@ public class DateOperation> extends DateExpression implements Operation { - private static final long serialVersionUID = -7859020164194396995L; + @Serial private static final long serialVersionUID = -7859020164194396995L; private final OperationImpl opMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DatePath.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DatePath.java index e7159995bb..12a6468434 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DatePath.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DatePath.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.PathMetadata; import com.querydsl.core.types.PathMetadataFactory; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.lang.reflect.AnnotatedElement; /** @@ -30,7 +31,7 @@ @SuppressWarnings({"unchecked"}) public class DatePath extends DateExpression implements Path { - private static final long serialVersionUID = -6030609920388740246L; + @Serial private static final long serialVersionUID = -6030609920388740246L; private final PathImpl pathMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTemplate.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTemplate.java index f10013f2ac..fee6610301 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTemplate.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTemplate.java @@ -18,6 +18,7 @@ import com.querydsl.core.types.TemplateExpression; import com.querydsl.core.types.TemplateExpressionImpl; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.List; /** @@ -29,7 +30,7 @@ public class DateTemplate> extends DateExpression implements TemplateExpression { - private static final long serialVersionUID = 4975559746071238026L; + @Serial private static final long serialVersionUID = 4975559746071238026L; private final TemplateExpressionImpl templateMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTimeExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTimeExpression.java index a0efb84f2d..a604390f2e 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTimeExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTimeExpression.java @@ -15,6 +15,7 @@ import com.querydsl.core.types.ExpressionUtils; import com.querydsl.core.types.Ops; import com.querydsl.core.types.Path; +import java.io.Serial; import java.util.Date; import org.jetbrains.annotations.Nullable; @@ -33,7 +34,7 @@ private static class Constants { private static final DateTimeExpression CURRENT_TIMESTAMP = currentTimestamp(Date.class); } - private static final long serialVersionUID = -6879277113694148047L; + @Serial private static final long serialVersionUID = -6879277113694148047L; /** * Create an expression representing the current date as a DateTimeExpression instance diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTimeOperation.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTimeOperation.java index 3b282c773d..eebfd1be2a 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTimeOperation.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTimeOperation.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.OperationImpl; import com.querydsl.core.types.Operator; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.Arrays; import java.util.List; @@ -31,7 +32,7 @@ public class DateTimeOperation> extends DateTimeExpression implements Operation { - private static final long serialVersionUID = 6523293814317168556L; + @Serial private static final long serialVersionUID = 6523293814317168556L; private final OperationImpl opMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTimePath.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTimePath.java index 3a2d0b7040..64594f9181 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTimePath.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTimePath.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.PathMetadata; import com.querydsl.core.types.PathMetadataFactory; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.lang.reflect.AnnotatedElement; /** @@ -29,7 +30,7 @@ */ public class DateTimePath extends DateTimeExpression implements Path { - private static final long serialVersionUID = -2807916228198184631L; + @Serial private static final long serialVersionUID = -2807916228198184631L; private final PathImpl pathMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTimeTemplate.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTimeTemplate.java index 3c13208871..ddc8932f5b 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTimeTemplate.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DateTimeTemplate.java @@ -18,6 +18,7 @@ import com.querydsl.core.types.TemplateExpression; import com.querydsl.core.types.TemplateExpressionImpl; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.List; /** @@ -29,7 +30,7 @@ public class DateTimeTemplate> extends DateTimeExpression implements TemplateExpression { - private static final long serialVersionUID = -2289699666347576749L; + @Serial private static final long serialVersionUID = -2289699666347576749L; private final TemplateExpressionImpl templateMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DslExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DslExpression.java index 0fb4475984..4f949ca621 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DslExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DslExpression.java @@ -17,6 +17,7 @@ import com.querydsl.core.types.ExpressionUtils; import com.querydsl.core.types.Ops; import com.querydsl.core.types.Path; +import java.io.Serial; /** * {@code DslExpression} is the base class for DSL expressions, but {@link SimpleExpression} is the @@ -27,7 +28,7 @@ */ public abstract class DslExpression implements Expression { - private static final long serialVersionUID = -3383063447710753290L; + @Serial private static final long serialVersionUID = -3383063447710753290L; protected final Expression mixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DslOperation.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DslOperation.java index 8239093599..6a326ef530 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DslOperation.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DslOperation.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.OperationImpl; import com.querydsl.core.types.Operator; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.Arrays; import java.util.List; @@ -30,7 +31,7 @@ */ public class DslOperation extends DslExpression implements Operation { - private static final long serialVersionUID = -285668548371034230L; + @Serial private static final long serialVersionUID = -285668548371034230L; private final OperationImpl opMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DslPath.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DslPath.java index abb3fb1e95..fec6f8861c 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DslPath.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DslPath.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.PathMetadata; import com.querydsl.core.types.PathMetadataFactory; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.lang.reflect.AnnotatedElement; /** @@ -29,7 +30,7 @@ */ public class DslPath extends DslExpression implements Path { - private static final long serialVersionUID = 3088836955328191852L; + @Serial private static final long serialVersionUID = 3088836955328191852L; private final PathImpl pathMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DslTemplate.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DslTemplate.java index c1f9a9d8ce..28a2955c51 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DslTemplate.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/DslTemplate.java @@ -18,6 +18,7 @@ import com.querydsl.core.types.TemplateExpression; import com.querydsl.core.types.TemplateExpressionImpl; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.List; /** @@ -28,7 +29,7 @@ */ public class DslTemplate extends DslExpression implements TemplateExpression { - private static final long serialVersionUID = -4697578522909045745L; + @Serial private static final long serialVersionUID = -4697578522909045745L; private final TemplateExpressionImpl templateMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EntityPathBase.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EntityPathBase.java index e0056fb0f6..325bd3d00e 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EntityPathBase.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EntityPathBase.java @@ -16,6 +16,7 @@ import com.querydsl.core.types.EntityPath; import com.querydsl.core.types.Path; import com.querydsl.core.types.PathMetadata; +import java.io.Serial; import org.jetbrains.annotations.Nullable; /** @@ -26,7 +27,7 @@ */ public class EntityPathBase extends BeanPath implements EntityPath { - private static final long serialVersionUID = -8610055828414880996L; + @Serial private static final long serialVersionUID = -8610055828414880996L; public EntityPathBase(Class type, String variable) { super(type, variable); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EnumExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EnumExpression.java index 6c951a712e..da3afd9aab 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EnumExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EnumExpression.java @@ -18,6 +18,7 @@ import com.querydsl.core.types.ExpressionUtils; import com.querydsl.core.types.Ops; import com.querydsl.core.types.Path; +import java.io.Serial; /** * {@code EnumExpression} represents Enum typed expressions @@ -27,7 +28,7 @@ */ public abstract class EnumExpression> extends LiteralExpression { - private static final long serialVersionUID = 8819222316513862829L; + @Serial private static final long serialVersionUID = 8819222316513862829L; private transient volatile NumberExpression ordinal; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EnumOperation.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EnumOperation.java index fa685c89ac..fab92ef32b 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EnumOperation.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EnumOperation.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.OperationImpl; import com.querydsl.core.types.Operator; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.Arrays; import java.util.List; @@ -30,7 +31,7 @@ */ public class EnumOperation> extends EnumExpression implements Operation { - private static final long serialVersionUID = -3593040852095778453L; + @Serial private static final long serialVersionUID = -3593040852095778453L; private final OperationImpl opMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EnumPath.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EnumPath.java index 5b5282b50d..c060ff6645 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EnumPath.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EnumPath.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.PathMetadata; import com.querydsl.core.types.PathMetadataFactory; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.lang.reflect.AnnotatedElement; /** @@ -29,7 +30,7 @@ */ public class EnumPath> extends EnumExpression implements Path { - private static final long serialVersionUID = 338191992784020563L; + @Serial private static final long serialVersionUID = 338191992784020563L; private final PathImpl pathMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EnumTemplate.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EnumTemplate.java index 7e8b8258ca..9ddb9ca26b 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EnumTemplate.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/EnumTemplate.java @@ -18,6 +18,7 @@ import com.querydsl.core.types.TemplateExpression; import com.querydsl.core.types.TemplateExpressionImpl; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.List; /** @@ -29,7 +30,7 @@ public class EnumTemplate> extends EnumExpression implements TemplateExpression { - private static final long serialVersionUID = 351057421752203377L; + @Serial private static final long serialVersionUID = 351057421752203377L; private final TemplateExpressionImpl templateMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Expressions.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Expressions.java index f4f6e6507b..548f90a312 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Expressions.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Expressions.java @@ -1580,10 +1580,10 @@ public static BooleanExpression asBoolean(Expression expr) { Expression underlyingMixin = ExpressionUtils.extract(expr); if (underlyingMixin instanceof PathImpl) { return new BooleanPath((PathImpl) underlyingMixin); - } else if (underlyingMixin instanceof PredicateOperation) { - return new BooleanOperation((PredicateOperation) underlyingMixin); - } else if (underlyingMixin instanceof PredicateTemplate) { - return new BooleanTemplate((PredicateTemplate) underlyingMixin); + } else if (underlyingMixin instanceof PredicateOperation operation) { + return new BooleanOperation(operation); + } else if (underlyingMixin instanceof PredicateTemplate template) { + return new BooleanTemplate(template); } else { return new BooleanExpression(underlyingMixin) { @@ -1598,8 +1598,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof BooleanExpression) { - var other = (BooleanExpression) o; + } else if (o instanceof BooleanExpression other) { return (other.mixin.equals(this.mixin)); } else { return false; @@ -1647,8 +1646,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof ComparableExpression) { - var other = (ComparableExpression) o; + } else if (o instanceof ComparableExpression other) { return (other.mixin.equals(this.mixin)); } else { return false; @@ -1807,8 +1805,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof EnumExpression) { - var other = (EnumExpression) o; + } else if (o instanceof EnumExpression other) { return (other.mixin.equals(this.mixin)); } else { return false; @@ -1857,8 +1854,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof NumberExpression) { - var other = (NumberExpression) o; + } else if (o instanceof NumberExpression other) { return (other.mixin.equals(this.mixin)); } else { return false; @@ -1906,8 +1902,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof StringExpression) { - var other = (StringExpression) o; + } else if (o instanceof StringExpression other) { return (other.mixin.equals(this.mixin)); } else { return false; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ListPath.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ListPath.java index 0c920efc12..0e2bdec830 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ListPath.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ListPath.java @@ -20,6 +20,7 @@ import com.querydsl.core.types.PathMetadata; import com.querydsl.core.types.PathMetadataFactory; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.lang.reflect.AnnotatedElement; import java.util.HashMap; import java.util.List; @@ -36,7 +37,7 @@ public class ListPath> extends CollectionPathBase, E, Q> implements ListExpression { - private static final long serialVersionUID = 3302301599074388860L; + @Serial private static final long serialVersionUID = 3302301599074388860L; private final Map cache = new HashMap<>(); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/MapExpressionBase.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/MapExpressionBase.java index 0b7e7ba5ed..f480ce8c09 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/MapExpressionBase.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/MapExpressionBase.java @@ -17,6 +17,7 @@ import com.querydsl.core.types.Expression; import com.querydsl.core.types.MapExpression; import com.querydsl.core.types.Ops; +import java.io.Serial; import java.util.Map; import org.jetbrains.annotations.Nullable; @@ -31,7 +32,7 @@ public abstract class MapExpressionBase> extends DslExpression> implements MapExpression { - private static final long serialVersionUID = 2856001983312366841L; + @Serial private static final long serialVersionUID = 2856001983312366841L; @Nullable private transient volatile NumberExpression size; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/MapPath.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/MapPath.java index 2f293e9034..67e8c8a958 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/MapPath.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/MapPath.java @@ -21,6 +21,7 @@ import com.querydsl.core.types.PathMetadata; import com.querydsl.core.types.PathMetadataFactory; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; @@ -38,7 +39,7 @@ public class MapPath> extends MapExpressionBase implements Path> { - private static final long serialVersionUID = -9113333728412016832L; + @Serial private static final long serialVersionUID = -9113333728412016832L; private final Class keyType; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/NumberExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/NumberExpression.java index 9c8f1ccc1d..244c0b4221 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/NumberExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/NumberExpression.java @@ -22,6 +22,7 @@ import com.querydsl.core.types.Path; import com.querydsl.core.types.SubQueryExpression; import com.querydsl.core.util.MathUtils; +import java.io.Serial; import java.math.BigDecimal; import java.math.BigInteger; import java.util.ArrayList; @@ -38,7 +39,7 @@ public abstract class NumberExpression> extends ComparableExpressionBase { - private static final long serialVersionUID = -5485902768703364888L; + @Serial private static final long serialVersionUID = -5485902768703364888L; private static class Constants { private static final NumberExpression RANDOM = diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/NumberOperation.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/NumberOperation.java index 43702fd602..5ecf6e4275 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/NumberOperation.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/NumberOperation.java @@ -20,6 +20,7 @@ import com.querydsl.core.types.Operator; import com.querydsl.core.types.Ops; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.Arrays; import java.util.List; @@ -32,7 +33,7 @@ public class NumberOperation> extends NumberExpression implements Operation { - private static final long serialVersionUID = -3593040852095778453L; + @Serial private static final long serialVersionUID = -3593040852095778453L; private final OperationImpl opMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/NumberPath.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/NumberPath.java index ca1aea0a0e..fccff69de5 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/NumberPath.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/NumberPath.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.PathMetadata; import com.querydsl.core.types.PathMetadataFactory; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.lang.reflect.AnnotatedElement; /** @@ -30,7 +31,7 @@ public class NumberPath> extends NumberExpression implements Path { - private static final long serialVersionUID = 338191992784020563L; + @Serial private static final long serialVersionUID = 338191992784020563L; private final PathImpl pathMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/NumberTemplate.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/NumberTemplate.java index 85b25af8cf..720136b7a8 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/NumberTemplate.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/NumberTemplate.java @@ -18,6 +18,7 @@ import com.querydsl.core.types.TemplateExpression; import com.querydsl.core.types.TemplateExpressionImpl; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.List; /** @@ -29,7 +30,7 @@ public class NumberTemplate> extends NumberExpression implements TemplateExpression { - private static final long serialVersionUID = 351057421752203377L; + @Serial private static final long serialVersionUID = 351057421752203377L; private final TemplateExpressionImpl templateMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Param.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Param.java index 1d8397d5f0..60ead8cbd3 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Param.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Param.java @@ -16,6 +16,7 @@ import com.querydsl.core.types.ParamExpression; import com.querydsl.core.types.ParamExpressionImpl; import com.querydsl.core.types.Visitor; +import java.io.Serial; /** * {@code Param} defines a parameter in a query with an optional name @@ -25,7 +26,7 @@ */ public class Param extends SimpleExpression implements ParamExpression { - private static final long serialVersionUID = -6872502615009012503L; + @Serial private static final long serialVersionUID = -6872502615009012503L; private final ParamExpression paramMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/PathBuilder.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/PathBuilder.java index 4355cf8f81..f51d20f6d8 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/PathBuilder.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/PathBuilder.java @@ -17,6 +17,7 @@ import com.querydsl.core.types.Path; import com.querydsl.core.types.PathMetadata; import com.querydsl.core.types.PathMetadataFactory; +import java.io.Serial; import java.lang.reflect.Array; import java.util.AbstractMap.SimpleEntry; import java.util.Collection; @@ -41,7 +42,7 @@ */ public class PathBuilder extends EntityPathBase { - private static final long serialVersionUID = -1666357914232685088L; + @Serial private static final long serialVersionUID = -1666357914232685088L; private final ConcurrentHashMap>, PathBuilder> properties = new ConcurrentHashMap<>(); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/PathInits.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/PathInits.java index db77b47a89..d78406d9ef 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/PathInits.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/PathInits.java @@ -14,6 +14,7 @@ package com.querydsl.core.types.dsl; import com.querydsl.core.types.PathMetadata; +import java.io.Serial; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; @@ -30,7 +31,7 @@ */ public class PathInits implements Serializable { - private static final long serialVersionUID = -2173980858324141095L; + @Serial private static final long serialVersionUID = -2173980858324141095L; public static final PathInits DEFAULT = new PathInits(); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SetPath.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SetPath.java index e12ac0f46e..98ae625e18 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SetPath.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SetPath.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.PathMetadata; import com.querydsl.core.types.PathMetadataFactory; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.lang.reflect.AnnotatedElement; import java.util.Set; import org.jetbrains.annotations.Nullable; @@ -33,7 +34,7 @@ public class SetPath> extends CollectionPathBase, E, Q> { - private static final long serialVersionUID = 4145848445507037373L; + @Serial private static final long serialVersionUID = 4145848445507037373L; private final Class elementType; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SimpleExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SimpleExpression.java index bb5fe6f758..765cf1d822 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SimpleExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SimpleExpression.java @@ -21,6 +21,7 @@ import com.querydsl.core.types.Path; import com.querydsl.core.types.SubQueryExpression; import com.querydsl.core.util.CollectionUtils; +import java.io.Serial; import java.util.Arrays; import java.util.Collection; import org.jetbrains.annotations.Nullable; @@ -33,7 +34,7 @@ */ public abstract class SimpleExpression extends DslExpression { - private static final long serialVersionUID = -4405387187738167105L; + @Serial private static final long serialVersionUID = -4405387187738167105L; @Nullable private transient volatile NumberExpression count; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SimpleOperation.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SimpleOperation.java index 16670d94f1..bcb48da5d9 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SimpleOperation.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SimpleOperation.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.OperationImpl; import com.querydsl.core.types.Operator; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.Arrays; import java.util.List; @@ -30,7 +31,7 @@ */ public class SimpleOperation extends SimpleExpression implements Operation { - private static final long serialVersionUID = -285668548371034230L; + @Serial private static final long serialVersionUID = -285668548371034230L; private final OperationImpl opMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SimplePath.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SimplePath.java index a6c41d713b..9eb9ada0e5 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SimplePath.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SimplePath.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.PathMetadata; import com.querydsl.core.types.PathMetadataFactory; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.lang.reflect.AnnotatedElement; /** @@ -29,7 +30,7 @@ */ public class SimplePath extends SimpleExpression implements Path { - private static final long serialVersionUID = 3088836955328191852L; + @Serial private static final long serialVersionUID = 3088836955328191852L; private final PathImpl pathMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SimpleTemplate.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SimpleTemplate.java index 435f82fd51..728cbfb39f 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SimpleTemplate.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SimpleTemplate.java @@ -18,6 +18,7 @@ import com.querydsl.core.types.TemplateExpression; import com.querydsl.core.types.TemplateExpressionImpl; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.List; /** @@ -28,7 +29,7 @@ */ public class SimpleTemplate extends SimpleExpression implements TemplateExpression { - private static final long serialVersionUID = -4697578522909045745L; + @Serial private static final long serialVersionUID = -4697578522909045745L; private final TemplateExpressionImpl templateMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/StringExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/StringExpression.java index a63c1c1559..3e6cfcf4a4 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/StringExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/StringExpression.java @@ -18,6 +18,7 @@ import com.querydsl.core.types.ExpressionUtils; import com.querydsl.core.types.Ops; import com.querydsl.core.types.Path; +import java.io.Serial; import org.jetbrains.annotations.Nullable; /** @@ -28,7 +29,7 @@ */ public abstract class StringExpression extends LiteralExpression { - private static final long serialVersionUID = 1536955079961023361L; + @Serial private static final long serialVersionUID = 1536955079961023361L; @Nullable private transient volatile NumberExpression length; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/StringOperation.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/StringOperation.java index 71f41b389b..602ca7d1f2 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/StringOperation.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/StringOperation.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.OperationImpl; import com.querydsl.core.types.Operator; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.Arrays; import java.util.List; @@ -29,7 +30,7 @@ */ public class StringOperation extends StringExpression implements Operation { - private static final long serialVersionUID = 6846556373847139549L; + @Serial private static final long serialVersionUID = 6846556373847139549L; private final OperationImpl opMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/StringPath.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/StringPath.java index 46b8eb4943..368cdea3c8 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/StringPath.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/StringPath.java @@ -19,6 +19,7 @@ import com.querydsl.core.types.PathMetadata; import com.querydsl.core.types.PathMetadataFactory; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.lang.reflect.AnnotatedElement; /** @@ -28,7 +29,7 @@ */ public class StringPath extends StringExpression implements Path { - private static final long serialVersionUID = 7983490925756833429L; + @Serial private static final long serialVersionUID = 7983490925756833429L; private final PathImpl pathMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/StringTemplate.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/StringTemplate.java index f1f78e8c10..83674efb7b 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/StringTemplate.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/StringTemplate.java @@ -18,6 +18,7 @@ import com.querydsl.core.types.TemplateExpression; import com.querydsl.core.types.TemplateExpressionImpl; import com.querydsl.core.types.Visitor; +import java.io.Serial; import java.util.List; /** @@ -27,7 +28,7 @@ */ public class StringTemplate extends StringExpression implements TemplateExpression { - private static final long serialVersionUID = 3181686132439356614L; + @Serial private static final long serialVersionUID = 3181686132439356614L; private final TemplateExpressionImpl templateMixin; diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/TemporalExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/TemporalExpression.java index 3e209e2af2..d5467a525e 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/TemporalExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/TemporalExpression.java @@ -14,6 +14,7 @@ package com.querydsl.core.types.dsl; import com.querydsl.core.types.Expression; +import java.io.Serial; /** * {@code TemporalExpression} is a supertype for Date/Time related types @@ -24,7 +25,7 @@ @SuppressWarnings({"unchecked"}) public abstract class TemporalExpression extends LiteralExpression { - private static final long serialVersionUID = 1137918766051524298L; + @Serial private static final long serialVersionUID = 1137918766051524298L; public TemporalExpression(Expression mixin) { super(mixin); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/TimeExpression.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/TimeExpression.java index 4332ce2ee2..2a7793669e 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/TimeExpression.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/TimeExpression.java @@ -18,6 +18,7 @@ import com.querydsl.core.types.ExpressionUtils; import com.querydsl.core.types.Ops; import com.querydsl.core.types.Path; +import java.io.Serial; import java.sql.Time; import org.jetbrains.annotations.Nullable; @@ -29,7 +30,7 @@ */ public abstract class TimeExpression extends TemporalExpression { - private static final long serialVersionUID = 7360552308332457990L; + @Serial private static final long serialVersionUID = 7360552308332457990L; private static class Constants { private static final TimeExpression> Collection numeric( public Collection string(StringExpression expr, StringExpression other) { var rv = new HashSet(); - if (module != QuerydslModule.LUCENE) { - rv.addAll(comparable(expr, other)); + rv.addAll(comparable(expr, other)); - rv.add(expr.charAt(0).eq(other.charAt(0))); - rv.add(expr.charAt(1).eq(other.charAt(1))); - } + rv.add(expr.charAt(0).eq(other.charAt(0))); + rv.add(expr.charAt(1).eq(other.charAt(1))); rv.add(expr.contains(other)); rv.add(expr.contains(other.substring(0, 1))); @@ -244,58 +240,50 @@ public Collection string(StringExpression expr, StringExpression othe rv.add(expr.eq(other)); rv.add(expr.equalsIgnoreCase(other)); - if (module != QuerydslModule.LUCENE) { - rv.add(expr.indexOf(other).eq(0)); - rv.add(expr.locate(other).eq(1)); - } + rv.add(expr.indexOf(other).eq(0)); + rv.add(expr.locate(other).eq(1)); - if (target != Target.DERBY && module != QuerydslModule.LUCENE) { + if (target != Target.DERBY) { rv.add(expr.indexOf(other.substring(1)).eq(1)); rv.add(expr.indexOf(other.substring(2)).eq(2)); } - if (module != QuerydslModule.LUCENE) { - rv.add(expr.isEmpty().not()); - rv.add(expr.isNotEmpty()); - } + rv.add(expr.isEmpty().not()); + rv.add(expr.isNotEmpty()); - if (module != QuerydslModule.LUCENE) { - rv.add(expr.length().eq(other.length())); - rv.add(expr.like(other)); + rv.add(expr.length().eq(other.length())); + rv.add(expr.like(other)); - if (module != QuerydslModule.JDO || other instanceof Constant) { - rv.add(expr.like(other.substring(0, 1).append("%"))); - rv.add(expr.like(other.substring(0, 1).append("%").append(other.substring(2)))); - rv.add(expr.like(other.substring(1).prepend("%"))); - rv.add(expr.like(other.substring(1, 2).append("%").prepend("%"))); - } + if (other instanceof Constant) { + rv.add(expr.like(other.substring(0, 1).append("%"))); + rv.add(expr.like(other.substring(0, 1).append("%").append(other.substring(2)))); + rv.add(expr.like(other.substring(1).prepend("%"))); + rv.add(expr.like(other.substring(1, 2).append("%").prepend("%"))); } rv.add(expr.lower().eq(other.lower())); - if (module != QuerydslModule.LUCENE) { - if (!module.equals(QuerydslModule.SQL) - || (!target.equals(Target.HSQLDB) - && !target.equals(Target.FIREBIRD) - && !target.equals(Target.H2) - && !target.equals(Target.DB2) - && !target.equals(Target.DERBY) - && !target.equals(Target.SQLITE) - && !target.equals(Target.SQLSERVER))) { - - rv.add(expr.matches(other)); - - if (module != QuerydslModule.JDO || other instanceof Constant) { - rv.add(expr.matches(other.substring(0, 1).append(".*"))); - rv.add(expr.matches(other.substring(0, 1).append(".").append(other.substring(2)))); - rv.add(expr.matches(other.substring(1).prepend(".*"))); - rv.add(expr.matches(other.substring(1, 2).prepend(".*").append(".*"))); - } + if (!module.equals(QuerydslModule.SQL) + || (!target.equals(Target.HSQLDB) + && !target.equals(Target.FIREBIRD) + && !target.equals(Target.H2) + && !target.equals(Target.DB2) + && !target.equals(Target.DERBY) + && !target.equals(Target.SQLITE) + && !target.equals(Target.SQLSERVER))) { + + rv.add(expr.matches(other)); + + if (other instanceof Constant) { + rv.add(expr.matches(other.substring(0, 1).append(".*"))); + rv.add(expr.matches(other.substring(0, 1).append(".").append(other.substring(2)))); + rv.add(expr.matches(other.substring(1).prepend(".*"))); + rv.add(expr.matches(other.substring(1, 2).prepend(".*").append(".*"))); } - - rv.add(expr.ne(other)); } + rv.add(expr.ne(other)); + rv.add(expr.startsWith(other)); rv.add(expr.startsWith(other.substring(0, 1))); rv.add(expr.startsWith(other.substring(0, 2))); @@ -304,13 +292,11 @@ public Collection string(StringExpression expr, StringExpression othe rv.add(expr.startsWithIgnoreCase(other.substring(0, 1))); rv.add(expr.startsWithIgnoreCase(other.substring(0, 2))); - if (module != QuerydslModule.LUCENE) { - rv.add(expr.substring(0, 1).eq(other.substring(0, 1))); - rv.add(expr.substring(1, 2).eq(other.substring(1, 2))); - rv.add(expr.substring(1).eq(other.substring(1))); + rv.add(expr.substring(0, 1).eq(other.substring(0, 1))); + rv.add(expr.substring(1, 2).eq(other.substring(1, 2))); + rv.add(expr.substring(1).eq(other.substring(1))); - rv.add(expr.trim().eq(other.trim())); - } + rv.add(expr.trim().eq(other.trim())); rv.add(expr.upper().eq(other.upper())); return Collections.unmodifiableSet(rv); diff --git a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/ProjectionsFactory.java b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/ProjectionsFactory.java index dd07b5408e..3345bf86f1 100644 --- a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/ProjectionsFactory.java +++ b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/ProjectionsFactory.java @@ -153,9 +153,7 @@ private > Collection> numer rv.add(expr.countDistinct()); } - if (!(other instanceof Constant - || module == QuerydslModule.JDO - || module == QuerydslModule.RDFBEAN)) { + if (!(other instanceof Constant || module == QuerydslModule.RDFBEAN)) { var cases = new CaseBuilder(); rv.add( NumberConstant.create(1) @@ -218,9 +216,7 @@ public Collection> stringProjections( rv.add(expr.substring(1)); rv.add(expr.substring(0, 1)); - if (!(other instanceof Constant - || module == QuerydslModule.JDO - || module == QuerydslModule.RDFBEAN)) { + if (!(other instanceof Constant || module == QuerydslModule.RDFBEAN)) { var cases = new CaseBuilder(); rv.add(cases.when(expr.eq("A")).then(other).when(expr.eq("B")).then(expr).otherwise(other)); @@ -231,9 +227,7 @@ public Collection> stringProjections( rv.add(expr.upper()); - if (module != QuerydslModule.JDO) { - rv.add(expr.nullif("xxx")); - } + rv.add(expr.nullif("xxx")); return Collections.unmodifiableSet(rv); } diff --git a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/QuerydslModule.java b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/QuerydslModule.java index 30cf177219..9b060f4870 100644 --- a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/QuerydslModule.java +++ b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/QuerydslModule.java @@ -22,11 +22,7 @@ public enum QuerydslModule { /** */ JPA, /** */ - JDO, - /** */ RDFBEAN, /** */ SQL, - /** */ - LUCENE; } diff --git a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/group/AbstractGroupByTest.java b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/group/AbstractGroupByTest.java index 30a5478d18..02a30fe862 100644 --- a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/group/AbstractGroupByTest.java +++ b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/group/AbstractGroupByTest.java @@ -1,6 +1,6 @@ package com.querydsl.core.group; -import com.mysema.commons.lang.Pair; +import com.querydsl.core.Pair; import com.querydsl.core.Tuple; import com.querydsl.core.support.DummyFetchableQuery; import com.querydsl.core.types.ConstructorExpression; diff --git a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/group/GroupByIterateTest.java b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/group/GroupByIterateTest.java index 600145cda8..8ea207b16a 100644 --- a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/group/GroupByIterateTest.java +++ b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/group/GroupByIterateTest.java @@ -19,9 +19,8 @@ import static com.querydsl.core.group.GroupBy.set; import static org.assertj.core.api.Assertions.assertThat; -import com.mysema.commons.lang.CloseableIterator; -import com.mysema.commons.lang.IteratorAdapter; -import com.mysema.commons.lang.Pair; +import com.querydsl.core.CloseableIterator; +import com.querydsl.core.Pair; import com.querydsl.core.Tuple; import com.querydsl.core.types.Projections; import java.util.Arrays; @@ -41,7 +40,7 @@ public class GroupByIterateTest extends AbstractGroupByTest { public void group_order() { CloseableIterator resultsIt = BASIC_RESULTS.transform(groupBy(postId).iterate(postName, set(commentId))); - List results = IteratorAdapter.asList(resultsIt); + List results = CloseableIterator.asList(resultsIt); assertThat(results).hasSize(4); } @@ -52,7 +51,7 @@ public void first_set_and_list() { CloseableIterator resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); - List results = IteratorAdapter.asList(resultsIt); + List results = CloseableIterator.asList(resultsIt); assertThat(results).hasSize(4); @@ -70,7 +69,7 @@ public void group_by_null() { CloseableIterator resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); - List results = IteratorAdapter.asList(resultsIt); + List results = CloseableIterator.asList(resultsIt); assertThat(results).hasSize(4); @@ -87,7 +86,7 @@ public void noSuchElementException() { CloseableIterator resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); - List results = IteratorAdapter.asList(resultsIt); + List results = CloseableIterator.asList(resultsIt); assertThat(results).hasSize(4); @@ -101,7 +100,7 @@ public void classCastException() { CloseableIterator resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); - List results = IteratorAdapter.asList(resultsIt); + List results = CloseableIterator.asList(resultsIt); assertThat(results).hasSize(4); @@ -114,7 +113,7 @@ public void classCastException() { public void map1() { CloseableIterator resultsIt = MAP_RESULTS.transform(groupBy(postId).iterate(postName, map(commentId, commentText))); - List results = IteratorAdapter.asList(resultsIt); + List results = CloseableIterator.asList(resultsIt); assertThat(results).hasSize(4); @@ -128,7 +127,7 @@ public void map1() { public void map2() { CloseableIterator> resultsIt = MAP2_RESULTS.transform(groupBy(postId).iterate(map(commentId, commentText))); - List> results = IteratorAdapter.asList(resultsIt); + List> results = CloseableIterator.asList(resultsIt); assertThat(results).hasSize(4); @@ -140,7 +139,7 @@ public void map2() { public void map22() { CloseableIterator> results = MAP2_RESULTS.transform(groupBy(postId).iterate(map(commentId, commentText))); - List> actual = IteratorAdapter.asList(results); + List> actual = CloseableIterator.asList(results); Object commentId = null; Map comments = null; @@ -168,7 +167,7 @@ public void map22() { public void map3() { CloseableIterator>> results = MAP3_RESULTS.transform(groupBy(postId).iterate(map(postId, map(commentId, commentText)))); - List>> actual = IteratorAdapter.asList(results); + List>> actual = CloseableIterator.asList(results); Object postId = null; Map> posts = null; @@ -197,7 +196,7 @@ public void map3() { public void map4() { CloseableIterator, String>> results = MAP4_RESULTS.transform(groupBy(postId).iterate(map(map(postId, commentText), postName))); - List, String>> actual = IteratorAdapter.asList(results); + List, String>> actual = CloseableIterator.asList(results); Object commentId = null; Map, String> comments = null; @@ -227,7 +226,7 @@ public void array_access() { CloseableIterator resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); - List results = IteratorAdapter.asList(resultsIt); + List results = CloseableIterator.asList(resultsIt); assertThat(results).hasSize(4); @@ -246,7 +245,7 @@ public void transform_results() { POST_W_COMMENTS.transform( groupBy(postId) .iterate(Projections.constructor(Post.class, postId, postName, set(qComment)))); - List results = IteratorAdapter.asList(resultsIt); + List results = CloseableIterator.asList(resultsIt); assertThat(results).hasSize(4); @@ -265,7 +264,7 @@ public void transform_as_bean() { groupBy(postId) .iterate( Projections.bean(Post.class, postId, postName, set(qComment).as("comments")))); - List results = IteratorAdapter.asList(resultsIt); + List results = CloseableIterator.asList(resultsIt); assertThat(results).hasSize(4); @@ -287,7 +286,7 @@ public void oneToOneToMany_projection() { User.class, userName, Projections.constructor(Post.class, postId, postName, set(qComment))))); - List results = IteratorAdapter.asList(resultsIt); + List results = CloseableIterator.asList(resultsIt); assertThat(results).hasSize(2); @@ -310,7 +309,7 @@ public void oneToOneToMany_projection_as_bean() { userName, Projections.bean(Post.class, postId, postName, set(qComment).as("comments")) .as("latestPost")))); - List results = IteratorAdapter.asList(resultsIt); + List results = CloseableIterator.asList(resultsIt); assertThat(results).hasSize(2); @@ -333,7 +332,7 @@ public void oneToOneToMany_projection_as_bean_and_constructor() { userName, Projections.constructor(Post.class, postId, postName, set(qComment)) .as("latestPost")))); - List results = IteratorAdapter.asList(resultsIt); + List results = CloseableIterator.asList(resultsIt); assertThat(results).hasSize(2); diff --git a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/group/GroupByListTest.java b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/group/GroupByListTest.java index c08e3e067b..3ca4a688a9 100644 --- a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/group/GroupByListTest.java +++ b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/group/GroupByListTest.java @@ -19,9 +19,8 @@ import static com.querydsl.core.group.GroupBy.set; import static org.assertj.core.api.Assertions.assertThat; -import com.mysema.commons.lang.CloseableIterator; -import com.mysema.commons.lang.IteratorAdapter; -import com.mysema.commons.lang.Pair; +import com.querydsl.core.CloseableIterator; +import com.querydsl.core.Pair; import com.querydsl.core.Tuple; import com.querydsl.core.types.Projections; import java.util.Arrays; @@ -174,7 +173,7 @@ private Map> findPostsById( public void map4() { CloseableIterator, String>> results = MAP4_RESULTS.transform(groupBy(postId).iterate(map(map(postId, commentText), postName))); - List, String>> actual = IteratorAdapter.asList(results); + List, String>> actual = CloseableIterator.asList(results); Object commentId = null; Map, String> comments = null; diff --git a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/group/GroupByMapTest.java b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/group/GroupByMapTest.java index 16e4e781c6..0924833123 100644 --- a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/group/GroupByMapTest.java +++ b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/group/GroupByMapTest.java @@ -23,7 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; -import com.mysema.commons.lang.Pair; +import com.querydsl.core.Pair; import com.querydsl.core.ResultTransformer; import com.querydsl.core.Tuple; import com.querydsl.core.types.Projections; diff --git a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/support/DummyFetchable.java b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/support/DummyFetchable.java index 8141defd06..1cce406c6b 100644 --- a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/support/DummyFetchable.java +++ b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/support/DummyFetchable.java @@ -1,7 +1,6 @@ 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.NonUniqueResultException; import com.querydsl.core.QueryModifiers; @@ -19,7 +18,7 @@ public DummyFetchable(List results) { @Override public CloseableIterator iterate() { - return new IteratorAdapter<>(results.iterator()); + return CloseableIterator.of(results.iterator()); } @Override diff --git a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/types/MappingProjectionTest.java b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/types/MappingProjectionTest.java index 84d1c1133f..8a5c1d5933 100644 --- a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/types/MappingProjectionTest.java +++ b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/types/MappingProjectionTest.java @@ -15,7 +15,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import com.mysema.commons.lang.Pair; +import com.querydsl.core.Pair; import com.querydsl.core.Tuple; import com.querydsl.core.types.dsl.Expressions; import com.querydsl.core.types.dsl.StringPath; diff --git a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/util/MultiIteratorTest.java b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/util/MultiIteratorTest.java index 3e3479426a..ab35d59a2e 100644 --- a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/util/MultiIteratorTest.java +++ b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/util/MultiIteratorTest.java @@ -17,7 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import com.mysema.commons.lang.IteratorAdapter; +import com.querydsl.core.CloseableIterator; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -117,7 +117,7 @@ public void test() { List list1 = asList(1, 2, 3, 4); List list2 = asList(10, 20, 30); var iterator = new MultiIterator<>(asList(list1, list2)); - List list = IteratorAdapter.asList(iterator); + List list = CloseableIterator.asList(iterator); assertThat(asList(list.getFirst())).isEqualTo(asList(1, 10)); assertThat(asList(list.get(1))).isEqualTo(asList(1, 20)); diff --git a/querydsl-libraries/querydsl-guava/pom.xml b/querydsl-libraries/querydsl-guava/pom.xml index 3f0e299d95..f272312a5d 100644 --- a/querydsl-libraries/querydsl-guava/pom.xml +++ b/querydsl-libraries/querydsl-guava/pom.xml @@ -4,7 +4,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-guava diff --git a/querydsl-libraries/querydsl-guava/src/main/java/com/querydsl/core/group/guava/GMultimap.java b/querydsl-libraries/querydsl-guava/src/main/java/com/querydsl/core/group/guava/GMultimap.java index 7e9a5299cb..798aac772d 100644 --- a/querydsl-libraries/querydsl-guava/src/main/java/com/querydsl/core/group/guava/GMultimap.java +++ b/querydsl-libraries/querydsl-guava/src/main/java/com/querydsl/core/group/guava/GMultimap.java @@ -17,7 +17,7 @@ import com.google.common.collect.Multimap; import com.google.common.collect.SortedSetMultimap; import com.google.common.collect.TreeMultimap; -import com.mysema.commons.lang.Pair; +import com.querydsl.core.Pair; import com.querydsl.core.group.AbstractGroupExpression; import com.querydsl.core.group.GroupCollector; import com.querydsl.core.group.GroupExpression; diff --git a/querydsl-libraries/querydsl-guava/src/main/java/com/querydsl/core/group/guava/GTable.java b/querydsl-libraries/querydsl-guava/src/main/java/com/querydsl/core/group/guava/GTable.java index 86cf3b0b66..8a7aab40fd 100644 --- a/querydsl-libraries/querydsl-guava/src/main/java/com/querydsl/core/group/guava/GTable.java +++ b/querydsl-libraries/querydsl-guava/src/main/java/com/querydsl/core/group/guava/GTable.java @@ -16,7 +16,7 @@ import com.google.common.collect.HashBasedTable; import com.google.common.collect.Table; import com.google.common.collect.TreeBasedTable; -import com.mysema.commons.lang.Pair; +import com.querydsl.core.Pair; import com.querydsl.core.group.AbstractGroupExpression; import com.querydsl.core.group.GroupCollector; import com.querydsl.core.group.GroupExpression; diff --git a/querydsl-libraries/querydsl-guava/src/main/java/com/querydsl/core/group/guava/GuavaGroupBy.java b/querydsl-libraries/querydsl-guava/src/main/java/com/querydsl/core/group/guava/GuavaGroupBy.java index 5540319c86..5b7e0c65a6 100644 --- a/querydsl-libraries/querydsl-guava/src/main/java/com/querydsl/core/group/guava/GuavaGroupBy.java +++ b/querydsl-libraries/querydsl-guava/src/main/java/com/querydsl/core/group/guava/GuavaGroupBy.java @@ -17,7 +17,7 @@ import com.google.common.collect.SortedSetMultimap; import com.google.common.collect.Table; import com.google.common.collect.TreeBasedTable; -import com.mysema.commons.lang.Pair; +import com.querydsl.core.Pair; import com.querydsl.core.ResultTransformer; import com.querydsl.core.group.AbstractGroupExpression; import com.querydsl.core.group.GroupBy; diff --git a/querydsl-libraries/querydsl-hibernate-search/pom.xml b/querydsl-libraries/querydsl-hibernate-search/pom.xml deleted file mode 100644 index 981ef7dc0c..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/pom.xml +++ /dev/null @@ -1,186 +0,0 @@ - - - 4.0.0 - - - io.github.openfeign.querydsl - querydsl-libraries - 6.0-SNAPSHOT - - - querydsl-hibernate-search - Querydsl - Hibernate Search support - Hibernate Search support for querydsl - - - 6.3.1.Final - 8.0.1.Final - 6.2.2.Final - 5.5.5 - org.apache.lucene.*;version="[3.6,4)", - org.hibernate.*;version="[4,5)", - ${osgi.import.package.root} - - - - - - org.apache.lucene - lucene-core - ${lucene.version} - - - org.hibernate.common - hibernate-commons-annotations - 6.0.6.Final - - - - - - - io.github.openfeign.querydsl - querydsl-lucene5 - ${project.version} - - - - - org.hibernate.orm - hibernate-core - ${hibernate.version} - provided - - - asm - asm - - - org.jboss.logging - jboss-logging - - - - - org.hibernate.validator - hibernate-validator - ${hibernate.validator.version} - provided - - - org.jboss.logging - jboss-logging - - - - - - jakarta.persistence - jakarta.persistence-api - 3.1.0 - provided - - - - org.apache.lucene - lucene-core - ${lucene.version} - provided - - - org.hibernate.search - hibernate-search-mapper-orm-orm6 - ${hibernate.search.version} - provided - - - hsqldb - hsqldb - - - org.hibernate.orm - hibernate-core - - - org.slf4j - slf4j-api - - - - - javassist - javassist - 3.12.1.GA - provided - - - - - org.apache.derby - derby - ${derby.version} - test - - - org.apache.derby - derbytools - ${derby.version} - test - - - - io.github.openfeign.querydsl - querydsl-core - ${project.version} - test-jar - test - - - - javax.xml.bind - jaxb-api - 2.3.1 - test - - - - jakarta.validation - jakarta.validation-api - test - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.3.0 - - - - com.querydsl.hibernate.search - - - - - - org.apache.felix - maven-bundle-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - - - derby.stream.error.file - target/derby.log - - - - - - - - diff --git a/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/AbstractSearchQuery.java b/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/AbstractSearchQuery.java deleted file mode 100644 index 4c5edc8ad7..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/AbstractSearchQuery.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.hibernate.search; - -import com.mysema.commons.lang.CloseableIterator; -import com.mysema.commons.lang.IteratorAdapter; -import com.querydsl.core.Fetchable; -import com.querydsl.core.NonUniqueResultException; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.QueryModifiers; -import com.querydsl.core.QueryResults; -import com.querydsl.core.SimpleQuery; -import com.querydsl.core.support.QueryMixin; -import com.querydsl.core.types.EntityPath; -import com.querydsl.core.types.OrderSpecifier; -import com.querydsl.core.types.ParamExpression; -import com.querydsl.core.types.Predicate; -import com.querydsl.lucene5.LuceneSerializer; -import java.util.List; -import org.hibernate.Session; -import org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory; -import org.hibernate.search.engine.search.query.SearchQuery; -import org.hibernate.search.engine.search.query.dsl.SearchQueryOptionsStep; -import org.hibernate.search.mapper.orm.Search; -import org.hibernate.search.mapper.orm.search.loading.dsl.SearchLoadingOptionsStep; -import org.hibernate.search.mapper.orm.session.SearchSession; - -/** - * Abstract base class for Hibernate Search query classes - * - * @param result type - * @param concrete subtype - */ -public abstract class AbstractSearchQuery> - implements SimpleQuery, Fetchable { - - private final EntityPath path; - - private final QueryMixin queryMixin; - - private final LuceneSerializer serializer; - - private final SearchSession session; - - @SuppressWarnings("unchecked") - public AbstractSearchQuery(SearchSession session, EntityPath path) { - this.queryMixin = new QueryMixin((Q) this); - this.session = session; - this.path = path; - this.serializer = SearchSerializer.DEFAULT; - queryMixin.from(path); - } - - public AbstractSearchQuery(Session session, EntityPath path) { - this(Search.session(session), path); - } - - @Override - public long fetchCount() { - return createQuery(true).fetchTotalHitCount(); - } - - private SearchQuery createQuery(boolean forCount) { - QueryMetadata metadata = queryMixin.getMetadata(); - Class type = (Class) path.getType(); - // org.apache.lucene.search.Query query; - // if (metadata.getWhere() != null) { - // query = serializer.toQuery(metadata.getWhere(), metadata); - // } else { - // query = new MatchAllDocsQuery(); - // } - - // TODO: implement where clause - - SearchQueryOptionsStep queryStep = - session.search(type).where(SearchPredicateFactory::matchAll); - - // TODO: add sorting - // List> orderBy = metadata.getOrderBy(); - // if (!orderBy.isEmpty() && !forCount) { - // fullTextQuery.setSort(serializer.toSort(metadata.getOrderBy())); - // } - return queryStep.toQuery(); - } - - @Override - public Q distinct() { - return queryMixin.distinct(); - } - - @Override - @SuppressWarnings("unchecked") - public CloseableIterator iterate() { - return new IteratorAdapter(fetchAll(createQuery(false)).iterator()); - } - - @Override - public Q limit(long limit) { - return queryMixin.limit(limit); - } - - @SuppressWarnings("unchecked") - @Override - public List fetch() { - return fetchAll(createQuery(false)); - } - - @SuppressWarnings("unchecked") - @Override - public QueryResults fetchResults() { - SearchQuery query = createQuery(false); - return new QueryResults( - fetchAll(query), queryMixin.getMetadata().getModifiers(), query.fetchTotalHitCount()); - } - - private List fetchAll(SearchQuery query) { - return query.fetchHits( - queryMixin.getMetadata().getModifiers().getOffsetAsInteger(), - queryMixin.getMetadata().getModifiers().getLimitAsInteger()); - } - - @Override - public Q offset(long offset) { - return queryMixin.offset(offset); - } - - @Override - public Q orderBy(OrderSpecifier... o) { - return queryMixin.orderBy(o); - } - - @Override - public Q restrict(QueryModifiers modifiers) { - return queryMixin.restrict(modifiers); - } - - @Override - public

Q set(ParamExpression

param, P value) { - return queryMixin.set(param, value); - } - - @Override - public T fetchFirst() { - return limit(1).fetchFirst(); - } - - @SuppressWarnings("unchecked") - @Override - public T fetchOne() throws NonUniqueResultException { - try { - return (T) createQuery(false).fetchSingleHit(); - } catch (org.hibernate.NonUniqueResultException e) { - throw new NonUniqueResultException(e); - } - } - - @Override - public Q where(Predicate... e) { - return queryMixin.where(e); - } -} diff --git a/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/SearchQuery.java b/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/SearchQuery.java deleted file mode 100644 index 6f17ebf3f2..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/SearchQuery.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.hibernate.search; - -import com.querydsl.core.types.EntityPath; -import org.hibernate.Session; -import org.hibernate.search.mapper.orm.Search; -import org.hibernate.search.mapper.orm.session.SearchSession; - -/** - * {@code SearchQuery} is a Query implementation for Hibernate Search - * - * @author tiwe - * @param - */ -public class SearchQuery extends AbstractSearchQuery> { - - /** - * Create a new SearchQuery instance - * - * @param session session - * @param path query source - */ - public SearchQuery(SearchSession session, EntityPath path) { - super(session, path); - } - - /** - * Create a new SearchQuery instance - * - * @param session session - * @param path query source - */ - public SearchQuery(Session session, EntityPath path) { - this(Search.session(session), path); - } -} diff --git a/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/SearchSerializer.java b/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/SearchSerializer.java deleted file mode 100644 index a8cf5539f5..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/SearchSerializer.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.hibernate.search; - -import com.querydsl.core.types.Path; -import com.querydsl.lucene5.LuceneSerializer; -import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField; -import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField; -import org.hibernate.search.mapper.pojo.mapping.definition.annotation.KeywordField; - -/** - * {@code SearchSerializer} extends the {@link LuceneSerializer} to use {@link FullTextField} - * annotation data from paths - * - * @author tiwe - */ -public class SearchSerializer extends LuceneSerializer { - - public static final SearchSerializer DEFAULT = new SearchSerializer(false, true); - - /** - * Create a new SearchSerializer instance - * - * @param lowerCase lowercase names - * @param splitTerms split terms - */ - public SearchSerializer(boolean lowerCase, boolean splitTerms) { - super(lowerCase, splitTerms); - } - - @Override - public String toField(Path path) { - if (path.getAnnotatedElement() != null) { - FullTextField fullTextField = path.getAnnotatedElement().getAnnotation(FullTextField.class); - if (fullTextField != null && fullTextField.name().length() > 0) { - return fullTextField.name(); - } - KeywordField keywordField = path.getAnnotatedElement().getAnnotation(KeywordField.class); - if (keywordField != null && keywordField.name().length() > 0) { - return keywordField.name(); - } - GenericField genericField = path.getAnnotatedElement().getAnnotation(GenericField.class); - if (genericField != null && genericField.name().length() > 0) { - return genericField.name(); - } - } - return super.toField(path); - } -} diff --git a/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/package-info.java b/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/package-info.java deleted file mode 100644 index 3d00e239e7..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/package-info.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** Hibernate Search support */ -package com.querydsl.hibernate.search; diff --git a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/AbstractQueryTest.java b/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/AbstractQueryTest.java deleted file mode 100644 index 063371f552..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/AbstractQueryTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.hibernate.search; - -import com.querydsl.core.util.FileUtils; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.sql.SQLException; -import java.util.List; -import java.util.Properties; -import org.hibernate.HibernateException; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.cfg.Configuration; -import org.hibernate.resource.transaction.spi.TransactionStatus; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; - -public abstract class AbstractQueryTest { - - private static SessionFactory sessionFactory; - - @BeforeClass - public static void setUpClass() throws IOException { - FileUtils.delete(new File("target/derbydb")); - FileUtils.delete(new File("target/lucene3")); - Configuration cfg = new Configuration(); - cfg.addAnnotatedClass(User.class); - Properties props = new Properties(); - try (InputStream is = SearchQueryTest.class.getResourceAsStream("/derby.properties")) { - props.load(is); - } - cfg.setProperties(props); - sessionFactory = cfg.buildSessionFactory(); - } - - @AfterClass - public static void tearDownClass() { - if (sessionFactory != null) { - sessionFactory.close(); - } - } - - private Session session; - - protected Session getSession() { - return session; - } - - @SuppressWarnings("unchecked") - @Before - public void setUp() { - session = sessionFactory.openSession(); - session.beginTransaction(); - - // clean up - List users = session.createQuery("from User").list(); - for (User user : users) { - session.delete(user); - } - session.flush(); - } - - @After - public void tearDown() throws HibernateException, SQLException { - if (session - .getTransaction() - .getStatus() - .isNotOneOf( - TransactionStatus.ROLLED_BACK, - TransactionStatus.ROLLING_BACK, - TransactionStatus.MARKED_ROLLBACK)) { - session.getTransaction().commit(); - } - session.close(); - } -} diff --git a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/QUser.java b/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/QUser.java deleted file mode 100644 index ed454309ad..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/QUser.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.hibernate.search; - -import com.querydsl.core.types.PathMetadataFactory; -import com.querydsl.core.types.dsl.EntityPathBase; -import com.querydsl.core.types.dsl.StringPath; - -public class QUser extends EntityPathBase { - - private static final long serialVersionUID = 8362025864799201294L; - - public QUser(String variable) { - super(User.class, PathMetadataFactory.forVariable(variable)); - } - - public final StringPath emailAddress = createString("emailAddress"); - - public final StringPath firstName = createString("firstName"); - - public final StringPath lastName = createString("lastName"); - - public final StringPath middleName = createString("middleName"); -} diff --git a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/SearchQueryTest.java b/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/SearchQueryTest.java deleted file mode 100644 index acb5a1b7d9..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/SearchQueryTest.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.hibernate.search; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.NonUniqueResultException; -import com.querydsl.core.QueryResults; -import com.querydsl.core.types.OrderSpecifier; -import com.querydsl.core.types.dsl.BooleanExpression; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import org.hibernate.Session; -import org.junit.Ignore; -import org.junit.Test; - -public class SearchQueryTest extends AbstractQueryTest { - - private final QUser user = new QUser("user"); - - @Override - public void setUp() { - super.setUp(); - createUser("Bob", "Stewart", "Smith", "bob@example.com"); - - createUser("Barbara", "X", "Lock", "barbara@a.com"); - createUser("Anton", "X", "Bruckner", "anton@b.com"); - createUser("Robert", "X", "Downing", "bob@c.com"); - createUser("John", "X", "Stewart", "john@d.com"); - - Session session = getSession(); - session.flush(); - session.getTransaction().commit(); - session.beginTransaction(); - } - - @Test - public void exists() { - assertThat(query().where(user.emailAddress.eq("bob@example.com")).fetchCount() > 0).isTrue(); - assertThat(query().where(user.emailAddress.eq("bobby@example.com")).fetchCount() > 0).isFalse(); - } - - @Test - public void notExists() { - assertThat(query().where(user.emailAddress.eq("bob@example.com")).fetchCount() == 0).isFalse(); - assertThat(query().where(user.emailAddress.eq("bobby@example.com")).fetchCount() == 0).isTrue(); - } - - @Test - public void count() { - BooleanExpression filter = user.emailAddress.eq("bob@example.com"); - assertThat(query().where(filter).fetchCount()).isEqualTo(1); - } - - @Test - public void uniqueResult() { - BooleanExpression filter = user.emailAddress.eq("bob@example.com"); - User u = query().where(filter).fetchOne(); - assertThat(u).isNotNull(); - assertThat(u.getEmailAddress()).isEqualTo("bob@example.com"); - } - - @Test - public void list() { - BooleanExpression filter = user.emailAddress.eq("bob@example.com"); - List list = query().where(filter).fetch(); - assertThat(list).hasSize(1); - User u = query().where(filter).fetchOne(); - assertThat(list.getFirst()).isEqualTo(u); - } - - @Test(expected = NonUniqueResultException.class) - public void unique_result_throws_exception_on_multiple_results() { - query().where(user.middleName.eq("X")).fetchOne(); - } - - @Test - public void singleResult() { - assertThat(query().where(user.middleName.eq("X")).fetchFirst()).isNotNull(); - } - - @Test - public void ordering() { - BooleanExpression filter = user.middleName.eq("X"); - // asc - List asc = getFirstNames(query().where(filter).orderBy(user.firstName.asc()).fetch()); - assertThat(asc).isEqualTo(Arrays.asList("Anton", "Barbara", "John", "Robert")); - - // desc - List desc = getFirstNames(query().where(filter).orderBy(user.firstName.desc()).fetch()); - assertThat(desc).isEqualTo(Arrays.asList("Robert", "John", "Barbara", "Anton")); - } - - @Test - public void paging() { - BooleanExpression filter = user.middleName.eq("X"); - OrderSpecifier order = user.firstName.asc(); - - // limit - List limit = getFirstNames(query().where(filter).orderBy(order).limit(2).fetch()); - assertThat(limit).isEqualTo(Arrays.asList("Anton", "Barbara")); - - // offset - List offset = getFirstNames(query().where(filter).orderBy(order).offset(1).fetch()); - assertThat(offset).isEqualTo(Arrays.asList("Barbara", "John", "Robert")); - - // limit + offset - List limitAndOffset = - getFirstNames(query().where(filter).orderBy(order).limit(2).offset(1).fetch()); - assertThat(limitAndOffset).isEqualTo(Arrays.asList("Barbara", "John")); - } - - @Test - public void listResults() { - BooleanExpression filter = user.middleName.eq("X"); - QueryResults users = - query().where(filter).orderBy(user.firstName.asc()).limit(2).fetchResults(); - List asc = getFirstNames(users.getResults()); - assertThat(asc).isEqualTo(Arrays.asList("Anton", "Barbara")); - assertThat(users.getTotal()).isEqualTo(4); - } - - @Test - public void no_where() { - assertThat(query().fetch()).hasSize(5); - } - - @Test - @Ignore // OufOfMemoryError - public void limit_max_value() { - assertThat(query().limit(Long.MAX_VALUE).fetch()).hasSize(5); - } - - private List getFirstNames(List users) { - List rv = new ArrayList(users.size()); - for (User user : users) { - rv.add(user.getFirstName()); - } - return rv; - } - - private User createUser(String firstName, String middleName, String lastName, String email) { - User user = new User(); - user.setFirstName(firstName); - user.setMiddleName(middleName); - user.setLastName(lastName); - user.setEmailAddress(email); - getSession().save(user); - return user; - } - - private SearchQuery query() { - return new SearchQuery(getSession(), user); - } -} diff --git a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/SearchSerializerTest.java b/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/SearchSerializerTest.java deleted file mode 100644 index 6c2db1097c..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/SearchSerializerTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.hibernate.search; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; - -public class SearchSerializerTest { - - @Test - public void toField() { - SearchSerializer serializer = SearchSerializer.DEFAULT; - QUser user = new QUser("user"); - assertThat(serializer.toField(user.emailAddress)).isEqualTo("email"); - assertThat(serializer.toField(user.firstName)).isEqualTo("firstName"); - } -} diff --git a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/User.java b/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/User.java deleted file mode 100644 index 33497b092e..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/User.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.hibernate.search; - -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.Table; -import java.io.Serializable; -import org.hibernate.annotations.NaturalId; -import org.hibernate.search.engine.backend.types.Projectable; -import org.hibernate.search.engine.backend.types.Searchable; -import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId; -import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField; -import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; - -@Entity -@Table(name = "user_") -@Indexed -public class User implements Serializable { - - private static final long serialVersionUID = 5955148455600241741L; - - @Id @GeneratedValue @DocumentId private Long id; - - // @SortableField - @GenericField(searchable = Searchable.YES, projectable = Projectable.YES) - private String firstName; - - @GenericField(searchable = Searchable.YES, projectable = Projectable.YES) - private String lastName; - - @GenericField(searchable = Searchable.YES, projectable = Projectable.YES) - private String middleName; - - @NaturalId - @GenericField(searchable = Searchable.YES, name = "email", projectable = Projectable.YES) - private String emailAddress; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getMiddleName() { - return middleName; - } - - public void setMiddleName(String middleName) { - this.middleName = middleName; - } - - public String getEmailAddress() { - return emailAddress; - } - - public void setEmailAddress(String emailAddress) { - this.emailAddress = emailAddress; - } -} diff --git a/querydsl-libraries/querydsl-hibernate-search/src/test/resources/derby.properties b/querydsl-libraries/querydsl-hibernate-search/src/test/resources/derby.properties deleted file mode 100644 index 4d96c12e66..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/test/resources/derby.properties +++ /dev/null @@ -1,15 +0,0 @@ -## Derby -hibernate.dialect=org.hibernate.dialect.DerbyDialect -hibernate.connection.driver_class=org.apache.derby.jdbc.EmbeddedDriver -hibernate.connection.url=jdbc:derby:target/derbydb;create=true -hibernate.connection.pool_size=0 - -## Common properties -hibernate.show_sql=false -hibernate.flushMode=FLUSH_AUTO -hibernate.hbm2ddl.auto=update - -hibernate.search.default.directory_provider=org.hibernate.search.store.impl.FSDirectoryProvider -hibernate.search.default.indexBase=target/lucene/indexes -hibernate.search.default.batch.merge_factor=10 -hibernate.search.default.batch.max_buffered_docs=10 diff --git a/querydsl-libraries/querydsl-jpa-spring/pom.xml b/querydsl-libraries/querydsl-jpa-spring/pom.xml index 5ab92be55e..485216f13b 100644 --- a/querydsl-libraries/querydsl-jpa-spring/pom.xml +++ b/querydsl-libraries/querydsl-jpa-spring/pom.xml @@ -5,18 +5,13 @@ io.github.openfeign.querydsl querydsl-libraries - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-jpa-spring Querydsl - JPA Spring support JPA Spring support for Querydsl - - - 17 - - @@ -70,8 +65,8 @@ org.hibernate.orm hibernate-core + ${hibernate.version} test - diff --git a/querydsl-libraries/querydsl-jpa/pom.xml b/querydsl-libraries/querydsl-jpa/pom.xml index 0f136135e4..76313464f9 100644 --- a/querydsl-libraries/querydsl-jpa/pom.xml +++ b/querydsl-libraries/querydsl-jpa/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-jpa @@ -35,6 +35,13 @@ + + org.hibernate.orm + hibernate-community-dialects + ${hibernate.version} + provided + true + jakarta.persistence diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/DefaultQueryHandler.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/DefaultQueryHandler.java index 233991a4c3..28ae1d81a8 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/DefaultQueryHandler.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/DefaultQueryHandler.java @@ -13,8 +13,7 @@ */ package com.querydsl.jpa; -import com.mysema.commons.lang.CloseableIterator; -import com.mysema.commons.lang.IteratorAdapter; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.types.FactoryExpression; import jakarta.persistence.Query; import java.util.Iterator; @@ -53,7 +52,7 @@ public CloseableIterator iterate( if (projection != null) { return new TransformingIterator<>(iterator, projection); } else { - return new IteratorAdapter<>(iterator); + return CloseableIterator.of(iterator); } } diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/EclipseLinkHandler.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/EclipseLinkHandler.java index eacef47c87..fe4e028ef1 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/EclipseLinkHandler.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/EclipseLinkHandler.java @@ -13,8 +13,7 @@ */ package com.querydsl.jpa; -import com.mysema.commons.lang.CloseableIterator; -import com.mysema.commons.lang.IteratorAdapter; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.types.FactoryExpression; import jakarta.persistence.PersistenceException; import jakarta.persistence.Query; @@ -96,7 +95,7 @@ public T next() { if (projection != null) { return new TransformingIterator<>(iterator, closeable, projection); } else { - return new IteratorAdapter<>(iterator, closeable); + return CloseableIterator.of(iterator, closeable); } } diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/HibernateHandler.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/HibernateHandler.java index 5c53754467..c014f9599e 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/HibernateHandler.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/HibernateHandler.java @@ -13,8 +13,7 @@ */ package com.querydsl.jpa; -import com.mysema.commons.lang.CloseableIterator; -import com.mysema.commons.lang.IteratorAdapter; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.types.FactoryExpression; import jakarta.persistence.PersistenceException; import jakarta.persistence.Query; @@ -63,7 +62,7 @@ public CloseableIterator iterate(Query query, FactoryExpression projec if (projection != null) { return new TransformingIterator<>(iterator, projection); } else { - return new IteratorAdapter<>(iterator); + return CloseableIterator.of(iterator); } } } diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPASubQuery.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPASubQuery.java index d10bf1b1c1..44f5a50848 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPASubQuery.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPASubQuery.java @@ -13,7 +13,7 @@ */ package com.querydsl.jpa; -import com.mysema.commons.lang.CloseableIterator; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.DefaultQueryMetadata; import com.querydsl.core.NonUniqueResultException; import com.querydsl.core.QueryMetadata; diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLSerializer.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLSerializer.java index d780470bdd..f4971930e3 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLSerializer.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLSerializer.java @@ -384,10 +384,10 @@ private void serializeSources(boolean forCountRow, List joins) { @Override public void visitConstant(Object constant) { if (inCaseOperation && templates.isCaseWithLiterals()) { - if (constant instanceof Collection) { + if (constant instanceof Collection collection) { append("("); var first = true; - for (Object o : (Collection) constant) { + for (Object o : collection) { if (!first) { append(", "); } @@ -517,17 +517,19 @@ protected void visitOperation( if (operator.getClass().getName().endsWith("SQLOps")) { throw new IllegalArgumentException( String.format( - "SQL Expressions like %s are not supported in JPQL - the query language for JPA." - + " SQLExpressions.* can only be used in JPQL queries when these functions" - + " are registered as custom function in your ORM.%n\tTo fix this issue, you" - + " have three options:%n\t1) If you do want to use advanced, dialect" - + " specific, SQL functions within JPQL, make sure to make these functions" - + " available to your ORM through custom functions and register these with" - + " your JPATemplates instance.%n\t2) Use JPASQLQuery instead. This allows" - + " you to generate a pure SQL query based on your JPA metamodel.%n\t3)" - + " Consider using the Blaze-Persistence QueryDSL integration." - + " Blaze-Persistence is an extension on top of JPA that makes various SQL" - + " specific functions like window functions available to JPQL.", + """ + SQL Expressions like %s are not supported in JPQL - the query language for JPA.\ + SQLExpressions.* can only be used in JPQL queries when these functions\ + are registered as custom function in your ORM.%n To fix this issue, you\ + have three options:%n 1) If you do want to use advanced, dialect\ + specific, SQL functions within JPQL, make sure to make these functions\ + available to your ORM through custom functions and register these with\ + your JPATemplates instance.%n 2) Use JPASQLQuery instead. This allows\ + you to generate a pure SQL query based on your JPA metamodel.%n 3)\ + Consider using the Blaze-Persistence QueryDSL integration.\ + Blaze-Persistence is an extension on top of JPA that makes various SQL\ + specific functions like window functions available to JPQL.\ + """, operator.name()), e); } else { diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLTemplates.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLTemplates.java index 8f0d3e73b9..dbb89a0ff5 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLTemplates.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLTemplates.java @@ -212,8 +212,8 @@ public String asLiteral(Object constant) { return constant.toString(); } else if (constant instanceof String) { return "'" + escapeLiteral(constant.toString()) + "'"; - } else if (constant instanceof Enum) { - return constant.getClass().getName() + "." + ((Enum) constant).name(); + } else if (constant instanceof Enum enum1) { + return constant.getClass().getName() + "." + enum1.name(); } else { return "'" + constant.toString() + "'"; } diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/NativeSQLSerializer.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/NativeSQLSerializer.java index 5f6aa5c193..a97948db54 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/NativeSQLSerializer.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/NativeSQLSerializer.java @@ -205,10 +205,10 @@ private static ArrayList createArrayList(Object key) { @Override public void visitConstant(Object constant) { - if (constant instanceof Collection) { + if (constant instanceof Collection collection) { append("("); var first = true; - for (Object element : ((Collection) constant)) { + for (Object element : collection) { if (!first) { append(", "); } diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/QueryHandler.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/QueryHandler.java index 833c218e7c..2c2e087110 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/QueryHandler.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/QueryHandler.java @@ -13,7 +13,7 @@ */ package com.querydsl.jpa; -import com.mysema.commons.lang.CloseableIterator; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.types.FactoryExpression; import jakarta.persistence.Query; import java.util.stream.Stream; diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/ScrollableResultsIterator.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/ScrollableResultsIterator.java index 402aea4c67..4be986252d 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/ScrollableResultsIterator.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/ScrollableResultsIterator.java @@ -10,7 +10,7 @@ */ package com.querydsl.jpa; -import com.mysema.commons.lang.CloseableIterator; +import com.querydsl.core.CloseableIterator; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/TransformingIterator.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/TransformingIterator.java index b90fb534b2..9db5f0ff5a 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/TransformingIterator.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/TransformingIterator.java @@ -13,7 +13,7 @@ */ package com.querydsl.jpa; -import com.mysema.commons.lang.CloseableIterator; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.types.FactoryExpression; import java.io.Closeable; import java.io.IOException; @@ -37,7 +37,7 @@ public class TransformingIterator implements CloseableIterator { public TransformingIterator(Iterator iterator, FactoryExpression projection) { this.iterator = iterator; this.projection = projection; - this.closeable = iterator instanceof Closeable ? (Closeable) iterator : null; + this.closeable = iterator instanceof Closeable c ? c : null; } public TransformingIterator( diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/AbstractHibernateQuery.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/AbstractHibernateQuery.java index d4842c2440..04fb83ebff 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/AbstractHibernateQuery.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/AbstractHibernateQuery.java @@ -13,7 +13,7 @@ */ package com.querydsl.jpa.hibernate; -import com.mysema.commons.lang.CloseableIterator; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.DefaultQueryMetadata; import com.querydsl.core.NonUniqueResultException; import com.querydsl.core.QueryException; diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/HibernateUtil.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/HibernateUtil.java index f8eb6dea36..1f7007b790 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/HibernateUtil.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/HibernateUtil.java @@ -108,10 +108,10 @@ public static void setConstants( private static void setValueWithNumberedLabel( org.hibernate.query.Query query, Integer key, Object val) { - if (val instanceof Collection) { - query.setParameterList(key, (Collection) val); - } else if (val instanceof Object[] && !BUILT_IN.contains(val.getClass())) { - query.setParameterList(key, (Object[]) val); + if (val instanceof Collection collection) { + query.setParameterList(key, collection); + } else if (val instanceof Object[] objects && !BUILT_IN.contains(val.getClass())) { + query.setParameterList(key, objects); } else if (val instanceof Number && TYPES.containsKey(val.getClass())) { query.setParameter(key, val, getType(val.getClass())); } else { diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/sql/AbstractHibernateSQLQuery.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/sql/AbstractHibernateSQLQuery.java index 854d8b3d1d..105102753b 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/sql/AbstractHibernateSQLQuery.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/sql/AbstractHibernateSQLQuery.java @@ -13,7 +13,7 @@ */ package com.querydsl.jpa.hibernate.sql; -import com.mysema.commons.lang.CloseableIterator; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.DefaultQueryMetadata; import com.querydsl.core.NonUniqueResultException; import com.querydsl.core.QueryMetadata; diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/impl/AbstractJPAQuery.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/impl/AbstractJPAQuery.java index e7fa43851a..438d858471 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/impl/AbstractJPAQuery.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/impl/AbstractJPAQuery.java @@ -13,7 +13,7 @@ */ package com.querydsl.jpa.impl; -import com.mysema.commons.lang.CloseableIterator; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.DefaultQueryMetadata; import com.querydsl.core.NonUniqueResultException; import com.querydsl.core.QueryMetadata; @@ -107,8 +107,10 @@ public long fetchCount() { try { if (getMetadata().getGroupBy().size() > 1 || getMetadata().getHaving() != null) { logger.warning( - "Fetchable#fetchCount() was computed in memory! See the Javadoc for" - + " AbstractJPAQuery#fetchCount for more details."); + """ + Fetchable#fetchCount() was computed in memory! See the Javadoc for\ + AbstractJPAQuery#fetchCount for more details.\ + """); var query = createQuery(null, false); return query.getResultList().size(); } @@ -286,8 +288,10 @@ public QueryResults fetchResults() { var modifiers = getMetadata().getModifiers(); if (getMetadata().getGroupBy().size() > 1 || getMetadata().getHaving() != null) { logger.warning( - "Fetchable#fetchResults() was computed in memory! See the Javadoc for" - + " AbstractJPAQuery#fetchResults for more details."); + """ + Fetchable#fetchResults() was computed in memory! See the Javadoc for\ + AbstractJPAQuery#fetchResults for more details.\ + """); var query = createQuery(null, false); @SuppressWarnings("unchecked") List resultList = query.getResultList(); diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/impl/JPAUtil.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/impl/JPAUtil.java index b3e4719f6b..adacb516c3 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/impl/JPAUtil.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/impl/JPAUtil.java @@ -50,8 +50,8 @@ public static void setConstants( Parameter parameter = query.getParameter(i + 1); var parameterType = parameter != null ? parameter.getParameterType() : null; if (parameterType != null && !parameterType.isInstance(val)) { - if (val instanceof Number && Number.class.isAssignableFrom(parameterType)) { - val = MathUtils.cast((Number) val, parameterType); + if (val instanceof Number number && Number.class.isAssignableFrom(parameterType)) { + val = MathUtils.cast(number, parameterType); } } } diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/sql/AbstractJPASQLQuery.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/sql/AbstractJPASQLQuery.java index 36752634cb..c8976cf1c6 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/sql/AbstractJPASQLQuery.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/sql/AbstractJPASQLQuery.java @@ -13,7 +13,7 @@ */ package com.querydsl.jpa.sql; -import com.mysema.commons.lang.CloseableIterator; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.DefaultQueryMetadata; import com.querydsl.core.NonUniqueResultException; import com.querydsl.core.QueryMetadata; diff --git a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QDerbyDialect.java b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QDerbyDialect.java index 7e9c4572dc..8f8d62f9ba 100644 --- a/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QDerbyDialect.java +++ b/querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QDerbyDialect.java @@ -16,7 +16,7 @@ import com.querydsl.core.types.Ops; import com.querydsl.sql.DerbyTemplates; import org.hibernate.boot.model.FunctionContributions; -import org.hibernate.dialect.DerbyDialect; +import org.hibernate.community.dialect.DerbyDialect; /** {@code QDerbyDialect} extends {@code DerbyDialect} with additional functions */ public class QDerbyDialect extends DerbyDialect { diff --git a/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/AbstractJPATest.java b/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/AbstractJPATest.java index 6f22696422..fe0f91863d 100644 --- a/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/AbstractJPATest.java +++ b/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/AbstractJPATest.java @@ -24,10 +24,10 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; -import com.mysema.commons.lang.Pair; import com.querydsl.core.Fetchable; import com.querydsl.core.FilterFactory; import com.querydsl.core.MatchingFiltersFactory; +import com.querydsl.core.Pair; import com.querydsl.core.ProjectionsFactory; import com.querydsl.core.QueryExecution; import com.querydsl.core.QuerydslModule; @@ -283,6 +283,7 @@ public void aggregates_uniqueResult_min() { } @Test + @NoEclipseLink public void alias() { assertThat(query().from(cat).select(cat.id.as(cat.id)).fetch()).hasSize(6); } diff --git a/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/HibernateBase.java b/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/HibernateBase.java index 4b2871944d..3c72301628 100644 --- a/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/HibernateBase.java +++ b/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/HibernateBase.java @@ -16,7 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import com.mysema.commons.lang.CloseableIterator; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.DefaultQueryMetadata; import com.querydsl.core.Target; import com.querydsl.core.Tuple; @@ -81,7 +81,7 @@ public void setSession(Session session) { @Override protected void save(Object entity) { - session.save(entity); + session.persist(entity); } @Test diff --git a/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/HibernateHandlerTest.java b/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/HibernateHandlerTest.java index b10d025ac8..503429e745 100644 --- a/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/HibernateHandlerTest.java +++ b/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/HibernateHandlerTest.java @@ -8,7 +8,7 @@ import static org.easymock.EasyMock.verify; import static org.hibernate.ScrollMode.FORWARD_ONLY; -import com.mysema.commons.lang.IteratorAdapter; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.types.FactoryExpression; import com.querydsl.jpa.domain4.Library; import jakarta.persistence.PersistenceException; @@ -119,7 +119,7 @@ public void should_return_iterator_adapter_when_call_iterate_function() { expect(queryResultList.iterator()).andReturn(iterator); replay(query); - assertThat(hibernateHandler.iterate(query, null).getClass()).isEqualTo(IteratorAdapter.class); + assertThat(hibernateHandler.iterate(query, null)).isInstanceOf(CloseableIterator.class); } @Test diff --git a/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/HibernateSQLBase.java b/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/HibernateSQLBase.java index e75c174210..acae720222 100644 --- a/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/HibernateSQLBase.java +++ b/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/HibernateSQLBase.java @@ -56,12 +56,12 @@ public void setSession(Session session) { @Before public void setUp() { if (query().from(cat).fetchCount() == 0) { - session.save(new Cat("Beck", 1, Color.BLACK)); - session.save(new Cat("Kate", 2, Color.BLACK)); - session.save(new Cat("Kitty", 3, Color.BLACK)); - session.save(new Cat("Bobby", 4, Color.BLACK)); - session.save(new Cat("Harold", 5, Color.BLACK)); - session.save(new Cat("Tim", 6, Color.BLACK)); + session.persist(new Cat("Beck", 1, Color.BLACK)); + session.persist(new Cat("Kate", 2, Color.BLACK)); + session.persist(new Cat("Kitty", 3, Color.BLACK)); + session.persist(new Cat("Bobby", 4, Color.BLACK)); + session.persist(new Cat("Harold", 5, Color.BLACK)); + session.persist(new Cat("Tim", 6, Color.BLACK)); session.flush(); } } diff --git a/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/IntegrationBase.java b/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/IntegrationBase.java index 3aef7b0cb9..ec9c5b8cc7 100644 --- a/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/IntegrationBase.java +++ b/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/IntegrationBase.java @@ -98,8 +98,8 @@ private HibernateInsertClause insert(EntityPath entity) { @Test public void scroll() { - session.save(new Cat("Bob", 10)); - session.save(new Cat("Steve", 11)); + session.persist(new Cat("Bob", 10)); + session.persist(new Cat("Steve", 11)); var cat = QCat.cat; HibernateQuery query = new HibernateQuery(session); @@ -112,7 +112,7 @@ public void scroll() { @Test public void insert() { - session.save(new Cat("Bob", 10)); + session.persist(new Cat("Bob", 10)); var cat = QCat.cat; var amount = insert(cat).set(cat.name, "Bobby").set(cat.alive, false).execute(); @@ -123,7 +123,7 @@ public void insert() { @Test public void insert2() { - session.save(new Cat("Bob", 10)); + session.persist(new Cat("Bob", 10)); var cat = QCat.cat; var amount = insert(cat).columns(cat.name, cat.alive).values("Bobby", false).execute(); @@ -134,7 +134,7 @@ public void insert2() { @Test public void insert3() { - session.save(new Cat("Bob", 10)); + session.persist(new Cat("Bob", 10)); var cat = QCat.cat; var bob = new QCat("Bob"); @@ -151,8 +151,8 @@ public void insert3() { @Test public void update() { - session.save(new Cat("Bob", 10)); - session.save(new Cat("Steve", 11)); + session.persist(new Cat("Bob", 10)); + session.persist(new Cat("Steve", 11)); var cat = QCat.cat; var amount = @@ -168,8 +168,8 @@ public void update() { @Test public void update_with_null() { - session.save(new Cat("Bob", 10)); - session.save(new Cat("Steve", 11)); + session.persist(new Cat("Bob", 10)); + session.persist(new Cat("Steve", 11)); var cat = QCat.cat; var amount = @@ -183,8 +183,8 @@ public void update_with_null() { @Test public void delete() { - session.save(new Cat("Bob", 10)); - session.save(new Cat("Steve", 11)); + session.persist(new Cat("Bob", 10)); + session.persist(new Cat("Steve", 11)); var cat = QCat.cat; var amount = delete(cat).where(cat.name.eq("Bob")).execute(); @@ -195,7 +195,7 @@ public void delete() { public void collection() throws Exception { List cats = Arrays.asList(new Cat("Bob", 10), new Cat("Steve", 11)); for (Cat cat : cats) { - session.save(cat); + session.persist(cat); } query().from(cat).innerJoin(cat.kittens, kitten).where(kitten.in(cats)).parse(); diff --git a/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/JPQLSerializerTest.java b/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/JPQLSerializerTest.java index 3040899b07..4a769c1a3e 100644 --- a/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/JPQLSerializerTest.java +++ b/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/JPQLSerializerTest.java @@ -250,7 +250,10 @@ public void nullsFirst() { md.addOrderBy(cat.name.asc().nullsFirst()); serializer.serialize(md, false, null); assertThat(serializer.toString()) - .isEqualTo("select cat\n" + "from Cat cat\n" + "order by cat.name asc nulls first"); + .isEqualTo(""" + select cat + from Cat cat + order by cat.name asc nulls first"""); } @Test @@ -262,7 +265,10 @@ public void nullsLast() { md.addOrderBy(cat.name.asc().nullsLast()); serializer.serialize(md, false, null); assertThat(serializer.toString()) - .isEqualTo("select cat\n" + "from Cat cat\n" + "order by cat.name asc nulls last"); + .isEqualTo(""" + select cat + from Cat cat + order by cat.name asc nulls last"""); } @SuppressWarnings("unchecked") diff --git a/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/QueryHelper.java b/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/QueryHelper.java index 5a01c6e1bb..bc3e664bd2 100644 --- a/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/QueryHelper.java +++ b/querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/QueryHelper.java @@ -13,7 +13,7 @@ */ package com.querydsl.jpa; -import com.mysema.commons.lang.CloseableIterator; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.DefaultQueryMetadata; import com.querydsl.core.NonUniqueResultException; import com.querydsl.core.QueryMetadata; diff --git a/querydsl-libraries/querydsl-kotlin/pom.xml b/querydsl-libraries/querydsl-kotlin/pom.xml index b473f3325a..0285803835 100644 --- a/querydsl-libraries/querydsl-kotlin/pom.xml +++ b/querydsl-libraries/querydsl-kotlin/pom.xml @@ -4,7 +4,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-kotlin diff --git a/querydsl-libraries/querydsl-lucene3/README.md b/querydsl-libraries/querydsl-lucene3/README.md deleted file mode 100644 index 898825b003..0000000000 --- a/querydsl-libraries/querydsl-lucene3/README.md +++ /dev/null @@ -1,59 +0,0 @@ -## Querydsl Lucene 3 - -The Lucene module provides integration with the Lucene 3 indexing library. - -**Maven integration** - - Add the following dependencies to your Maven project : - -```XML - - io.github.openfeign.querydsl - querydsl-lucene3 - ${querydsl.version} - -``` - -**Creating the query types** - -With fields year and title a manually created query type could look something like this: - -```JAVA -public class QDocument extends EntityPathBase{ - private static final long serialVersionUID = -4872833626508344081L; - - public QDocument(String var) { - super(Document.class, PathMetadataFactory.forVariable(var)); - } - - public final StringPath year = createString("year"); - - public final StringPath title = createString("title"); -} -``` - -QDocument represents a Lucene document with the fields year and title. - -Code generation is not available for Lucene, since no schema data is available. - -**Querying** - -Querying with Querydsl Lucene is as simple as this: - -```JAVA -QDocument doc = new QDocument("doc"); - -IndexSearcher searcher = new IndexSearcher(index); -LuceneQuery query = new LuceneQuery(true, searcher); -List documents = query - .where(doc.year.between("1800", "2000").and(doc.title.startsWith("Huckle")) - .fetch(); - ``` - -which is transformed into the following Lucene query : - -``` -+year:[1800 TO 2000] +title:huckle* -``` - -For more information on the Querydsl Lucene module visit the reference documentation http://www.querydsl.com/static/querydsl/latest/reference/html/ch02s05.html diff --git a/querydsl-libraries/querydsl-lucene3/pom.xml b/querydsl-libraries/querydsl-lucene3/pom.xml deleted file mode 100644 index 54437d3498..0000000000 --- a/querydsl-libraries/querydsl-lucene3/pom.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - 4.0.0 - - - io.github.openfeign.querydsl - querydsl-libraries - 6.0-SNAPSHOT - - - querydsl-lucene3 - Querydsl - Lucene 3 support - Lucene support for Querydsl - - - 3.6.2 - org.apache.lucene.*;version="[3.6,4)", - ${osgi.import.package.root} - - - - - org.jetbrains - annotations - provided - - - org.apache.lucene - lucene-core - ${lucene.version} - provided - - - org.apache.lucene - lucene-queries - ${lucene.version} - provided - - - io.github.openfeign.querydsl - querydsl-core - ${project.version} - - - - - io.github.openfeign.querydsl - querydsl-core - ${project.version} - test-jar - test - - - - io.github.openfeign.querydsl - querydsl-apt - ${project.version} - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.3.0 - - - - com.querydsl.lucene3 - - - - - - - org.apache.felix - maven-bundle-plugin - - - - org.apache.maven.plugins - maven-compiler-plugin - - - com.querydsl.apt.QuerydslAnnotationProcessor - - - - - - diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/AbstractLuceneQuery.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/AbstractLuceneQuery.java deleted file mode 100644 index ed518222fd..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/AbstractLuceneQuery.java +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -import com.mysema.commons.lang.CloseableIterator; -import com.mysema.commons.lang.EmptyCloseableIterator; -import com.mysema.commons.lang.IteratorAdapter; -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.Fetchable; -import com.querydsl.core.NonUniqueResultException; -import com.querydsl.core.QueryException; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.QueryModifiers; -import com.querydsl.core.QueryResults; -import com.querydsl.core.SimpleQuery; -import com.querydsl.core.support.QueryMixin; -import com.querydsl.core.types.OrderSpecifier; -import com.querydsl.core.types.ParamExpression; -import com.querydsl.core.types.Path; -import com.querydsl.core.types.Predicate; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.FieldSelector; -import org.apache.lucene.document.MapFieldSelector; -import org.apache.lucene.search.ChainedFilter; -import org.apache.lucene.search.DuplicateFilter; -import org.apache.lucene.search.Filter; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.QueryWrapperFilter; -import org.apache.lucene.search.ScoreDoc; -import org.apache.lucene.search.Sort; -import org.apache.lucene.search.TotalHitCountCollector; -import org.jetbrains.annotations.Nullable; - -/** - * AbstractLuceneQuery is an abstract super class for Lucene query implementations - * - * @author tiwe - * @param projection type - * @param concrete subtype of query - */ -public abstract class AbstractLuceneQuery> - implements SimpleQuery, Fetchable { - - private static final String JAVA_ISO_CONTROL = "[\\p{Cntrl}&&[^\r\n\t]]"; - - private final QueryMixin queryMixin; - - private final IndexSearcher searcher; - - private final LuceneSerializer serializer; - - private final Function transformer; - - @Nullable private FieldSelector fieldSelector; - - private List filters = Collections.emptyList(); - - @Nullable private Filter filter; - - @Nullable private Sort querySort; - - @SuppressWarnings("unchecked") - public AbstractLuceneQuery( - LuceneSerializer serializer, IndexSearcher searcher, Function transformer) { - queryMixin = new QueryMixin((Q) this, new DefaultQueryMetadata()); - this.serializer = serializer; - this.searcher = searcher; - this.transformer = transformer; - } - - public AbstractLuceneQuery(IndexSearcher searcher, Function transformer) { - this(LuceneSerializer.DEFAULT, searcher, transformer); - } - - private long innerCount() { - try { - final int maxDoc = searcher.maxDoc(); - if (maxDoc == 0) { - return 0; - } - TotalHitCountCollector collector = new TotalHitCountCollector(); - searcher.search(createQuery(), getFilter(), collector); - return collector.getTotalHits(); - } catch (IOException | IllegalArgumentException e) { - throw new QueryException(e); - } - } - - @Override - public long fetchCount() { - return innerCount(); - } - - protected Query createQuery() { - if (queryMixin.getMetadata().getWhere() == null) { - return new MatchAllDocsQuery(); - } - return serializer.toQuery(queryMixin.getMetadata().getWhere(), queryMixin.getMetadata()); - } - - /** - * Create a filter for constraints defined in this query - * - * @return filter - */ - public Filter asFilter() { - return new QueryWrapperFilter(createQuery()); - } - - @Override - public Q distinct() { - throw new UnsupportedOperationException("use distinct(path) instead"); - } - - /** - * Add a DuplicateFilter for the field of the given property path - * - * @param property distinct property - * @return the current object - */ - public Q distinct(Path property) { - return filter(new DuplicateFilter(serializer.toField(property))); - } - - /** - * Apply the given Lucene filter to the search results - * - * @param filter filter - * @return the current object - */ - @SuppressWarnings("unchecked") - public Q filter(Filter filter) { - if (filters.isEmpty()) { - this.filter = filter; - filters = Collections.singletonList(filter); - } else { - this.filter = null; - if (filters.size() == 1) { - filters = new ArrayList(); - } - filters.add(filter); - } - return (Q) this; - } - - private Filter getFilter() { - if (filter == null && !filters.isEmpty()) { - filter = new ChainedFilter(filters.toArray(new Filter[0])); - } - return filter; - } - - @Override - public Q limit(long limit) { - return queryMixin.limit(limit); - } - - @Override - public CloseableIterator iterate() { - final QueryMetadata metadata = queryMixin.getMetadata(); - final List> orderBys = metadata.getOrderBy(); - final Integer queryLimit = metadata.getModifiers().getLimitAsInteger(); - final Integer queryOffset = metadata.getModifiers().getOffsetAsInteger(); - Sort sort = querySort; - int limit; - final int offset = queryOffset != null ? queryOffset : 0; - try { - limit = maxDoc(); - if (limit == 0) { - return new EmptyCloseableIterator(); - } - } catch (IOException | IllegalArgumentException e) { - throw new QueryException(e); - } - if (queryLimit != null && queryLimit < limit) { - limit = queryLimit; - } - if (sort == null && !orderBys.isEmpty()) { - sort = serializer.toSort(orderBys); - } - - try { - ScoreDoc[] scoreDocs; - int sumOfLimitAndOffset = limit + offset; - if (sumOfLimitAndOffset < 1) { - throw new QueryException( - "The given limit (" - + limit - + ") and offset (" - + offset - + ") cause an integer overflow."); - } - if (sort != null) { - scoreDocs = - searcher.search(createQuery(), getFilter(), sumOfLimitAndOffset, sort).scoreDocs; - } else { - scoreDocs = searcher.search(createQuery(), getFilter(), sumOfLimitAndOffset).scoreDocs; - } - if (offset < scoreDocs.length) { - return new ResultIterator(scoreDocs, offset, searcher, fieldSelector, transformer); - } - return new EmptyCloseableIterator(); - } catch (final IOException e) { - throw new QueryException(e); - } - } - - private List innerList() { - return new IteratorAdapter(iterate()).asList(); - } - - @Override - public List fetch() { - return innerList(); - } - - /** - * Set the given FieldSelector to the query - * - * @param fieldSelector field selector - * @return the current object - */ - @SuppressWarnings("unchecked") - public Q load(FieldSelector fieldSelector) { - this.fieldSelector = fieldSelector; - return (Q) this; - } - - /** - * Load only the fields of the given paths - * - * @param paths fields to load - * @return the current object - */ - @SuppressWarnings("unchecked") - public Q load(Path... paths) { - List fields = new ArrayList(paths.length); - for (Path path : paths) { - fields.add(serializer.toField(path)); - } - this.fieldSelector = new MapFieldSelector(fields); - return (Q) this; - } - - @Override - public QueryResults fetchResults() { - List documents = innerList(); - /* - * TODO Get rid of fetchCount(). It could be implemented by iterating the - * fetch results in fetch* from n to m. - */ - return new QueryResults(documents, queryMixin.getMetadata().getModifiers(), innerCount()); - } - - @Override - public Q offset(long offset) { - return queryMixin.offset(offset); - } - - public Q orderBy(OrderSpecifier o) { - return queryMixin.orderBy(o); - } - - @Override - public Q orderBy(OrderSpecifier... o) { - return queryMixin.orderBy(o); - } - - @Override - public Q restrict(QueryModifiers modifiers) { - return queryMixin.restrict(modifiers); - } - - @Override - public

Q set(ParamExpression

param, P value) { - return queryMixin.set(param, value); - } - - @SuppressWarnings("unchecked") - public Q sort(Sort sort) { - this.querySort = sort; - return (Q) this; - } - - @Nullable - private T oneResult(boolean unique) { - try { - int maxDoc = maxDoc(); - if (maxDoc == 0) { - return null; - } - final ScoreDoc[] scoreDocs = searcher.search(createQuery(), getFilter(), maxDoc).scoreDocs; - int index = 0; - QueryModifiers modifiers = queryMixin.getMetadata().getModifiers(); - Long offset = modifiers.getOffset(); - if (offset != null) { - index = offset.intValue(); - } - Long limit = modifiers.getLimit(); - if (unique - && (limit == null ? scoreDocs.length - index > 1 : limit > 1 && scoreDocs.length > 1)) { - throw new NonUniqueResultException( - "Unique result requested, but " + scoreDocs.length + " found."); - } else if (scoreDocs.length > index) { - Document document; - if (fieldSelector != null) { - document = searcher.doc(scoreDocs[index].doc, fieldSelector); - } else { - document = searcher.doc(scoreDocs[index].doc); - } - return transformer.apply(document); - } else { - return null; - } - } catch (IOException | IllegalArgumentException e) { - throw new QueryException(e); - } - } - - @Override - public T fetchFirst() { - return oneResult(false); - } - - @Override - public T fetchOne() throws NonUniqueResultException { - return oneResult(true); - } - - public Q where(Predicate e) { - return queryMixin.where(e); - } - - @Override - public Q where(Predicate... e) { - return queryMixin.where(e); - } - - @Override - public String toString() { - return createQuery().toString().replaceAll(JAVA_ISO_CONTROL, "_"); - } - - private int maxDoc() throws IOException { - return searcher.maxDoc(); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/IgnoreCaseUnsupportedException.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/IgnoreCaseUnsupportedException.java deleted file mode 100644 index 79bbabed31..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/IgnoreCaseUnsupportedException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -/** - * Thrown for case ignore usage - * - * @author tiwe - */ -public class IgnoreCaseUnsupportedException extends UnsupportedOperationException { - - private static final long serialVersionUID = 412913389929530788L; - - public IgnoreCaseUnsupportedException() { - super("Ignore case queries are not supported with Lucene"); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneExpressions.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneExpressions.java deleted file mode 100644 index 5539335652..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneExpressions.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -import com.querydsl.core.types.Path; -import com.querydsl.core.types.dsl.BooleanExpression; -import org.apache.lucene.index.Term; -import org.apache.lucene.search.FuzzyQuery; - -/** - * Utility methods to create filter expressions for Lucene queries that are not covered by the - * Querydsl standard expression model - * - * @author tiwe - */ -public final class LuceneExpressions { - - /** - * Create a fuzzy query - * - * @param path path - * @param value value to match - * @return condition - */ - public static BooleanExpression fuzzyLike(Path path, String value) { - Term term = new Term(path.getMetadata().getName(), value); - return new QueryElement(new FuzzyQuery(term)); - } - - /** - * Create a fuzzy query - * - * @param path path - * @param value value to match - * @param minimumSimilarity a value between 0 and 1 to set the required similarity - * @return condition - */ - public static BooleanExpression fuzzyLike( - Path path, String value, float minimumSimilarity) { - Term term = new Term(path.getMetadata().getName(), value); - return new QueryElement(new FuzzyQuery(term, minimumSimilarity)); - } - - /** - * Create a fuzzy query - * - * @param path path - * @param value value to match - * @param minimumSimilarity a value between 0 and 1 to set the required similarity - * @param prefixLength length of common (non-fuzzy) prefix - * @return condition - */ - public static BooleanExpression fuzzyLike( - Path path, String value, float minimumSimilarity, int prefixLength) { - Term term = new Term(path.getMetadata().getName(), value); - return new QueryElement(new FuzzyQuery(term, minimumSimilarity, prefixLength)); - } - - private LuceneExpressions() {} -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneOps.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneOps.java deleted file mode 100644 index cc598e440b..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneOps.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -import com.querydsl.core.types.Operator; - -/** - * Lucene specific operators - * - * @author tiwe - */ -public enum LuceneOps implements Operator { - LUCENE_QUERY(Object.class), - PHRASE(String.class), - TERM(String.class); - - private final Class type; - - LuceneOps(Class type) { - this.type = type; - } - - @Override - public Class getType() { - return type; - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneQuery.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneQuery.java deleted file mode 100644 index ead825a659..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneQuery.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.search.IndexSearcher; - -/** - * {@code LuceneQuery} is a Querydsl query implementation for Lucene queries. - * - *

Example: - * - *

{@code
- * QDocument doc = new QDocument("doc");
- *
- * IndexSearcher searcher = new IndexSearcher(index);
- * LuceneQuery query = new LuceneQuery(true, searcher);
- * List documents = query
- *     .where(doc.year.between("1800", "2000").and(doc.title.startsWith("Huckle"))
- *     .fetch();
- * }
- * - * @author vema - */ -public class LuceneQuery extends AbstractLuceneQuery { - - private static final Function TRANSFORMER = - new Function() { - @Override - public Document apply(Document input) { - return input; - } - }; - - public LuceneQuery(IndexSearcher searcher) { - super(searcher, TRANSFORMER); - } - - public LuceneQuery(LuceneSerializer luceneSerializer, IndexSearcher searcher) { - super(luceneSerializer, searcher, TRANSFORMER); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneSerializer.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneSerializer.java deleted file mode 100644 index 1fac8516ba..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneSerializer.java +++ /dev/null @@ -1,542 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.*; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.*; -import org.apache.lucene.index.Term; -import org.apache.lucene.queryParser.QueryParser; -import org.apache.lucene.search.*; -import org.apache.lucene.search.BooleanClause.Occur; -import org.apache.lucene.util.NumericUtils; -import org.jetbrains.annotations.Nullable; - -/** - * Serializes Querydsl queries to Lucene queries. - * - * @author vema - */ -public class LuceneSerializer { - private static final Map, Integer> sortFields = new HashMap, Integer>(); - - static { - sortFields.put(Integer.class, SortField.INT); - sortFields.put(Float.class, SortField.FLOAT); - sortFields.put(Long.class, SortField.LONG); - sortFields.put(Double.class, SortField.DOUBLE); - sortFields.put(Short.class, SortField.SHORT); - sortFields.put(Byte.class, SortField.BYTE); - sortFields.put(BigDecimal.class, SortField.DOUBLE); - sortFields.put(BigInteger.class, SortField.LONG); - } - - public static final LuceneSerializer DEFAULT = new LuceneSerializer(false, true); - - private final boolean lowerCase; - - private final boolean splitTerms; - - private final Locale sortLocale; - - public LuceneSerializer(boolean lowerCase, boolean splitTerms) { - this(lowerCase, splitTerms, Locale.getDefault()); - } - - public LuceneSerializer(boolean lowerCase, boolean splitTerms, Locale sortLocale) { - this.lowerCase = lowerCase; - this.splitTerms = splitTerms; - this.sortLocale = sortLocale; - } - - private Query toQuery(Operation operation, QueryMetadata metadata) { - Operator op = operation.getOperator(); - if (op == Ops.OR) { - return toTwoHandSidedQuery(operation, Occur.SHOULD, metadata); - } else if (op == Ops.AND) { - return toTwoHandSidedQuery(operation, Occur.MUST, metadata); - } else if (op == Ops.NOT) { - BooleanQuery bq = new BooleanQuery(); - bq.add(new BooleanClause(toQuery(operation.getArg(0), metadata), Occur.MUST_NOT)); - bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); - return bq; - } else if (op == Ops.LIKE) { - return like(operation, metadata); - } else if (op == Ops.LIKE_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.EQ) { - return eq(operation, metadata, false); - } else if (op == Ops.EQ_IGNORE_CASE) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.NE) { - return ne(operation, metadata, false); - } else if (op == Ops.STARTS_WITH) { - return startsWith(metadata, operation, false); - } else if (op == Ops.STARTS_WITH_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.ENDS_WITH) { - return endsWith(operation, metadata, false); - } else if (op == Ops.ENDS_WITH_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.STRING_CONTAINS) { - return stringContains(operation, metadata, false); - } else if (op == Ops.STRING_CONTAINS_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.BETWEEN) { - return between(operation, metadata); - } else if (op == Ops.IN) { - return in(operation, metadata, false); - } else if (op == Ops.NOT_IN) { - return notIn(operation, metadata, false); - } else if (op == Ops.LT) { - return lt(operation, metadata); - } else if (op == Ops.GT) { - return gt(operation, metadata); - } else if (op == Ops.LOE) { - return le(operation, metadata); - } else if (op == Ops.GOE) { - return ge(operation, metadata); - } else if (op == LuceneOps.LUCENE_QUERY) { - @SuppressWarnings("unchecked") // This is the expected type - Query rv = ((Constant) operation.getArg(0)).getConstant(); - return rv; - } - throw new UnsupportedOperationException("Illegal operation " + operation); - } - - private Query toTwoHandSidedQuery(Operation operation, Occur occur, QueryMetadata metadata) { - Query lhs = toQuery(operation.getArg(0), metadata); - Query rhs = toQuery(operation.getArg(1), metadata); - BooleanQuery bq = new BooleanQuery(); - bq.add(createBooleanClause(lhs, occur)); - bq.add(createBooleanClause(rhs, occur)); - return bq; - } - - /** - * If the query is a BooleanQuery and it contains a single Occur.MUST_NOT clause it will be - * returned as is. Otherwise it will be wrapped in a BooleanClause with the given Occur. - */ - private BooleanClause createBooleanClause(Query query, Occur occur) { - if (query instanceof BooleanQuery) { - BooleanClause[] clauses = ((BooleanQuery) query).getClauses(); - if (clauses.length == 1 && clauses[0].getOccur().equals(Occur.MUST_NOT)) { - return clauses[0]; - } - } - return new BooleanClause(query, occur); - } - - protected Query like(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convert(path, operation.getArg(1)); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (String s : terms) { - bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST); - } - return bq; - } - return new WildcardQuery(new Term(field, terms[0])); - } - - protected Query eq(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - - if (Number.class.isAssignableFrom(operation.getArg(1).getType())) { - @SuppressWarnings("unchecked") // guarded by previous check - Constant rightArg = (Constant) operation.getArg(1); - return new TermQuery(new Term(field, convertNumber(rightArg.getConstant()))); - } - - return eq(field, convert(path, operation.getArg(1), metadata), ignoreCase); - } - - private String convertNumber(Number number) { - if (Integer.class.isInstance(number)) { - return NumericUtils.intToPrefixCoded(number.intValue()); - } else if (Double.class.isInstance(number)) { - return NumericUtils.doubleToPrefixCoded(number.doubleValue()); - } else if (Long.class.isInstance(number)) { - return NumericUtils.longToPrefixCoded(number.longValue()); - } else if (Float.class.isInstance(number)) { - return NumericUtils.floatToPrefixCoded(number.floatValue()); - } else if (Byte.class.isInstance(number)) { - return NumericUtils.intToPrefixCoded(number.intValue()); - } else if (Short.class.isInstance(number)) { - return NumericUtils.intToPrefixCoded(number.intValue()); - } else if (BigDecimal.class.isInstance(number)) { - return NumericUtils.doubleToPrefixCoded(number.doubleValue()); - } else if (BigInteger.class.isInstance(number)) { - return NumericUtils.longToPrefixCoded(number.longValue()); - } else { - throw new IllegalArgumentException("Unsupported numeric type " + number.getClass().getName()); - } - } - - protected Query eq(String field, String[] terms, boolean ignoreCase) { - if (terms.length > 1) { - PhraseQuery pq = new PhraseQuery(); - for (String s : terms) { - pq.add(new Term(field, s)); - } - return pq; - } - return new TermQuery(new Term(field, terms[0])); - } - - protected Query in(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - Path path = getPath(operation.getArg(0)); - String field = toField(path); - @SuppressWarnings("unchecked") // This is the second argument type - Constant> collConstant = (Constant>) operation.getArg(1); - Collection values = collConstant.getConstant(); - BooleanQuery bq = new BooleanQuery(); - if (Number.class.isAssignableFrom(path.getType())) { - for (Object value : values) { - TermQuery eq = new TermQuery(new Term(field, convertNumber((Number) value))); - bq.add(eq, Occur.SHOULD); - } - } else { - for (Object value : values) { - String[] str = convert(path, value); - bq.add(eq(field, str, ignoreCase), Occur.SHOULD); - } - } - return bq; - } - - protected Query notIn(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - BooleanQuery bq = new BooleanQuery(); - bq.add(new BooleanClause(in(operation, metadata, false), Occur.MUST_NOT)); - bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); - return bq; - } - - protected Query ne(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - BooleanQuery bq = new BooleanQuery(); - bq.add(new BooleanClause(eq(operation, metadata, ignoreCase), Occur.MUST_NOT)); - bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); - return bq; - } - - protected Query startsWith(QueryMetadata metadata, Operation operation, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convertEscaped(path, operation.getArg(1), metadata); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (int i = 0; i < terms.length; ++i) { - String s = i == 0 ? terms[i] + "*" : "*" + terms[i] + "*"; - bq.add(new WildcardQuery(new Term(field, s)), Occur.MUST); - } - return bq; - } - return new PrefixQuery(new Term(field, terms[0])); - } - - protected Query stringContains( - Operation operation, QueryMetadata metadata, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convertEscaped(path, operation.getArg(1), metadata); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (String s : terms) { - bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST); - } - return bq; - } - return new WildcardQuery(new Term(field, "*" + terms[0] + "*")); - } - - protected Query endsWith(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convertEscaped(path, operation.getArg(1), metadata); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (int i = 0; i < terms.length; ++i) { - String s = i == terms.length - 1 ? "*" + terms[i] : "*" + terms[i] + "*"; - bq.add(new WildcardQuery(new Term(field, s)), Occur.MUST); - } - return bq; - } - return new WildcardQuery(new Term(field, "*" + terms[0])); - } - - protected Query between(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - // TODO Phrase not properly supported - return range( - path, toField(path), operation.getArg(1), operation.getArg(2), true, true, metadata); - } - - protected Query lt(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), null, operation.getArg(1), false, false, metadata); - } - - protected Query gt(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), operation.getArg(1), null, false, false, metadata); - } - - protected Query le(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), null, operation.getArg(1), true, true, metadata); - } - - protected Query ge(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), operation.getArg(1), null, true, true, metadata); - } - - protected Query range( - Path leftHandSide, - String field, - @Nullable Expression min, - @Nullable Expression max, - boolean minInc, - boolean maxInc, - QueryMetadata metadata) { - if (min != null && Number.class.isAssignableFrom(min.getType()) - || max != null && Number.class.isAssignableFrom(max.getType())) { - @SuppressWarnings("unchecked") // guarded by previous check - Constant minConstant = (Constant) min; - @SuppressWarnings("unchecked") // guarded by previous check - Constant maxConstant = (Constant) max; - - Class numType = - minConstant != null ? minConstant.getType() : maxConstant.getType(); - // this is not necessarily safe, but compile time checking - // on the user side mandates these types to be interchangeable - @SuppressWarnings("unchecked") - Class unboundedNumType = (Class) numType; - return numericRange( - unboundedNumType, - field, - minConstant == null ? null : minConstant.getConstant(), - maxConstant == null ? null : maxConstant.getConstant(), - minInc, - maxInc); - } - return stringRange(leftHandSide, field, min, max, minInc, maxInc, metadata); - } - - protected NumericRangeQuery numericRange( - Class clazz, - String field, - @Nullable N min, - @Nullable N max, - boolean minInc, - boolean maxInc) { - if (clazz.equals(Integer.class)) { - return NumericRangeQuery.newIntRange(field, (Integer) min, (Integer) max, minInc, maxInc); - } else if (clazz.equals(Double.class)) { - return NumericRangeQuery.newDoubleRange(field, (Double) min, (Double) max, minInc, minInc); - } else if (clazz.equals(Float.class)) { - return NumericRangeQuery.newFloatRange(field, (Float) min, (Float) max, minInc, minInc); - } else if (clazz.equals(Long.class)) { - return NumericRangeQuery.newLongRange(field, (Long) min, (Long) max, minInc, minInc); - } else if (clazz.equals(Byte.class) || clazz.equals(Short.class)) { - return NumericRangeQuery.newIntRange( - field, - min != null ? min.intValue() : null, - max != null ? max.intValue() : null, - minInc, - maxInc); - } else { - throw new IllegalArgumentException("Unsupported numeric type " + clazz.getName()); - } - } - - protected Query stringRange( - Path leftHandSide, - String field, - @Nullable Expression min, - @Nullable Expression max, - boolean minInc, - boolean maxInc, - QueryMetadata metadata) { - - if (min == null) { - return new TermRangeQuery( - field, null, convert(leftHandSide, max, metadata)[0], minInc, maxInc); - } else if (max == null) { - return new TermRangeQuery( - field, convert(leftHandSide, min, metadata)[0], null, minInc, maxInc); - } else { - return new TermRangeQuery( - field, - convert(leftHandSide, min, metadata)[0], - convert(leftHandSide, max, metadata)[0], - minInc, - maxInc); - } - } - - private Path getPath(Expression leftHandSide) { - if (leftHandSide instanceof Path) { - return (Path) leftHandSide; - } else if (leftHandSide instanceof Operation) { - Operation operation = (Operation) leftHandSide; - if (operation.getOperator() == Ops.LOWER || operation.getOperator() == Ops.UPPER) { - return (Path) operation.getArg(0); - } - } - throw new IllegalArgumentException("Unable to transform " + leftHandSide + " to path"); - } - - /** - * template method, override to customize - * - * @param path path - * @return field name - */ - protected String toField(Path path) { - PathMetadata md = path.getMetadata(); - if (md.getPathType() == PathType.COLLECTION_ANY) { - return toField(md.getParent()); - } else { - String rv = md.getName(); - if (md.getParent() != null) { - Path parent = md.getParent(); - if (parent.getMetadata().getPathType() != PathType.VARIABLE) { - rv = toField(parent) + "." + rv; - } - } - return rv; - } - } - - private void verifyArguments(Operation operation) { - List> arguments = operation.getArgs(); - for (int i = 1; i < arguments.size(); ++i) { - if (!(arguments.get(i) instanceof Constant) - && !(arguments.get(i) instanceof ParamExpression) - && !(arguments.get(i) instanceof PhraseElement) - && !(arguments.get(i) instanceof TermElement)) { - throw new IllegalArgumentException( - "operand was of unsupported type " + arguments.get(i).getClass().getName()); - } - } - } - - /** - * template method - * - * @param leftHandSide left hand side - * @param rightHandSide right hand side - * @return results - */ - protected String[] convert( - Path leftHandSide, Expression rightHandSide, QueryMetadata metadata) { - if (rightHandSide instanceof Operation) { - Operation operation = (Operation) rightHandSide; - if (operation.getOperator() == LuceneOps.PHRASE) { - return operation.getArg(0).toString().split("\\s+"); - } else if (operation.getOperator() == LuceneOps.TERM) { - return new String[] {operation.getArg(0).toString()}; - } else { - throw new IllegalArgumentException(rightHandSide.toString()); - } - } else if (rightHandSide instanceof ParamExpression) { - Object value = metadata.getParams().get(rightHandSide); - if (value == null) { - throw new ParamNotSetException((ParamExpression) rightHandSide); - } - return convert(leftHandSide, value); - - } else if (rightHandSide instanceof Constant) { - return convert(leftHandSide, ((Constant) rightHandSide).getConstant()); - } else { - throw new IllegalArgumentException(rightHandSide.toString()); - } - } - - /** - * template method - * - * @param leftHandSide left hand side - * @param rightHandSide right hand side - * @return results - */ - protected String[] convert(Path leftHandSide, Object rightHandSide) { - String str = rightHandSide.toString(); - if (lowerCase) { - str = str.toLowerCase(); - } - if (splitTerms) { - if (str.equals("")) { - return new String[] {str}; - } else { - return str.split("\\s+"); - } - } else { - return new String[] {str}; - } - } - - private String[] convertEscaped( - Path leftHandSide, Expression rightHandSide, QueryMetadata metadata) { - String[] str = convert(leftHandSide, rightHandSide, metadata); - for (int i = 0; i < str.length; i++) { - str[i] = QueryParser.escape(str[i]); - } - return str; - } - - public Query toQuery(Expression expr, QueryMetadata metadata) { - if (expr instanceof Operation) { - return toQuery((Operation) expr, metadata); - } else { - return toQuery(ExpressionUtils.extract(expr), metadata); - } - } - - public Sort toSort(List> orderBys) { - List sorts = new ArrayList(orderBys.size()); - for (OrderSpecifier order : orderBys) { - if (!(order.getTarget() instanceof Path)) { - throw new IllegalArgumentException("argument was not of type Path."); - } - Class type = order.getTarget().getType(); - boolean reverse = !order.isAscending(); - Path path = getPath(order.getTarget()); - if (Number.class.isAssignableFrom(type)) { - sorts.add(new SortField(toField(path), sortFields.get(type), reverse)); - } else { - sorts.add(new SortField(toField(path), sortLocale, reverse)); - } - } - Sort sort = new Sort(); - sort.setSort(sorts.toArray(new SortField[0])); - return sort; - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/PhraseElement.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/PhraseElement.java deleted file mode 100644 index f0e855cbc0..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/PhraseElement.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.dsl.StringOperation; - -/** - * {@code PhraseElement} represents the embedded String as a phrase - * - * @author tiwe - */ -public class PhraseElement extends StringOperation { - - private static final long serialVersionUID = 2350215644019186076L; - - public PhraseElement(String str) { - super(LuceneOps.PHRASE, ConstantImpl.create(str)); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/QueryElement.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/QueryElement.java deleted file mode 100644 index 340312ec27..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/QueryElement.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.dsl.BooleanOperation; -import org.apache.lucene.search.Query; - -/** - * {@code QueryElement} wraps a Lucene Query - * - * @author tiwe - */ -public class QueryElement extends BooleanOperation { - - private static final long serialVersionUID = 470868107363840155L; - - public QueryElement(Query query) { - super(LuceneOps.LUCENE_QUERY, ConstantImpl.create(query)); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/ResultIterator.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/ResultIterator.java deleted file mode 100644 index 30ed43dd7e..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/ResultIterator.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -import com.mysema.commons.lang.CloseableIterator; -import com.querydsl.core.QueryException; -import java.io.IOException; -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.FieldSelector; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.ScoreDoc; -import org.jetbrains.annotations.Nullable; - -/** - * {@code ResultIterator} is a {@link CloseableIterator} implementation for Lucene query results - * - * @author tiwe - * @param - */ -public final class ResultIterator implements CloseableIterator { - - private final ScoreDoc[] scoreDocs; - - private int cursor; - - private final IndexSearcher searcher; - - @Nullable private final FieldSelector fieldSelector; - - private final Function transformer; - - public ResultIterator( - ScoreDoc[] scoreDocs, - int offset, - IndexSearcher searcher, - @Nullable FieldSelector fieldSelector, - Function transformer) { - this.scoreDocs = scoreDocs.clone(); - this.cursor = offset; - this.searcher = searcher; - this.fieldSelector = fieldSelector; - this.transformer = transformer; - } - - @Override - public boolean hasNext() { - return cursor != scoreDocs.length; - } - - @Override - public T next() { - try { - Document document; - if (fieldSelector != null) { - document = searcher.doc(scoreDocs[cursor++].doc, fieldSelector); - } else { - document = searcher.doc(scoreDocs[cursor++].doc); - } - return transformer.apply(document); - } catch (IOException e) { - throw new QueryException(e); - } - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - @Override - public void close() {} -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/TermElement.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/TermElement.java deleted file mode 100644 index e4b6b13adc..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/TermElement.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.dsl.StringOperation; - -/** - * {@code TermElement} represents the embedded String as a term - * - * @author tiwe - */ -public class TermElement extends StringOperation { - - private static final long serialVersionUID = 2350215644019186076L; - - public TermElement(String str) { - super(LuceneOps.TERM, ConstantImpl.create(str)); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/TypedQuery.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/TypedQuery.java deleted file mode 100644 index 76baca5cc7..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/TypedQuery.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.search.IndexSearcher; - -/** - * {@code TypedQuery} is a typed query implementation for Lucene queries. - * - *

Converts Lucene documents to typed results via a constructor supplied transformer - * - * @param result type - * @author laim - * @author tiwe - */ -public class TypedQuery extends AbstractLuceneQuery> { - - /** - * Create a new TypedQuery instance - * - * @param searcher index searcher - * @param transformer transformer to transform Lucene documents to result objects - */ - public TypedQuery(IndexSearcher searcher, Function transformer) { - super(searcher, transformer); - } - - /** - * Create a new TypedQuery instance - * - * @param serializer serializer - * @param searcher index search - * @param transformer transformer to transform documents to result objects - */ - public TypedQuery( - LuceneSerializer serializer, IndexSearcher searcher, Function transformer) { - super(serializer, searcher, transformer); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/package-info.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/package-info.java deleted file mode 100644 index 777d96cb34..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/package-info.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** Lucene 3 support */ -package com.querydsl.lucene3; diff --git a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneQueryTest.java b/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneQueryTest.java deleted file mode 100644 index 53d01d745f..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneQueryTest.java +++ /dev/null @@ -1,745 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.easymock.EasyMock.*; - -import com.querydsl.core.NonUniqueResultException; -import com.querydsl.core.QueryException; -import com.querydsl.core.QueryModifiers; -import com.querydsl.core.QueryResults; -import com.querydsl.core.types.ParamNotSetException; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.Param; -import com.querydsl.core.types.dsl.StringPath; -import java.io.IOException; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.Field.Index; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.document.MapFieldSelector; -import org.apache.lucene.document.NumericField; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.search.DuplicateFilter; -import org.apache.lucene.search.Filter; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Sort; -import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.util.Version; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Tests for LuceneQuery - * - * @author vema - */ -public class LuceneQueryTest { - - private LuceneQuery query; - private StringPath title; - private NumberPath year; - private NumberPath gross; - - private final StringPath sort = Expressions.stringPath("sort"); - - private RAMDirectory idx; - private IndexWriter writer; - private IndexSearcher searcher; - - private Document createDocument( - final String docTitle, - final String docAuthor, - final String docText, - final int docYear, - final double docGross) { - final Document doc = new Document(); - - doc.add(new Field("title", docTitle, Store.YES, Index.ANALYZED)); - doc.add(new Field("author", docAuthor, Store.YES, Index.ANALYZED)); - doc.add(new Field("text", docText, Store.YES, Index.ANALYZED)); - doc.add(new NumericField("year", Store.YES, true).setIntValue(docYear)); - doc.add(new NumericField("gross", Store.YES, true).setDoubleValue(docGross)); - - return doc; - } - - @Before - public void setUp() throws Exception { - final QDocument entityPath = new QDocument("doc"); - title = entityPath.title; - year = entityPath.year; - gross = entityPath.gross; - - idx = new RAMDirectory(); - writer = createWriter(idx); - - writer.addDocument( - createDocument( - "Jurassic Park", "Michael Crichton", "It's a UNIX system! I know this!", 1990, 90.00)); - writer.addDocument( - createDocument( - "Nummisuutarit", "Aleksis Kivi", "ESKO. Ja iloitset ja riemuitset?", 1864, 10.00)); - writer.addDocument( - createDocument( - "The Lord of the Rings", - "John R. R. Tolkien", - "One Ring to rule them all, One Ring to find them, One Ring to bring them all and in" - + " the darkness bind them", - 1954, - 89.00)); - writer.addDocument( - createDocument( - "Introduction to Algorithms", - "Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein", - "Bubble sort", - 1990, - 30.50)); - - writer.close(); - - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - } - - private IndexWriter createWriter(RAMDirectory idx) throws Exception { - IndexWriterConfig config = - new IndexWriterConfig(Version.LUCENE_31, new StandardAnalyzer(Version.LUCENE_30)) - .setOpenMode(IndexWriterConfig.OpenMode.CREATE); - return new IndexWriter(idx, config); - } - - @After - public void tearDown() throws Exception { - searcher.close(); - } - - @Test - public void between() { - assertThat(query.where(year.between(1950, 1990)).fetchCount()).isEqualTo(3); - } - - @Test - public void count_empty_where_clause() { - assertThat(query.fetchCount()).isEqualTo(4); - } - - @Test - public void exists() { - assertThat(query.where(title.eq("Jurassic Park")).fetchCount() > 0).isTrue(); - assertThat(query.where(title.eq("Jurassic Park X")).fetchCount() > 0).isFalse(); - } - - @Test - public void notExists() { - assertThat(query.where(title.eq("Jurassic Park")).fetchCount() == 0).isFalse(); - assertThat(query.where(title.eq("Jurassic Park X")).fetchCount() == 0).isTrue(); - } - - @Test - public void count() { - query.where(title.eq("Jurassic Park")); - assertThat(query.fetchCount()).isEqualTo(1); - } - - @Test(expected = QueryException.class) - public void count_index_problem() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.maxDoc()).andThrow(new IllegalArgumentException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.fetchCount(); - verify(searcher); - } - - @Test(expected = UnsupportedOperationException.class) - public void countDistinct() { - query.where(year.between(1900, 3000)); - assertThat(query.distinct().fetchCount()).isEqualTo(3); - } - - @Test - public void in() { - assertThat(query.where(title.in("Jurassic Park", "Nummisuutarit")).fetchCount()).isEqualTo(2); - } - - @Test - public void in2() { - assertThat(query.where(year.in(1990, 1864)).fetchCount()).isEqualTo(3); - } - - @Test - public void in_toString() { - assertThat(query.where(year.in(1990, 1864)).toString()).isEqualTo("year:`____F year:`____H"); - } - - @Test - public void list_sorted_by_year_ascending() { - query.where(year.between(1800, 2000)); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void list_not_sorted() { - query.where(year.between(1800, 2000)); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void sorted_by_different_locales() throws Exception { - Document d1 = new Document(); - Document d2 = new Document(); - Document d3 = new Document(); - d1.add(new Field("sort", "a\u00c4", Store.YES, Index.NOT_ANALYZED)); - d2.add(new Field("sort", "ab", Store.YES, Index.NOT_ANALYZED)); - d3.add(new Field("sort", "aa", Store.YES, Index.NOT_ANALYZED)); - writer = createWriter(idx); - writer.addDocument(d1); - writer.addDocument(d2); - writer.addDocument(d3); - writer.close(); - - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - query = new LuceneQuery(new LuceneSerializer(true, true, Locale.ENGLISH), searcher); - assertThat(query.fetch()).hasSize(3); - List results = query.where(sort.startsWith("a")).orderBy(sort.asc()).fetch(); - assertThat(results).hasSize(3); - assertThat(results.getFirst().getFieldable("sort").stringValue()).isEqualTo("aa"); - assertThat(results.get(1).getFieldable("sort").stringValue()).isEqualTo("a\u00c4"); - assertThat(results.get(2).getFieldable("sort").stringValue()).isEqualTo("ab"); - - query = new LuceneQuery(new LuceneSerializer(true, true, Locale.of("fi", "FI")), searcher); - results = query.where(sort.startsWith("a")).orderBy(sort.asc()).fetch(); - assertThat(results.getFirst().getFieldable("sort").stringValue()).isEqualTo("aa"); - assertThat(results.get(1).getFieldable("sort").stringValue()).isEqualTo("ab"); - assertThat(results.get(2).getFieldable("sort").stringValue()).isEqualTo("a\u00c4"); - } - - @Test - public void list_not_sorted_limit_2() { - query.where(year.between(1800, 2000)); - query.limit(2); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - } - - @Test - public void list_sorted_by_year_limit_1() { - query.where(year.between(1800, 2000)); - query.limit(1); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(1); - } - - @Test - public void list_not_sorted_offset_2() { - query.where(year.between(1800, 2000)); - query.offset(2); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - } - - @Test - public void list_sorted_ascending_by_year_offset_2() { - query.where(year.between(1800, 2000)); - query.offset(2); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - } - - @Test - public void list_sorted_ascending_by_year_restrict_limit_2_offset_1() { - query.where(year.between(1800, 2000)); - query.restrict(new QueryModifiers(2L, 1L)); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - assertThat(documents.getFirst().get("year")).isEqualTo("1954"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - } - - @Test - public void list_sorted_ascending_by_year() { - query.where(year.between(1800, 2000)); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1864"); - assertThat(documents.get(1).get("year")).isEqualTo("1954"); - assertThat(documents.get(2).get("year")).isEqualTo("1990"); - assertThat(documents.get(3).get("year")).isEqualTo("1990"); - } - - @Test - public void list_sort() { - Sort sort = LuceneSerializer.DEFAULT.toSort(Collections.singletonList(year.asc())); - - query.where(year.between(1800, 2000)); - // query.orderBy(year.asc()); - query.sort(sort); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1864"); - assertThat(documents.get(1).get("year")).isEqualTo("1954"); - assertThat(documents.get(2).get("year")).isEqualTo("1990"); - assertThat(documents.get(3).get("year")).isEqualTo("1990"); - } - - @Test - public void list_distinct_property() { - assertThat(query.fetch()).hasSize(4); - assertThat(query.distinct(year).fetch()).hasSize(3); - } - - @Test - public void list_with_filter() { - Filter filter = new DuplicateFilter("year"); - assertThat(query.fetch()).hasSize(4); - assertThat(query.filter(filter).fetch()).hasSize(3); - } - - @Test - public void count_distinct_property() { - assertThat(query.fetchCount()).isEqualTo(4L); - assertThat(query.distinct(year).fetchCount()).isEqualTo(3L); - } - - @Test - public void list_sorted_descending_by_year() { - query.where(year.between(1800, 2000)); - query.orderBy(year.desc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - assertThat(documents.get(2).get("year")).isEqualTo("1954"); - assertThat(documents.get(3).get("year")).isEqualTo("1864"); - } - - @Test - public void list_sorted_descending_by_gross() { - query.where(gross.between(0.0, 1000.00)); - query.orderBy(gross.desc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("gross")).isEqualTo("90.0"); - assertThat(documents.get(1).get("gross")).isEqualTo("89.0"); - assertThat(documents.get(2).get("gross")).isEqualTo("30.5"); - assertThat(documents.get(3).get("gross")).isEqualTo("10.0"); - } - - @Test - public void list_sorted_descending_by_year_and_ascending_by_title() { - query.where(year.between(1800, 2000)); - query.orderBy(year.desc()); - query.orderBy(title.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - assertThat(documents.getFirst().get("title")).isEqualTo("Introduction to Algorithms"); - assertThat(documents.get(1).get("title")).isEqualTo("Jurassic Park"); - } - - @Test - public void list_sorted_descending_by_year_and_descending_by_title() { - query.where(year.between(1800, 2000)); - query.orderBy(year.desc()); - query.orderBy(title.desc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - assertThat(documents.getFirst().get("title")).isEqualTo("Jurassic Park"); - assertThat(documents.get(1).get("title")).isEqualTo("Introduction to Algorithms"); - } - - @Ignore - @Test(expected = QueryException.class) - public void list_index_problem_in_max_doc() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.maxDoc()).andThrow(new IOException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.fetch(); - verify(searcher); - } - - @Ignore - @Test(expected = QueryException.class) - public void list_sorted_index_problem_in_max_doc() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.maxDoc()).andThrow(new IOException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.orderBy(title.asc()); - query.fetch(); - verify(searcher); - } - - @Test - public void offset() { - assertThat(query.where(title.eq("Jurassic Park")).offset(30).fetch()).isEmpty(); - } - - @Test - public void load_list() { - Document document = query.where(title.ne("")).load(title).fetch().get(0); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void load_list_fieldSelector() { - Document document = - query.where(title.ne("")).load(new MapFieldSelector("title")).fetch().get(0); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void load_singleResult() { - Document document = query.where(title.ne("")).load(title).fetchFirst(); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void load_singleResult_fieldSelector() { - Document document = query.where(title.ne("")).load(new MapFieldSelector("title")).fetchFirst(); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void singleResult() { - assertThat(query.where(title.ne("")).fetchFirst()).isNotNull(); - } - - @Test - public void single_result_takes_limit() { - assertThat(query.where(title.ne("")).limit(1).fetchFirst().get("title")) - .isEqualTo("Jurassic Park"); - } - - @Test - public void single_result_considers_limit_and_actual_result_size() { - query.where(title.startsWith("Nummi")); - final Document document = query.limit(3).fetchFirst(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test - public void single_result_returns_null_if_nothing_is_in_range() { - query.where(title.startsWith("Nummi")); - assertThat(query.offset(10).fetchFirst()).isNull(); - } - - @Test - public void single_result_considers_offset() { - assertThat(query.where(title.ne("")).offset(3).fetchFirst().get("title")) - .isEqualTo("Introduction to Algorithms"); - } - - @Test - public void single_result_considers_limit_and_offset() { - assertThat(query.where(title.ne("")).limit(1).offset(2).fetchFirst().get("title")) - .isEqualTo("The Lord of the Rings"); - } - - @Test(expected = NonUniqueResultException.class) - public void uniqueResult_contract() { - query.where(title.ne("")).fetchOne(); - } - - @Test - public void unique_result_takes_limit() { - assertThat(query.where(title.ne("")).limit(1).fetchOne().get("title")) - .isEqualTo("Jurassic Park"); - } - - @Test - public void unique_result_considers_limit_and_actual_result_size() { - query.where(title.startsWith("Nummi")); - final Document document = query.limit(3).fetchOne(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test - public void unique_result_returns_null_if_nothing_is_in_range() { - query.where(title.startsWith("Nummi")); - assertThat(query.offset(10).fetchOne()).isNull(); - } - - @Test - public void unique_result_considers_offset() { - assertThat(query.where(title.ne("")).offset(3).fetchOne().get("title")) - .isEqualTo("Introduction to Algorithms"); - } - - @Test - public void unique_result_considers_limit_and_offset() { - assertThat(query.where(title.ne("")).limit(1).offset(2).fetchOne().get("title")) - .isEqualTo("The Lord of the Rings"); - } - - @Test - public void uniqueResult() { - query.where(title.startsWith("Nummi")); - final Document document = query.fetchOne(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test - public void uniqueResult_with_param() { - final Param param = new Param(String.class, "title"); - query.set(param, "Nummi"); - query.where(title.startsWith(param)); - final Document document = query.fetchOne(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test(expected = ParamNotSetException.class) - public void uniqueResult_param_not_set() { - final Param param = new Param(String.class, "title"); - query.where(title.startsWith(param)); - query.fetchOne(); - } - - @Test(expected = QueryException.class) - public void uniqueResult_finds_more_than_one_result() { - query.where(year.eq(1990)); - query.fetchOne(); - } - - @Test - public void uniqueResult_finds_no_results() { - query.where(year.eq(2200)); - assertThat(query.fetchOne()).isNull(); - } - - @Test - public void uniqueResult_finds_no_results_because_no_documents_in_index() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.maxDoc()).andReturn(0); - replay(searcher); - assertThat(query.where(year.eq(3000)).fetchOne()).isNull(); - verify(searcher); - } - - @Test(expected = QueryException.class) - public void uniqueResult_sorted_index_problem_in_max_doc() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.maxDoc()).andThrow(new IllegalArgumentException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.fetchOne(); - verify(searcher); - } - - @Test - public void count_returns_0_because_no_documents_in_index() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.maxDoc()).andReturn(0); - replay(searcher); - assertThat(query.where(year.eq(3000)).fetchCount()).isEqualTo(0); - verify(searcher); - } - - @Test(expected = UnsupportedOperationException.class) - public void listDistinct() { - query.where(year.between(1900, 2000).or(title.startsWith("Jura"))); - query.orderBy(year.asc()); - final List documents = query.distinct().fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(3); - } - - @Test - public void listResults() { - query.where(year.between(1800, 2000)); - query.restrict(new QueryModifiers(2L, 1L)); - query.orderBy(year.asc()); - final QueryResults results = query.fetchResults(); - assertThat(results.isEmpty()).isFalse(); - assertThat(results.getResults().get(0).get("year")).isEqualTo("1954"); - assertThat(results.getResults().get(1).get("year")).isEqualTo("1990"); - assertThat(results.getLimit()).isEqualTo(2); - assertThat(results.getOffset()).isEqualTo(1); - assertThat(results.getTotal()).isEqualTo(4); - } - - @Test(expected = UnsupportedOperationException.class) - public void listDistinctResults() { - query.where(year.between(1800, 2000).or(title.eq("The Lord of the Rings"))); - query.restrict(new QueryModifiers(1L, 1L)); - query.orderBy(year.asc()); - final QueryResults results = query.distinct().fetchResults(); - assertThat(results.isEmpty()).isFalse(); - assertThat(results.getResults().get(0).get("year")).isEqualTo("1954"); - assertThat(results.getLimit()).isEqualTo(1); - assertThat(results.getOffset()).isEqualTo(1); - assertThat(results.getTotal()).isEqualTo(4); - } - - @Test - public void list_all() { - final List results = - query.where(title.like("*")).orderBy(title.asc(), year.desc()).fetch(); - assertThat(results).hasSize(4); - } - - @Test(expected = IllegalArgumentException.class) - public void list_sorted_ascending_limit_negative() { - query.where(year.between(1800, 2000)); - query.limit(-1); - query.orderBy(year.asc()); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_not_sorted_limit_negative() { - query.where(year.between(1800, 2000)); - query.limit(-1); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_sorted_ascending_limit_0() { - query.where(year.between(1800, 2000)); - query.limit(0); - query.orderBy(year.asc()); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_not_sorted_limit_0() { - query.where(year.between(1800, 2000)); - query.limit(0); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_sorted_ascending_offset_negative() { - query.where(year.between(1800, 2000)); - query.offset(-1); - query.orderBy(year.asc()); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_not_sorted_offset_negative() { - query.where(year.between(1800, 2000)); - query.offset(-1); - query.fetch(); - } - - @Test - public void list_sorted_ascending_offset_0() { - query.where(year.between(1800, 2000)); - query.offset(0); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void list_not_sorted_offset_0() { - query.where(year.between(1800, 2000)); - query.offset(0); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void iterate() { - query.where(year.between(1800, 2000)); - final Iterator iterator = query.iterate(); - int count = 0; - while (iterator.hasNext()) { - iterator.next(); - ++count; - } - assertThat(count).isEqualTo(4); - } - - @Test - public void all_by_excluding_where() { - assertThat(query.fetch()).hasSize(4); - } - - @Test - public void empty_index_should_return_empty_list() throws Exception { - idx = new RAMDirectory(); - - writer = createWriter(idx); - writer.close(); - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - assertThat(query.fetch()).isEmpty(); - } - - @Test(expected = QueryException.class) - public void - list_results_throws_an_illegal_argument_exception_when_sum_of_limit_and_offset_is_negative() { - query.limit(1).offset(Integer.MAX_VALUE).fetchResults(); - } - - @Test - public void limit_max_value() { - assertThat(query.limit(Long.MAX_VALUE).fetch()).hasSize(4); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneSerializerNotTokenizedTest.java b/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneSerializerNotTokenizedTest.java deleted file mode 100644 index 718e2edf97..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneSerializerNotTokenizedTest.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -import static com.querydsl.lucene3.QPerson.person; -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.Expression; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringPath; -import java.time.LocalDate; -import java.util.Arrays; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.Field.Index; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TopDocs; -import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.util.Version; -import org.junit.Before; -import org.junit.Test; - -public class LuceneSerializerNotTokenizedTest { - private RAMDirectory idx; - private IndexWriter writer; - private IndexSearcher searcher; - private LuceneSerializer serializer; - - private final QueryMetadata metadata = new DefaultQueryMetadata(); - - private final Person clooney = new Person("actor_1", "George Clooney", LocalDate.of(1961, 4, 6)); - private final Person pitt = new Person("actor_2", "Brad Pitt", LocalDate.of(1963, 12, 18)); - - private void testQuery(Expression expr, String expectedQuery, int expectedHits) - throws Exception { - Query query = serializer.toQuery(expr, metadata); - TopDocs docs = searcher.search(query, 100); - assertThat(docs.totalHits).isEqualTo(expectedHits); - assertThat(query.toString()).isEqualTo(expectedQuery); - } - - private Document createDocument(Person person) { - Document doc = new Document(); - doc.add(new Field("id", person.getId(), Store.YES, Index.NOT_ANALYZED)); - doc.add(new Field("name", person.getName(), Store.YES, Index.NOT_ANALYZED)); - doc.add( - new Field("birthDate", person.getBirthDate().toString(), Store.YES, Index.NOT_ANALYZED)); - return doc; - } - - @Before - public void before() throws Exception { - serializer = new LuceneSerializer(false, false); - idx = new RAMDirectory(); - IndexWriterConfig config = - new IndexWriterConfig(Version.LUCENE_31, new StandardAnalyzer(Version.LUCENE_30)) - .setOpenMode(IndexWriterConfig.OpenMode.CREATE); - writer = new IndexWriter(idx, config); - - writer.addDocument(createDocument(clooney)); - writer.addDocument(createDocument(pitt)); - - Document document = new Document(); - for (String movie : Arrays.asList("Interview with the Vampire", "Up in the Air")) { - document.add(new Field("movie", movie, Store.YES, Index.NOT_ANALYZED)); - } - writer.addDocument(document); - - writer.close(); - - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - } - - @Test - public void equals_by_id_matches() throws Exception { - testQuery(person.id.eq("actor_1"), "id:actor_1", 1); - } - - @Test - public void equals_by_id_does_not_match() throws Exception { - testQuery(person.id.eq("actor_8"), "id:actor_8", 0); - } - - @Test - public void equals_by_name_matches() throws Exception { - testQuery(person.name.eq("George Clooney"), "name:George Clooney", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void equals_by_name_ignoring_case_does_not_match() throws Exception { - testQuery(person.name.equalsIgnoreCase("george clooney"), "name:george clooney", 0); - } - - @Test - public void equals_by_name_does_not_match() throws Exception { - testQuery(person.name.eq("George Looney"), "name:George Looney", 0); - } - - @Test - public void starts_with_name_should_match() throws Exception { - testQuery(person.name.startsWith("George C"), "name:George C*", 1); - } - - @Test - public void starts_with_name_should_not_match() throws Exception { - testQuery(person.name.startsWith("George L"), "name:George L*", 0); - } - - @Test - public void ends_with_name_should_match() throws Exception { - testQuery(person.name.endsWith("e Clooney"), "name:*e Clooney", 1); - } - - @Test - public void ends_with_name_should_not_match() throws Exception { - testQuery(person.name.endsWith("e Looney"), "name:*e Looney", 0); - } - - @Test - public void contains_name_should_match() throws Exception { - testQuery(person.name.contains("oney"), "name:*oney*", 1); - } - - @Test - public void contains_name_should_not_match() throws Exception { - testQuery(person.name.contains("bloney"), "name:*bloney*", 0); - } - - @Test - public void in_names_should_match_2() throws Exception { - testQuery( - person.name.in("Brad Pitt", "George Clooney"), "name:Brad Pitt name:George Clooney", 2); - } - - @Test - public void or_by_name_should_match_2() throws Exception { - testQuery( - person.name.eq("Brad Pitt").or(person.name.eq("George Clooney")), - "name:Brad Pitt name:George Clooney", - 2); - } - - @Test - public void equals_by_birth_date() throws Exception { - testQuery(person.birthDate.eq(clooney.getBirthDate()), "birthDate:1961-04-06", 1); - } - - @Test - public void between_phrase() throws Exception { - testQuery( - person.name.between("Brad Pitt", "George Clooney"), - "name:[Brad Pitt TO George Clooney]", - 2); - } - - @Test - public void not_equals_finds_the_actors_and_movies() throws Exception { - testQuery(person.name.ne("Michael Douglas"), "-name:Michael Douglas +*:*", 3); - } - - @Test - public void not_equals_finds_only_clooney_and_movies() throws Exception { - testQuery(person.name.ne("Brad Pitt"), "-name:Brad Pitt +*:*", 2); - } - - @Test - public void and_with_two_not_equals_doesnt_find_the_actors() throws Exception { - testQuery( - person.name.ne("Brad Pitt").and(person.name.ne("George Clooney")), - "+(-name:Brad Pitt +*:*) +(-name:George Clooney +*:*)", - 1); - } - - @Test - public void or_with_two_not_equals_finds_movies_and_actors() throws Exception { - testQuery( - person.name.ne("Brad Pitt").or(person.name.ne("George Clooney")), - "(-name:Brad Pitt +*:*) (-name:George Clooney +*:*)", - 3); - } - - @Test - public void negation_of_equals_finds_movies_and_actors() throws Exception { - testQuery(person.name.eq("Michael Douglas").not(), "-name:Michael Douglas +*:*", 3); - } - - @Test - public void negation_of_equals_finds_pitt_and_movies() throws Exception { - testQuery(person.name.eq("Brad Pitt").not(), "-name:Brad Pitt +*:*", 2); - } - - @Test - public void multiple_field_search_from_movies() throws Exception { - StringPath movie = Expressions.stringPath("movie"); - testQuery(movie.in("Interview with the Vampire"), "movie:Interview with the Vampire", 1); - testQuery(movie.eq("Up in the Air"), "movie:Up in the Air", 1); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneSerializerTest.java b/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneSerializerTest.java deleted file mode 100644 index b46810dda3..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneSerializerTest.java +++ /dev/null @@ -1,697 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; -import static org.junit.jupiter.api.Assertions.*; - -import com.querydsl.core.*; -import com.querydsl.core.types.*; -import com.querydsl.core.types.dsl.*; -import java.io.StringReader; -import java.util.Arrays; -import java.util.Collections; -import java.util.EnumSet; -import java.util.Set; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.Field.Index; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.document.NumericField; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TopDocs; -import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.util.NumericUtils; -import org.apache.lucene.util.Version; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Tests for LuceneSerializer - * - * @author vema - */ -public class LuceneSerializerTest { - private LuceneSerializer serializer; - private PathBuilder entityPath; - private StringPath title; - private StringPath author; - private StringPath text; - private StringPath rating; - private StringPath publisher; - private NumberPath year; - private NumberPath gross; - private CollectionPath titles; - - private NumberPath longField; - private NumberPath shortField; - private NumberPath byteField; - private NumberPath floatField; - - private static final String YEAR_PREFIX_CODED = NumericUtils.intToPrefixCoded(1990); - private static final String GROSS_PREFIX_CODED = NumericUtils.doubleToPrefixCoded(900.00); - private static final String LONG_PREFIX_CODED = NumericUtils.longToPrefixCoded(1); - private static final String SHORT_PREFIX_CODED = NumericUtils.intToPrefixCoded(1); - private static final String BYTE_PREFIX_CODED = NumericUtils.intToPrefixCoded(1); - private static final String FLOAT_PREFIX_CODED = NumericUtils.floatToPrefixCoded((float) 1.0); - - private IndexWriterConfig config; - private RAMDirectory idx; - private IndexWriter writer; - private IndexSearcher searcher; - - private static final Set UNSUPPORTED_OPERATORS = - Collections.unmodifiableSet( - EnumSet.of( - Ops.STARTS_WITH_IC, Ops.EQ_IGNORE_CASE, Ops.ENDS_WITH_IC, Ops.STRING_CONTAINS_IC)); - - private final QueryMetadata metadata = new DefaultQueryMetadata(); - - private Document createDocument() { - Document doc = new Document(); - - doc.add(new Field("title", new StringReader("Jurassic Park"))); - doc.add(new Field("author", new StringReader("Michael Crichton"))); - doc.add(new Field("text", new StringReader("It's a UNIX system! I know this!"))); - doc.add(new Field("rating", new StringReader("Good"))); - doc.add(new Field("publisher", "", Store.YES, Index.ANALYZED)); - doc.add(new NumericField("year", Store.YES, true).setIntValue(1990)); - doc.add(new NumericField("gross", Store.YES, true).setDoubleValue(900.00)); - - doc.add(new NumericField("longField", Store.YES, true).setLongValue(1)); - doc.add(new NumericField("shortField", Store.YES, true).setIntValue(1)); - doc.add(new NumericField("byteField", Store.YES, true).setIntValue(1)); - doc.add(new NumericField("floatField", Store.YES, true).setFloatValue(1)); - - return doc; - } - - @Before - public void setUp() throws Exception { - serializer = new LuceneSerializer(true, true); - entityPath = new PathBuilder(Object.class, "obj"); - title = entityPath.getString("title"); - author = entityPath.getString("author"); - text = entityPath.getString("text"); - publisher = entityPath.getString("publisher"); - year = entityPath.getNumber("year", Integer.class); - rating = entityPath.getString("rating"); - gross = entityPath.getNumber("gross", Double.class); - titles = entityPath.getCollection("title", String.class, StringPath.class); - - longField = entityPath.getNumber("longField", Long.class); - shortField = entityPath.getNumber("shortField", Short.class); - byteField = entityPath.getNumber("byteField", Byte.class); - floatField = entityPath.getNumber("floatField", Float.class); - - idx = new RAMDirectory(); - config = - new IndexWriterConfig(Version.LUCENE_31, new StandardAnalyzer(Version.LUCENE_30)) - .setOpenMode(IndexWriterConfig.OpenMode.CREATE); - writer = new IndexWriter(idx, config); - - writer.addDocument(createDocument()); - - writer.close(); - - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - } - - @After - public void tearDown() throws Exception { - searcher.close(); - } - - private void testQuery(Expression expr, int expectedHits) throws Exception { - Query query = serializer.toQuery(expr, metadata); - TopDocs docs = searcher.search(query, 100); - assertThat(docs.totalHits).isEqualTo(expectedHits); - } - - private void testQuery(Expression expr, String expectedQuery, int expectedHits) - throws Exception { - Query query = serializer.toQuery(expr, metadata); - TopDocs docs = searcher.search(query, 100); - assertThat(docs.totalHits).isEqualTo(expectedHits); - assertThat(query.toString()).isEqualTo(expectedQuery); - } - - @Test - public void queryElement() throws Exception { - Query query1 = serializer.toQuery(author.like("Michael"), metadata); - Query query2 = serializer.toQuery(text.like("Text"), metadata); - - BooleanExpression query = Expressions.anyOf(new QueryElement(query1), new QueryElement(query2)); - testQuery(query, "author:michael text:text", 1); - } - - @Test - public void like() throws Exception { - testQuery(author.like("*ichael*"), "author:*ichael*", 1); - } - - @Test - public void like_custom_wildcard_single_character() throws Exception { - testQuery(author.like("Mi?hael"), "author:mi?hael", 1); - } - - @Test - public void like_custom_wildcard_multiple_character() throws Exception { - testQuery(text.like("*U*X*"), "text:*u*x*", 1); - } - - @Test - public void like_phrase() throws Exception { - testQuery(title.like("*rassic Par*"), "+title:**rassic* +title:*par**", 1); - } - - @Test - public void like_or_like() throws Exception { - testQuery(title.like("House").or(author.like("*ichae*")), "title:house author:*ichae*", 1); - } - - @Test - public void like_and_like() throws Exception { - testQuery(title.like("*assic*").and(rating.like("G?od")), "+title:*assic* +rating:g?od", 1); - } - - @Test - public void eq() throws Exception { - testQuery(rating.eq("good"), "rating:good", 1); - } - - @Test - public void eq_with_deep_path() throws Exception { - StringPath deepPath = entityPath.get("property1", Object.class).getString("property2"); - testQuery(deepPath.eq("good"), "property1.property2:good", 0); - } - - @Test - public void fuzzyLike() throws Exception { - testQuery(LuceneExpressions.fuzzyLike(rating, "Good"), "rating:Good~0.5", 1); - } - - @Test - public void fuzzyLike_with_similarity() throws Exception { - testQuery(LuceneExpressions.fuzzyLike(rating, "Good", 0.6f), "rating:Good~0.6", 1); - } - - @Test - public void fuzzyLike_with_similarity_and_prefix() throws Exception { - testQuery(LuceneExpressions.fuzzyLike(rating, "Good", 0.6f, 0), "rating:Good~0.6", 1); - } - - @Test - public void eq_numeric_integer() throws Exception { - testQuery(year.eq(1990), "year:" + YEAR_PREFIX_CODED, 1); - } - - @Test - public void eq_numeric_double() throws Exception { - testQuery(gross.eq(900.00), "gross:" + GROSS_PREFIX_CODED, 1); - } - - @Test - public void eq_numeric() throws Exception { - testQuery(longField.eq(1L), "longField:" + LONG_PREFIX_CODED, 1); - testQuery(shortField.eq((short) 1), "shortField:" + SHORT_PREFIX_CODED, 1); - testQuery(byteField.eq((byte) 1), "byteField:" + BYTE_PREFIX_CODED, 1); - testQuery(floatField.eq((float) 1.0), "floatField:" + FLOAT_PREFIX_CODED, 1); - } - - @Test - public void equals_ignores_case() throws Exception { - testQuery(title.eq("Jurassic"), "title:jurassic", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void title_equals_ignore_case_or_year_equals() throws Exception { - testQuery( - title.equalsIgnoreCase("House").or(year.eq(1990)), - "title:house year:" + YEAR_PREFIX_CODED, - 1); - } - - @Test - public void eq_and_eq() throws Exception { - testQuery( - title.eq("Jurassic Park").and(year.eq(1990)), - "+title:\"jurassic park\" +year:" + YEAR_PREFIX_CODED, - 1); - } - - @Test - public void eq_and_eq_and_eq() throws Exception { - testQuery( - title.eq("Jurassic Park").and(year.eq(1990)).and(author.eq("Michael Crichton")), - "+(+title:\"jurassic park\" +year:" + YEAR_PREFIX_CODED + ") +author:\"michael crichton\"", - 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void equals_ignore_case_and_or() throws Exception { - testQuery( - title - .equalsIgnoreCase("Jurassic Park") - .and(rating.equalsIgnoreCase("Bad")) - .or(author.equalsIgnoreCase("Michael Crichton")), - "(+title:\"jurassic park\" +rating:bad) author:\"michael crichton\"", - 1); - } - - @Test - public void eq_or_eq_and_eq_does_not_find_results() throws Exception { - testQuery( - title.eq("jeeves").or(rating.eq("superb")).and(author.eq("michael crichton")), - "+(title:jeeves rating:superb) +author:\"michael crichton\"", - 0); - } - - @Test - public void eq_phrase() throws Exception { - testQuery(title.eq("Jurassic Park"), "title:\"jurassic park\"", 1); - } - - @Test - @Ignore("Not easily done in Lucene!") - public void publisher_equals_empty_string() throws Exception { - testQuery(publisher.eq(""), "publisher:", 1); - } - - @Test - public void eq_phrase_should_not_find_results_but_luceNe_semantics_differs_from_querydsls() - throws Exception { - testQuery(text.eq("UNIX System"), "text:\"unix system\"", 1); - } - - @Test - public void eq_phrase_does_not_find_results_because_word_in_middle() throws Exception { - testQuery(title.eq("Jurassic Amusement Park"), "title:\"jurassic amusement park\"", 0); - } - - @Test - public void like_not_does_not_find_results() throws Exception { - testQuery(title.like("*H*e*").not(), "-title:*h*e* +*:*", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void title_equals_ignore_case_negation_or_rating_equals_ignore_case() throws Exception { - testQuery( - title.equalsIgnoreCase("House").not().or(rating.equalsIgnoreCase("Good")), - "-title:house rating:good", - 1); - } - - @Test - public void eq_not_does_not_find_results() throws Exception { - testQuery(title.eq("Jurassic Park").not(), "-title:\"jurassic park\" +*:*", 0); - } - - @Test - public void title_equals_not_house() throws Exception { - testQuery(title.eq("house").not(), "-title:house +*:*", 1); - } - - @Test - public void eq_and_eq_not_does_not_find_results_because_second_expression_finds_nothing() - throws Exception { - testQuery( - rating.eq("superb").and(title.eq("house").not()), "+rating:superb +(-title:house +*:*)", 0); - } - - @Test - public void not_equals_finds_one() throws Exception { - testQuery(title.ne("house"), "-title:house +*:*", 1); - } - - @Test - public void not_equals_finds_none() throws Exception { - testQuery(title.ne("Jurassic Park"), "-title:\"jurassic park\" +*:*", 0); - } - - @Test - public void nothing_found_with_not_equals_or_equals() throws Exception { - testQuery( - title.ne("jurassic park").or(rating.eq("lousy")), - "(-title:\"jurassic park\" +*:*) rating:lousy", - 0); - } - - @Test - public void ne_and_eq() throws Exception { - testQuery(title.ne("house").and(rating.eq("good")), "+(-title:house +*:*) +rating:good", 1); - } - - @Test - public void startsWith() throws Exception { - testQuery(title.startsWith("Jurassi"), "title:jurassi*", 1); - } - - @Test - public void startsWith_phrase() throws Exception { - testQuery(title.startsWith("jurassic par"), "+title:jurassic* +title:*par*", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void starts_with_ignore_case_phrase_does_not_find_results() throws Exception { - testQuery(title.startsWithIgnoreCase("urassic Par"), "+title:urassic* +title:*par*", 0); - } - - @Test - public void endsWith() throws Exception { - testQuery(title.endsWith("ark"), "title:*ark", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void ends_with_ignore_case_phrase() throws Exception { - testQuery(title.endsWithIgnoreCase("sic Park"), "+title:*sic* +title:*park", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void ends_with_ignore_case_phrase_does_not_find_results() throws Exception { - testQuery(title.endsWithIgnoreCase("sic Par"), "+title:*sic* +title:*par", 0); - } - - @Test - public void contains() throws Exception { - testQuery(title.contains("rassi"), "title:*rassi*", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void contains_ignore_case_phrase() throws Exception { - testQuery(title.containsIgnoreCase("rassi Pa"), "+title:*rassi* +title:*pa*", 1); - } - - @Test - public void contains_user_inputted_wildcards_dont_work() throws Exception { - testQuery(title.contains("r*i"), "title:*r\\*i*", 0); - } - - @Test - public void between() throws Exception { - testQuery(title.between("Indiana", "Kundun"), "title:[indiana TO kundun]", 1); - } - - @Test - public void between_numeric_integer() throws Exception { - testQuery(year.between(1980, 2000), "year:[1980 TO 2000]", 1); - } - - @Test - public void between_numeric_double() throws Exception { - testQuery(gross.between(10.00, 19030.00), "gross:[10.0 TO 19030.0]", 1); - } - - @Test - public void between_numeric() throws Exception { - testQuery(longField.between(0L, 2L), "longField:[0 TO 2]", 1); - testQuery(shortField.between((short) 0, (short) 2), "shortField:[0 TO 2]", 1); - testQuery(byteField.between((byte) 0, (byte) 2), "byteField:[0 TO 2]", 1); - testQuery(floatField.between((float) 0.0, (float) 2.0), "floatField:[0.0 TO 2.0]", 1); - } - - @Test - public void between_is_inclusive_from_start() throws Exception { - testQuery(title.between("Jurassic", "Kundun"), "title:[jurassic TO kundun]", 1); - } - - @Test - public void between_is_inclusive_to_end() throws Exception { - testQuery(title.between("Indiana", "Jurassic"), "title:[indiana TO jurassic]", 1); - } - - @Test - public void between_does_not_find_results() throws Exception { - testQuery(title.between("Indiana", "Jurassib"), "title:[indiana TO jurassib]", 0); - } - - @Test - public void in() throws Exception { - testQuery(title.in(Arrays.asList("jurassic", "park")), "title:jurassic title:park", 1); - testQuery(title.in("jurassic", "park"), "title:jurassic title:park", 1); - testQuery(title.eq("jurassic").or(title.eq("park")), "title:jurassic title:park", 1); - } - - @Test - public void lt() throws Exception { - testQuery(rating.lt("Superb"), "rating:{* TO superb}", 1); - } - - @Test - public void lt_numeric_integer() throws Exception { - testQuery(year.lt(1991), "year:{* TO 1991}", 1); - } - - @Test - public void lt_numeric_double() throws Exception { - testQuery(gross.lt(10000.0), "gross:{* TO 10000.0}", 1); - } - - @Test - public void lt_not_in_range_because_equal() throws Exception { - testQuery(rating.lt("Good"), "rating:{* TO good}", 0); - } - - @Test - public void lt_numeric_integer_not_in_range_because_equal() throws Exception { - testQuery(year.lt(1990), "year:{* TO 1990}", 0); - } - - @Test - public void lt_numeric_double_not_in_range_because_equal() throws Exception { - testQuery(gross.lt(900.0), "gross:{* TO 900.0}", 0); - } - - @Test - public void loe() throws Exception { - testQuery(rating.loe("Superb"), "rating:[* TO superb]", 1); - } - - @Test - public void loe_numeric_integer() throws Exception { - testQuery(year.loe(1991), "year:[* TO 1991]", 1); - } - - @Test - public void loe_numeric_double() throws Exception { - testQuery(gross.loe(903.0), "gross:[* TO 903.0]", 1); - } - - @Test - public void loe_equal() throws Exception { - testQuery(rating.loe("Good"), "rating:[* TO good]", 1); - } - - @Test - public void loe_numeric_integer_equal() throws Exception { - testQuery(year.loe(1990), "year:[* TO 1990]", 1); - } - - @Test - public void loe_numeric_double_equal() throws Exception { - testQuery(gross.loe(900.0), "gross:[* TO 900.0]", 1); - } - - @Test - public void loe_not_found() throws Exception { - testQuery(rating.loe("Bad"), "rating:[* TO bad]", 0); - } - - @Test - public void loe_numeric_integer_not_found() throws Exception { - testQuery(year.loe(1989), "year:[* TO 1989]", 0); - } - - @Test - public void loe_numeric_double_not_found() throws Exception { - testQuery(gross.loe(899.9), "gross:[* TO 899.9]", 0); - } - - @Test - public void gt() throws Exception { - testQuery(rating.gt("Bad"), "rating:{bad TO *}", 1); - } - - @Test - public void gt_numeric_integer() throws Exception { - testQuery(year.gt(1989), "year:{1989 TO *}", 1); - } - - @Test - public void gt_numeric_double() throws Exception { - testQuery(gross.gt(100.00), "gross:{100.0 TO *}", 1); - } - - @Test - public void gt_not_in_range_because_equal() throws Exception { - testQuery(rating.gt("Good"), "rating:{good TO *}", 0); - } - - @Test - public void gt_numeric_integer_not_in_range_because_equal() throws Exception { - testQuery(year.gt(1990), "year:{1990 TO *}", 0); - } - - @Test - public void gt_numeric_double_not_in_range_because_equal() throws Exception { - testQuery(gross.gt(900.00), "gross:{900.0 TO *}", 0); - } - - @Test - public void goe() throws Exception { - testQuery(rating.goe("Bad"), "rating:[bad TO *]", 1); - } - - @Test - public void goe_numeric_integer() throws Exception { - testQuery(year.goe(1989), "year:[1989 TO *]", 1); - } - - @Test - public void goe_numeric_double() throws Exception { - testQuery(gross.goe(320.50), "gross:[320.5 TO *]", 1); - } - - @Test - public void goe_equal() throws Exception { - testQuery(rating.goe("Good"), "rating:[good TO *]", 1); - } - - @Test - public void goe_numeric_integer_equal() throws Exception { - testQuery(year.goe(1990), "year:[1990 TO *]", 1); - } - - @Test - public void goe_numeric_double_equal() throws Exception { - testQuery(gross.goe(900.00), "gross:[900.0 TO *]", 1); - } - - @Test - public void goe_not_found() throws Exception { - testQuery(rating.goe("Hood"), "rating:[hood TO *]", 0); - } - - @Test - public void goe_numeric_integer_not_found() throws Exception { - testQuery(year.goe(1991), "year:[1991 TO *]", 0); - } - - @Test - public void goe_numeric_double_not_found() throws Exception { - testQuery(gross.goe(900.10), "gross:[900.1 TO *]", 0); - } - - @Test - public void equals_empty_string() throws Exception { - testQuery(title.eq(""), "title:", 0); - } - - @Test - public void not_equals_empty_string() throws Exception { - testQuery(title.ne(""), "-title: +*:*", 1); - } - - @Test - public void contains_empty_string() throws Exception { - testQuery(title.contains(""), "title:**", 1); - } - - @Test - public void like_empty_string() throws Exception { - testQuery(title.like(""), "title:", 0); - } - - @Test - public void starts_with_empty_string() throws Exception { - testQuery(title.startsWith(""), "title:*", 1); - } - - @Test - public void ends_with_empty_string() throws Exception { - testQuery(title.endsWith(""), "title:*", 1); - } - - @Test - public void between_empty_strings() throws Exception { - testQuery(title.between("", ""), "title:[ TO ]", 0); - } - - @Test - public void booleanBuilder() throws Exception { - testQuery(new BooleanBuilder(gross.goe(900.10)), "gross:[900.1 TO *]", 0); - } - - @Test - @Ignore - public void fuzzy() throws Exception { - fail("Not yet implemented!"); - } - - @Test - @Ignore - public void proximity() throws Exception { - fail("Not yet implemented!"); - } - - @Test - @Ignore - public void boost() throws Exception { - fail("Not yet implemented!"); - } - - @Test - public void pathAny() throws Exception { - testQuery(titles.any().eq("Jurassic"), "title:jurassic", 1); - } - - private boolean unsupportedOperation(Predicate filter) { - return UNSUPPORTED_OPERATORS.contains(((Operation) filter).getOperator()); - } - - @Test - public void various() throws Exception { - MatchingFiltersFactory filters = - new MatchingFiltersFactory(QuerydslModule.LUCENE, Target.LUCENE); - for (Predicate filter : filters.string(title, StringConstant.create("jurassic park"))) { - if (unsupportedOperation(filter)) { - continue; - } - testQuery(filter, 1); - } - - for (Predicate filter : filters.string(author, StringConstant.create("michael crichton"))) { - if (unsupportedOperation(filter)) { - continue; - } - testQuery(filter, 1); - } - - for (Predicate filter : filters.string(title, StringConstant.create("1990"))) { - if (unsupportedOperation(filter)) { - continue; - } - testQuery(filter, 0); - } - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/Person.java b/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/Person.java deleted file mode 100644 index 98b5b9091b..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/Person.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -import com.querydsl.core.annotations.QueryEntity; -import java.time.LocalDate; - -@QueryEntity -public class Person { - private final String id; - private final String name; - private final LocalDate birthDate; - - public Person(String id, String name, LocalDate birthDate) { - this.id = id; - this.name = name; - this.birthDate = birthDate; - } - - public String getId() { - return id; - } - - public LocalDate getBirthDate() { - return birthDate; - } - - public String getName() { - return name; - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/PhraseElementTest.java b/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/PhraseElementTest.java deleted file mode 100644 index 0fa6f92014..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/PhraseElementTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringPath; -import org.junit.Test; - -public class PhraseElementTest { - - @Test - public void test() { - StringPath title = Expressions.stringPath("title"); - LuceneSerializer serializer = new LuceneSerializer(false, false); - QueryMetadata metadata = new DefaultQueryMetadata(); - assertThat(serializer.toQuery(title.eq("Hello World"), metadata).toString()) - .isEqualTo("title:Hello World"); - assertThat(serializer.toQuery(title.eq(new PhraseElement("Hello World")), metadata).toString()) - .isEqualTo("title:\"Hello World\""); - } - - @Test - public void equals() { - PhraseElement el1 = new PhraseElement("x"), - el2 = new PhraseElement("x"), - el3 = new PhraseElement("y"); - assertThat(el2).isEqualTo(el1); - assertThat(el1.equals(el3)).isFalse(); - } - - @Test - public void hashCode_() { - PhraseElement el1 = new PhraseElement("x"), el2 = new PhraseElement("x"); - assertThat(el2.hashCode()).isEqualTo(el1.hashCode()); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/QDocument.java b/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/QDocument.java deleted file mode 100644 index 84c11ce8fc..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/QDocument.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -import com.querydsl.core.types.PathMetadataFactory; -import com.querydsl.core.types.dsl.EntityPathBase; -import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.StringPath; -import org.apache.lucene.document.Document; - -public class QDocument extends EntityPathBase { - - private static final long serialVersionUID = -4872833626508344081L; - - public QDocument(final String var) { - super(Document.class, PathMetadataFactory.forVariable(var)); - } - - public final NumberPath year = createNumber("year", Integer.class); - - public final StringPath title = createString("title"); - - public final NumberPath gross = createNumber("gross", Double.class); -} diff --git a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/QueryElementTest.java b/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/QueryElementTest.java deleted file mode 100644 index 74ede9c968..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/QueryElementTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.apache.lucene.index.Term; -import org.apache.lucene.search.TermQuery; -import org.junit.Ignore; -import org.junit.Test; - -public class QueryElementTest { - - @Test - @Ignore - public void test() { - QueryElement element = new QueryElement(new TermQuery(new Term("str", "text"))); - assertThat(element.toString()).isEqualTo("str:text"); - // assertEquals(element.getQuery().hashCode(), element.hashCode()); - - QueryElement element2 = new QueryElement(new TermQuery(new Term("str", "text"))); - assertThat(element).isEqualTo(element2); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/TermElementTest.java b/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/TermElementTest.java deleted file mode 100644 index ca879526a7..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/TermElementTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene3; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringPath; -import org.junit.Test; - -public class TermElementTest { - - @Test - public void test() { - StringPath title = Expressions.stringPath("title"); - LuceneSerializer serializer = new LuceneSerializer(false, true); - QueryMetadata metadata = new DefaultQueryMetadata(); - assertThat(serializer.toQuery(title.eq("Hello World"), metadata).toString()) - .isEqualTo("title:\"Hello World\""); - assertThat(serializer.toQuery(title.eq(new TermElement("Hello World")), metadata).toString()) - .isEqualTo("title:Hello World"); - } - - @Test - public void testEqualsAndHashCode() { - TermElement el1 = new TermElement("x"), el2 = new TermElement("x"), el3 = new TermElement("y"); - assertThat(el2).isEqualTo(el1); - assertThat(el1.equals(el3)).isFalse(); - assertThat(el2.hashCode()).isEqualTo(el1.hashCode()); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/test/resources/log4j.properties.example b/querydsl-libraries/querydsl-lucene3/src/test/resources/log4j.properties.example deleted file mode 100644 index 0c3a1143dc..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/test/resources/log4j.properties.example +++ /dev/null @@ -1,9 +0,0 @@ -# Configure an appender that logs to console -log4j.rootLogger=info, A1 -log4j.threshold=debug -log4j.appender.A1=org.apache.log4j.ConsoleAppender -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c{1} - %m%n - -# Configuration of logging levels for different packages -log4j.logger.com.querydsl.lucene3=DEBUG diff --git a/querydsl-libraries/querydsl-lucene4/README.md b/querydsl-libraries/querydsl-lucene4/README.md deleted file mode 100644 index 60e5c75742..0000000000 --- a/querydsl-libraries/querydsl-lucene4/README.md +++ /dev/null @@ -1,57 +0,0 @@ -## Querydsl Lucene 4 - -The Lucene module provides integration with the Lucene 4 indexing library. - -**Maven integration** - - Add the following dependencies to your Maven project : -```XML - - io.github.openfeign.querydsl - querydsl-lucene4 - ${querydsl.version} - -``` - -**Creating the query types** - -With fields year and title a manually created query type could look something like this: - -```JAVA -public class QDocument extends EntityPathBase{ - private static final long serialVersionUID = -4872833626508344081L; - - public QDocument(String var) { - super(Document.class, PathMetadataFactory.forVariable(var)); - } - - public final StringPath year = createString("year"); - - public final StringPath title = createString("title"); -} -``` - -QDocument represents a Lucene document with the fields year and title. - -Code generation is not available for Lucene, since no schema data is available. - -**Querying** - -Querying with Querydsl Lucene is as simple as this: - -```JAVA -QDocument doc = new QDocument("doc"); - -IndexSearcher searcher = new IndexSearcher(index); -LuceneQuery query = new LuceneQuery(true, searcher); -List documents = query - .where(doc.year.between("1800", "2000").and(doc.title.startsWith("Huckle")) - .fetch(); -``` - -which is transformed into the following Lucene query : -``` -+year:[1800 TO 2000] +title:huckle* -``` - -For more information on the Querydsl Lucene module visit the reference documentation http://www.querydsl.com/static/querydsl/latest/reference/html/ch02s05.html diff --git a/querydsl-libraries/querydsl-lucene4/pom.xml b/querydsl-libraries/querydsl-lucene4/pom.xml deleted file mode 100644 index 257682d532..0000000000 --- a/querydsl-libraries/querydsl-lucene4/pom.xml +++ /dev/null @@ -1,104 +0,0 @@ - - - 4.0.0 - - - io.github.openfeign.querydsl - querydsl-libraries - 6.0-SNAPSHOT - - - querydsl-lucene4 - Querydsl - Lucene 4 support - Lucene support for Querydsl - - - 4.10.4 - org.apache.lucene.*;version="[4,5)", - ${osgi.import.package.root} - - - - - org.jetbrains - annotations - provided - - - org.apache.lucene - lucene-core - ${lucene.version} - provided - - - org.apache.lucene - lucene-analyzers-common - ${lucene.version} - provided - - - org.apache.lucene - lucene-queryparser - ${lucene.version} - provided - - - org.apache.lucene - lucene-queries - ${lucene.version} - provided - - - io.github.openfeign.querydsl - querydsl-core - ${project.version} - - - - - io.github.openfeign.querydsl - querydsl-core - ${project.version} - test-jar - test - - - - io.github.openfeign.querydsl - querydsl-apt - ${project.version} - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.3.0 - - - - com.querydsl.lucene4 - - - - - - - org.apache.felix - maven-bundle-plugin - - - - org.apache.maven.plugins - maven-compiler-plugin - - - com.querydsl.apt.QuerydslAnnotationProcessor - - - - - - diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/AbstractLuceneQuery.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/AbstractLuceneQuery.java deleted file mode 100644 index 9f409722ad..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/AbstractLuceneQuery.java +++ /dev/null @@ -1,371 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -import com.mysema.commons.lang.CloseableIterator; -import com.mysema.commons.lang.EmptyCloseableIterator; -import com.mysema.commons.lang.IteratorAdapter; -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.Fetchable; -import com.querydsl.core.NonUniqueResultException; -import com.querydsl.core.QueryException; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.QueryModifiers; -import com.querydsl.core.QueryResults; -import com.querydsl.core.SimpleQuery; -import com.querydsl.core.support.QueryMixin; -import com.querydsl.core.types.OrderSpecifier; -import com.querydsl.core.types.ParamExpression; -import com.querydsl.core.types.Path; -import com.querydsl.core.types.Predicate; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.queries.ChainedFilter; -import org.apache.lucene.sandbox.queries.DuplicateFilter; -import org.apache.lucene.search.Filter; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.QueryWrapperFilter; -import org.apache.lucene.search.ScoreDoc; -import org.apache.lucene.search.Sort; -import org.apache.lucene.search.TotalHitCountCollector; -import org.jetbrains.annotations.Nullable; - -/** - * AbstractLuceneQuery is an abstract super class for Lucene query implementations - * - * @author tiwe - * @param projection type - * @param concrete subtype of querydsl - */ -public abstract class AbstractLuceneQuery> - implements SimpleQuery, Fetchable { - - private static final String JAVA_ISO_CONTROL = "[\\p{Cntrl}&&[^\r\n\t]]"; - - private final QueryMixin queryMixin; - - private final IndexSearcher searcher; - - private final LuceneSerializer serializer; - - private final Function transformer; - - @Nullable private Set fieldsToLoad; - - private List filters = Collections.emptyList(); - - @Nullable private Filter filter; - - @Nullable private Sort querySort; - - @SuppressWarnings("unchecked") - public AbstractLuceneQuery( - LuceneSerializer serializer, IndexSearcher searcher, Function transformer) { - queryMixin = new QueryMixin((Q) this, new DefaultQueryMetadata()); - this.serializer = serializer; - this.searcher = searcher; - this.transformer = transformer; - } - - public AbstractLuceneQuery(IndexSearcher searcher, Function transformer) { - this(LuceneSerializer.DEFAULT, searcher, transformer); - } - - private long innerCount() { - try { - final int maxDoc = searcher.getIndexReader().maxDoc(); - if (maxDoc == 0) { - return 0; - } - TotalHitCountCollector collector = new TotalHitCountCollector(); - searcher.search(createQuery(), getFilter(), collector); - return collector.getTotalHits(); - } catch (IOException | IllegalArgumentException e) { - throw new QueryException(e); - } - } - - @Override - public long fetchCount() { - return innerCount(); - } - - protected Query createQuery() { - if (queryMixin.getMetadata().getWhere() == null) { - return new MatchAllDocsQuery(); - } - return serializer.toQuery(queryMixin.getMetadata().getWhere(), queryMixin.getMetadata()); - } - - /** - * Create a filter for constraints defined in this querydsl - * - * @return filter - */ - public Filter asFilter() { - return new QueryWrapperFilter(createQuery()); - } - - @Override - public Q distinct() { - throw new UnsupportedOperationException("use distinct(path) instead"); - } - - /** - * Add a DuplicateFilter for the field of the given property path - * - * @param property distinct property - * @return the current object - */ - public Q distinct(Path property) { - return filter(new DuplicateFilter(serializer.toField(property))); - } - - /** - * Apply the given Lucene filter to the search results - * - * @param filter filter - * @return the current object - */ - @SuppressWarnings("unchecked") - public Q filter(Filter filter) { - if (filters.isEmpty()) { - this.filter = filter; - filters = Collections.singletonList(filter); - } else { - this.filter = null; - if (filters.size() == 1) { - filters = new ArrayList(); - } - filters.add(filter); - } - return (Q) this; - } - - private Filter getFilter() { - if (filter == null && !filters.isEmpty()) { - filter = new ChainedFilter(filters.toArray(new Filter[0])); - } - return filter; - } - - @Override - public Q limit(long limit) { - return queryMixin.limit(limit); - } - - @Override - public CloseableIterator iterate() { - final QueryMetadata metadata = queryMixin.getMetadata(); - final List> orderBys = metadata.getOrderBy(); - final Integer queryLimit = metadata.getModifiers().getLimitAsInteger(); - final Integer queryOffset = metadata.getModifiers().getOffsetAsInteger(); - Sort sort = querySort; - int limit; - final int offset = queryOffset != null ? queryOffset : 0; - try { - limit = maxDoc(); - if (limit == 0) { - return new EmptyCloseableIterator(); - } - } catch (IOException | IllegalArgumentException e) { - throw new QueryException(e); - } - if (queryLimit != null && queryLimit < limit) { - limit = queryLimit; - } - if (sort == null && !orderBys.isEmpty()) { - sort = serializer.toSort(orderBys); - } - - try { - ScoreDoc[] scoreDocs; - int sumOfLimitAndOffset = limit + offset; - if (sumOfLimitAndOffset < 1) { - throw new QueryException( - "The given limit (" - + limit - + ") and offset (" - + offset - + ") cause an integer overflow."); - } - if (sort != null) { - scoreDocs = - searcher.search(createQuery(), getFilter(), sumOfLimitAndOffset, sort, false, false) - .scoreDocs; - } else { - scoreDocs = - searcher.search( - createQuery(), getFilter(), sumOfLimitAndOffset, Sort.INDEXORDER, false, false) - .scoreDocs; - } - if (offset < scoreDocs.length) { - return new ResultIterator(scoreDocs, offset, searcher, fieldsToLoad, transformer); - } - return new EmptyCloseableIterator(); - } catch (final IOException e) { - throw new QueryException(e); - } - } - - private List innerList() { - return new IteratorAdapter(iterate()).asList(); - } - - @Override - public List fetch() { - return innerList(); - } - - /** - * Set the given fields to load - * - * @param fieldsToLoad fields to load - * @return the current object - */ - @SuppressWarnings("unchecked") - public Q load(Set fieldsToLoad) { - this.fieldsToLoad = fieldsToLoad; - return (Q) this; - } - - /** - * Load only the fields of the given paths - * - * @param paths fields to load - * @return the current object - */ - @SuppressWarnings("unchecked") - public Q load(Path... paths) { - Set fields = new HashSet(); - for (Path path : paths) { - fields.add(serializer.toField(path)); - } - this.fieldsToLoad = fields; - return (Q) this; - } - - @Override - public QueryResults fetchResults() { - List documents = innerList(); - /* - * TODO Get rid of fetchCount(). It could be implemented by iterating the - * fetch results in fetch* from n to m. - */ - return new QueryResults(documents, queryMixin.getMetadata().getModifiers(), innerCount()); - } - - @Override - public Q offset(long offset) { - return queryMixin.offset(offset); - } - - public Q orderBy(OrderSpecifier o) { - return queryMixin.orderBy(o); - } - - @Override - public Q orderBy(OrderSpecifier... o) { - return queryMixin.orderBy(o); - } - - @Override - public Q restrict(QueryModifiers modifiers) { - return queryMixin.restrict(modifiers); - } - - @Override - public

Q set(ParamExpression

param, P value) { - return queryMixin.set(param, value); - } - - @SuppressWarnings("unchecked") - public Q sort(Sort sort) { - this.querySort = sort; - return (Q) this; - } - - @Nullable - private T oneResult(boolean unique) { - try { - int maxDoc = maxDoc(); - if (maxDoc == 0) { - return null; - } - final ScoreDoc[] scoreDocs = - searcher.search(createQuery(), getFilter(), maxDoc, Sort.INDEXORDER, false, false) - .scoreDocs; - int index = 0; - QueryModifiers modifiers = queryMixin.getMetadata().getModifiers(); - Long offset = modifiers.getOffset(); - if (offset != null) { - index = offset.intValue(); - } - Long limit = modifiers.getLimit(); - if (unique - && (limit == null ? scoreDocs.length - index > 1 : limit > 1 && scoreDocs.length > 1)) { - throw new NonUniqueResultException( - "Unique result requested, but " + scoreDocs.length + " found."); - } else if (scoreDocs.length > index) { - Document document; - if (fieldsToLoad != null) { - document = searcher.doc(scoreDocs[index].doc, fieldsToLoad); - } else { - document = searcher.doc(scoreDocs[index].doc); - } - return transformer.apply(document); - } else { - return null; - } - } catch (IOException | IllegalArgumentException e) { - throw new QueryException(e); - } - } - - @Override - public T fetchFirst() { - return oneResult(false); - } - - @Override - public T fetchOne() throws NonUniqueResultException { - return oneResult(true); - } - - public Q where(Predicate e) { - return queryMixin.where(e); - } - - @Override - public Q where(Predicate... e) { - return queryMixin.where(e); - } - - @Override - public String toString() { - return createQuery().toString().replaceAll(JAVA_ISO_CONTROL, "_"); - } - - private int maxDoc() throws IOException { - return searcher.getIndexReader().maxDoc(); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/IgnoreCaseUnsupportedException.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/IgnoreCaseUnsupportedException.java deleted file mode 100644 index 6a33cff01f..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/IgnoreCaseUnsupportedException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -/** - * Thrown for case ignore usage - * - * @author tiwe - */ -public class IgnoreCaseUnsupportedException extends UnsupportedOperationException { - - private static final long serialVersionUID = 412913389929530788L; - - public IgnoreCaseUnsupportedException() { - super("Ignore case queries are not supported with Lucene"); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneExpressions.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneExpressions.java deleted file mode 100644 index e8054f82a0..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneExpressions.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -import com.querydsl.core.types.Path; -import com.querydsl.core.types.dsl.BooleanExpression; -import org.apache.lucene.index.Term; -import org.apache.lucene.search.FuzzyQuery; -import org.apache.lucene.util.automaton.LevenshteinAutomata; - -/** - * Utility methods to create filter expressions for Lucene queries that are not covered by the - * Querydsl standard expression model - * - * @author tiwe - */ -public final class LuceneExpressions { - - /** - * Create a fuzzy query - * - * @param path path - * @param value value to match - * @return condition - */ - public static BooleanExpression fuzzyLike(Path path, String value) { - Term term = new Term(path.getMetadata().getName(), value); - return new QueryElement(new FuzzyQuery(term)); - } - - /** - * Create a fuzzy query - * - * @param path path - * @param value value to match - * @param maxEdits must be >= 0 and <= {@link - * LevenshteinAutomata#MAXIMUM_SUPPORTED_DISTANCE}. - * @return condition - */ - public static BooleanExpression fuzzyLike(Path path, String value, int maxEdits) { - Term term = new Term(path.getMetadata().getName(), value); - return new QueryElement(new FuzzyQuery(term, maxEdits)); - } - - /** - * Create a fuzzy query - * - * @param path path - * @param value value to match - * @param maxEdits must be >= 0 and <= {@link - * LevenshteinAutomata#MAXIMUM_SUPPORTED_DISTANCE}. - * @param prefixLength length of common (non-fuzzy) prefix - * @return condition - */ - public static BooleanExpression fuzzyLike( - Path path, String value, int maxEdits, int prefixLength) { - Term term = new Term(path.getMetadata().getName(), value); - return new QueryElement(new FuzzyQuery(term, maxEdits, prefixLength)); - } - - private LuceneExpressions() {} -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneOps.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneOps.java deleted file mode 100644 index d11f3d01a5..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneOps.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -import com.querydsl.core.types.Operator; - -/** - * Lucene specific operators - * - * @author tiwe - */ -public enum LuceneOps implements Operator { - LUCENE_QUERY(Object.class), - PHRASE(String.class), - TERM(String.class); - - private final Class type; - - LuceneOps(Class type) { - this.type = type; - } - - @Override - public Class getType() { - return type; - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneQuery.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneQuery.java deleted file mode 100644 index 5e9ad57d1c..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneQuery.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.search.IndexSearcher; - -/** - * {@code LuceneQuery} is a Querydsl query implementation for Lucene queries. - * - *

Example: - * - *

{@code
- * QDocument doc = new QDocument("doc");
- *
- * IndexSearcher searcher = new IndexSearcher(index);
- * LuceneQuery query = new LuceneQuery(true, searcher);
- * List documents = query
- *     .where(doc.year.between("1800", "2000").and(doc.title.startsWith("Huckle"))
- *     .fetch();
- * }
- * - * @author vema - */ -public class LuceneQuery extends AbstractLuceneQuery { - - private static final Function TRANSFORMER = - new Function() { - @Override - public Document apply(Document input) { - return input; - } - }; - - public LuceneQuery(IndexSearcher searcher) { - super(searcher, TRANSFORMER); - } - - public LuceneQuery(LuceneSerializer luceneSerializer, IndexSearcher searcher) { - super(luceneSerializer, searcher, TRANSFORMER); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneSerializer.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneSerializer.java deleted file mode 100644 index 8fe0919519..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneSerializer.java +++ /dev/null @@ -1,553 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.*; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.*; -import org.apache.lucene.index.Term; -import org.apache.lucene.queryparser.classic.QueryParser; -import org.apache.lucene.search.*; -import org.apache.lucene.search.BooleanClause.Occur; -import org.apache.lucene.util.BytesRef; -import org.apache.lucene.util.BytesRefBuilder; -import org.apache.lucene.util.NumericUtils; -import org.jetbrains.annotations.Nullable; - -/** - * Serializes Querydsl queries to Lucene queries. - * - * @author vema - */ -public class LuceneSerializer { - private static final Map, SortField.Type> sortFields = - new HashMap, SortField.Type>(); - - static { - sortFields.put(Integer.class, SortField.Type.INT); - sortFields.put(Float.class, SortField.Type.FLOAT); - sortFields.put(Long.class, SortField.Type.LONG); - sortFields.put(Double.class, SortField.Type.DOUBLE); - sortFields.put(Short.class, SortField.Type.SHORT); - sortFields.put(Byte.class, SortField.Type.BYTE); - sortFields.put(BigDecimal.class, SortField.Type.DOUBLE); - sortFields.put(BigInteger.class, SortField.Type.LONG); - } - - public static final LuceneSerializer DEFAULT = new LuceneSerializer(false, true); - - private final boolean lowerCase; - - private final boolean splitTerms; - - private final Locale sortLocale; - - public LuceneSerializer(boolean lowerCase, boolean splitTerms) { - this(lowerCase, splitTerms, Locale.getDefault()); - } - - public LuceneSerializer(boolean lowerCase, boolean splitTerms, Locale sortLocale) { - this.lowerCase = lowerCase; - this.splitTerms = splitTerms; - this.sortLocale = sortLocale; - } - - private Query toQuery(Operation operation, QueryMetadata metadata) { - Operator op = operation.getOperator(); - if (op == Ops.OR) { - return toTwoHandSidedQuery(operation, Occur.SHOULD, metadata); - } else if (op == Ops.AND) { - return toTwoHandSidedQuery(operation, Occur.MUST, metadata); - } else if (op == Ops.NOT) { - BooleanQuery bq = new BooleanQuery(); - bq.add(new BooleanClause(toQuery(operation.getArg(0), metadata), Occur.MUST_NOT)); - bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); - return bq; - } else if (op == Ops.LIKE) { - return like(operation, metadata); - } else if (op == Ops.LIKE_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.EQ) { - return eq(operation, metadata, false); - } else if (op == Ops.EQ_IGNORE_CASE) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.NE) { - return ne(operation, metadata, false); - } else if (op == Ops.STARTS_WITH) { - return startsWith(metadata, operation, false); - } else if (op == Ops.STARTS_WITH_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.ENDS_WITH) { - return endsWith(operation, metadata, false); - } else if (op == Ops.ENDS_WITH_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.STRING_CONTAINS) { - return stringContains(operation, metadata, false); - } else if (op == Ops.STRING_CONTAINS_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.BETWEEN) { - return between(operation, metadata); - } else if (op == Ops.IN) { - return in(operation, metadata, false); - } else if (op == Ops.NOT_IN) { - return notIn(operation, metadata, false); - } else if (op == Ops.LT) { - return lt(operation, metadata); - } else if (op == Ops.GT) { - return gt(operation, metadata); - } else if (op == Ops.LOE) { - return le(operation, metadata); - } else if (op == Ops.GOE) { - return ge(operation, metadata); - } else if (op == LuceneOps.LUCENE_QUERY) { - @SuppressWarnings("unchecked") // this is the expected type - Constant expectedConstant = (Constant) operation.getArg(0); - return expectedConstant.getConstant(); - } - throw new UnsupportedOperationException("Illegal operation " + operation); - } - - private Query toTwoHandSidedQuery(Operation operation, Occur occur, QueryMetadata metadata) { - Query lhs = toQuery(operation.getArg(0), metadata); - Query rhs = toQuery(operation.getArg(1), metadata); - BooleanQuery bq = new BooleanQuery(); - bq.add(createBooleanClause(lhs, occur)); - bq.add(createBooleanClause(rhs, occur)); - return bq; - } - - /** - * If the query is a BooleanQuery and it contains a single Occur.MUST_NOT clause it will be - * returned as is. Otherwise it will be wrapped in a BooleanClause with the given Occur. - */ - private BooleanClause createBooleanClause(Query query, Occur occur) { - if (query instanceof BooleanQuery) { - BooleanClause[] clauses = ((BooleanQuery) query).getClauses(); - if (clauses.length == 1 && clauses[0].getOccur().equals(Occur.MUST_NOT)) { - return clauses[0]; - } - } - return new BooleanClause(query, occur); - } - - protected Query like(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convert(path, operation.getArg(1)); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (String s : terms) { - bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST); - } - return bq; - } - return new WildcardQuery(new Term(field, terms[0])); - } - - protected Query eq(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - - if (Number.class.isAssignableFrom(operation.getArg(1).getType())) { - @SuppressWarnings("unchecked") // guarded by previous check - Constant rightArg = (Constant) operation.getArg(1); - return new TermQuery(new Term(field, convertNumber(rightArg.getConstant()))); - } - - return eq(field, convert(path, operation.getArg(1), metadata), ignoreCase); - } - - private BytesRef convertNumber(Number number) { - if (Integer.class.isInstance(number) - || Byte.class.isInstance(number) - || Short.class.isInstance(number)) { - BytesRefBuilder bytes = new BytesRefBuilder(); - bytes.setLength(NumericUtils.BUF_SIZE_INT); - NumericUtils.intToPrefixCoded(number.intValue(), 0, bytes); - return bytes.toBytesRef(); - } else if (Double.class.isInstance(number) || BigDecimal.class.isInstance(number)) { - BytesRefBuilder bytes = new BytesRefBuilder(); - bytes.setLength(NumericUtils.BUF_SIZE_LONG); - long l = NumericUtils.doubleToSortableLong(number.doubleValue()); - NumericUtils.longToPrefixCoded(l, 0, bytes); - return bytes.toBytesRef(); - } else if (Long.class.isInstance(number) || BigInteger.class.isInstance(number)) { - BytesRefBuilder bytes = new BytesRefBuilder(); - bytes.setLength(NumericUtils.BUF_SIZE_LONG); - NumericUtils.longToPrefixCoded(number.longValue(), 0, bytes); - return bytes.toBytesRef(); - } else if (Float.class.isInstance(number)) { - BytesRefBuilder bytes = new BytesRefBuilder(); - bytes.setLength(NumericUtils.BUF_SIZE_INT); - int i = NumericUtils.floatToSortableInt(number.floatValue()); - NumericUtils.intToPrefixCoded(i, 0, bytes); - return bytes.toBytesRef(); - } else { - throw new IllegalArgumentException("Unsupported numeric type " + number.getClass().getName()); - } - } - - protected Query eq(String field, String[] terms, boolean ignoreCase) { - if (terms.length > 1) { - PhraseQuery pq = new PhraseQuery(); - for (String s : terms) { - pq.add(new Term(field, s)); - } - return pq; - } - return new TermQuery(new Term(field, terms[0])); - } - - protected Query in(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - Path path = getPath(operation.getArg(0)); - String field = toField(path); - @SuppressWarnings("unchecked") // this is the expected type - Constant> expectedConstant = (Constant>) operation.getArg(1); - Collection values = expectedConstant.getConstant(); - BooleanQuery bq = new BooleanQuery(); - if (Number.class.isAssignableFrom(path.getType())) { - for (Object value : values) { - TermQuery eq = new TermQuery(new Term(field, convertNumber((Number) value))); - bq.add(eq, Occur.SHOULD); - } - } else { - for (Object value : values) { - String[] str = convert(path, value); - bq.add(eq(field, str, ignoreCase), Occur.SHOULD); - } - } - return bq; - } - - protected Query notIn(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - BooleanQuery bq = new BooleanQuery(); - bq.add(new BooleanClause(in(operation, metadata, false), Occur.MUST_NOT)); - bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); - return bq; - } - - protected Query ne(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - BooleanQuery bq = new BooleanQuery(); - bq.add(new BooleanClause(eq(operation, metadata, ignoreCase), Occur.MUST_NOT)); - bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); - return bq; - } - - protected Query startsWith(QueryMetadata metadata, Operation operation, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convertEscaped(path, operation.getArg(1), metadata); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (int i = 0; i < terms.length; ++i) { - String s = i == 0 ? terms[i] + "*" : "*" + terms[i] + "*"; - bq.add(new WildcardQuery(new Term(field, s)), Occur.MUST); - } - return bq; - } - return new PrefixQuery(new Term(field, terms[0])); - } - - protected Query stringContains( - Operation operation, QueryMetadata metadata, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convertEscaped(path, operation.getArg(1), metadata); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (String s : terms) { - bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST); - } - return bq; - } - return new WildcardQuery(new Term(field, "*" + terms[0] + "*")); - } - - protected Query endsWith(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convertEscaped(path, operation.getArg(1), metadata); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (int i = 0; i < terms.length; ++i) { - String s = i == terms.length - 1 ? "*" + terms[i] : "*" + terms[i] + "*"; - bq.add(new WildcardQuery(new Term(field, s)), Occur.MUST); - } - return bq; - } - return new WildcardQuery(new Term(field, "*" + terms[0])); - } - - protected Query between(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - // TODO Phrase not properly supported - return range( - path, toField(path), operation.getArg(1), operation.getArg(2), true, true, metadata); - } - - protected Query lt(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), null, operation.getArg(1), false, false, metadata); - } - - protected Query gt(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), operation.getArg(1), null, false, false, metadata); - } - - protected Query le(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), null, operation.getArg(1), true, true, metadata); - } - - protected Query ge(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), operation.getArg(1), null, true, true, metadata); - } - - protected Query range( - Path leftHandSide, - String field, - @Nullable Expression min, - @Nullable Expression max, - boolean minInc, - boolean maxInc, - QueryMetadata metadata) { - if (min != null && Number.class.isAssignableFrom(min.getType()) - || max != null && Number.class.isAssignableFrom(max.getType())) { - @SuppressWarnings("unchecked") // guarded by previous check - Constant minConstant = (Constant) min; - @SuppressWarnings("unchecked") // guarded by previous check - Constant maxConstant = (Constant) max; - - Class numType = - minConstant != null ? minConstant.getType() : maxConstant.getType(); - // this is not necessarily safe, but compile time checking - // on the user side mandates these types to be interchangeable - @SuppressWarnings("unchecked") - Class unboundedNumType = (Class) numType; - return numericRange( - unboundedNumType, - field, - minConstant == null ? null : minConstant.getConstant(), - maxConstant == null ? null : maxConstant.getConstant(), - minInc, - maxInc); - } - return stringRange(leftHandSide, field, min, max, minInc, maxInc, metadata); - } - - protected NumericRangeQuery numericRange( - Class clazz, - String field, - @Nullable N min, - @Nullable N max, - boolean minInc, - boolean maxInc) { - if (clazz.equals(Integer.class)) { - return NumericRangeQuery.newIntRange(field, (Integer) min, (Integer) max, minInc, maxInc); - } else if (clazz.equals(Double.class)) { - return NumericRangeQuery.newDoubleRange(field, (Double) min, (Double) max, minInc, minInc); - } else if (clazz.equals(Float.class)) { - return NumericRangeQuery.newFloatRange(field, (Float) min, (Float) max, minInc, minInc); - } else if (clazz.equals(Long.class)) { - return NumericRangeQuery.newLongRange(field, (Long) min, (Long) max, minInc, minInc); - } else if (clazz.equals(Byte.class) || clazz.equals(Short.class)) { - return NumericRangeQuery.newIntRange( - field, - min != null ? min.intValue() : null, - max != null ? max.intValue() : null, - minInc, - maxInc); - } else { - throw new IllegalArgumentException("Unsupported numeric type " + clazz.getName()); - } - } - - protected Query stringRange( - Path leftHandSide, - String field, - @Nullable Expression min, - @Nullable Expression max, - boolean minInc, - boolean maxInc, - QueryMetadata metadata) { - - if (min == null) { - return TermRangeQuery.newStringRange( - field, null, convert(leftHandSide, max, metadata)[0], minInc, maxInc); - } else if (max == null) { - return TermRangeQuery.newStringRange( - field, convert(leftHandSide, min, metadata)[0], null, minInc, maxInc); - } else { - return TermRangeQuery.newStringRange( - field, - convert(leftHandSide, min, metadata)[0], - convert(leftHandSide, max, metadata)[0], - minInc, - maxInc); - } - } - - private Path getPath(Expression leftHandSide) { - if (leftHandSide instanceof Path) { - return (Path) leftHandSide; - } else if (leftHandSide instanceof Operation) { - Operation operation = (Operation) leftHandSide; - if (operation.getOperator() == Ops.LOWER || operation.getOperator() == Ops.UPPER) { - return (Path) operation.getArg(0); - } - } - throw new IllegalArgumentException("Unable to transform " + leftHandSide + " to path"); - } - - /** - * template method, override to customize - * - * @param path path - * @return field name - */ - protected String toField(Path path) { - PathMetadata md = path.getMetadata(); - if (md.getPathType() == PathType.COLLECTION_ANY) { - return toField(md.getParent()); - } else { - String rv = md.getName(); - if (md.getParent() != null) { - Path parent = md.getParent(); - if (parent.getMetadata().getPathType() != PathType.VARIABLE) { - rv = toField(parent) + "." + rv; - } - } - return rv; - } - } - - private void verifyArguments(Operation operation) { - List> arguments = operation.getArgs(); - for (int i = 1; i < arguments.size(); ++i) { - if (!(arguments.get(i) instanceof Constant) - && !(arguments.get(i) instanceof ParamExpression) - && !(arguments.get(i) instanceof PhraseElement) - && !(arguments.get(i) instanceof TermElement)) { - throw new IllegalArgumentException( - "operand was of unsupported type " + arguments.get(i).getClass().getName()); - } - } - } - - /** - * template method - * - * @param leftHandSide left hand side - * @param rightHandSide right hand side - * @return results - */ - protected String[] convert( - Path leftHandSide, Expression rightHandSide, QueryMetadata metadata) { - if (rightHandSide instanceof Operation) { - Operation operation = (Operation) rightHandSide; - if (operation.getOperator() == LuceneOps.PHRASE) { - return operation.getArg(0).toString().split("\\s+"); - } else if (operation.getOperator() == LuceneOps.TERM) { - return new String[] {operation.getArg(0).toString()}; - } else { - throw new IllegalArgumentException(rightHandSide.toString()); - } - } else if (rightHandSide instanceof ParamExpression) { - Object value = metadata.getParams().get(rightHandSide); - if (value == null) { - throw new ParamNotSetException((ParamExpression) rightHandSide); - } - return convert(leftHandSide, value); - - } else if (rightHandSide instanceof Constant) { - return convert(leftHandSide, ((Constant) rightHandSide).getConstant()); - } else { - throw new IllegalArgumentException(rightHandSide.toString()); - } - } - - /** - * template method - * - * @param leftHandSide left hand side - * @param rightHandSide right hand side - * @return results - */ - protected String[] convert(Path leftHandSide, Object rightHandSide) { - String str = rightHandSide.toString(); - if (lowerCase) { - str = str.toLowerCase(); - } - if (splitTerms) { - if (str.equals("")) { - return new String[] {str}; - } else { - return str.split("\\s+"); - } - } else { - return new String[] {str}; - } - } - - private String[] convertEscaped( - Path leftHandSide, Expression rightHandSide, QueryMetadata metadata) { - String[] str = convert(leftHandSide, rightHandSide, metadata); - for (int i = 0; i < str.length; i++) { - str[i] = QueryParser.escape(str[i]); - } - return str; - } - - public Query toQuery(Expression expr, QueryMetadata metadata) { - if (expr instanceof Operation) { - return toQuery((Operation) expr, metadata); - } else { - return toQuery(ExpressionUtils.extract(expr), metadata); - } - } - - public Sort toSort(List> orderBys) { - List sorts = new ArrayList(orderBys.size()); - for (OrderSpecifier order : orderBys) { - if (!(order.getTarget() instanceof Path)) { - throw new IllegalArgumentException("argument was not of type Path."); - } - Class type = order.getTarget().getType(); - boolean reverse = !order.isAscending(); - Path path = getPath(order.getTarget()); - if (Number.class.isAssignableFrom(type)) { - sorts.add(new SortField(toField(path), sortFields.get(type), reverse)); - } else { - sorts.add(new SortField(toField(path), SortField.Type.STRING, reverse)); - } - } - Sort sort = new Sort(); - sort.setSort(sorts.toArray(new SortField[0])); - return sort; - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/PhraseElement.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/PhraseElement.java deleted file mode 100644 index 16a7e8c13b..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/PhraseElement.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.dsl.StringOperation; - -/** - * {@code PhraseElement} represents the embedded String as a phrase - * - * @author tiwe - */ -public class PhraseElement extends StringOperation { - - private static final long serialVersionUID = 2350215644019186076L; - - public PhraseElement(String str) { - super(LuceneOps.PHRASE, ConstantImpl.create(str)); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/QueryElement.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/QueryElement.java deleted file mode 100644 index 141c8ede51..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/QueryElement.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.dsl.BooleanOperation; -import org.apache.lucene.search.Query; - -/** - * {@code QueryElement} wraps a Lucene Query - * - * @author tiwe - */ -public class QueryElement extends BooleanOperation { - - private static final long serialVersionUID = 470868107363840155L; - - public QueryElement(Query query) { - super(LuceneOps.LUCENE_QUERY, ConstantImpl.create(query)); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/ResultIterator.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/ResultIterator.java deleted file mode 100644 index c2b76d06a3..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/ResultIterator.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -import com.mysema.commons.lang.CloseableIterator; -import com.querydsl.core.QueryException; -import java.io.IOException; -import java.util.Set; -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.ScoreDoc; -import org.jetbrains.annotations.Nullable; - -/** - * {@code ResultIterator} is a {@link CloseableIterator} implementation for Lucene query results - * - * @author tiwe - * @param - */ -public final class ResultIterator implements CloseableIterator { - - private final ScoreDoc[] scoreDocs; - - private int cursor; - - private final IndexSearcher searcher; - - @Nullable private final Set fieldsToLoad; - - private final Function transformer; - - public ResultIterator( - ScoreDoc[] scoreDocs, - int offset, - IndexSearcher searcher, - @Nullable Set fieldsToLoad, - Function transformer) { - this.scoreDocs = scoreDocs.clone(); - this.cursor = offset; - this.searcher = searcher; - this.fieldsToLoad = fieldsToLoad; - this.transformer = transformer; - } - - @Override - public boolean hasNext() { - return cursor != scoreDocs.length; - } - - @Override - public T next() { - try { - Document document; - if (fieldsToLoad != null) { - document = searcher.doc(scoreDocs[cursor++].doc, fieldsToLoad); - } else { - document = searcher.doc(scoreDocs[cursor++].doc); - } - return transformer.apply(document); - } catch (IOException e) { - throw new QueryException(e); - } - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - @Override - public void close() {} -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/TermElement.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/TermElement.java deleted file mode 100644 index edf055d37e..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/TermElement.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.dsl.StringOperation; - -/** - * {@code TermElement} represents the embedded String as a term - * - * @author tiwe - */ -public class TermElement extends StringOperation { - - private static final long serialVersionUID = 2350215644019186076L; - - public TermElement(String str) { - super(LuceneOps.TERM, ConstantImpl.create(str)); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/TypedQuery.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/TypedQuery.java deleted file mode 100644 index 0809eefe34..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/TypedQuery.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.search.IndexSearcher; - -/** - * {@code TypedQuery} is a typed query implementation for Lucene queries. - * - *

Converts Lucene documents to typed results via a constructor supplied transformer - * - * @param result type - * @author laim - * @author tiwe - */ -public class TypedQuery extends AbstractLuceneQuery> { - - /** - * Create a new TypedQuery instance - * - * @param searcher index searcher - * @param transformer transformer to transform Lucene documents to result objects - */ - public TypedQuery(IndexSearcher searcher, Function transformer) { - super(searcher, transformer); - } - - /** - * Create a new TypedQuery instance - * - * @param serializer serializer - * @param searcher index searcher - * @param transformer transformer to transform Lucene documents to result objects - */ - public TypedQuery( - LuceneSerializer serializer, IndexSearcher searcher, Function transformer) { - super(serializer, searcher, transformer); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/package-info.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/package-info.java deleted file mode 100644 index e4fa5fc679..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/package-info.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** Lucene 4 support */ -package com.querydsl.lucene4; diff --git a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneQueryTest.java b/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneQueryTest.java deleted file mode 100644 index ac02ce1acf..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneQueryTest.java +++ /dev/null @@ -1,747 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.easymock.EasyMock.*; - -import com.querydsl.core.NonUniqueResultException; -import com.querydsl.core.QueryException; -import com.querydsl.core.QueryModifiers; -import com.querydsl.core.QueryResults; -import com.querydsl.core.types.ParamNotSetException; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.Param; -import com.querydsl.core.types.dsl.StringPath; -import java.io.IOException; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.*; -import org.apache.lucene.document.Field.Index; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.sandbox.queries.DuplicateFilter; -import org.apache.lucene.search.Filter; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Sort; -import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.util.Version; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Tests for LuceneQuery - * - * @author vema - */ -public class LuceneQueryTest { - - private LuceneQuery query; - private StringPath title; - private NumberPath year; - private NumberPath gross; - - private final StringPath sort = Expressions.stringPath("sort"); - - private RAMDirectory idx; - private IndexWriter writer; - private IndexSearcher searcher; - - private Document createDocument( - final String docTitle, - final String docAuthor, - final String docText, - final int docYear, - final double docGross) { - final Document doc = new Document(); - - doc.add(new TextField("title", docTitle, Store.YES)); - doc.add(new TextField("author", docAuthor, Store.YES)); - doc.add(new TextField("text", docText, Store.YES)); - doc.add(new IntField("year", docYear, Store.YES)); - doc.add(new DoubleField("gross", docGross, Store.YES)); - - return doc; - } - - @Before - public void setUp() throws Exception { - final QDocument entityPath = new QDocument("doc"); - title = entityPath.title; - year = entityPath.year; - gross = entityPath.gross; - - idx = new RAMDirectory(); - writer = createWriter(idx); - - writer.addDocument( - createDocument( - "Jurassic Park", "Michael Crichton", "It's a UNIX system! I know this!", 1990, 90.00)); - writer.addDocument( - createDocument( - "Nummisuutarit", "Aleksis Kivi", "ESKO. Ja iloitset ja riemuitset?", 1864, 10.00)); - writer.addDocument( - createDocument( - "The Lord of the Rings", - "John R. R. Tolkien", - "One Ring to rule them all, One Ring to find them, One Ring to bring them all and in" - + " the darkness bind them", - 1954, - 89.00)); - writer.addDocument( - createDocument( - "Introduction to Algorithms", - "Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein", - "Bubble sort", - 1990, - 30.50)); - - writer.close(); - - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - } - - private IndexWriter createWriter(RAMDirectory idx) throws Exception { - IndexWriterConfig config = - new IndexWriterConfig(Version.LUCENE_31, new StandardAnalyzer(Version.LUCENE_42)) - .setOpenMode(IndexWriterConfig.OpenMode.CREATE); - return new IndexWriter(idx, config); - } - - @After - public void tearDown() throws Exception { - searcher.getIndexReader().close(); - } - - @Test - public void between() { - assertThat(query.where(year.between(1950, 1990)).fetchCount()).isEqualTo(3); - } - - @Test - public void count_empty_where_clause() { - assertThat(query.fetchCount()).isEqualTo(4); - } - - @Test - public void exists() { - assertThat(query.where(title.eq("Jurassic Park")).fetchCount() > 0).isTrue(); - assertThat(query.where(title.eq("Jurassic Park X")).fetchCount() > 0).isFalse(); - } - - @Test - public void notExists() { - assertThat(query.where(title.eq("Jurassic Park")).fetchCount() == 0).isFalse(); - assertThat(query.where(title.eq("Jurassic Park X")).fetchCount() == 0).isTrue(); - } - - @Test - public void count() { - query.where(title.eq("Jurassic Park")); - assertThat(query.fetchCount()).isEqualTo(1); - } - - @Test(expected = QueryException.class) - @Ignore - public void count_index_problem() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andThrow(new IllegalArgumentException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.fetchCount(); - verify(searcher); - } - - @Test(expected = UnsupportedOperationException.class) - public void countDistinct() { - query.where(year.between(1900, 3000)); - assertThat(query.distinct().fetchCount()).isEqualTo(3); - } - - @Test - public void in() { - assertThat(query.where(title.in("Jurassic Park", "Nummisuutarit")).fetchCount()).isEqualTo(2); - } - - @Test - public void in2() { - assertThat(query.where(year.in(1990, 1864)).fetchCount()).isEqualTo(3); - } - - @Test - public void in_toString() { - assertThat(query.where(year.in(1990, 1864)).toString()).isEqualTo("year:`____F year:`____H"); - } - - @Test - public void list_sorted_by_year_ascending() { - query.where(year.between(1800, 2000)); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void list_not_sorted() { - query.where(year.between(1800, 2000)); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - @Ignore // FIXME - public void sorted_by_different_locales() throws Exception { - Document d1 = new Document(); - Document d2 = new Document(); - Document d3 = new Document(); - d1.add(new Field("sort", "a\u00c4", Store.YES, Index.NOT_ANALYZED)); - d2.add(new Field("sort", "ab", Store.YES, Index.NOT_ANALYZED)); - d3.add(new Field("sort", "aa", Store.YES, Index.NOT_ANALYZED)); - writer = createWriter(idx); - writer.addDocument(d1); - writer.addDocument(d2); - writer.addDocument(d3); - writer.close(); - - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - query = new LuceneQuery(new LuceneSerializer(true, true, Locale.ENGLISH), searcher); - assertThat(query.fetch()).hasSize(3); - List results = query.where(sort.startsWith("a")).orderBy(sort.asc()).fetch(); - assertThat(results).hasSize(3); - assertThat(results.getFirst().getField("sort").stringValue()).isEqualTo("aa"); - assertThat(results.get(1).getField("sort").stringValue()).isEqualTo("a\u00c4"); - assertThat(results.get(2).getField("sort").stringValue()).isEqualTo("ab"); - - query = new LuceneQuery(new LuceneSerializer(true, true, Locale.of("fi", "FI")), searcher); - results = query.where(sort.startsWith("a")).orderBy(sort.asc()).fetch(); - assertThat(results.getFirst().getField("sort").stringValue()).isEqualTo("aa"); - assertThat(results.get(1).getField("sort").stringValue()).isEqualTo("ab"); - assertThat(results.get(2).getField("sort").stringValue()).isEqualTo("a\u00c4"); - } - - @Test - public void list_not_sorted_limit_2() { - query.where(year.between(1800, 2000)); - query.limit(2); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - } - - @Test - public void list_sorted_by_year_limit_1() { - query.where(year.between(1800, 2000)); - query.limit(1); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(1); - } - - @Test - public void list_not_sorted_offset_2() { - query.where(year.between(1800, 2000)); - query.offset(2); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - } - - @Test - public void list_sorted_ascending_by_year_offset_2() { - query.where(year.between(1800, 2000)); - query.offset(2); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - } - - @Test - public void list_sorted_ascending_by_year_restrict_limit_2_offset_1() { - query.where(year.between(1800, 2000)); - query.restrict(new QueryModifiers(2L, 1L)); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - assertThat(documents.getFirst().get("year")).isEqualTo("1954"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - } - - @Test - public void list_sorted_ascending_by_year() { - query.where(year.between(1800, 2000)); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1864"); - assertThat(documents.get(1).get("year")).isEqualTo("1954"); - assertThat(documents.get(2).get("year")).isEqualTo("1990"); - assertThat(documents.get(3).get("year")).isEqualTo("1990"); - } - - @Test - public void list_sort() { - Sort sort = LuceneSerializer.DEFAULT.toSort(Collections.singletonList(year.asc())); - - query.where(year.between(1800, 2000)); - // query.orderBy(year.asc()); - query.sort(sort); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1864"); - assertThat(documents.get(1).get("year")).isEqualTo("1954"); - assertThat(documents.get(2).get("year")).isEqualTo("1990"); - assertThat(documents.get(3).get("year")).isEqualTo("1990"); - } - - @Test - public void list_distinct_property() { - assertThat(query.fetch()).hasSize(4); - assertThat(query.distinct(year).fetch()).hasSize(3); - } - - @Test - public void list_with_filter() { - Filter filter = new DuplicateFilter("year"); - assertThat(query.fetch()).hasSize(4); - assertThat(query.filter(filter).fetch()).hasSize(3); - } - - @Test - public void count_distinct_property() { - assertThat(query.fetchCount()).isEqualTo(4L); - assertThat(query.distinct(year).fetchCount()).isEqualTo(3L); - } - - @Test - public void list_sorted_descending_by_year() { - query.where(year.between(1800, 2000)); - query.orderBy(year.desc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - assertThat(documents.get(2).get("year")).isEqualTo("1954"); - assertThat(documents.get(3).get("year")).isEqualTo("1864"); - } - - @Test - public void list_sorted_descending_by_gross() { - query.where(gross.between(0.0, 1000.00)); - query.orderBy(gross.desc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("gross")).isEqualTo("90.0"); - assertThat(documents.get(1).get("gross")).isEqualTo("89.0"); - assertThat(documents.get(2).get("gross")).isEqualTo("30.5"); - assertThat(documents.get(3).get("gross")).isEqualTo("10.0"); - } - - @Test - public void list_sorted_descending_by_year_and_ascending_by_title() { - query.where(year.between(1800, 2000)); - query.orderBy(year.desc()); - query.orderBy(title.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - assertThat(documents.getFirst().get("title")).isEqualTo("Introduction to Algorithms"); - assertThat(documents.get(1).get("title")).isEqualTo("Jurassic Park"); - } - - @Test - public void list_sorted_descending_by_year_and_descending_by_title() { - query.where(year.between(1800, 2000)); - query.orderBy(year.desc()); - query.orderBy(title.desc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - assertThat(documents.getFirst().get("title")).isEqualTo("Jurassic Park"); - assertThat(documents.get(1).get("title")).isEqualTo("Introduction to Algorithms"); - } - - @Ignore - @Test(expected = QueryException.class) - public void list_index_problem_in_max_doc() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andThrow(new IOException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.fetch(); - verify(searcher); - } - - @Ignore - @Test(expected = QueryException.class) - public void list_sorted_index_problem_in_max_doc() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andThrow(new IOException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.orderBy(title.asc()); - query.fetch(); - verify(searcher); - } - - @Test - public void offset() { - assertThat(query.where(title.eq("Jurassic Park")).offset(30).fetch()).isEmpty(); - } - - @Test - public void load_list() { - Document document = query.where(title.ne("")).load(title).fetch().get(0); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void load_list_fieldSelector() { - Document document = - query.where(title.ne("")).load(Collections.singleton("title")).fetch().get(0); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void load_singleResult() { - Document document = query.where(title.ne("")).load(title).fetchFirst(); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void load_singleResult_fieldSelector() { - Document document = query.where(title.ne("")).load(Collections.singleton("title")).fetchFirst(); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void singleResult() { - assertThat(query.where(title.ne("")).fetchFirst()).isNotNull(); - } - - @Test - public void single_result_takes_limit() { - assertThat(query.where(title.ne("")).limit(1).fetchFirst().get("title")) - .isEqualTo("Jurassic Park"); - } - - @Test - public void single_result_considers_limit_and_actual_result_size() { - query.where(title.startsWith("Nummi")); - final Document document = query.limit(3).fetchFirst(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test - public void single_result_returns_null_if_nothing_is_in_range() { - query.where(title.startsWith("Nummi")); - assertThat(query.offset(10).fetchFirst()).isNull(); - } - - @Test - public void single_result_considers_offset() { - assertThat(query.where(title.ne("")).offset(3).fetchFirst().get("title")) - .isEqualTo("Introduction to Algorithms"); - } - - @Test - public void single_result_considers_limit_and_offset() { - assertThat(query.where(title.ne("")).limit(1).offset(2).fetchFirst().get("title")) - .isEqualTo("The Lord of the Rings"); - } - - @Test(expected = NonUniqueResultException.class) - public void uniqueResult_contract() { - query.where(title.ne("")).fetchOne(); - } - - @Test - public void unique_result_takes_limit() { - assertThat(query.where(title.ne("")).limit(1).fetchOne().get("title")) - .isEqualTo("Jurassic Park"); - } - - @Test - public void unique_result_considers_limit_and_actual_result_size() { - query.where(title.startsWith("Nummi")); - final Document document = query.limit(3).fetchOne(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test - public void unique_result_returns_null_if_nothing_is_in_range() { - query.where(title.startsWith("Nummi")); - assertThat(query.offset(10).fetchOne()).isNull(); - } - - @Test - public void unique_result_considers_offset() { - assertThat(query.where(title.ne("")).offset(3).fetchOne().get("title")) - .isEqualTo("Introduction to Algorithms"); - } - - @Test - public void unique_result_considers_limit_and_offset() { - assertThat(query.where(title.ne("")).limit(1).offset(2).fetchOne().get("title")) - .isEqualTo("The Lord of the Rings"); - } - - @Test - public void uniqueResult() { - query.where(title.startsWith("Nummi")); - final Document document = query.fetchOne(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test - public void uniqueResult_with_param() { - final Param param = new Param(String.class, "title"); - query.set(param, "Nummi"); - query.where(title.startsWith(param)); - final Document document = query.fetchOne(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test(expected = ParamNotSetException.class) - public void uniqueResult_param_not_set() { - final Param param = new Param(String.class, "title"); - query.where(title.startsWith(param)); - query.fetchOne(); - } - - @Test(expected = QueryException.class) - public void uniqueResult_finds_more_than_one_result() { - query.where(year.eq(1990)); - query.fetchOne(); - } - - @Test - public void uniqueResult_finds_no_results() { - query.where(year.eq(2200)); - assertThat(query.fetchOne()).isNull(); - } - - @Test - @Ignore - public void uniqueResult_finds_no_results_because_no_documents_in_index() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andReturn(0); - replay(searcher); - assertThat(query.where(year.eq(3000)).fetchOne()).isNull(); - verify(searcher); - } - - @Test(expected = QueryException.class) - @Ignore - public void uniqueResult_sorted_index_problem_in_max_doc() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andThrow(new IllegalArgumentException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.fetchOne(); - verify(searcher); - } - - @Test - @Ignore - public void count_returns_0_because_no_documents_in_index() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andReturn(0); - replay(searcher); - assertThat(query.where(year.eq(3000)).fetchCount()).isEqualTo(0); - verify(searcher); - } - - @Test(expected = UnsupportedOperationException.class) - public void listDistinct() { - query.where(year.between(1900, 2000).or(title.startsWith("Jura"))); - query.orderBy(year.asc()); - final List documents = query.distinct().fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(3); - } - - @Test - public void listResults() { - query.where(year.between(1800, 2000)); - query.restrict(new QueryModifiers(2L, 1L)); - query.orderBy(year.asc()); - final QueryResults results = query.fetchResults(); - assertThat(results.isEmpty()).isFalse(); - assertThat(results.getResults().get(0).get("year")).isEqualTo("1954"); - assertThat(results.getResults().get(1).get("year")).isEqualTo("1990"); - assertThat(results.getLimit()).isEqualTo(2); - assertThat(results.getOffset()).isEqualTo(1); - assertThat(results.getTotal()).isEqualTo(4); - } - - @Test(expected = UnsupportedOperationException.class) - public void listDistinctResults() { - query.where(year.between(1800, 2000).or(title.eq("The Lord of the Rings"))); - query.restrict(new QueryModifiers(1L, 1L)); - query.orderBy(year.asc()); - final QueryResults results = query.distinct().fetchResults(); - assertThat(results.isEmpty()).isFalse(); - assertThat(results.getResults().get(0).get("year")).isEqualTo("1954"); - assertThat(results.getLimit()).isEqualTo(1); - assertThat(results.getOffset()).isEqualTo(1); - assertThat(results.getTotal()).isEqualTo(4); - } - - @Test - public void list_all() { - final List results = - query.where(title.like("*")).orderBy(title.asc(), year.desc()).fetch(); - assertThat(results).hasSize(4); - } - - @Test(expected = IllegalArgumentException.class) - public void list_sorted_ascending_limit_negative() { - query.where(year.between(1800, 2000)); - query.limit(-1); - query.orderBy(year.asc()); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_not_sorted_limit_negative() { - query.where(year.between(1800, 2000)); - query.limit(-1); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_sorted_ascending_limit_0() { - query.where(year.between(1800, 2000)); - query.limit(0); - query.orderBy(year.asc()); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_not_sorted_limit_0() { - query.where(year.between(1800, 2000)); - query.limit(0); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_sorted_ascending_offset_negative() { - query.where(year.between(1800, 2000)); - query.offset(-1); - query.orderBy(year.asc()); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_not_sorted_offset_negative() { - query.where(year.between(1800, 2000)); - query.offset(-1); - query.fetch(); - } - - @Test - public void list_sorted_ascending_offset_0() { - query.where(year.between(1800, 2000)); - query.offset(0); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void list_not_sorted_offset_0() { - query.where(year.between(1800, 2000)); - query.offset(0); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void iterate() { - query.where(year.between(1800, 2000)); - final Iterator iterator = query.iterate(); - int count = 0; - while (iterator.hasNext()) { - iterator.next(); - ++count; - } - assertThat(count).isEqualTo(4); - } - - @Test - public void all_by_excluding_where() { - assertThat(query.fetch()).hasSize(4); - } - - @Test - public void empty_index_should_return_empty_list() throws Exception { - idx = new RAMDirectory(); - - writer = createWriter(idx); - writer.close(); - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - assertThat(query.fetch()).isEmpty(); - } - - @Test(expected = QueryException.class) - public void - list_results_throws_an_illegal_argument_exception_when_sum_of_limit_and_offset_is_negative() { - query.limit(1).offset(Integer.MAX_VALUE).fetchResults(); - } - - @Test - public void limit_max_value() { - assertThat(query.limit(Long.MAX_VALUE).fetch()).hasSize(4); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneSerializerNotTokenizedTest.java b/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneSerializerNotTokenizedTest.java deleted file mode 100644 index 4f5ac8c122..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneSerializerNotTokenizedTest.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -import static com.querydsl.lucene4.QPerson.person; -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.Expression; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringPath; -import java.time.LocalDate; -import java.util.Arrays; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.Field.Index; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TopDocs; -import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.util.Version; -import org.junit.Before; -import org.junit.Test; - -public class LuceneSerializerNotTokenizedTest { - private RAMDirectory idx; - private IndexWriter writer; - private IndexSearcher searcher; - private LuceneSerializer serializer; - - private final QueryMetadata metadata = new DefaultQueryMetadata(); - - private final Person clooney = new Person("actor_1", "George Clooney", LocalDate.of(1961, 4, 6)); - private final Person pitt = new Person("actor_2", "Brad Pitt", LocalDate.of(1963, 12, 18)); - - private void testQuery(Expression expr, String expectedQuery, int expectedHits) - throws Exception { - Query query = serializer.toQuery(expr, metadata); - TopDocs docs = searcher.search(query, 100); - assertThat(docs.totalHits).isEqualTo(expectedHits); - assertThat(query.toString()).isEqualTo(expectedQuery); - } - - private Document createDocument(Person person) { - Document doc = new Document(); - doc.add(new Field("id", person.getId(), Store.YES, Index.NOT_ANALYZED)); - doc.add(new Field("name", person.getName(), Store.YES, Index.NOT_ANALYZED)); - doc.add( - new Field("birthDate", person.getBirthDate().toString(), Store.YES, Index.NOT_ANALYZED)); - return doc; - } - - @Before - public void before() throws Exception { - serializer = new LuceneSerializer(false, false); - idx = new RAMDirectory(); - IndexWriterConfig config = - new IndexWriterConfig(Version.LUCENE_31, new StandardAnalyzer(Version.LUCENE_30)) - .setOpenMode(IndexWriterConfig.OpenMode.CREATE); - writer = new IndexWriter(idx, config); - - writer.addDocument(createDocument(clooney)); - writer.addDocument(createDocument(pitt)); - - Document document = new Document(); - for (String movie : Arrays.asList("Interview with the Vampire", "Up in the Air")) { - document.add(new Field("movie", movie, Store.YES, Index.NOT_ANALYZED)); - } - writer.addDocument(document); - - writer.close(); - - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - } - - @Test - public void equals_by_id_matches() throws Exception { - testQuery(person.id.eq("actor_1"), "id:actor_1", 1); - } - - @Test - public void equals_by_id_does_not_match() throws Exception { - testQuery(person.id.eq("actor_8"), "id:actor_8", 0); - } - - @Test - public void equals_by_name_matches() throws Exception { - testQuery(person.name.eq("George Clooney"), "name:George Clooney", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void equals_by_name_ignoring_case_does_not_match() throws Exception { - testQuery(person.name.equalsIgnoreCase("george clooney"), "name:george clooney", 0); - } - - @Test - public void equals_by_name_does_not_match() throws Exception { - testQuery(person.name.eq("George Looney"), "name:George Looney", 0); - } - - @Test - public void starts_with_name_should_match() throws Exception { - testQuery(person.name.startsWith("George C"), "name:George C*", 1); - } - - @Test - public void starts_with_name_should_not_match() throws Exception { - testQuery(person.name.startsWith("George L"), "name:George L*", 0); - } - - @Test - public void ends_with_name_should_match() throws Exception { - testQuery(person.name.endsWith("e Clooney"), "name:*e Clooney", 1); - } - - @Test - public void ends_with_name_should_not_match() throws Exception { - testQuery(person.name.endsWith("e Looney"), "name:*e Looney", 0); - } - - @Test - public void contains_name_should_match() throws Exception { - testQuery(person.name.contains("oney"), "name:*oney*", 1); - } - - @Test - public void contains_name_should_not_match() throws Exception { - testQuery(person.name.contains("bloney"), "name:*bloney*", 0); - } - - @Test - public void in_names_should_match_2() throws Exception { - testQuery( - person.name.in("Brad Pitt", "George Clooney"), "name:Brad Pitt name:George Clooney", 2); - } - - @Test - public void or_by_name_should_match_2() throws Exception { - testQuery( - person.name.eq("Brad Pitt").or(person.name.eq("George Clooney")), - "name:Brad Pitt name:George Clooney", - 2); - } - - @Test - public void equals_by_birth_date() throws Exception { - testQuery(person.birthDate.eq(clooney.getBirthDate()), "birthDate:1961-04-06", 1); - } - - @Test - public void between_phrase() throws Exception { - testQuery( - person.name.between("Brad Pitt", "George Clooney"), - "name:[Brad Pitt TO George Clooney]", - 2); - } - - @Test - public void not_equals_finds_the_actors_and_movies() throws Exception { - testQuery(person.name.ne("Michael Douglas"), "-name:Michael Douglas +*:*", 3); - } - - @Test - public void not_equals_finds_only_clooney_and_movies() throws Exception { - testQuery(person.name.ne("Brad Pitt"), "-name:Brad Pitt +*:*", 2); - } - - @Test - public void and_with_two_not_equals_doesnt_find_the_actors() throws Exception { - testQuery( - person.name.ne("Brad Pitt").and(person.name.ne("George Clooney")), - "+(-name:Brad Pitt +*:*) +(-name:George Clooney +*:*)", - 1); - } - - @Test - public void or_with_two_not_equals_finds_movies_and_actors() throws Exception { - testQuery( - person.name.ne("Brad Pitt").or(person.name.ne("George Clooney")), - "(-name:Brad Pitt +*:*) (-name:George Clooney +*:*)", - 3); - } - - @Test - public void negation_of_equals_finds_movies_and_actors() throws Exception { - testQuery(person.name.eq("Michael Douglas").not(), "-name:Michael Douglas +*:*", 3); - } - - @Test - public void negation_of_equals_finds_pitt_and_movies() throws Exception { - testQuery(person.name.eq("Brad Pitt").not(), "-name:Brad Pitt +*:*", 2); - } - - @Test - public void multiple_field_search_from_movies() throws Exception { - StringPath movie = Expressions.stringPath("movie"); - testQuery(movie.in("Interview with the Vampire"), "movie:Interview with the Vampire", 1); - testQuery(movie.eq("Up in the Air"), "movie:Up in the Air", 1); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneSerializerTest.java b/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneSerializerTest.java deleted file mode 100644 index c3214f66e5..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneSerializerTest.java +++ /dev/null @@ -1,718 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; - -import com.querydsl.core.BooleanBuilder; -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.MatchingFiltersFactory; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.QuerydslModule; -import com.querydsl.core.StringConstant; -import com.querydsl.core.Target; -import com.querydsl.core.types.Expression; -import com.querydsl.core.types.Operation; -import com.querydsl.core.types.Operator; -import com.querydsl.core.types.Ops; -import com.querydsl.core.types.Predicate; -import com.querydsl.core.types.dsl.BooleanExpression; -import com.querydsl.core.types.dsl.CollectionPath; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.PathBuilder; -import com.querydsl.core.types.dsl.StringPath; -import java.io.StringReader; -import java.util.Arrays; -import java.util.Collections; -import java.util.EnumSet; -import java.util.Set; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.DoubleField; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.Field.Index; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.document.FloatField; -import org.apache.lucene.document.IntField; -import org.apache.lucene.document.LongField; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TopDocs; -import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.util.Version; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Tests for LuceneSerializer - * - * @author vema - */ -public class LuceneSerializerTest { - private LuceneSerializer serializer; - private PathBuilder entityPath; - private StringPath title; - private StringPath author; - private StringPath text; - private StringPath rating; - private StringPath publisher; - private NumberPath year; - private NumberPath gross; - private CollectionPath titles; - - private NumberPath longField; - private NumberPath shortField; - private NumberPath byteField; - private NumberPath floatField; - - private static final String YEAR_PREFIX_CODED = ""; - private static final String GROSS_PREFIX_CODED = ""; - private static final String LONG_PREFIX_CODED = ""; - private static final String SHORT_PREFIX_CODED = ""; - private static final String BYTE_PREFIX_CODED = ""; - private static final String FLOAT_PREFIX_CODED = ""; - - private IndexWriterConfig config; - private RAMDirectory idx; - private IndexWriter writer; - private IndexSearcher searcher; - - private static final Set UNSUPPORTED_OPERATORS = - Collections.unmodifiableSet( - EnumSet.of( - Ops.STARTS_WITH_IC, Ops.EQ_IGNORE_CASE, Ops.ENDS_WITH_IC, Ops.STRING_CONTAINS_IC)); - - private final QueryMetadata metadata = new DefaultQueryMetadata(); - - private Document createDocument() { - Document doc = new Document(); - - doc.add(new Field("title", new StringReader("Jurassic Park"))); - doc.add(new Field("author", new StringReader("Michael Crichton"))); - doc.add(new Field("text", new StringReader("It's a UNIX system! I know this!"))); - doc.add(new Field("rating", new StringReader("Good"))); - doc.add(new Field("publisher", "", Store.YES, Index.ANALYZED)); - doc.add(new IntField("year", 1990, Store.YES)); - doc.add(new DoubleField("gross", 900.0, Store.YES)); - - doc.add(new LongField("longField", 1, Store.YES)); - doc.add(new IntField("shortField", 1, Store.YES)); - doc.add(new IntField("byteField", 1, Store.YES)); - doc.add(new FloatField("floatField", 1, Store.YES)); - - return doc; - } - - @Before - public void setUp() throws Exception { - serializer = new LuceneSerializer(true, true); - entityPath = new PathBuilder(Object.class, "obj"); - title = entityPath.getString("title"); - author = entityPath.getString("author"); - text = entityPath.getString("text"); - publisher = entityPath.getString("publisher"); - year = entityPath.getNumber("year", Integer.class); - rating = entityPath.getString("rating"); - gross = entityPath.getNumber("gross", Double.class); - titles = entityPath.getCollection("title", String.class, StringPath.class); - - longField = entityPath.getNumber("longField", Long.class); - shortField = entityPath.getNumber("shortField", Short.class); - byteField = entityPath.getNumber("byteField", Byte.class); - floatField = entityPath.getNumber("floatField", Float.class); - - idx = new RAMDirectory(); - config = - new IndexWriterConfig(Version.LUCENE_42, new StandardAnalyzer(Version.LUCENE_42)) - .setOpenMode(IndexWriterConfig.OpenMode.CREATE); - writer = new IndexWriter(idx, config); - - writer.addDocument(createDocument()); - - writer.close(); - - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - } - - @After - public void tearDown() throws Exception { - searcher.getIndexReader().close(); - } - - private void testQuery(Expression expr, int expectedHits) throws Exception { - Query query = serializer.toQuery(expr, metadata); - TopDocs docs = searcher.search(query, 100); - assertThat(docs.totalHits).isEqualTo(expectedHits); - } - - private void testQuery(Expression expr, String expectedQuery, int expectedHits) - throws Exception { - Query query = serializer.toQuery(expr, metadata); - TopDocs docs = searcher.search(query, 100); - assertThat(docs.totalHits).isEqualTo(expectedHits); - assertThat(query.toString()).isEqualTo(expectedQuery); - } - - @Test - public void queryElement() throws Exception { - Query query1 = serializer.toQuery(author.like("Michael"), metadata); - Query query2 = serializer.toQuery(text.like("Text"), metadata); - - BooleanExpression query = Expressions.anyOf(new QueryElement(query1), new QueryElement(query2)); - testQuery(query, "author:michael text:text", 1); - } - - @Test - public void like() throws Exception { - testQuery(author.like("*ichael*"), "author:*ichael*", 1); - } - - @Test - public void like_custom_wildcard_single_character() throws Exception { - testQuery(author.like("Mi?hael"), "author:mi?hael", 1); - } - - @Test - public void like_custom_wildcard_multiple_character() throws Exception { - testQuery(text.like("*U*X*"), "text:*u*x*", 1); - } - - @Test - public void like_phrase() throws Exception { - testQuery(title.like("*rassic Par*"), "+title:**rassic* +title:*par**", 1); - } - - @Test - public void like_or_like() throws Exception { - testQuery(title.like("House").or(author.like("*ichae*")), "title:house author:*ichae*", 1); - } - - @Test - public void like_and_like() throws Exception { - testQuery(title.like("*assic*").and(rating.like("G?od")), "+title:*assic* +rating:g?od", 1); - } - - @Test - public void eq() throws Exception { - testQuery(rating.eq("good"), "rating:good", 1); - } - - @Test - public void eq_with_deep_path() throws Exception { - StringPath deepPath = entityPath.get("property1", Object.class).getString("property2"); - testQuery(deepPath.eq("good"), "property1.property2:good", 0); - } - - @Test - public void fuzzyLike() throws Exception { - testQuery(LuceneExpressions.fuzzyLike(rating, "Good"), "rating:Good~2", 1); - } - - @Test - public void fuzzyLike_with_similarity() throws Exception { - testQuery(LuceneExpressions.fuzzyLike(rating, "Good", 2), "rating:Good~2", 1); - } - - @Test - public void fuzzyLike_with_similarity_and_prefix() throws Exception { - testQuery(LuceneExpressions.fuzzyLike(rating, "Good", 2, 0), "rating:Good~2", 1); - } - - @Test - @Ignore - public void eq_numeric_integer() throws Exception { - testQuery(year.eq(1990), "year:" + YEAR_PREFIX_CODED, 1); - } - - @Test - @Ignore - public void eq_numeric_double() throws Exception { - testQuery(gross.eq(900.00), "gross:" + GROSS_PREFIX_CODED, 1); - } - - @Test - @Ignore - public void eq_numeric() throws Exception { - testQuery(longField.eq(1L), "longField:" + LONG_PREFIX_CODED, 1); - testQuery(shortField.eq((short) 1), "shortField:" + SHORT_PREFIX_CODED, 1); - testQuery(byteField.eq((byte) 1), "byteField:" + BYTE_PREFIX_CODED, 1); - testQuery(floatField.eq((float) 1.0), "floatField:" + FLOAT_PREFIX_CODED, 1); - } - - @Test - public void equals_ignores_case() throws Exception { - testQuery(title.eq("Jurassic"), "title:jurassic", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void title_equals_ignore_case_or_year_equals() throws Exception { - testQuery( - title.equalsIgnoreCase("House").or(year.eq(1990)), - "title:house year:" + YEAR_PREFIX_CODED, - 1); - } - - @Test - @Ignore - public void eq_and_eq() throws Exception { - testQuery( - title.eq("Jurassic Park").and(year.eq(1990)), - "+title:\"jurassic park\" +year:" + YEAR_PREFIX_CODED, - 1); - } - - @Test - @Ignore - public void eq_and_eq_and_eq() throws Exception { - testQuery( - title.eq("Jurassic Park").and(year.eq(1990)).and(author.eq("Michael Crichton")), - "+(+title:\"jurassic park\" +year:" + YEAR_PREFIX_CODED + ") +author:\"michael crichton\"", - 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void equals_ignore_case_and_or() throws Exception { - testQuery( - title - .equalsIgnoreCase("Jurassic Park") - .and(rating.equalsIgnoreCase("Bad")) - .or(author.equalsIgnoreCase("Michael Crichton")), - "(+title:\"jurassic park\" +rating:bad) author:\"michael crichton\"", - 1); - } - - @Test - public void eq_or_eq_and_eq_does_not_find_results() throws Exception { - testQuery( - title.eq("jeeves").or(rating.eq("superb")).and(author.eq("michael crichton")), - "+(title:jeeves rating:superb) +author:\"michael crichton\"", - 0); - } - - @Test - public void eq_phrase() throws Exception { - testQuery(title.eq("Jurassic Park"), "title:\"jurassic park\"", 1); - } - - @Test - @Ignore("Not easily done in Lucene!") - public void publisher_equals_empty_string() throws Exception { - testQuery(publisher.eq(""), "publisher:", 1); - } - - @Test - public void eq_phrase_should_not_find_results_but_luceNe_semantics_differs_from_querydsls() - throws Exception { - testQuery(text.eq("UNIX System"), "text:\"unix system\"", 1); - } - - @Test - public void eq_phrase_does_not_find_results_because_word_in_middle() throws Exception { - testQuery(title.eq("Jurassic Amusement Park"), "title:\"jurassic amusement park\"", 0); - } - - @Test - public void like_not_does_not_find_results() throws Exception { - testQuery(title.like("*H*e*").not(), "-title:*h*e* +*:*", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void title_equals_ignore_case_negation_or_rating_equals_ignore_case() throws Exception { - testQuery( - title.equalsIgnoreCase("House").not().or(rating.equalsIgnoreCase("Good")), - "-title:house rating:good", - 1); - } - - @Test - public void eq_not_does_not_find_results() throws Exception { - testQuery(title.eq("Jurassic Park").not(), "-title:\"jurassic park\" +*:*", 0); - } - - @Test - public void title_equals_not_house() throws Exception { - testQuery(title.eq("house").not(), "-title:house +*:*", 1); - } - - @Test - public void eq_and_eq_not_does_not_find_results_because_second_expression_finds_nothing() - throws Exception { - testQuery( - rating.eq("superb").and(title.eq("house").not()), "+rating:superb +(-title:house +*:*)", 0); - } - - @Test - public void not_equals_finds_one() throws Exception { - testQuery(title.ne("house"), "-title:house +*:*", 1); - } - - @Test - public void not_equals_finds_none() throws Exception { - testQuery(title.ne("Jurassic Park"), "-title:\"jurassic park\" +*:*", 0); - } - - @Test - public void nothing_found_with_not_equals_or_equals() throws Exception { - testQuery( - title.ne("jurassic park").or(rating.eq("lousy")), - "(-title:\"jurassic park\" +*:*) rating:lousy", - 0); - } - - @Test - public void ne_and_eq() throws Exception { - testQuery(title.ne("house").and(rating.eq("good")), "+(-title:house +*:*) +rating:good", 1); - } - - @Test - public void startsWith() throws Exception { - testQuery(title.startsWith("Jurassi"), "title:jurassi*", 1); - } - - @Test - public void startsWith_phrase() throws Exception { - testQuery(title.startsWith("jurassic par"), "+title:jurassic* +title:*par*", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void starts_with_ignore_case_phrase_does_not_find_results() throws Exception { - testQuery(title.startsWithIgnoreCase("urassic Par"), "+title:urassic* +title:*par*", 0); - } - - @Test - public void endsWith() throws Exception { - testQuery(title.endsWith("ark"), "title:*ark", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void ends_with_ignore_case_phrase() throws Exception { - testQuery(title.endsWithIgnoreCase("sic Park"), "+title:*sic* +title:*park", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void ends_with_ignore_case_phrase_does_not_find_results() throws Exception { - testQuery(title.endsWithIgnoreCase("sic Par"), "+title:*sic* +title:*par", 0); - } - - @Test - public void contains() throws Exception { - testQuery(title.contains("rassi"), "title:*rassi*", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void contains_ignore_case_phrase() throws Exception { - testQuery(title.containsIgnoreCase("rassi Pa"), "+title:*rassi* +title:*pa*", 1); - } - - @Test - public void contains_user_inputted_wildcards_dont_work() throws Exception { - testQuery(title.contains("r*i"), "title:*r\\*i*", 0); - } - - @Test - public void between() throws Exception { - testQuery(title.between("Indiana", "Kundun"), "title:[indiana TO kundun]", 1); - } - - @Test - public void between_numeric_integer() throws Exception { - testQuery(year.between(1980, 2000), "year:[1980 TO 2000]", 1); - } - - @Test - public void between_numeric_double() throws Exception { - testQuery(gross.between(10.00, 19030.00), "gross:[10.0 TO 19030.0]", 1); - } - - @Test - public void between_numeric() throws Exception { - testQuery(longField.between(0L, 2L), "longField:[0 TO 2]", 1); - testQuery(shortField.between((short) 0, (short) 2), "shortField:[0 TO 2]", 1); - testQuery(byteField.between((byte) 0, (byte) 2), "byteField:[0 TO 2]", 1); - testQuery(floatField.between((float) 0.0, (float) 2.0), "floatField:[0.0 TO 2.0]", 1); - } - - @Test - public void between_is_inclusive_from_start() throws Exception { - testQuery(title.between("Jurassic", "Kundun"), "title:[jurassic TO kundun]", 1); - } - - @Test - public void between_is_inclusive_to_end() throws Exception { - testQuery(title.between("Indiana", "Jurassic"), "title:[indiana TO jurassic]", 1); - } - - @Test - public void between_does_not_find_results() throws Exception { - testQuery(title.between("Indiana", "Jurassib"), "title:[indiana TO jurassib]", 0); - } - - @Test - public void in() throws Exception { - testQuery(title.in(Arrays.asList("jurassic", "park")), "title:jurassic title:park", 1); - testQuery(title.in("jurassic", "park"), "title:jurassic title:park", 1); - testQuery(title.eq("jurassic").or(title.eq("park")), "title:jurassic title:park", 1); - } - - @Test - public void lt() throws Exception { - testQuery(rating.lt("Superb"), "rating:{* TO superb}", 1); - } - - @Test - public void lt_numeric_integer() throws Exception { - testQuery(year.lt(1991), "year:{* TO 1991}", 1); - } - - @Test - public void lt_numeric_double() throws Exception { - testQuery(gross.lt(10000.0), "gross:{* TO 10000.0}", 1); - } - - @Test - public void lt_not_in_range_because_equal() throws Exception { - testQuery(rating.lt("Good"), "rating:{* TO good}", 0); - } - - @Test - public void lt_numeric_integer_not_in_range_because_equal() throws Exception { - testQuery(year.lt(1990), "year:{* TO 1990}", 0); - } - - @Test - public void lt_numeric_double_not_in_range_because_equal() throws Exception { - testQuery(gross.lt(900.0), "gross:{* TO 900.0}", 0); - } - - @Test - public void loe() throws Exception { - testQuery(rating.loe("Superb"), "rating:[* TO superb]", 1); - } - - @Test - public void loe_numeric_integer() throws Exception { - testQuery(year.loe(1991), "year:[* TO 1991]", 1); - } - - @Test - public void loe_numeric_double() throws Exception { - testQuery(gross.loe(903.0), "gross:[* TO 903.0]", 1); - } - - @Test - public void loe_equal() throws Exception { - testQuery(rating.loe("Good"), "rating:[* TO good]", 1); - } - - @Test - public void loe_numeric_integer_equal() throws Exception { - testQuery(year.loe(1990), "year:[* TO 1990]", 1); - } - - @Test - public void loe_numeric_double_equal() throws Exception { - testQuery(gross.loe(900.0), "gross:[* TO 900.0]", 1); - } - - @Test - public void loe_not_found() throws Exception { - testQuery(rating.loe("Bad"), "rating:[* TO bad]", 0); - } - - @Test - public void loe_numeric_integer_not_found() throws Exception { - testQuery(year.loe(1989), "year:[* TO 1989]", 0); - } - - @Test - public void loe_numeric_double_not_found() throws Exception { - testQuery(gross.loe(899.9), "gross:[* TO 899.9]", 0); - } - - @Test - public void gt() throws Exception { - testQuery(rating.gt("Bad"), "rating:{bad TO *}", 1); - } - - @Test - public void gt_numeric_integer() throws Exception { - testQuery(year.gt(1989), "year:{1989 TO *}", 1); - } - - @Test - public void gt_numeric_double() throws Exception { - testQuery(gross.gt(100.00), "gross:{100.0 TO *}", 1); - } - - @Test - public void gt_not_in_range_because_equal() throws Exception { - testQuery(rating.gt("Good"), "rating:{good TO *}", 0); - } - - @Test - public void gt_numeric_integer_not_in_range_because_equal() throws Exception { - testQuery(year.gt(1990), "year:{1990 TO *}", 0); - } - - @Test - public void gt_numeric_double_not_in_range_because_equal() throws Exception { - testQuery(gross.gt(900.00), "gross:{900.0 TO *}", 0); - } - - @Test - public void goe() throws Exception { - testQuery(rating.goe("Bad"), "rating:[bad TO *]", 1); - } - - @Test - public void goe_numeric_integer() throws Exception { - testQuery(year.goe(1989), "year:[1989 TO *]", 1); - } - - @Test - public void goe_numeric_double() throws Exception { - testQuery(gross.goe(320.50), "gross:[320.5 TO *]", 1); - } - - @Test - public void goe_equal() throws Exception { - testQuery(rating.goe("Good"), "rating:[good TO *]", 1); - } - - @Test - public void goe_numeric_integer_equal() throws Exception { - testQuery(year.goe(1990), "year:[1990 TO *]", 1); - } - - @Test - public void goe_numeric_double_equal() throws Exception { - testQuery(gross.goe(900.00), "gross:[900.0 TO *]", 1); - } - - @Test - public void goe_not_found() throws Exception { - testQuery(rating.goe("Hood"), "rating:[hood TO *]", 0); - } - - @Test - public void goe_numeric_integer_not_found() throws Exception { - testQuery(year.goe(1991), "year:[1991 TO *]", 0); - } - - @Test - public void goe_numeric_double_not_found() throws Exception { - testQuery(gross.goe(900.10), "gross:[900.1 TO *]", 0); - } - - @Test - public void equals_empty_string() throws Exception { - testQuery(title.eq(""), "title:", 0); - } - - @Test - public void not_equals_empty_string() throws Exception { - testQuery(title.ne(""), "-title: +*:*", 1); - } - - @Test - public void contains_empty_string() throws Exception { - testQuery(title.contains(""), "title:**", 1); - } - - @Test - public void like_empty_string() throws Exception { - testQuery(title.like(""), "title:", 0); - } - - @Test - public void starts_with_empty_string() throws Exception { - testQuery(title.startsWith(""), "title:*", 1); - } - - @Test - public void ends_with_empty_string() throws Exception { - testQuery(title.endsWith(""), "title:*", 1); - } - - @Test - public void between_empty_strings() throws Exception { - testQuery(title.between("", ""), "title:[ TO ]", 0); - } - - @Test - public void booleanBuilder() throws Exception { - testQuery(new BooleanBuilder(gross.goe(900.10)), "gross:[900.1 TO *]", 0); - } - - @Test - @Ignore - public void fuzzy() throws Exception { - fail("Not yet implemented!"); - } - - @Test - @Ignore - public void proximity() throws Exception { - fail("Not yet implemented!"); - } - - @Test - @Ignore - public void boost() throws Exception { - fail("Not yet implemented!"); - } - - @Test - public void pathAny() throws Exception { - testQuery(titles.any().eq("Jurassic"), "title:jurassic", 1); - } - - private boolean unsupportedOperation(Predicate filter) { - return UNSUPPORTED_OPERATORS.contains(((Operation) filter).getOperator()); - } - - @Test - public void various() throws Exception { - MatchingFiltersFactory filters = - new MatchingFiltersFactory(QuerydslModule.LUCENE, Target.LUCENE); - for (Predicate filter : filters.string(title, StringConstant.create("jurassic park"))) { - if (unsupportedOperation(filter)) { - continue; - } - testQuery(filter, 1); - } - - for (Predicate filter : filters.string(author, StringConstant.create("michael crichton"))) { - if (unsupportedOperation(filter)) { - continue; - } - testQuery(filter, 1); - } - - for (Predicate filter : filters.string(title, StringConstant.create("1990"))) { - if (unsupportedOperation(filter)) { - continue; - } - testQuery(filter, 0); - } - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/Person.java b/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/Person.java deleted file mode 100644 index d201e3c2b5..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/Person.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -import com.querydsl.core.annotations.QueryEntity; -import java.time.LocalDate; - -@QueryEntity -public class Person { - private final String id; - private final String name; - private final LocalDate birthDate; - - public Person(String id, String name, LocalDate birthDate) { - this.id = id; - this.name = name; - this.birthDate = birthDate; - } - - public String getId() { - return id; - } - - public LocalDate getBirthDate() { - return birthDate; - } - - public String getName() { - return name; - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/PhraseElementTest.java b/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/PhraseElementTest.java deleted file mode 100644 index 7c94e762cc..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/PhraseElementTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringPath; -import org.junit.Test; - -public class PhraseElementTest { - - @Test - public void test() { - StringPath title = Expressions.stringPath("title"); - LuceneSerializer serializer = new LuceneSerializer(false, false); - QueryMetadata metadata = new DefaultQueryMetadata(); - assertThat(serializer.toQuery(title.eq("Hello World"), metadata).toString()) - .isEqualTo("title:Hello World"); - assertThat(serializer.toQuery(title.eq(new PhraseElement("Hello World")), metadata).toString()) - .isEqualTo("title:\"Hello World\""); - } - - @Test - public void equals() { - PhraseElement el1 = new PhraseElement("x"), - el2 = new PhraseElement("x"), - el3 = new PhraseElement("y"); - assertThat(el2).isEqualTo(el1); - assertThat(el1.equals(el3)).isFalse(); - } - - @Test - public void hashCode_() { - PhraseElement el1 = new PhraseElement("x"), el2 = new PhraseElement("x"); - assertThat(el2.hashCode()).isEqualTo(el1.hashCode()); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/QDocument.java b/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/QDocument.java deleted file mode 100644 index e55c66f386..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/QDocument.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -import com.querydsl.core.types.PathMetadataFactory; -import com.querydsl.core.types.dsl.EntityPathBase; -import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.StringPath; -import org.apache.lucene.document.Document; - -public class QDocument extends EntityPathBase { - - private static final long serialVersionUID = -4872833626508344081L; - - public QDocument(final String var) { - super(Document.class, PathMetadataFactory.forVariable(var)); - } - - public final NumberPath year = createNumber("year", Integer.class); - - public final StringPath title = createString("title"); - - public final NumberPath gross = createNumber("gross", Double.class); -} diff --git a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/QueryElementTest.java b/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/QueryElementTest.java deleted file mode 100644 index 0049bd96be..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/QueryElementTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.apache.lucene.index.Term; -import org.apache.lucene.search.TermQuery; -import org.junit.Ignore; -import org.junit.Test; - -public class QueryElementTest { - - @Test - @Ignore - public void test() { - QueryElement element = new QueryElement(new TermQuery(new Term("str", "text"))); - assertThat(element.toString()).isEqualTo("str:text"); - // assertEquals(element.getQuery().hashCode(), element.hashCode()); - - QueryElement element2 = new QueryElement(new TermQuery(new Term("str", "text"))); - assertThat(element).isEqualTo(element2); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/TermElementTest.java b/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/TermElementTest.java deleted file mode 100644 index f552069711..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/TermElementTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene4; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringPath; -import org.junit.Test; - -public class TermElementTest { - - @Test - public void test() { - StringPath title = Expressions.stringPath("title"); - LuceneSerializer serializer = new LuceneSerializer(false, true); - QueryMetadata metadata = new DefaultQueryMetadata(); - assertThat(serializer.toQuery(title.eq("Hello World"), metadata).toString()) - .isEqualTo("title:\"Hello World\""); - assertThat(serializer.toQuery(title.eq(new TermElement("Hello World")), metadata).toString()) - .isEqualTo("title:Hello World"); - } - - @Test - public void testEqualsAndHashCode() { - TermElement el1 = new TermElement("x"), el2 = new TermElement("x"), el3 = new TermElement("y"); - assertThat(el2).isEqualTo(el1); - assertThat(el1.equals(el3)).isFalse(); - assertThat(el2.hashCode()).isEqualTo(el1.hashCode()); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/test/resources/log4j.properties.example b/querydsl-libraries/querydsl-lucene4/src/test/resources/log4j.properties.example deleted file mode 100644 index 50eef686c1..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/test/resources/log4j.properties.example +++ /dev/null @@ -1,9 +0,0 @@ -# Configure an appender that logs to console -log4j.rootLogger=info, A1 -log4j.threshold=debug -log4j.appender.A1=org.apache.log4j.ConsoleAppender -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c{1} - %m%n - -# Configuration of logging levels for different packages -log4j.logger.com.querydsl.lucene4=DEBUG diff --git a/querydsl-libraries/querydsl-lucene5/README.md b/querydsl-libraries/querydsl-lucene5/README.md deleted file mode 100644 index 3bcd908515..0000000000 --- a/querydsl-libraries/querydsl-lucene5/README.md +++ /dev/null @@ -1,57 +0,0 @@ -## Querydsl Lucene 5 - -The Lucene module provides integration with the Lucene 5 indexing library. - -**Maven integration** - - Add the following dependencies to your Maven project : -```XML - - io.github.openfeign.querydsl - querydsl-lucene5 - ${querydsl.version} - -``` - -**Creating the query types** - -With fields year and title a manually created query type could look something like this: - -```JAVA -public class QDocument extends EntityPathBase{ - private static final long serialVersionUID = -4872833626508344081L; - - public QDocument(String var) { - super(Document.class, PathMetadataFactory.forVariable(var)); - } - - public final StringPath year = createString("year"); - - public final StringPath title = createString("title"); -} -``` - -QDocument represents a Lucene document with the fields year and title. - -Code generation is not available for Lucene, since no schema data is available. - -**Querying** - -Querying with Querydsl Lucene is as simple as this: - -```JAVA -QDocument doc = new QDocument("doc"); - -IndexSearcher searcher = new IndexSearcher(index); -LuceneQuery query = new LuceneQuery(true, searcher); -List documents = query - .where(doc.year.between("1800", "2000").and(doc.title.startsWith("Huckle")) - .fetch(); -``` - -which is transformed into the following Lucene query : -``` -+year:[1800 TO 2000] +title:huckle* -``` - -For more information on the Querydsl Lucene module visit the reference documentation http://www.querydsl.com/static/querydsl/latest/reference/html/ch02s05.html diff --git a/querydsl-libraries/querydsl-lucene5/pom.xml b/querydsl-libraries/querydsl-lucene5/pom.xml deleted file mode 100644 index 53134d5322..0000000000 --- a/querydsl-libraries/querydsl-lucene5/pom.xml +++ /dev/null @@ -1,104 +0,0 @@ - - - 4.0.0 - - - io.github.openfeign.querydsl - querydsl-libraries - 6.0-SNAPSHOT - - - querydsl-lucene5 - Querydsl - Lucene 5 support - Lucene support for Querydsl - - - 5.5.5 - org.apache.lucene.*;version="[5.1.0,6)", - ${osgi.import.package.root} - - - - - org.jetbrains - annotations - provided - - - org.apache.lucene - lucene-core - ${lucene.version} - provided - - - org.apache.lucene - lucene-analyzers-common - ${lucene.version} - provided - - - org.apache.lucene - lucene-queryparser - ${lucene.version} - provided - - - org.apache.lucene - lucene-queries - ${lucene.version} - provided - - - io.github.openfeign.querydsl - querydsl-core - ${project.version} - - - - - io.github.openfeign.querydsl - querydsl-core - ${project.version} - test-jar - test - - - - io.github.openfeign.querydsl - querydsl-apt - ${project.version} - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.3.0 - - - - com.querydsl.lucene5 - - - - - - - org.apache.felix - maven-bundle-plugin - - - - org.apache.maven.plugins - maven-compiler-plugin - - - com.querydsl.apt.QuerydslAnnotationProcessor - - - - - - diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/AbstractLuceneQuery.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/AbstractLuceneQuery.java deleted file mode 100644 index 1a9159f651..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/AbstractLuceneQuery.java +++ /dev/null @@ -1,395 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -import com.mysema.commons.lang.CloseableIterator; -import com.mysema.commons.lang.EmptyCloseableIterator; -import com.mysema.commons.lang.IteratorAdapter; -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.Fetchable; -import com.querydsl.core.NonUniqueResultException; -import com.querydsl.core.QueryException; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.QueryModifiers; -import com.querydsl.core.QueryResults; -import com.querydsl.core.SimpleQuery; -import com.querydsl.core.support.QueryMixin; -import com.querydsl.core.types.OrderSpecifier; -import com.querydsl.core.types.ParamExpression; -import com.querydsl.core.types.Path; -import com.querydsl.core.types.Predicate; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.sandbox.queries.DuplicateFilter; -import org.apache.lucene.search.BooleanClause.Occur; -import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.Filter; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.QueryWrapperFilter; -import org.apache.lucene.search.ScoreDoc; -import org.apache.lucene.search.Sort; -import org.apache.lucene.search.TotalHitCountCollector; -import org.jetbrains.annotations.Nullable; - -/** - * AbstractLuceneQuery is an abstract super class for Lucene query implementations - * - * @author tiwe - * @param projection type - * @param concrete subtype of querydsl - */ -public abstract class AbstractLuceneQuery> - implements SimpleQuery, Fetchable { - - private static final String JAVA_ISO_CONTROL = "[\\p{Cntrl}&&[^\r\n\t]]"; - - private final QueryMixin queryMixin; - - private final IndexSearcher searcher; - - private final LuceneSerializer serializer; - - private final Function transformer; - - @Nullable private Set fieldsToLoad; - - private List filters = Collections.emptyList(); - - @Nullable private Filter filter; - - @Nullable private Sort querySort; - - @SuppressWarnings("unchecked") - public AbstractLuceneQuery( - LuceneSerializer serializer, IndexSearcher searcher, Function transformer) { - queryMixin = new QueryMixin((Q) this, new DefaultQueryMetadata()); - this.serializer = serializer; - this.searcher = searcher; - this.transformer = transformer; - } - - public AbstractLuceneQuery(IndexSearcher searcher, Function transformer) { - this(LuceneSerializer.DEFAULT, searcher, transformer); - } - - private long innerCount() { - try { - final int maxDoc = searcher.getIndexReader().maxDoc(); - if (maxDoc == 0) { - return 0; - } - TotalHitCountCollector collector = new TotalHitCountCollector(); - searcher.search(createQuery(), getFilter(), collector); - return collector.getTotalHits(); - } catch (IOException | IllegalArgumentException e) { - throw new QueryException(e); - } - } - - @Override - public long fetchCount() { - return innerCount(); - } - - protected Query createQuery() { - Query returnedQuery = null; - Query originalQuery = null; - if (queryMixin.getMetadata().getWhere() == null) { - originalQuery = new MatchAllDocsQuery(); - } else { - originalQuery = - serializer.toQuery(queryMixin.getMetadata().getWhere(), queryMixin.getMetadata()); - } - Filter filter = getFilter(); - if (filter != null) { - BooleanQuery booleanQuery = new BooleanQuery(); - booleanQuery.add(originalQuery, Occur.MUST); - booleanQuery.add(filter, Occur.FILTER); - returnedQuery = booleanQuery; - } else { - returnedQuery = originalQuery; - } - - return returnedQuery; - } - - /** - * Create a filter for constraints defined in this querydsl - * - * @return filter - */ - public Filter asFilter() { - return new QueryWrapperFilter(createQuery()); - } - - @Override - public Q distinct() { - throw new UnsupportedOperationException("use distinct(path) instead"); - } - - /** - * Add a DuplicateFilter for the field of the given property path - * - * @param property distinct property - * @return the current object - */ - public Q distinct(Path property) { - return filter(new DuplicateFilter(serializer.toField(property))); - } - - /** - * Apply the given Lucene filter to the search results - * - * @param filter filter - * @return the current object - */ - @SuppressWarnings("unchecked") - public Q filter(Filter filter) { - if (filters.isEmpty()) { - this.filter = filter; - filters = Collections.singletonList(filter); - } else { - this.filter = null; - if (filters.size() == 1) { - filters = new ArrayList(); - } - filters.add(filter); - } - return (Q) this; - } - - private Filter getFilter() { - if (filter == null && !filters.isEmpty()) { - BooleanQuery filterQuery = new BooleanQuery(); - for (Filter filter : filters) { - filterQuery.add(filter, Occur.SHOULD); - } - filter = new QueryWrapperFilter(filterQuery); - } - return filter; - } - - @Override - public Q limit(long limit) { - return queryMixin.limit(limit); - } - - @Override - public CloseableIterator iterate() { - final QueryMetadata metadata = queryMixin.getMetadata(); - final List> orderBys = metadata.getOrderBy(); - final Integer queryLimit = metadata.getModifiers().getLimitAsInteger(); - final Integer queryOffset = metadata.getModifiers().getOffsetAsInteger(); - Sort sort = querySort; - int limit; - final int offset = queryOffset != null ? queryOffset : 0; - try { - limit = maxDoc(); - if (limit == 0) { - return new EmptyCloseableIterator(); - } - } catch (IOException | IllegalArgumentException e) { - throw new QueryException(e); - } - if (queryLimit != null && queryLimit < limit) { - limit = queryLimit; - } - if (sort == null && !orderBys.isEmpty()) { - sort = serializer.toSort(orderBys); - } - - try { - ScoreDoc[] scoreDocs; - int sumOfLimitAndOffset = limit + offset; - if (sumOfLimitAndOffset < 1) { - throw new QueryException( - "The given limit (" - + limit - + ") and offset (" - + offset - + ") cause an integer overflow."); - } - if (sort != null) { - scoreDocs = - searcher.search( - createQuery(), - // sumOfLimitAndOffset).scoreDocs; - sumOfLimitAndOffset, - sort, - false, - false) - .scoreDocs; - } else { - scoreDocs = - searcher.search(createQuery(), sumOfLimitAndOffset, Sort.INDEXORDER, false, false) - .scoreDocs; - } - if (offset < scoreDocs.length) { - return new ResultIterator(scoreDocs, offset, searcher, fieldsToLoad, transformer); - } - return new EmptyCloseableIterator(); - } catch (final IOException e) { - throw new QueryException(e); - } - } - - private List innerList() { - return new IteratorAdapter(iterate()).asList(); - } - - @Override - public List fetch() { - return innerList(); - } - - /** - * Set the given fields to load - * - * @param fieldsToLoad fields to load - * @return the current object - */ - @SuppressWarnings("unchecked") - public Q load(Set fieldsToLoad) { - this.fieldsToLoad = fieldsToLoad; - return (Q) this; - } - - /** - * Load only the fields of the given paths - * - * @param paths fields to load - * @return the current object - */ - @SuppressWarnings("unchecked") - public Q load(Path... paths) { - Set fields = new HashSet(); - for (Path path : paths) { - fields.add(serializer.toField(path)); - } - this.fieldsToLoad = fields; - return (Q) this; - } - - @Override - public QueryResults fetchResults() { - List documents = innerList(); - /* - * TODO Get rid of fetchCount(). It could be implemented by iterating - * the fetch results in fetch* from n to m. - */ - return new QueryResults(documents, queryMixin.getMetadata().getModifiers(), innerCount()); - } - - @Override - public Q offset(long offset) { - return queryMixin.offset(offset); - } - - public Q orderBy(OrderSpecifier o) { - return queryMixin.orderBy(o); - } - - @Override - public Q orderBy(OrderSpecifier... o) { - return queryMixin.orderBy(o); - } - - @Override - public Q restrict(QueryModifiers modifiers) { - return queryMixin.restrict(modifiers); - } - - @Override - public

Q set(ParamExpression

param, P value) { - return queryMixin.set(param, value); - } - - @SuppressWarnings("unchecked") - public Q sort(Sort sort) { - this.querySort = sort; - return (Q) this; - } - - @Nullable - private T oneResult(boolean unique) { - try { - int maxDoc = maxDoc(); - if (maxDoc == 0) { - return null; - } - final ScoreDoc[] scoreDocs = - searcher.search(createQuery(), maxDoc, Sort.INDEXORDER, false, false).scoreDocs; - int index = 0; - QueryModifiers modifiers = queryMixin.getMetadata().getModifiers(); - Long offset = modifiers.getOffset(); - if (offset != null) { - index = offset.intValue(); - } - Long limit = modifiers.getLimit(); - if (unique - && (limit == null ? scoreDocs.length - index > 1 : limit > 1 && scoreDocs.length > 1)) { - throw new NonUniqueResultException( - "Unique result requested, but " + scoreDocs.length + " found."); - } else if (scoreDocs.length > index) { - Document document; - if (fieldsToLoad != null) { - document = searcher.doc(scoreDocs[index].doc, fieldsToLoad); - } else { - document = searcher.doc(scoreDocs[index].doc); - } - return transformer.apply(document); - } else { - return null; - } - } catch (IOException | IllegalArgumentException e) { - throw new QueryException(e); - } - } - - @Override - public T fetchFirst() { - return oneResult(false); - } - - @Override - public T fetchOne() throws NonUniqueResultException { - return oneResult(true); - } - - public Q where(Predicate e) { - return queryMixin.where(e); - } - - @Override - public Q where(Predicate... e) { - return queryMixin.where(e); - } - - @Override - public String toString() { - return createQuery().toString().replaceAll(JAVA_ISO_CONTROL, "_"); - } - - private int maxDoc() throws IOException { - return searcher.getIndexReader().maxDoc(); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/IgnoreCaseUnsupportedException.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/IgnoreCaseUnsupportedException.java deleted file mode 100644 index de7c597b38..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/IgnoreCaseUnsupportedException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -/** - * Thrown for case ignore usage - * - * @author tiwe - */ -public class IgnoreCaseUnsupportedException extends UnsupportedOperationException { - - private static final long serialVersionUID = 412913389929530788L; - - public IgnoreCaseUnsupportedException() { - super("Ignore case queries are not supported with Lucene"); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneExpressions.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneExpressions.java deleted file mode 100644 index a1bc496729..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneExpressions.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -import com.querydsl.core.types.Path; -import com.querydsl.core.types.dsl.BooleanExpression; -import org.apache.lucene.index.Term; -import org.apache.lucene.search.FuzzyQuery; -import org.apache.lucene.util.automaton.LevenshteinAutomata; - -/** - * Utility methods to create filter expressions for Lucene queries that are not covered by the - * Querydsl standard expression model - * - * @author tiwe - */ -public final class LuceneExpressions { - - /** - * Create a fuzzy query - * - * @param path path - * @param value value to match - * @return condition - */ - public static BooleanExpression fuzzyLike(Path path, String value) { - Term term = new Term(path.getMetadata().getName(), value); - return new QueryElement(new FuzzyQuery(term)); - } - - /** - * Create a fuzzy query - * - * @param path path - * @param value value to match - * @param maxEdits must be >= 0 and <= {@link - * LevenshteinAutomata#MAXIMUM_SUPPORTED_DISTANCE}. - * @return condition - */ - public static BooleanExpression fuzzyLike(Path path, String value, int maxEdits) { - Term term = new Term(path.getMetadata().getName(), value); - return new QueryElement(new FuzzyQuery(term, maxEdits)); - } - - /** - * Create a fuzzy query - * - * @param path path - * @param value value to match - * @param maxEdits must be >= 0 and <= {@link - * LevenshteinAutomata#MAXIMUM_SUPPORTED_DISTANCE}. - * @param prefixLength length of common (non-fuzzy) prefix - * @return condition - */ - public static BooleanExpression fuzzyLike( - Path path, String value, int maxEdits, int prefixLength) { - Term term = new Term(path.getMetadata().getName(), value); - return new QueryElement(new FuzzyQuery(term, maxEdits, prefixLength)); - } - - private LuceneExpressions() {} -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneOps.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneOps.java deleted file mode 100644 index 375316fe25..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneOps.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -import com.querydsl.core.types.Operator; - -/** - * Lucene specific operators - * - * @author tiwe - */ -public enum LuceneOps implements Operator { - LUCENE_QUERY(Object.class), - PHRASE(String.class), - TERM(String.class); - - private final Class type; - - LuceneOps(Class type) { - this.type = type; - } - - @Override - public Class getType() { - return type; - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneQuery.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneQuery.java deleted file mode 100644 index 9c7fa0431c..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneQuery.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.search.IndexSearcher; - -/** - * {@code LuceneQuery} is a Querydsl query implementation for Lucene queries. - * - *

Example: - * - *

{@code
- * QDocument doc = new QDocument("doc");
- * IndexSearcher searcher = new IndexSearcher(index);
- * LuceneQuery query = new LuceneQuery(true, searcher);
- * List documents = query
- *     .where(doc.year.between("1800", "2000").and(doc.title.startsWith("Huckle"))
- *     .fetch();
- * }
- * - * @author vema - */ -public class LuceneQuery extends AbstractLuceneQuery { - - private static final Function TRANSFORMER = - new Function() { - @Override - public Document apply(Document input) { - return input; - } - }; - - public LuceneQuery(IndexSearcher searcher) { - super(searcher, TRANSFORMER); - } - - public LuceneQuery(LuceneSerializer luceneSerializer, IndexSearcher searcher) { - super(luceneSerializer, searcher, TRANSFORMER); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneSerializer.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneSerializer.java deleted file mode 100644 index 2601e07f8a..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneSerializer.java +++ /dev/null @@ -1,580 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.Constant; -import com.querydsl.core.types.Expression; -import com.querydsl.core.types.ExpressionUtils; -import com.querydsl.core.types.Operation; -import com.querydsl.core.types.Operator; -import com.querydsl.core.types.Ops; -import com.querydsl.core.types.OrderSpecifier; -import com.querydsl.core.types.ParamExpression; -import com.querydsl.core.types.ParamNotSetException; -import com.querydsl.core.types.Path; -import com.querydsl.core.types.PathMetadata; -import com.querydsl.core.types.PathType; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import org.apache.lucene.index.Term; -import org.apache.lucene.queryparser.classic.QueryParser; -import org.apache.lucene.search.BooleanClause; -import org.apache.lucene.search.BooleanClause.Occur; -import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.NumericRangeQuery; -import org.apache.lucene.search.PhraseQuery; -import org.apache.lucene.search.PrefixQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.Sort; -import org.apache.lucene.search.SortField; -import org.apache.lucene.search.SortedNumericSortField; -import org.apache.lucene.search.TermQuery; -import org.apache.lucene.search.TermRangeQuery; -import org.apache.lucene.search.WildcardQuery; -import org.apache.lucene.util.BytesRef; -import org.apache.lucene.util.BytesRefBuilder; -import org.apache.lucene.util.NumericUtils; -import org.jetbrains.annotations.Nullable; - -/** - * Serializes Querydsl queries to Lucene queries. - * - * @author vema - */ -public class LuceneSerializer { - private static final Map, SortField.Type> sortFields = - new HashMap, SortField.Type>(); - - static { - sortFields.put(Integer.class, SortField.Type.INT); - sortFields.put(Float.class, SortField.Type.FLOAT); - sortFields.put(Long.class, SortField.Type.LONG); - sortFields.put(Double.class, SortField.Type.DOUBLE); - sortFields.put(BigDecimal.class, SortField.Type.DOUBLE); - sortFields.put(BigInteger.class, SortField.Type.LONG); - } - - public static final LuceneSerializer DEFAULT = new LuceneSerializer(false, true); - - private final boolean lowerCase; - - private final boolean splitTerms; - - private final Locale sortLocale; - - public LuceneSerializer(boolean lowerCase, boolean splitTerms) { - this(lowerCase, splitTerms, Locale.getDefault()); - } - - public LuceneSerializer(boolean lowerCase, boolean splitTerms, Locale sortLocale) { - this.lowerCase = lowerCase; - this.splitTerms = splitTerms; - this.sortLocale = sortLocale; - } - - private Query toQuery(Operation operation, QueryMetadata metadata) { - Operator op = operation.getOperator(); - if (op == Ops.OR) { - return toTwoHandSidedQuery(operation, Occur.SHOULD, metadata); - } else if (op == Ops.AND) { - return toTwoHandSidedQuery(operation, Occur.MUST, metadata); - } else if (op == Ops.NOT) { - BooleanQuery bq = new BooleanQuery(); - bq.add(new BooleanClause(toQuery(operation.getArg(0), metadata), Occur.MUST_NOT)); - bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); - return bq; - } else if (op == Ops.LIKE) { - return like(operation, metadata); - } else if (op == Ops.LIKE_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.EQ) { - return eq(operation, metadata, false); - } else if (op == Ops.EQ_IGNORE_CASE) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.NE) { - return ne(operation, metadata, false); - } else if (op == Ops.STARTS_WITH) { - return startsWith(metadata, operation, false); - } else if (op == Ops.STARTS_WITH_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.ENDS_WITH) { - return endsWith(operation, metadata, false); - } else if (op == Ops.ENDS_WITH_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.STRING_CONTAINS) { - return stringContains(operation, metadata, false); - } else if (op == Ops.STRING_CONTAINS_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.BETWEEN) { - return between(operation, metadata); - } else if (op == Ops.IN) { - return in(operation, metadata, false); - } else if (op == Ops.NOT_IN) { - return notIn(operation, metadata, false); - } else if (op == Ops.LT) { - return lt(operation, metadata); - } else if (op == Ops.GT) { - return gt(operation, metadata); - } else if (op == Ops.LOE) { - return le(operation, metadata); - } else if (op == Ops.GOE) { - return ge(operation, metadata); - } else if (op == LuceneOps.LUCENE_QUERY) { - @SuppressWarnings("unchecked") - // this is the expected type - Constant expectedConstant = (Constant) operation.getArg(0); - return expectedConstant.getConstant(); - } - throw new UnsupportedOperationException("Illegal operation " + operation); - } - - private Query toTwoHandSidedQuery(Operation operation, Occur occur, QueryMetadata metadata) { - Query lhs = toQuery(operation.getArg(0), metadata); - Query rhs = toQuery(operation.getArg(1), metadata); - BooleanQuery bq = new BooleanQuery(); - bq.add(createBooleanClause(lhs, occur)); - bq.add(createBooleanClause(rhs, occur)); - return bq; - } - - /** - * If the query is a BooleanQuery and it contains a single Occur.MUST_NOT clause it will be - * returned as is. Otherwise it will be wrapped in a BooleanClause with the given Occur. - */ - private BooleanClause createBooleanClause(Query query, Occur occur) { - if (query instanceof BooleanQuery) { - BooleanClause[] clauses = ((BooleanQuery) query).getClauses(); - if (clauses.length == 1 && clauses[0].getOccur().equals(Occur.MUST_NOT)) { - return clauses[0]; - } - } - return new BooleanClause(query, occur); - } - - protected Query like(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convert(path, operation.getArg(1)); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (String s : terms) { - bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST); - } - return bq; - } - return new WildcardQuery(new Term(field, terms[0])); - } - - protected Query eq(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - - if (Number.class.isAssignableFrom(operation.getArg(1).getType())) { - @SuppressWarnings("unchecked") - // guarded by previous check - Constant rightArg = (Constant) operation.getArg(1); - return new TermQuery(new Term(field, convertNumber(rightArg.getConstant()))); - } - - return eq(field, convert(path, operation.getArg(1), metadata), ignoreCase); - } - - private BytesRef convertNumber(Number number) { - if (Integer.class.isInstance(number) - || Byte.class.isInstance(number) - || Short.class.isInstance(number)) { - BytesRefBuilder ref = new BytesRefBuilder(); - NumericUtils.intToPrefixCoded(number.intValue(), 0, ref); - return ref.get(); - } else if (Double.class.isInstance(number) || BigDecimal.class.isInstance(number)) { - BytesRefBuilder ref = new BytesRefBuilder(); - long l = NumericUtils.doubleToSortableLong(number.doubleValue()); - NumericUtils.longToPrefixCoded(l, 0, ref); - return ref.get(); - } else if (Long.class.isInstance(number) || BigInteger.class.isInstance(number)) { - BytesRefBuilder ref = new BytesRefBuilder(); - NumericUtils.longToPrefixCoded(number.longValue(), 0, ref); - return ref.get(); - } else if (Float.class.isInstance(number)) { - BytesRefBuilder ref = new BytesRefBuilder(); - int i = NumericUtils.floatToSortableInt(number.floatValue()); - NumericUtils.intToPrefixCoded(i, 0, ref); - return ref.get(); - } else { - throw new IllegalArgumentException("Unsupported numeric type " + number.getClass().getName()); - } - } - - protected Query eq(String field, String[] terms, boolean ignoreCase) { - if (terms.length > 1) { - PhraseQuery pq = new PhraseQuery(); - for (String s : terms) { - pq.add(new Term(field, s)); - } - return pq; - } - return new TermQuery(new Term(field, terms[0])); - } - - protected Query in(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - Path path = getPath(operation.getArg(0)); - String field = toField(path); - @SuppressWarnings("unchecked") - // this is the expected type - Constant> expectedConstant = (Constant>) operation.getArg(1); - Collection values = expectedConstant.getConstant(); - BooleanQuery bq = new BooleanQuery(); - if (Number.class.isAssignableFrom(path.getType())) { - for (Object value : values) { - TermQuery eq = new TermQuery(new Term(field, convertNumber((Number) value))); - bq.add(eq, Occur.SHOULD); - } - } else { - for (Object value : values) { - String[] str = convert(path, value); - bq.add(eq(field, str, ignoreCase), Occur.SHOULD); - } - } - return bq; - } - - protected Query notIn(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - BooleanQuery bq = new BooleanQuery(); - bq.add(new BooleanClause(in(operation, metadata, false), Occur.MUST_NOT)); - bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); - return bq; - } - - protected Query ne(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - BooleanQuery bq = new BooleanQuery(); - bq.add(new BooleanClause(eq(operation, metadata, ignoreCase), Occur.MUST_NOT)); - bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); - return bq; - } - - protected Query startsWith(QueryMetadata metadata, Operation operation, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convertEscaped(path, operation.getArg(1), metadata); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (int i = 0; i < terms.length; ++i) { - String s = i == 0 ? terms[i] + "*" : "*" + terms[i] + "*"; - bq.add(new WildcardQuery(new Term(field, s)), Occur.MUST); - } - return bq; - } - return new PrefixQuery(new Term(field, terms[0])); - } - - protected Query stringContains( - Operation operation, QueryMetadata metadata, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convertEscaped(path, operation.getArg(1), metadata); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (String s : terms) { - bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST); - } - return bq; - } - return new WildcardQuery(new Term(field, "*" + terms[0] + "*")); - } - - protected Query endsWith(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convertEscaped(path, operation.getArg(1), metadata); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (int i = 0; i < terms.length; ++i) { - String s = i == terms.length - 1 ? "*" + terms[i] : "*" + terms[i] + "*"; - bq.add(new WildcardQuery(new Term(field, s)), Occur.MUST); - } - return bq; - } - return new WildcardQuery(new Term(field, "*" + terms[0])); - } - - protected Query between(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - // TODO Phrase not properly supported - return range( - path, toField(path), operation.getArg(1), operation.getArg(2), true, true, metadata); - } - - protected Query lt(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), null, operation.getArg(1), false, false, metadata); - } - - protected Query gt(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), operation.getArg(1), null, false, false, metadata); - } - - protected Query le(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), null, operation.getArg(1), true, true, metadata); - } - - protected Query ge(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), operation.getArg(1), null, true, true, metadata); - } - - protected Query range( - Path leftHandSide, - String field, - @Nullable Expression min, - @Nullable Expression max, - boolean minInc, - boolean maxInc, - QueryMetadata metadata) { - if (min != null && Number.class.isAssignableFrom(min.getType()) - || max != null && Number.class.isAssignableFrom(max.getType())) { - @SuppressWarnings("unchecked") - // guarded by previous check - Constant minConstant = (Constant) min; - @SuppressWarnings("unchecked") - // guarded by previous check - Constant maxConstant = (Constant) max; - - Class numType = - minConstant != null ? minConstant.getType() : maxConstant.getType(); - // this is not necessarily safe, but compile time checking - // on the user side mandates these types to be interchangeable - @SuppressWarnings("unchecked") - Class unboundedNumType = (Class) numType; - return numericRange( - unboundedNumType, - field, - minConstant == null ? null : minConstant.getConstant(), - maxConstant == null ? null : maxConstant.getConstant(), - minInc, - maxInc); - } - return stringRange(leftHandSide, field, min, max, minInc, maxInc, metadata); - } - - protected NumericRangeQuery numericRange( - Class clazz, - String field, - @Nullable N min, - @Nullable N max, - boolean minInc, - boolean maxInc) { - if (clazz.equals(Integer.class)) { - return NumericRangeQuery.newIntRange(field, (Integer) min, (Integer) max, minInc, maxInc); - } else if (clazz.equals(Double.class)) { - return NumericRangeQuery.newDoubleRange(field, (Double) min, (Double) max, minInc, minInc); - } else if (clazz.equals(Float.class)) { - return NumericRangeQuery.newFloatRange(field, (Float) min, (Float) max, minInc, minInc); - } else if (clazz.equals(Long.class)) { - return NumericRangeQuery.newLongRange(field, (Long) min, (Long) max, minInc, minInc); - } else if (clazz.equals(Byte.class) || clazz.equals(Short.class)) { - return NumericRangeQuery.newIntRange( - field, - min != null ? min.intValue() : null, - max != null ? max.intValue() : null, - minInc, - maxInc); - } else { - throw new IllegalArgumentException("Unsupported numeric type " + clazz.getName()); - } - } - - protected Query stringRange( - Path leftHandSide, - String field, - @Nullable Expression min, - @Nullable Expression max, - boolean minInc, - boolean maxInc, - QueryMetadata metadata) { - - if (min == null) { - return TermRangeQuery.newStringRange( - field, null, convert(leftHandSide, max, metadata)[0], minInc, maxInc); - } else if (max == null) { - return TermRangeQuery.newStringRange( - field, convert(leftHandSide, min, metadata)[0], null, minInc, maxInc); - } else { - return TermRangeQuery.newStringRange( - field, - convert(leftHandSide, min, metadata)[0], - convert(leftHandSide, max, metadata)[0], - minInc, - maxInc); - } - } - - private Path getPath(Expression leftHandSide) { - if (leftHandSide instanceof Path) { - return (Path) leftHandSide; - } else if (leftHandSide instanceof Operation) { - Operation operation = (Operation) leftHandSide; - if (operation.getOperator() == Ops.LOWER || operation.getOperator() == Ops.UPPER) { - return (Path) operation.getArg(0); - } - } - throw new IllegalArgumentException("Unable to transform " + leftHandSide + " to path"); - } - - /** - * template method, override to customize - * - * @param path path - * @return field name - */ - protected String toField(Path path) { - PathMetadata md = path.getMetadata(); - if (md.getPathType() == PathType.COLLECTION_ANY) { - return toField(md.getParent()); - } else { - String rv = md.getName(); - if (md.getParent() != null) { - Path parent = md.getParent(); - if (parent.getMetadata().getPathType() != PathType.VARIABLE) { - rv = toField(parent) + "." + rv; - } - } - return rv; - } - } - - private void verifyArguments(Operation operation) { - List> arguments = operation.getArgs(); - for (int i = 1; i < arguments.size(); ++i) { - if (!(arguments.get(i) instanceof Constant) - && !(arguments.get(i) instanceof ParamExpression) - && !(arguments.get(i) instanceof PhraseElement) - && !(arguments.get(i) instanceof TermElement)) { - throw new IllegalArgumentException( - "operand was of unsupported type " + arguments.get(i).getClass().getName()); - } - } - } - - /** - * template method - * - * @param leftHandSide left hand side - * @param rightHandSide right hand side - * @return results - */ - protected String[] convert( - Path leftHandSide, Expression rightHandSide, QueryMetadata metadata) { - if (rightHandSide instanceof Operation) { - Operation operation = (Operation) rightHandSide; - if (operation.getOperator() == LuceneOps.PHRASE) { - return operation.getArg(0).toString().split("\\s+"); - } else if (operation.getOperator() == LuceneOps.TERM) { - return new String[] {operation.getArg(0).toString()}; - } else { - throw new IllegalArgumentException(rightHandSide.toString()); - } - } else if (rightHandSide instanceof ParamExpression) { - Object value = metadata.getParams().get(rightHandSide); - if (value == null) { - throw new ParamNotSetException((ParamExpression) rightHandSide); - } - return convert(leftHandSide, value); - - } else if (rightHandSide instanceof Constant) { - return convert(leftHandSide, ((Constant) rightHandSide).getConstant()); - } else { - throw new IllegalArgumentException(rightHandSide.toString()); - } - } - - /** - * template method - * - * @param leftHandSide left hand side - * @param rightHandSide right hand side - * @return results - */ - protected String[] convert(Path leftHandSide, Object rightHandSide) { - String str = rightHandSide.toString(); - if (lowerCase) { - str = str.toLowerCase(); - } - if (splitTerms) { - if (str.equals("")) { - return new String[] {str}; - } else { - return str.split("\\s+"); - } - } else { - return new String[] {str}; - } - } - - private String[] convertEscaped( - Path leftHandSide, Expression rightHandSide, QueryMetadata metadata) { - String[] str = convert(leftHandSide, rightHandSide, metadata); - for (int i = 0; i < str.length; i++) { - str[i] = QueryParser.escape(str[i]); - } - return str; - } - - public Query toQuery(Expression expr, QueryMetadata metadata) { - if (expr instanceof Operation) { - return toQuery((Operation) expr, metadata); - } else { - return toQuery(ExpressionUtils.extract(expr), metadata); - } - } - - public Sort toSort(List> orderBys) { - List sorts = new ArrayList(orderBys.size()); - for (OrderSpecifier order : orderBys) { - if (!(order.getTarget() instanceof Path)) { - throw new IllegalArgumentException("argument was not of type Path."); - } - Class type = order.getTarget().getType(); - boolean reverse = !order.isAscending(); - Path path = getPath(order.getTarget()); - if (Number.class.isAssignableFrom(type)) { - sorts.add(new SortedNumericSortField(toField(path), sortFields.get(type), reverse)); - } else { - sorts.add(new SortField(toField(path), SortField.Type.STRING, reverse)); - } - } - Sort sort = new Sort(); - sort.setSort(sorts.toArray(new SortField[0])); - return sort; - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/PhraseElement.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/PhraseElement.java deleted file mode 100644 index b41cc8b839..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/PhraseElement.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.dsl.StringOperation; - -/** - * {@code PhraseElement} represents the embedded String as a phrase - * - * @author tiwe - */ -public class PhraseElement extends StringOperation { - - private static final long serialVersionUID = 2350215644019186076L; - - public PhraseElement(String str) { - super(LuceneOps.PHRASE, ConstantImpl.create(str)); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/QueryElement.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/QueryElement.java deleted file mode 100644 index 33d2c781b6..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/QueryElement.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.dsl.BooleanOperation; -import org.apache.lucene.search.Query; - -/** - * {@code QueryElement} wraps a Lucene Query - * - * @author tiwe - */ -public class QueryElement extends BooleanOperation { - - private static final long serialVersionUID = 470868107363840155L; - - public QueryElement(Query query) { - super(LuceneOps.LUCENE_QUERY, ConstantImpl.create(query)); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/ResultIterator.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/ResultIterator.java deleted file mode 100644 index 42fe409577..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/ResultIterator.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -import com.mysema.commons.lang.CloseableIterator; -import com.querydsl.core.QueryException; -import java.io.IOException; -import java.util.Set; -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.ScoreDoc; -import org.jetbrains.annotations.Nullable; - -/** - * {@code ResultIterator} is a {@link CloseableIterator} implementation for Lucene query results - * - * @author tiwe - * @param - */ -public final class ResultIterator implements CloseableIterator { - - private final ScoreDoc[] scoreDocs; - - private int cursor; - - private final IndexSearcher searcher; - - @Nullable private final Set fieldsToLoad; - - private final Function transformer; - - public ResultIterator( - ScoreDoc[] scoreDocs, - int offset, - IndexSearcher searcher, - @Nullable Set fieldsToLoad, - Function transformer) { - this.scoreDocs = scoreDocs.clone(); - this.cursor = offset; - this.searcher = searcher; - this.fieldsToLoad = fieldsToLoad; - this.transformer = transformer; - } - - @Override - public boolean hasNext() { - return cursor != scoreDocs.length; - } - - @Override - public T next() { - try { - Document document; - if (fieldsToLoad != null) { - document = searcher.doc(scoreDocs[cursor++].doc, fieldsToLoad); - } else { - document = searcher.doc(scoreDocs[cursor++].doc); - } - return transformer.apply(document); - } catch (IOException e) { - throw new QueryException(e); - } - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - @Override - public void close() {} -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/TermElement.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/TermElement.java deleted file mode 100644 index c5264f9740..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/TermElement.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.dsl.StringOperation; - -/** - * {@code TermElement} represents the embedded String as a term - * - * @author tiwe - */ -public class TermElement extends StringOperation { - - private static final long serialVersionUID = 2350215644019186076L; - - public TermElement(String str) { - super(LuceneOps.TERM, ConstantImpl.create(str)); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/TypedQuery.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/TypedQuery.java deleted file mode 100644 index acbc62b12c..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/TypedQuery.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.search.IndexSearcher; - -/** - * {@code TypedQuery} is a typed query implementation for Lucene queries. - * - *

Converts Lucene documents to typed results via a constructor supplied transformer - * - * @param result type - * @author laim - * @author tiwe - */ -public class TypedQuery extends AbstractLuceneQuery> { - - /** - * Create a new TypedQuery instance - * - * @param searcher index searcher - * @param transformer transformer to transform Lucene documents to result objects - */ - public TypedQuery(IndexSearcher searcher, Function transformer) { - super(searcher, transformer); - } - - /** - * Create a new TypedQuery instance - * - * @param serializer serializer - * @param searcher index searcher - * @param transformer transformer to transform Lucene documents to result objects - */ - public TypedQuery( - LuceneSerializer serializer, IndexSearcher searcher, Function transformer) { - super(serializer, searcher, transformer); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/package-info.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/package-info.java deleted file mode 100644 index 65984f31f8..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/package-info.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** Lucene 5 support */ -package com.querydsl.lucene5; diff --git a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneQueryTest.java b/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneQueryTest.java deleted file mode 100644 index 7e30244c3a..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneQueryTest.java +++ /dev/null @@ -1,820 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.easymock.EasyMock.createMockBuilder; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -import com.querydsl.core.NonUniqueResultException; -import com.querydsl.core.QueryException; -import com.querydsl.core.QueryModifiers; -import com.querydsl.core.QueryResults; -import com.querydsl.core.types.ParamNotSetException; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.Param; -import com.querydsl.core.types.dsl.StringPath; -import java.io.IOException; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.DoubleDocValuesField; -import org.apache.lucene.document.DoubleField; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.document.IntField; -import org.apache.lucene.document.NumericDocValuesField; -import org.apache.lucene.document.SortedDocValuesField; -import org.apache.lucene.document.TextField; -import org.apache.lucene.index.DirectoryReader; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.sandbox.queries.DuplicateFilter; -import org.apache.lucene.search.Filter; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Sort; -import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.util.BytesRef; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Tests for LuceneQuery - * - * @author vema - */ -public class LuceneQueryTest { - - private LuceneQuery query; - private StringPath title; - private NumberPath year; - private NumberPath gross; - - private final StringPath sort = Expressions.stringPath("sort"); - - private RAMDirectory idx; - private IndexWriter writer; - private IndexSearcher searcher; - private Field titleField = null; - private SortedDocValuesField titleSortedField; - private TextField authorField = null; - private SortedDocValuesField authorSortedField; - private TextField textField = null; - private IntField yearField = null; - private DoubleField grossField = null; - private SortedDocValuesField textSortedField; - private NumericDocValuesField yearSortedField; - private DoubleDocValuesField grossSortedField; - - private Document createDocument( - final String docTitle, - final String docAuthor, - final String docText, - final int docYear, - final double docGross) { - Document doc = new Document(); - // Reusing field for performance - if (titleField == null) { - titleField = new TextField("title", docTitle, Store.YES); - doc.add(titleField); - titleSortedField = new SortedDocValuesField("title", new BytesRef(docTitle)); - doc.add(titleSortedField); - } else { - titleField.setStringValue(docTitle); - titleSortedField.setBytesValue(new BytesRef(docTitle)); - doc.add(titleField); - doc.add(titleSortedField); - } - if (authorField == null) { - authorField = new TextField("author", docAuthor, Store.YES); - doc.add(authorField); - authorSortedField = new SortedDocValuesField("author", new BytesRef(docAuthor)); - doc.add(authorSortedField); - - } else { - authorField.setStringValue(docAuthor); - authorSortedField.setBytesValue(new BytesRef(docAuthor)); - doc.add(authorField); - doc.add(authorSortedField); - } - if (textField == null) { - textField = new TextField("text", docText, Store.YES); - doc.add(textField); - textSortedField = new SortedDocValuesField("text", new BytesRef(docText)); - doc.add(textSortedField); - } else { - textField.setStringValue(docText); - textSortedField.setBytesValue(new BytesRef(docText)); - doc.add(textField); - doc.add(textSortedField); - } - if (yearField == null) { - yearField = new IntField("year", docYear, Store.YES); - doc.add(yearField); - yearSortedField = new NumericDocValuesField("year", docYear); - doc.add(yearSortedField); - } else { - yearField.setIntValue(docYear); - yearSortedField.setLongValue(docYear); - doc.add(yearField); - doc.add(yearSortedField); - } - - if (grossField == null) { - grossField = new DoubleField("gross", docGross, Store.YES); - doc.add(grossField); - grossSortedField = new DoubleDocValuesField("gross", docGross); - doc.add(grossSortedField); - } else { - grossField.setDoubleValue(docGross); - grossSortedField.setDoubleValue(docGross); - doc.add(grossField); - doc.add(grossSortedField); - } - - return doc; - } - - @Before - public void setUp() throws Exception { - final QDocument entityPath = new QDocument("doc"); - title = entityPath.title; - year = entityPath.year; - gross = entityPath.gross; - - idx = new RAMDirectory(); - writer = createWriter(idx); - - writer.addDocument( - createDocument( - "Jurassic Park", "Michael Crichton", "It's a UNIX system! I know this!", 1990, 90.00)); - writer.addDocument( - createDocument( - "Nummisuutarit", "Aleksis Kivi", "ESKO. Ja iloitset ja riemuitset?", 1864, 10.00)); - writer.addDocument( - createDocument( - "The Lord of the Rings", - "John R. R. Tolkien", - "One Ring to rule them all, One Ring to find them, One Ring to bring them all and in" - + " the darkness bind them", - 1954, - 89.00)); - writer.addDocument( - createDocument( - "Introduction to Algorithms", - "Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein", - "Bubble sort", - 1990, - 30.50)); - - writer.close(); - - IndexReader reader = DirectoryReader.open(idx); - searcher = new IndexSearcher(reader); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - } - - private IndexWriter createWriter(RAMDirectory idx) throws Exception { - IndexWriterConfig config = - new IndexWriterConfig(new StandardAnalyzer()) - .setOpenMode(IndexWriterConfig.OpenMode.CREATE); - return new IndexWriter(idx, config); - } - - @After - public void tearDown() throws Exception { - searcher.getIndexReader().close(); - } - - @Test - public void between() { - assertThat(query.where(year.between(1950, 1990)).fetchCount()).isEqualTo(3); - } - - @Test - public void count_empty_where_clause() { - assertThat(query.fetchCount()).isEqualTo(4); - } - - @Test - public void exists() { - assertThat(query.where(title.eq("Jurassic Park")).fetchCount() > 0).isTrue(); - assertThat(query.where(title.eq("Jurassic Park X")).fetchCount() > 0).isFalse(); - } - - @Test - public void notExists() { - assertThat(query.where(title.eq("Jurassic Park")).fetchCount() == 0).isFalse(); - assertThat(query.where(title.eq("Jurassic Park X")).fetchCount() == 0).isTrue(); - } - - @Test - public void count() { - query.where(title.eq("Jurassic Park")); - assertThat(query.fetchCount()).isEqualTo(1); - } - - @Test(expected = QueryException.class) - @Ignore - public void count_index_problem() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andThrow(new IllegalArgumentException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.fetchCount(); - verify(searcher); - } - - @Test(expected = UnsupportedOperationException.class) - public void countDistinct() { - query.where(year.between(1900, 3000)); - assertThat(query.distinct().fetchCount()).isEqualTo(3); - } - - @Test - public void in() { - assertThat(query.where(title.in("Jurassic Park", "Nummisuutarit")).fetchCount()).isEqualTo(2); - } - - @Test - public void in2() { - assertThat(query.where(year.in(1990, 1864)).fetchCount()).isEqualTo(3); - } - - @Test - public void in_toString() { - assertThat(query.where(year.in(1990, 1864)).toString()).isEqualTo("year:`____F year:`____H"); - } - - @Test - public void list_sorted_by_year_ascending() { - query.where(year.between(1800, 2000)); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void list_not_sorted() { - query.where(year.between(1800, 2000)); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - @Ignore - // FIXME - public void sorted_by_different_locales() throws Exception { - Document d1 = new Document(); - Document d2 = new Document(); - Document d3 = new Document(); - d1.add(new TextField("sort", "a\u00c4", Store.YES)); - d2.add(new TextField("sort", "ab", Store.YES)); - d3.add(new TextField("sort", "aa", Store.YES)); - writer = createWriter(idx); - writer.addDocument(d1); - writer.addDocument(d2); - writer.addDocument(d3); - writer.close(); - - IndexReader reader = DirectoryReader.open(writer, true); - searcher = new IndexSearcher(reader); - query = new LuceneQuery(new LuceneSerializer(true, true, Locale.ENGLISH), searcher); - assertThat(query.fetch()).hasSize(3); - List results = query.where(sort.startsWith("a")).orderBy(sort.asc()).fetch(); - assertThat(results).hasSize(3); - assertThat(results.getFirst().getField("sort").stringValue()).isEqualTo("aa"); - assertThat(results.get(1).getField("sort").stringValue()).isEqualTo("a\u00c4"); - assertThat(results.get(2).getField("sort").stringValue()).isEqualTo("ab"); - - query = new LuceneQuery(new LuceneSerializer(true, true, Locale.of("fi", "FI")), searcher); - results = query.where(sort.startsWith("a")).orderBy(sort.asc()).fetch(); - assertThat(results.getFirst().getField("sort").stringValue()).isEqualTo("aa"); - assertThat(results.get(1).getField("sort").stringValue()).isEqualTo("ab"); - assertThat(results.get(2).getField("sort").stringValue()).isEqualTo("a\u00c4"); - } - - @Test - public void list_not_sorted_limit_2() { - query.where(year.between(1800, 2000)); - query.limit(2); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - } - - @Test - public void list_sorted_by_year_limit_1() { - query.where(year.between(1800, 2000)); - query.limit(1); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(1); - } - - @Test - public void list_not_sorted_offset_2() { - query.where(year.between(1800, 2000)); - query.offset(2); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - } - - @Test - public void list_sorted_ascending_by_year_offset_2() { - query.where(year.between(1800, 2000)); - query.offset(2); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - } - - @Test - public void list_sorted_ascending_by_year_restrict_limit_2_offset_1() { - query.where(year.between(1800, 2000)); - query.restrict(new QueryModifiers(2L, 1L)); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - assertThat(documents.getFirst().get("year")).isEqualTo("1954"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - } - - @Test - public void list_sorted_ascending_by_year() { - query.where(year.between(1800, 2000)); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1864"); - assertThat(documents.get(1).get("year")).isEqualTo("1954"); - assertThat(documents.get(2).get("year")).isEqualTo("1990"); - assertThat(documents.get(3).get("year")).isEqualTo("1990"); - } - - @Test - public void list_sort() { - Sort sort = LuceneSerializer.DEFAULT.toSort(Collections.singletonList(year.asc())); - - query.where(year.between(1800, 2000)); - // query.orderBy(year.asc()); - query.sort(sort); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1864"); - assertThat(documents.get(1).get("year")).isEqualTo("1954"); - assertThat(documents.get(2).get("year")).isEqualTo("1990"); - assertThat(documents.get(3).get("year")).isEqualTo("1990"); - } - - @Test - public void list_distinct_property() { - assertThat(query.fetch()).hasSize(4); - assertThat(query.distinct(year).fetch()).hasSize(3); - } - - @Test - public void list_with_filter() { - Filter filter = new DuplicateFilter("year"); - assertThat(query.fetch()).hasSize(4); - assertThat(query.filter(filter).fetch()).hasSize(3); - } - - @Test - public void count_distinct_property() { - assertThat(query.fetchCount()).isEqualTo(4L); - assertThat(query.distinct(year).fetchCount()).isEqualTo(3L); - } - - @Test - public void list_sorted_descending_by_year() { - query.where(year.between(1800, 2000)); - query.orderBy(year.desc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - assertThat(documents.get(2).get("year")).isEqualTo("1954"); - assertThat(documents.get(3).get("year")).isEqualTo("1864"); - } - - @Test - public void list_sorted_descending_by_gross() { - query.where(gross.between(0.0, 1000.00)); - query.orderBy(gross.desc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("gross")).isEqualTo("90.0"); - assertThat(documents.get(1).get("gross")).isEqualTo("89.0"); - assertThat(documents.get(2).get("gross")).isEqualTo("30.5"); - assertThat(documents.get(3).get("gross")).isEqualTo("10.0"); - } - - @Test - public void list_sorted_descending_by_year_and_ascending_by_title() { - query.where(year.between(1800, 2000)); - query.orderBy(year.desc()); - query.orderBy(title.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - assertThat(documents.getFirst().get("title")).isEqualTo("Introduction to Algorithms"); - assertThat(documents.get(1).get("title")).isEqualTo("Jurassic Park"); - } - - @Test - public void list_sorted_descending_by_year_and_descending_by_title() { - query.where(year.between(1800, 2000)); - query.orderBy(year.desc()); - query.orderBy(title.desc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - assertThat(documents.getFirst().get("title")).isEqualTo("Jurassic Park"); - assertThat(documents.get(1).get("title")).isEqualTo("Introduction to Algorithms"); - } - - @Ignore - @Test(expected = QueryException.class) - public void list_index_problem_in_max_doc() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andThrow(new IOException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.fetch(); - verify(searcher); - } - - @Ignore - @Test(expected = QueryException.class) - public void list_sorted_index_problem_in_max_doc() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andThrow(new IOException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.orderBy(title.asc()); - query.fetch(); - verify(searcher); - } - - @Test - public void offset() { - assertThat(query.where(title.eq("Jurassic Park")).offset(30).fetch()).isEmpty(); - } - - @Test - public void load_list() { - Document document = query.where(title.ne("")).load(title).fetch().get(0); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void load_list_fieldSelector() { - Document document = - query.where(title.ne("")).load(Collections.singleton("title")).fetch().get(0); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void load_singleResult() { - Document document = query.where(title.ne("")).load(title).fetchFirst(); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void load_singleResult_fieldSelector() { - Document document = query.where(title.ne("")).load(Collections.singleton("title")).fetchFirst(); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void singleResult() { - assertThat(query.where(title.ne("")).fetchFirst()).isNotNull(); - } - - @Test - public void single_result_takes_limit() { - assertThat(query.where(title.ne("")).limit(1).fetchFirst().get("title")) - .isEqualTo("Jurassic Park"); - } - - @Test - public void single_result_considers_limit_and_actual_result_size() { - query.where(title.startsWith("Nummi")); - final Document document = query.limit(3).fetchFirst(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test - public void single_result_returns_null_if_nothing_is_in_range() { - query.where(title.startsWith("Nummi")); - assertThat(query.offset(10).fetchFirst()).isNull(); - } - - @Test - public void single_result_considers_offset() { - assertThat(query.where(title.ne("")).offset(3).fetchFirst().get("title")) - .isEqualTo("Introduction to Algorithms"); - } - - @Test - public void single_result_considers_limit_and_offset() { - assertThat(query.where(title.ne("")).limit(1).offset(2).fetchFirst().get("title")) - .isEqualTo("The Lord of the Rings"); - } - - @Test(expected = NonUniqueResultException.class) - public void uniqueResult_contract() { - query.where(title.ne("")).fetchOne(); - } - - @Test - public void unique_result_takes_limit() { - assertThat(query.where(title.ne("")).limit(1).fetchOne().get("title")) - .isEqualTo("Jurassic Park"); - } - - @Test - public void unique_result_considers_limit_and_actual_result_size() { - query.where(title.startsWith("Nummi")); - final Document document = query.limit(3).fetchOne(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test - public void unique_result_returns_null_if_nothing_is_in_range() { - query.where(title.startsWith("Nummi")); - assertThat(query.offset(10).fetchOne()).isNull(); - } - - @Test - public void unique_result_considers_offset() { - assertThat(query.where(title.ne("")).offset(3).fetchOne().get("title")) - .isEqualTo("Introduction to Algorithms"); - } - - @Test - public void unique_result_considers_limit_and_offset() { - assertThat(query.where(title.ne("")).limit(1).offset(2).fetchOne().get("title")) - .isEqualTo("The Lord of the Rings"); - } - - @Test - public void uniqueResult() { - query.where(title.startsWith("Nummi")); - final Document document = query.fetchOne(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test - public void uniqueResult_with_param() { - final Param param = new Param(String.class, "title"); - query.set(param, "Nummi"); - query.where(title.startsWith(param)); - final Document document = query.fetchOne(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test(expected = ParamNotSetException.class) - public void uniqueResult_param_not_set() { - final Param param = new Param(String.class, "title"); - query.where(title.startsWith(param)); - query.fetchOne(); - } - - @Test(expected = QueryException.class) - public void uniqueResult_finds_more_than_one_result() { - query.where(year.eq(1990)); - query.fetchOne(); - } - - @Test - public void uniqueResult_finds_no_results() { - query.where(year.eq(2200)); - assertThat(query.fetchOne()).isNull(); - } - - @Test - @Ignore - public void uniqueResult_finds_no_results_because_no_documents_in_index() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andReturn(0); - replay(searcher); - assertThat(query.where(year.eq(3000)).fetchOne()).isNull(); - verify(searcher); - } - - @Test(expected = QueryException.class) - @Ignore - public void uniqueResult_sorted_index_problem_in_max_doc() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andThrow(new IllegalArgumentException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.fetchOne(); - verify(searcher); - } - - @Test - @Ignore - public void count_returns_0_because_no_documents_in_index() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andReturn(0); - replay(searcher); - assertThat(query.where(year.eq(3000)).fetchCount()).isEqualTo(0); - verify(searcher); - } - - @Test(expected = UnsupportedOperationException.class) - public void listDistinct() { - query.where(year.between(1900, 2000).or(title.startsWith("Jura"))); - query.orderBy(year.asc()); - final List documents = query.distinct().fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(3); - } - - @Test - public void listResults() { - query.where(year.between(1800, 2000)); - query.restrict(new QueryModifiers(2L, 1L)); - query.orderBy(year.asc()); - final QueryResults results = query.fetchResults(); - assertThat(results.isEmpty()).isFalse(); - assertThat(results.getResults().get(0).get("year")).isEqualTo("1954"); - assertThat(results.getResults().get(1).get("year")).isEqualTo("1990"); - assertThat(results.getLimit()).isEqualTo(2); - assertThat(results.getOffset()).isEqualTo(1); - assertThat(results.getTotal()).isEqualTo(4); - } - - @Test(expected = UnsupportedOperationException.class) - public void listDistinctResults() { - query.where(year.between(1800, 2000).or(title.eq("The Lord of the Rings"))); - query.restrict(new QueryModifiers(1L, 1L)); - query.orderBy(year.asc()); - final QueryResults results = query.distinct().fetchResults(); - assertThat(results.isEmpty()).isFalse(); - assertThat(results.getResults().get(0).get("year")).isEqualTo("1954"); - assertThat(results.getLimit()).isEqualTo(1); - assertThat(results.getOffset()).isEqualTo(1); - assertThat(results.getTotal()).isEqualTo(4); - } - - @Test - public void list_all() { - final List results = - query.where(title.like("*")).orderBy(title.asc(), year.desc()).fetch(); - assertThat(results).hasSize(4); - } - - @Test(expected = IllegalArgumentException.class) - public void list_sorted_ascending_limit_negative() { - query.where(year.between(1800, 2000)); - query.limit(-1); - query.orderBy(year.asc()); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_not_sorted_limit_negative() { - query.where(year.between(1800, 2000)); - query.limit(-1); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_sorted_ascending_limit_0() { - query.where(year.between(1800, 2000)); - query.limit(0); - query.orderBy(year.asc()); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_not_sorted_limit_0() { - query.where(year.between(1800, 2000)); - query.limit(0); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_sorted_ascending_offset_negative() { - query.where(year.between(1800, 2000)); - query.offset(-1); - query.orderBy(year.asc()); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_not_sorted_offset_negative() { - query.where(year.between(1800, 2000)); - query.offset(-1); - query.fetch(); - } - - @Test - public void list_sorted_ascending_offset_0() { - query.where(year.between(1800, 2000)); - query.offset(0); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void list_not_sorted_offset_0() { - query.where(year.between(1800, 2000)); - query.offset(0); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void iterate() { - query.where(year.between(1800, 2000)); - final Iterator iterator = query.iterate(); - int count = 0; - while (iterator.hasNext()) { - iterator.next(); - ++count; - } - assertThat(count).isEqualTo(4); - } - - @Test - public void all_by_excluding_where() { - assertThat(query.fetch()).hasSize(4); - } - - @Test - public void empty_index_should_return_empty_list() throws Exception { - idx = new RAMDirectory(); - - writer = createWriter(idx); - writer.close(); - IndexReader reader = DirectoryReader.open(idx); - searcher = new IndexSearcher(reader); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - assertThat(query.fetch()).isEmpty(); - } - - @Test(expected = QueryException.class) - public void - list_results_throws_an_illegal_argument_exception_when_sum_of_limit_and_offset_is_negative() { - query.limit(1).offset(Integer.MAX_VALUE).fetchResults(); - } - - @Test - public void limit_max_value() { - assertThat(query.limit(Long.MAX_VALUE).fetch()).hasSize(4); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneSerializerNotTokenizedTest.java b/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneSerializerNotTokenizedTest.java deleted file mode 100644 index 85e6942296..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneSerializerNotTokenizedTest.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -import static com.querydsl.lucene5.QPerson.person; -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.Expression; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringPath; -import java.time.LocalDate; -import java.util.Arrays; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.Field.Index; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.index.DirectoryReader; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TopDocs; -import org.apache.lucene.store.RAMDirectory; -import org.junit.Before; -import org.junit.Test; - -public class LuceneSerializerNotTokenizedTest { - private RAMDirectory idx; - private IndexWriter writer; - private IndexSearcher searcher; - private LuceneSerializer serializer; - - private final QueryMetadata metadata = new DefaultQueryMetadata(); - - private final Person clooney = new Person("actor_1", "George Clooney", LocalDate.of(1961, 4, 6)); - private final Person pitt = new Person("actor_2", "Brad Pitt", LocalDate.of(1963, 12, 18)); - - private void testQuery(Expression expr, String expectedQuery, int expectedHits) - throws Exception { - Query query = serializer.toQuery(expr, metadata); - TopDocs docs = searcher.search(query, 100); - assertThat(docs.totalHits).isEqualTo(expectedHits); - assertThat(query.toString()).isEqualTo(expectedQuery); - } - - private Document createDocument(Person person) { - Document doc = new Document(); - doc.add(new Field("id", person.getId(), Store.YES, Index.NOT_ANALYZED)); - doc.add(new Field("name", person.getName(), Store.YES, Index.NOT_ANALYZED)); - doc.add( - new Field("birthDate", person.getBirthDate().toString(), Store.YES, Index.NOT_ANALYZED)); - return doc; - } - - @Before - public void before() throws Exception { - serializer = new LuceneSerializer(false, false); - idx = new RAMDirectory(); - IndexWriterConfig config = - new IndexWriterConfig(new StandardAnalyzer()) - .setOpenMode(IndexWriterConfig.OpenMode.CREATE); - writer = new IndexWriter(idx, config); - - writer.addDocument(createDocument(clooney)); - writer.addDocument(createDocument(pitt)); - - Document document = new Document(); - for (String movie : Arrays.asList("Interview with the Vampire", "Up in the Air")) { - document.add(new Field("movie", movie, Store.YES, Index.NOT_ANALYZED)); - } - writer.addDocument(document); - - writer.close(); - - IndexReader reader = DirectoryReader.open(idx); - searcher = new IndexSearcher(reader); - } - - @Test - public void equals_by_id_matches() throws Exception { - testQuery(person.id.eq("actor_1"), "id:actor_1", 1); - } - - @Test - public void equals_by_id_does_not_match() throws Exception { - testQuery(person.id.eq("actor_8"), "id:actor_8", 0); - } - - @Test - public void equals_by_name_matches() throws Exception { - testQuery(person.name.eq("George Clooney"), "name:George Clooney", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void equals_by_name_ignoring_case_does_not_match() throws Exception { - testQuery(person.name.equalsIgnoreCase("george clooney"), "name:george clooney", 0); - } - - @Test - public void equals_by_name_does_not_match() throws Exception { - testQuery(person.name.eq("George Looney"), "name:George Looney", 0); - } - - @Test - public void starts_with_name_should_match() throws Exception { - testQuery(person.name.startsWith("George C"), "name:George C*", 1); - } - - @Test - public void starts_with_name_should_not_match() throws Exception { - testQuery(person.name.startsWith("George L"), "name:George L*", 0); - } - - @Test - public void ends_with_name_should_match() throws Exception { - testQuery(person.name.endsWith("e Clooney"), "name:*e Clooney", 1); - } - - @Test - public void ends_with_name_should_not_match() throws Exception { - testQuery(person.name.endsWith("e Looney"), "name:*e Looney", 0); - } - - @Test - public void contains_name_should_match() throws Exception { - testQuery(person.name.contains("oney"), "name:*oney*", 1); - } - - @Test - public void contains_name_should_not_match() throws Exception { - testQuery(person.name.contains("bloney"), "name:*bloney*", 0); - } - - @Test - public void in_names_should_match_2() throws Exception { - testQuery( - person.name.in("Brad Pitt", "George Clooney"), "name:Brad Pitt name:George Clooney", 2); - } - - @Test - public void or_by_name_should_match_2() throws Exception { - testQuery( - person.name.eq("Brad Pitt").or(person.name.eq("George Clooney")), - "name:Brad Pitt name:George Clooney", - 2); - } - - @Test - public void equals_by_birth_date() throws Exception { - testQuery(person.birthDate.eq(clooney.getBirthDate()), "birthDate:1961-04-06", 1); - } - - @Test - public void between_phrase() throws Exception { - testQuery( - person.name.between("Brad Pitt", "George Clooney"), - "name:[Brad Pitt TO George Clooney]", - 2); - } - - @Test - public void not_equals_finds_the_actors_and_movies() throws Exception { - testQuery(person.name.ne("Michael Douglas"), "-name:Michael Douglas +*:*", 3); - } - - @Test - public void not_equals_finds_only_clooney_and_movies() throws Exception { - testQuery(person.name.ne("Brad Pitt"), "-name:Brad Pitt +*:*", 2); - } - - @Test - public void and_with_two_not_equals_doesnt_find_the_actors() throws Exception { - testQuery( - person.name.ne("Brad Pitt").and(person.name.ne("George Clooney")), - "+(-name:Brad Pitt +*:*) +(-name:George Clooney +*:*)", - 1); - } - - @Test - public void or_with_two_not_equals_finds_movies_and_actors() throws Exception { - testQuery( - person.name.ne("Brad Pitt").or(person.name.ne("George Clooney")), - "(-name:Brad Pitt +*:*) (-name:George Clooney +*:*)", - 3); - } - - @Test - public void negation_of_equals_finds_movies_and_actors() throws Exception { - testQuery(person.name.eq("Michael Douglas").not(), "-name:Michael Douglas +*:*", 3); - } - - @Test - public void negation_of_equals_finds_pitt_and_movies() throws Exception { - testQuery(person.name.eq("Brad Pitt").not(), "-name:Brad Pitt +*:*", 2); - } - - @Test - public void multiple_field_search_from_movies() throws Exception { - StringPath movie = Expressions.stringPath("movie"); - testQuery(movie.in("Interview with the Vampire"), "movie:Interview with the Vampire", 1); - testQuery(movie.eq("Up in the Air"), "movie:Up in the Air", 1); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneSerializerTest.java b/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneSerializerTest.java deleted file mode 100644 index eeb35d3b10..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneSerializerTest.java +++ /dev/null @@ -1,718 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; - -import com.querydsl.core.BooleanBuilder; -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.MatchingFiltersFactory; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.QuerydslModule; -import com.querydsl.core.StringConstant; -import com.querydsl.core.Target; -import com.querydsl.core.types.Expression; -import com.querydsl.core.types.Operation; -import com.querydsl.core.types.Operator; -import com.querydsl.core.types.Ops; -import com.querydsl.core.types.Predicate; -import com.querydsl.core.types.dsl.BooleanExpression; -import com.querydsl.core.types.dsl.CollectionPath; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.PathBuilder; -import com.querydsl.core.types.dsl.StringPath; -import java.io.StringReader; -import java.util.Arrays; -import java.util.Collections; -import java.util.EnumSet; -import java.util.Set; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.DoubleField; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.Field.Index; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.document.FloatField; -import org.apache.lucene.document.IntField; -import org.apache.lucene.document.LongField; -import org.apache.lucene.index.DirectoryReader; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TopDocs; -import org.apache.lucene.store.RAMDirectory; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Tests for LuceneSerializer - * - * @author vema - */ -public class LuceneSerializerTest { - private LuceneSerializer serializer; - private PathBuilder entityPath; - private StringPath title; - private StringPath author; - private StringPath text; - private StringPath rating; - private StringPath publisher; - private NumberPath year; - private NumberPath gross; - private CollectionPath titles; - - private NumberPath longField; - private NumberPath shortField; - private NumberPath byteField; - private NumberPath floatField; - - private static final String YEAR_PREFIX_CODED = ""; - private static final String GROSS_PREFIX_CODED = ""; - private static final String LONG_PREFIX_CODED = ""; - private static final String SHORT_PREFIX_CODED = ""; - private static final String BYTE_PREFIX_CODED = ""; - private static final String FLOAT_PREFIX_CODED = ""; - - private IndexWriterConfig config; - private RAMDirectory idx; - private IndexWriter writer; - private IndexSearcher searcher; - - private static final Set UNSUPPORTED_OPERATORS = - Collections.unmodifiableSet( - EnumSet.of( - Ops.STARTS_WITH_IC, Ops.EQ_IGNORE_CASE, Ops.ENDS_WITH_IC, Ops.STRING_CONTAINS_IC)); - - private final QueryMetadata metadata = new DefaultQueryMetadata(); - - private Document createDocument() { - Document doc = new Document(); - - doc.add(new Field("title", new StringReader("Jurassic Park"))); - doc.add(new Field("author", new StringReader("Michael Crichton"))); - doc.add(new Field("text", new StringReader("It's a UNIX system! I know this!"))); - doc.add(new Field("rating", new StringReader("Good"))); - doc.add(new Field("publisher", "", Store.YES, Index.ANALYZED)); - doc.add(new IntField("year", 1990, Store.YES)); - doc.add(new DoubleField("gross", 900.0, Store.YES)); - - doc.add(new LongField("longField", 1, Store.YES)); - doc.add(new IntField("shortField", 1, Store.YES)); - doc.add(new IntField("byteField", 1, Store.YES)); - doc.add(new FloatField("floatField", 1, Store.YES)); - - return doc; - } - - @Before - public void setUp() throws Exception { - serializer = new LuceneSerializer(true, true); - entityPath = new PathBuilder(Object.class, "obj"); - title = entityPath.getString("title"); - author = entityPath.getString("author"); - text = entityPath.getString("text"); - publisher = entityPath.getString("publisher"); - year = entityPath.getNumber("year", Integer.class); - rating = entityPath.getString("rating"); - gross = entityPath.getNumber("gross", Double.class); - titles = entityPath.getCollection("title", String.class, StringPath.class); - - longField = entityPath.getNumber("longField", Long.class); - shortField = entityPath.getNumber("shortField", Short.class); - byteField = entityPath.getNumber("byteField", Byte.class); - floatField = entityPath.getNumber("floatField", Float.class); - - idx = new RAMDirectory(); - config = - new IndexWriterConfig(new StandardAnalyzer()) - .setOpenMode(IndexWriterConfig.OpenMode.CREATE); - writer = new IndexWriter(idx, config); - - writer.addDocument(createDocument()); - - writer.close(); - - IndexReader reader = DirectoryReader.open(idx); - searcher = new IndexSearcher(reader); - } - - @After - public void tearDown() throws Exception { - searcher.getIndexReader().close(); - } - - private void testQuery(Expression expr, int expectedHits) throws Exception { - Query query = serializer.toQuery(expr, metadata); - TopDocs docs = searcher.search(query, 100); - assertThat(docs.totalHits).isEqualTo(expectedHits); - } - - private void testQuery(Expression expr, String expectedQuery, int expectedHits) - throws Exception { - Query query = serializer.toQuery(expr, metadata); - TopDocs docs = searcher.search(query, 100); - assertThat(docs.totalHits).isEqualTo(expectedHits); - assertThat(query.toString()).isEqualTo(expectedQuery); - } - - @Test - public void queryElement() throws Exception { - Query query1 = serializer.toQuery(author.like("Michael"), metadata); - Query query2 = serializer.toQuery(text.like("Text"), metadata); - - BooleanExpression query = Expressions.anyOf(new QueryElement(query1), new QueryElement(query2)); - testQuery(query, "author:michael text:text", 1); - } - - @Test - public void like() throws Exception { - testQuery(author.like("*ichael*"), "author:*ichael*", 1); - } - - @Test - public void like_custom_wildcard_single_character() throws Exception { - testQuery(author.like("Mi?hael"), "author:mi?hael", 1); - } - - @Test - public void like_custom_wildcard_multiple_character() throws Exception { - testQuery(text.like("*U*X*"), "text:*u*x*", 1); - } - - @Test - public void like_phrase() throws Exception { - testQuery(title.like("*rassic Par*"), "+title:**rassic* +title:*par**", 1); - } - - @Test - public void like_or_like() throws Exception { - testQuery(title.like("House").or(author.like("*ichae*")), "title:house author:*ichae*", 1); - } - - @Test - public void like_and_like() throws Exception { - testQuery(title.like("*assic*").and(rating.like("G?od")), "+title:*assic* +rating:g?od", 1); - } - - @Test - public void eq() throws Exception { - testQuery(rating.eq("good"), "rating:good", 1); - } - - @Test - public void eq_with_deep_path() throws Exception { - StringPath deepPath = entityPath.get("property1", Object.class).getString("property2"); - testQuery(deepPath.eq("good"), "property1.property2:good", 0); - } - - @Test - public void fuzzyLike() throws Exception { - testQuery(LuceneExpressions.fuzzyLike(rating, "Good"), "rating:Good~2", 1); - } - - @Test - public void fuzzyLike_with_similarity() throws Exception { - testQuery(LuceneExpressions.fuzzyLike(rating, "Good", 2), "rating:Good~2", 1); - } - - @Test - public void fuzzyLike_with_similarity_and_prefix() throws Exception { - testQuery(LuceneExpressions.fuzzyLike(rating, "Good", 2, 0), "rating:Good~2", 1); - } - - @Test - @Ignore - public void eq_numeric_integer() throws Exception { - testQuery(year.eq(1990), "year:" + YEAR_PREFIX_CODED, 1); - } - - @Test - @Ignore - public void eq_numeric_double() throws Exception { - testQuery(gross.eq(900.00), "gross:" + GROSS_PREFIX_CODED, 1); - } - - @Test - @Ignore - public void eq_numeric() throws Exception { - testQuery(longField.eq(1L), "longField:" + LONG_PREFIX_CODED, 1); - testQuery(shortField.eq((short) 1), "shortField:" + SHORT_PREFIX_CODED, 1); - testQuery(byteField.eq((byte) 1), "byteField:" + BYTE_PREFIX_CODED, 1); - testQuery(floatField.eq((float) 1.0), "floatField:" + FLOAT_PREFIX_CODED, 1); - } - - @Test - public void equals_ignores_case() throws Exception { - testQuery(title.eq("Jurassic"), "title:jurassic", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void title_equals_ignore_case_or_year_equals() throws Exception { - testQuery( - title.equalsIgnoreCase("House").or(year.eq(1990)), - "title:house year:" + YEAR_PREFIX_CODED, - 1); - } - - @Test - @Ignore - public void eq_and_eq() throws Exception { - testQuery( - title.eq("Jurassic Park").and(year.eq(1990)), - "+title:\"jurassic park\" +year:" + YEAR_PREFIX_CODED, - 1); - } - - @Test - @Ignore - public void eq_and_eq_and_eq() throws Exception { - testQuery( - title.eq("Jurassic Park").and(year.eq(1990)).and(author.eq("Michael Crichton")), - "+(+title:\"jurassic park\" +year:" + YEAR_PREFIX_CODED + ") +author:\"michael crichton\"", - 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void equals_ignore_case_and_or() throws Exception { - testQuery( - title - .equalsIgnoreCase("Jurassic Park") - .and(rating.equalsIgnoreCase("Bad")) - .or(author.equalsIgnoreCase("Michael Crichton")), - "(+title:\"jurassic park\" +rating:bad) author:\"michael crichton\"", - 1); - } - - @Test - public void eq_or_eq_and_eq_does_not_find_results() throws Exception { - testQuery( - title.eq("jeeves").or(rating.eq("superb")).and(author.eq("michael crichton")), - "+(title:jeeves rating:superb) +author:\"michael crichton\"", - 0); - } - - @Test - public void eq_phrase() throws Exception { - testQuery(title.eq("Jurassic Park"), "title:\"jurassic park\"", 1); - } - - @Test - @Ignore("Not easily done in Lucene!") - public void publisher_equals_empty_string() throws Exception { - testQuery(publisher.eq(""), "publisher:", 1); - } - - @Test - public void eq_phrase_should_not_find_results_but_luceNe_semantics_differs_from_querydsls() - throws Exception { - testQuery(text.eq("UNIX System"), "text:\"unix system\"", 1); - } - - @Test - public void eq_phrase_does_not_find_results_because_word_in_middle() throws Exception { - testQuery(title.eq("Jurassic Amusement Park"), "title:\"jurassic amusement park\"", 0); - } - - @Test - public void like_not_does_not_find_results() throws Exception { - testQuery(title.like("*H*e*").not(), "-title:*h*e* +*:*", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void title_equals_ignore_case_negation_or_rating_equals_ignore_case() throws Exception { - testQuery( - title.equalsIgnoreCase("House").not().or(rating.equalsIgnoreCase("Good")), - "-title:house rating:good", - 1); - } - - @Test - public void eq_not_does_not_find_results() throws Exception { - testQuery(title.eq("Jurassic Park").not(), "-title:\"jurassic park\" +*:*", 0); - } - - @Test - public void title_equals_not_house() throws Exception { - testQuery(title.eq("house").not(), "-title:house +*:*", 1); - } - - @Test - public void eq_and_eq_not_does_not_find_results_because_second_expression_finds_nothing() - throws Exception { - testQuery( - rating.eq("superb").and(title.eq("house").not()), "+rating:superb +(-title:house +*:*)", 0); - } - - @Test - public void not_equals_finds_one() throws Exception { - testQuery(title.ne("house"), "-title:house +*:*", 1); - } - - @Test - public void not_equals_finds_none() throws Exception { - testQuery(title.ne("Jurassic Park"), "-title:\"jurassic park\" +*:*", 0); - } - - @Test - public void nothing_found_with_not_equals_or_equals() throws Exception { - testQuery( - title.ne("jurassic park").or(rating.eq("lousy")), - "(-title:\"jurassic park\" +*:*) rating:lousy", - 0); - } - - @Test - public void ne_and_eq() throws Exception { - testQuery(title.ne("house").and(rating.eq("good")), "+(-title:house +*:*) +rating:good", 1); - } - - @Test - public void startsWith() throws Exception { - testQuery(title.startsWith("Jurassi"), "title:jurassi*", 1); - } - - @Test - public void startsWith_phrase() throws Exception { - testQuery(title.startsWith("jurassic par"), "+title:jurassic* +title:*par*", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void starts_with_ignore_case_phrase_does_not_find_results() throws Exception { - testQuery(title.startsWithIgnoreCase("urassic Par"), "+title:urassic* +title:*par*", 0); - } - - @Test - public void endsWith() throws Exception { - testQuery(title.endsWith("ark"), "title:*ark", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void ends_with_ignore_case_phrase() throws Exception { - testQuery(title.endsWithIgnoreCase("sic Park"), "+title:*sic* +title:*park", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void ends_with_ignore_case_phrase_does_not_find_results() throws Exception { - testQuery(title.endsWithIgnoreCase("sic Par"), "+title:*sic* +title:*par", 0); - } - - @Test - public void contains() throws Exception { - testQuery(title.contains("rassi"), "title:*rassi*", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void contains_ignore_case_phrase() throws Exception { - testQuery(title.containsIgnoreCase("rassi Pa"), "+title:*rassi* +title:*pa*", 1); - } - - @Test - public void contains_user_inputted_wildcards_dont_work() throws Exception { - testQuery(title.contains("r*i"), "title:*r\\*i*", 0); - } - - @Test - public void between() throws Exception { - testQuery(title.between("Indiana", "Kundun"), "title:[indiana TO kundun]", 1); - } - - @Test - public void between_numeric_integer() throws Exception { - testQuery(year.between(1980, 2000), "year:[1980 TO 2000]", 1); - } - - @Test - public void between_numeric_double() throws Exception { - testQuery(gross.between(10.00, 19030.00), "gross:[10.0 TO 19030.0]", 1); - } - - @Test - public void between_numeric() throws Exception { - testQuery(longField.between(0L, 2L), "longField:[0 TO 2]", 1); - testQuery(shortField.between((short) 0, (short) 2), "shortField:[0 TO 2]", 1); - testQuery(byteField.between((byte) 0, (byte) 2), "byteField:[0 TO 2]", 1); - testQuery(floatField.between((float) 0.0, (float) 2.0), "floatField:[0.0 TO 2.0]", 1); - } - - @Test - public void between_is_inclusive_from_start() throws Exception { - testQuery(title.between("Jurassic", "Kundun"), "title:[jurassic TO kundun]", 1); - } - - @Test - public void between_is_inclusive_to_end() throws Exception { - testQuery(title.between("Indiana", "Jurassic"), "title:[indiana TO jurassic]", 1); - } - - @Test - public void between_does_not_find_results() throws Exception { - testQuery(title.between("Indiana", "Jurassib"), "title:[indiana TO jurassib]", 0); - } - - @Test - public void in() throws Exception { - testQuery(title.in(Arrays.asList("jurassic", "park")), "title:jurassic title:park", 1); - testQuery(title.in("jurassic", "park"), "title:jurassic title:park", 1); - testQuery(title.eq("jurassic").or(title.eq("park")), "title:jurassic title:park", 1); - } - - @Test - public void lt() throws Exception { - testQuery(rating.lt("Superb"), "rating:{* TO superb}", 1); - } - - @Test - public void lt_numeric_integer() throws Exception { - testQuery(year.lt(1991), "year:{* TO 1991}", 1); - } - - @Test - public void lt_numeric_double() throws Exception { - testQuery(gross.lt(10000.0), "gross:{* TO 10000.0}", 1); - } - - @Test - public void lt_not_in_range_because_equal() throws Exception { - testQuery(rating.lt("Good"), "rating:{* TO good}", 0); - } - - @Test - public void lt_numeric_integer_not_in_range_because_equal() throws Exception { - testQuery(year.lt(1990), "year:{* TO 1990}", 0); - } - - @Test - public void lt_numeric_double_not_in_range_because_equal() throws Exception { - testQuery(gross.lt(900.0), "gross:{* TO 900.0}", 0); - } - - @Test - public void loe() throws Exception { - testQuery(rating.loe("Superb"), "rating:[* TO superb]", 1); - } - - @Test - public void loe_numeric_integer() throws Exception { - testQuery(year.loe(1991), "year:[* TO 1991]", 1); - } - - @Test - public void loe_numeric_double() throws Exception { - testQuery(gross.loe(903.0), "gross:[* TO 903.0]", 1); - } - - @Test - public void loe_equal() throws Exception { - testQuery(rating.loe("Good"), "rating:[* TO good]", 1); - } - - @Test - public void loe_numeric_integer_equal() throws Exception { - testQuery(year.loe(1990), "year:[* TO 1990]", 1); - } - - @Test - public void loe_numeric_double_equal() throws Exception { - testQuery(gross.loe(900.0), "gross:[* TO 900.0]", 1); - } - - @Test - public void loe_not_found() throws Exception { - testQuery(rating.loe("Bad"), "rating:[* TO bad]", 0); - } - - @Test - public void loe_numeric_integer_not_found() throws Exception { - testQuery(year.loe(1989), "year:[* TO 1989]", 0); - } - - @Test - public void loe_numeric_double_not_found() throws Exception { - testQuery(gross.loe(899.9), "gross:[* TO 899.9]", 0); - } - - @Test - public void gt() throws Exception { - testQuery(rating.gt("Bad"), "rating:{bad TO *}", 1); - } - - @Test - public void gt_numeric_integer() throws Exception { - testQuery(year.gt(1989), "year:{1989 TO *}", 1); - } - - @Test - public void gt_numeric_double() throws Exception { - testQuery(gross.gt(100.00), "gross:{100.0 TO *}", 1); - } - - @Test - public void gt_not_in_range_because_equal() throws Exception { - testQuery(rating.gt("Good"), "rating:{good TO *}", 0); - } - - @Test - public void gt_numeric_integer_not_in_range_because_equal() throws Exception { - testQuery(year.gt(1990), "year:{1990 TO *}", 0); - } - - @Test - public void gt_numeric_double_not_in_range_because_equal() throws Exception { - testQuery(gross.gt(900.00), "gross:{900.0 TO *}", 0); - } - - @Test - public void goe() throws Exception { - testQuery(rating.goe("Bad"), "rating:[bad TO *]", 1); - } - - @Test - public void goe_numeric_integer() throws Exception { - testQuery(year.goe(1989), "year:[1989 TO *]", 1); - } - - @Test - public void goe_numeric_double() throws Exception { - testQuery(gross.goe(320.50), "gross:[320.5 TO *]", 1); - } - - @Test - public void goe_equal() throws Exception { - testQuery(rating.goe("Good"), "rating:[good TO *]", 1); - } - - @Test - public void goe_numeric_integer_equal() throws Exception { - testQuery(year.goe(1990), "year:[1990 TO *]", 1); - } - - @Test - public void goe_numeric_double_equal() throws Exception { - testQuery(gross.goe(900.00), "gross:[900.0 TO *]", 1); - } - - @Test - public void goe_not_found() throws Exception { - testQuery(rating.goe("Hood"), "rating:[hood TO *]", 0); - } - - @Test - public void goe_numeric_integer_not_found() throws Exception { - testQuery(year.goe(1991), "year:[1991 TO *]", 0); - } - - @Test - public void goe_numeric_double_not_found() throws Exception { - testQuery(gross.goe(900.10), "gross:[900.1 TO *]", 0); - } - - @Test - public void equals_empty_string() throws Exception { - testQuery(title.eq(""), "title:", 0); - } - - @Test - public void not_equals_empty_string() throws Exception { - testQuery(title.ne(""), "-title: +*:*", 1); - } - - @Test - public void contains_empty_string() throws Exception { - testQuery(title.contains(""), "title:**", 1); - } - - @Test - public void like_empty_string() throws Exception { - testQuery(title.like(""), "title:", 0); - } - - @Test - public void starts_with_empty_string() throws Exception { - testQuery(title.startsWith(""), "title:*", 1); - } - - @Test - public void ends_with_empty_string() throws Exception { - testQuery(title.endsWith(""), "title:*", 1); - } - - @Test - public void between_empty_strings() throws Exception { - testQuery(title.between("", ""), "title:[ TO ]", 0); - } - - @Test - public void booleanBuilder() throws Exception { - testQuery(new BooleanBuilder(gross.goe(900.10)), "gross:[900.1 TO *]", 0); - } - - @Test - @Ignore - public void fuzzy() throws Exception { - fail("Not yet implemented!"); - } - - @Test - @Ignore - public void proximity() throws Exception { - fail("Not yet implemented!"); - } - - @Test - @Ignore - public void boost() throws Exception { - fail("Not yet implemented!"); - } - - @Test - public void pathAny() throws Exception { - testQuery(titles.any().eq("Jurassic"), "title:jurassic", 1); - } - - private boolean unsupportedOperation(Predicate filter) { - return UNSUPPORTED_OPERATORS.contains(((Operation) filter).getOperator()); - } - - @Test - public void various() throws Exception { - MatchingFiltersFactory filters = - new MatchingFiltersFactory(QuerydslModule.LUCENE, Target.LUCENE); - for (Predicate filter : filters.string(title, StringConstant.create("jurassic park"))) { - if (unsupportedOperation(filter)) { - continue; - } - testQuery(filter, 1); - } - - for (Predicate filter : filters.string(author, StringConstant.create("michael crichton"))) { - if (unsupportedOperation(filter)) { - continue; - } - testQuery(filter, 1); - } - - for (Predicate filter : filters.string(title, StringConstant.create("1990"))) { - if (unsupportedOperation(filter)) { - continue; - } - testQuery(filter, 0); - } - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/Person.java b/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/Person.java deleted file mode 100644 index 0577368fd8..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/Person.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -import com.querydsl.core.annotations.QueryEntity; -import java.time.LocalDate; - -@QueryEntity -public class Person { - private final String id; - private final String name; - private final LocalDate birthDate; - - public Person(String id, String name, LocalDate birthDate) { - this.id = id; - this.name = name; - this.birthDate = birthDate; - } - - public String getId() { - return id; - } - - public LocalDate getBirthDate() { - return birthDate; - } - - public String getName() { - return name; - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/PhraseElementTest.java b/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/PhraseElementTest.java deleted file mode 100644 index 5e23bfc1fb..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/PhraseElementTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringPath; -import org.junit.Test; - -public class PhraseElementTest { - - @Test - public void test() { - StringPath title = Expressions.stringPath("title"); - LuceneSerializer serializer = new LuceneSerializer(false, false); - QueryMetadata metadata = new DefaultQueryMetadata(); - assertThat(serializer.toQuery(title.eq("Hello World"), metadata).toString()) - .isEqualTo("title:Hello World"); - assertThat(serializer.toQuery(title.eq(new PhraseElement("Hello World")), metadata).toString()) - .isEqualTo("title:\"Hello World\""); - } - - @Test - public void equals() { - PhraseElement el1 = new PhraseElement("x"), - el2 = new PhraseElement("x"), - el3 = new PhraseElement("y"); - assertThat(el2).isEqualTo(el1); - assertThat(el1.equals(el3)).isFalse(); - } - - @Test - public void hashCode_() { - PhraseElement el1 = new PhraseElement("x"), el2 = new PhraseElement("x"); - assertThat(el2.hashCode()).isEqualTo(el1.hashCode()); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/QDocument.java b/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/QDocument.java deleted file mode 100644 index 83b7b4c8ab..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/QDocument.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -import com.querydsl.core.types.PathMetadataFactory; -import com.querydsl.core.types.dsl.EntityPathBase; -import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.StringPath; -import org.apache.lucene.document.Document; - -public class QDocument extends EntityPathBase { - - private static final long serialVersionUID = -4872833626508344081L; - - public QDocument(final String var) { - super(Document.class, PathMetadataFactory.forVariable(var)); - } - - public final NumberPath year = createNumber("year", Integer.class); - - public final StringPath title = createString("title"); - - public final NumberPath gross = createNumber("gross", Double.class); -} diff --git a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/QueryElementTest.java b/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/QueryElementTest.java deleted file mode 100644 index 9b3aec786c..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/QueryElementTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.apache.lucene.index.Term; -import org.apache.lucene.search.TermQuery; -import org.junit.Ignore; -import org.junit.Test; - -public class QueryElementTest { - - @Test - @Ignore - public void test() { - QueryElement element = new QueryElement(new TermQuery(new Term("str", "text"))); - assertThat(element.toString()).isEqualTo("str:text"); - // assertEquals(element.getQuery().hashCode(), element.hashCode()); - - QueryElement element2 = new QueryElement(new TermQuery(new Term("str", "text"))); - assertThat(element).isEqualTo(element2); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/TermElementTest.java b/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/TermElementTest.java deleted file mode 100644 index 005e4e7155..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/TermElementTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.lucene5; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringPath; -import org.junit.Test; - -public class TermElementTest { - - @Test - public void test() { - StringPath title = Expressions.stringPath("title"); - LuceneSerializer serializer = new LuceneSerializer(false, true); - QueryMetadata metadata = new DefaultQueryMetadata(); - assertThat(serializer.toQuery(title.eq("Hello World"), metadata).toString()) - .isEqualTo("title:\"Hello World\""); - assertThat(serializer.toQuery(title.eq(new TermElement("Hello World")), metadata).toString()) - .isEqualTo("title:Hello World"); - } - - @Test - public void testEqualsAndHashCode() { - TermElement el1 = new TermElement("x"), el2 = new TermElement("x"), el3 = new TermElement("y"); - assertThat(el2).isEqualTo(el1); - assertThat(el1.equals(el3)).isFalse(); - assertThat(el2.hashCode()).isEqualTo(el1.hashCode()); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/test/resources/log4j.properties.example b/querydsl-libraries/querydsl-lucene5/src/test/resources/log4j.properties.example deleted file mode 100644 index 0f193f333c..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/test/resources/log4j.properties.example +++ /dev/null @@ -1,9 +0,0 @@ -# Configure an appender that logs to console -log4j.rootLogger=info, A1 -log4j.threshold=debug -log4j.appender.A1=org.apache.log4j.ConsoleAppender -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c{1} - %m%n - -# Configuration of logging levels for different packages -log4j.logger.com.querydsl.lucene5=DEBUG diff --git a/querydsl-libraries/querydsl-mongodb/pom.xml b/querydsl-libraries/querydsl-mongodb/pom.xml index b97bc372fe..2115bebac1 100644 --- a/querydsl-libraries/querydsl-mongodb/pom.xml +++ b/querydsl-libraries/querydsl-mongodb/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-mongodb diff --git a/querydsl-libraries/querydsl-mongodb/src/main/java/com/querydsl/mongodb/AbstractMongodbQuery.java b/querydsl-libraries/querydsl-mongodb/src/main/java/com/querydsl/mongodb/AbstractMongodbQuery.java index 78190fec2a..8696b11afa 100644 --- a/querydsl-libraries/querydsl-mongodb/src/main/java/com/querydsl/mongodb/AbstractMongodbQuery.java +++ b/querydsl-libraries/querydsl-mongodb/src/main/java/com/querydsl/mongodb/AbstractMongodbQuery.java @@ -18,7 +18,7 @@ import com.mongodb.DBCursor; import com.mongodb.DBObject; import com.mongodb.ReadPreference; -import com.mysema.commons.lang.CloseableIterator; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.DefaultQueryMetadata; import com.querydsl.core.Fetchable; import com.querydsl.core.JoinExpression; diff --git a/querydsl-libraries/querydsl-mongodb/src/main/java/com/querydsl/mongodb/document/AbstractFetchableMongodbQuery.java b/querydsl-libraries/querydsl-mongodb/src/main/java/com/querydsl/mongodb/document/AbstractFetchableMongodbQuery.java index 8d79eb2936..f682df6ac1 100644 --- a/querydsl-libraries/querydsl-mongodb/src/main/java/com/querydsl/mongodb/document/AbstractFetchableMongodbQuery.java +++ b/querydsl-libraries/querydsl-mongodb/src/main/java/com/querydsl/mongodb/document/AbstractFetchableMongodbQuery.java @@ -17,7 +17,7 @@ import com.mongodb.client.FindIterable; import com.mongodb.client.MongoCollection; -import com.mysema.commons.lang.CloseableIterator; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.Fetchable; import com.querydsl.core.NonUniqueResultException; import com.querydsl.core.QueryModifiers; diff --git a/querydsl-libraries/querydsl-r2dbc/pom.xml b/querydsl-libraries/querydsl-r2dbc/pom.xml index 4c84544f2e..6a7a279604 100644 --- a/querydsl-libraries/querydsl-r2dbc/pom.xml +++ b/querydsl-libraries/querydsl-r2dbc/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-r2dbc diff --git a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/JDBCTypeMapping.java b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/JDBCTypeMapping.java index c4523154a5..1b6c06f3c8 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/JDBCTypeMapping.java +++ b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/JDBCTypeMapping.java @@ -13,7 +13,7 @@ */ package com.querydsl.r2dbc; -import com.mysema.commons.lang.Pair; +import com.querydsl.core.Pair; import com.querydsl.sql.types.Null; import io.r2dbc.spi.Blob; import java.math.BigDecimal; diff --git a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/MySQLTemplates.java b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/MySQLTemplates.java index 67b76973f8..dabffba8bd 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/MySQLTemplates.java +++ b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/MySQLTemplates.java @@ -176,21 +176,11 @@ public String escapeLiteral(String str) { @Override public String getCastTypeNameForCode(int code) { - switch (code) { - case Types.TINYINT: - case Types.SMALLINT: - case Types.INTEGER: - case Types.BIGINT: - return "signed"; - case Types.FLOAT: - case Types.DOUBLE: - case Types.REAL: - case Types.DECIMAL: - return "decimal"; - case Types.VARCHAR: - return "char"; - default: - return super.getCastTypeNameForCode(code); - } + return switch (code) { + case Types.TINYINT, Types.SMALLINT, Types.INTEGER, Types.BIGINT -> "signed"; + case Types.FLOAT, Types.DOUBLE, Types.REAL, Types.DECIMAL -> "decimal"; + case Types.VARCHAR -> "char"; + default -> super.getCastTypeNameForCode(code); + }; } } diff --git a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLSerializer.java b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLSerializer.java index d7fccd1bd3..cdc67e684e 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLSerializer.java +++ b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLSerializer.java @@ -816,10 +816,10 @@ public void serializeUnion(Expression union, QueryMetadata metadata, boolean @Override public void visitConstant(Object constant) { if (useLiterals) { - if (constant instanceof Collection) { + if (constant instanceof Collection collection) { append("("); var first = true; - for (Object o : ((Collection) constant)) { + for (Object o : collection) { if (!first) { append(COMMA); } @@ -830,10 +830,10 @@ public void visitConstant(Object constant) { } else { append(configuration.asLiteral(constant)); } - } else if (constant instanceof Collection) { + } else if (constant instanceof Collection collection) { append("("); var first = true; - for (Object o : ((Collection) constant)) { + for (Object o : collection) { if (!first) { append(COMMA); } @@ -846,7 +846,7 @@ public void visitConstant(Object constant) { } append(")"); - var size = ((Collection) constant).size() - 1; + var size = collection.size() - 1; Path lastPath = constantPaths.peekLast(); for (var i = 0; i < size; i++) { constantPaths.add(lastPath); diff --git a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLServerTemplates.java b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLServerTemplates.java index 07adae97d5..5d6a6e692f 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLServerTemplates.java +++ b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLServerTemplates.java @@ -191,18 +191,12 @@ protected SQLServerTemplates(Set keywords, char escape, boolean quote) { @Override public String serialize(String literal, int jdbcType) { - switch (jdbcType) { - case Types.TIMESTAMP: - case TIMESTAMP_WITH_TIMEZONE: - return "{ts '" + literal + "'}"; - case Types.DATE: - return "{d '" + literal + "'}"; - case Types.TIME: - case TIME_WITH_TIMEZONE: - return "{t '" + literal + "'}"; - default: - return super.serialize(literal, jdbcType); - } + return switch (jdbcType) { + case Types.TIMESTAMP, TIMESTAMP_WITH_TIMEZONE -> "{ts '" + literal + "'}"; + case Types.DATE -> "{d '" + literal + "'}"; + case Types.TIME, TIME_WITH_TIMEZONE -> "{t '" + literal + "'}"; + default -> super.serialize(literal, jdbcType); + }; } @Override diff --git a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLTemplates.java b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLTemplates.java index 3fa2ba8004..ac995da80b 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLTemplates.java +++ b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLTemplates.java @@ -450,41 +450,34 @@ protected SQLTemplates( } public String serialize(String literal, int jdbcType) { - switch (jdbcType) { - case Types.TIMESTAMP: - case TIMESTAMP_WITH_TIMEZONE: - return "(timestamp '" + literal + "')"; - case Types.DATE: - return "(date '" + literal + "')"; - case Types.TIME: - case TIME_WITH_TIMEZONE: - return "(time '" + literal + "')"; - case Types.CHAR: - case Types.CLOB: - case Types.LONGNVARCHAR: - case Types.LONGVARCHAR: - case Types.NCHAR: - case Types.NCLOB: - case Types.NVARCHAR: - case Types.VARCHAR: - return "'" + escapeLiteral(literal) + "'"; - case Types.BIGINT: - case Types.BIT: - case Types.BOOLEAN: - case Types.DECIMAL: - case Types.DOUBLE: - case Types.FLOAT: - case Types.INTEGER: - case Types.NULL: - case Types.NUMERIC: - case Types.SMALLINT: - case Types.TINYINT: - return literal; - default: - // for other JDBC types the Type instance is expected to provide - // the necessary quoting - return literal; - } + return switch (jdbcType) { + case Types.TIMESTAMP, TIMESTAMP_WITH_TIMEZONE -> "(timestamp '" + literal + "')"; + case Types.DATE -> "(date '" + literal + "')"; + case Types.TIME, TIME_WITH_TIMEZONE -> "(time '" + literal + "')"; + case Types.CHAR, + Types.CLOB, + Types.LONGNVARCHAR, + Types.LONGVARCHAR, + Types.NCHAR, + Types.NCLOB, + Types.NVARCHAR, + Types.VARCHAR -> + "'" + escapeLiteral(literal) + "'"; + case Types.BIGINT, + Types.BIT, + Types.BOOLEAN, + Types.DECIMAL, + Types.DOUBLE, + Types.FLOAT, + Types.INTEGER, + Types.NULL, + Types.NUMERIC, + Types.SMALLINT, + Types.TINYINT -> + literal; + default -> /* for other JDBC types the Type instance is expected to provide */ /* the necessary quoting */ + literal; + }; } public String escapeLiteral(String str) { @@ -593,20 +586,14 @@ public final String getJoin() { } public final String getJoinSymbol(JoinType joinType) { - switch (joinType) { - case JOIN: - return join; - case INNERJOIN: - return innerJoin; - case FULLJOIN: - return fullJoin; - case LEFTJOIN: - return leftJoin; - case RIGHTJOIN: - return rightJoin; - default: - return crossJoin; - } + return switch (joinType) { + case JOIN -> join; + case INNERJOIN -> innerJoin; + case FULLJOIN -> fullJoin; + case LEFTJOIN -> leftJoin; + case RIGHTJOIN -> rightJoin; + default -> crossJoin; + }; } public final String getKey() { diff --git a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLTemplatesRegistry.java b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLTemplatesRegistry.java index 434aa73d91..ae6fc90abd 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLTemplatesRegistry.java +++ b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/SQLTemplatesRegistry.java @@ -48,18 +48,12 @@ public SQLTemplates.Builder getBuilder(DatabaseMetaData md) throws SQLException } else if (name.equals("postgresql")) { return PostgreSQLTemplates.builder(); } else if (name.equals("microsoft sql server")) { - switch (md.getDatabaseMajorVersion()) { - case 13: - case 12: - case 11: - return SQLServer2012Templates.builder(); - case 10: - return SQLServer2008Templates.builder(); - case 9: - return SQLServer2005Templates.builder(); - default: - return SQLServerTemplates.builder(); - } + return switch (md.getDatabaseMajorVersion()) { + case 13, 12, 11 -> SQLServer2012Templates.builder(); + case 10 -> SQLServer2008Templates.builder(); + case 9 -> SQLServer2005Templates.builder(); + default -> SQLServerTemplates.builder(); + }; } else { return new SQLTemplates.Builder() { @Override diff --git a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/dml/AbstractR2DBCDeleteClause.java b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/dml/AbstractR2DBCDeleteClause.java index e8f14317cd..5ffe87e7a9 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/dml/AbstractR2DBCDeleteClause.java +++ b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/dml/AbstractR2DBCDeleteClause.java @@ -52,9 +52,11 @@ public abstract class AbstractR2DBCDeleteClause entity; diff --git a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/group/ReactiveGroupBy.java b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/group/ReactiveGroupBy.java index e943127c74..c15df6151f 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/group/ReactiveGroupBy.java +++ b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/group/ReactiveGroupBy.java @@ -13,7 +13,7 @@ */ package com.querydsl.r2dbc.group; -import com.mysema.commons.lang.Pair; +import com.querydsl.core.Pair; import com.querydsl.core.ResultTransformer; import com.querydsl.core.group.AbstractGroupExpression; import com.querydsl.core.group.GAvg; diff --git a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/CharacterType.java b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/CharacterType.java index 9520342060..905e31e9fb 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/CharacterType.java +++ b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/CharacterType.java @@ -34,8 +34,8 @@ public CharacterType(int type) { @Override public Character getValue(Row row, int startIndex) { var val = row.get(startIndex); - if (val instanceof Character) { - return (Character) val; + if (val instanceof Character character) { + return character; } return val == null ? null : ((String) val).charAt(0); diff --git a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/DateType.java b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/DateType.java index 37565256ce..46280287d1 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/DateType.java +++ b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/DateType.java @@ -58,12 +58,12 @@ protected LocalDate toDbValue(Date value) { @Override protected Date fromDbValue(Temporal value) { - if (value instanceof LocalDate) { - return Date.valueOf((LocalDate) value); + if (value instanceof LocalDate date) { + return Date.valueOf(date); } - if (value instanceof LocalDateTime) { - return Date.valueOf(((LocalDateTime) value).toLocalDate()); + if (value instanceof LocalDateTime time) { + return Date.valueOf(time.toLocalDate()); } // mysql // if (String.class.isAssignableFrom(value.getClass())) { diff --git a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/StringAsObjectType.java b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/StringAsObjectType.java index 0b84e8ed29..c874178e73 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/StringAsObjectType.java +++ b/querydsl-libraries/querydsl-r2dbc/src/main/java/com/querydsl/r2dbc/types/StringAsObjectType.java @@ -38,8 +38,8 @@ public StringAsObjectType(int type) { @Override public String getValue(Row row, int startIndex) { var o = row.get(startIndex); - if (o instanceof String) { - return (String) o; + if (o instanceof String string) { + return string; // } else if (o instanceof Clob) { // Clob clob = (Clob) o; // return clob.stream(); diff --git a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/AbstractSQLTemplatesTest.java b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/AbstractSQLTemplatesTest.java index 0e10e7a6db..3eda879fba 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/AbstractSQLTemplatesTest.java +++ b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/AbstractSQLTemplatesTest.java @@ -83,7 +83,12 @@ public void union() { """); } else { assertThat(union.toString()) - .isEqualTo("select 1 as col1)\n" + "union\n" + "select 2\n" + "union\n" + "select 3"); + .isEqualTo(""" + select 1 as col1) + union + select 2 + union + select 3"""); } } else { var dummyTable = templates.getDummyTable(); diff --git a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/JoinFlagsTest.java b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/JoinFlagsTest.java index 816a956c6f..4a63fef388 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/JoinFlagsTest.java +++ b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/JoinFlagsTest.java @@ -50,7 +50,10 @@ public void joinFlags_beforeCondition() { query.addJoinFlag(" a ", JoinFlag.Position.BEFORE_CONDITION); assertThat(query.toString()) - .isEqualTo("from SURVEY s\n" + "inner join SURVEY s2 a \n" + "on s.ID = s2.ID"); + .isEqualTo(""" + from SURVEY s + inner join SURVEY s2 a\s + on s.ID = s2.ID"""); } @SuppressWarnings("unchecked") @@ -60,7 +63,10 @@ public void joinFlags_beforeTarget() { query.addJoinFlag(" b ", JoinFlag.Position.BEFORE_TARGET); assertThat(query.toString()) - .isEqualTo("from SURVEY s\n" + "inner join b SURVEY s3\n" + "on s.ID = s3.ID"); + .isEqualTo(""" + from SURVEY s + inner join b SURVEY s3 + on s.ID = s3.ID"""); } @SuppressWarnings("unchecked") @@ -70,7 +76,10 @@ public void joinFlags_end() { query.addJoinFlag(" c ", JoinFlag.Position.END); assertThat(query.toString()) - .isEqualTo("from SURVEY s\n" + "inner join SURVEY s4\n" + "on s.ID = s4.ID c"); + .isEqualTo(""" + from SURVEY s + inner join SURVEY s4 + on s.ID = s4.ID c"""); } @SuppressWarnings("unchecked") @@ -89,6 +98,9 @@ public void joinFlags_start() { query.addJoinFlag(" e ", JoinFlag.Position.START); assertThat(query.toString()) - .isEqualTo("from SURVEY s e \n" + "inner join SURVEY s6\n" + "on s.ID = s6.ID"); + .isEqualTo(""" + from SURVEY s e\s + inner join SURVEY s6 + on s.ID = s6.ID"""); } } diff --git a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/PostgreSQLTemplatesTest.java b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/PostgreSQLTemplatesTest.java index f65bd30cf7..057e1cca43 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/PostgreSQLTemplatesTest.java +++ b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/PostgreSQLTemplatesTest.java @@ -48,7 +48,12 @@ public void union() { R2DBCExpressions.select(two), R2DBCExpressions.select(three)); assertThat(union.toString()) - .isEqualTo("(select 1 as col1)\n" + "union\n" + "(select 2)\n" + "union\n" + "(select 3)"); + .isEqualTo(""" + (select 1 as col1) + union + (select 2) + union + (select 3)"""); } @Test diff --git a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/R2DBCMatchingFiltersFactory.java b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/R2DBCMatchingFiltersFactory.java index 139d8a1580..8d73c6e82f 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/R2DBCMatchingFiltersFactory.java +++ b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/R2DBCMatchingFiltersFactory.java @@ -97,7 +97,6 @@ public Collection date( rv.add(expr.dayOfMonth().eq(other.dayOfMonth())); if (!target.equals(Target.DERBY) - && !module.equals(QuerydslModule.JDO) && !target.equals(Target.ORACLE) && !target.equals(Target.FIREBIRD) && (!target.equals(Target.POSTGRESQL) || !module.equals(QuerydslModule.JPA))) { @@ -138,7 +137,6 @@ public Collection dateTime( rv.add(expr.dayOfMonth().eq(other.dayOfMonth())); if (!target.equals(Target.DERBY) - && !module.equals(QuerydslModule.JDO) && !target.equals(Target.ORACLE) && (!target.equals(Target.POSTGRESQL) || !module.equals(QuerydslModule.JPA))) { rv.add(expr.dayOfWeek().eq(other.dayOfWeek())); @@ -214,12 +212,10 @@ public > Collection numeric( public Collection string(StringExpression expr, StringExpression other) { var rv = new HashSet(); - if (module != QuerydslModule.LUCENE) { - rv.addAll(comparable(expr, other)); + rv.addAll(comparable(expr, other)); - rv.add(expr.charAt(0).eq(other.charAt(0))); - rv.add(expr.charAt(1).eq(other.charAt(1))); - } + rv.add(expr.charAt(0).eq(other.charAt(0))); + rv.add(expr.charAt(1).eq(other.charAt(1))); rv.add(expr.contains(other)); rv.add(expr.contains(other.substring(0, 1))); @@ -248,58 +244,50 @@ public Collection string(StringExpression expr, StringExpression othe rv.add(expr.eq(other)); rv.add(expr.equalsIgnoreCase(other)); - if (module != QuerydslModule.LUCENE) { - rv.add(expr.indexOf(other).eq(0)); - rv.add(expr.locate(other).eq(1)); - } + rv.add(expr.indexOf(other).eq(0)); + rv.add(expr.locate(other).eq(1)); - if (target != Target.DERBY && module != QuerydslModule.LUCENE) { + if (target != Target.DERBY) { rv.add(expr.indexOf(other.substring(1)).eq(1)); rv.add(expr.indexOf(other.substring(2)).eq(2)); } - if (module != QuerydslModule.LUCENE) { - rv.add(expr.isEmpty().not()); - rv.add(expr.isNotEmpty()); - } + rv.add(expr.isEmpty().not()); + rv.add(expr.isNotEmpty()); - if (module != QuerydslModule.LUCENE) { - rv.add(expr.length().eq(other.length())); - rv.add(expr.like(other)); + rv.add(expr.length().eq(other.length())); + rv.add(expr.like(other)); - if (module != QuerydslModule.JDO || other instanceof Constant) { - rv.add(expr.like(other.substring(0, 1).append("%"))); - rv.add(expr.like(other.substring(0, 1).append("%").append(other.substring(2)))); - rv.add(expr.like(other.substring(1).prepend("%"))); - rv.add(expr.like(other.substring(1, 2).append("%").prepend("%"))); - } + if (other instanceof Constant) { + rv.add(expr.like(other.substring(0, 1).append("%"))); + rv.add(expr.like(other.substring(0, 1).append("%").append(other.substring(2)))); + rv.add(expr.like(other.substring(1).prepend("%"))); + rv.add(expr.like(other.substring(1, 2).append("%").prepend("%"))); } rv.add(expr.lower().eq(other.lower())); - if (module != QuerydslModule.LUCENE) { - if (!module.equals(QuerydslModule.SQL) - || (!target.equals(Target.HSQLDB) - && !target.equals(Target.FIREBIRD) - && !target.equals(Target.H2) - && !target.equals(Target.DB2) - && !target.equals(Target.DERBY) - && !target.equals(Target.SQLITE) - && !target.equals(Target.SQLSERVER))) { - - rv.add(expr.matches(other)); - - if (module != QuerydslModule.JDO || other instanceof Constant) { - rv.add(expr.matches(other.substring(0, 1).append(".*"))); - rv.add(expr.matches(other.substring(0, 1).append(".").append(other.substring(2)))); - rv.add(expr.matches(other.substring(1).prepend(".*"))); - rv.add(expr.matches(other.substring(1, 2).prepend(".*").append(".*"))); - } + if (!module.equals(QuerydslModule.SQL) + || (!target.equals(Target.HSQLDB) + && !target.equals(Target.FIREBIRD) + && !target.equals(Target.H2) + && !target.equals(Target.DB2) + && !target.equals(Target.DERBY) + && !target.equals(Target.SQLITE) + && !target.equals(Target.SQLSERVER))) { + + rv.add(expr.matches(other)); + + if (other instanceof Constant) { + rv.add(expr.matches(other.substring(0, 1).append(".*"))); + rv.add(expr.matches(other.substring(0, 1).append(".").append(other.substring(2)))); + rv.add(expr.matches(other.substring(1).prepend(".*"))); + rv.add(expr.matches(other.substring(1, 2).prepend(".*").append(".*"))); } - - rv.add(expr.ne(other)); } + rv.add(expr.ne(other)); + rv.add(expr.startsWith(other)); rv.add(expr.startsWith(other.substring(0, 1))); rv.add(expr.startsWith(other.substring(0, 2))); @@ -308,13 +296,11 @@ public Collection string(StringExpression expr, StringExpression othe rv.add(expr.startsWithIgnoreCase(other.substring(0, 1))); rv.add(expr.startsWithIgnoreCase(other.substring(0, 2))); - if (module != QuerydslModule.LUCENE) { - rv.add(expr.substring(0, 1).eq(other.substring(0, 1))); - rv.add(expr.substring(1, 2).eq(other.substring(1, 2))); - rv.add(expr.substring(1).eq(other.substring(1))); + rv.add(expr.substring(0, 1).eq(other.substring(0, 1))); + rv.add(expr.substring(1, 2).eq(other.substring(1, 2))); + rv.add(expr.substring(1).eq(other.substring(1))); - rv.add(expr.trim().eq(other.trim())); - } + rv.add(expr.trim().eq(other.trim())); rv.add(expr.upper().eq(other.upper())); return Collections.unmodifiableSet(rv); diff --git a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/SQLServer2005TemplatesTest.java b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/SQLServer2005TemplatesTest.java index 615ef61e4b..3cf5bc6a6a 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/SQLServer2005TemplatesTest.java +++ b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/SQLServer2005TemplatesTest.java @@ -52,7 +52,12 @@ public void union() { R2DBCExpressions.select(two), R2DBCExpressions.select(three)); assertThat(union.toString()) - .isEqualTo("(select 1 as col1)\n" + "union\n" + "(select 2)\n" + "union\n" + "(select 3)"); + .isEqualTo(""" + (select 1 as col1) + union + (select 2) + union + (select 3)"""); } @Test diff --git a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/SQLServer2012TemplatesTest.java b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/SQLServer2012TemplatesTest.java index 5ed8d352c4..ba7e5c41e9 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/SQLServer2012TemplatesTest.java +++ b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/SQLServer2012TemplatesTest.java @@ -53,7 +53,12 @@ public void union() { R2DBCExpressions.select(two), R2DBCExpressions.select(three)); assertThat(union.toString()) - .isEqualTo("(select 1 as col1)\n" + "union\n" + "(select 2)\n" + "union\n" + "(select 3)"); + .isEqualTo(""" + (select 1 as col1) + union + (select 2) + union + (select 3)"""); } @Test diff --git a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/SQLServerTemplatesTest.java b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/SQLServerTemplatesTest.java index c3d524250c..9a672732bd 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/SQLServerTemplatesTest.java +++ b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/SQLServerTemplatesTest.java @@ -51,7 +51,12 @@ public void union() { R2DBCExpressions.select(two), R2DBCExpressions.select(three)); assertThat(union.toString()) - .isEqualTo("(select 1 as col1)\n" + "union\n" + "(select 2)\n" + "union\n" + "(select 3)"); + .isEqualTo(""" + (select 1 as col1) + union + (select 2) + union + (select 3)"""); } @Test diff --git a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/SelectBase.java b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/SelectBase.java index f3ae940b38..3bd38cd34c 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/SelectBase.java +++ b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/SelectBase.java @@ -37,8 +37,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.common.collect.Maps; -import com.mysema.commons.lang.Pair; import com.querydsl.core.NonUniqueResultException; +import com.querydsl.core.Pair; import com.querydsl.core.QueryException; import com.querydsl.core.QuerydslModule; import com.querydsl.core.ReactiveFetchable; diff --git a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/UnionSubQueryTest.java b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/UnionSubQueryTest.java index 990dcf46d7..ef9d90a86c 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/UnionSubQueryTest.java +++ b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/UnionSubQueryTest.java @@ -47,7 +47,10 @@ public void in_union() { serializer.handle(expr); assertThat(serializer.toString()) - .isEqualTo("intPath in ((select 1 from dual)\n" + "union\n" + "(select 2 from dual))"); + .isEqualTo(""" + intPath in ((select 1 from dual) + union + (select 2 from dual))"""); } @SuppressWarnings("unchecked") diff --git a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/types/TypeTest.java b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/types/TypeTest.java index cdcd5685f5..2714e3b802 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/types/TypeTest.java +++ b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/types/TypeTest.java @@ -15,7 +15,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import com.mysema.commons.lang.Pair; +import com.querydsl.core.Pair; import com.querydsl.r2dbc.binding.BindMarkersFactory; import com.querydsl.r2dbc.binding.BindTarget; import com.querydsl.r2dbc.binding.StatementWrapper; diff --git a/querydsl-libraries/querydsl-scala/pom.xml b/querydsl-libraries/querydsl-scala/pom.xml index c5e1a1c8ea..275fec3219 100644 --- a/querydsl-libraries/querydsl-scala/pom.xml +++ b/querydsl-libraries/querydsl-scala/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-scala diff --git a/querydsl-libraries/querydsl-spatial/pom.xml b/querydsl-libraries/querydsl-spatial/pom.xml index 49938b2d72..8e02ca46f1 100644 --- a/querydsl-libraries/querydsl-spatial/pom.xml +++ b/querydsl-libraries/querydsl-spatial/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-spatial diff --git a/querydsl-libraries/querydsl-sql-json/pom.xml b/querydsl-libraries/querydsl-sql-json/pom.xml index 742c217d2f..557f61007b 100644 --- a/querydsl-libraries/querydsl-sql-json/pom.xml +++ b/querydsl-libraries/querydsl-sql-json/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-sql-json diff --git a/querydsl-libraries/querydsl-sql-spatial/pom.xml b/querydsl-libraries/querydsl-sql-spatial/pom.xml index 7350b02295..10eb17bbee 100644 --- a/querydsl-libraries/querydsl-sql-spatial/pom.xml +++ b/querydsl-libraries/querydsl-sql-spatial/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-sql-spatial diff --git a/querydsl-libraries/querydsl-sql-spring/pom.xml b/querydsl-libraries/querydsl-sql-spring/pom.xml index 688b7a5d1d..ad7a6607c1 100644 --- a/querydsl-libraries/querydsl-sql-spring/pom.xml +++ b/querydsl-libraries/querydsl-sql-spring/pom.xml @@ -5,18 +5,13 @@ io.github.openfeign.querydsl querydsl-libraries - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-sql-spring Querydsl - SQL Spring support SQL Spring support for Querydsl - - - 17 - - org.jetbrains diff --git a/querydsl-libraries/querydsl-sql/pom.xml b/querydsl-libraries/querydsl-sql/pom.xml index 8580a12a52..76fdf3e0e0 100644 --- a/querydsl-libraries/querydsl-sql/pom.xml +++ b/querydsl-libraries/querydsl-sql/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-sql diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/AbstractSQLQuery.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/AbstractSQLQuery.java index 283abcfb51..109be7e45f 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/AbstractSQLQuery.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/AbstractSQLQuery.java @@ -13,7 +13,7 @@ */ package com.querydsl.sql; -import com.mysema.commons.lang.CloseableIterator; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.DefaultQueryMetadata; import com.querydsl.core.QueryException; import com.querydsl.core.QueryFlag; @@ -518,8 +518,8 @@ public QueryResults fetchResults() { } long total; if (!results.isEmpty()) { - if (lastCell instanceof Number) { - total = ((Number) lastCell).longValue(); + if (lastCell instanceof Number number) { + total = number.longValue(); } else { throw new IllegalStateException("Unsupported lastCell instance " + lastCell); } diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/CUBRIDTemplates.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/CUBRIDTemplates.java index 99aa0a157a..b7c9e51124 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/CUBRIDTemplates.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/CUBRIDTemplates.java @@ -118,16 +118,12 @@ public CUBRIDTemplates(char escape, boolean quote) { @Override public String serialize(String literal, int jdbcType) { - switch (jdbcType) { - case Types.TIMESTAMP: - return "timestamp'" + literal + "'"; - case Types.DATE: - return "date'" + literal + "'"; - case Types.TIME: - return "time'" + literal + "'"; - default: - return super.serialize(literal, jdbcType); - } + return switch (jdbcType) { + case Types.TIMESTAMP -> "timestamp'" + literal + "'"; + case Types.DATE -> "date'" + literal + "'"; + case Types.TIME -> "time'" + literal + "'"; + default -> super.serialize(literal, jdbcType); + }; } @Override diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/ColumnMetadata.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/ColumnMetadata.java index b9b0af225f..84421c0866 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/ColumnMetadata.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/ColumnMetadata.java @@ -15,13 +15,14 @@ import com.querydsl.core.types.EntityPath; import com.querydsl.core.types.Path; +import java.io.Serial; import java.io.Serializable; import java.util.Objects; /** Provides metadata like the column name, JDBC type and constraints */ public final class ColumnMetadata implements Serializable { - private static final long serialVersionUID = -5678865742525938470L; + @Serial private static final long serialVersionUID = -5678865742525938470L; /** * Returns this path's column metadata if present. Otherwise returns default metadata where the @@ -31,8 +32,8 @@ public static ColumnMetadata getColumnMetadata(Path path) { Path parent = path.getMetadata().getParent(); if (parent instanceof EntityPath) { var columnMetadata = ((EntityPath) parent).getMetadata(path); - if (columnMetadata instanceof ColumnMetadata) { - return (ColumnMetadata) columnMetadata; + if (columnMetadata instanceof ColumnMetadata metadata) { + return metadata; } } return ColumnMetadata.named(path.getMetadata().getName()); @@ -49,8 +50,8 @@ public static String getName(Path path) { Path parent = path.getMetadata().getParent(); if (parent instanceof EntityPath) { var columnMetadata = ((EntityPath) parent).getMetadata(path); - if (columnMetadata instanceof ColumnMetadata) { - return ((ColumnMetadata) columnMetadata).getName(); + if (columnMetadata instanceof ColumnMetadata metadata) { + return metadata.getName(); } } return path.getMetadata().getName(); @@ -161,8 +162,7 @@ public ColumnMetadata withDigits(int decimalDigits) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof ColumnMetadata) { - var md = (ColumnMetadata) o; + } else if (o instanceof ColumnMetadata md) { return name.equals(md.name) && Objects.equals(jdbcType, md.jdbcType) && nullable == md.nullable diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/DB2Templates.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/DB2Templates.java index 788947cf50..445b87f6a2 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/DB2Templates.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/DB2Templates.java @@ -149,12 +149,10 @@ public DB2Templates(char escape, boolean quote) { @Override public String getCastTypeNameForCode(int code) { - switch (code) { - case Types.VARCHAR: - return "varchar(4000)"; - default: - return super.getCastTypeNameForCode(code); - } + return switch (code) { + case Types.VARCHAR -> "varchar(4000)"; + default -> super.getCastTypeNameForCode(code); + }; } @Override diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/DerbyTemplates.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/DerbyTemplates.java index 76757ea955..1f86cdaa28 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/DerbyTemplates.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/DerbyTemplates.java @@ -131,20 +131,13 @@ public DerbyTemplates(char escape, boolean quote) { @Override public String serialize(String literal, int jdbcType) { - switch (jdbcType) { - case Types.BOOLEAN: - return "1".equals(literal) ? "true" : "false"; - case Types.TIMESTAMP: - case TIMESTAMP_WITH_TIMEZONE: - return "{ts '" + literal + "'}"; - case Types.DATE: - return "{d '" + literal + "'}"; - case Types.TIME: - case TIME_WITH_TIMEZONE: - return "{t '" + literal + "'}"; - default: - return super.serialize(literal, jdbcType); - } + return switch (jdbcType) { + case Types.BOOLEAN -> "1".equals(literal) ? "true" : "false"; + case Types.TIMESTAMP, TIMESTAMP_WITH_TIMEZONE -> "{ts '" + literal + "'}"; + case Types.DATE -> "{d '" + literal + "'}"; + case Types.TIME, TIME_WITH_TIMEZONE -> "{t '" + literal + "'}"; + default -> super.serialize(literal, jdbcType); + }; } @Override diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/ForeignKey.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/ForeignKey.java index 44f26d5e76..e5d9f31ded 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/ForeignKey.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/ForeignKey.java @@ -26,6 +26,7 @@ import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.core.types.dsl.Expressions; import com.querydsl.core.util.CollectionUtils; +import java.io.Serial; import java.io.Serializable; import java.util.Collections; import java.util.List; @@ -40,7 +41,7 @@ @Immutable public final class ForeignKey implements Serializable, ProjectionRole { - private static final long serialVersionUID = 2260578033772289023L; + @Serial private static final long serialVersionUID = 2260578033772289023L; private final RelationalPath entity; diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/H2Templates.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/H2Templates.java index 0b22fcb152..117aaa2f0d 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/H2Templates.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/H2Templates.java @@ -89,13 +89,10 @@ public H2Templates(char escape, boolean quote) { @Override public String serialize(String literal, int jdbcType) { - switch (jdbcType) { - case TIMESTAMP_WITH_TIMEZONE: - return "(timestamp with time zone '" + literal + "')"; - case TIME_WITH_TIMEZONE: - return "(time with time zone '" + literal + "')"; - default: - return super.serialize(literal, jdbcType); - } + return switch (jdbcType) { + case TIMESTAMP_WITH_TIMEZONE -> "(timestamp with time zone '" + literal + "')"; + case TIME_WITH_TIMEZONE -> "(time with time zone '" + literal + "')"; + default -> super.serialize(literal, jdbcType); + }; } } diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/JDBCTypeMapping.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/JDBCTypeMapping.java index af02dae9cb..b11698c0ab 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/JDBCTypeMapping.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/JDBCTypeMapping.java @@ -13,7 +13,7 @@ */ package com.querydsl.sql; -import com.mysema.commons.lang.Pair; +import com.querydsl.core.Pair; import com.querydsl.sql.types.Null; import java.math.BigDecimal; import java.math.BigInteger; diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/MySQLTemplates.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/MySQLTemplates.java index 8144d0bb19..9cd368ccb8 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/MySQLTemplates.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/MySQLTemplates.java @@ -174,21 +174,11 @@ public String escapeLiteral(String str) { @Override public String getCastTypeNameForCode(int code) { - switch (code) { - case Types.TINYINT: - case Types.SMALLINT: - case Types.INTEGER: - case Types.BIGINT: - return "signed"; - case Types.FLOAT: - case Types.DOUBLE: - case Types.REAL: - case Types.DECIMAL: - return "decimal"; - case Types.VARCHAR: - return "char"; - default: - return super.getCastTypeNameForCode(code); - } + return switch (code) { + case Types.TINYINT, Types.SMALLINT, Types.INTEGER, Types.BIGINT -> "signed"; + case Types.FLOAT, Types.DOUBLE, Types.REAL, Types.DECIMAL -> "decimal"; + case Types.VARCHAR -> "char"; + default -> super.getCastTypeNameForCode(code); + }; } } diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/OracleTemplates.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/OracleTemplates.java index 2c73604459..d5bb5357a1 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/OracleTemplates.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/OracleTemplates.java @@ -167,30 +167,21 @@ public OracleTemplates(char escape, boolean quote) { @Override public String getCastTypeNameForCode(int code) { - switch (code) { - case Types.DOUBLE: - return "double precision"; - case Types.VARCHAR: - return "varchar(4000 char)"; - default: - return super.getCastTypeNameForCode(code); - } + return switch (code) { + case Types.DOUBLE -> "double precision"; + case Types.VARCHAR -> "varchar(4000 char)"; + default -> super.getCastTypeNameForCode(code); + }; } @Override public String serialize(String literal, int jdbcType) { - switch (jdbcType) { - case Types.TIMESTAMP: - case TIMESTAMP_WITH_TIMEZONE: - return "timestamp '" + literal + "'"; - case Types.DATE: - return "date '" + literal + "'"; - case Types.TIME: - case TIME_WITH_TIMEZONE: - return "timestamp '1970-01-01 " + literal + "'"; - default: - return super.serialize(literal, jdbcType); - } + return switch (jdbcType) { + case Types.TIMESTAMP, TIMESTAMP_WITH_TIMEZONE -> "timestamp '" + literal + "'"; + case Types.DATE -> "date '" + literal + "'"; + case Types.TIME, TIME_WITH_TIMEZONE -> "timestamp '1970-01-01 " + literal + "'"; + default -> super.serialize(literal, jdbcType); + }; } @Override diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/PrimaryKey.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/PrimaryKey.java index 30f6ca7a73..e213c4b0fa 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/PrimaryKey.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/PrimaryKey.java @@ -24,6 +24,7 @@ import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.core.types.dsl.Expressions; import com.querydsl.core.util.CollectionUtils; +import java.io.Serial; import java.io.Serializable; import java.util.Arrays; import java.util.List; @@ -38,7 +39,7 @@ @Immutable public final class PrimaryKey implements Serializable, ProjectionRole { - private static final long serialVersionUID = -6913344535043394649L; + @Serial private static final long serialVersionUID = -6913344535043394649L; private final RelationalPath entity; diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/RelationalPathBase.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/RelationalPathBase.java index e096ca3051..f983a1339a 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/RelationalPathBase.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/RelationalPathBase.java @@ -142,8 +142,8 @@ public NumberExpression countDistinct() { */ @Override public BooleanExpression eq(T right) { - if (right instanceof RelationalPath) { - return primaryKeyOperation(Ops.EQ, primaryKey, ((RelationalPath) right).getPrimaryKey()); + if (right instanceof RelationalPath path) { + return primaryKeyOperation(Ops.EQ, primaryKey, path.getPrimaryKey()); } else { return super.eq(right); } @@ -157,8 +157,8 @@ public BooleanExpression eq(T right) { */ @Override public BooleanExpression eq(Expression right) { - if (right instanceof RelationalPath) { - return primaryKeyOperation(Ops.EQ, primaryKey, ((RelationalPath) right).getPrimaryKey()); + if (right instanceof RelationalPath path) { + return primaryKeyOperation(Ops.EQ, primaryKey, path.getPrimaryKey()); } else { return super.eq(right); } @@ -172,8 +172,8 @@ public BooleanExpression eq(Expression right) { */ @Override public BooleanExpression ne(T right) { - if (right instanceof RelationalPath) { - return primaryKeyOperation(Ops.NE, primaryKey, ((RelationalPath) right).getPrimaryKey()); + if (right instanceof RelationalPath path) { + return primaryKeyOperation(Ops.NE, primaryKey, path.getPrimaryKey()); } else { return super.ne(right); } @@ -187,8 +187,8 @@ public BooleanExpression ne(T right) { */ @Override public BooleanExpression ne(Expression right) { - if (right instanceof RelationalPath) { - return primaryKeyOperation(Ops.NE, primaryKey, ((RelationalPath) right).getPrimaryKey()); + if (right instanceof RelationalPath path) { + return primaryKeyOperation(Ops.NE, primaryKey, path.getPrimaryKey()); } else { return super.ne(right); } diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/RelationalPathExtractor.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/RelationalPathExtractor.java index efb9eacdc3..a624addc04 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/RelationalPathExtractor.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/RelationalPathExtractor.java @@ -95,8 +95,8 @@ public Set> visit(ParamExpression expr, Set> visit(Path expr, Set> known) { if (expr.getMetadata().isRoot()) { - if (expr instanceof RelationalPath) { - known = add(known, (RelationalPath) expr); + if (expr instanceof RelationalPath path) { + known = add(known, path); } } else { known = expr.getMetadata().getParent().accept(this, known); diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLListenerAdapter.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLListenerAdapter.java index 762ac694fd..2a7e443676 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLListenerAdapter.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLListenerAdapter.java @@ -35,8 +35,7 @@ class SQLListenerAdapter implements SQLDetailedListener { private final SQLDetailedListener detailedListener; SQLListenerAdapter(final SQLListener sqlListener) { - this.detailedListener = - sqlListener instanceof SQLDetailedListener ? (SQLDetailedListener) sqlListener : null; + this.detailedListener = sqlListener instanceof SQLDetailedListener sqldl ? sqldl : null; this.sqlListener = sqlListener; } diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLListeners.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLListeners.java index 40dc389869..3a40677157 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLListeners.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLListeners.java @@ -50,12 +50,12 @@ public SQLListeners() { } public void add(SQLListener listener) { - if (listener instanceof SQLListeners) { - for (SQLListener l : ((SQLListeners) listener).listeners) { + if (listener instanceof SQLListeners lListeners) { + for (SQLListener l : lListeners.listeners) { add(l); } - } else if (listener instanceof SQLDetailedListener) { - listeners.add((SQLDetailedListener) listener); + } else if (listener instanceof SQLDetailedListener detailedListener) { + listeners.add(detailedListener); } else { listeners.add(new SQLListenerAdapter(listener)); } diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLResultIterator.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLResultIterator.java index d1385df9c4..4326a16dee 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLResultIterator.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLResultIterator.java @@ -13,7 +13,7 @@ */ package com.querydsl.sql; -import com.mysema.commons.lang.CloseableIterator; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.QueryException; import java.sql.ResultSet; import java.sql.SQLException; diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLSerializer.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLSerializer.java index 033692a212..9672580677 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLSerializer.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLSerializer.java @@ -607,14 +607,12 @@ public void serializeForMergeUsing( append("\nusing "); // A hacky way to allow merging table to table directly - if (usingExpression instanceof RelationalPath) { + if (usingExpression instanceof RelationalPath path) { dmlWithSchema = true; // If table has an alias, handle both original table name and alias - if (!((RelationalPath) usingExpression) - .getTableName() - .equals(ColumnMetadata.getName((RelationalPath) usingExpression))) { + if (!path.getTableName().equals(ColumnMetadata.getName(path))) { RelationalPath originalEntity = this.entity; - this.entity = (RelationalPath) usingExpression; + this.entity = path; handle(usingExpression); append(" "); this.entity = originalEntity; @@ -936,10 +934,10 @@ public void serializeUnion(Expression union, QueryMetadata metadata, boolean @Override public void visitConstant(Object constant) { if (useLiterals) { - if (constant instanceof Collection) { + if (constant instanceof Collection collection) { append("("); var first = true; - for (Object o : ((Collection) constant)) { + for (Object o : collection) { if (!first) { append(COMMA); } @@ -950,10 +948,10 @@ public void visitConstant(Object constant) { } else { append(configuration.asLiteral(constant)); } - } else if (constant instanceof Collection) { + } else if (constant instanceof Collection collection) { append("("); var first = true; - for (Object o : ((Collection) constant)) { + for (Object o : collection) { if (!first) { append(COMMA); } @@ -966,7 +964,7 @@ public void visitConstant(Object constant) { } append(")"); - var size = ((Collection) constant).size() - 1; + var size = collection.size() - 1; Path lastPath = constantPaths.peekLast(); for (var i = 0; i < size; i++) { constantPaths.add(lastPath); @@ -1007,8 +1005,8 @@ protected void serializeConstant(int parameterIndex, String constantLabel) { @Override public Void visit(Path path, Void context) { if (dml) { - if (path.equals(entity) && path instanceof RelationalPath) { - var schemaAndTable = getSchemaAndTable((RelationalPath) path); + if (path.equals(entity) && path instanceof RelationalPath relationalPath) { + var schemaAndTable = getSchemaAndTable(relationalPath); boolean precededByDot; if (dmlWithSchema && templates.isPrintSchema()) { appendSchemaName(schemaAndTable.getSchema()); diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLServerTemplates.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLServerTemplates.java index a90aef7cce..3dde8ac213 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLServerTemplates.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLServerTemplates.java @@ -189,19 +189,13 @@ protected SQLServerTemplates(Set keywords, char escape, boolean quote) { @Override public String serialize(String literal, int jdbcType) { - switch (jdbcType) { - case Types.TIMESTAMP: - return "CAST('" + literal + "' AS DATETIME2)"; - case TIMESTAMP_WITH_TIMEZONE: - return "CAST('" + literal + "' AS DATETIMEOFFSET)"; - case Types.DATE: - return "CAST('" + literal + "' AS DATE)"; - case Types.TIME: - case TIME_WITH_TIMEZONE: - return "CAST('" + literal + "' AS TIME)"; - default: - return super.serialize(literal, jdbcType); - } + return switch (jdbcType) { + case Types.TIMESTAMP -> "CAST('" + literal + "' AS DATETIME2)"; + case TIMESTAMP_WITH_TIMEZONE -> "CAST('" + literal + "' AS DATETIMEOFFSET)"; + case Types.DATE -> "CAST('" + literal + "' AS DATE)"; + case Types.TIME, TIME_WITH_TIMEZONE -> "CAST('" + literal + "' AS TIME)"; + default -> super.serialize(literal, jdbcType); + }; } @Override diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLTemplates.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLTemplates.java index 09e13a82e3..6be096975f 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLTemplates.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLTemplates.java @@ -467,41 +467,34 @@ protected SQLTemplates( } public String serialize(String literal, int jdbcType) { - switch (jdbcType) { - case Types.TIMESTAMP: - case TIMESTAMP_WITH_TIMEZONE: - return "(timestamp '" + literal + "')"; - case Types.DATE: - return "(date '" + literal + "')"; - case Types.TIME: - case TIME_WITH_TIMEZONE: - return "(time '" + literal + "')"; - case Types.CHAR: - case Types.CLOB: - case Types.LONGNVARCHAR: - case Types.LONGVARCHAR: - case Types.NCHAR: - case Types.NCLOB: - case Types.NVARCHAR: - case Types.VARCHAR: - return "'" + escapeLiteral(literal) + "'"; - case Types.BIGINT: - case Types.BIT: - case Types.BOOLEAN: - case Types.DECIMAL: - case Types.DOUBLE: - case Types.FLOAT: - case Types.INTEGER: - case Types.NULL: - case Types.NUMERIC: - case Types.SMALLINT: - case Types.TINYINT: - return literal; - default: - // for other JDBC types the Type instance is expected to provide - // the necessary quoting - return literal; - } + return switch (jdbcType) { + case Types.TIMESTAMP, TIMESTAMP_WITH_TIMEZONE -> "(timestamp '" + literal + "')"; + case Types.DATE -> "(date '" + literal + "')"; + case Types.TIME, TIME_WITH_TIMEZONE -> "(time '" + literal + "')"; + case Types.CHAR, + Types.CLOB, + Types.LONGNVARCHAR, + Types.LONGVARCHAR, + Types.NCHAR, + Types.NCLOB, + Types.NVARCHAR, + Types.VARCHAR -> + "'" + escapeLiteral(literal) + "'"; + case Types.BIGINT, + Types.BIT, + Types.BOOLEAN, + Types.DECIMAL, + Types.DOUBLE, + Types.FLOAT, + Types.INTEGER, + Types.NULL, + Types.NUMERIC, + Types.SMALLINT, + Types.TINYINT -> + literal; + default -> /* for other JDBC types the Type instance is expected to provide */ /* the necessary quoting */ + literal; + }; } public String escapeLiteral(String str) { @@ -610,20 +603,14 @@ public final String getJoin() { } public final String getJoinSymbol(JoinType joinType) { - switch (joinType) { - case JOIN: - return join; - case INNERJOIN: - return innerJoin; - case FULLJOIN: - return fullJoin; - case LEFTJOIN: - return leftJoin; - case RIGHTJOIN: - return rightJoin; - default: - return crossJoin; - } + return switch (joinType) { + case JOIN -> join; + case INNERJOIN -> innerJoin; + case FULLJOIN -> fullJoin; + case LEFTJOIN -> leftJoin; + case RIGHTJOIN -> rightJoin; + default -> crossJoin; + }; } public final String getKey() { diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLiteTemplates.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLiteTemplates.java index db20254ebf..edc2a8cbdf 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLiteTemplates.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLiteTemplates.java @@ -113,8 +113,10 @@ public SQLiteTemplates(char escape, boolean quote) { add( Ops.DateTimeOps.YEAR_MONTH, - "cast(strftime('%Y',{0} / 1000, 'unixepoch', 'localtime') * 100 + strftime('%m',{0} / 1000," - + " 'unixepoch', 'localtime') as integer)"); + """ + cast(strftime('%Y',{0} / 1000, 'unixepoch', 'localtime') * 100 + strftime('%m',{0} / 1000,\ + 'unixepoch', 'localtime') as integer)\ + """); add( Ops.DateTimeOps.YEAR_WEEK, "cast(strftime('%Y%W',{0} / 1000, 'unixepoch', 'localtime') as integer)"); @@ -140,27 +142,24 @@ public SQLiteTemplates(char escape, boolean quote) { @Override public String serialize(String literal, int jdbcType) { // XXX doesn't work with LocalDate, LocalDateTime and LocalTime - switch (jdbcType) { - case Types.TIMESTAMP: - case TIMESTAMP_WITH_TIMEZONE: - return String.valueOf( - dateTimeFormatter - .parse(literal, LocalDateTime::from) - .toInstant(ZoneOffset.UTC) - .toEpochMilli()); - case Types.DATE: - return String.valueOf( - dateFormatter - .parse(literal, LocalDate::from) - .atStartOfDay(ZoneOffset.UTC) - .toInstant() - .toEpochMilli()); - case Types.TIME: - case TIME_WITH_TIMEZONE: - return String.valueOf( - timeFormatter.parse(literal, LocalTime::from).get(ChronoField.MILLI_OF_DAY)); - default: - return super.serialize(literal, jdbcType); - } + return switch (jdbcType) { + case Types.TIMESTAMP, TIMESTAMP_WITH_TIMEZONE -> + String.valueOf( + dateTimeFormatter + .parse(literal, LocalDateTime::from) + .toInstant(ZoneOffset.UTC) + .toEpochMilli()); + case Types.DATE -> + String.valueOf( + dateFormatter + .parse(literal, LocalDate::from) + .atStartOfDay(ZoneOffset.UTC) + .toInstant() + .toEpochMilli()); + case Types.TIME, TIME_WITH_TIMEZONE -> + String.valueOf( + timeFormatter.parse(literal, LocalTime::from).get(ChronoField.MILLI_OF_DAY)); + default -> super.serialize(literal, jdbcType); + }; } } diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SchemaAndTable.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SchemaAndTable.java index 7907d5068e..b0f3a771a7 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SchemaAndTable.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SchemaAndTable.java @@ -38,8 +38,7 @@ public String getTable() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof SchemaAndTable) { - var st = (SchemaAndTable) o; + } else if (o instanceof SchemaAndTable st) { return Objects.equals(st.schema, schema) && Objects.equals(st.table, table); } else { return false; diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/TeradataTemplates.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/TeradataTemplates.java index 20fed92668..024fe0a2f0 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/TeradataTemplates.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/TeradataTemplates.java @@ -118,12 +118,10 @@ public TeradataTemplates(char escape, boolean quote) { @Override public String getCastTypeNameForCode(int code) { - switch (code) { - case Types.VARCHAR: - return "varchar(4000)"; - default: - return super.getCastTypeNameForCode(code); - } + return switch (code) { + case Types.VARCHAR -> "varchar(4000)"; + default -> super.getCastTypeNameForCode(code); + }; } @Override diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/Union.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/Union.java index ae14fb9745..6ed4c2441b 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/Union.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/Union.java @@ -13,7 +13,7 @@ */ package com.querydsl.sql; -import com.mysema.commons.lang.CloseableIterator; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.Fetchable; import com.querydsl.core.types.Expression; import com.querydsl.core.types.OrderSpecifier; diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/UnionImpl.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/UnionImpl.java index bc53a62d97..7750ad56e5 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/UnionImpl.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/UnionImpl.java @@ -13,7 +13,7 @@ */ package com.querydsl.sql; -import com.mysema.commons.lang.CloseableIterator; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.NonUniqueResultException; import com.querydsl.core.Query; import com.querydsl.core.QueryMetadata; diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/WindowFunction.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/WindowFunction.java index 91864c7843..bb9d11442d 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/WindowFunction.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/WindowFunction.java @@ -121,8 +121,7 @@ public R accept(Visitor v, C context) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof WindowFunction) { - WindowFunction so = (WindowFunction) o; + } else if (o instanceof WindowFunction so) { return so.target.equals(target) && so.partitionBy.equals(partitionBy) && so.orderBy.equals(orderBy); diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/ddl/CreateTableClause.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/ddl/CreateTableClause.java index 32c2f3e7c3..a138a2363f 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/ddl/CreateTableClause.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/ddl/CreateTableClause.java @@ -103,7 +103,7 @@ public CreateTableClause autoIncrement() { * @return */ public CreateTableClause primaryKey(String name, String... columns) { - for (int i = 0; i < columns.length; i++) { + for (var i = 0; i < columns.length; i++) { columns[i] = templates.quoteIdentifier(columns[i]); } primaryKey = new PrimaryKeyData(templates.quoteIdentifier(name), columns); diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/dml/AbstractSQLDeleteClause.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/dml/AbstractSQLDeleteClause.java index e6f3e3673e..9cb702c1f7 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/dml/AbstractSQLDeleteClause.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/dml/AbstractSQLDeleteClause.java @@ -52,9 +52,11 @@ public abstract class AbstractSQLDeleteClause entity; diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/StringAsObjectType.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/StringAsObjectType.java index a97b943a28..cb1268e928 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/StringAsObjectType.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/StringAsObjectType.java @@ -39,10 +39,9 @@ public StringAsObjectType(int type) { @Override public String getValue(ResultSet rs, int startIndex) throws SQLException { var o = rs.getObject(startIndex); - if (o instanceof String) { - return (String) o; - } else if (o instanceof Clob) { - var clob = (Clob) o; + if (o instanceof String string) { + return string; + } else if (o instanceof Clob clob) { return clob.getSubString(1, (int) clob.length()); } else if (o != null) { return o.toString(); diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/AbstractSQLTemplatesTest.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/AbstractSQLTemplatesTest.java index 998e98e25e..8b93fc18b1 100644 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/AbstractSQLTemplatesTest.java +++ b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/AbstractSQLTemplatesTest.java @@ -80,7 +80,12 @@ public void union() { """); } else { assertThat(union.toString()) - .isEqualTo("select 1 as col1)\n" + "union\n" + "select 2\n" + "union\n" + "select 3"); + .isEqualTo(""" + select 1 as col1) + union + select 2 + union + select 3"""); } } else { var dummyTable = templates.getDummyTable(); diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ExtendedSQLQuery.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ExtendedSQLQuery.java index df4434992c..76728d6843 100644 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ExtendedSQLQuery.java +++ b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ExtendedSQLQuery.java @@ -13,7 +13,7 @@ */ package com.querydsl.sql; -import com.mysema.commons.lang.CloseableIterator; +import com.querydsl.core.CloseableIterator; import com.querydsl.core.DefaultQueryMetadata; import com.querydsl.core.QueryMetadata; import com.querydsl.core.QueryResults; diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/JoinFlagsTest.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/JoinFlagsTest.java index 692a222194..23e0d2c332 100644 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/JoinFlagsTest.java +++ b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/JoinFlagsTest.java @@ -50,7 +50,10 @@ public void joinFlags_beforeCondition() { query.addJoinFlag(" a ", JoinFlag.Position.BEFORE_CONDITION); assertThat(query.toString()) - .isEqualTo("from SURVEY s\n" + "inner join SURVEY s2 a \n" + "on s.ID = s2.ID"); + .isEqualTo(""" + from SURVEY s + inner join SURVEY s2 a\s + on s.ID = s2.ID"""); } @SuppressWarnings("unchecked") @@ -60,7 +63,10 @@ public void joinFlags_beforeTarget() { query.addJoinFlag(" b ", JoinFlag.Position.BEFORE_TARGET); assertThat(query.toString()) - .isEqualTo("from SURVEY s\n" + "inner join b SURVEY s3\n" + "on s.ID = s3.ID"); + .isEqualTo(""" + from SURVEY s + inner join b SURVEY s3 + on s.ID = s3.ID"""); } @SuppressWarnings("unchecked") @@ -70,7 +76,10 @@ public void joinFlags_end() { query.addJoinFlag(" c ", JoinFlag.Position.END); assertThat(query.toString()) - .isEqualTo("from SURVEY s\n" + "inner join SURVEY s4\n" + "on s.ID = s4.ID c"); + .isEqualTo(""" + from SURVEY s + inner join SURVEY s4 + on s.ID = s4.ID c"""); } @SuppressWarnings("unchecked") @@ -89,6 +98,9 @@ public void joinFlags_start() { query.addJoinFlag(" e ", JoinFlag.Position.START); assertThat(query.toString()) - .isEqualTo("from SURVEY s e \n" + "inner join SURVEY s6\n" + "on s.ID = s6.ID"); + .isEqualTo(""" + from SURVEY s e\s + inner join SURVEY s6 + on s.ID = s6.ID"""); } } diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/PostgreSQLTemplatesTest.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/PostgreSQLTemplatesTest.java index f8d4107cc3..53ff4038e8 100644 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/PostgreSQLTemplatesTest.java +++ b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/PostgreSQLTemplatesTest.java @@ -45,7 +45,12 @@ public void union() { Path col1 = Expressions.path(Integer.class, "col1"); Union union = query.union(select(one.as(col1)), select(two), select(three)); assertThat(union.toString()) - .isEqualTo("(select 1 as col1)\n" + "union\n" + "(select 2)\n" + "union\n" + "(select 3)"); + .isEqualTo(""" + (select 1 as col1) + union + (select 2) + union + (select 3)"""); } @Test diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SQLServer2005TemplatesTest.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SQLServer2005TemplatesTest.java index 27d06f41e7..6b7b5c6244 100644 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SQLServer2005TemplatesTest.java +++ b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SQLServer2005TemplatesTest.java @@ -48,7 +48,12 @@ public void union() { Path col1 = Expressions.path(Integer.class, "col1"); Union union = query.union(select(one.as(col1)), select(two), select(three)); assertThat(union.toString()) - .isEqualTo("(select 1 as col1)\n" + "union\n" + "(select 2)\n" + "union\n" + "(select 3)"); + .isEqualTo(""" + (select 1 as col1) + union + (select 2) + union + (select 3)"""); } @Test diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SQLServer2012TemplatesTest.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SQLServer2012TemplatesTest.java index ec43169438..2b88ac50dd 100644 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SQLServer2012TemplatesTest.java +++ b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SQLServer2012TemplatesTest.java @@ -49,7 +49,12 @@ public void union() { Path col1 = Expressions.path(Integer.class, "col1"); Union union = query.union(select(one.as(col1)), select(two), select(three)); assertThat(union.toString()) - .isEqualTo("(select 1 as col1)\n" + "union\n" + "(select 2)\n" + "union\n" + "(select 3)"); + .isEqualTo(""" + (select 1 as col1) + union + (select 2) + union + (select 3)"""); } @Test diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SQLServerTemplatesTest.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SQLServerTemplatesTest.java index 2346d981bd..d0a3be9d6d 100644 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SQLServerTemplatesTest.java +++ b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SQLServerTemplatesTest.java @@ -47,7 +47,12 @@ public void union() { Path col1 = Expressions.path(Integer.class, "col1"); Union union = query.union(select(one.as(col1)), select(two), select(three)); assertThat(union.toString()) - .isEqualTo("(select 1 as col1)\n" + "union\n" + "(select 2)\n" + "union\n" + "(select 3)"); + .isEqualTo(""" + (select 1 as col1) + union + (select 2) + union + (select 3)"""); } @Test diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SQLiteTemplatesTest.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SQLiteTemplatesTest.java index 12a135774d..9baa1a0059 100644 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SQLiteTemplatesTest.java +++ b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SQLiteTemplatesTest.java @@ -38,7 +38,12 @@ public void union() { Union union = query.union(select(one.as(col1)), select(two), select(three)); assertThat(union.toString()) - .isEqualTo("select 1 as col1\n" + "union\n" + "select 2\n" + "union\n" + "select 3"); + .isEqualTo(""" + select 1 as col1 + union + select 2 + union + select 3"""); } @Test diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SelectBase.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SelectBase.java index 07f62de23e..1900fc2c7f 100644 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SelectBase.java +++ b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/SelectBase.java @@ -38,9 +38,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import com.mysema.commons.lang.Pair; import com.querydsl.core.Fetchable; import com.querydsl.core.NonUniqueResultException; +import com.querydsl.core.Pair; import com.querydsl.core.QueryException; import com.querydsl.core.QueryExecution; import com.querydsl.core.QuerydslModule; @@ -579,19 +579,11 @@ private void dates(boolean literals) throws SQLException { // have to explicitly list these // connection.getMetaData().getTypeInfo() is not helpful in this case for most drivers - boolean supportsTimeZones; - switch (target) { - case FIREBIRD: - case H2: - case HSQLDB: - case ORACLE: - case SQLSERVER: - supportsTimeZones = true; - break; - default: - supportsTimeZones = false; - break; - } + boolean supportsTimeZones = + switch (target) { + case FIREBIRD, H2, HSQLDB, ORACLE, SQLSERVER -> true; + default -> false; + }; if (supportsTimeZones) { // java.time.OffsetTime // SQL Server does not support TIME WITH TIME ZONE diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/UnionSubQueryTest.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/UnionSubQueryTest.java index 13669b373b..f4be522292 100644 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/UnionSubQueryTest.java +++ b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/UnionSubQueryTest.java @@ -48,7 +48,10 @@ public void in_union() { serializer.handle(expr); assertThat(serializer.toString()) - .isEqualTo("intPath in ((select 1 from dual)\n" + "union\n" + "(select 2 from dual))"); + .isEqualTo(""" + intPath in ((select 1 from dual) + union + (select 2 from dual))"""); } @SuppressWarnings("unchecked") diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/types/TypeTest.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/types/TypeTest.java index 02953cb216..b50135c6cf 100644 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/types/TypeTest.java +++ b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/types/TypeTest.java @@ -15,7 +15,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import com.mysema.commons.lang.Pair; +import com.querydsl.core.Pair; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; diff --git a/querydsl-tooling/pom.xml b/querydsl-tooling/pom.xml index 23e1fdfcbc..827d483c6a 100644 --- a/querydsl-tooling/pom.xml +++ b/querydsl-tooling/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-root - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-tooling diff --git a/querydsl-tooling/querydsl-apt/pom.xml b/querydsl-tooling/querydsl-apt/pom.xml index f5003452ff..f381f0d200 100644 --- a/querydsl-tooling/querydsl-apt/pom.xml +++ b/querydsl-tooling/querydsl-apt/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-tooling - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-apt @@ -34,31 +34,6 @@ - - org.datanucleus - javax.jdo - provided - - - org.springframework.roo - org.springframework.roo.annotations - 1.3.2.RELEASE - provided - - - org.apache.commons - commons-lang3 - - - commons-io - commons-io - - - commons-codec - commons-codec - - - org.mongodb.morphia morphia @@ -160,10 +135,8 @@ src/main/general.xml src/main/hibernate.xml src/main/jakarta.xml - src/main/jdo.xml src/main/jpa.xml src/main/morphia.xml - src/main/roo.xml src/main/onejar.xml ${project.build.directory} @@ -189,8 +162,6 @@ com.querydsl.apt.QuerydslAnnotationProcessor com.querydsl.apt.hibernate.HibernateAnnotationProcessor - com.querydsl.apt.jdo.JDOAnnotationProcessor - com.querydsl.apt.roo.RooAnnotationProcessor diff --git a/querydsl-tooling/querydsl-apt/src/apt/jdo/META-INF/services/javax.annotation.processing.Processor b/querydsl-tooling/querydsl-apt/src/apt/jdo/META-INF/services/javax.annotation.processing.Processor deleted file mode 100644 index ff511957d0..0000000000 --- a/querydsl-tooling/querydsl-apt/src/apt/jdo/META-INF/services/javax.annotation.processing.Processor +++ /dev/null @@ -1 +0,0 @@ -com.querydsl.apt.jdo.JDOAnnotationProcessor \ No newline at end of file diff --git a/querydsl-tooling/querydsl-apt/src/apt/roo/META-INF/services/javax.annotation.processing.Processor b/querydsl-tooling/querydsl-apt/src/apt/roo/META-INF/services/javax.annotation.processing.Processor deleted file mode 100644 index 8ba591975e..0000000000 --- a/querydsl-tooling/querydsl-apt/src/apt/roo/META-INF/services/javax.annotation.processing.Processor +++ /dev/null @@ -1 +0,0 @@ -com.querydsl.apt.roo.RooAnnotationProcessor \ No newline at end of file diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/AbstractQuerydslProcessor.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/AbstractQuerydslProcessor.java index e03d74a4ce..c30ac82646 100644 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/AbstractQuerydslProcessor.java +++ b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/AbstractQuerydslProcessor.java @@ -248,8 +248,8 @@ protected Set collectElements() { // from class annotations for (Class annotation : conf.getEntityAnnotations()) { for (Element element : getElements(annotation)) { - if (element instanceof TypeElement) { - elements.add((TypeElement) element); + if (element instanceof TypeElement typeElement) { + elements.add(typeElement); } } } @@ -402,8 +402,8 @@ private void handleEmbeddedType(Element element, Set elements) { private Set getTypeFromProperties(Set parents) { Set elements = new HashSet<>(); for (Element element : parents) { - if (element instanceof TypeElement) { - processFromProperties((TypeElement) element, elements); + if (element instanceof TypeElement typeElement) { + processFromProperties(typeElement, elements); } } @@ -470,10 +470,10 @@ private void addSupertypeFields(EntityType model, Set handled) { private void processExclusions() { for (Element element : getElements(QueryExclude.class)) { - if (element instanceof PackageElement) { - conf.addExcludedPackage(((PackageElement) element).getQualifiedName().toString()); - } else if (element instanceof TypeElement) { - conf.addExcludedClass(((TypeElement) element).getQualifiedName().toString()); + if (element instanceof PackageElement packageElement) { + conf.addExcludedPackage(packageElement.getQualifiedName().toString()); + } else if (element instanceof TypeElement typeElement) { + conf.addExcludedClass(typeElement.getQualifiedName().toString()); } else { throw new IllegalArgumentException(element.toString()); } diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/DefaultConfiguration.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/DefaultConfiguration.java index d1e4db7200..a8c0b56db4 100644 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/DefaultConfiguration.java +++ b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/DefaultConfiguration.java @@ -222,11 +222,9 @@ public DefaultConfiguration( for (Element element : roundEnv.getElementsAnnotatedWith(Config.class)) { var querydslConfig = element.getAnnotation(Config.class); var config = SimpleSerializerConfig.getConfig(querydslConfig); - if (element instanceof PackageElement) { - var packageElement = (PackageElement) element; + if (element instanceof PackageElement packageElement) { packageToConfig.put(packageElement.getQualifiedName().toString(), config); - } else if (element instanceof TypeElement) { - var typeElement = (TypeElement) element; + } else if (element instanceof TypeElement typeElement) { typeToConfig.put(typeElement.getQualifiedName().toString(), config); } } diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/ExtendedTypeFactory.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/ExtendedTypeFactory.java index 5bd1e5c9ed..a95567f1c6 100644 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/ExtendedTypeFactory.java +++ b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/ExtendedTypeFactory.java @@ -92,49 +92,31 @@ public class ExtendedTypeFactory { @Override public Type visitPrimitive(PrimitiveType primitiveType, Boolean p) { - switch (primitiveType.getKind()) { - case BOOLEAN: - return Types.BOOLEAN; - case BYTE: - return Types.BYTE; - case SHORT: - return Types.SHORT; - case INT: - return Types.INTEGER; - case LONG: - return Types.LONG; - case CHAR: - return Types.CHARACTER; - case FLOAT: - return Types.FLOAT; - case DOUBLE: - return Types.DOUBLE; - default: - return null; - } + return switch (primitiveType.getKind()) { + case BOOLEAN -> Types.BOOLEAN; + case BYTE -> Types.BYTE; + case SHORT -> Types.SHORT; + case INT -> Types.INTEGER; + case LONG -> Types.LONG; + case CHAR -> Types.CHARACTER; + case FLOAT -> Types.FLOAT; + case DOUBLE -> Types.DOUBLE; + default -> null; + }; } private Type getPrimitive(PrimitiveType primitiveType) { - switch (primitiveType.getKind()) { - case BOOLEAN: - return Types.BOOLEAN_P; - case BYTE: - return Types.BYTE_P; - case SHORT: - return Types.SHORT_P; - case INT: - return Types.INT; - case LONG: - return Types.LONG_P; - case CHAR: - return Types.CHAR; - case FLOAT: - return Types.FLOAT_P; - case DOUBLE: - return Types.DOUBLE_P; - default: - return null; - } + return switch (primitiveType.getKind()) { + case BOOLEAN -> Types.BOOLEAN_P; + case BYTE -> Types.BYTE_P; + case SHORT -> Types.SHORT_P; + case INT -> Types.INT; + case LONG -> Types.LONG_P; + case CHAR -> Types.CHAR; + case FLOAT -> Types.FLOAT_P; + case DOUBLE -> Types.DOUBLE_P; + default -> null; + }; } @Override @@ -447,8 +429,8 @@ && isAssignable(typeElement.asType(), comparableType)) { } } typeElement = (TypeElement) env.getTypeUtils().asElement(type); - if (type instanceof DeclaredType) { - arguments = ((DeclaredType) type).getTypeArguments(); + if (type instanceof DeclaredType declaredType1) { + arguments = declaredType1.getTypeArguments(); } } @@ -456,8 +438,8 @@ && isAssignable(typeElement.asType(), comparableType)) { var superType = typeElement.getSuperclass(); TypeElement superTypeElement = null; - if (superType instanceof DeclaredType) { - superTypeElement = (TypeElement) ((DeclaredType) superType).asElement(); + if (superType instanceof DeclaredType declaredType1) { + superTypeElement = (TypeElement) declaredType1.asElement(); } // entity type @@ -624,8 +606,8 @@ private Set getSupertypes(TypeMirror typeMirror, boolean deep) { if (e.getKind() == ElementKind.CLASS) { if (e.getSuperclass().getKind() != TypeKind.NONE) { var supertype = normalize(e.getSuperclass()); - if (supertype instanceof DeclaredType - && ((DeclaredType) supertype).asElement().getAnnotation(QueryExclude.class) != null) { + if (supertype instanceof DeclaredType type + && type.asElement().getAnnotation(QueryExclude.class) != null) { return Collections.emptySet(); } else { Type superClass = getType(supertype, deep); diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/TypeExtractor.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/TypeExtractor.java index e8ee1db10a..6b7b11b2dd 100644 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/TypeExtractor.java +++ b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/TypeExtractor.java @@ -57,17 +57,12 @@ public TypeElement visitArray(ArrayType t, Void p) { public TypeElement visitDeclared(DeclaredType t, Void p) { if (t.asElement() instanceof TypeElement) { var typeElement = (TypeElement) t.asElement(); - switch (typeElement.getKind().name()) { - case "ENUM": - return skipEnum ? null : typeElement; - case "RECORD": - case "CLASS": - return typeElement; - case "INTERFACE": - return visitInterface(t); - default: - throw new IllegalArgumentException("Illegal type: " + typeElement); - } + return switch (typeElement.getKind().name()) { + case "ENUM" -> skipEnum ? null : typeElement; + case "RECORD", "CLASS" -> typeElement; + case "INTERFACE" -> visitInterface(t); + default -> throw new IllegalArgumentException("Illegal type: " + typeElement); + }; } else { return null; } diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/hibernate/HibernateConfiguration.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/hibernate/HibernateConfiguration.java index fb20ba2afe..4a7ec9eb2f 100644 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/hibernate/HibernateConfiguration.java +++ b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/hibernate/HibernateConfiguration.java @@ -47,7 +47,7 @@ public HibernateConfiguration( protected List> getAnnotations() { try { List> annotations = new ArrayList<>(super.getAnnotations()); - for (String simpleName : Arrays.asList("Type", "Cascade", "LazyCollection", "OnDelete")) { + for (String simpleName : Arrays.asList("Type", "Cascade", "OnDelete")) { annotations.add( (Class) Class.forName("org.hibernate.annotations." + simpleName)); } diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/JDOAnnotationProcessor.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/JDOAnnotationProcessor.java deleted file mode 100644 index 81088431b5..0000000000 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/JDOAnnotationProcessor.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.apt.jdo; - -import com.querydsl.apt.AbstractQuerydslProcessor; -import com.querydsl.apt.Configuration; -import com.querydsl.core.annotations.QueryEmbedded; -import com.querydsl.core.annotations.QueryEntities; -import com.querydsl.core.annotations.QuerySupertype; -import java.lang.annotation.Annotation; -import javax.annotation.processing.RoundEnvironment; -import javax.annotation.processing.SupportedAnnotationTypes; -import javax.jdo.annotations.EmbeddedOnly; -import javax.jdo.annotations.NotPersistent; -import javax.jdo.annotations.PersistenceCapable; - -/** - * AnnotationProcessor for JDO which takes {@link PersistenceCapable}, {@link EmbeddedOnly} and - * {@link NotPersistent} into account - * - * @author tiwe - */ -@SupportedAnnotationTypes({"com.querydsl.core.annotations.*", "javax.jdo.annotations.*"}) -public class JDOAnnotationProcessor extends AbstractQuerydslProcessor { - - @Override - protected Configuration createConfiguration(RoundEnvironment roundEnv) { - Class entities = QueryEntities.class; - Class entity = PersistenceCapable.class; - Class superType = QuerySupertype.class; - Class embeddable = EmbeddedOnly.class; - Class embedded = QueryEmbedded.class; - Class skip = NotPersistent.class; - return new JDOConfiguration( - processingEnv, roundEnv, entities, entity, superType, embeddable, embedded, skip); - } -} diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/JDOConfiguration.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/JDOConfiguration.java deleted file mode 100644 index 02e28c513c..0000000000 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/JDOConfiguration.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.apt.jdo; - -import com.querydsl.apt.DefaultConfiguration; -import com.querydsl.apt.VisitorConfig; -import com.querydsl.codegen.Keywords; -import com.querydsl.core.annotations.QueryInit; -import com.querydsl.core.annotations.QueryTransient; -import com.querydsl.core.annotations.QueryType; -import java.lang.annotation.Annotation; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import javax.annotation.processing.ProcessingEnvironment; -import javax.annotation.processing.RoundEnvironment; -import javax.jdo.annotations.Cacheable; -import javax.jdo.annotations.Column; -import javax.jdo.annotations.Columns; -import javax.jdo.annotations.Embedded; -import javax.jdo.annotations.Extension; -import javax.jdo.annotations.Extensions; -import javax.jdo.annotations.ForeignKey; -import javax.jdo.annotations.Index; -import javax.jdo.annotations.Join; -import javax.jdo.annotations.Key; -import javax.jdo.annotations.NotPersistent; -import javax.jdo.annotations.Order; -import javax.jdo.annotations.Persistent; -import javax.jdo.annotations.PrimaryKey; -import javax.jdo.annotations.Serialized; -import javax.jdo.annotations.Transactional; -import javax.jdo.annotations.Unique; -import javax.jdo.annotations.Value; -import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; -import javax.lang.model.element.TypeElement; - -/** - * Configuration for {@link JDOAnnotationProcessor} - * - * @author tiwe - * @see JDOAnnotationProcessor - */ -public class JDOConfiguration extends DefaultConfiguration { - - @SuppressWarnings("unchecked") - private static final Iterable> relevantAnnotations = - Collections.unmodifiableList( - Arrays.asList( - Cacheable.class, - Column.class, - Columns.class, - javax.jdo.annotations.Element.class, - Embedded.class, - Extension.class, - Extensions.class, - ForeignKey.class, - Index.class, - Join.class, - Key.class, - NotPersistent.class, - Order.class, - Persistent.class, - PrimaryKey.class, - QueryType.class, - QueryInit.class, - QueryTransient.class, - Serialized.class, - Transactional.class, - Unique.class, - Value.class)); - - public JDOConfiguration( - ProcessingEnvironment processingEnvironment, - RoundEnvironment roundEnv, - Class entitiesAnn, - Class entityAnn, - Class superTypeAnn, - Class embeddableAnn, - Class embeddedAnn, - Class skipAnn) { - super( - processingEnvironment, - roundEnv, - Keywords.JDO, - entitiesAnn, - entityAnn, - superTypeAnn, - embeddableAnn, - embeddedAnn, - skipAnn); - } - - @Override - public VisitorConfig getConfig(TypeElement e, List elements) { - boolean fields = false, methods = false; - for (Element element : elements) { - if (hasRelevantAnnotation(element)) { - fields |= element.getKind().equals(ElementKind.FIELD); - methods |= element.getKind().equals(ElementKind.METHOD); - } - } - return VisitorConfig.get(fields, methods, VisitorConfig.FIELDS_ONLY); - } - - private boolean hasRelevantAnnotation(Element element) { - for (Class relevantAnnotation : relevantAnnotations) { - if (element.getAnnotation(relevantAnnotation) != null) { - return true; - } - } - return false; - } -} diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/package-info.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/package-info.java deleted file mode 100644 index 92a33acd79..0000000000 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/package-info.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** APT JDO support */ -package com.querydsl.apt.jdo; diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jpa/JPAConfiguration.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jpa/JPAConfiguration.java index 88059338ef..6d0f98cbf5 100644 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jpa/JPAConfiguration.java +++ b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jpa/JPAConfiguration.java @@ -168,8 +168,8 @@ private TypeMirror getRealElementType(Element element) { if (mirror != null) { var typeArg = TypeUtils.getAnnotationValueAsTypeMirror(mirror, "targetEntity"); TypeMirror erasure; - if (element instanceof ExecutableElement) { - erasure = ((ExecutableElement) element).getReturnType(); + if (element instanceof ExecutableElement executableElement) { + erasure = executableElement.getReturnType(); } else { erasure = types.erasure(element.asType()); } diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/roo/RooAnnotationProcessor.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/roo/RooAnnotationProcessor.java deleted file mode 100644 index 17a7e0e0e6..0000000000 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/roo/RooAnnotationProcessor.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.apt.roo; - -import com.querydsl.apt.AbstractQuerydslProcessor; -import com.querydsl.apt.Configuration; -import com.querydsl.apt.DefaultConfiguration; -import com.querydsl.apt.jpa.JPAConfiguration; -import jakarta.persistence.Embeddable; -import jakarta.persistence.Embedded; -import jakarta.persistence.MappedSuperclass; -import jakarta.persistence.Transient; -import java.lang.annotation.Annotation; -import javax.annotation.processing.RoundEnvironment; -import javax.annotation.processing.SupportedAnnotationTypes; -import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord; -import org.springframework.roo.addon.jpa.entity.RooJpaEntity; - -/** - * AnnotationProcessor for Spring Roo which takes {@link RooJpaEntity}, {@link RooJpaActiveRecord}, - * {@link MappedSuperclass}, {@link Embeddable} and {@link Transient} into account - * - * @author tiwe - */ -@SupportedAnnotationTypes({ - "com.querydsl.core.annotations.*", - "org.springframework.roo.addon.jpa.entity.*" -}) -public class RooAnnotationProcessor extends AbstractQuerydslProcessor { - - @Override - protected Configuration createConfiguration(RoundEnvironment roundEnv) { - Class entity = RooJpaEntity.class; - Class superType = MappedSuperclass.class; - Class embeddable = Embeddable.class; - Class embedded = Embedded.class; - Class skip = Transient.class; - DefaultConfiguration conf = - new JPAConfiguration( - roundEnv, processingEnv, entity, superType, embeddable, embedded, skip); - conf.setAlternativeEntityAnnotation(RooJpaActiveRecord.class); - return conf; - } -} diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/roo/package-info.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/roo/package-info.java deleted file mode 100644 index 839087dc87..0000000000 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/roo/package-info.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** APT Roo support */ -package com.querydsl.apt.roo; diff --git a/querydsl-tooling/querydsl-apt/src/main/jdo.xml b/querydsl-tooling/querydsl-apt/src/main/jdo.xml deleted file mode 100644 index 016a08ac4d..0000000000 --- a/querydsl-tooling/querydsl-apt/src/main/jdo.xml +++ /dev/null @@ -1,19 +0,0 @@ - - jdo - - jar - - false - - - src/apt/jdo - / - - - ${project.build.outputDirectory} - / - - - \ No newline at end of file diff --git a/querydsl-tooling/querydsl-apt/src/main/roo.xml b/querydsl-tooling/querydsl-apt/src/main/roo.xml deleted file mode 100644 index 6e56b67f02..0000000000 --- a/querydsl-tooling/querydsl-apt/src/main/roo.xml +++ /dev/null @@ -1,19 +0,0 @@ - - roo - - jar - - false - - - src/apt/roo - / - - - ${project.build.outputDirectory} - / - - - \ No newline at end of file diff --git a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/QuerydslAnnotationProcessorTest.java b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/QuerydslAnnotationProcessorTest.java index f6aa418f1b..751d3a3857 100644 --- a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/QuerydslAnnotationProcessorTest.java +++ b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/QuerydslAnnotationProcessorTest.java @@ -13,12 +13,8 @@ */ package com.querydsl.apt; -import static org.assertj.core.api.Assertions.assertThat; - import com.querydsl.apt.hibernate.HibernateAnnotationProcessor; -import com.querydsl.apt.jdo.JDOAnnotationProcessor; import com.querydsl.apt.jpa.JPAAnnotationProcessor; -import com.querydsl.apt.roo.RooAnnotationProcessor; import java.io.File; import java.io.IOException; import java.util.Collections; @@ -155,16 +151,4 @@ public void jpaAnnotationProcessor() throws IOException { public void hibernateAnnotationProcessor() throws IOException { process(HibernateAnnotationProcessor.class, CLASSES, "hibernate"); } - - @Test - public void jdoAnnotationProcessor() throws IOException { - process(JDOAnnotationProcessor.class, CLASSES, "jdo"); - } - - @Test - public void rooAnnotationProcessor() throws IOException { - process(RooAnnotationProcessor.class, CLASSES, "roo"); - - assertThat(new File("target/roo/com/querydsl/apt/domain/QRooEntities_MyEntity.java")).exists(); - } } diff --git a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/InterfaceType2Test.java b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/InterfaceType2Test.java index db2833b504..4a2079a244 100644 --- a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/InterfaceType2Test.java +++ b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/InterfaceType2Test.java @@ -49,8 +49,6 @@ public void setId(Long id) { @Entity @Table(name = "USERS") - // @org.hibernate.annotations.AccessType("field") - @org.hibernate.annotations.Proxy(proxyClass = User.class) public static class UserImpl extends EntityImpl implements User { @NaturalId(mutable = true) @@ -85,8 +83,6 @@ public void setParty(Party party) { @jakarta.persistence.Entity @Table(name = "PARTY") - // @org.hibernate.annotations.AccessType("field") - @org.hibernate.annotations.Proxy(proxyClass = Party.class) public abstract static class PartyImpl extends EntityImpl implements Party { @Column(name = "NAME", nullable = false) diff --git a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/JDOTest.java b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/JDOTest.java deleted file mode 100644 index baf4275d22..0000000000 --- a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/JDOTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.apt.domain; - -import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.StringPath; -import javax.jdo.annotations.NotPersistent; -import javax.jdo.annotations.PersistenceCapable; -import javax.jdo.annotations.Persistent; -import javax.jdo.annotations.PrimaryKey; -import org.junit.Test; - -public class JDOTest extends AbstractTest { - - @PersistenceCapable - public static class JDOEntity { - - String prop; - - @NotPersistent String skipped; - - @NotPersistent JDOEntity skippedEntity; - } - - @PersistenceCapable - public static class JDOEntity2 { - - private String stringField1; - - private String stringField2; - - public String getStringfield1() { - return stringField1; - } - - public String getStringField2() { - return stringField2; - } - } - - @PersistenceCapable - public static class JDOEntity3 { - - private Integer integerField; - - private String stringField; - - @PrimaryKey - public Integer getId() { - return integerField; - } - - @Persistent - public String getName() { - return stringField; - } - } - - @Test - public void test() throws IllegalAccessException, NoSuchFieldException { - start(QJDOTest_JDOEntity.class, QJDOTest_JDOEntity.jDOEntity); - match(StringPath.class, "prop"); - assertMissing("skipped"); - assertMissing("skippedEntity"); - - start(QJDOTest_JDOEntity2.class, QJDOTest_JDOEntity2.jDOEntity2); - match(StringPath.class, "stringField1"); - assertMissing("stringfield1"); - match(StringPath.class, "stringField2"); - - start(QJDOTest_JDOEntity3.class, QJDOTest_JDOEntity3.jDOEntity3); - match(NumberPath.class, "id"); - matchType(Integer.class, "id"); - match(StringPath.class, "name"); - } -} diff --git a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/JPATest.java b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/JPATest.java index c7cf25ebe5..a5b46ad431 100644 --- a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/JPATest.java +++ b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/JPATest.java @@ -27,7 +27,7 @@ public static class JPAEntity { @Transient String skipped; - @Transient JDOTest.JDOEntity skippedEntity; + @Transient QueryTypeTest.QueryTypeEntity skippedEntity; } @Test diff --git a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/QueryProjectionTest.java b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/QueryProjectionTest.java index 6189c97890..c3e459c2a9 100644 --- a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/QueryProjectionTest.java +++ b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/QueryProjectionTest.java @@ -22,7 +22,6 @@ import com.querydsl.core.types.dsl.StringExpression; import jakarta.persistence.Entity; import java.util.Map; -import javax.jdo.annotations.PersistenceCapable; import org.junit.Test; public class QueryProjectionTest { @@ -30,7 +29,6 @@ public class QueryProjectionTest { // all three annotations are needed, because all are used as entity annotations @QueryEntity @Entity - @PersistenceCapable public static class EntityWithProjection { public EntityWithProjection(long id) {} diff --git a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/QuerySuperTypeTest.java b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/QuerySuperTypeTest.java deleted file mode 100644 index 29fa750c01..0000000000 --- a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/QuerySuperTypeTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.querydsl.apt.domain; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.annotations.QuerySupertype; -import java.util.Set; -import javax.jdo.annotations.PersistenceCapable; -import org.junit.Test; - -public class QuerySuperTypeTest { - - @QuerySupertype - public static class Supertype {} - - @PersistenceCapable - public static class JdoEntity { - Set references; - } - - @Test - public void jdoEntity() { - assertThat(QQuerySuperTypeTest_JdoEntity.jdoEntity.references.any().getClass()) - .isEqualTo(QQuerySuperTypeTest_Supertype.class); - } -} diff --git a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/RooEntities.java b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/RooEntities.java deleted file mode 100644 index e164ba2899..0000000000 --- a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/RooEntities.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.querydsl.apt.domain; - -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord; -import org.springframework.roo.addon.jpa.entity.RooJpaEntity; - -public class RooEntities { - - @RooJpaEntity - public static class MyEntity { - - @Id Long id; - - String name; - - @ManyToOne MyEntity entity; - } - - @RooJpaActiveRecord - public static class MyEntity2 { - - @Id Long id; - - String name; - - @ManyToOne MyEntity entity; - } -} diff --git a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/RooEntitiesTest.java b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/RooEntitiesTest.java deleted file mode 100644 index 19b4cfb8cc..0000000000 --- a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/RooEntitiesTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.querydsl.apt.domain; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; - -public class RooEntitiesTest { - - @Test - public void rooJpaEntity() { - assertThat(QRooEntities_MyEntity.myEntity).isNotNull(); - } - - @Test - public void rooJpaActiveRecord() { - assertThat(QRooEntities_MyEntity2.myEntity2).isNotNull(); - } -} diff --git a/querydsl-tooling/querydsl-codegen-utils/pom.xml b/querydsl-tooling/querydsl-codegen-utils/pom.xml index a59cf4ffac..327867b47d 100644 --- a/querydsl-tooling/querydsl-codegen-utils/pom.xml +++ b/querydsl-tooling/querydsl-codegen-utils/pom.xml @@ -6,7 +6,7 @@ io.github.openfeign.querydsl querydsl-tooling - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-codegen-utils diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/CodegenException.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/CodegenException.java index 86707fbe3e..d3a99586b9 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/CodegenException.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/CodegenException.java @@ -13,12 +13,14 @@ */ package com.querydsl.codegen.utils; +import java.io.Serial; + /** * @author tiwe */ public class CodegenException extends RuntimeException { - private static final long serialVersionUID = -8704782349669898467L; + @Serial private static final long serialVersionUID = -8704782349669898467L; public CodegenException(String msg) { super(msg); diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/ECJEvaluatorFactory.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/ECJEvaluatorFactory.java index ab6fd14a5e..904ba0200c 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/ECJEvaluatorFactory.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/ECJEvaluatorFactory.java @@ -309,8 +309,8 @@ public void acceptResult(CompilationResult result) { // not one of our checked exceptions boxed as unchecked; just rethrow var cause = ex.getCause(); if (cause != null) { - if (cause instanceof IOException) { - throw (IOException) cause; + if (cause instanceof IOException exception) { + throw exception; } else if (cause instanceof ClassFormatException) { throw new IOException(cause); } diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/JavaWriter.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/JavaWriter.java index 944b0068b8..a1fd8e57b1 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/JavaWriter.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/JavaWriter.java @@ -144,12 +144,11 @@ private void annotationConstant(Object value) throws IOException { first = false; } append("}"); - } else if (value instanceof Class) { - appendType((Class) value).append(".class"); + } else if (value instanceof Class class1) { + appendType(class1).append(".class"); } else if (value instanceof Number || value instanceof Boolean) { append(value.toString()); - } else if (value instanceof Enum) { - Enum enumValue = (Enum) value; + } else if (value instanceof Enum enumValue) { if (classes.contains(enumValue.getClass().getName()) || packages.contains(enumValue.getClass().getPackage().getName())) { append(enumValue.name()); diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/LocationAndKind.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/LocationAndKind.java index 44e3142765..0a5ad65aa4 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/LocationAndKind.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/LocationAndKind.java @@ -36,8 +36,7 @@ public LocationAndKind(Location location, Kind kind) { public boolean equals(Object obj) { if (obj == this) { return true; - } else if (obj instanceof LocationAndKind) { - var other = (LocationAndKind) obj; + } else if (obj instanceof LocationAndKind other) { return location.equals(other.location) && kind.equals(other.kind); } else { return false; diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/ScalaWriter.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/ScalaWriter.java index dcf7c06b03..2f6cee4ae6 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/ScalaWriter.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/ScalaWriter.java @@ -168,14 +168,13 @@ private void annotationConstant(Object value) throws IOException { first = false; } append(")"); - } else if (value instanceof Class) { + } else if (value instanceof Class class1) { append("classOf["); - appendType((Class) value); + appendType(class1); append("]"); } else if (value instanceof Number || value instanceof Boolean) { append(value.toString()); - } else if (value instanceof Enum) { - Enum enumValue = (Enum) value; + } else if (value instanceof Enum enumValue) { if (classes.contains(enumValue.getClass().getName()) || packages.contains(enumValue.getClass().getPackage().getName())) { append(enumValue.name()); diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/ClassType.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/ClassType.java index f960a95e1a..a408aa0751 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/ClassType.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/ClassType.java @@ -74,8 +74,7 @@ public Type asArrayType() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Type) { - var t = (Type) o; + } else if (o instanceof Type t) { return t.getFullName().equals(className) && t.getParameters().equals(parameters); } else { return false; diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/Constructor.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/Constructor.java index a30f086f17..aca49f4b7e 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/Constructor.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/Constructor.java @@ -30,8 +30,8 @@ public Constructor(Collection params) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Constructor) { - return ((Constructor) o).parameters.equals(parameters); + } else if (o instanceof Constructor constructor) { + return constructor.parameters.equals(parameters); } else { return false; } diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/Parameter.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/Parameter.java index 61bace5153..6b0426ad3d 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/Parameter.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/Parameter.java @@ -33,8 +33,7 @@ public Parameter(String name, Type type) { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Parameter) { - var t = (Parameter) o; + } else if (o instanceof Parameter t) { return type.equals(t.type) && name.equals(t.name); } else { return false; diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/SimpleType.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/SimpleType.java index be74b84277..cf8767bade 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/SimpleType.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/SimpleType.java @@ -156,8 +156,7 @@ public Type asArrayType() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Type) { - var t = (Type) o; + } else if (o instanceof Type t) { return t.getFullName().equals(fullName) && t.getParameters().equals(parameters); } else { return false; diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/TypeExtends.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/TypeExtends.java index 18928094bf..e70d9a3d63 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/TypeExtends.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/TypeExtends.java @@ -62,9 +62,8 @@ public String getVarName() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof TypeExtends) { - return Objects.equals(((TypeExtends) o).varName, varName) - && ((TypeExtends) o).type.equals(type); + } else if (o instanceof TypeExtends extends1) { + return Objects.equals(extends1.varName, varName) && extends1.type.equals(type); } else { return false; } diff --git a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/TypeSuper.java b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/TypeSuper.java index 0890c16189..ca2728e68d 100644 --- a/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/TypeSuper.java +++ b/querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/TypeSuper.java @@ -68,9 +68,8 @@ public String getVarName() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof TypeSuper) { - return Objects.equals(((TypeSuper) o).varName, varName) - && ((TypeSuper) o).superType.equals(superType); + } else if (o instanceof TypeSuper super1) { + return Objects.equals(super1.varName, varName) && super1.superType.equals(superType); } else { return false; } diff --git a/querydsl-tooling/querydsl-codegen/pom.xml b/querydsl-tooling/querydsl-codegen/pom.xml index e07cc46536..4730893479 100644 --- a/querydsl-tooling/querydsl-codegen/pom.xml +++ b/querydsl-tooling/querydsl-codegen/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-tooling - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-codegen diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/DefaultEmbeddableSerializer.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/DefaultEmbeddableSerializer.java index f087932d28..cf9f3be3d3 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/DefaultEmbeddableSerializer.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/DefaultEmbeddableSerializer.java @@ -82,34 +82,18 @@ protected void introClassHeader(CodeWriter writer, EntityType model) throws IOEx var category = model.getOriginalCategory(); Class pathType; if (model.getProperties().isEmpty()) { - switch (category) { - case COMPARABLE: - pathType = ComparablePath.class; - break; - case ENUM: - pathType = EnumPath.class; - break; - case DATE: - pathType = DatePath.class; - break; - case DATETIME: - pathType = DateTimePath.class; - break; - case TIME: - pathType = TimePath.class; - break; - case NUMERIC: - pathType = NumberPath.class; - break; - case STRING: - pathType = StringPath.class; - break; - case BOOLEAN: - pathType = BooleanPath.class; - break; - default: - pathType = BeanPath.class; - } + pathType = + switch (category) { + case COMPARABLE -> ComparablePath.class; + case ENUM -> EnumPath.class; + case DATE -> DatePath.class; + case DATETIME -> DateTimePath.class; + case TIME -> TimePath.class; + case NUMERIC -> NumberPath.class; + case STRING -> StringPath.class; + case BOOLEAN -> BooleanPath.class; + default -> BeanPath.class; + }; } else { pathType = BeanPath.class; } diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/DefaultEntitySerializer.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/DefaultEntitySerializer.java index 2de0a4e9b2..7affef987f 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/DefaultEntitySerializer.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/DefaultEntitySerializer.java @@ -125,7 +125,7 @@ public DefaultEntitySerializer(TypeMappings mappings, Collection keyword } private boolean superTypeHasEntityFields(EntityType model) { - Supertype superType = model.getSuperType(); + var superType = model.getSuperType(); return null != superType && null != superType.getEntityType() && superType.getEntityType().hasEntityFields(); @@ -313,9 +313,9 @@ protected boolean hasOwnEntityProperties(EntityType model) { protected void initEntityFields(CodeWriter writer, SerializerConfig config, EntityType model) throws IOException { - Supertype superType = model.getSuperType(); + var superType = model.getSuperType(); if (superType != null) { - EntityType entityType = superType.getEntityType(); + var entityType = superType.getEntityType(); if (entityType != null && entityType.hasEntityFields()) { var superQueryType = typeMappings.getPathType(entityType, model, false); writer.line( @@ -383,34 +383,18 @@ protected void introClassHeader(CodeWriter writer, EntityType model) throws IOEx Class pathType; if (model.getProperties().isEmpty()) { - switch (category) { - case COMPARABLE: - pathType = ComparablePath.class; - break; - case ENUM: - pathType = EnumPath.class; - break; - case DATE: - pathType = DatePath.class; - break; - case DATETIME: - pathType = DateTimePath.class; - break; - case TIME: - pathType = TimePath.class; - break; - case NUMERIC: - pathType = NumberPath.class; - break; - case STRING: - pathType = StringPath.class; - break; - case BOOLEAN: - pathType = BooleanPath.class; - break; - default: - pathType = EntityPathBase.class; - } + pathType = + switch (category) { + case COMPARABLE -> ComparablePath.class; + case ENUM -> EnumPath.class; + case DATE -> DatePath.class; + case DATETIME -> DateTimePath.class; + case TIME -> TimePath.class; + case NUMERIC -> NumberPath.class; + case STRING -> StringPath.class; + case BOOLEAN -> BooleanPath.class; + default -> EntityPathBase.class; + }; } else { pathType = EntityPathBase.class; } @@ -647,7 +631,7 @@ protected void introPackage(CodeWriter writer, EntityType model) throws IOExcept } protected void introSuper(CodeWriter writer, EntityType model) throws IOException { - EntityType superType = model.getSuperType().getEntityType(); + var superType = model.getSuperType().getEntityType(); var superQueryType = typeMappings.getPathType(superType, model, false); if (!superType.hasEntityFields()) { writer.publicFinal( @@ -759,7 +743,7 @@ protected void serialize( String factoryMethod, String... args) throws IOException { - Supertype superType = model.getSuperType(); + var superType = model.getSuperType(); // construct value var value = new StringBuilder(); if (field.isInherited() && superType != null) { @@ -792,7 +776,7 @@ protected void customField( writer.line("// custom"); if (field.isInherited()) { writer.line("// inherited"); - Supertype superType = model.getSuperType(); + var superType = model.getSuperType(); if (!superType.getEntityType().hasEntityFields()) { var value = NEW + writer.getRawName(queryType) + "(_super." + field.getEscapedName() + ")"; writer.publicFinal(queryType, field.getEscapedName(), value); diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Delegate.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Delegate.java index 6b5fa15046..1d0d78d830 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Delegate.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Delegate.java @@ -48,8 +48,7 @@ public Delegate( public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Delegate) { - var m = (Delegate) o; + } else if (o instanceof Delegate m) { return m.name.equals(name) && m.parameters.equals(parameters); } else { return false; diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/EntityType.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/EntityType.java index cd9a7d8dc6..8db2939a18 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/EntityType.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/EntityType.java @@ -253,7 +253,7 @@ private boolean hasPropertyWithType(TypeCategory category) { } public void include(Supertype supertype) { - EntityType entityType = supertype.getEntityType(); + var entityType = supertype.getEntityType(); for (Delegate delegate : entityType.getDelegates()) { addDelegate(delegate); } diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/GenericExporter.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/GenericExporter.java index 223ff9d9c5..5e7a0586ea 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/GenericExporter.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/GenericExporter.java @@ -496,11 +496,11 @@ private Type getPropertyType( } if (propertyType == null) { propertyType = typeFactory.get(type, annotated, genericType); - if (propertyType instanceof EntityType + if (propertyType instanceof EntityType entityType && !allTypes.containsKey(ClassUtils.getFullName(type))) { var fullName = ClassUtils.getFullName(type); if (!allTypes.containsKey(fullName)) { - allTypes.put(fullName, (EntityType) propertyType); + allTypes.put(fullName, entityType); } } } diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Keywords.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Keywords.java index 83d8579b39..e35ca699b5 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Keywords.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Keywords.java @@ -109,33 +109,4 @@ private Keywords() {} "VALUE", "WHEN", "WHERE")); - - public static final Collection JDO = - Collections.unmodifiableList( - Arrays.asList( - "AS", - "ASC", - "ASCENDING", - "AVG", - "BY", - "COUNT", - "DESC", - "DESCENDING", - "DISTINCT", - "EXCLUDE", - "FROM", - "GROUP", - "HAVING", - "INTO", - "MAX", - "MIN", - "ORDER", - "PARAMETERS", - "RANGE", - "SELECT", - "SUBCLASSES", - "SUM", - "UNIQUE", - "VARIABLES", - "WHERE")); } diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/ParameterizedTypeImpl.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/ParameterizedTypeImpl.java index e9b1390287..e4208003cc 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/ParameterizedTypeImpl.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/ParameterizedTypeImpl.java @@ -53,8 +53,7 @@ public Type getOwnerType() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof ParameterizedTypeImpl) { - var other = (ParameterizedTypeImpl) o; + } else if (o instanceof ParameterizedTypeImpl other) { return other.rawType.equals(rawType) && Arrays.equals(other.arguments, arguments); } else { return false; diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Property.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Property.java index d1d3f95570..1415feee36 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Property.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Property.java @@ -126,8 +126,7 @@ public int hashCode() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Property) { - var p = (Property) o; + } else if (o instanceof Property p) { return p.name.equals(name) && p.type.equals(type); } else { return false; diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/PropertyHandling.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/PropertyHandling.java index c6b99c48b0..30db4e2566 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/PropertyHandling.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/PropertyHandling.java @@ -50,21 +50,6 @@ public Config getConfig(Class type) { return Config.NONE; } }, - /** JDO compatibility */ - JDO { - @Override - public Config getConfig(Class type) { - var fields = false; - var methods = false; - for (Field field : type.getDeclaredFields()) { - fields |= hasAnnotations(field, "javax.jdo.annotations."); - } - for (Method method : type.getDeclaredMethods()) { - methods |= hasAnnotations(method, "javax.jdo.annotations."); - } - return Config.of(fields, methods, Config.FIELDS); - } - }, /** JPA compatibility */ JPA { @Override diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Supertype.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Supertype.java index 82c744cda5..30b151d388 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Supertype.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Supertype.java @@ -59,8 +59,8 @@ public int hashCode() { public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof Supertype) { - return ((Supertype) o).type.equals(type); + } else if (o instanceof Supertype supertype) { + return supertype.type.equals(type); } else { return false; } diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/TypeFactory.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/TypeFactory.java index 85c193f217..e4c7f83b4b 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/TypeFactory.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/TypeFactory.java @@ -172,8 +172,7 @@ private Type create( value = createOther(cl, entity, annotationHelper, annotation, parameters); } - if (genericType instanceof TypeVariable) { - var tv = (TypeVariable) genericType; + if (genericType instanceof TypeVariable tv) { if (tv.getBounds().length == 1 && tv.getBounds()[0].equals(Object.class)) { value = new TypeSuper(tv.getName(), value); } else { @@ -248,13 +247,12 @@ private Type[] getGenericParameters( @SuppressWarnings("rawtypes") private Type getGenericParameter(Class cl, java.lang.reflect.Type genericType, int i) { java.lang.reflect.Type parameter = ReflectionUtils.getTypeParameter(genericType, i); - if (parameter instanceof TypeVariable) { - var variable = (TypeVariable) parameter; + if (parameter instanceof TypeVariable variable) { var rv = get(ReflectionUtils.getTypeParameterAsClass(genericType, i), null, parameter); return new TypeExtends(variable.getName(), rv); - } else if (parameter instanceof WildcardType - && ((WildcardType) parameter).getUpperBounds()[0].equals(Object.class) - && ((WildcardType) parameter).getLowerBounds().length == 0) { + } else if (parameter instanceof WildcardType type + && type.getUpperBounds()[0].equals(Object.class) + && type.getLowerBounds().length == 0) { return ANY; } else { var rv = get(ReflectionUtils.getTypeParameterAsClass(genericType, i), null, parameter); @@ -280,8 +278,8 @@ public void extendTypes() { var entityType = (EntityType) entry.getValue(); if (entityType.getProperties().isEmpty()) { for (Type type : cache.values()) { - if (type.getFullName().equals(entityType.getFullName()) && type instanceof EntityType) { - var base = (EntityType) type; + if (type.getFullName().equals(entityType.getFullName()) + && type instanceof EntityType base) { for (Property property : base.getProperties()) { entityType.addProperty(property); } diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/TypeResolver.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/TypeResolver.java index ae1c1ddd71..d225bd30b4 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/TypeResolver.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/TypeResolver.java @@ -46,9 +46,9 @@ public static Type resolve(Type type, Type declaringType, EntityType context) { } // rewrap entity type - if (type instanceof EntityType) { + if (type instanceof EntityType entityType) { if (!unwrap(type).equals(resolved)) { - resolved = new EntityType(resolved, ((EntityType) type).getSuperTypes()); + resolved = new EntityType(resolved, entityType.getSuperTypes()); } else { // reset to original type resolved = type; @@ -74,7 +74,7 @@ private static Type resolveVar( "Did not find type " + varName + " in " + declaringType + " for " + context); } - Supertype type = context.getSuperType(); + var type = context.getSuperType(); while (!type.getEntityType().equals(declaringType)) { type = type.getEntityType().getSuperType(); } @@ -116,8 +116,8 @@ private static String getVarName(Type type) { } private static Type unwrap(Type type) { - if (type instanceof EntityType) { - return ((EntityType) type).getInnerType(); + if (type instanceof EntityType entityType) { + return entityType.getInnerType(); } else { return type; } diff --git a/querydsl-tooling/querydsl-jpa-codegen/pom.xml b/querydsl-tooling/querydsl-jpa-codegen/pom.xml index 9ef00b92d9..a18eaefc4e 100644 --- a/querydsl-tooling/querydsl-jpa-codegen/pom.xml +++ b/querydsl-tooling/querydsl-jpa-codegen/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-tooling - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-jpa-codegen diff --git a/querydsl-tooling/querydsl-kotlin-codegen/pom.xml b/querydsl-tooling/querydsl-kotlin-codegen/pom.xml index 04eb96bb13..58f2a59442 100644 --- a/querydsl-tooling/querydsl-kotlin-codegen/pom.xml +++ b/querydsl-tooling/querydsl-kotlin-codegen/pom.xml @@ -4,7 +4,7 @@ io.github.openfeign.querydsl querydsl-tooling - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-kotlin-codegen diff --git a/querydsl-tooling/querydsl-ksp-codegen/pom.xml b/querydsl-tooling/querydsl-ksp-codegen/pom.xml index 0f244dcb6b..d54d398b6f 100644 --- a/querydsl-tooling/querydsl-ksp-codegen/pom.xml +++ b/querydsl-tooling/querydsl-ksp-codegen/pom.xml @@ -4,7 +4,7 @@ io.github.openfeign.querydsl querydsl-tooling - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-ksp-codegen diff --git a/querydsl-tooling/querydsl-maven-plugin/pom.xml b/querydsl-tooling/querydsl-maven-plugin/pom.xml index f377f307f6..6f2baf2ed7 100644 --- a/querydsl-tooling/querydsl-maven-plugin/pom.xml +++ b/querydsl-tooling/querydsl-maven-plugin/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-tooling - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-maven-plugin @@ -80,11 +80,6 @@ - - org.datanucleus - javax.jdo - provided - jakarta.persistence jakarta.persistence-api diff --git a/querydsl-tooling/querydsl-maven-plugin/src/main/java/com/querydsl/maven/JDOExporterMojo.java b/querydsl-tooling/querydsl-maven-plugin/src/main/java/com/querydsl/maven/JDOExporterMojo.java deleted file mode 100644 index 967c59f55f..0000000000 --- a/querydsl-tooling/querydsl-maven-plugin/src/main/java/com/querydsl/maven/JDOExporterMojo.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.querydsl.maven; - -import com.querydsl.codegen.GenericExporter; -import com.querydsl.codegen.PropertyHandling; -import jakarta.persistence.Embedded; -import javax.jdo.annotations.EmbeddedOnly; -import javax.jdo.annotations.NotPersistent; -import javax.jdo.annotations.PersistenceCapable; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.ResolutionScope; - -/** - * {@code JDOExporterMojo} calls {@link GenericExporter} using the classpath of the module - * - * @author tiwe - */ -@Mojo(name = "jdo-export", requiresDependencyResolution = ResolutionScope.TEST) -public class JDOExporterMojo extends AbstractExporterMojo { - - @Override - protected void configure(GenericExporter exporter) { - super.configure(exporter); - exporter.setEmbeddableAnnotation(EmbeddedOnly.class); - exporter.setEmbeddedAnnotation(Embedded.class); - exporter.setEntityAnnotation(PersistenceCapable.class); - exporter.setSkipAnnotation(NotPersistent.class); - exporter.setPropertyHandling(PropertyHandling.JDO); - } -} diff --git a/querydsl-tooling/querydsl-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml b/querydsl-tooling/querydsl-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml index f4fbbca00b..67ddc7d06b 100644 --- a/querydsl-tooling/querydsl-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml +++ b/querydsl-tooling/querydsl-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml @@ -5,7 +5,6 @@ generic-export - jdo-export jpa-export export test-export diff --git a/querydsl-tooling/querydsl-maven-plugin/src/test/java/com/querydsl/maven/Entity.java b/querydsl-tooling/querydsl-maven-plugin/src/test/java/com/querydsl/maven/Entity.java index ee6c8dc5a7..ef7d827f55 100644 --- a/querydsl-tooling/querydsl-maven-plugin/src/test/java/com/querydsl/maven/Entity.java +++ b/querydsl-tooling/querydsl-maven-plugin/src/test/java/com/querydsl/maven/Entity.java @@ -4,9 +4,7 @@ import jakarta.persistence.Temporal; import jakarta.persistence.TemporalType; import java.util.Date; -import javax.jdo.annotations.PersistenceCapable; -@PersistenceCapable @jakarta.persistence.Entity @QueryEntity public class Entity { diff --git a/querydsl-tooling/querydsl-maven-plugin/src/test/java/com/querydsl/maven/JDOExporterMojoTest.java b/querydsl-tooling/querydsl-maven-plugin/src/test/java/com/querydsl/maven/JDOExporterMojoTest.java deleted file mode 100644 index 94235baef7..0000000000 --- a/querydsl-tooling/querydsl-maven-plugin/src/test/java/com/querydsl/maven/JDOExporterMojoTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.querydsl.maven; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.File; -import org.apache.maven.project.MavenProject; -import org.junit.Test; - -public class JDOExporterMojoTest { - - @Test - public void execute() throws Exception { - var mavenProject = new MavenProject(); - mavenProject.getBuild().setOutputDirectory("target/classes"); - mavenProject.getBuild().setTestOutputDirectory("target/test-classes"); - - var mojo = new JDOExporterMojo(); - mojo.setTargetFolder(new File("target/generated-test-data3")); - mojo.setPackages(new String[] {"com.querydsl.maven"}); - mojo.setProject(mavenProject); - mojo.setTestClasspath(true); - mojo.execute(); - - var file = new File("target/generated-test-data3/com/querydsl/maven/QEntity.java"); - assertThat(file).exists(); - } -} diff --git a/querydsl-tooling/querydsl-sql-codegen/pom.xml b/querydsl-tooling/querydsl-sql-codegen/pom.xml index 5b9962e504..3f34fb3b9d 100644 --- a/querydsl-tooling/querydsl-sql-codegen/pom.xml +++ b/querydsl-tooling/querydsl-sql-codegen/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-tooling - 6.11-SNAPSHOT + 7.0-SNAPSHOT querydsl-sql-codegen