Class AbstractHibernateOperations<S,Q,P extends Q>
java.lang.Object
io.micronaut.data.hibernate.operations.AbstractHibernateOperations<S,Q,P>
- Type Parameters:
S
- The session typeQ
- The query typeP
- The selection query type
- All Implemented Interfaces:
HintsCapableRepository
,PreparedQueryDecorator
,StoredQueryDecorator
@Internal
public abstract class AbstractHibernateOperations<S,Q,P extends Q>
extends Object
implements HintsCapableRepository, PreparedQueryDecorator, StoredQueryDecorator
Abstract Hibernate operations shared between the synchronous and the reactive implementations.
- Since:
- 3.5.0
- Author:
- Denis Stepanov
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
The result collector. -
Field Summary
Modifier and TypeFieldDescriptionprotected final io.micronaut.core.convert.ConversionService
protected final RuntimeEntityRegistry
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractHibernateOperations
(RuntimeEntityRegistry runtimeEntityRegistry, DataConversionService dataConversionService) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected <T,
R> void bindParameters
(Q q, @NonNull PreparedQuery<T, R> preparedQuery, boolean bindNamed) Bind parameters into query.protected <T,
R> void bindParameters
(Q q, @NonNull StoredQuery<T, R> storedQuery, io.micronaut.aop.InvocationContext<?, ?> invocationContext, boolean bindNamed, T entity) Bind parameters into query.protected final <R> void
collectCountOf
(jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder, S session, Class<R> entity, @Nullable Pageable pageable, AbstractHibernateOperations<S, Q, P>.ResultCollector<Long> resultCollector) protected <R> void
collectFindAll
(S session, PreparedQuery<?, R> preparedQuery, AbstractHibernateOperations<S, Q, P>.ResultCollector<R> collector) Collect all results.protected <R> void
collectFindOne
(S session, PreparedQuery<?, R> preparedQuery, AbstractHibernateOperations<S, Q, P>.ResultCollector<R> collector) Collect one result.protected final <T> void
collectPagedResults
(jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder, S session, PagedQuery<T> pagedQuery, AbstractHibernateOperations<S, Q, P>.ResultCollector<T> resultCollector) protected abstract <T> jakarta.persistence.EntityGraph<T>
createEntityGraph
(S session, Class<T> entityType) Creates an entity graph.protected abstract P
createNativeQuery
(S session, String query, Class<?> resultType) Create a new native query.protected abstract P
createQuery
(S session, jakarta.persistence.criteria.CriteriaQuery<?> criteriaQuery) Create a native query.protected abstract P
createQuery
(S session, String query, @Nullable Class<?> resultType) Create a new query.<E,
R> PreparedQuery<E, R> decorate
(PreparedQuery<E, R> preparedQuery) Decorate prepared query.<E,
R> StoredQuery<E, R> decorate
(StoredQuery<E, R> storedQuery) Decorate stored query.protected io.micronaut.context.ApplicationContext
protected io.micronaut.core.convert.ConversionService
protected abstract <T> @NonNull RuntimePersistentEntity<T>
Gets the persistence entity.protected abstract <T> jakarta.persistence.EntityGraph<T>
getEntityGraph
(S session, Class<T> entityType, String graphName) Gets an entity graph.protected final jakarta.persistence.FlushModeType
getFlushModeType
(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) getQueryHints
(@NonNull StoredQuery<?, ?> storedQuery) Obtain any custom query hints for this method and repository implementation.protected abstract void
Sets a hint.protected abstract void
setMaxResults
(P query, int max) Sets the max results value.protected abstract void
Sets the offset value.protected abstract void
setParameter
(Q query, int parameterIndex, Object value) Sets a parameter into query.protected abstract void
setParameter
(Q query, int parameterIndex, Object value, io.micronaut.core.type.Argument<?> argument) Sets parameter into query.protected abstract void
setParameter
(Q query, String parameterName, Object value) Sets a parameter into query.protected abstract void
setParameter
(Q query, String parameterName, Object value, io.micronaut.core.type.Argument<?> argument) Sets parameter into query.protected abstract void
setParameterList
(Q query, int parameterIndex, Collection<Object> value) Sets a list parameter into query.protected abstract void
setParameterList
(Q query, int parameterIndex, Collection<Object> value, io.micronaut.core.type.Argument<?> argument) Sets a list parameter into query.protected abstract void
setParameterList
(Q query, String parameterName, Collection<Object> value) Sets a list parameter into query.protected abstract void
setParameterList
(Q query, String parameterName, Collection<Object> value, io.micronaut.core.type.Argument<?> argument) Sets a list parameter into query.
-
Field Details
-
dataConversionService
protected final io.micronaut.core.convert.ConversionService dataConversionService -
runtimeEntityRegistry
-
-
Constructor Details
-
AbstractHibernateOperations
protected AbstractHibernateOperations(RuntimeEntityRegistry runtimeEntityRegistry, DataConversionService dataConversionService) Default constructor.- Parameters:
runtimeEntityRegistry
- The runtime entity registrydataConversionService
- The data conversion service
-
-
Method Details
-
decorate
Description copied from interface:PreparedQueryDecorator
Decorate prepared query.- Specified by:
decorate
in interfacePreparedQueryDecorator
- Type Parameters:
E
- The entity typeR
- The result type- Parameters:
preparedQuery
- The query to be decorated- Returns:
- decorated prepared query
-
decorate
Description copied from interface:StoredQueryDecorator
Decorate stored query.- Specified by:
decorate
in interfaceStoredQueryDecorator
- Type Parameters:
E
- The entity typeR
- The result type- Parameters:
storedQuery
- The query to be decorated- Returns:
- decorated stored query
-
getApplicationContext
protected io.micronaut.context.ApplicationContext getApplicationContext()- Returns:
- The application context
-
getConversionService
protected io.micronaut.core.convert.ConversionService getConversionService()- Returns:
- The conversion service
-
getEntity
@NonNull protected abstract <T> @NonNull RuntimePersistentEntity<T> getEntity(@NonNull @NonNull Class<T> type) Gets the persistence entity.- Type Parameters:
T
- The entity type- Parameters:
type
- The entity type- Returns:
- The persistent entity
-
getQueryHints
@NonNull public @NonNull Map<String,Object> getQueryHints(@NonNull @NonNull StoredQuery<?, ?> storedQuery) Description copied from interface:HintsCapableRepository
Obtain any custom query hints for this method and repository implementation.- Specified by:
getQueryHints
in interfaceHintsCapableRepository
- Parameters:
storedQuery
- The stored query- Returns:
- THe query hints
-
setParameter
Sets a parameter into query.- Parameters:
query
- The queryparameterName
- The parameter namevalue
- The value
-
setParameter
protected abstract void setParameter(Q query, String parameterName, Object value, io.micronaut.core.type.Argument<?> argument) Sets parameter into query.- Parameters:
query
- The queryparameterName
- The parameter namevalue
- The valueargument
- The argument
-
setParameterList
Sets a list parameter into query.- Parameters:
query
- The queryparameterName
- The parameter namevalue
- The value
-
setParameterList
protected abstract void setParameterList(Q query, String parameterName, Collection<Object> value, io.micronaut.core.type.Argument<?> argument) Sets a list parameter into query.- Parameters:
query
- The queryparameterName
- The parameter namevalue
- The valueargument
- The argument
-
setParameter
Sets a parameter into query.- Parameters:
query
- The queryparameterIndex
- The parameter indexvalue
- The value
-
setParameter
protected abstract void setParameter(Q query, int parameterIndex, Object value, io.micronaut.core.type.Argument<?> argument) Sets parameter into query.- Parameters:
query
- The queryparameterIndex
- The parameter indexvalue
- The valueargument
- The argument
-
setParameterList
Sets a list parameter into query.- Parameters:
query
- The queryparameterIndex
- The parameter indexvalue
- The value
-
setParameterList
protected abstract void setParameterList(Q query, int parameterIndex, Collection<Object> value, io.micronaut.core.type.Argument<?> argument) Sets a list parameter into query.- Parameters:
query
- The queryparameterIndex
- The parameter indexvalue
- The valueargument
- The argument
-
setHint
Sets a hint.- Parameters:
query
- The queryhintName
- The hint namevalue
- The value
-
setMaxResults
Sets the max results value.- Parameters:
query
- The querymax
- The max value
-
setOffset
Sets the offset value.- Parameters:
query
- The queryoffset
- The offset value
-
getEntityGraph
protected abstract <T> jakarta.persistence.EntityGraph<T> getEntityGraph(S session, Class<T> entityType, String graphName) Gets an entity graph.- Type Parameters:
T
- The entity type- Parameters:
session
- The sessionentityType
- The entity typegraphName
- The graph name- Returns:
- The graph
-
createEntityGraph
protected abstract <T> jakarta.persistence.EntityGraph<T> createEntityGraph(S session, Class<T> entityType) Creates an entity graph.- Type Parameters:
T
- The entityType- Parameters:
session
- The sessionentityType
- The entityType- Returns:
- The graph
-
createQuery
Create a new query.- Parameters:
session
- The sessionquery
- The queryresultType
- The result type- Returns:
- new query
-
createNativeQuery
Create a new native query.- Parameters:
session
- The sessionquery
- The queryresultType
- The result type- Returns:
- new query
-
createQuery
protected abstract P createQuery(S session, jakarta.persistence.criteria.CriteriaQuery<?> criteriaQuery) Create a native query.- Parameters:
session
- The sessioncriteriaQuery
- The criteriaQuery- Returns:
- new query
-
collectFindOne
protected <R> void collectFindOne(S session, PreparedQuery<?, R> preparedQuery, AbstractHibernateOperations<S, Q, P>.ResultCollector<R> collector) Collect one result.- Type Parameters:
R
- The result type- Parameters:
session
- The sessionpreparedQuery
- The prepared querycollector
- The collector
-
collectFindAll
protected <R> void collectFindAll(S session, PreparedQuery<?, R> preparedQuery, AbstractHibernateOperations<S, Q, P>.ResultCollector<R> collector) Collect all results.- Type Parameters:
R
- The result type- Parameters:
session
- The sessionpreparedQuery
- The prepared querycollector
- The collector
-
bindParameters
protected <T,R> void bindParameters(Q q, @NonNull @NonNull PreparedQuery<T, R> preparedQuery, boolean bindNamed) Bind parameters into query.- Type Parameters:
T
- The entity typeR
- The result type- Parameters:
q
- The querypreparedQuery
- The prepared querybindNamed
- If parameter should be bind by the name
-
bindParameters
protected <T,R> void bindParameters(Q q, @NonNull @NonNull StoredQuery<T, R> storedQuery, io.micronaut.aop.InvocationContext<?, ?> invocationContext, boolean bindNamed, T entity) Bind parameters into query.- Type Parameters:
T
- The entity typeR
- The result type- Parameters:
q
- The querystoredQuery
- The stored queryinvocationContext
- The invocationContextbindNamed
- If parameter should be bind by the nameentity
- The entity
-
getFlushModeType
protected final jakarta.persistence.FlushModeType getFlushModeType(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) -
collectPagedResults
protected final <T> void collectPagedResults(jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder, S session, PagedQuery<T> pagedQuery, AbstractHibernateOperations<S, Q, P>.ResultCollector<T> resultCollector) -
collectCountOf
protected final <R> void collectCountOf(jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder, S session, Class<R> entity, @Nullable @Nullable Pageable pageable, AbstractHibernateOperations<S, Q, P>.ResultCollector<Long> resultCollector)
-