Class AbstractSqlRepositoryOperations<RS,PS,Exc extends java.lang.Exception>
- java.lang.Object
-
- io.micronaut.data.runtime.operations.internal.AbstractRepositoryOperations
-
- io.micronaut.data.runtime.operations.internal.sql.AbstractSqlRepositoryOperations<RS,PS,Exc>
-
- Type Parameters:
RS- The result set typePS- The prepared statement typeExc- The exception type
- All Implemented Interfaces:
io.micronaut.context.ApplicationContextProvider,HintsCapableRepository,MethodContextAwareStoredQueryDecorator,PreparedQueryDecorator
- Direct Known Subclasses:
DefaultJdbcRepositoryOperations
@Internal public abstract class AbstractSqlRepositoryOperations<RS,PS,Exc extends java.lang.Exception> extends AbstractRepositoryOperations implements io.micronaut.context.ApplicationContextProvider, PreparedQueryDecorator, MethodContextAwareStoredQueryDecorator, HintsCapableRepository
Abstract SQL repository implementation not specifically bound to JDBC.- Since:
- 1.0.0
- Author:
- graemerocher, Denis Stepanov
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceAbstractSqlRepositoryOperations.StatementSupplier<PS>Functional interface used to supply a statement.
-
Field Summary
Fields Modifier and Type Field Description protected ResultReader<RS,java.lang.Integer>columnIndexResultSetReaderprotected ResultReader<RS,java.lang.String>columnNameResultSetReaderprotected static SqlQueryBuilderDEFAULT_SQL_BUILDERprotected QueryStatement<PS,java.lang.Integer>preparedStatementWriterprotected static org.slf4j.LoggerQUERY_LOGprotected java.util.Map<java.lang.Class,SqlQueryBuilder>queryBuilders-
Fields inherited from class io.micronaut.data.runtime.operations.internal.AbstractRepositoryOperations
attributeConverterRegistry, conversionService, dateTimeProvider, entityEventRegistry, jsonCodec, runtimeEntityRegistry
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractSqlRepositoryOperations(java.lang.String dataSourceName, ResultReader<RS,java.lang.String> columnNameResultSetReader, ResultReader<RS,java.lang.Integer> columnIndexResultSetReader, QueryStatement<PS,java.lang.Integer> preparedStatementWriter, java.util.List<io.micronaut.http.codec.MediaTypeCodec> codecs, DateTimeProvider<java.lang.Object> dateTimeProvider, RuntimeEntityRegistry runtimeEntityRegistry, io.micronaut.context.BeanContext beanContext, DataConversionService<?> conversionService, AttributeConverterRegistry attributeConverterRegistry)Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <E,R>
StoredQuery<E,R>decorate(io.micronaut.aop.MethodInvocationContext<?,?> context, StoredQuery<E,R> storedQuery)Decorate stored query.<E,R>
PreparedQuery<E,R>decorate(PreparedQuery<E,R> preparedQuery)Decorate prepared query.protected <E,R>
SqlPreparedQuery<E,R>getSqlPreparedQuery(PreparedQuery<E,R> preparedQuery)protected <E,R>
SqlStoredQuery<E,R>getSqlStoredQuery(StoredQuery<E,R> storedQuery)protected booleanisSupportsBatchDelete(PersistentEntity persistentEntity, Dialect dialect)Does supports batch for delete queries.protected booleanisSupportsBatchInsert(PersistentEntity persistentEntity, Dialect dialect)Does supports batch for update queries.protected booleanisSupportsBatchUpdate(PersistentEntity persistentEntity, Dialect dialect)Does supports batch for update queries.protected <T,R>
PSprepareStatement(AbstractSqlRepositoryOperations.StatementSupplier<PS> statementFunction, PreparedQuery<T,R> preparedQuery, boolean isUpdate, boolean isSingleResult)Prepare a statement for execution.protected <T> java.lang.StringresolveAssociationInsert(java.lang.Class repositoryType, RuntimePersistentEntity<T> persistentEntity, RuntimeAssociation<T> association)Builds a join table insert.protected <E> SqlStoredQuery<E,E>resolveEntityInsert(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.lang.Class<?> repositoryType, java.lang.Class<E> rootEntity, RuntimePersistentEntity<E> persistentEntity)Resolves a stored insert for the given entity.protected <E> SqlStoredQuery<E,E>resolveEntityUpdate(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.lang.Class<?> repositoryType, java.lang.Class<E> rootEntity, RuntimePersistentEntity<E> persistentEntity)Resolves a stored update for the given entity.protected <T> SqlStoredQuery<T,?>resolveSqlInsertAssociation(java.lang.Class<?> repositoryType, RuntimeAssociation<T> association, RuntimePersistentEntity<T> persistentEntity, T entity)Resolve SQL insert association operation.protected voidsetStatementParameter(PS preparedStatement, int index, DataType dataType, java.lang.Object value, Dialect dialect)Set the parameter value on the given statement.-
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
-
-
-
-
Field Detail
-
QUERY_LOG
protected static final org.slf4j.Logger QUERY_LOG
-
DEFAULT_SQL_BUILDER
protected static final SqlQueryBuilder DEFAULT_SQL_BUILDER
-
columnNameResultSetReader
protected final ResultReader<RS,java.lang.String> columnNameResultSetReader
-
columnIndexResultSetReader
protected final ResultReader<RS,java.lang.Integer> columnIndexResultSetReader
-
preparedStatementWriter
protected final QueryStatement<PS,java.lang.Integer> preparedStatementWriter
-
queryBuilders
protected final java.util.Map<java.lang.Class,SqlQueryBuilder> queryBuilders
-
-
Constructor Detail
-
AbstractSqlRepositoryOperations
protected AbstractSqlRepositoryOperations(java.lang.String dataSourceName, ResultReader<RS,java.lang.String> columnNameResultSetReader, ResultReader<RS,java.lang.Integer> columnIndexResultSetReader, QueryStatement<PS,java.lang.Integer> preparedStatementWriter, java.util.List<io.micronaut.http.codec.MediaTypeCodec> codecs, DateTimeProvider<java.lang.Object> dateTimeProvider, RuntimeEntityRegistry runtimeEntityRegistry, io.micronaut.context.BeanContext beanContext, DataConversionService<?> conversionService, AttributeConverterRegistry attributeConverterRegistry)Default constructor.- Parameters:
dataSourceName- The datasource namecolumnNameResultSetReader- The column name result readercolumnIndexResultSetReader- The column index result readerpreparedStatementWriter- The prepared statement writercodecs- The media type codecsdateTimeProvider- The date time providerruntimeEntityRegistry- The entity registrybeanContext- The bean contextconversionService- The conversion serviceattributeConverterRegistry- The attribute converter registry
-
-
Method Detail
-
decorate
public <E,R> PreparedQuery<E,R> decorate(PreparedQuery<E,R> preparedQuery)
Description copied from interface:PreparedQueryDecoratorDecorate prepared query.- Specified by:
decoratein interfacePreparedQueryDecorator- Type Parameters:
E- The entity typeR- The result type- Parameters:
preparedQuery- The query to be decorated- Returns:
- decorated prepared query
-
decorate
public <E,R> StoredQuery<E,R> decorate(io.micronaut.aop.MethodInvocationContext<?,?> context, StoredQuery<E,R> storedQuery)
Description copied from interface:MethodContextAwareStoredQueryDecoratorDecorate stored query.- Specified by:
decoratein interfaceMethodContextAwareStoredQueryDecorator- Type Parameters:
E- The entity typeR- The result type- Parameters:
context- The contextstoredQuery- The query to be decorated- Returns:
- decorated stored query
-
prepareStatement
protected <T,R> PS prepareStatement(AbstractSqlRepositoryOperations.StatementSupplier<PS> statementFunction, @NonNull PreparedQuery<T,R> preparedQuery, boolean isUpdate, boolean isSingleResult) throws Exc extends java.lang.Exception
Prepare a statement for execution.- Type Parameters:
T- The query declaring typeR- The query result type- Parameters:
statementFunction- The statement functionpreparedQuery- The prepared queryisUpdate- Is this an updateisSingleResult- Is it a single result- Returns:
- The prepared statement
- Throws:
Exc extends java.lang.Exception
-
setStatementParameter
protected void setStatementParameter(PS preparedStatement, int index, DataType dataType, java.lang.Object value, Dialect dialect)
Set the parameter value on the given statement.- Parameters:
preparedStatement- The prepared statementindex- The indexdataType- The data typevalue- The valuedialect- The dialect
-
resolveEntityInsert
@NonNull protected <E> SqlStoredQuery<E,E> resolveEntityInsert(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.lang.Class<?> repositoryType, @NonNull java.lang.Class<E> rootEntity, @NonNull RuntimePersistentEntity<E> persistentEntity)
Resolves a stored insert for the given entity.- Type Parameters:
E- The entity type- Parameters:
annotationMetadata- The repository annotation metadatarepositoryType- The repository typerootEntity- The root entitypersistentEntity- The persistent entity- Returns:
- The insert
-
resolveAssociationInsert
protected <T> java.lang.String resolveAssociationInsert(java.lang.Class repositoryType, RuntimePersistentEntity<T> persistentEntity, RuntimeAssociation<T> association)Builds a join table insert.- Type Parameters:
T- The entity generic type- Parameters:
repositoryType- The repository typepersistentEntity- The entityassociation- The association- Returns:
- The insert statement
-
resolveEntityUpdate
@NonNull protected <E> SqlStoredQuery<E,E> resolveEntityUpdate(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.lang.Class<?> repositoryType, @NonNull java.lang.Class<E> rootEntity, @NonNull RuntimePersistentEntity<E> persistentEntity)
Resolves a stored update for the given entity.- Type Parameters:
E- The entity type- Parameters:
annotationMetadata- The repository annotation metadatarepositoryType- The repository typerootEntity- The root entitypersistentEntity- The persistent entity- Returns:
- The insert
-
resolveSqlInsertAssociation
protected <T> SqlStoredQuery<T,?> resolveSqlInsertAssociation(java.lang.Class<?> repositoryType, RuntimeAssociation<T> association, RuntimePersistentEntity<T> persistentEntity, T entity)
Resolve SQL insert association operation.- Type Parameters:
T- The entity type- Parameters:
repositoryType- The repository typeassociation- The associationpersistentEntity- The persistent entityentity- The entity- Returns:
- The operation
-
getSqlPreparedQuery
protected final <E,R> SqlPreparedQuery<E,R> getSqlPreparedQuery(PreparedQuery<E,R> preparedQuery)
-
getSqlStoredQuery
protected final <E,R> SqlStoredQuery<E,R> getSqlStoredQuery(StoredQuery<E,R> storedQuery)
-
isSupportsBatchInsert
protected boolean isSupportsBatchInsert(PersistentEntity persistentEntity, Dialect dialect)
Does supports batch for update queries.- Parameters:
persistentEntity- The persistent entitydialect- The dialect- Returns:
- true if supported
-
isSupportsBatchUpdate
protected boolean isSupportsBatchUpdate(PersistentEntity persistentEntity, Dialect dialect)
Does supports batch for update queries.- Parameters:
persistentEntity- The persistent entitydialect- The dialect- Returns:
- true if supported
-
isSupportsBatchDelete
protected boolean isSupportsBatchDelete(PersistentEntity persistentEntity, Dialect dialect)
Does supports batch for delete queries.- Parameters:
persistentEntity- The persistent entitydialect- The dialect- Returns:
- true if supported
-
-