public class R2dbcEntityTemplate extends Object implements R2dbcEntityOperations, BeanFactoryAware, ApplicationContextAware
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.UpdateWithTable
ReactiveDeleteOperation.DeleteWithQuery, ReactiveDeleteOperation.DeleteWithTable, ReactiveDeleteOperation.ReactiveDelete, ReactiveDeleteOperation.TerminatingDelete
Constructor and Description |
---|
R2dbcEntityTemplate(ConnectionFactory connectionFactory)
Create a new
R2dbcEntityTemplate given ConnectionFactory . |
R2dbcEntityTemplate(DatabaseClient databaseClient)
Deprecated.
since 1.2, use
R2dbcEntityTemplate(DatabaseClient, R2dbcDialect) instead. |
R2dbcEntityTemplate(DatabaseClient databaseClient,
R2dbcDialect dialect)
Create a new
R2dbcEntityTemplate given DatabaseClient . |
R2dbcEntityTemplate(DatabaseClient databaseClient,
R2dbcDialect dialect,
R2dbcConverter converter)
|
R2dbcEntityTemplate(DatabaseClient databaseClient,
ReactiveDataAccessStrategy strategy)
|
R2dbcEntityTemplate(DatabaseClient databaseClient,
ReactiveDataAccessStrategy strategy)
Deprecated.
since 1.2, use
R2dbcEntityTemplate(DatabaseClient, ReactiveDataAccessStrategy) instead. |
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. |
R2dbcConverter |
getConverter()
Return the underlying
R2dbcConverter . |
ReactiveDataAccessStrategy |
getDataAccessStrategy()
Expose the underlying
ReactiveDataAccessStrategy encapsulating dialect specifics. |
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.
|
protected <T> reactor.core.publisher.Mono<T> |
maybeCallAfterConvert(T object,
org.springframework.data.relational.core.sql.SqlIdentifier table) |
protected <T> reactor.core.publisher.Mono<T> |
maybeCallAfterSave(T object,
OutboundRow row,
org.springframework.data.relational.core.sql.SqlIdentifier table) |
protected <T> reactor.core.publisher.Mono<T> |
maybeCallBeforeConvert(T object,
org.springframework.data.relational.core.sql.SqlIdentifier table) |
protected <T> reactor.core.publisher.Mono<T> |
maybeCallBeforeSave(T object,
OutboundRow row,
org.springframework.data.relational.core.sql.SqlIdentifier table) |
<T> RowsFetchSpec<T> |
query(PreparedOperation<?> operation,
BiFunction<Row,RowMetadata,T> rowMapper)
Execute a query for a
RowsFetchSpec , given PreparedOperation . |
<T> RowsFetchSpec<T> |
query(PreparedOperation<?> operation,
Class<?> entityClass,
BiFunction<Row,RowMetadata,T> rowMapper)
|
<T> RowsFetchSpec<T> |
query(PreparedOperation<?> operation,
Class<T> entityClass)
Execute a query for a
RowsFetchSpec , given PreparedOperation . |
<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 ensuring exactly one result. |
void |
setApplicationContext(ApplicationContext applicationContext) |
void |
setBeanFactory(BeanFactory beanFactory)
Deprecated.
|
void |
setEntityCallbacks(ReactiveEntityCallbacks entityCallbacks)
Set the
ReactiveEntityCallbacks instance to use when invoking
callbacks like the
BeforeSaveCallback . |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
query, query
public R2dbcEntityTemplate(ConnectionFactory connectionFactory)
R2dbcEntityTemplate
given ConnectionFactory
.connectionFactory
- must not be null.public R2dbcEntityTemplate(DatabaseClient databaseClient, R2dbcDialect dialect)
R2dbcEntityTemplate
given DatabaseClient
.databaseClient
- must not be null.dialect
- the dialect to use, must not be null.@Deprecated public R2dbcEntityTemplate(DatabaseClient databaseClient)
R2dbcEntityTemplate(DatabaseClient, R2dbcDialect)
instead.R2dbcEntityTemplate
given DatabaseClient
.databaseClient
- must not be null.public R2dbcEntityTemplate(DatabaseClient databaseClient, R2dbcDialect dialect, R2dbcConverter converter)
databaseClient
- must not be null.dialect
- the dialect to use, must not be null.converter
- the dialect to use, must not be null.public R2dbcEntityTemplate(DatabaseClient databaseClient, ReactiveDataAccessStrategy strategy)
databaseClient
- must not be null.@Deprecated public R2dbcEntityTemplate(DatabaseClient databaseClient, ReactiveDataAccessStrategy strategy)
R2dbcEntityTemplate(DatabaseClient, ReactiveDataAccessStrategy)
instead.databaseClient
- must not be null.public DatabaseClient getDatabaseClient()
R2dbcEntityOperations
DatabaseClient
to allow SQL operations.getDatabaseClient
in interface R2dbcEntityOperations
DatabaseClient
.DatabaseClient
public ReactiveDataAccessStrategy getDataAccessStrategy()
R2dbcEntityOperations
ReactiveDataAccessStrategy
encapsulating dialect specifics.getDataAccessStrategy
in interface R2dbcEntityOperations
ReactiveDataAccessStrategy
.ReactiveDataAccessStrategy
public R2dbcConverter getConverter()
R2dbcEntityOperations
R2dbcConverter
.getConverter
in interface R2dbcEntityOperations
R2dbcConverter
.@Deprecated public void setBeanFactory(BeanFactory beanFactory) throws BeansException
setBeanFactory
in interface BeanFactoryAware
BeansException
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
setApplicationContext
in interface ApplicationContextAware
BeansException
public void setEntityCallbacks(ReactiveEntityCallbacks entityCallbacks)
ReactiveEntityCallbacks
instance to use when invoking
callbacks
like the
BeforeSaveCallback
.
Overrides potentially existing ReactiveEntityCallbacks
.
entityCallbacks
- must not be null.IllegalArgumentException
- if the given instance is null.public <T> ReactiveSelectOperation.ReactiveSelect<T> select(Class<T> domainType)
ReactiveSelectOperation
SELECT
operation for the given domainType
.select
in interface ReactiveSelectOperation
T
- type
of the application domain object.domainType
- type
of the domain object to query; must not be null.ReactiveSelectOperation.ReactiveSelect
.ReactiveSelectOperation.ReactiveSelect
public <T> ReactiveInsertOperation.ReactiveInsert<T> insert(Class<T> domainType)
ReactiveInsertOperation
INSERT
operation for given domainType
.insert
in interface ReactiveInsertOperation
T
- type
of the application domain object.domainType
- type
of the domain object to insert; must not be null.ReactiveInsertOperation.ReactiveInsert
.ReactiveInsertOperation.ReactiveInsert
public ReactiveUpdateOperation.ReactiveUpdate update(Class<?> domainType)
ReactiveUpdateOperation
UPDATE
operation for the given domainType
.update
in interface ReactiveUpdateOperation
domainType
- type
of domain object to update; must not be null.ReactiveUpdateOperation.ReactiveUpdate
.ReactiveUpdateOperation.ReactiveUpdate
public ReactiveDeleteOperation.ReactiveDelete delete(Class<?> domainType)
ReactiveDeleteOperation
DELETE
operation for the given domainType
.delete
in interface ReactiveDeleteOperation
domainType
- type
of domain object to delete; must not be null.ReactiveDeleteOperation.ReactiveDelete
.ReactiveDeleteOperation.ReactiveDelete
public reactor.core.publisher.Mono<Long> count(org.springframework.data.relational.core.query.Query query, Class<?> entityClass) throws DataAccessException
R2dbcEntityOperations
Query
. 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 R2dbcEntityOperations
query
- 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
R2dbcEntityOperations
entityClass
Query
yields at least one row.exists
in interface R2dbcEntityOperations
query
- 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
R2dbcEntityOperations
SELECT
query and convert the resulting items to a stream of entities.select
in interface R2dbcEntityOperations
query
- 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
R2dbcEntityOperations
SELECT
query and convert the resulting item to an entity ensuring exactly one result.selectOne
in interface R2dbcEntityOperations
query
- must not be null.entityClass
- the entity type must not be null.Mono.empty()
if no match found.IncorrectResultSizeDataAccessException
- if more than one match found.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
R2dbcEntityOperations
update
in interface R2dbcEntityOperations
query
- 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
R2dbcEntityOperations
Query
.delete
in interface R2dbcEntityOperations
query
- must not be null.entityClass
- the entity type must not be null.DataAccessException
- if there is any problem issuing the execution.public <T> RowsFetchSpec<T> query(PreparedOperation<?> operation, Class<T> entityClass)
R2dbcEntityOperations
RowsFetchSpec
, given PreparedOperation
. Any provided bindings within
PreparedOperation
are applied to the underlying DatabaseClient
. The query is issued as-is without
additional pre-processing such as named parameter expansion. Results of the query are mapped onto
entityClass
.query
in interface R2dbcEntityOperations
operation
- the prepared operation wrapping a SQL query and bind parameters.entityClass
- the entity type must not be null.RowsFetchSpec
ready to materialize.public <T> RowsFetchSpec<T> query(PreparedOperation<?> operation, BiFunction<Row,RowMetadata,T> rowMapper)
R2dbcEntityOperations
RowsFetchSpec
, given PreparedOperation
. Any provided bindings within
PreparedOperation
are applied to the underlying DatabaseClient
. The query is issued as-is without
additional pre-processing such as named parameter expansion. Results of the query are mapped using
rowMapper
.query
in interface R2dbcEntityOperations
operation
- the prepared operation wrapping a SQL query and bind parameters.rowMapper
- the row mapper must not be null.RowsFetchSpec
with rowMapper
applied ready to materialize.public <T> RowsFetchSpec<T> query(PreparedOperation<?> operation, Class<?> entityClass, BiFunction<Row,RowMetadata,T> rowMapper)
R2dbcEntityOperations
RowsFetchSpec
in the context of entityClass
, given PreparedOperation
.
Any provided bindings within PreparedOperation
are applied to the underlying DatabaseClient
. The
query is issued as-is without additional pre-processing such as named parameter expansion. Results of the query are
mapped using rowMapper
.query
in interface R2dbcEntityOperations
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.RowsFetchSpec
with rowMapper
applied ready to materialize.R2dbcEntityOperations.query(PreparedOperation, Class, BiFunction)
public <T> reactor.core.publisher.Mono<T> insert(T entity) throws DataAccessException
R2dbcEntityOperations
insert
in interface R2dbcEntityOperations
entity
- 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
R2dbcEntityOperations
update
in interface R2dbcEntityOperations
entity
- 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
R2dbcEntityOperations
delete
in interface R2dbcEntityOperations
entity
- must not be null.DataAccessException
- if there is any problem issuing the execution.protected <T> reactor.core.publisher.Mono<T> maybeCallBeforeConvert(T object, org.springframework.data.relational.core.sql.SqlIdentifier table)
protected <T> reactor.core.publisher.Mono<T> maybeCallBeforeSave(T object, OutboundRow row, org.springframework.data.relational.core.sql.SqlIdentifier table)
protected <T> reactor.core.publisher.Mono<T> maybeCallAfterSave(T object, OutboundRow row, org.springframework.data.relational.core.sql.SqlIdentifier table)
protected <T> reactor.core.publisher.Mono<T> maybeCallAfterConvert(T object, org.springframework.data.relational.core.sql.SqlIdentifier table)
Copyright © 2018–2022 Pivotal Software, Inc.. All rights reserved.