Migration Guide

以下部分说明如何迁移到 Spring Data R2DBC 的较新版本。

The following sections explain how to migrate to a newer version of Spring Data R2DBC.

Upgrading from 1.1.x to 1.2.x

Spring Data R2DBC 的开发意在评估 R2DBC 与 Spring 应用程序的集成效果如何。一旦 R2DBC 支持证明是有用的,主要方面之一是将核心支持移入 Spring Framework。Spring Framework 5.3 附带一个新模块:Spring R2DBC (spring-r2dbc)。

Spring Data R2DBC was developed with the intent to evaluate how well R2DBC can integrate with Spring applications. One of the main aspects was to move core support into Spring Framework once R2DBC support has proven useful. Spring Framework 5.3 ships with a new module: Spring R2DBC (spring-r2dbc).

spring-r2dbc 附带最初由 Spring Data R2DBC 提供的核心 R2DBC 功能(DatabaseClient 的精简变体、事务管理器、连接工厂初始化、异常转换)。1.2.0 版本与 Spring R2DBC 中提供的功能一致,进行了以下部分中概述的几项更改。

spring-r2dbc ships core R2DBC functionality (a slim variant of DatabaseClient, Transaction Manager, Connection Factory initialization, Exception translation) that was initially provided by Spring Data R2DBC. The 1.2.0 release aligns with what’s provided in Spring R2DBC by making several changes outlined in the following sections.

Spring R2DBC 的 DatabaseClient 是一种封装了面向 SQL 的纯接口的轻量级实现。您会注意到用于运行 SQL 语句的方法已从 DatabaseClient.execute(…) 更改为 DatabaseClient.sql(…)。CRUD 操作的 fluent API 已移入 R2dbcEntityTemplate

Spring R2DBC’s DatabaseClient is a more lightweight implementation that encapsulates a pure SQL-oriented interface. You will notice that the method to run SQL statements changed from DatabaseClient.execute(…) to DatabaseClient.sql(…). The fluent API for CRUD operations has moved into R2dbcEntityTemplate.

如果您通过日志记录前缀 org.springframework.data.r2dbc 记录 SQL 语句,请务必将其更新为 org.springframework.r2dbc(即删除 .data)以指向 Spring R2DBC 组件。

If you use logging of SQL statements through the logger prefix org.springframework.data.r2dbc, make sure to update it to org.springframework.r2dbc (that is removing .data) to point to Spring R2DBC components.

Deprecations

  • Deprecation of o.s.d.r2dbc.core.DatabaseClient and its support classes ConnectionAccessor, FetchSpec, SqlProvider and a few more. Named parameter support classes such as NamedParameterExpander are encapsulated by Spring R2DBC’s DatabaseClient implementation hence we’re not providing replacements as this was internal API in the first place. Use o.s.r2dbc.core.DatabaseClient and their Spring R2DBC replacements available from org.springframework.r2dbc.core. Entity-based methods (select/insert/update/delete) methods are available through R2dbcEntityTemplate which was introduced with version 1.1.

  • Deprecation of o.s.d.r2dbc.connectionfactory, o.s.d.r2dbc.connectionfactory.init, and o.s.d.r2dbc.connectionfactory.lookup packages. Use Spring R2DBC’s variant which you can find at o.s.r2dbc.connection.

  • Deprecation of o.s.d.r2dbc.convert.ColumnMapRowMapper. Use o.s.r2dbc.core.ColumnMapRowMapper instead.

  • Deprecation of binding support classes o.s.d.r2dbc.dialect.Bindings, BindMarker, BindMarkers, BindMarkersFactory and related types. Use replacements from org.springframework.r2dbc.core.binding.

  • Deprecation of BadSqlGrammarException, UncategorizedR2dbcException and exception translation at o.s.d.r2dbc.support. Spring R2DBC provides a slim exception translation variant without an SPI for now available through o.s.r2dbc.connection.ConnectionFactoryUtils#convertR2dbcException.

Usage of replacements provided by Spring R2DBC

为了轻松迁移,一些已弃用的类型现在是 Spring R2DBC 提供的替换类型的子类型。Spring Data R2DBC 更改了几个方法,或者引入了新的方法,以接受 Spring R2DBC 类型。具体来说,更改了以下类:

To ease migration, several deprecated types are now subtypes of their replacements provided by Spring R2DBC. Spring Data R2DBC has changes several methods or introduced new methods accepting Spring R2DBC types. Specifically the following classes are changed:

  • R2dbcEntityTemplate

  • R2dbcDialect

  • Types in org.springframework.data.r2dbc.query

如果您直接使用这些类型,我们建议您查看并更新您的导入。

We recommend that you review and update your imports if you work with these types directly.

Breaking Changes

  • OutboundRow and statement mappers switched from using SettableValue to Parameter

  • Repository factory support requires o.s.r2dbc.core.DatabaseClient instead of o.s.data.r2dbc.core.DatabaseClient.

Dependency Changes

要使用 Spring R2DBC,请确保包含以下依赖项:

To make use of Spring R2DBC, make sure to include the following dependency:

  • org.springframework:spring-r2dbc