From 01282453306bd80a74e029f7ecdf6e207e4c31b5 Mon Sep 17 00:00:00 2001 From: quicklyfast <69248473+quicklyfast@users.noreply.github.com> Date: Fri, 26 Jul 2024 06:40:12 +0000 Subject: [PATCH 1/6] support for deserializing object property values based on value class --- .../main/java/com/querydsl/sql/Configuration.java | 2 +- .../src/main/java/com/querydsl/sql/types/Type.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/Configuration.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/Configuration.java index db28d01dcc..4ed2cb171f 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/Configuration.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/Configuration.java @@ -228,7 +228,7 @@ public Class getJavaType( @Nullable public T get(ResultSet rs, @Nullable Path path, int i, Class clazz) throws SQLException { - return getType(path, clazz).getValue(rs, i); + return getType(path, clazz).getValue(rs, i, clazz); } /** diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/Type.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/Type.java index f1731cd1bf..773a8e60b7 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/Type.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/Type.java @@ -51,6 +51,20 @@ public interface Type { */ String getLiteral(T value); + /** + * Get the object from the result set + * + * @param rs result set + * @param startIndex column index in result set + * @param clazz value type + * @return value + * @throws SQLException + */ + @Nullable + default T getValue(ResultSet rs, int startIndex, Class clazz) throws SQLException { + return getValue(rs, startIndex); + } + /** * Get the object from the result set * From 025a6d5c8e02c92a2d92caf737e6e9a7ff3a06fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E9=A3=9E=E8=88=9E?= Date: Mon, 29 Jul 2024 09:52:33 +0800 Subject: [PATCH 2/6] format code --- .../querydsl-sql/src/main/java/com/querydsl/sql/types/Type.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/Type.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/Type.java index 773a8e60b7..4f1d512dd8 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/Type.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/Type.java @@ -62,7 +62,7 @@ public interface Type { */ @Nullable default T getValue(ResultSet rs, int startIndex, Class clazz) throws SQLException { - return getValue(rs, startIndex); + return getValue(rs, startIndex); } /** From 324cf9abff1783cbc907271a8d2f6ea4a6486855 Mon Sep 17 00:00:00 2001 From: Marvin Froeder Date: Thu, 1 Aug 2024 20:46:20 -0300 Subject: [PATCH 3/6] Add json support to sql queries and update example to show usage --- .../querydsl-example-sql-spring/pom.xml | 12 + .../example/config/JdbcConfiguration.java | 11 +- .../querydsl/example/dao/CustomerDaoImpl.java | 19 +- .../com/querydsl/example/dto/Address.java | 3 +- .../src/main/sql/001_schema.sql | 15 +- querydsl-libraries/pom.xml | 1 + querydsl-libraries/querydsl-sql-json/pom.xml | 224 ++++++++++++++++++ .../querydsl/sql/json/JsonEntity.java | 3 + .../querydsl/sql/json/JsonSupport.java | 62 +++++ .../querydsl/sql/json/types/JSONType.java | 82 +++++++ .../services/com.querydsl.codegen.Extension | 1 + .../java/com/querydsl/sql/Configuration.java | 22 +- .../com/querydsl/sql/types/SimpleType.java | 58 +++++ .../java/com/querydsl/sql/ddl/ColumnData.java | 59 ----- .../querydsl/sql/ddl/CreateTableClause.java | 215 ----------------- .../com/querydsl/sql/ddl/DropTableClause.java | 48 ---- .../querydsl/sql/ddl/ForeignKeyBuilder.java | 51 ---- .../com/querydsl/sql/ddl/ForeignKeyData.java | 49 ---- .../java/com/querydsl/sql/ddl/IndexData.java | 39 --- .../java/com/querydsl/sql/ddl/KeyData.java | 22 -- .../com/querydsl/sql/ddl/PrimaryKeyData.java | 41 ---- .../sql/codegen/MetaDataExporter.java | 15 +- .../sql/codegen/support/TypeMapping.java | 9 +- 23 files changed, 493 insertions(+), 568 deletions(-) create mode 100644 querydsl-libraries/querydsl-sql-json/pom.xml create mode 100644 querydsl-libraries/querydsl-sql-json/src/main/java/io/github/openfeign/querydsl/sql/json/JsonEntity.java create mode 100644 querydsl-libraries/querydsl-sql-json/src/main/java/io/github/openfeign/querydsl/sql/json/JsonSupport.java create mode 100644 querydsl-libraries/querydsl-sql-json/src/main/java/io/github/openfeign/querydsl/sql/json/types/JSONType.java create mode 100644 querydsl-libraries/querydsl-sql-json/src/main/resources/META-INF/services/com.querydsl.codegen.Extension create mode 100644 querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/SimpleType.java delete mode 100644 querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/ColumnData.java delete mode 100644 querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/CreateTableClause.java delete mode 100644 querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/DropTableClause.java delete mode 100644 querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/ForeignKeyBuilder.java delete mode 100644 querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/ForeignKeyData.java delete mode 100644 querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/IndexData.java delete mode 100644 querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/KeyData.java delete mode 100644 querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/PrimaryKeyData.java diff --git a/querydsl-examples/querydsl-example-sql-spring/pom.xml b/querydsl-examples/querydsl-example-sql-spring/pom.xml index 6bd1900295..e2c7d96386 100644 --- a/querydsl-examples/querydsl-example-sql-spring/pom.xml +++ b/querydsl-examples/querydsl-example-sql-spring/pom.xml @@ -51,6 +51,11 @@ querydsl-sql ${project.version} + + io.github.openfeign.querydsl + querydsl-sql-json + ${project.version} + io.github.openfeign.querydsl querydsl-sql-spring @@ -90,6 +95,13 @@ com.querydsl.sql.types.LocalDateTimeType com.querydsl.sql.types.LocalDateType + + + CUSTOMER_ADDRESS
+ ADDRESS + com.querydsl.example.dto.Address +
+
com.querydsl.example.sql ${project.basedir}/target/generated-sources/java diff --git a/querydsl-examples/querydsl-example-sql-spring/src/main/java/com/querydsl/example/config/JdbcConfiguration.java b/querydsl-examples/querydsl-example-sql-spring/src/main/java/com/querydsl/example/config/JdbcConfiguration.java index eb1cd10ed2..1a0439df79 100644 --- a/querydsl-examples/querydsl-example-sql-spring/src/main/java/com/querydsl/example/config/JdbcConfiguration.java +++ b/querydsl-examples/querydsl-example-sql-spring/src/main/java/com/querydsl/example/config/JdbcConfiguration.java @@ -2,11 +2,11 @@ import com.querydsl.sql.H2Templates; import com.querydsl.sql.SQLQueryFactory; -import com.querydsl.sql.SQLTemplates; import com.querydsl.sql.spring.SpringConnectionProvider; import com.querydsl.sql.spring.SpringExceptionTranslator; import com.querydsl.sql.types.LocalDateTimeType; import com.querydsl.sql.types.LocalDateType; +import io.github.openfeign.querydsl.sql.json.types.JSONType; import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -25,7 +25,7 @@ public class JdbcConfiguration { @Bean public DataSource dataSource() { - SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); + var dataSource = new SimpleDriverDataSource(); Class driver; try { driver = Class.forName(env.getRequiredProperty("jdbc.driver")); @@ -46,17 +46,18 @@ public PlatformTransactionManager transactionManager() { @Bean public com.querydsl.sql.Configuration querydslConfiguration() { - SQLTemplates templates = H2Templates.builder().build(); - com.querydsl.sql.Configuration configuration = new com.querydsl.sql.Configuration(templates); + var templates = H2Templates.builder().build(); + var configuration = new com.querydsl.sql.Configuration(templates); configuration.setExceptionTranslator(new SpringExceptionTranslator()); configuration.register(new LocalDateTimeType()); configuration.register(new LocalDateType()); + configuration.register(new JSONType()); return configuration; } @Bean public SQLQueryFactory queryFactory() { - SpringConnectionProvider provider = new SpringConnectionProvider(dataSource()); + var provider = new SpringConnectionProvider(dataSource()); return new SQLQueryFactory(querydslConfiguration(), provider); } } diff --git a/querydsl-examples/querydsl-example-sql-spring/src/main/java/com/querydsl/example/dao/CustomerDaoImpl.java b/querydsl-examples/querydsl-example-sql-spring/src/main/java/com/querydsl/example/dao/CustomerDaoImpl.java index 28ba6bdfaa..27a22ee655 100644 --- a/querydsl-examples/querydsl-example-sql-spring/src/main/java/com/querydsl/example/dao/CustomerDaoImpl.java +++ b/querydsl-examples/querydsl-example-sql-spring/src/main/java/com/querydsl/example/dao/CustomerDaoImpl.java @@ -1,7 +1,6 @@ package com.querydsl.example.dao; import static com.querydsl.core.types.Projections.bean; -import static com.querydsl.example.sql.QAddress.address; import static com.querydsl.example.sql.QCustomer.customer; import static com.querydsl.example.sql.QCustomerAddress.customerAddress; import static com.querydsl.example.sql.QPerson.person; @@ -9,12 +8,10 @@ import com.querydsl.core.group.GroupBy; import com.querydsl.core.types.Predicate; import com.querydsl.core.types.QBean; -import com.querydsl.example.dto.Address; import com.querydsl.example.dto.Customer; import com.querydsl.example.dto.CustomerAddress; import com.querydsl.example.dto.Person; import com.querydsl.sql.SQLQueryFactory; -import com.querydsl.sql.dml.SQLInsertClause; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; @@ -30,7 +27,7 @@ public class CustomerDaoImpl implements CustomerDao { customerAddress.addressTypeCode, customerAddress.fromDate, customerAddress.toDate, - bean(Address.class, address.all()).as("address")); + customerAddress.address); final QBean customerBean = bean( @@ -42,7 +39,7 @@ public class CustomerDaoImpl implements CustomerDao { @Override public Customer findById(long id) { - List customers = findAll(customer.id.eq(id)); + var customers = findAll(customer.id.eq(id)); return customers.isEmpty() ? null : customers.get(0); } @@ -52,14 +49,13 @@ public List findAll(Predicate... where) { .from(customer) .leftJoin(customer.contactPersonFk, person) .leftJoin(customer._customer3Fk, customerAddress) - .leftJoin(customerAddress.addressFk, address) .where(where) .transform(GroupBy.groupBy(customer.id).list(customerBean)); } @Override public Customer save(Customer c) { - Long id = c.getId(); + var id = c.getId(); if (id == null) { id = @@ -81,16 +77,11 @@ public Customer save(Customer c) { queryFactory.delete(customerAddress).where(customerAddress.customerId.eq(id)).execute(); } - SQLInsertClause insert = queryFactory.insert(customerAddress); + var insert = queryFactory.insert(customerAddress); for (CustomerAddress ca : c.getAddresses()) { - if (ca.getAddress().getId() == null) { - ca.getAddress() - .setId( - queryFactory.insert(address).populate(ca.getAddress()).executeWithKey(address.id)); - } insert .set(customerAddress.customerId, id) - .set(customerAddress.addressId, ca.getAddress().getId()) + .set(customerAddress.address, ca.getAddress()) .set(customerAddress.addressTypeCode, ca.getAddressTypeCode()) .set(customerAddress.fromDate, ca.getFromDate()) .set(customerAddress.toDate, ca.getToDate()) diff --git a/querydsl-examples/querydsl-example-sql-spring/src/main/java/com/querydsl/example/dto/Address.java b/querydsl-examples/querydsl-example-sql-spring/src/main/java/com/querydsl/example/dto/Address.java index 7d8afb85de..ea8c2e4571 100644 --- a/querydsl-examples/querydsl-example-sql-spring/src/main/java/com/querydsl/example/dto/Address.java +++ b/querydsl-examples/querydsl-example-sql-spring/src/main/java/com/querydsl/example/dto/Address.java @@ -1,9 +1,10 @@ package com.querydsl.example.dto; +import io.github.openfeign.querydsl.sql.json.*; import lombok.Data; @Data -public class Address { +public class Address implements JsonEntity { private Long id; diff --git a/querydsl-examples/querydsl-example-sql-spring/src/main/sql/001_schema.sql b/querydsl-examples/querydsl-example-sql-spring/src/main/sql/001_schema.sql index 924eae726b..5864e8cea4 100644 --- a/querydsl-examples/querydsl-example-sql-spring/src/main/sql/001_schema.sql +++ b/querydsl-examples/querydsl-example-sql-spring/src/main/sql/001_schema.sql @@ -82,23 +82,12 @@ create table customer_order_delivery ( constraint order2_fk foreign key (order_id) references customer_order(id) ); -create table address ( - id identity primary key, - street varchar(64), - zip varchar(64), - town varchar(64), - state varchar(64), - country varchar(3), - other_details varchar(64) -); - create table customer_address ( customer_id long, - address_id long, + address clob, from_date date, to_date date, address_type_code varchar(12), - constraint customer3_fk foreign key (customer_id) references customer(id), - constraint address_fk foreign key (address_id) references address(id) + constraint customer3_fk foreign key (customer_id) references customer(id) ); diff --git a/querydsl-libraries/pom.xml b/querydsl-libraries/pom.xml index 05035921c4..b8b22d34af 100644 --- a/querydsl-libraries/pom.xml +++ b/querydsl-libraries/pom.xml @@ -23,6 +23,7 @@ querydsl-sql querydsl-sql-spatial querydsl-sql-spring + querydsl-sql-json querydsl-r2dbc diff --git a/querydsl-libraries/querydsl-sql-json/pom.xml b/querydsl-libraries/querydsl-sql-json/pom.xml new file mode 100644 index 0000000000..6ccab170b5 --- /dev/null +++ b/querydsl-libraries/querydsl-sql-json/pom.xml @@ -0,0 +1,224 @@ + + + 4.0.0 + + + io.github.openfeign.querydsl + querydsl-libraries + 6.6-SNAPSHOT + + + querydsl-sql-json + Querydsl - SQL JSON support + SQL JSON support for Querydsl + + + + + com.fasterxml.jackson + jackson-bom + 2.17.2 + pom + import + + + + + + + io.github.openfeign.querydsl + querydsl-codegen + ${project.version} + provided + true + + + io.github.openfeign.querydsl + querydsl-sql-codegen + ${project.version} + provided + true + + + + com.fasterxml.jackson.core + jackson-databind + + + + org.jetbrains + annotations + provided + + + io.github.openfeign.querydsl + querydsl-sql + ${project.version} + + + + + org.hsqldb + hsqldb + ${hsqldb.version} + test + + + + com.ibm.db2 + jcc + ${db2.version} + test + + + org.apache.derby + derby + ${derby.version} + test + + + org.apache.derby + derbytools + ${derby.version} + test + + + mysql + mysql-connector-java + ${mysql.version} + test + + + org.postgresql + postgresql + ${postgresql.version} + provided + + + org.slf4j + slf4j-simple + + + + + com.oracle.database.jdbc + ojdbc8 + ${oracle.version} + test + + + com.microsoft.sqlserver + mssql-jdbc + ${mssql.version} + test + + + com.h2database + h2 + test + + + + com.github.jinahya + cubrid-jdbc-driver-${cubrid.version} + 1.0.0 + test + + + org.firebirdsql.jdbc + jaybird + ${firebird.version} + test + + + + org.xerial + sqlite-jdbc + ${sqlite.version} + test + + + + io.github.openfeign.querydsl + querydsl-core + ${project.version} + test-jar + test + + + io.github.openfeign.querydsl + querydsl-sql + ${project.version} + test-jar + test + + + + jdepend + jdepend + 2.9.1 + test + + + + jakarta.annotation + jakarta.annotation-api + test + + + + + + + org.apache.felix + maven-bundle-plugin + + + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + com.querydsl.sql.json + + + + + + test-jar + + test-jar + + + + + + org.apache.maven.plugins + maven-source-plugin + + + + test-jar + + package + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + derby.stream.error.file + target/derby.log + + + + + + + + diff --git a/querydsl-libraries/querydsl-sql-json/src/main/java/io/github/openfeign/querydsl/sql/json/JsonEntity.java b/querydsl-libraries/querydsl-sql-json/src/main/java/io/github/openfeign/querydsl/sql/json/JsonEntity.java new file mode 100644 index 0000000000..687f064c17 --- /dev/null +++ b/querydsl-libraries/querydsl-sql-json/src/main/java/io/github/openfeign/querydsl/sql/json/JsonEntity.java @@ -0,0 +1,3 @@ +package io.github.openfeign.querydsl.sql.json; + +public interface JsonEntity {} diff --git a/querydsl-libraries/querydsl-sql-json/src/main/java/io/github/openfeign/querydsl/sql/json/JsonSupport.java b/querydsl-libraries/querydsl-sql-json/src/main/java/io/github/openfeign/querydsl/sql/json/JsonSupport.java new file mode 100644 index 0000000000..257f17795d --- /dev/null +++ b/querydsl-libraries/querydsl-sql-json/src/main/java/io/github/openfeign/querydsl/sql/json/JsonSupport.java @@ -0,0 +1,62 @@ +/* + * 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 io.github.openfeign.querydsl.sql.json; + +import com.querydsl.codegen.AbstractModule; +import com.querydsl.codegen.CodegenModule; +import com.querydsl.codegen.Extension; +import com.querydsl.codegen.TypeMappings; +import com.querydsl.codegen.utils.model.ClassType; +import com.querydsl.codegen.utils.model.SimpleType; +import com.querydsl.codegen.utils.model.TypeCategory; +import io.github.openfeign.querydsl.sql.json.types.JSONType; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** {@code JsonSupport} provides support for j types in code generation */ +public final class JsonSupport implements Extension { + + private static void registerTypes(TypeMappings typeMappings) { + typeMappings.register( + new ClassType(TypeCategory.MAP, JsonEntity.class), + new SimpleType(JSONType.class.getSimpleName())); + } + + private static void addImports(AbstractModule module, String packageName) { + @SuppressWarnings("unchecked") + Set imports = module.get(Set.class, CodegenModule.IMPORTS); + if (imports.isEmpty()) { + imports = Collections.singleton(packageName); + } else { + var old = imports; + imports = new HashSet<>(); + imports.addAll(old); + imports.add(packageName); + } + module.bind(CodegenModule.IMPORTS, imports); + } + + /** + * Register spatial types to the given codegen module + * + * @param module module to be customized for spatial support + */ + @Override + public void addSupport(AbstractModule module) { + registerTypes(module.get(TypeMappings.class)); + addImports(module, "io.github.openfeign.querydsl.sql.json.types"); + addImports(module, "io.github.openfeign.querydsl.sql.json"); + } +} diff --git a/querydsl-libraries/querydsl-sql-json/src/main/java/io/github/openfeign/querydsl/sql/json/types/JSONType.java b/querydsl-libraries/querydsl-sql-json/src/main/java/io/github/openfeign/querydsl/sql/json/types/JSONType.java new file mode 100644 index 0000000000..fe3ebe6ccb --- /dev/null +++ b/querydsl-libraries/querydsl-sql-json/src/main/java/io/github/openfeign/querydsl/sql/json/types/JSONType.java @@ -0,0 +1,82 @@ +package io.github.openfeign.querydsl.sql.json.types; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.querydsl.sql.types.Type; +import io.github.openfeign.querydsl.sql.json.JsonEntity; +import java.io.IOException; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Types; + +public class JSONType implements Type { + private final ObjectMapper objectMapper; + + public JSONType(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + public JSONType() { + objectMapper = new ObjectMapper(); + objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); + objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); + objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); + } + + @Override + public int[] getSQLTypes() { + return new int[] {Types.BLOB, Types.VARBINARY, Types.VARCHAR, Types.BINARY}; + } + + @Override + public Class getReturnedClass() { + return JsonEntity.class; + } + + @Override + public String getLiteral(JsonEntity value) { + if (value == null) { + return null; + } + try { + return objectMapper.writeValueAsString(value); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + @Override + public JsonEntity getValue(ResultSet rs, int startIndex) throws SQLException { + try { + return objectMapper.readValue(rs.getBytes(startIndex), JsonEntity.class); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public JsonEntity getValue(ResultSet rs, int startIndex, Class clazz) + throws SQLException { + try { + var value = rs.getBytes(startIndex); + if (value == null) { + return null; + } + return objectMapper.readValue(value, clazz); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void setValue(PreparedStatement st, int startIndex, JsonEntity value) throws SQLException { + st.setObject(startIndex, getLiteral(value)); + } +} diff --git a/querydsl-libraries/querydsl-sql-json/src/main/resources/META-INF/services/com.querydsl.codegen.Extension b/querydsl-libraries/querydsl-sql-json/src/main/resources/META-INF/services/com.querydsl.codegen.Extension new file mode 100644 index 0000000000..017342dde4 --- /dev/null +++ b/querydsl-libraries/querydsl-sql-json/src/main/resources/META-INF/services/com.querydsl.codegen.Extension @@ -0,0 +1 @@ +io.github.openfeign.querydsl.sql.json.JsonSupport \ No newline at end of file diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/Configuration.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/Configuration.java index 4ed2cb171f..de972bae6c 100644 --- a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/Configuration.java +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/Configuration.java @@ -105,7 +105,7 @@ public Configuration(SQLTemplates templates, StatementOptions statementOptions) Float.class); for (Class cl : classes) { int code = jdbcTypeMapping.get(cl); - String name = templates.getTypeNameForCode(code); + var name = templates.getTypeNameForCode(code); Class arrType = Array.newInstance(cl, 0).getClass(); javaTypeMapping.register(new ArrayType(arrType, name)); if (PrimitiveUtils.isWrapperType(cl) && !cl.equals(Byte.class)) { @@ -201,7 +201,7 @@ public Class getJavaType( typeName = typeName.substring(0, typeName.indexOf("(")); } - Integer sqlComponentType = templates.getCodeForTypeName(typeName); + var sqlComponentType = templates.getCodeForTypeName(typeName); if (sqlComponentType == null) { logger.warning("Found no JDBC type for " + typeName + " using OTHER instead"); sqlComponentType = Types.OTHER; @@ -239,7 +239,7 @@ public T get(ResultSet rs, @Nullable Path path, int i, Class clazz) */ @Nullable public SchemaAndTable getOverride(SchemaAndTable key) { - SchemaAndTable result = nameMapping.getOverride(key).orElse(key); + var result = nameMapping.getOverride(key).orElse(key); if (schemaMapping.containsKey(key.getSchema())) { result = new SchemaAndTable(schemaMapping.get(key.getSchema()), result.getTable()); } @@ -287,7 +287,7 @@ public void set(PreparedStatement stmt, Path path, int i, T value) throws if (value == null || value instanceof Null) { Integer sqlType = null; if (path != null) { - ColumnMetadata columnMetadata = ColumnMetadata.getColumnMetadata(path); + var columnMetadata = ColumnMetadata.getColumnMetadata(path); if (columnMetadata.hasJdbcType()) { sqlType = columnMetadata.getJdbcType(); } @@ -308,8 +308,8 @@ private Type getType(@Nullable Path path, Class clazz) { && path != null && !clazz.equals(Null.class) && path.getMetadata().getParent() instanceof RelationalPath) { - String table = ((RelationalPath) path.getMetadata().getParent()).getTableName(); - String column = ColumnMetadata.getName(path); + var table = ((RelationalPath) path.getMetadata().getParent()).getTableName(); + var column = ColumnMetadata.getName(path); Type type = (Type) javaTypeMapping.getType(table, column); if (type != null) { return type; @@ -383,7 +383,7 @@ public String registerTableOverride(String oldTable, String newTable) { */ @Deprecated public String registerTableOverride(String schema, String oldTable, String newTable) { - SchemaAndTable st = registerTableOverride(schema, oldTable, schema, newTable); + var st = registerTableOverride(schema, oldTable, schema, newTable); return st != null ? st.getTable() : null; } @@ -489,8 +489,8 @@ public void registerNumeric(int total, int decimal, Class javaType) { */ public void registerNumeric( int beginTotal, int endTotal, int beginDecimal, int endDecimal, Class javaType) { - for (int total = beginTotal; total <= endTotal; total++) { - for (int decimal = beginDecimal; decimal <= endDecimal; decimal++) { + for (var total = beginTotal; total <= endTotal; total++) { + for (var decimal = beginDecimal; decimal <= endDecimal; decimal++) { registerNumeric(total, decimal, javaType); } } @@ -597,4 +597,8 @@ public void setExceptionTranslator(SQLExceptionTranslator exceptionTranslator) { public void setTemplates(SQLTemplates templates) { this.templates = templates; } + + public Type getType(String tableName, String columnName) { + return javaTypeMapping.getType(tableName, columnName); + } } diff --git a/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/SimpleType.java b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/SimpleType.java new file mode 100644 index 0000000000..4ec19bb97e --- /dev/null +++ b/querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/types/SimpleType.java @@ -0,0 +1,58 @@ +/* + * 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.sql.types; + +import java.sql.*; +import org.jetbrains.annotations.Nullable; + +/** {@code SimpleType} maps Java classes on the JDBC level */ +public class SimpleType implements Type { + + private String classname; + + public SimpleType(String classname) { + this.classname = classname; + } + + @Override + public int[] getSQLTypes() { + return new int[] {Types.OTHER}; + } + + @Override + public Class getReturnedClass() { + return Object.class; + } + + @Override + public String getLiteral(Object value) { + return classname; + } + + public String getClassname() { + return classname; + } + + @Override + public @Nullable Object getValue(ResultSet rs, int startIndex) throws SQLException { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setValue(PreparedStatement st, int startIndex, Object value) throws SQLException { + // TODO Auto-generated method stub + + } +} diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/ColumnData.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/ColumnData.java deleted file mode 100644 index 23f20121d3..0000000000 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/ColumnData.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2010 Mysema Ltd. - * All rights reserved. - * - */ -package com.querydsl.sql.ddl; - -/** - * @author tiwe - */ -public class ColumnData { - - private final String name; - - private final String type; - - private boolean nullAllowed = true; - - private boolean autoIncrement; - - private Integer size; - - public ColumnData(String name, String type) { - this.name = name; - this.type = type; - } - - public String getName() { - return name; - } - - public String getType() { - return type; - } - - public boolean isNullAllowed() { - return nullAllowed; - } - - public void setNullAllowed(boolean nullAllowed) { - this.nullAllowed = nullAllowed; - } - - public void setSize(Integer size) { - this.size = size; - } - - public Integer getSize() { - return size; - } - - public boolean isAutoIncrement() { - return autoIncrement; - } - - public void setAutoIncrement(boolean autoIncrement) { - this.autoIncrement = autoIncrement; - } -} diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/CreateTableClause.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/CreateTableClause.java deleted file mode 100644 index f0fb715f63..0000000000 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/CreateTableClause.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright (c) 2010 Mysema Ltd. - * All rights reserved. - * - */ -package com.querydsl.sql.ddl; - -import com.querydsl.core.QueryException; -import com.querydsl.sql.Configuration; -import com.querydsl.sql.SQLTemplates; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; - -/** - * CreateTableClause defines a CREATE TABLE clause - * - * @author tiwe - */ -public class CreateTableClause { - - private static final Logger logger = Logger.getLogger(CreateTableClause.class.getName()); - - private final Connection connection; - - private final Configuration configuration; - - private final SQLTemplates templates; - - private final String table; - - private final List columns = new ArrayList(); - - private final List indexes = new ArrayList(); - - private PrimaryKeyData primaryKey; - - private final List foreignKeys = new ArrayList(); - - public CreateTableClause(Connection conn, Configuration c, String table) { - this.connection = conn; - this.configuration = c; - this.templates = c.getTemplates(); - this.table = templates.quoteIdentifier(table); - } - - /** - * Add a new column definition - * - * @param name - * @param type - * @return - */ - public CreateTableClause column(String name, Class type) { - String typeName = configuration.getTypeName(type); - columns.add(new ColumnData(templates.quoteIdentifier(name), typeName)); - return this; - } - - private ColumnData lastColumn() { - return columns.getLast(); - } - - /** - * Set the last added column to not null - * - * @return - */ - public CreateTableClause notNull() { - lastColumn().setNullAllowed(false); - return this; - } - - /** - * Set the size of the last column's type - * - * @param size - * @return - */ - public CreateTableClause size(int size) { - lastColumn().setSize(size); - return this; - } - - /** - * Set the last column to auto increment - * - * @return - */ - public CreateTableClause autoIncrement() { - lastColumn().setAutoIncrement(true); - return this; - } - - /** - * Set the primary key - * - * @param name - * @param columns - * @return - */ - public CreateTableClause primaryKey(String name, String... columns) { - for (int i = 0; i < columns.length; i++) { - columns[i] = templates.quoteIdentifier(columns[i]); - } - primaryKey = new PrimaryKeyData(templates.quoteIdentifier(name), columns); - return this; - } - - /** - * Add an index - * - * @param name - * @param columns - * @return - */ - public CreateTableClause index(String name, String... columns) { - indexes.add(new IndexData(name, columns)); - return this; - } - - /** - * Set the last added index to unique - * - * @return - */ - public CreateTableClause unique() { - indexes.getLast().setUnique(true); - return this; - } - - /** - * Add a foreign key - * - * @param name - * @param columns - * @return - */ - public ForeignKeyBuilder foreignKey(String name, String... columns) { - return new ForeignKeyBuilder( - this, templates, foreignKeys, templates.quoteIdentifier(name), columns); - } - - /** Execute the clause */ - @SuppressWarnings("SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE") - public void execute() { - StringBuilder builder = new StringBuilder(); - builder.append(templates.getCreateTable()).append(table).append(" (\n"); - List lines = new ArrayList(columns.size() + foreignKeys.size() + 1); - // columns - for (ColumnData column : columns) { - StringBuilder line = new StringBuilder(); - line.append(column.getName()).append(" ").append(column.getType().toUpperCase()); - if (column.getSize() != null) { - line.append("(").append(column.getSize()).append(")"); - } - if (!column.isNullAllowed()) { - line.append(templates.getNotNull().toUpperCase()); - } - if (column.isAutoIncrement()) { - line.append(templates.getAutoIncrement().toUpperCase()); - } - lines.add(line.toString()); - } - - // primary key - if (primaryKey != null) { - StringBuilder line = new StringBuilder(); - line.append("CONSTRAINT ").append(primaryKey.getName()).append(" "); - line.append("PRIMARY KEY(").append(String.join(", ", primaryKey.getColumns())).append(")"); - lines.add(line.toString()); - } - - // foreign keys - for (ForeignKeyData foreignKey : foreignKeys) { - StringBuilder line = new StringBuilder(); - line.append("CONSTRAINT ").append(foreignKey.getName()).append(" "); - line.append("FOREIGN KEY(") - .append(String.join(", ", foreignKey.getForeignColumns())) - .append(") "); - line.append("REFERENCES ") - .append(foreignKey.getTable()) - .append("(") - .append(String.join(", ", foreignKey.getParentColumns())) - .append(")"); - lines.add(line.toString()); - } - builder.append(" ").append(String.join(",\n ", lines)); - builder.append("\n)\n"); - logger.info(builder.toString()); - - try (Statement stmt = connection.createStatement()) { - stmt.execute(builder.toString()); - - // indexes - for (IndexData index : indexes) { - String indexColumns = String.join(", ", index.getColumns()); - String prefix = templates.getCreateIndex(); - if (index.isUnique()) { - prefix = templates.getCreateUniqueIndex(); - } - String sql = - prefix + index.getName() + templates.getOn() + table + "(" + indexColumns + ")"; - logger.info(sql); - stmt.execute(sql); - } - } catch (SQLException e) { - System.err.println(builder.toString()); - throw new QueryException(e.getMessage(), e); - } - } -} diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/DropTableClause.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/DropTableClause.java deleted file mode 100644 index 1717ec09d8..0000000000 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/DropTableClause.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2010 Mysema Ltd. - * All rights reserved. - * - */ -package com.querydsl.sql.ddl; - -import com.querydsl.core.QueryException; -import com.querydsl.sql.Configuration; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; - -/** - * DropTableClause defines a DROP TABLE clause - * - * @author tiwe - */ -public class DropTableClause { - - private final Connection connection; - - private final String table; - - public DropTableClause(Connection conn, Configuration c, String table) { - this.connection = conn; - this.table = c.getTemplates().quoteIdentifier(table); - } - - @SuppressWarnings("SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE") - public void execute() { - Statement stmt = null; - try { - stmt = connection.createStatement(); - stmt.execute("DROP TABLE " + table); - } catch (SQLException e) { - // do not rethrow - } finally { - if (stmt != null) { - try { - stmt.close(); - } catch (SQLException e) { - throw new QueryException(e); - } - } - } - } -} diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/ForeignKeyBuilder.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/ForeignKeyBuilder.java deleted file mode 100644 index ce42bef972..0000000000 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/ForeignKeyBuilder.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2010 Mysema Ltd. - * All rights reserved. - * - */ -package com.querydsl.sql.ddl; - -import com.querydsl.sql.SQLTemplates; -import java.util.List; - -/** - * ForeignKeyBuilder is part of the fluent interface of CreateTableClause - * - * @author tiwe - */ -public class ForeignKeyBuilder { - - private final List foreignKeys; - - private final CreateTableClause clause; - - private final String name; - - private final String[] foreignColumns; - - private final SQLTemplates templates; - - public ForeignKeyBuilder( - CreateTableClause clause, - SQLTemplates templates, - List foreignKeys, - String name, - String[] columns) { - this.clause = clause; - this.templates = templates; - this.foreignKeys = foreignKeys; - this.name = name; - this.foreignColumns = columns.clone(); - } - - public CreateTableClause references(String table, String... parentColumns) { - ForeignKeyData foreignKey = new ForeignKeyData(name, templates.quoteIdentifier(table)); - for (int i = 0; i < parentColumns.length; i++) { - foreignKey.add( - templates.quoteIdentifier(foreignColumns[i]), - templates.quoteIdentifier(parentColumns[i])); - } - foreignKeys.add(foreignKey); - return clause; - } -} diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/ForeignKeyData.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/ForeignKeyData.java deleted file mode 100644 index 50d2e84f94..0000000000 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/ForeignKeyData.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2010 Mysema Ltd. - * All rights reserved. - * - */ -package com.querydsl.sql.ddl; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author tiwe - */ -public class ForeignKeyData implements KeyData { - - private final String name; - - private final String table; - - private final List foreignColumns = new ArrayList(); - - private final List parentColumns = new ArrayList(); - - public ForeignKeyData(String name, String parentTable) { - this.name = name; - this.table = parentTable; - } - - public void add(String foreignColumn, String parentColumn) { - foreignColumns.add(foreignColumn); - parentColumns.add(parentColumn); - } - - public String getName() { - return name; - } - - public String getTable() { - return table; - } - - public List getForeignColumns() { - return foreignColumns; - } - - public List getParentColumns() { - return parentColumns; - } -} diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/IndexData.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/IndexData.java deleted file mode 100644 index 93a7c82618..0000000000 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/IndexData.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2010 Mysema Ltd. - * All rights reserved. - * - */ -package com.querydsl.sql.ddl; - -/** - * @author tiwe - */ -public class IndexData { - - private final String name; - - private final String[] columns; - - private boolean unique; - - public IndexData(String name, String[] columns) { - this.name = name; - this.columns = columns.clone(); - } - - public String getName() { - return name; - } - - public String[] getColumns() { - return columns.clone(); - } - - public boolean isUnique() { - return unique; - } - - public void setUnique(boolean unique) { - this.unique = unique; - } -} diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/KeyData.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/KeyData.java deleted file mode 100644 index 03950c8a6b..0000000000 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/KeyData.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * - */ -package com.querydsl.sql.ddl; - -import java.util.List; - -/** - * Common interface for ForeignKeyData and InverseForeignKeyData - * - * @author tiwe - */ -public interface KeyData { - - String getName(); - - String getTable(); - - List getForeignColumns(); - - List getParentColumns(); -} diff --git a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/PrimaryKeyData.java b/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/PrimaryKeyData.java deleted file mode 100644 index cb740c6b84..0000000000 --- a/querydsl-libraries/querydsl-sql/src/test/java/com/querydsl/sql/ddl/PrimaryKeyData.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2010 Mysema Ltd. - * All rights reserved. - * - */ -package com.querydsl.sql.ddl; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * @author tiwe - */ -public class PrimaryKeyData { - - private final String name; - - private final List columns = new ArrayList(); - - public PrimaryKeyData(String name) { - this.name = name; - } - - public PrimaryKeyData(String name, String[] c) { - this.name = name; - columns.addAll(Arrays.asList(c)); - } - - public void add(String column) { - columns.add(column); - } - - public String getName() { - return name; - } - - public List getColumns() { - return columns; - } -} diff --git a/querydsl-tooling/querydsl-sql-codegen/src/main/java/com/querydsl/sql/codegen/MetaDataExporter.java b/querydsl-tooling/querydsl-sql-codegen/src/main/java/com/querydsl/sql/codegen/MetaDataExporter.java index 1a3ce984d0..7b0ac8adbe 100644 --- a/querydsl-tooling/querydsl-sql-codegen/src/main/java/com/querydsl/sql/codegen/MetaDataExporter.java +++ b/querydsl-tooling/querydsl-sql-codegen/src/main/java/com/querydsl/sql/codegen/MetaDataExporter.java @@ -424,6 +424,8 @@ private void handleColumn(EntityType classModel, String tableName, ResultSet col columnDigits != null ? columnDigits.intValue() : 0, tableName, columnName); + + com.querydsl.sql.types.Type type = configuration.getType(tableName, normalizedColumnName); if (clazz == null) { clazz = Object.class; } @@ -433,7 +435,10 @@ private void handleColumn(EntityType classModel, String tableName, ResultSet col } else if (Enum.class.isAssignableFrom(clazz)) { fieldType = TypeCategory.ENUM; } - Type typeModel = new ClassType(fieldType, clazz); + Type typeModel = + type instanceof com.querydsl.sql.types.SimpleType + ? asModel((com.querydsl.sql.types.SimpleType) type) + : new ClassType(fieldType, clazz); Property property = createProperty(classModel, normalizedColumnName, propertyName, typeModel); ColumnMetadata column = ColumnMetadata.named(normalizedColumnName).ofType(columnType).withIndex(columnIndex); @@ -463,6 +468,14 @@ private void handleColumn(EntityType classModel, String tableName, ResultSet col classModel.addProperty(property); } + private Type asModel(com.querydsl.sql.types.SimpleType st) { + String fullname = st.getClassname(); + return new SimpleType( + fullname, + fullname.substring(0, fullname.lastIndexOf('.')), + fullname.substring(fullname.lastIndexOf('.') + 1)); + } + private void handleTable(DatabaseMetaData md, ResultSet tables) throws SQLException { String catalog = tables.getString("TABLE_CAT"); String schema = tables.getString("TABLE_SCHEM"); diff --git a/querydsl-tooling/querydsl-sql-codegen/src/main/java/com/querydsl/sql/codegen/support/TypeMapping.java b/querydsl-tooling/querydsl-sql-codegen/src/main/java/com/querydsl/sql/codegen/support/TypeMapping.java index 46ba96abd2..ea08c5e7ea 100644 --- a/querydsl-tooling/querydsl-sql-codegen/src/main/java/com/querydsl/sql/codegen/support/TypeMapping.java +++ b/querydsl-tooling/querydsl-sql-codegen/src/main/java/com/querydsl/sql/codegen/support/TypeMapping.java @@ -45,7 +45,9 @@ public void apply(Configuration configuration) { } else { configuration.register(table, column, typeClass); } - } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { + } catch (ClassNotFoundException e) { + configuration.register(table, column, new com.querydsl.sql.types.SimpleType(type)); + } catch (IllegalAccessException | InstantiationException e) { throw new RuntimeException(e); } } @@ -73,4 +75,9 @@ public String getType() { public void setType(String type) { this.type = type; } + + @Override + public String toString() { + return "TypeMapping [table=" + table + ", column=" + column + ", type=" + type + "]"; + } } From 15021333da4e95f5ba5a4216e1dcfbe9295ef3ea Mon Sep 17 00:00:00 2001 From: Marvin Froeder Date: Thu, 1 Aug 2024 21:06:14 -0300 Subject: [PATCH 4/6] Minor code clean up --- .../src/main/java/com/querydsl/example/FruitResource.java | 4 ++-- .../src/main/java/com/querydsl/example/Customer.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/querydsl-examples/querydsl-example-jpa-quarkus/src/main/java/com/querydsl/example/FruitResource.java b/querydsl-examples/querydsl-example-jpa-quarkus/src/main/java/com/querydsl/example/FruitResource.java index f447ca2cf7..e0027254f0 100644 --- a/querydsl-examples/querydsl-example-jpa-quarkus/src/main/java/com/querydsl/example/FruitResource.java +++ b/querydsl-examples/querydsl-example-jpa-quarkus/src/main/java/com/querydsl/example/FruitResource.java @@ -101,8 +101,8 @@ public Response toResponse(Exception exception) { LOGGER.error("Failed to handle request", exception); int code = 500; - if (exception instanceof WebApplicationException) { - code = ((WebApplicationException) exception).getResponse().getStatus(); + if (exception instanceof WebApplicationException applicationException) { + code = applicationException.getResponse().getStatus(); } ObjectNode exceptionJson = objectMapper.createObjectNode(); diff --git a/querydsl-examples/querydsl-example-jpa-spring/src/main/java/com/querydsl/example/Customer.java b/querydsl-examples/querydsl-example-jpa-spring/src/main/java/com/querydsl/example/Customer.java index ab4f6791a1..ea2f2063dd 100755 --- a/querydsl-examples/querydsl-example-jpa-spring/src/main/java/com/querydsl/example/Customer.java +++ b/querydsl-examples/querydsl-example-jpa-spring/src/main/java/com/querydsl/example/Customer.java @@ -24,7 +24,7 @@ public Customer(String firstName, String lastName) { @Override public String toString() { - return String.format("Customer[id=%d, firstName='%s', lastName='%s']", id, firstName, lastName); + return "Customer[id=%d, firstName='%s', lastName='%s']".formatted(id, firstName, lastName); } public Long getId() { From 2f2264dc2ef244a3983e5e9b2153d51674da4a51 Mon Sep 17 00:00:00 2001 From: Marvin Froeder Date: Thu, 1 Aug 2024 21:07:27 -0300 Subject: [PATCH 5/6] Include querydsl-json on examples build --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0d80a15866..0da9dcee47 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -140,7 +140,7 @@ jobs: - run: name: 'Test' command: | - ./mvnw -ntp -B install -Pquickbuild -pl :querydsl-sql-spring,:querydsl-jpa-spring,:querydsl-kotlin-codegen,:querydsl-mongodb,:querydsl-r2dbc -am -T2 + ./mvnw -ntp -B install -Pquickbuild -pl :querydsl-sql-spring,:querydsl-jpa-spring,:querydsl-kotlin-codegen,:querydsl-mongodb,:querydsl-r2dbc,:querydsl-json -am -T2 ./mvnw -ntp -B verify -Pexamples -rf :querydsl-examples - save-test-results buildQuarkusExample: From b4fb160103ae832571e6376edc3df257cb626132 Mon Sep 17 00:00:00 2001 From: Marvin Froeder Date: Thu, 1 Aug 2024 21:07:27 -0300 Subject: [PATCH 6/6] Include querydsl-json on examples build --- .circleci/config.yml | 2 +- querydsl-examples/pom.xml | 4 ++++ querydsl-examples/querydsl-example-jpa-spring/pom.xml | 5 ----- .../querydsl-example-r2dbc-sql-codegen/pom.xml | 9 --------- querydsl-examples/querydsl-example-sql-spring/pom.xml | 9 --------- 5 files changed, 5 insertions(+), 24 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0da9dcee47..48c94abd3a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -140,7 +140,7 @@ jobs: - run: name: 'Test' command: | - ./mvnw -ntp -B install -Pquickbuild -pl :querydsl-sql-spring,:querydsl-jpa-spring,:querydsl-kotlin-codegen,:querydsl-mongodb,:querydsl-r2dbc,:querydsl-json -am -T2 + ./mvnw -ntp -B install -Pquickbuild -pl :querydsl-sql-spring,:querydsl-jpa-spring,:querydsl-kotlin-codegen,:querydsl-mongodb,:querydsl-r2dbc,:querydsl-sql-json -am -T2 ./mvnw -ntp -B verify -Pexamples -rf :querydsl-examples - save-test-results buildQuarkusExample: diff --git a/querydsl-examples/pom.xml b/querydsl-examples/pom.xml index 2a347dfb98..4b26d59ff9 100644 --- a/querydsl-examples/pom.xml +++ b/querydsl-examples/pom.xml @@ -12,6 +12,10 @@ pom Querydsl - Examples + + 17 + + querydsl-example-sql-guice querydsl-example-sql-spring diff --git a/querydsl-examples/querydsl-example-jpa-spring/pom.xml b/querydsl-examples/querydsl-example-jpa-spring/pom.xml index 53dc713083..3c7b6d3e84 100755 --- a/querydsl-examples/querydsl-example-jpa-spring/pom.xml +++ b/querydsl-examples/querydsl-example-jpa-spring/pom.xml @@ -10,11 +10,6 @@ querydsl-example-jpa-spring Querydsl example - JPA Spring - - - 17 - - diff --git a/querydsl-examples/querydsl-example-r2dbc-sql-codegen/pom.xml b/querydsl-examples/querydsl-example-r2dbc-sql-codegen/pom.xml index 171b8d8954..f9ee8088d8 100644 --- a/querydsl-examples/querydsl-example-r2dbc-sql-codegen/pom.xml +++ b/querydsl-examples/querydsl-example-r2dbc-sql-codegen/pom.xml @@ -11,13 +11,6 @@ querydsl-example-r2dbc-sql-codegen Querydsl example - R2DBC SQL Codegen - - UTF-8 - - - 17 - - @@ -31,9 +24,7 @@ - - org.springframework spring-context diff --git a/querydsl-examples/querydsl-example-sql-spring/pom.xml b/querydsl-examples/querydsl-example-sql-spring/pom.xml index e2c7d96386..170e65c1f1 100644 --- a/querydsl-examples/querydsl-example-sql-spring/pom.xml +++ b/querydsl-examples/querydsl-example-sql-spring/pom.xml @@ -11,17 +11,8 @@ querydsl-example-sql-spring Querydsl example - SQL Spring - - UTF-8 - - - 17 - - - - org.springframework spring-context