From 3fe4704809814329ec1cf45056b6042084343244 Mon Sep 17 00:00:00 2001 From: Marvin Froeder Date: Wed, 21 Aug 2024 16:59:32 -0300 Subject: [PATCH] Cleanup vars, switches, pattern matching and text blocks --- .../querydsl/core/types/TemplateFactory.java | 13 +-- .../querydsl/core/types/ToStringVisitor.java | 4 +- .../querydsl/core/util/CollectionUtils.java | 43 +++++----- .../java/com/querydsl/jpa/JPQLSerializer.java | 23 ++--- .../com/querydsl/jpa/JPQLSerializerTest.java | 10 ++- .../com/querydsl/r2dbc/MySQLTemplates.java | 22 ++--- .../querydsl/r2dbc/SQLServerTemplates.java | 18 ++-- .../java/com/querydsl/r2dbc/SQLTemplates.java | 85 ++++++++----------- .../querydsl/r2dbc/SQLTemplatesRegistry.java | 18 ++-- .../r2dbc/dml/AbstractR2DBCDeleteClause.java | 7 +- .../r2dbc/AbstractSQLTemplatesTest.java | 7 +- .../com/querydsl/r2dbc/JoinFlagsTest.java | 20 ++++- .../r2dbc/PostgreSQLTemplatesTest.java | 7 +- .../r2dbc/SQLServer2005TemplatesTest.java | 7 +- .../r2dbc/SQLServer2012TemplatesTest.java | 7 +- .../r2dbc/SQLServerTemplatesTest.java | 7 +- .../com/querydsl/r2dbc/UnionSubQueryTest.java | 5 +- .../com/querydsl/sql/CUBRIDTemplates.java | 16 ++-- .../java/com/querydsl/sql/DB2Templates.java | 10 +-- .../java/com/querydsl/sql/DerbyTemplates.java | 21 ++--- .../java/com/querydsl/sql/H2Templates.java | 13 ++- .../java/com/querydsl/sql/MySQLTemplates.java | 22 ++--- .../com/querydsl/sql/OracleTemplates.java | 31 +++---- .../com/querydsl/sql/SQLServerTemplates.java | 20 ++--- .../java/com/querydsl/sql/SQLTemplates.java | 85 ++++++++----------- .../com/querydsl/sql/SQLiteTemplates.java | 41 +++++---- .../com/querydsl/sql/TeradataTemplates.java | 10 +-- .../querydsl/sql/ddl/CreateTableClause.java | 2 +- .../sql/dml/AbstractSQLDeleteClause.java | 7 +- .../sql/AbstractSQLTemplatesTest.java | 7 +- .../java/com/querydsl/sql/JoinFlagsTest.java | 20 ++++- .../querydsl/sql/PostgreSQLTemplatesTest.java | 7 +- .../sql/SQLServer2005TemplatesTest.java | 7 +- .../sql/SQLServer2012TemplatesTest.java | 7 +- .../querydsl/sql/SQLServerTemplatesTest.java | 7 +- .../com/querydsl/sql/SQLiteTemplatesTest.java | 7 +- .../java/com/querydsl/sql/SelectBase.java | 18 ++-- .../com/querydsl/sql/UnionSubQueryTest.java | 5 +- .../com/querydsl/apt/ExtendedTypeFactory.java | 62 +++++--------- .../java/com/querydsl/apt/TypeExtractor.java | 17 ++-- .../codegen/DefaultEmbeddableSerializer.java | 40 +++------ .../codegen/DefaultEntitySerializer.java | 52 ++++-------- .../java/com/querydsl/codegen/EntityType.java | 2 +- .../com/querydsl/codegen/TypeResolver.java | 2 +- 44 files changed, 387 insertions(+), 454 deletions(-) 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 298610663c..6fbc8769d5 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,13 @@ 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<>()); 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 0e4713dbfe..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,7 +51,7 @@ 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(); @@ -90,7 +90,7 @@ 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(); diff --git a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/util/CollectionUtils.java b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/util/CollectionUtils.java index c02f9825df..654342fac7 100644 --- a/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/util/CollectionUtils.java +++ b/querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/util/CollectionUtils.java @@ -105,14 +105,11 @@ public static List unmodifiableList(List list) { if (isUnmodifiableType(list.getClass())) { return list; } - switch (list.size()) { - case 0: - return Collections.emptyList(); - case 1: - return Collections.singletonList(list.get(0)); - default: - return Collections.unmodifiableList(new ArrayList<>(list)); - } + return switch (list.size()) { + case 0 -> Collections.emptyList(); + case 1 -> Collections.singletonList(list.get(0)); + default -> Collections.unmodifiableList(new ArrayList<>(list)); + }; } /** @@ -127,22 +124,20 @@ public static Set unmodifiableSet(Set set) { if (isUnmodifiableType(set.getClass())) { return set; } - switch (set.size()) { - case 0: - return Collections.emptySet(); - case 1: - return Collections.singleton(set.iterator().next()); - default: - return Collections.unmodifiableSet( - (Set) - (set instanceof LinkedHashSet - ? ((LinkedHashSet) set).clone() - : set instanceof TreeSet - ? ((TreeSet) set).clone() - : set instanceof HashSet - ? ((HashSet) set).clone() - : new LinkedHashSet<>(set))); - } + return switch (set.size()) { + case 0 -> Collections.emptySet(); + case 1 -> Collections.singleton(set.iterator().next()); + default -> + Collections.unmodifiableSet( + (Set) + (set instanceof LinkedHashSet + ? ((LinkedHashSet) set).clone() + : set instanceof TreeSet + ? ((TreeSet) set).clone() + : set instanceof HashSet + ? ((HashSet) set).clone() + : new LinkedHashSet<>(set))); + }; } public static List> partition(List list, int batchSize) { 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 b1c80c0bb8..9772964c10 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 @@ -517,17 +517,18 @@ 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/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-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/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 8d0fd0e729..90a99da3b6 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 @@ -447,41 +447,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) { @@ -590,20 +583,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..c88a2ffdc3 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,10 @@ public abstract class AbstractR2DBCDeleteClause entity; 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/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/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-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/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/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/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/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 cf66cf516c..a6783843ea 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 @@ -464,41 +464,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) { @@ -607,20 +600,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..8fc80247d6 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 @@ -140,27 +140,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/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/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..d11cedbc87 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,10 @@ public abstract class AbstractSQLDeleteClause entity; 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/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 6fc0bce3d0..49d96991f7 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 @@ -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-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 d85e5a9bbc..013dc19ba8 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 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-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/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/TypeResolver.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/TypeResolver.java index ee8c17eb3a..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 @@ -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(); }