@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
JdbcRepositoryOperations.AbstractSqlRepositoryOperations.BaseOperations<T>, AbstractSqlRepositoryOperations.CascadeContext, AbstractSqlRepositoryOperations.CascadeManyOp, AbstractSqlRepositoryOperations.CascadeOneOp, AbstractSqlRepositoryOperations.CascadeOp, AbstractSqlRepositoryOperations.DBOperation1<In,Exc extends java.lang.Exception>, AbstractSqlRepositoryOperations.DBOperation2<In1,In2,Exc extends java.lang.Exception>, AbstractSqlRepositoryOperations.EntitiesOperations<T>, AbstractSqlRepositoryOperations.EntityOperations<T>, AbstractSqlRepositoryOperations.SqlOperation, AbstractSqlRepositoryOperations.StatementSupplier<PS>, AbstractSqlRepositoryOperations.StoredAnnotationMetadataSqlOperation, AbstractSqlRepositoryOperations.StoredSqlOperationcolumnIndexResultSetReader, columnNameResultSetReader, dateTimeProvider, DEFAULT_SQL_BUILDER, entityEventRegistry, jsonCodec, preparedStatementWriter, QUERY_LOG, queryBuilders, runtimeEntityRegistry| Modifier | Constructor and Description |
|---|---|
protected |
DefaultJdbcRepositoryOperations(java.lang.String dataSourceName,
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)
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.
|
<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() |
protected ResultConsumer.Context<java.sql.ResultSet> |
newMappingContext(java.sql.ResultSet rs) |
<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.
|
protected void |
prepareStatement(java.sql.Connection connection,
Dialect dialect,
PersistentProperty identity,
boolean hasGeneratedID,
java.lang.String insertSql,
AbstractSqlRepositoryOperations.DBOperation1<java.sql.PreparedStatement,java.sql.SQLException> fn)
Prepare a statement and run a function.
|
protected void |
prepareStatement(java.sql.Connection connection,
java.lang.String query,
AbstractSqlRepositoryOperations.DBOperation1<java.sql.PreparedStatement,java.sql.SQLException> fn)
Prepare a statement and run a function.
|
<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.
|
afterCascadedMany, afterCascadedOne, cascade, checkOptimisticLocking, deleteInBatch, deleteOne, getApplicationContext, getEntity, getIdReader, isOnlySingleEndedJoins, isSqlServerWithoutOrderBy, isSupportsBatchDelete, isSupportsBatchInsert, isSupportsBatchUpdate, persistInBatch, persistJoinTableAssociation, persistOne, prepareStatement, resolveAssociationInsert, resolveEntityInsert, resolveEntityUpdate, setStatementParameter, shiftIndex, sizeOf, sortById, triggerPostLoad, updateInBatch, updateOneclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitreadDTO, readEntityexecuteDelete, getEntity, getQueryHints@Internal
protected DefaultJdbcRepositoryOperations(@Parameter
java.lang.String dataSourceName,
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)
dataSourceName - The data source namedataSource - The datasourcetransactionOperations - The JDBC operations for the data sourceexecutorService - The executor servicebeanContext - The bean contextcodecs - The codecsdateTimeProvider - The dateTimeProviderentityRegistry - The entity registryprotected void prepareStatement(java.sql.Connection connection,
java.lang.String query,
AbstractSqlRepositoryOperations.DBOperation1<java.sql.PreparedStatement,java.sql.SQLException> fn)
throws java.sql.SQLException
AbstractSqlRepositoryOperationsprepareStatement in class AbstractSqlRepositoryOperations<java.sql.Connection,java.sql.ResultSet,java.sql.PreparedStatement,java.sql.SQLException>connection - The connection.query - The queryfn - The function to be run with a statementjava.sql.SQLExceptionprotected void prepareStatement(java.sql.Connection connection,
Dialect dialect,
PersistentProperty identity,
boolean hasGeneratedID,
java.lang.String insertSql,
AbstractSqlRepositoryOperations.DBOperation1<java.sql.PreparedStatement,java.sql.SQLException> fn)
throws java.sql.SQLException
AbstractSqlRepositoryOperationsprepareStatement in class AbstractSqlRepositoryOperations<java.sql.Connection,java.sql.ResultSet,java.sql.PreparedStatement,java.sql.SQLException>connection - The connectiondialect - The dialectidentity - The identity propertyhasGeneratedID - Is genereted idenntityinsertSql - Te queryfn - The function to be run with a statementjava.sql.SQLException@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)
RepositoryOperationsfindOne in interface RepositoryOperationsT - The generic resultTypeR - The result typepreparedQuery - The prepared querypublic <T> boolean exists(@NonNull
PreparedQuery<T,java.lang.Boolean> preparedQuery)
RepositoryOperationsexists in interface RepositoryOperationsT - The generic resultTypepreparedQuery - The prepared query@NonNull
public <T,R> java.util.stream.Stream<R> findStream(@NonNull
PreparedQuery<T,R> preparedQuery)
RepositoryOperationsfindStream in interface RepositoryOperationsT - The entity typeR - The result typepreparedQuery - The prepared query@NonNull
public <T,R> java.lang.Iterable<R> findAll(@NonNull
PreparedQuery<T,R> preparedQuery)
RepositoryOperationsfindAll in interface RepositoryOperationsT - The entity typeR - The result typepreparedQuery - The prepared query@NonNull
public java.util.Optional<java.lang.Number> executeUpdate(@NonNull
PreparedQuery<?,java.lang.Number> preparedQuery)
RepositoryOperationsexecuteUpdate in interface RepositoryOperationspreparedQuery - The prepared querypublic <T> java.util.Optional<java.lang.Number> deleteAll(@NonNull
DeleteBatchOperation<T> operation)
RepositoryOperationsdeleteAll in interface RepositoryOperationsT - The generic typeoperation - The operationpublic <T> int delete(@NonNull
DeleteOperation<T> operation)
RepositoryOperationsdelete in interface RepositoryOperationsT - The generic typeoperation - The operation@NonNull
public <T> T update(@NonNull
UpdateOperation<T> operation)
RepositoryOperationsupdate in interface RepositoryOperationsT - The generic typeoperation - The operation@NonNull
public <T> java.lang.Iterable<T> updateAll(@NonNull
UpdateBatchOperation<T> operation)
RepositoryOperationsupdateAll in interface RepositoryOperationsT - The generic typeoperation - The operation@NonNull
public <T> T persist(@NonNull
InsertOperation<T> operation)
RepositoryOperationspersist in interface RepositoryOperationsT - The generic typeoperation - The operation@Nullable
public <T> T findOne(@NonNull
java.lang.Class<T> type,
@NonNull
java.io.Serializable id)
RepositoryOperationsfindOne in interface RepositoryOperationsT - The generic typetype - The typeid - The id@NonNull
public <T> java.lang.Iterable<T> findAll(@NonNull
PagedQuery<T> query)
RepositoryOperationsfindAll in interface RepositoryOperationsT - The generic typequery - The root entitypublic <T> long count(PagedQuery<T> pagedQuery)
RepositoryOperationscount in interface RepositoryOperationsT - The generic typepagedQuery - The paged query@NonNull
public <T> java.util.stream.Stream<T> findStream(@NonNull
PagedQuery<T> query)
RepositoryOperationsfindStream in interface RepositoryOperationsT - The generic typequery - The querypublic <R> Page<R> findPage(@NonNull PagedQuery<R> query)
RepositoryOperationsfindPage in interface RepositoryOperationsR - The entity generic typequery - The query@NonNull
public <T> java.lang.Iterable<T> persistAll(@NonNull
InsertBatchOperation<T> operation)
RepositoryOperationspersistAll in interface RepositoryOperationsT - 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()
JdbcOperationsgetConnection in interface JdbcOperations@NonNull
public <R> R execute(@NonNull
ConnectionCallback<R> callback)
JdbcOperationsexecute in interface JdbcOperationsR - The result typecallback - The callback@NonNull
public <R> R prepareStatement(@NonNull
java.lang.String sql,
@NonNull
PreparedStatementCallback<R> callback)
JdbcOperationsprepareStatement in interface JdbcOperationsR - 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)
JdbcOperationsentityStream in interface JdbcOperationsT - 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
JdbcOperationsreadEntity in interface JdbcOperationsE - 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
JdbcOperationsreadDTO in interface JdbcOperationsE - The entity generic typeD - The DTO generic typeprefix - The prefixresultSet - The result setrootEntity - The entity typedtoType - The DTO type. Must be annotated with IntrospectedDataAccessException - 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)
JdbcOperationsentityStream in interface JdbcOperationsT - The generic typeresultSet - The result setprefix - The prefix to use for each column name that is mappedrootEntity - The entity type@NonNull protected ResultConsumer.Context<java.sql.ResultSet> newMappingContext(java.sql.ResultSet rs)