Class DefaultJdbcRepositoryOperations
- java.lang.Object
-
- io.micronaut.data.runtime.operations.internal.AbstractRepositoryOperations
-
- io.micronaut.data.runtime.operations.internal.sql.AbstractSqlRepositoryOperations<java.sql.ResultSet,java.sql.PreparedStatement,java.sql.SQLException>
-
- io.micronaut.data.jdbc.operations.DefaultJdbcRepositoryOperations
-
- All Implemented Interfaces:
io.micronaut.context.ApplicationContextProvider
,JdbcRepositoryOperations
,JdbcOperations
,AsyncCapableRepository
,HintsCapableRepository
,ReactiveCapableRepository
,RepositoryOperations
,SyncCascadeOperations.SyncCascadeOperationsHelper<DefaultJdbcRepositoryOperations.JdbcOperationContext>
,MethodContextAwareStoredQueryDecorator
,PreparedQueryDecorator
,java.lang.AutoCloseable
@EachBean(javax.sql.DataSource.class) @Internal public final class DefaultJdbcRepositoryOperations extends AbstractSqlRepositoryOperations<java.sql.ResultSet,java.sql.PreparedStatement,java.sql.SQLException> implements JdbcRepositoryOperations, AsyncCapableRepository, ReactiveCapableRepository, java.lang.AutoCloseable, SyncCascadeOperations.SyncCascadeOperationsHelper<DefaultJdbcRepositoryOperations.JdbcOperationContext>
Implementation ofJdbcRepositoryOperations
.- Since:
- 1.0.0
- Author:
- graemerocher, Denis Stepanov
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
DefaultJdbcRepositoryOperations.JdbcOperationContext
-
Nested classes/interfaces inherited from class io.micronaut.data.runtime.operations.internal.sql.AbstractSqlRepositoryOperations
AbstractSqlRepositoryOperations.StatementSupplier<PS>
-
-
Field Summary
-
Fields inherited from class io.micronaut.data.runtime.operations.internal.sql.AbstractSqlRepositoryOperations
columnIndexResultSetReader, columnNameResultSetReader, DEFAULT_SQL_BUILDER, preparedStatementWriter, QUERY_LOG, queryBuilders
-
Fields inherited from class io.micronaut.data.runtime.operations.internal.AbstractRepositoryOperations
attributeConverterRegistry, conversionService, dateTimeProvider, entityEventRegistry, jsonCodec, runtimeEntityRegistry
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DefaultJdbcRepositoryOperations(java.lang.String dataSourceName, DataJdbcConfiguration jdbcConfiguration, javax.sql.DataSource dataSource, TransactionOperations<java.sql.Connection> transactionOperations, java.util.concurrent.ExecutorService executorService, io.micronaut.context.BeanContext beanContext, java.util.List<io.micronaut.http.codec.MediaTypeCodec> codecs, DateTimeProvider dateTimeProvider, RuntimeEntityRegistry entityRegistry, DataConversionService<?> conversionService, AttributeConverterRegistry attributeConverterRegistry)
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ExecutorAsyncOperations
async()
void
close()
<T> long
count(PagedQuery<T> pagedQuery)
Counts all results for the given query.<T> int
delete(DeleteOperation<T> operation)
Deletes the entity.<T> java.util.Optional<java.lang.Number>
deleteAll(DeleteBatchOperation<T> operation)
Deletes all the entities of the given type.<T> java.util.stream.Stream<T>
entityStream(java.sql.ResultSet resultSet, java.lang.Class<T> rootEntity)
Map a result set to a stream of the given type.<T> java.util.stream.Stream<T>
entityStream(java.sql.ResultSet resultSet, java.lang.String prefix, java.lang.Class<T> rootEntity)
Map a result set to a stream of the given type.<R> R
execute(ConnectionCallback<R> callback)
Execute the given operation with the given callback.java.util.Optional<java.lang.Number>
executeUpdate(PreparedQuery<?,java.lang.Number> pq)
Executes an update for the given query and parameter values.<T> boolean
exists(PreparedQuery<T,java.lang.Boolean> pq)
Execute a query that checks for existence.<T> java.lang.Iterable<T>
findAll(PagedQuery<T> query)
Finds all results for the given query.<T,R>
java.lang.Iterable<R>findAll(PreparedQuery<T,R> preparedQuery)
Finds all results for the given query.<T,R>
RfindOne(PreparedQuery<T,R> pq)
Find one by Query.<T> T
findOne(java.lang.Class<T> type, java.io.Serializable id)
Find one by ID.<R> Page<R>
findPage(PagedQuery<R> query)
Find a page for the given entity and pageable.<T> java.util.stream.Stream<T>
findStream(PagedQuery<T> query)
Finds a stream for the given arguments.<T,R>
java.util.stream.Stream<R>findStream(PreparedQuery<T,R> preparedQuery)
Finds all results for the given query.java.sql.Connection
getConnection()
This method will return the currently active connection for the current transaction or throw an exception if no transaction is present.javax.sql.DataSource
getDataSource()
boolean
isSupportsBatchInsert(DefaultJdbcRepositoryOperations.JdbcOperationContext jdbcOperationContext, RuntimePersistentEntity<?> persistentEntity)
Is supports batch insert.<T> T
persist(InsertOperation<T> operation)
Persist the operation returning a possibly new entity.<T> java.lang.Iterable<T>
persistAll(InsertBatchOperation<T> operation)
Persist all the given entities.<T> java.util.List<T>
persistBatch(DefaultJdbcRepositoryOperations.JdbcOperationContext ctx, java.lang.Iterable<T> values, RuntimePersistentEntity<T> childPersistentEntity, java.util.function.Predicate<T> predicate)
Persist multiple entities in batch during cascade.void
persistManyAssociation(DefaultJdbcRepositoryOperations.JdbcOperationContext ctx, RuntimeAssociation runtimeAssociation, java.lang.Object value, RuntimePersistentEntity<java.lang.Object> persistentEntity, java.lang.Object child, RuntimePersistentEntity<java.lang.Object> childPersistentEntity)
Persist JOIN table relationship.void
persistManyAssociationBatch(DefaultJdbcRepositoryOperations.JdbcOperationContext ctx, RuntimeAssociation runtimeAssociation, java.lang.Object value, RuntimePersistentEntity<java.lang.Object> persistentEntity, java.lang.Iterable<java.lang.Object> child, RuntimePersistentEntity<java.lang.Object> childPersistentEntity)
Persist JOIN table relationships in batch.<T> T
persistOne(DefaultJdbcRepositoryOperations.JdbcOperationContext ctx, T value, RuntimePersistentEntity<T> persistentEntity)
Persist one entity during cascade.<R> R
prepareStatement(java.lang.String sql, PreparedStatementCallback<R> callback)
Execute the given operation with the given callback.ReactiveRepositoryOperations
reactive()
<E,D>
DreadDTO(java.lang.String prefix, java.sql.ResultSet resultSet, java.lang.Class<E> rootEntity, java.lang.Class<D> dtoType)
Read an entity using the given prefix to be passes to result set lookups.<E> E
readEntity(java.lang.String prefix, java.sql.ResultSet resultSet, java.lang.Class<E> type)
Read an entity using the given prefix to be passes to result set lookups.<T> T
update(UpdateOperation<T> operation)
Updates the entity for the given operation.<T> java.lang.Iterable<T>
updateAll(UpdateBatchOperation<T> operation)
Updates the entities for the given operation.<T> T
updateOne(DefaultJdbcRepositoryOperations.JdbcOperationContext ctx, T value, RuntimePersistentEntity<T> persistentEntity)
Update one entity during cascade.-
Methods inherited from class io.micronaut.data.runtime.operations.internal.sql.AbstractSqlRepositoryOperations
decorate, decorate, getSqlPreparedQuery, getSqlStoredQuery, isSupportsBatchDelete, isSupportsBatchInsert, isSupportsBatchUpdate, prepareStatement, resolveAssociationInsert, resolveEntityInsert, resolveEntityUpdate, resolveSqlInsertAssociation, setStatementParameter
-
Methods inherited from class io.micronaut.data.runtime.operations.internal.AbstractRepositoryOperations
checkOptimisticLocking, getApplicationContext, getConversionService, getEntity, getIdReader, isOnlySingleEndedJoins, triggerPostLoad
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.micronaut.context.ApplicationContextProvider
getApplicationContext
-
Methods inherited from interface io.micronaut.data.operations.HintsCapableRepository
getQueryHints
-
Methods inherited from interface io.micronaut.data.jdbc.runtime.JdbcOperations
readDTO, readEntity
-
Methods inherited from interface io.micronaut.data.operations.RepositoryOperations
executeDelete, getConversionService, getEntity
-
Methods inherited from interface io.micronaut.data.runtime.operations.internal.SyncCascadeOperations.SyncCascadeOperationsHelper
isSupportsBatchDelete, isSupportsBatchUpdate
-
-
-
-
Constructor Detail
-
DefaultJdbcRepositoryOperations
@Internal protected DefaultJdbcRepositoryOperations(@Parameter java.lang.String dataSourceName, @Parameter DataJdbcConfiguration jdbcConfiguration, javax.sql.DataSource dataSource, @Parameter TransactionOperations<java.sql.Connection> transactionOperations, @Named("io") @Nullable java.util.concurrent.ExecutorService executorService, io.micronaut.context.BeanContext beanContext, java.util.List<io.micronaut.http.codec.MediaTypeCodec> codecs, @NonNull DateTimeProvider dateTimeProvider, RuntimeEntityRegistry entityRegistry, DataConversionService<?> conversionService, AttributeConverterRegistry attributeConverterRegistry)
Default constructor.- Parameters:
dataSourceName
- The data source namejdbcConfiguration
- The jdbcConfigurationdataSource
- The datasourcetransactionOperations
- The JDBC operations for the data sourceexecutorService
- The executor servicebeanContext
- The bean contextcodecs
- The codecsdateTimeProvider
- The dateTimeProviderentityRegistry
- The entity registryconversionService
- The conversion serviceattributeConverterRegistry
- The attribute converter registry
-
-
Method Detail
-
persistOne
public <T> T persistOne(DefaultJdbcRepositoryOperations.JdbcOperationContext ctx, T value, RuntimePersistentEntity<T> persistentEntity)
Description copied from interface:SyncCascadeOperations.SyncCascadeOperationsHelper
Persist one entity during cascade.- Specified by:
persistOne
in interfaceSyncCascadeOperations.SyncCascadeOperationsHelper<DefaultJdbcRepositoryOperations.JdbcOperationContext>
- Type Parameters:
T
- The entity type- Parameters:
ctx
- The contextvalue
- The entity valuepersistentEntity
- The persistent entity- Returns:
- The entity value
-
persistBatch
public <T> java.util.List<T> persistBatch(DefaultJdbcRepositoryOperations.JdbcOperationContext ctx, java.lang.Iterable<T> values, RuntimePersistentEntity<T> childPersistentEntity, java.util.function.Predicate<T> predicate)
Description copied from interface:SyncCascadeOperations.SyncCascadeOperationsHelper
Persist multiple entities in batch during cascade.- Specified by:
persistBatch
in interfaceSyncCascadeOperations.SyncCascadeOperationsHelper<DefaultJdbcRepositoryOperations.JdbcOperationContext>
- Type Parameters:
T
- The entity type- Parameters:
ctx
- The contextvalues
- The entity valueschildPersistentEntity
- The persistent entitypredicate
- The veto predicate- Returns:
- The entity values
-
updateOne
public <T> T updateOne(DefaultJdbcRepositoryOperations.JdbcOperationContext ctx, T value, RuntimePersistentEntity<T> persistentEntity)
Description copied from interface:SyncCascadeOperations.SyncCascadeOperationsHelper
Update one entity during cascade.- Specified by:
updateOne
in interfaceSyncCascadeOperations.SyncCascadeOperationsHelper<DefaultJdbcRepositoryOperations.JdbcOperationContext>
- Type Parameters:
T
- The entity type- Parameters:
ctx
- The contextvalue
- The entity valuepersistentEntity
- The persistent entity- Returns:
- The entity value
-
persistManyAssociation
public void persistManyAssociation(DefaultJdbcRepositoryOperations.JdbcOperationContext ctx, RuntimeAssociation runtimeAssociation, java.lang.Object value, RuntimePersistentEntity<java.lang.Object> persistentEntity, java.lang.Object child, RuntimePersistentEntity<java.lang.Object> childPersistentEntity)
Description copied from interface:SyncCascadeOperations.SyncCascadeOperationsHelper
Persist JOIN table relationship.- Specified by:
persistManyAssociation
in interfaceSyncCascadeOperations.SyncCascadeOperationsHelper<DefaultJdbcRepositoryOperations.JdbcOperationContext>
- Parameters:
ctx
- The contextruntimeAssociation
- The associationvalue
- The parent entity valuepersistentEntity
- The parent persistent entitychild
- The child entity valuechildPersistentEntity
- The child persistent entity
-
persistManyAssociationBatch
public void persistManyAssociationBatch(DefaultJdbcRepositoryOperations.JdbcOperationContext ctx, RuntimeAssociation runtimeAssociation, java.lang.Object value, RuntimePersistentEntity<java.lang.Object> persistentEntity, java.lang.Iterable<java.lang.Object> child, RuntimePersistentEntity<java.lang.Object> childPersistentEntity)
Description copied from interface:SyncCascadeOperations.SyncCascadeOperationsHelper
Persist JOIN table relationships in batch.- Specified by:
persistManyAssociationBatch
in interfaceSyncCascadeOperations.SyncCascadeOperationsHelper<DefaultJdbcRepositoryOperations.JdbcOperationContext>
- Parameters:
ctx
- The contextruntimeAssociation
- The associationvalue
- The parent entity valuepersistentEntity
- The parent persistent entitychild
- The child entity valueschildPersistentEntity
- The child persistent entity
-
async
@NonNull public ExecutorAsyncOperations async()
- Specified by:
async
in interfaceAsyncCapableRepository
- Returns:
- The async operations.
-
reactive
@NonNull public ReactiveRepositoryOperations reactive()
- Specified by:
reactive
in interfaceReactiveCapableRepository
- Returns:
- The reactive operations instance.
-
findOne
@Nullable public <T,R> R findOne(@NonNull PreparedQuery<T,R> pq)
Description copied from interface:RepositoryOperations
Find one by Query.- Specified by:
findOne
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic resultTypeR
- The result type- Parameters:
pq
- The prepared query- Returns:
- A result or null
-
exists
public <T> boolean exists(@NonNull PreparedQuery<T,java.lang.Boolean> pq)
Description copied from interface:RepositoryOperations
Execute a query that checks for existence.- Specified by:
exists
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic resultType- Parameters:
pq
- The prepared query- Returns:
- A result or null
-
findStream
@NonNull public <T,R> java.util.stream.Stream<R> findStream(@NonNull PreparedQuery<T,R> preparedQuery)
Description copied from interface:RepositoryOperations
Finds all results for the given query.- Specified by:
findStream
in interfaceRepositoryOperations
- Type Parameters:
T
- The entity typeR
- The result type- Parameters:
preparedQuery
- The prepared query- Returns:
- An iterable result
-
findAll
@NonNull public <T,R> java.lang.Iterable<R> findAll(@NonNull PreparedQuery<T,R> preparedQuery)
Description copied from interface:RepositoryOperations
Finds all results for the given query.- Specified by:
findAll
in interfaceRepositoryOperations
- Type Parameters:
T
- The entity typeR
- The result type- Parameters:
preparedQuery
- The prepared query- Returns:
- An iterable result
-
executeUpdate
@NonNull public java.util.Optional<java.lang.Number> executeUpdate(@NonNull PreparedQuery<?,java.lang.Number> pq)
Description copied from interface:RepositoryOperations
Executes an update for the given query and parameter values. If it is possible to return the number of objects updated, then do so.- Specified by:
executeUpdate
in interfaceRepositoryOperations
- Parameters:
pq
- The prepared query- Returns:
- An optional number with the count of the number of records updated
-
deleteAll
public <T> java.util.Optional<java.lang.Number> deleteAll(@NonNull DeleteBatchOperation<T> operation)
Description copied from interface:RepositoryOperations
Deletes all the entities of the given type.- Specified by:
deleteAll
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
operation
- The operation- Returns:
- The number of entities deleted
-
delete
public <T> int delete(@NonNull DeleteOperation<T> operation)
Description copied from interface:RepositoryOperations
Deletes the entity.- Specified by:
delete
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
operation
- The operation- Returns:
- The number of entities deleted
-
update
@NonNull public <T> T update(@NonNull UpdateOperation<T> operation)
Description copied from interface:RepositoryOperations
Updates the entity for the given operation.- Specified by:
update
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
operation
- The operation- Returns:
- The operation
-
updateAll
@NonNull public <T> java.lang.Iterable<T> updateAll(@NonNull UpdateBatchOperation<T> operation)
Description copied from interface:RepositoryOperations
Updates the entities for the given operation.- Specified by:
updateAll
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
operation
- The operation- Returns:
- The updated entities
-
persist
@NonNull public <T> T persist(@NonNull InsertOperation<T> operation)
Description copied from interface:RepositoryOperations
Persist the operation returning a possibly new entity.- Specified by:
persist
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
operation
- The operation- Returns:
- The operation
-
findOne
@Nullable public <T> T findOne(@NonNull java.lang.Class<T> type, @NonNull java.io.Serializable id)
Description copied from interface:RepositoryOperations
Find one by ID.- Specified by:
findOne
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
type
- The typeid
- The id- Returns:
- A result or null
-
findAll
@NonNull public <T> java.lang.Iterable<T> findAll(@NonNull PagedQuery<T> query)
Description copied from interface:RepositoryOperations
Finds all results for the given query.- Specified by:
findAll
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
query
- The root entity- Returns:
- An iterable result
-
count
public <T> long count(PagedQuery<T> pagedQuery)
Description copied from interface:RepositoryOperations
Counts all results for the given query.- Specified by:
count
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
pagedQuery
- The paged query- Returns:
- An iterable result
-
findStream
@NonNull public <T> java.util.stream.Stream<T> findStream(@NonNull PagedQuery<T> query)
Description copied from interface:RepositoryOperations
Finds a stream for the given arguments.- Specified by:
findStream
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
query
- The query- Returns:
- The stream
-
findPage
public <R> Page<R> findPage(@NonNull PagedQuery<R> query)
Description copied from interface:RepositoryOperations
Find a page for the given entity and pageable.- Specified by:
findPage
in interfaceRepositoryOperations
- Type Parameters:
R
- The entity generic type- Parameters:
query
- The query- Returns:
- The page type
-
persistAll
@NonNull public <T> java.lang.Iterable<T> persistAll(@NonNull InsertBatchOperation<T> operation)
Description copied from interface:RepositoryOperations
Persist all the given entities.- Specified by:
persistAll
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
operation
- The operation- Returns:
- The entities, possibly mutated
-
close
@PreDestroy public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
-
getDataSource
@NonNull public javax.sql.DataSource getDataSource()
- Specified by:
getDataSource
in interfaceJdbcOperations
- Returns:
- The backing data source.
-
getConnection
@NonNull public java.sql.Connection getConnection()
Description copied from interface:JdbcOperations
This method will return the currently active connection for the current transaction or throw an exception if no transaction is present.- Specified by:
getConnection
in interfaceJdbcOperations
- Returns:
- The current connection for the active transaction.
-
execute
@NonNull public <R> R execute(@NonNull ConnectionCallback<R> callback)
Description copied from interface:JdbcOperations
Execute the given operation with the given callback.- Specified by:
execute
in interfaceJdbcOperations
- Type Parameters:
R
- The result type- Parameters:
callback
- The callback- Returns:
- The result
-
prepareStatement
@NonNull public <R> R prepareStatement(@NonNull java.lang.String sql, @NonNull PreparedStatementCallback<R> callback)
Description copied from interface:JdbcOperations
Execute the given operation with the given callback.- Specified by:
prepareStatement
in interfaceJdbcOperations
- Type Parameters:
R
- The result type- Parameters:
sql
- The SQLcallback
- The callback- Returns:
- The result
-
entityStream
@NonNull public <T> java.util.stream.Stream<T> entityStream(@NonNull java.sql.ResultSet resultSet, @NonNull java.lang.Class<T> rootEntity)
Description copied from interface:JdbcOperations
Map a result set to a stream of the given type.- Specified by:
entityStream
in interfaceJdbcOperations
- Type Parameters:
T
- The generic type- Parameters:
resultSet
- The result setrootEntity
- The entity type- Returns:
- The stream
-
readEntity
@NonNull public <E> E readEntity(@NonNull java.lang.String prefix, @NonNull java.sql.ResultSet resultSet, @NonNull java.lang.Class<E> type) throws DataAccessException
Description copied from interface:JdbcOperations
Read an entity using the given prefix to be passes to result set lookups.- Specified by:
readEntity
in interfaceJdbcOperations
- Type Parameters:
E
- The entity generic type- Parameters:
prefix
- The prefixresultSet
- The result settype
- The entity type- Returns:
- The entity result
- Throws:
DataAccessException
- if it is not possible read the result from the result set.
-
readDTO
@NonNull public <E,D> D readDTO(@NonNull java.lang.String prefix, @NonNull java.sql.ResultSet resultSet, @NonNull java.lang.Class<E> rootEntity, @NonNull java.lang.Class<D> dtoType) throws DataAccessException
Description copied from interface:JdbcOperations
Read an entity using the given prefix to be passes to result set lookups.- Specified by:
readDTO
in interfaceJdbcOperations
- Type Parameters:
E
- The entity generic typeD
- The DTO generic type- Parameters:
prefix
- The prefixresultSet
- The result setrootEntity
- The entity typedtoType
- The DTO type. Must be annotated withIntrospected
- Returns:
- The entity result
- Throws:
DataAccessException
- if it is not possible read the result from the result set.
-
entityStream
@NonNull public <T> java.util.stream.Stream<T> entityStream(@NonNull java.sql.ResultSet resultSet, @Nullable java.lang.String prefix, @NonNull java.lang.Class<T> rootEntity)
Description copied from interface:JdbcOperations
Map a result set to a stream of the given type.- Specified by:
entityStream
in interfaceJdbcOperations
- Type Parameters:
T
- The generic type- Parameters:
resultSet
- The result setprefix
- The prefix to use for each column name that is mappedrootEntity
- The entity type- Returns:
- The stream
-
isSupportsBatchInsert
public boolean isSupportsBatchInsert(DefaultJdbcRepositoryOperations.JdbcOperationContext jdbcOperationContext, RuntimePersistentEntity<?> persistentEntity)
Description copied from interface:SyncCascadeOperations.SyncCascadeOperationsHelper
Is supports batch insert.- Specified by:
isSupportsBatchInsert
in interfaceSyncCascadeOperations.SyncCascadeOperationsHelper<DefaultJdbcRepositoryOperations.JdbcOperationContext>
- Parameters:
jdbcOperationContext
- The contextpersistentEntity
- The persistent entity- Returns:
- True if supports
-
-