Class AbstractSqlRepositoryOperations<RS,PS,Exc extends 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 type
- PS- The prepared statement type
- Exc- 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 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 SummaryNested ClassesModifier and TypeClassDescriptionprotected static interfaceFunctional interface used to supply a statement.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected final ResultReader<RS,Integer> protected final ResultReader<RS,String> protected final Stringprotected final io.micronaut.json.JsonMapperprotected final QueryStatement<PS,Integer> protected static final org.slf4j.Loggerprotected final Map<Class,SqlQueryBuilder> protected final SqlJsonColumnMapperProvider<RS>Fields inherited from class io.micronaut.data.runtime.operations.internal.AbstractRepositoryOperationsattributeConverterRegistry, conversionService, dateTimeProvider, entityEventRegistry, runtimeEntityRegistry
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedAbstractSqlRepositoryOperations(String dataSourceName, ResultReader<RS, String> columnNameResultSetReader, ResultReader<RS, Integer> columnIndexResultSetReader, QueryStatement<PS, Integer> preparedStatementWriter, DateTimeProvider<Object> dateTimeProvider, RuntimeEntityRegistry runtimeEntityRegistry, io.micronaut.context.BeanContext beanContext, DataConversionService conversionService, AttributeConverterRegistry attributeConverterRegistry, io.micronaut.json.JsonMapper jsonMapper, SqlJsonColumnMapperProvider<RS> sqlJsonColumnMapperProvider) Default constructor.
- 
Method SummaryModifier and TypeMethodDescriptionprotected final <T,R> SqlTypeMapper<RS, R> createQueryResultMapper(SqlPreparedQuery<?, ?> sqlPreparedQuery, String columnName, JsonDataType jsonDataType, Class<RS> resultSetType, RuntimePersistentEntity<T> persistentEntity, BiFunction<RuntimePersistentEntity<Object>, Object, Object> loadListener) CreatesSqlTypeMapperfor reading results from single column into an entity.<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 final StringgetJsonColumn(QueryResultInfo queryResultInfo) Gets column name for JSON result.protected final JsonDataTypegetJsonDataType(QueryResultInfo queryResultInfo) Gets JSON data type for JSON result.protected final <E,R> SqlPreparedQuery<E, R> getSqlPreparedQuery(PreparedQuery<E, R> preparedQuery) protected final <E,R> SqlStoredQuery<E, R> getSqlStoredQuery(StoredQuery<E, R> storedQuery) protected static ThrowablehandleSqlException(SQLException sqlException, Dialect dialect) Handles SQL exception, used in context of update but could be used elsewhere.protected final booleanisJsonEntityGeneratedId(StoredQuery<?, ?> storedQuery, PersistentEntity persistentEntity) Inserting JSON entity representation (like Oracle Json View) can generate new id, and we support retrieval only numeric auto generated ids.protected final booleanisJsonResult(PreparedQuery<?, ?> preparedQuery, QueryResultInfo queryResultInfo) Return an indicator telling whether prepared query result produces JSON result.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 final <R,T> R mapQueryColumnResult(SqlPreparedQuery<?, ?> sqlPreparedQuery, RS rs, String columnName, JsonDataType jsonDataType, RuntimePersistentEntity<T> persistentEntity, Class<R> resultType, Class<RS> resultSetType, BiFunction<RuntimePersistentEntity<Object>, Object, Object> loadListener) Reads an object from the result set and given column.protected <T,R> PS prepareStatement(AbstractSqlRepositoryOperations.StatementSupplier<PS> statementFunction, @NonNull PreparedQuery<T, R> preparedQuery, boolean isUpdate, boolean isSingleResult) Prepare a statement for execution.protected <T> StringresolveAssociationInsert(Class repositoryType, RuntimePersistentEntity<T> persistentEntity, RuntimeAssociation<T> association) Builds a join table insert.protected <E> @NonNull SqlStoredQuery<E,E> resolveEntityInsert(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, Class<?> repositoryType, @NonNull Class<E> rootEntity, @NonNull RuntimePersistentEntity<E> persistentEntity) Resolves a stored insert for the given entity.protected <E> @NonNull SqlStoredQuery<E,E> resolveEntityUpdate(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, Class<?> repositoryType, @NonNull Class<E> rootEntity, @NonNull RuntimePersistentEntity<E> persistentEntity) Resolves a stored update for the given entity.protected <T> SqlStoredQuery<T,?> resolveSqlInsertAssociation(Class<?> repositoryType, RuntimeAssociation<T> association, RuntimePersistentEntity<T> persistentEntity, T entity) Resolve SQL insert association operation.protected voidsetStatementParameter(PS preparedStatement, int index, DataType dataType, JsonDataType jsonDataType, Object value, SqlStoredQuery<?, ?> storedQuery) Set the parameter value on the given statement.Methods inherited from class io.micronaut.data.runtime.operations.internal.AbstractRepositoryOperationscheckOptimisticLocking, getApplicationContext, getConversionService, getEntity, getIdReader, isOnlySingleEndedJoins, triggerPostLoadMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.context.ApplicationContextProvidergetApplicationContextMethods inherited from interface io.micronaut.data.operations.HintsCapableRepositorygetQueryHints
- 
Field Details- 
QUERY_LOGprotected static final org.slf4j.Logger QUERY_LOG
- 
dataSourceName
- 
columnNameResultSetReader
- 
columnIndexResultSetReader
- 
preparedStatementWriter
- 
jsonMapperprotected final io.micronaut.json.JsonMapper jsonMapper
- 
sqlJsonColumnMapperProvider
- 
queryBuilders
- 
repositoriesWithHardcodedDataSource
 
- 
- 
Constructor Details- 
AbstractSqlRepositoryOperationsprotected AbstractSqlRepositoryOperations(String dataSourceName, ResultReader<RS, String> columnNameResultSetReader, ResultReader<RS, Integer> columnIndexResultSetReader, QueryStatement<PS, Integer> preparedStatementWriter, DateTimeProvider<Object> dateTimeProvider, RuntimeEntityRegistry runtimeEntityRegistry, io.micronaut.context.BeanContext beanContext, DataConversionService conversionService, AttributeConverterRegistry attributeConverterRegistry, io.micronaut.json.JsonMapper jsonMapper, SqlJsonColumnMapperProvider<RS> sqlJsonColumnMapperProvider) Default constructor.- Parameters:
- dataSourceName- The datasource name
- columnNameResultSetReader- The column name result reader
- columnIndexResultSetReader- The column index result reader
- preparedStatementWriter- The prepared statement writer
- dateTimeProvider- The date time provider
- runtimeEntityRegistry- The entity registry
- beanContext- The bean context
- conversionService- The conversion service
- attributeConverterRegistry- The attribute converter registry
- jsonMapper- The JSON mapper
- sqlJsonColumnMapperProvider- The SQL JSON column mapper provider
 
 
- 
- 
Method Details- 
decorateDescription copied from interface:PreparedQueryDecoratorDecorate prepared query.- Specified by:
- decoratein interface- PreparedQueryDecorator
- Type Parameters:
- E- The entity type
- R- The result type
- Parameters:
- preparedQuery- The query to be decorated
- Returns:
- decorated prepared query
 
- 
decoratepublic <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 interface- MethodContextAwareStoredQueryDecorator
- Type Parameters:
- E- The entity type
- R- The result type
- Parameters:
- context- The context
- storedQuery- The query to be decorated
- Returns:
- decorated stored query
 
- 
prepareStatementprotected <T,R> PS prepareStatement(AbstractSqlRepositoryOperations.StatementSupplier<PS> statementFunction, @NonNull @NonNull PreparedQuery<T, R> preparedQuery, boolean isUpdate, boolean isSingleResult) throws ExcPrepare a statement for execution.
- 
setStatementParameterprotected void setStatementParameter(PS preparedStatement, int index, DataType dataType, JsonDataType jsonDataType, Object value, SqlStoredQuery<?, ?> storedQuery) Set the parameter value on the given statement.- Parameters:
- preparedStatement- The prepared statement
- index- The index
- dataType- The data type
- jsonDataType- The JSON representation type if data type is JSON
- value- The value
- storedQuery- The SQL stored query
 
- 
resolveEntityInsert@NonNull protected <E> @NonNull SqlStoredQuery<E,E> resolveEntityInsert(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, Class<?> repositoryType, @NonNull @NonNull Class<E> rootEntity, @NonNull @NonNull RuntimePersistentEntity<E> persistentEntity) Resolves a stored insert for the given entity.- Type Parameters:
- E- The entity type
- Parameters:
- annotationMetadata- The repository annotation metadata
- repositoryType- The repository type
- rootEntity- The root entity
- persistentEntity- The persistent entity
- Returns:
- The insert
 
- 
resolveAssociationInsertprotected <T> String resolveAssociationInsert(Class repositoryType, RuntimePersistentEntity<T> persistentEntity, RuntimeAssociation<T> association) Builds a join table insert.- Type Parameters:
- T- The entity generic type
- Parameters:
- repositoryType- The repository type
- persistentEntity- The entity
- association- The association
- Returns:
- The insert statement
 
- 
resolveEntityUpdate@NonNull protected <E> @NonNull SqlStoredQuery<E,E> resolveEntityUpdate(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, Class<?> repositoryType, @NonNull @NonNull Class<E> rootEntity, @NonNull @NonNull RuntimePersistentEntity<E> persistentEntity) Resolves a stored update for the given entity.- Type Parameters:
- E- The entity type
- Parameters:
- annotationMetadata- The repository annotation metadata
- repositoryType- The repository type
- rootEntity- The root entity
- persistentEntity- The persistent entity
- Returns:
- The insert
 
- 
resolveSqlInsertAssociationprotected <T> SqlStoredQuery<T,?> resolveSqlInsertAssociation(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 type
- association- The association
- persistentEntity- The persistent entity
- entity- The entity
- Returns:
- The operation
 
- 
getSqlPreparedQuery
- 
getSqlStoredQuery
- 
isSupportsBatchInsertDoes supports batch for update queries.- Parameters:
- persistentEntity- The persistent entity
- dialect- The dialect
- Returns:
- true if supported
 
- 
isSupportsBatchUpdateDoes supports batch for update queries.- Parameters:
- persistentEntity- The persistent entity
- dialect- The dialect
- Returns:
- true if supported
 
- 
isSupportsBatchDeleteDoes supports batch for delete queries.- Parameters:
- persistentEntity- The persistent entity
- dialect- The dialect
- Returns:
- true if supported
 
- 
createQueryResultMapperprotected final <T,R> SqlTypeMapper<RS,R> createQueryResultMapper(SqlPreparedQuery<?, ?> sqlPreparedQuery, String columnName, JsonDataType jsonDataType, Class<RS> resultSetType, RuntimePersistentEntity<T> persistentEntity, BiFunction<RuntimePersistentEntity<Object>, Object, Object> loadListener) CreatesSqlTypeMapperfor reading results from single column into an entity. For now, we support reading from JSON column, however in support we might add XML support etc.- Type Parameters:
- T- the entity type
- R- the result type
- Parameters:
- sqlPreparedQuery- the SQL prepared query
- columnName- the column name where we are reading from
- jsonDataType- the JSON representation type
- resultSetType- resultSetType the result set type (different for R2dbc and Jdbc)
- persistentEntity- the persistent entity
- loadListener- the load listener if needed after entity loaded
- Returns:
- the SqlTypeMapperable to decode from column value into given type
 
- 
mapQueryColumnResultprotected final <R,T> R mapQueryColumnResult(SqlPreparedQuery<?, ?> sqlPreparedQuery, RS rs, String columnName, JsonDataType jsonDataType, RuntimePersistentEntity<T> persistentEntity, Class<R> resultType, Class<RS> resultSetType, BiFunction<RuntimePersistentEntity<Object>, Object, Object> loadListener) Reads an object from the result set and given column.- Type Parameters:
- R- the result type
- T- the entity type
- Parameters:
- sqlPreparedQuery- the SQL prepared query
- rs- the result set
- columnName- the column name where we are reading from
- jsonDataType- the JSON representation type
- persistentEntity- the persistent entity
- resultType- the result type
- resultSetType- the result set type
- loadListener- the load listener if needed after entity loaded
- Returns:
- an object read from the result set column
 
- 
handleSqlExceptionHandles SQL exception, used in context of update but could be used elsewhere. It can throw custom exception based on theSQLException.- Parameters:
- sqlException- the SQL exception
- dialect- the SQL dialect
- Returns:
- custom exception based on SQLExceptionthat was thrown or that same exception if nothing specific was about it
 
- 
isJsonResultprotected final boolean isJsonResult(PreparedQuery<?, ?> preparedQuery, QueryResultInfo queryResultInfo) Return an indicator telling whether prepared query result produces JSON result.- Parameters:
- preparedQuery- the prepared query
- queryResultInfo- the query result info, if not null will hold info about result type
- Returns:
- true if result is JSON
 
- 
isJsonEntityGeneratedIdprotected final boolean isJsonEntityGeneratedId(StoredQuery<?, ?> storedQuery, PersistentEntity persistentEntity) Inserting JSON entity representation (like Oracle Json View) can generate new id, and we support retrieval only numeric auto generated ids.- Parameters:
- storedQuery- the stored query
- persistentEntity- the persistent entity
- Returns:
- true if entity being inserted is JSON entity representation with auto generated numeric id
 
- 
getJsonColumnGets column name for JSON result. IfQueryResultannotation is present, takes column value from there, otherwise defaults to 'DATA' column name.- Parameters:
- queryResultInfo- the query result info from the- QueryResultannotation, null if annotation not present
- Returns:
- the JSON column name
 
- 
getJsonDataTypeGets JSON data type for JSON result. IfQueryResultannotation is present, takes data type value from there, otherwise defaults toJsonDataType.DEFAULT.- Parameters:
- queryResultInfo- the query result info from the- QueryResultannotation, null if annotation not present
- Returns:
- the JSON data type
 
 
-