@EachBean(value=javax.sql.DataSource.class) @Internal public final class DefaultJdbcRepositoryOperations extends AbstractSqlRepositoryOperations<java.sql.Connection,java.sql.ResultSet,java.sql.PreparedStatement,java.sql.SQLException> implements JdbcRepositoryOperations, AsyncCapableRepository, ReactiveCapableRepository, java.lang.AutoCloseable, SyncCascadeOperations.SyncCascadeOperationsHelper<DefaultJdbcRepositoryOperations.JdbcOperationContext>
JdbcRepositoryOperations
.Modifier and Type | Class and Description |
---|---|
protected static class |
DefaultJdbcRepositoryOperations.JdbcOperationContext |
AbstractSqlRepositoryOperations.StatementSupplier<PS>
columnIndexResultSetReader, columnNameResultSetReader, DEFAULT_SQL_BUILDER, preparedStatementWriter, QUERY_LOG, queryBuilders
attributeConverterRegistry, conversionService, dateTimeProvider, entityEventRegistry, jsonCodec, runtimeEntityRegistry
Modifier | Constructor and 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.
|
Modifier and Type | Method and Description |
---|---|
ExecutorAsyncOperations |
async() |
void |
close() |
<T> long |
count(PagedQuery<T> pagedQuery)
Counts all results for the given query.
|
protected io.micronaut.core.convert.ConversionContext |
createTypeConversionContext(java.sql.Connection connection,
RuntimePersistentProperty<?> property,
io.micronaut.core.type.Argument<?> argument)
Creates implementation specific conversion context.
|
<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> preparedQuery)
Executes an update for the given query and parameter values.
|
<T> boolean |
exists(PreparedQuery<T,java.lang.Boolean> preparedQuery)
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> T |
findOne(java.lang.Class<T> type,
java.io.Serializable id)
Find one by ID.
|
<T,R> R |
findOne(PreparedQuery<T,R> preparedQuery)
Find one by Query.
|
<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> D |
readDTO(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.
|
isSupportsBatchDelete, isSupportsBatchInsert, isSupportsBatchUpdate, prepareStatement, resolveAssociationInsert, resolveEntityInsert, resolveEntityUpdate, resolveSqlInsertAssociation, setStatementParameter
checkOptimisticLocking, convert, convert, getApplicationContext, getConversionService, getEntity, getIdReader, getRuntimeEntityRegistry, isOnlySingleEndedJoins, shiftIndex, triggerPostLoad
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
readDTO, readEntity
executeDelete, getConversionService, getEntity
getQueryHints
getApplicationContext
isSupportsBatchDelete, isSupportsBatchUpdate
convert, convert, getEntity, getRuntimeEntityRegistry, shiftIndex
@Internal protected DefaultJdbcRepositoryOperations(@Parameter java.lang.String dataSourceName, @Parameter DataJdbcConfiguration jdbcConfiguration, javax.sql.DataSource dataSource, @Parameter TransactionOperations<java.sql.Connection> transactionOperations, @Named(value="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)
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 registrypublic <T> T persistOne(DefaultJdbcRepositoryOperations.JdbcOperationContext ctx, T value, RuntimePersistentEntity<T> persistentEntity)
SyncCascadeOperations.SyncCascadeOperationsHelper
persistOne
in interface SyncCascadeOperations.SyncCascadeOperationsHelper<DefaultJdbcRepositoryOperations.JdbcOperationContext>
T
- The entity typectx
- The contextvalue
- The entity valuepersistentEntity
- The persistent entitypublic <T> java.util.List<T> persistBatch(DefaultJdbcRepositoryOperations.JdbcOperationContext ctx, java.lang.Iterable<T> values, RuntimePersistentEntity<T> childPersistentEntity, java.util.function.Predicate<T> predicate)
SyncCascadeOperations.SyncCascadeOperationsHelper
persistBatch
in interface SyncCascadeOperations.SyncCascadeOperationsHelper<DefaultJdbcRepositoryOperations.JdbcOperationContext>
T
- The entity typectx
- The contextvalues
- The entity valueschildPersistentEntity
- The persistent entitypredicate
- The veto predicatepublic <T> T updateOne(DefaultJdbcRepositoryOperations.JdbcOperationContext ctx, T value, RuntimePersistentEntity<T> persistentEntity)
SyncCascadeOperations.SyncCascadeOperationsHelper
updateOne
in interface SyncCascadeOperations.SyncCascadeOperationsHelper<DefaultJdbcRepositoryOperations.JdbcOperationContext>
T
- The entity typectx
- The contextvalue
- The entity valuepersistentEntity
- The persistent entitypublic 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)
SyncCascadeOperations.SyncCascadeOperationsHelper
persistManyAssociation
in interface SyncCascadeOperations.SyncCascadeOperationsHelper<DefaultJdbcRepositoryOperations.JdbcOperationContext>
ctx
- The contextruntimeAssociation
- The associationvalue
- The parent entity valuepersistentEntity
- The parent persistent entitychild
- The child entity valuechildPersistentEntity
- The child persistent entitypublic 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)
SyncCascadeOperations.SyncCascadeOperationsHelper
persistManyAssociationBatch
in interface SyncCascadeOperations.SyncCascadeOperationsHelper<DefaultJdbcRepositoryOperations.JdbcOperationContext>
ctx
- The contextruntimeAssociation
- The associationvalue
- The parent entity valuepersistentEntity
- The parent persistent entitychild
- The child entity valueschildPersistentEntity
- The child persistent entityprotected io.micronaut.core.convert.ConversionContext createTypeConversionContext(java.sql.Connection connection, RuntimePersistentProperty<?> property, io.micronaut.core.type.Argument<?> argument)
AbstractRepositoryOperations
createTypeConversionContext
in class AbstractRepositoryOperations<java.sql.Connection,java.sql.PreparedStatement>
connection
- The connectionproperty
- The propertyargument
- The argumentConversionContext
@NonNull public ExecutorAsyncOperations async()
async
in interface AsyncCapableRepository
@NonNull public ReactiveRepositoryOperations reactive()
reactive
in interface ReactiveCapableRepository
@Nullable public <T,R> R findOne(@NonNull PreparedQuery<T,R> preparedQuery)
RepositoryOperations
findOne
in interface RepositoryOperations
T
- The generic resultTypeR
- The result typepreparedQuery
- The prepared querypublic <T> boolean exists(@NonNull PreparedQuery<T,java.lang.Boolean> preparedQuery)
RepositoryOperations
exists
in interface RepositoryOperations
T
- The generic resultTypepreparedQuery
- The prepared query@NonNull public <T,R> java.util.stream.Stream<R> findStream(@NonNull PreparedQuery<T,R> preparedQuery)
RepositoryOperations
findStream
in interface RepositoryOperations
T
- The entity typeR
- The result typepreparedQuery
- The prepared query@NonNull public <T,R> java.lang.Iterable<R> findAll(@NonNull PreparedQuery<T,R> preparedQuery)
RepositoryOperations
findAll
in interface RepositoryOperations
T
- The entity typeR
- The result typepreparedQuery
- The prepared query@NonNull public java.util.Optional<java.lang.Number> executeUpdate(@NonNull PreparedQuery<?,java.lang.Number> preparedQuery)
RepositoryOperations
executeUpdate
in interface RepositoryOperations
preparedQuery
- The prepared querypublic <T> java.util.Optional<java.lang.Number> deleteAll(@NonNull DeleteBatchOperation<T> operation)
RepositoryOperations
deleteAll
in interface RepositoryOperations
T
- The generic typeoperation
- The operationpublic <T> int delete(@NonNull DeleteOperation<T> operation)
RepositoryOperations
delete
in interface RepositoryOperations
T
- The generic typeoperation
- The operation@NonNull public <T> T update(@NonNull UpdateOperation<T> operation)
RepositoryOperations
update
in interface RepositoryOperations
T
- The generic typeoperation
- The operation@NonNull public <T> java.lang.Iterable<T> updateAll(@NonNull UpdateBatchOperation<T> operation)
RepositoryOperations
updateAll
in interface RepositoryOperations
T
- The generic typeoperation
- The operation@NonNull public <T> T persist(@NonNull InsertOperation<T> operation)
RepositoryOperations
persist
in interface RepositoryOperations
T
- The generic typeoperation
- The operation@Nullable public <T> T findOne(@NonNull java.lang.Class<T> type, @NonNull java.io.Serializable id)
RepositoryOperations
findOne
in interface RepositoryOperations
T
- The generic typetype
- The typeid
- The id@NonNull public <T> java.lang.Iterable<T> findAll(@NonNull PagedQuery<T> query)
RepositoryOperations
findAll
in interface RepositoryOperations
T
- The generic typequery
- The root entitypublic <T> long count(PagedQuery<T> pagedQuery)
RepositoryOperations
count
in interface RepositoryOperations
T
- The generic typepagedQuery
- The paged query@NonNull public <T> java.util.stream.Stream<T> findStream(@NonNull PagedQuery<T> query)
RepositoryOperations
findStream
in interface RepositoryOperations
T
- The generic typequery
- The querypublic <R> Page<R> findPage(@NonNull PagedQuery<R> query)
RepositoryOperations
findPage
in interface RepositoryOperations
R
- The entity generic typequery
- The query@NonNull public <T> java.lang.Iterable<T> persistAll(@NonNull InsertBatchOperation<T> operation)
RepositoryOperations
persistAll
in interface RepositoryOperations
T
- The generic typeoperation
- The operation@PreDestroy public void close()
close
in interface java.lang.AutoCloseable
@NonNull public javax.sql.DataSource getDataSource()
getDataSource
in interface JdbcOperations
@NonNull public java.sql.Connection getConnection()
JdbcOperations
getConnection
in interface JdbcOperations
@NonNull public <R> R execute(@NonNull ConnectionCallback<R> callback)
JdbcOperations
execute
in interface JdbcOperations
R
- The result typecallback
- The callback@NonNull public <R> R prepareStatement(@NonNull java.lang.String sql, @NonNull PreparedStatementCallback<R> callback)
JdbcOperations
prepareStatement
in interface JdbcOperations
R
- The result typesql
- The SQLcallback
- The callback@NonNull public <T> java.util.stream.Stream<T> entityStream(@NonNull java.sql.ResultSet resultSet, @NonNull java.lang.Class<T> rootEntity)
JdbcOperations
entityStream
in interface JdbcOperations
T
- The generic typeresultSet
- The result setrootEntity
- The entity type@NonNull public <E> E readEntity(@NonNull java.lang.String prefix, @NonNull java.sql.ResultSet resultSet, @NonNull java.lang.Class<E> type) throws DataAccessException
JdbcOperations
readEntity
in interface JdbcOperations
E
- The entity generic typeprefix
- The prefixresultSet
- The result settype
- The entity typeDataAccessException
- if it is not possible read the result from the result set.@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
JdbcOperations
readDTO
in interface JdbcOperations
E
- The entity generic typeD
- The DTO generic typeprefix
- The prefixresultSet
- The result setrootEntity
- The entity typedtoType
- The DTO type. Must be annotated with Introspected
DataAccessException
- if it is not possible read the result from the result set.@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)
JdbcOperations
entityStream
in interface JdbcOperations
T
- The generic typeresultSet
- The result setprefix
- The prefix to use for each column name that is mappedrootEntity
- The entity typepublic boolean isSupportsBatchInsert(DefaultJdbcRepositoryOperations.JdbcOperationContext jdbcOperationContext, RuntimePersistentEntity<?> persistentEntity)
SyncCascadeOperations.SyncCascadeOperationsHelper
isSupportsBatchInsert
in interface SyncCascadeOperations.SyncCascadeOperationsHelper<DefaultJdbcRepositoryOperations.JdbcOperationContext>
jdbcOperationContext
- The contextpersistentEntity
- The persistent entity