Interface R2dbcEntityOperations
- All Superinterfaces:
FluentR2dbcOperations, ReactiveDeleteOperation, ReactiveInsertOperation, ReactiveSelectOperation, ReactiveUpdateOperation, ReactiveUpsertOperation
- All Known Implementing Classes:
R2dbcEntityTemplate
Interface specifying a basic set of reactive R2DBC operations using entities. Implemented by
R2dbcEntityTemplate. Not often used directly, but a useful option to enhance testability, as it can easily be
mocked or stubbed.- Since:
- 1.1
- Author:
- Mark Paluch, Christoph Strobl
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface ReactiveDeleteOperation
ReactiveDeleteOperation.DeleteWithQuery, ReactiveDeleteOperation.DeleteWithTable, ReactiveDeleteOperation.ReactiveDelete, ReactiveDeleteOperation.TerminatingDeleteNested classes/interfaces inherited from interface ReactiveInsertOperation
ReactiveInsertOperation.InsertWithTable<T>, ReactiveInsertOperation.ReactiveInsert<T>, ReactiveInsertOperation.TerminatingInsert<T>Nested classes/interfaces inherited from interface ReactiveSelectOperation
ReactiveSelectOperation.ReactiveSelect<T>, ReactiveSelectOperation.SelectWithProjection<T>, ReactiveSelectOperation.SelectWithQuery<T>, ReactiveSelectOperation.SelectWithTable<T>, ReactiveSelectOperation.TerminatingSelect<T>Nested classes/interfaces inherited from interface ReactiveUpdateOperation
ReactiveUpdateOperation.ReactiveUpdate, ReactiveUpdateOperation.TerminatingUpdate, ReactiveUpdateOperation.UpdateWithQuery, ReactiveUpdateOperation.UpdateWithTableNested classes/interfaces inherited from interface ReactiveUpsertOperation
ReactiveUpsertOperation.ReactiveUpsert<T>, ReactiveUpsertOperation.TerminatingUpsert<T>, ReactiveUpsertOperation.UpsertWithTable<T> -
Method Summary
Modifier and TypeMethodDescriptionReturns the number of rows for the given entity class applyingQuery.Remove entities (rows)/columns from the table byQuery.<T> Mono<T> delete(T entity) Delete the given entity and emit the entity if the delete was applied.Determine whether the result forentityClassQueryyields at least one row.Return the underlyingR2dbcConverter.Deprecated.Expose the underlyingDatabaseClientto allow SQL operations.<T> RowsFetchSpec<T> getRowsFetchSpec(DatabaseClient.GenericExecuteSpec executeSpec, Class<?> entityType, Class<T> resultType) <T> Mono<T> insert(T entity) Insert the given entity and emit the entity if the insert was applied.<T> RowsFetchSpec<T> query(PreparedOperation<?> operation, Class<?> entityClass, Class<T> resultType) Execute a query for aRowsFetchSpec, givenPreparedOperation.<T> RowsFetchSpec<T> query(PreparedOperation<?> operation, Class<?> entityClass, BiFunction<Row, RowMetadata, T> rowMapper) default <T> RowsFetchSpec<T> query(PreparedOperation<?> operation, Class<?> entityClass, Function<Row, T> rowMapper) <T> RowsFetchSpec<T> query(PreparedOperation<?> operation, Class<T> entityClass) Execute a query for aRowsFetchSpec, givenPreparedOperation.<T> RowsFetchSpec<T> query(PreparedOperation<?> operation, BiFunction<Row, RowMetadata, T> rowMapper) Execute a query for aRowsFetchSpec, givenPreparedOperation.default <T> RowsFetchSpec<T> query(PreparedOperation<?> operation, Function<Row, T> rowMapper) Execute a query for aRowsFetchSpec, givenPreparedOperation.<T> Flux<T> Execute aSELECTquery and convert the resulting items to a stream of entities.<T> Mono<T> Execute aSELECTquery and convert the resulting item to an entity ensuring exactly one result.update(org.springframework.data.relational.core.query.Query query, org.springframework.data.relational.core.query.Update update, Class<?> entityClass) Update the queried entities and return true if the update was applied.<T> Mono<T> update(T entity) Update the given entity and emit the entity if the update was applied.<T> Mono<T> upsert(T entity) Upserts the given entity, specifically insert if the row with the given identifier does not exist or update otherwise.Methods inherited from interface ReactiveDeleteOperation
deleteMethods inherited from interface ReactiveInsertOperation
insertMethods inherited from interface ReactiveSelectOperation
selectMethods inherited from interface ReactiveUpdateOperation
updateMethods inherited from interface ReactiveUpsertOperation
upsert
-
Method Details
-
getDatabaseClient
DatabaseClient getDatabaseClient()Expose the underlyingDatabaseClientto allow SQL operations.- Returns:
- the underlying
DatabaseClient. - See Also:
-
getDataAccessStrategy
Deprecated.usegetConverter()instead asReactiveDataAccessStrategywill be removed in a future release.Expose the underlyingReactiveDataAccessStrategyencapsulating dialect specifics.- Returns:
- the underlying
ReactiveDataAccessStrategy. - Since:
- 1.1.3
- See Also:
-
getConverter
R2dbcConverter getConverter()Return the underlyingR2dbcConverter.- Returns:
- the underlying
R2dbcConverter. - Since:
- 1.2
-
count
Mono<Long> count(org.springframework.data.relational.core.query.Query query, Class<?> entityClass) throws DataAccessException Returns the number of rows for the given entity class applyingQuery. This overridden method allows users to further refine the selection Query using aQuerypredicate to determine how many entities of the giventypematch the Query.- Parameters:
query- user-defined countQueryto execute; must not be null.entityClass-typeof the entity; must not be null.- Returns:
- the number of existing entities.
- Throws:
DataAccessException- if any problem occurs while executing the query.
-
exists
Mono<Boolean> exists(org.springframework.data.relational.core.query.Query query, Class<?> entityClass) throws DataAccessException Determine whether the result forentityClassQueryyields at least one row.- Parameters:
query- user-defined existsQueryto execute; must not be null.entityClass-typeof the entity; must not be null.- Returns:
- true if the object exists.
- Throws:
DataAccessException- if any problem occurs while executing the query.- Since:
- 2.1
-
select
<T> Flux<T> select(org.springframework.data.relational.core.query.Query query, Class<T> entityClass) throws DataAccessException Execute aSELECTquery and convert the resulting items to a stream of entities.- Parameters:
query- must not be null.entityClass- the entity type must not be null.- Returns:
- the result objects returned by the action.
- Throws:
DataAccessException- if there is any problem issuing the execution.
-
selectOne
<T> Mono<T> selectOne(org.springframework.data.relational.core.query.Query query, Class<T> entityClass) throws DataAccessException Execute aSELECTquery and convert the resulting item to an entity ensuring exactly one result.- Parameters:
query- must not be null.entityClass- the entity type must not be null.- Returns:
- exactly one result or
Mono.empty()if no match found. - Throws:
IncorrectResultSizeDataAccessException- if more than one match found.DataAccessException- if there is any problem issuing the execution.
-
update
Mono<Long> update(org.springframework.data.relational.core.query.Query query, org.springframework.data.relational.core.query.Update update, Class<?> entityClass) throws DataAccessException Update the queried entities and return true if the update was applied.- Parameters:
query- must not be null.update- must not be null.entityClass- the entity type must not be null.- Returns:
- the number of affected rows.
- Throws:
DataAccessException- if there is any problem executing the query.
-
delete
Mono<Long> delete(org.springframework.data.relational.core.query.Query query, Class<?> entityClass) throws DataAccessException Remove entities (rows)/columns from the table byQuery.- Parameters:
query- must not be null.entityClass- the entity type must not be null.- Returns:
- the number of affected rows.
- Throws:
DataAccessException- if there is any problem issuing the execution.
-
query
<T> RowsFetchSpec<T> query(PreparedOperation<?> operation, Class<T> entityClass) throws DataAccessException Execute a query for aRowsFetchSpec, givenPreparedOperation. Any provided bindings withinPreparedOperationare applied to the underlyingDatabaseClient. The query is issued as-is without additional pre-processing such as named parameter expansion. Results of the query are mapped ontoentityClass.- Parameters:
operation- the prepared operation wrapping a SQL query and bind parameters.entityClass- the entity type must not be null.- Returns:
- a
RowsFetchSpecready to materialize. - Throws:
DataAccessException- if there is any problem issuing the execution.- Since:
- 1.4
-
query
<T> RowsFetchSpec<T> query(PreparedOperation<?> operation, Class<?> entityClass, Class<T> resultType) throws DataAccessException Execute a query for aRowsFetchSpec, givenPreparedOperation. Any provided bindings withinPreparedOperationare applied to the underlyingDatabaseClient. The query is issued as-is without additional pre-processing such as named parameter expansion. Results of the query are mapped ontoentityClass.- Parameters:
operation- the prepared operation wrapping a SQL query and bind parameters.entityClass- the entity type must not be null.resultType- the returned entity, type must not be null.- Returns:
- a
RowsFetchSpecready to materialize. - Throws:
DataAccessException- if there is any problem issuing the execution.- Since:
- 3.2.1
-
query
default <T> RowsFetchSpec<T> query(PreparedOperation<?> operation, Function<Row, T> rowMapper) throws DataAccessExceptionExecute a query for aRowsFetchSpec, givenPreparedOperation. Any provided bindings withinPreparedOperationare applied to the underlyingDatabaseClient. The query is issued as-is without additional pre-processing such as named parameter expansion. Results of the query are mapped usingrowMapper.- Parameters:
operation- the prepared operation wrapping a SQL query and bind parameters.rowMapper- the row mapper must not be null.- Returns:
- a
RowsFetchSpecwithrowMapperapplied ready to materialize. - Throws:
DataAccessException- if there is any problem issuing the execution.- Since:
- 1.4
- See Also:
-
query
<T> RowsFetchSpec<T> query(PreparedOperation<?> operation, BiFunction<Row, RowMetadata, T> rowMapper) throws DataAccessException Execute a query for aRowsFetchSpec, givenPreparedOperation. Any provided bindings withinPreparedOperationare applied to the underlyingDatabaseClient. The query is issued as-is without additional pre-processing such as named parameter expansion. Results of the query are mapped usingrowMapper.- Parameters:
operation- the prepared operation wrapping a SQL query and bind parameters.rowMapper- the row mapper must not be null.- Returns:
- a
RowsFetchSpecwithrowMapperapplied ready to materialize. - Throws:
DataAccessException- if there is any problem issuing the execution.- Since:
- 1.4
-
query
default <T> RowsFetchSpec<T> query(PreparedOperation<?> operation, Class<?> entityClass, Function<Row, T> rowMapper) throws DataAccessExceptionExecute a query for aRowsFetchSpecin the context ofentityClass, givenPreparedOperation. Any provided bindings withinPreparedOperationare applied to the underlyingDatabaseClient. The query is issued as-is without additional pre-processing such as named parameter expansion. Results of the query are mapped usingrowMapper.- Parameters:
operation- the prepared operation wrapping a SQL query and bind parameters.entityClass- the entity type must not be null.rowMapper- the row mapper must not be null.- Returns:
- a
RowsFetchSpecwithrowMapperapplied ready to materialize. - Throws:
DataAccessException- if there is any problem issuing the execution.- Since:
- 1.4
- See Also:
-
query
<T> RowsFetchSpec<T> query(PreparedOperation<?> operation, Class<?> entityClass, BiFunction<Row, RowMetadata, T> rowMapper) throws DataAccessException Execute a query for aRowsFetchSpecin the context ofentityClass, givenPreparedOperation. Any provided bindings withinPreparedOperationare applied to the underlyingDatabaseClient. The query is issued as-is without additional pre-processing such as named parameter expansion. Results of the query are mapped usingrowMapper.- Parameters:
operation- the prepared operation wrapping a SQL query and bind parameters.entityClass- the entity type must not be null.rowMapper- the row mapper must not be null.- Returns:
- a
RowsFetchSpecwithrowMapperapplied ready to materialize. - Throws:
DataAccessException- if there is any problem issuing the execution.- Since:
- 1.4
- See Also:
-
getRowsFetchSpec
<T> RowsFetchSpec<T> getRowsFetchSpec(DatabaseClient.GenericExecuteSpec executeSpec, Class<?> entityType, Class<T> resultType) -
insert
Insert the given entity and emit the entity if the insert was applied.- Parameters:
entity- the entity to insert, must not be null.- Returns:
- the inserted entity.
- Throws:
DataAccessException- if there is any problem issuing the execution.
-
update
Update the given entity and emit the entity if the update was applied.- Parameters:
entity- the entity to update, must not be null.- Returns:
- the updated entity.
- Throws:
DataAccessException- if there is any problem issuing the execution.TransientDataAccessResourceException- if the update did not affect any rows.OptimisticLockingFailureException- in case of version mismatch in case aVersionis defined.
-
upsert
Upserts the given entity, specifically insert if the row with the given identifier does not exist or update otherwise. The identifier must be already assigned. Only supported when the dialect supports single-statement upsert.Typically, this operation uses
MERGEorINSERT ... ON CONFLICTsyntax.Note: Upserts currently do not support optimistic locking.
- Parameters:
entity- the entity to upsert, must not be null.- Returns:
- the upserted entity.
- Throws:
DataAccessException- if there is any problem issuing the execution.UnsupportedOperationException- if the dialect does not support upsert.- Since:
- 4.1
-
delete
Delete the given entity and emit the entity if the delete was applied.- Parameters:
entity- must not be null.- Returns:
- the deleted entity.
- Throws:
DataAccessException- if there is any problem issuing the execution.OptimisticLockingFailureException- in case of version mismatch in case aVersionis defined.
-
getConverter()instead asReactiveDataAccessStrategywill be removed in a future release.