public class R2dbcEntityTemplate extends Object implements R2dbcEntityOperations, BeanFactoryAware
R2dbcEntityOperations. It simplifies the use of Reactive R2DBC usage through entities and
helps to avoid common errors. This class uses DatabaseClient to execute SQL queries or updates, initiating
iteration over Result.
Can be used within a service implementation via direct instantiation with a DatabaseClient reference, or get
prepared in an application context and given to services as bean reference.
ReactiveSelectOperation.ReactiveSelect<T>, ReactiveSelectOperation.SelectWithProjection<T>, ReactiveSelectOperation.SelectWithQuery<T>, ReactiveSelectOperation.SelectWithTable<T>, ReactiveSelectOperation.TerminatingSelect<T>ReactiveInsertOperation.InsertWithTable<T>, ReactiveInsertOperation.ReactiveInsert<T>, ReactiveInsertOperation.TerminatingInsert<T>ReactiveUpdateOperation.ReactiveUpdate, ReactiveUpdateOperation.TerminatingUpdate, ReactiveUpdateOperation.UpdateWithQuery, ReactiveUpdateOperation.UpdateWithTableReactiveDeleteOperation.DeleteWithQuery, ReactiveDeleteOperation.DeleteWithTable, ReactiveDeleteOperation.ReactiveDelete, ReactiveDeleteOperation.TerminatingDelete| Constructor and Description |
|---|
R2dbcEntityTemplate(DatabaseClient databaseClient)
Create a new
R2dbcEntityTemplate given DatabaseClient. |
R2dbcEntityTemplate(DatabaseClient databaseClient,
ReactiveDataAccessStrategy strategy)
|
| Modifier and Type | Method and Description |
|---|---|
reactor.core.publisher.Mono<Long> |
count(org.springframework.data.relational.core.query.Query query,
Class<?> entityClass)
Returns the number of rows for the given entity class applying
Query. |
ReactiveDeleteOperation.ReactiveDelete |
delete(Class<?> domainType)
Begin creating a
DELETE operation for the given domainType. |
reactor.core.publisher.Mono<Integer> |
delete(org.springframework.data.relational.core.query.Query query,
Class<?> entityClass)
Remove entities (rows)/columns from the table by
Query. |
<T> reactor.core.publisher.Mono<T> |
delete(T entity)
Delete the given entity and emit the entity if the delete was applied.
|
reactor.core.publisher.Mono<Boolean> |
exists(org.springframework.data.relational.core.query.Query query,
Class<?> entityClass)
Determine whether the result for
entityClass Query yields at least one row. |
DatabaseClient |
getDatabaseClient()
Expose the underlying
DatabaseClient to allow SQL operations. |
<T> ReactiveInsertOperation.ReactiveInsert<T> |
insert(Class<T> domainType)
Begin creating an
INSERT operation for given domainType. |
<T> reactor.core.publisher.Mono<T> |
insert(T entity)
Insert the given entity and emit the entity if the insert was applied.
|
<T> ReactiveSelectOperation.ReactiveSelect<T> |
select(Class<T> domainType)
Begin creating a
SELECT operation for the given domainType. |
<T> reactor.core.publisher.Flux<T> |
select(org.springframework.data.relational.core.query.Query query,
Class<T> entityClass)
Execute a
SELECT query and convert the resulting items to a stream of entities. |
<T> reactor.core.publisher.Mono<T> |
selectOne(org.springframework.data.relational.core.query.Query query,
Class<T> entityClass)
Execute a
SELECT query and convert the resulting item to an entity. |
void |
setBeanFactory(BeanFactory beanFactory) |
ReactiveUpdateOperation.ReactiveUpdate |
update(Class<?> domainType)
Begin creating an
UPDATE operation for the given domainType. |
reactor.core.publisher.Mono<Integer> |
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> reactor.core.publisher.Mono<T> |
update(T entity)
Update the given entity and emit the entity if the update was applied.
|
public R2dbcEntityTemplate(DatabaseClient databaseClient)
R2dbcEntityTemplate given DatabaseClient.databaseClient - must not be null.public R2dbcEntityTemplate(DatabaseClient databaseClient, ReactiveDataAccessStrategy strategy)
databaseClient - must not be null.public DatabaseClient getDatabaseClient()
R2dbcEntityOperationsDatabaseClient to allow SQL operations.getDatabaseClient in interface R2dbcEntityOperationsDatabaseClient.DatabaseClientpublic void setBeanFactory(BeanFactory beanFactory) throws BeansException
setBeanFactory in interface BeanFactoryAwareBeansExceptionpublic <T> ReactiveSelectOperation.ReactiveSelect<T> select(Class<T> domainType)
ReactiveSelectOperationSELECT operation for the given domainType.select in interface ReactiveSelectOperationT - type of the application domain object.domainType - type of the domain object to query; must not be null.ReactiveSelectOperation.ReactiveSelect.ReactiveSelectOperation.ReactiveSelectpublic <T> ReactiveInsertOperation.ReactiveInsert<T> insert(Class<T> domainType)
ReactiveInsertOperationINSERT operation for given domainType.insert in interface ReactiveInsertOperationT - type of the application domain object.domainType - type of the domain object to insert; must not be null.ReactiveInsertOperation.ReactiveInsert.ReactiveInsertOperation.ReactiveInsertpublic ReactiveUpdateOperation.ReactiveUpdate update(Class<?> domainType)
ReactiveUpdateOperationUPDATE operation for the given domainType.update in interface ReactiveUpdateOperationdomainType - type of domain object to update; must not be null.ReactiveUpdateOperation.ReactiveUpdate.ReactiveUpdateOperation.ReactiveUpdatepublic ReactiveDeleteOperation.ReactiveDelete delete(Class<?> domainType)
ReactiveDeleteOperationDELETE operation for the given domainType.delete in interface ReactiveDeleteOperationdomainType - type of domain object to delete; must not be null.ReactiveDeleteOperation.ReactiveDelete.ReactiveDeleteOperation.ReactiveDeletepublic reactor.core.publisher.Mono<Long> count(org.springframework.data.relational.core.query.Query query, Class<?> entityClass) throws DataAccessException
R2dbcEntityOperationsQuery. This overridden method allows users
to further refine the selection Query using a Query predicate to determine how many entities of the given
type match the Query.count in interface R2dbcEntityOperationsquery - user-defined count Query to execute; must not be null.entityClass - type of the entity; must not be null.DataAccessException - if any problem occurs while executing the query.public reactor.core.publisher.Mono<Boolean> exists(org.springframework.data.relational.core.query.Query query, Class<?> entityClass) throws DataAccessException
R2dbcEntityOperationsentityClass Query yields at least one row.exists in interface R2dbcEntityOperationsquery - user-defined exists Query to execute; must not be null.entityClass - type of the entity; must not be null.DataAccessException - if any problem occurs while executing the query.public <T> reactor.core.publisher.Flux<T> select(org.springframework.data.relational.core.query.Query query,
Class<T> entityClass)
throws DataAccessException
R2dbcEntityOperationsSELECT query and convert the resulting items to a stream of entities.select in interface R2dbcEntityOperationsquery - must not be null.entityClass - The entity type must not be null.DataAccessException - if there is any problem issuing the execution.public <T> reactor.core.publisher.Mono<T> selectOne(org.springframework.data.relational.core.query.Query query,
Class<T> entityClass)
throws DataAccessException
R2dbcEntityOperationsSELECT query and convert the resulting item to an entity.selectOne in interface R2dbcEntityOperationsquery - must not be null.entityClass - The entity type must not be null.Mono.empty().DataAccessException - if there is any problem issuing the execution.public reactor.core.publisher.Mono<Integer> update(org.springframework.data.relational.core.query.Query query, org.springframework.data.relational.core.query.Update update, Class<?> entityClass) throws DataAccessException
R2dbcEntityOperationsupdate in interface R2dbcEntityOperationsquery - must not be null.update - must not be null.entityClass - The entity type must not be null.DataAccessException - if there is any problem executing the query.public reactor.core.publisher.Mono<Integer> delete(org.springframework.data.relational.core.query.Query query, Class<?> entityClass) throws DataAccessException
R2dbcEntityOperationsQuery.delete in interface R2dbcEntityOperationsquery - must not be null.entityClass - The entity type must not be null.DataAccessException - if there is any problem issuing the execution.public <T> reactor.core.publisher.Mono<T> insert(T entity)
throws DataAccessException
R2dbcEntityOperationsinsert in interface R2dbcEntityOperationsentity - The entity to insert, must not be null.DataAccessException - if there is any problem issuing the execution.public <T> reactor.core.publisher.Mono<T> update(T entity)
throws DataAccessException
R2dbcEntityOperationsupdate in interface R2dbcEntityOperationsentity - The entity to update, must not be null.DataAccessException - if there is any problem issuing the execution.TransientDataAccessResourceException - if the update did not affect any rows.public <T> reactor.core.publisher.Mono<T> delete(T entity)
throws DataAccessException
R2dbcEntityOperationsdelete in interface R2dbcEntityOperationsentity - must not be null.DataAccessException - if there is any problem issuing the execution.Copyright © 2018–2020 Pivotal Software, Inc.. All rights reserved.