Class HibernateJpaOperations
- java.lang.Object
-
- io.micronaut.data.hibernate.operations.AbstractHibernateOperations<org.hibernate.Session,org.hibernate.query.Query<?>>
-
- io.micronaut.data.hibernate.operations.HibernateJpaOperations
-
- All Implemented Interfaces:
io.micronaut.context.ApplicationContextProvider,JpaRepositoryOperations,AsyncCapableRepository,HintsCapableRepository,PrimaryRepositoryOperations,ReactiveCapableRepository,RepositoryOperations
@EachBean(javax.sql.DataSource.class) public class HibernateJpaOperations extends AbstractHibernateOperations<org.hibernate.Session,org.hibernate.query.Query<?>> implements JpaRepositoryOperations, AsyncCapableRepository, ReactiveCapableRepository
Implementation of theJpaRepositoryOperationsinterface for Hibernate.- Since:
- 1.0
- Author:
- graemerocher
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.micronaut.data.hibernate.operations.AbstractHibernateOperations
AbstractHibernateOperations.ResultCollector<R>
-
-
Field Summary
-
Fields inherited from class io.micronaut.data.hibernate.operations.AbstractHibernateOperations
dataConversionService, runtimeEntityRegistry
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedHibernateJpaOperations(org.hibernate.SessionFactory sessionFactory, TransactionOperations<java.sql.Connection> transactionOperations, java.util.concurrent.ExecutorService executorService, RuntimeEntityRegistry runtimeEntityRegistry)Deprecated.HibernateJpaOperations(org.hibernate.SessionFactory sessionFactory, TransactionOperations<java.sql.Connection> transactionOperations, java.util.concurrent.ExecutorService executorService, RuntimeEntityRegistry runtimeEntityRegistry, DataConversionService<?> dataConversionService)Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ExecutorAsyncOperationsasync()<T> longcount(PagedQuery<T> pagedQuery)Counts all results for the given query.protected <T> org.hibernate.graph.RootGraph<T>createEntityGraph(org.hibernate.Session session, java.lang.Class<T> entityType)Creates an entity graph.protected org.hibernate.query.Query<?>createNativeQuery(org.hibernate.Session session, java.lang.String query, java.lang.Class<?> resultType)Create a new native query.protected org.hibernate.query.Query<?>createQuery(org.hibernate.Session session, java.lang.String query, java.lang.Class<?> resultType)Create a new query.protected org.hibernate.query.Query<?>createQuery(org.hibernate.Session session, javax.persistence.criteria.CriteriaQuery<?> criteriaQuery)Create a native query.<T> intdelete(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.java.util.Optional<java.lang.Number>executeUpdate(PreparedQuery<?,java.lang.Number> preparedQuery)Executes an update for the given query and parameter values.<T> booleanexists(PreparedQuery<T,java.lang.Boolean> preparedQuery)Execute a query that checks for existence.<T> java.lang.Iterable<T>findAll(PagedQuery<T> pagedQuery)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,R>
RfindOne(PreparedQuery<T,R> preparedQuery)Find one by Query.<T> TfindOne(java.lang.Class<T> type, java.io.Serializable id)Find one by ID.<R> Page<R>findPage(PagedQuery<R> pagedQuery)Find a page for the given entity and pageable.<T> java.util.stream.Stream<T>findStream(PagedQuery<T> pagedQuery)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.voidflush()Flush the current session.io.micronaut.context.ApplicationContextgetApplicationContext()io.micronaut.core.convert.ConversionService<?>getConversionService()Get conversion service.javax.persistence.EntityManagergetCurrentEntityManager()<T> RuntimePersistentEntity<T>getEntity(java.lang.Class<T> type)Gets the persistence entity.protected <T> org.hibernate.graph.RootGraph<T>getEntityGraph(org.hibernate.Session session, java.lang.Class<T> entityType, java.lang.String graphName)Gets an entity graph.javax.persistence.EntityManagerFactorygetEntityManagerFactory()java.util.Map<java.lang.String,java.lang.Object>getQueryHints(StoredQuery<?,?> storedQuery)Obtain any custom query hints for this method and repository implementation.<T> Tload(java.lang.Class<T> type, java.io.Serializable id)Create an uninitialized proxy.<T> Tpersist(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.ReactiveRepositoryOperationsreactive()protected voidsetHint(org.hibernate.query.Query<?> query, java.lang.String hintName, java.lang.Object value)Sets a hint.protected voidsetMaxResults(org.hibernate.query.Query<?> query, int max)Sets the max results value.protected voidsetOffset(org.hibernate.query.Query<?> query, int offset)Sets the offset value.protected voidsetParameter(org.hibernate.query.Query<?> query, java.lang.String parameterName, java.lang.Object value)Sets a parameter into query.protected voidsetParameter(org.hibernate.query.Query<?> query, java.lang.String parameterName, java.lang.Object value, io.micronaut.core.type.Argument argument)Sets parameter into query.protected voidsetParameterList(org.hibernate.query.Query<?> query, java.lang.String parameterName, java.util.Collection<java.lang.Object> value)Sets a list parameter into query.protected voidsetParameterList(org.hibernate.query.Query<?> query, java.lang.String parameterName, java.util.Collection<java.lang.Object> value, io.micronaut.core.type.Argument argument)Sets a list parameter into query.<T> Tupdate(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.-
Methods inherited from class io.micronaut.data.hibernate.operations.AbstractHibernateOperations
bindParameters, collectCountOf, collectFindAll, collectFindOne, collectPagedResults, getFlushModeType, getParameterValue
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.micronaut.data.operations.RepositoryOperations
executeDelete
-
-
-
-
Constructor Detail
-
HibernateJpaOperations
@Deprecated protected HibernateJpaOperations(@NonNull org.hibernate.SessionFactory sessionFactory, @NonNull @Parameter TransactionOperations<java.sql.Connection> transactionOperations, @Named("io") @Nullable java.util.concurrent.ExecutorService executorService, RuntimeEntityRegistry runtimeEntityRegistry)Deprecated.Default constructor.- Parameters:
sessionFactory- The session factorytransactionOperations- The transaction operationsexecutorService- The executor service for I/O tasks to useruntimeEntityRegistry- The runtime entity registry
-
HibernateJpaOperations
@Creator public HibernateJpaOperations(@NonNull @Parameter org.hibernate.SessionFactory sessionFactory, @NonNull @Parameter TransactionOperations<java.sql.Connection> transactionOperations, @Named("io") @Nullable java.util.concurrent.ExecutorService executorService, RuntimeEntityRegistry runtimeEntityRegistry, DataConversionService<?> dataConversionService)Default constructor.- Parameters:
sessionFactory- The session factorytransactionOperations- The transaction operationsexecutorService- The executor service for I/O tasks to useruntimeEntityRegistry- The runtime entity registrydataConversionService- The data conversion service
-
-
Method Detail
-
getEntity
public <T> RuntimePersistentEntity<T> getEntity(java.lang.Class<T> type)
Description copied from class:AbstractHibernateOperationsGets the persistence entity.- Specified by:
getEntityin interfaceRepositoryOperations- Specified by:
getEntityin classAbstractHibernateOperations<org.hibernate.Session,org.hibernate.query.Query<?>>- Type Parameters:
T- The entity type- Parameters:
type- The entity type- Returns:
- The persistent entity
-
getApplicationContext
public io.micronaut.context.ApplicationContext getApplicationContext()
- Specified by:
getApplicationContextin interfaceio.micronaut.context.ApplicationContextProvider- Overrides:
getApplicationContextin classAbstractHibernateOperations<org.hibernate.Session,org.hibernate.query.Query<?>>- Returns:
- The application context
-
getConversionService
public io.micronaut.core.convert.ConversionService<?> getConversionService()
Description copied from interface:RepositoryOperationsGet conversion service.- Specified by:
getConversionServicein interfaceRepositoryOperations- Overrides:
getConversionServicein classAbstractHibernateOperations<org.hibernate.Session,org.hibernate.query.Query<?>>- Returns:
- The conversion service
-
setParameter
protected void setParameter(org.hibernate.query.Query<?> query, java.lang.String parameterName, java.lang.Object value)Description copied from class:AbstractHibernateOperationsSets a parameter into query.- Specified by:
setParameterin classAbstractHibernateOperations<org.hibernate.Session,org.hibernate.query.Query<?>>- Parameters:
query- The queryparameterName- The parameter namevalue- The value
-
setParameter
protected void setParameter(org.hibernate.query.Query<?> query, java.lang.String parameterName, java.lang.Object value, io.micronaut.core.type.Argument argument)Description copied from class:AbstractHibernateOperationsSets parameter into query.- Specified by:
setParameterin classAbstractHibernateOperations<org.hibernate.Session,org.hibernate.query.Query<?>>- Parameters:
query- The queryparameterName- The parameter namevalue- The valueargument- The argument
-
setParameterList
protected void setParameterList(org.hibernate.query.Query<?> query, java.lang.String parameterName, java.util.Collection<java.lang.Object> value)Description copied from class:AbstractHibernateOperationsSets a list parameter into query.- Specified by:
setParameterListin classAbstractHibernateOperations<org.hibernate.Session,org.hibernate.query.Query<?>>- Parameters:
query- The queryparameterName- The parameter namevalue- The value
-
setParameterList
protected void setParameterList(org.hibernate.query.Query<?> query, java.lang.String parameterName, java.util.Collection<java.lang.Object> value, io.micronaut.core.type.Argument argument)Description copied from class:AbstractHibernateOperationsSets a list parameter into query.- Specified by:
setParameterListin classAbstractHibernateOperations<org.hibernate.Session,org.hibernate.query.Query<?>>- Parameters:
query- The queryparameterName- The parameter namevalue- The valueargument- The argument
-
setHint
protected void setHint(org.hibernate.query.Query<?> query, java.lang.String hintName, java.lang.Object value)Description copied from class:AbstractHibernateOperationsSets a hint.- Specified by:
setHintin classAbstractHibernateOperations<org.hibernate.Session,org.hibernate.query.Query<?>>- Parameters:
query- The queryhintName- The hint namevalue- The value
-
getEntityGraph
protected <T> org.hibernate.graph.RootGraph<T> getEntityGraph(org.hibernate.Session session, java.lang.Class<T> entityType, java.lang.String graphName)Description copied from class:AbstractHibernateOperationsGets an entity graph.- Specified by:
getEntityGraphin classAbstractHibernateOperations<org.hibernate.Session,org.hibernate.query.Query<?>>- Type Parameters:
T- The entity type- Parameters:
session- The sessionentityType- The entity typegraphName- The graph name- Returns:
- The graph
-
createEntityGraph
protected <T> org.hibernate.graph.RootGraph<T> createEntityGraph(org.hibernate.Session session, java.lang.Class<T> entityType)Description copied from class:AbstractHibernateOperationsCreates an entity graph.- Specified by:
createEntityGraphin classAbstractHibernateOperations<org.hibernate.Session,org.hibernate.query.Query<?>>- Type Parameters:
T- The entityType- Parameters:
session- The sessionentityType- The entityType- Returns:
- The graph
-
createQuery
protected org.hibernate.query.Query<?> createQuery(org.hibernate.Session session, java.lang.String query, java.lang.Class<?> resultType)Description copied from class:AbstractHibernateOperationsCreate a new query.- Specified by:
createQueryin classAbstractHibernateOperations<org.hibernate.Session,org.hibernate.query.Query<?>>- Parameters:
session- The sessionquery- The queryresultType- The result type- Returns:
- new query
-
createNativeQuery
protected org.hibernate.query.Query<?> createNativeQuery(org.hibernate.Session session, java.lang.String query, java.lang.Class<?> resultType)Description copied from class:AbstractHibernateOperationsCreate a new native query.- Specified by:
createNativeQueryin classAbstractHibernateOperations<org.hibernate.Session,org.hibernate.query.Query<?>>- Parameters:
session- The sessionquery- The queryresultType- The result type- Returns:
- new query
-
createQuery
protected org.hibernate.query.Query<?> createQuery(org.hibernate.Session session, javax.persistence.criteria.CriteriaQuery<?> criteriaQuery)Description copied from class:AbstractHibernateOperationsCreate a native query.- Specified by:
createQueryin classAbstractHibernateOperations<org.hibernate.Session,org.hibernate.query.Query<?>>- Parameters:
session- The sessioncriteriaQuery- The criteriaQuery- Returns:
- new query
-
setOffset
protected void setOffset(org.hibernate.query.Query<?> query, int offset)Description copied from class:AbstractHibernateOperationsSets the offset value.- Specified by:
setOffsetin classAbstractHibernateOperations<org.hibernate.Session,org.hibernate.query.Query<?>>- Parameters:
query- The queryoffset- The offset value
-
setMaxResults
protected void setMaxResults(org.hibernate.query.Query<?> query, int max)Description copied from class:AbstractHibernateOperationsSets the max results value.- Specified by:
setMaxResultsin classAbstractHibernateOperations<org.hibernate.Session,org.hibernate.query.Query<?>>- Parameters:
query- The querymax- The max value
-
getQueryHints
@NonNull public java.util.Map<java.lang.String,java.lang.Object> getQueryHints(@NonNull StoredQuery<?,?> storedQuery)Description copied from interface:HintsCapableRepositoryObtain any custom query hints for this method and repository implementation.- Specified by:
getQueryHintsin interfaceHintsCapableRepository- Overrides:
getQueryHintsin classAbstractHibernateOperations<org.hibernate.Session,org.hibernate.query.Query<?>>- Parameters:
storedQuery- The stored query- Returns:
- THe query hints
-
findOne
@Nullable public <T> T findOne(@NonNull java.lang.Class<T> type, @NonNull java.io.Serializable id)Description copied from interface:RepositoryOperationsFind one by ID.- Specified by:
findOnein interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
type- The typeid- The id- Returns:
- A result or null
-
load
@NonNull public <T> T load(@NonNull java.lang.Class<T> type, @NonNull java.io.Serializable id)Description copied from interface:JpaRepositoryOperationsCreate an uninitialized proxy.- Specified by:
loadin interfaceJpaRepositoryOperations- Type Parameters:
T- the entity type- Parameters:
type- the entity typeid- the entity id- Returns:
- an uninitialized proxy
-
findOne
@Nullable public <T,R> R findOne(@NonNull PreparedQuery<T,R> preparedQuery)Description copied from interface:RepositoryOperationsFind one by Query.- Specified by:
findOnein interfaceRepositoryOperations- Type Parameters:
T- The generic resultTypeR- The result type- Parameters:
preparedQuery- The prepared query- Returns:
- A result or null
-
exists
public <T> boolean exists(@NonNull PreparedQuery<T,java.lang.Boolean> preparedQuery)Description copied from interface:RepositoryOperationsExecute a query that checks for existence.- Specified by:
existsin interfaceRepositoryOperations- Type Parameters:
T- The generic resultType- Parameters:
preparedQuery- The prepared query- Returns:
- A result or null
-
findAll
@NonNull public <T> java.lang.Iterable<T> findAll(@NonNull PagedQuery<T> pagedQuery)Description copied from interface:RepositoryOperationsFinds all results for the given query.- Specified by:
findAllin interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
pagedQuery- The root entity- Returns:
- An iterable result
-
findStream
@NonNull public <T> java.util.stream.Stream<T> findStream(@NonNull PagedQuery<T> pagedQuery)Description copied from interface:RepositoryOperationsFinds a stream for the given arguments.- Specified by:
findStreamin interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
pagedQuery- The query- Returns:
- The stream
-
findPage
public <R> Page<R> findPage(@NonNull PagedQuery<R> pagedQuery)
Description copied from interface:RepositoryOperationsFind a page for the given entity and pageable.- Specified by:
findPagein interfaceRepositoryOperations- Type Parameters:
R- The entity generic type- Parameters:
pagedQuery- The query- Returns:
- The page type
-
count
public <T> long count(PagedQuery<T> pagedQuery)
Description copied from interface:RepositoryOperationsCounts all results for the given query.- Specified by:
countin interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
pagedQuery- The paged query- Returns:
- An iterable result
-
findAll
@NonNull public <T,R> java.lang.Iterable<R> findAll(@NonNull PreparedQuery<T,R> preparedQuery)Description copied from interface:RepositoryOperationsFinds all results for the given query.- Specified by:
findAllin interfaceRepositoryOperations- Type Parameters:
T- The entity typeR- The result type- Parameters:
preparedQuery- The prepared query- Returns:
- An iterable result
-
persist
public <T> T persist(@NonNull InsertOperation<T> operation)Description copied from interface:RepositoryOperationsPersist the operation returning a possibly new entity.- Specified by:
persistin interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
operation- The operation- Returns:
- The operation
-
update
@NonNull public <T> T update(@NonNull UpdateOperation<T> operation)Description copied from interface:RepositoryOperationsUpdates the entity for the given operation.- Specified by:
updatein interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
operation- The operation- Returns:
- The operation
-
updateAll
@NonNull public <T> java.lang.Iterable<T> updateAll(@NonNull UpdateBatchOperation<T> operation)Description copied from interface:RepositoryOperationsUpdates the entities for the given operation.- Specified by:
updateAllin interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
operation- The operation- Returns:
- The updated entities
-
persistAll
@NonNull public <T> java.lang.Iterable<T> persistAll(@NonNull InsertBatchOperation<T> operation)Description copied from interface:RepositoryOperationsPersist all the given entities.- Specified by:
persistAllin interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
operation- The operation- Returns:
- The entities, possibly mutated
-
executeUpdate
@NonNull public java.util.Optional<java.lang.Number> executeUpdate(@NonNull PreparedQuery<?,java.lang.Number> preparedQuery)Description copied from interface:RepositoryOperationsExecutes an update for the given query and parameter values. If it is possible to return the number of objects updated, then do so.- Specified by:
executeUpdatein interfaceRepositoryOperations- Parameters:
preparedQuery- The prepared query- Returns:
- An optional number with the count of the number of records updated
-
delete
public <T> int delete(@NonNull DeleteOperation<T> operation)Description copied from interface:RepositoryOperationsDeletes the entity.- Specified by:
deletein interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
operation- The operation- Returns:
- The number of entities deleted
-
deleteAll
public <T> java.util.Optional<java.lang.Number> deleteAll(@NonNull DeleteBatchOperation<T> operation)Description copied from interface:RepositoryOperationsDeletes all the entities of the given type.- Specified by:
deleteAllin interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
operation- The operation- Returns:
- The number of entities deleted
-
findStream
@NonNull public <T,R> java.util.stream.Stream<R> findStream(@NonNull PreparedQuery<T,R> preparedQuery)Description copied from interface:RepositoryOperationsFinds all results for the given query.- Specified by:
findStreamin interfaceRepositoryOperations- Type Parameters:
T- The entity typeR- The result type- Parameters:
preparedQuery- The prepared query- Returns:
- An iterable result
-
async
@NonNull public ExecutorAsyncOperations async()
- Specified by:
asyncin interfaceAsyncCapableRepository- Returns:
- The async operations.
-
reactive
@NonNull public ReactiveRepositoryOperations reactive()
- Specified by:
reactivein interfaceReactiveCapableRepository- Returns:
- The reactive operations instance.
-
getCurrentEntityManager
@NonNull public javax.persistence.EntityManager getCurrentEntityManager()
- Specified by:
getCurrentEntityManagerin interfaceJpaRepositoryOperations- Returns:
- The currrent entity manager
-
getEntityManagerFactory
@NonNull public javax.persistence.EntityManagerFactory getEntityManagerFactory()
- Specified by:
getEntityManagerFactoryin interfaceJpaRepositoryOperations- Returns:
- The entity manager factory
-
flush
public void flush()
Description copied from interface:JpaRepositoryOperationsFlush the current session.- Specified by:
flushin interfaceJpaRepositoryOperations
-
-