Spring Data R2DBC | Appendix

Appendix A: Repository Query Keywords

Supported Query Method Subject Keywords

The following keywords are generally supported by the Spring Data repository query derivation mechanism. Consult store-specific documentation because some keywords may not be supported by every store.

Keyword Description
find...By, read...By, get...By, query...By, search...By, stream...By General query methods returning a repository type, Collection, Streamable, Page, GeoResults, or a store-specific wrapper.
count...By Count projection returning a numeric result.
delete...By, remove...By Delete query returning no result or the delete count.
...First<number>..., ...Top<number>... Limit results to the first <number> entries.
...Distinct... Return distinct results when supported by the store.

Supported Query Method Predicate Keywords and Modifiers

Logical keyword Keyword expressions
AND And
OR Or
AFTER After, IsAfter
BEFORE Before, IsBefore
CONTAINING Containing, IsContaining, Contains
BETWEEN Between, IsBetween
ENDING_WITH EndingWith, IsEndingWith, EndsWith
EXISTS Exists
FALSE False, IsFalse
GREATER_THAN GreaterThan, IsGreaterThan
GREATER_THAN_EQUALS GreaterThanEqual, IsGreaterThanEqual
IN In, IsIn
IS Is, Equals, or no keyword
IS_EMPTY IsEmpty, Empty
IS_NOT_EMPTY IsNotEmpty, NotEmpty
IS_NOT_NULL NotNull, IsNotNull
IS_NULL Null, IsNull
LESS_THAN LessThan, IsLessThan
LESS_THAN_EQUAL LessThanEqual, IsLessThanEqual
LIKE Like, IsLike
NEAR Near, IsNear
NOT Not, IsNot
NOT_IN NotIn, IsNotIn
NOT_LIKE NotLike, IsNotLike
REGEX Regex, MatchesRegex, Matches
STARTING_WITH StartingWith, IsStartingWith, StartsWith
TRUE True, IsTrue
WITHIN Within, IsWithin
Modifier Description
IgnoreCase, IgnoringCase Apply a case-insensitive comparison to a predicate.
AllIgnoreCase, AllIgnoringCase Ignore case for all suitable properties.
OrderBy... Specify a static sort order, such as OrderByFirstnameAscLastnameDesc.

Appendix B: Repository Query Return Types

The following return types are generally supported. Consult store-specific documentation for an exact list.

Return type Description
void, primitives, wrapper types No return value, Java primitives, or Java wrapper types.
T One entity or null. Multiple results trigger IncorrectResultSizeDataAccessException.
Iterator<T>, Collection<T>, List<T> Standard container types.
Optional<T> Java 8 or Guava optional value. Multiple results trigger IncorrectResultSizeDataAccessException.
Option<T> Scala or Vavr equivalent of Optional.
Stream<T> Java 8 Stream.
Streamable<T> Iterable extension with streaming, mapping, filtering, and concatenation methods.
Custom Streamable wrapper Type with a Streamable constructor or of(...)/valueOf(...) factory.
Vavr Seq, List, Map, Set Vavr collection types.
Future<T>, CompletableFuture<T>, ListenableFuture Asynchronous return types requiring @Async and Spring asynchronous method execution.
Slice<T> Chunk of data indicating whether more data is available. Requires Pageable.
Page<T> Slice with additional information such as total result count. Requires Pageable.
GeoResult<T>, GeoResults<T>, GeoPage<T> Geospatial results with details such as distance and page information.
Mono<T> Reactor type emitting zero or one element. Multiple results trigger IncorrectResultSizeDataAccessException.
Flux<T> Reactor type emitting zero, one, many, or infinitely many elements.
Single<T> RxJava type emitting one element.
Maybe<T> RxJava type emitting zero or one element.
Flowable<T> RxJava type emitting zero, one, many, or infinitely many elements.

Appendix C: Migration Guide

Upgrade from 1.1.x to 1.2.x

Spring Data R2DBC was created to evaluate R2DBC integration with Spring applications. Once core support proved useful, it moved to Spring Framework 5.3 as Spring R2DBC (spring-r2dbc).

spring-r2dbc provides the core functionality originally supplied by Spring Data R2DBC: a slimmer DatabaseClient, transaction manager, connection-factory initialization, and exception translation. DatabaseClient.execute(...) changed to DatabaseClient.sql(...), and fluent CRUD APIs moved to R2dbcEntityTemplate.

For SQL logging, update the logger prefix from org.springframework.data.r2dbc to org.springframework.r2dbc.

Deprecations

  • Replace o.s.d.r2dbc.core.DatabaseClient and related classes with o.s.r2dbc.core.DatabaseClient. Use R2dbcEntityTemplate for entity-based CRUD methods.
  • Replace o.s.d.r2dbc.connectionfactory, .init, and .lookup packages with o.s.r2dbc.connection.
  • Replace o.s.d.r2dbc.convert.ColumnMapRowMapper with o.s.r2dbc.core.ColumnMapRowMapper.
  • Replace binding support classes with alternatives in org.springframework.r2dbc.core.binding.
  • Replace deprecated exception translation with o.s.r2dbc.connection.ConnectionFactoryUtils#convertR2dbcException.

Use Spring R2DBC Replacements

Review imports when directly using R2dbcEntityTemplate, R2dbcDialect, or org.springframework.data.r2dbc.query types.

Breaking Changes

  • OutboundRow and statement mappers now use Parameter instead of SettableValue.
  • Repository factory support requires o.s.r2dbc.core.DatabaseClient.

Dependency Changes

  • org.springframework:spring-r2dbc

Version 1.4.0
Last updated 2021-11-12 11:03:33 +0100