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
Nested ClassesModifier and TypeClassDescriptionprotected classThe result collector. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final io.micronaut.core.convert.ConversionServiceprotected final RuntimeEntityRegistry -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractHibernateOperations(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, T entity) Bind parameters into query.protected final <R> voidcollectCountOf(jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder, S session, Class<R> entity, @NonNull Limit limit, AbstractHibernateOperations<S, Q, P>.ResultCollector<Long> resultCollector) protected <R> voidcollectFindAll(S session, PreparedQuery<?, R> preparedQuery, AbstractHibernateOperations<S, Q, P>.ResultCollector<R> collector) Collect all results.protected <R> voidcollectFindOne(S session, PreparedQuery<?, R> preparedQuery, AbstractHibernateOperations<S, Q, P>.ResultCollector<R> collector) Collect one result.protected final <T> voidcollectPagedResults(jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder, S session, PagedQuery<T> pagedQuery, AbstractHibernateOperations<S, Q, P>.ResultCollector<T> resultCollector) protected final <T,R> void collectResults(S session, String queryStr, PreparedQuery<T, R> preparedQuery, Limit limit, Sort sort, AbstractHibernateOperations<S, Q, P>.ResultCollector<R> resultCollector) protected static voidconvertFetchesToJoinsForIdQuery(jakarta.persistence.criteria.CriteriaQuery<?> query) Converts fetch joins in Micronaut Data's dedicated paginated ID query to regular joins.protected abstract <T> jakarta.persistence.EntityGraph<T> createEntityGraph(S session, Class<T> entityType) Creates an entity graph.protected abstract PcreateNativeQuery(S session, String query, Class<?> resultType) Create a new native query.protected abstract PcreateQuery(S session, jakarta.persistence.criteria.CriteriaQuery<?> criteriaQuery) Create a native query.protected abstract PcreateQuery(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.ApplicationContextprotected io.micronaut.core.convert.ConversionServiceprotected 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 @Nullable jakarta.persistence.FlushModeTypegetFlushModeType(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) protected static <T> List<org.hibernate.query.Order<? super T>> getQueryHints(@NonNull StoredQuery<?, ?> storedQuery) Obtain any custom query hints for this method and repository implementation.protected abstract voidSets a hint.protected abstract voidsetMaxResults(P query, int max) Sets the max results value.protected abstract voidSets the offset value.protected abstract voidsetParameter(Q query, int parameterIndex, @Nullable Object value) Sets a parameter into query.protected abstract voidsetParameter(Q query, int parameterIndex, @Nullable Object value, io.micronaut.core.type.Argument<?> argument) Sets parameter into query.protected abstract voidsetParameter(Q query, String parameterName, @Nullable Object value) Sets a parameter into query.protected abstract voidsetParameter(Q query, String parameterName, @Nullable Object value, io.micronaut.core.type.Argument<?> argument) Sets parameter into query.protected abstract voidsetParameterList(Q query, int parameterIndex, Collection<Object> value) Sets a list parameter into query.protected abstract voidsetParameterList(Q query, int parameterIndex, Collection<Object> value, io.micronaut.core.type.Argument<?> argument) Sets a list parameter into query.protected abstract voidsetParameterList(Q query, String parameterName, Collection<Object> value) Sets a list parameter into query.protected abstract voidsetParameterList(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: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
Description copied from interface:StoredQueryDecoratorDecorate stored query.- Specified by:
decoratein 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
Gets the persistence entity.- Type Parameters:
T- The entity type- Parameters:
type- The entity type- Returns:
- The persistent entity
-
getQueryHints
Description copied from interface:HintsCapableRepositoryObtain any custom query hints for this method and repository implementation.- Specified by:
getQueryHintsin interfaceHintsCapableRepository- Parameters:
storedQuery- The stored query- Returns:
- THe query hints
-
setParameter
-
setParameter
-
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
-
setParameter
-
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
-
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
-
createEntityGraph
-
createQuery
-
createNativeQuery
-
createQuery
-
convertFetchesToJoinsForIdQuery
protected static void convertFetchesToJoinsForIdQuery(jakarta.persistence.criteria.CriteriaQuery<?> query) Converts fetch joins in Micronaut Data's dedicated paginated ID query to regular joins. The query specification may use a Hibernate fetch as a join in its predicate, but fetching is invalid once the query selects IDs instead of the owning entity. Keeping the join preserves the predicate while allowing the database to page distinct parent IDs. This method is invoked only through the internal page-ID operation, never for a user criteria query.- Parameters:
query- The paginated criteria 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
-
collectResults
protected final <T,R> void collectResults(S session, String queryStr, PreparedQuery<T, R> preparedQuery, Limit limit, Sort sort, AbstractHibernateOperations<S, Q, P>.ResultCollector<R> resultCollector) -
bindParameters
protected <T,R> void bindParameters(Q q, @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 StoredQuery<T, R> storedQuery, io.micronaut.aop.InvocationContext<?, ?> invocationContext, T entity) Bind parameters into query.- Type Parameters:
T- The entity typeR- The result type- Parameters:
q- The querystoredQuery- The stored queryinvocationContext- The invocationContextentity- The entity
-
getFlushModeType
protected final @Nullable jakarta.persistence.FlushModeType getFlushModeType(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) -
getOrders
-
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, @NonNull Limit limit, AbstractHibernateOperations<S, Q, P>.ResultCollector<Long> resultCollector)
-