QueryDSL 5.0 快照已发布,久等了!

QueryDSL 5.0 快照已发布,久等了!

Xy718 1,049 2021-06-17

我说JPA+QueryDSL是最好的orm实现方案没人反对吧?

从开始使用jpa+QueryDSL之后所有话事的新项目和还未完成的老项目也都换成了这种方案来实现orm
因为真的很香!
TI9TWT_MUQOBRL.jpg

6月16日17日 querydsl团队合并了QueryDSL 5 的pr,时隔9个月,QueryDSL也终于迎来了新的大版本,
image.png

本来想等等英语好的老哥翻译看看有啥新功能的,但是等不及了,配合蹩脚的英语和机翻,直接先吃!
以下来自官方github的release

QueryDSL 5.0.0.M1

此版本的 QueryDSL 以最低支持Java8为目标,进行了各种改进,为现代 Java 生态做准备。
删除了 joda-time:joda-timecom.google.guava:guavacom.google.code.findbugs:jsr305 的运行时(runtime)依赖

因为QueryDSL项目大部分时间都没有得到维护,所以5.0也是大家期待已久的版本!我们将在该版本中优先解决在社区中被反复提出的历史遗留问题

非常感谢所有的贡献者牺牲了自己的休息时间做出贡献,使得这个版本成为了可能:

New features

  • #2672 - 在Java8源码层面对性能和代码做了各种提升和改进

  • #2672 - 添加了返回Stream<T>Fetchable#stream()。(笔:这个新功能还是蛮重要的)

    Make sure that the returned stream is always closed to free up resources, for example using try-with-resources.
    It does not suffice to rely on a terminating operation on the stream for this (i.e. forEach, collect).

  • #2324 - 移除Guava依赖项

    Almost no required transitive dependencies to get started with QueryDSL.
    And no more conflicts with Guava versions required by your other tools or own application.

  • #2025 - joda-time:joda-time 不再是 querydsl-sql 的必要依赖项.

    By default, the Java 8 date/time API is used for date/time operations.
    The joda-time:joda-time types will still be registered automatically if they are on the classpath.

  • #2215 - 通过文档API支持MongoDB 4

  • #2697 - 允许com.querydsl.core.alias.Alias.*依靠ECJ作为编译器,在JRE上使用。

  • #2479 - Swap out JSR305 for Jetbrains Annotations.
    Because the Jetbrains Annotations, contrary to the JSR305 annotations, use a Class retention level, Jetbrains Annotations
    does not have to be available at runtime and is not a transitive dependency.

  • #658 - 增加了JPAExpressions#treat,可用于生成JPA 2.1的TreatedPath表达式。

  • #2666 - 在JPA中使用不支持的查询功能时,有更具体的错误信息。

  • #2106 - querydsl-collections实现了NullsLast排序.

  • #2404 - Upgrade of JTS / Geolatte in querydsl-spatial

  • #2320 - HibernateDomainExporterJPADomainExporter支持了Spatial

  • #2612 - 支持 Jakarta EE 新版本的 jakarta.* 包(available through thejakarta classifiers for Maven)

  • #1376 - Expression的函数nullifcoalesce返回的Expression有了具体返回类型(笔:打个比方就是Qxxx.fieldXX.nullif()函数)

  • #1828 - Kotlin Codegen支持

  • #2798 - Java Record 支持(笔:高版本的东西,Java14开始出现,Java8没有哈哈)

Bugfixes

  • #2579 - Count query generation in JPASQLQuery
  • #2671 - Fixed a concurrency issue in Alias.*. Alias.* is now Thread safe.
  • #2053 - Work around issues with AbstractJPAQuery#fetchResults and AbstractJPAQuery#fetchCount in a query with a having clause by using an in-memory calculation.
  • #2504 - Work around issues with AbstractJPAQuery#fetchResults and AbstractJPAQuery#fetchCount in a query with multiple group by expressions by using an in-memory calculation.
  • #2663 - Fix issues with the JPA implementation of InsertClause.
  • #2706 - Fix a memory leak in TemplateFactory.
  • #2467 - Prevent ExtendedBeanSerializer from generating toString method twice
  • #2326 - Use JPA indexed parameters instead of HQL’s legacy positional parameters
  • #2816 - Generated JPA query with incorrect argument binding indexes
  • #1413 - Incorrect parameter values with Hibernate custom types
  • #1429 - Reusing of constants in JPQL generation causes issues with hibernate query caching

Breaking changes(破坏性更新)

  • 最低支持Java8. 如果你使用Java7以下,请使用4.X.X版本的QueryDSL
  • JavaSE6SQLExceptionWrapper and other parts regarding pre-Java 7 exception handling are removed.
  • 删除了为了向后兼容传统API而设置的桥接方法。这可能会导致一些破坏性的API变化。
  • 删除了依赖项Guava。如果您的应用程序依赖Guava,请确保将其添加为项目的直接依赖项,而不是依赖 QueryDSL 传递它。
  • In order for Guava to be removed Mysema Codegen had to be rereleased as QueryDSL Codegen Utils.
    Therefore, the classes in this module moved to a different package: com.mysema.codegen is now com.querydsl.codegen.utils.
    This for example affects com.mysema.codegen.model.SimpleType.
    Although many applications won’t touch the codgen internal classes, custom APT extensions might be affected by this.
  • 由于移除了 Guava,任何接收 ImmutableList 作为参数的方法现在都接受任何 List
    Normal code should handle this signature just fine.
    However, make sure to check any reflective uses of these parameters.
  • 用于DefaultConfigurationquerydsl.variableNameFunctionClass属性现在应该提供java.util.function.Function,而不是com.google.common.base.Function
  • CodeWriter#beginStaticMethod现在采用java.util.function.Function而不是com.google.common.base.Function.
  • AbstractLuceneQuery现在采用java.util.function.Function而不是com.google.common.base.Function.
  • AbstractMongodbQuery现在采用java.util.function.Function而不是com.google.common.base.Function.
  • com.querydsl.codegen.NamingFunction, EvaluatorFunction, DefaultVariableFunction从继承com.google.common.base.Function改为继承java.util.function.Function.
  • 任何需要传入javax.inject.Provider的构造函数,现在都需要一个java.util.function.Supplier来代替。在大多数情况下,你可以用provider::get代替这个参数
  • 这个版本继承的Hibernate主要针对Hibernate5.2。如果你需要Hibernate 4方言的特定工作方法,请使用HQLTemplates而不是Hibernate5Templates
  • 删除了所有的弃用函数
  • joda-time:joda-time现在是一个可选的依赖关系。如果你的应用程序也依赖了joda-time:joda-time,请确保将其作为直接依赖关系,而不是依靠QueryDSL来引入它。
  • com.google.code.findbugs:jsr305 is no longer a dependency. If your application currently relies on QueryDSL shipping JSR305 transitively, you should add JSR305 as a direct dependency to your project.(笔:同上,不翻译了)
  • MDC keys现在使用下划线_而不是点.作为分隔符:querydsl.query现在是querydsl_query,querydsl.parameters是querydsl_parameters。
  • Removal of PolyHedralSurface in querydsl-spatial and querydsl-sql-spatial due to the upgrade of geolatte-geom.
  • com.querydsl.apt.Extension moved to com.querydsl.codegen and now resides in the querydsl-codegen module.
  • com.querydsl.apt.SpatialSupport moved to com.querydsl.spatial.apt.SpatialSupport and now resides in the querydsl-spatial module.
  • com.querydsl.sql.codegen.SpatialSupport moved to com.querydsl.sql.spatial.SpatialSupport and now resides in the querydsl-sql-spatial module.(笔:同上,一些模块上的变化)
  • SQLServerGeometryReader in querydsl-sql-spatial is removed in favour of org.geolatte.geom.codec.db.sqlserver.*.
  • PGgeometryConverter in querydsl-sql-spatial is removed in favour of org.geolatte.geom.codec.Wkt.
  • JGeometryConverter in querydsl-sql-spatial is removed in favour of org.geolatte.geom.codec.db.oracle.*.(笔:同上,querydsl-sql-spatial的一些XX代替了一些XX)
  • 删除了querysql-jpa-codegen中的HibernateDomainExporterHibernateDomainExporter只支持Hibernate 4,而QueryDSL不再积极支持Hibernate。相反,使用Hibernate和JPADomainExporter。
  • ComparableExpression#coalesce(和其子类型)不再返回mutable的Coalesce Expression,而是返回一个具体类型(typed)的Expression。
    如果您需要 Coalesce builder,请改用 new Coalesce<T>().add(expression)
  • getConstantToNamedLabelgetConstantToNumberedLabelgetConstantToAllLabels是在SerializerBaseJPQLSerializer中临时引入的,用于最终取代 QueryDSL 4.3.0的getConstantToLabel
    现在getConstantToLabel已被删除,转而使用getConstants

Deprecations (弃用)

  • AbstractJPAQuery#fetchResultsAbstractJPAQuery#fetchCount现在已经不再适用于有多个group by表达式或有子句的查询,因为这些情况不能由纯JPA支持,而是在内存中来计算的。

如果不需要计算结果的总数,我们建议使用AbstractJPAQuery#fetch来代替。

如果你想要一个即便复杂但是可靠的方法来计算分页结果的数量,我们建议使用Blaze-Persistence QueryDSL integration

BlazeJPAQuery正确地实现了fetchResultsfetchCount,甚至还带有page方法。

  • getConstantToLabel which was deprecated in QueryDSL 4.3.0 is no longer deprecated.(笔:上面破坏性更新说了)

Dependency updates (依赖升级)

  • cglib:cglib to 3.3.0 for Java 8+ support
  • org.eclipse.jdt.core.compiler:ecj to 4.6.1 for Java 8+ support
  • joda-time:joda-time to 2.10.10 for better interoperability with other frameworks that use more recent versions than QueryDSL.
    joda-time:joda-time is also no longer a required dependency and as such is no longer provided transitively to your application.
    If your application relies on joda-time:joda-time being available, make sure to add the dependency to your project.
  • org.geolatte:geolatte-geom to 1.8.1 for better interopability with Hibernate Spatial.
    querydsl-spatial is still backwards compatible with older versions of Geolatte, however, querydsl-sql-spatial is not and requires 1.4.0 or newer.
  • com.vividsolutions:jts to org.locationtech:jts for better interopability with Hibernate Spatial.
    com.vividsolutions:jts is still supported for querydsl-spatial if an older version of org.geolatte:geolatte-geom is provided.
  • DataNucleus 5.2.x for Java 8+ support
    • JDO now uses org.datanucleus:javax.jdo instead of javax.jdo:jdo-api
  • com.google.guava:guava is no longer a dependency of QueryDSL and as such is no longer provided transitively to your application.
    If your application relies on com.google.guava:guava being available, make sure to add the dependency to your project.
  • com.google.code.findbugs:jsr305 is no longer a dependency of QueryDSL and as such is no longer provided transitively to your application.
    If your application relies on com.google.code.findbugs:jsr305 being available, make sure to add the dependency to your project.

以上

有很多地方可能翻译有错误,希望大家指出🖖

有部分翻译,比如bugfix和依赖升级的地方我没有做翻译,因为翻译起来难度很大(我是废物!),有遇到bug的小伙伴可能也不需要我的翻译,直接就看到了,所以没有翻译👐

翻译的过程虽然比较消耗精力,但是可以很好地了解一个项目的更新内容和方向,还是很快乐的💖


冶心·练体·得技