Class LcReactiveDataRelationalClient
- java.lang.Object
-
- net.lecousin.reactive.data.relational.LcReactiveDataRelationalClient
-
@Component public class LcReactiveDataRelationalClient extends Object
Reactive client for a relational database connection handling features such as join, lazy loading, persistence, deletion...- Author:
- Guillaume Le Cousin
-
-
Field Summary
Fields Modifier and Type Field Description static org.apache.commons.logging.Log
logger
-
Constructor Summary
Constructors Constructor Description LcReactiveDataRelationalClient(org.springframework.r2dbc.core.DatabaseClient client, RelationalDatabaseSchemaDialect schemaDialect, LcReactiveDataAccessStrategy dataAccess)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RelationalDatabaseSchema
buildSchemaFromEntities()
Build the schema definition from all known entities.RelationalDatabaseSchema
buildSchemaFromEntities(Collection<Class<?>> classes)
Build the schema definition from given entities.reactor.core.publisher.Mono<Void>
createSchemaContent(RelationalDatabaseSchema schema)
Create tables, constraints and sequences from the given schema.<T> reactor.core.publisher.Mono<Void>
delete(Iterable<T> entities)
Delete the given entities (with cascade).<T> reactor.core.publisher.Mono<Void>
delete(org.reactivestreams.Publisher<T> publisher)
Delete the given entities (with cascade).<T> reactor.core.publisher.Mono<Void>
delete(org.reactivestreams.Publisher<T> publisher, int bunchSize, Duration bunchTimeout)
Delete the given entities (with cascade), by bunch.<T> reactor.core.publisher.Mono<Void>
delete(T entity)
Delete the given entity (with cascade).reactor.core.publisher.Mono<Void>
dropCreateSchemaContent(RelationalDatabaseSchema schema)
Drop then create the given schema.reactor.core.publisher.Mono<Void>
dropSchemaContent(RelationalDatabaseSchema schema)
Drop all elements from the given schema.<T> reactor.core.publisher.Flux<T>
execute(SelectQuery<T> query, LcEntityReader reader)
Execute a select query using the given LcEntityReader to map rows to entities.reactor.core.publisher.Mono<Long>
executeCount(SelectQuery<?> query)
Execute a select query.LcReactiveDataAccessStrategy
getDataAccess()
org.springframework.data.r2dbc.dialect.R2dbcDialect
getDialect()
Collection<EntityMetadata>
getEntities()
Collection<EntityMetadata>
getEntities(Collection<Class<?>> types)
<T> EntityInstance<T>
getInstance(T entity)
LcMappingR2dbcConverter
getMapper()
EntityMetadata
getRequiredEntity(Class<?> type)
RelationalDatabaseSchemaDialect
getSchemaDialect()
org.springframework.r2dbc.core.DatabaseClient
getSpringClient()
<T> reactor.core.publisher.Mono<T>
lazyLoad(T entity)
Load the given entity from database.<T> reactor.core.publisher.Mono<EntityInstance<T>>
lazyLoadInstance(EntityInstance<T> instance)
Load the given entity from database.<T> reactor.core.publisher.Flux<EntityInstance<T>>
lazyLoadInstances(Iterable<EntityInstance<T>> entities)
Load the given entities from database.<T> reactor.core.publisher.Flux<T>
save(Iterable<T> entities)
Save the given entities (insert or update in cascade).<T> reactor.core.publisher.Flux<T>
save(org.reactivestreams.Publisher<T> publisher)
Save the given entities (insert or update in cascade).<T> reactor.core.publisher.Mono<T>
save(T entity)
Save the given entity (insert or update in cascade).reactor.core.publisher.Mono<Void>
saveAll(Iterable<Object> entities)
Save the given entities (insert or update in cascade).reactor.core.publisher.Mono<Void>
saveAll(Object... entities)
Save the given entities (insert or update in cascade).
-
-
-
Constructor Detail
-
LcReactiveDataRelationalClient
public LcReactiveDataRelationalClient(org.springframework.r2dbc.core.DatabaseClient client, RelationalDatabaseSchemaDialect schemaDialect, LcReactiveDataAccessStrategy dataAccess)
-
-
Method Detail
-
getSpringClient
public org.springframework.r2dbc.core.DatabaseClient getSpringClient()
- Returns:
- the Spring R2DBC database client.
-
getMapper
public LcMappingR2dbcConverter getMapper()
- Returns:
- entity mapper and converters.
-
getDataAccess
public LcReactiveDataAccessStrategy getDataAccess()
- Returns:
- the Spring Data R2DBC data access strategy.
-
getSchemaDialect
public RelationalDatabaseSchemaDialect getSchemaDialect()
- Returns:
- the extended dialect.
-
getDialect
public org.springframework.data.r2dbc.dialect.R2dbcDialect getDialect()
- Returns:
- the R2DBC native dialect.
-
getRequiredEntity
@NonNull public EntityMetadata getRequiredEntity(Class<?> type)
-
getEntities
public Collection<EntityMetadata> getEntities()
-
getEntities
public Collection<EntityMetadata> getEntities(Collection<Class<?>> types)
-
dropSchemaContent
public reactor.core.publisher.Mono<Void> dropSchemaContent(RelationalDatabaseSchema schema)
Drop all elements from the given schema.
-
createSchemaContent
public reactor.core.publisher.Mono<Void> createSchemaContent(RelationalDatabaseSchema schema)
Create tables, constraints and sequences from the given schema.
-
dropCreateSchemaContent
public reactor.core.publisher.Mono<Void> dropCreateSchemaContent(RelationalDatabaseSchema schema)
Drop then create the given schema.
-
buildSchemaFromEntities
public RelationalDatabaseSchema buildSchemaFromEntities()
Build the schema definition from all known entities.
-
buildSchemaFromEntities
public RelationalDatabaseSchema buildSchemaFromEntities(Collection<Class<?>> classes)
Build the schema definition from given entities.
-
save
public <T> reactor.core.publisher.Mono<T> save(T entity)
Save the given entity (insert or update in cascade).
-
save
public <T> reactor.core.publisher.Flux<T> save(Iterable<T> entities)
Save the given entities (insert or update in cascade).
-
save
public <T> reactor.core.publisher.Flux<T> save(org.reactivestreams.Publisher<T> publisher)
Save the given entities (insert or update in cascade).
-
saveAll
public reactor.core.publisher.Mono<Void> saveAll(Iterable<Object> entities)
Save the given entities (insert or update in cascade).
-
saveAll
public reactor.core.publisher.Mono<Void> saveAll(Object... entities)
Save the given entities (insert or update in cascade).
-
getInstance
public <T> EntityInstance<T> getInstance(T entity)
-
lazyLoad
public <T> reactor.core.publisher.Mono<T> lazyLoad(T entity)
Load the given entity from database.
-
lazyLoadInstance
public <T> reactor.core.publisher.Mono<EntityInstance<T>> lazyLoadInstance(EntityInstance<T> instance)
Load the given entity from database.
-
lazyLoadInstances
public <T> reactor.core.publisher.Flux<EntityInstance<T>> lazyLoadInstances(Iterable<EntityInstance<T>> entities)
Load the given entities from database.
-
execute
public <T> reactor.core.publisher.Flux<T> execute(SelectQuery<T> query, @Nullable LcEntityReader reader)
Execute a select query using the given LcEntityReader to map rows to entities.
-
executeCount
public reactor.core.publisher.Mono<Long> executeCount(SelectQuery<?> query)
Execute a select query.
-
delete
public <T> reactor.core.publisher.Mono<Void> delete(T entity)
Delete the given entity (with cascade).
-
delete
public <T> reactor.core.publisher.Mono<Void> delete(Iterable<T> entities)
Delete the given entities (with cascade).
-
delete
public <T> reactor.core.publisher.Mono<Void> delete(org.reactivestreams.Publisher<T> publisher)
Delete the given entities (with cascade).
-
delete
public <T> reactor.core.publisher.Mono<Void> delete(org.reactivestreams.Publisher<T> publisher, int bunchSize, Duration bunchTimeout)
Delete the given entities (with cascade), by bunch.- Parameters:
publisher
- entities to deletebunchSize
- bufferize entities to delete them by bunchbunchTimeout
- timeout after which a the current bunch of entities are deleted even the bunch is not full
-
-