Class HibernateTopiaJpaSupport
java.lang.Object
org.nuiton.topia.persistence.internal.support.HibernateTopiaJpaSupport
- All Implemented Interfaces:
TopiaJpaSupport
This class is the Hibernate implementation of TopiaJpaSupport. It realizes the bridge between the JPA specification
and the technical choice made for its implementation : Hibernate.
- Since:
- 3.0
- Author:
- Arnaud Thimel (Code Lutin)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TopiaFiresSupportObject that handles each event propagation.protected TopiaHibernateSupportObject to get Hibernate's Session, Configuration, ...Delay after which Topia should consider a query as slow then log a warn.protected booleanThis flag permits to use (or not) the flush mode when doing queries. -
Constructor Summary
ConstructorsConstructorDescriptionHibernateTopiaJpaSupport(TopiaHibernateSupport hibernateSupport, TopiaFiresSupport firesSupport, Optional<Duration> slowQueriesThreshold) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckHqlParameters(Map<String, Object> parameters) voidRemove a persistent instance.intExecute JPA-QL operation on data (Update, Delete).<T> List<T>Allow to do some JPA-QL query using the given bounds.protected <T> List<T><T> List<T>Allow to do some JPA-QL query WARNING : Depending on the registered service, this method may not support something else than queries on TopiaEntity<T> TAllow to do some JPA-QL query and return a single result.<T> TfindUnique(String jpaql, Map<String, Object> parameters) Allow to do some JPA-QL query and return an unique result.protected booleanhqlContainsOrderBy(String hql) protected SlowQueryWatchermonitorQuery(org.hibernate.query.Query query, Map<String, Object> args) protected org.hibernate.query.QueryprepareQuery(String jpaql, Map<String, Object> parameters) voidPersist the given transient instance, first assigning a generated identifier.voidsaveOrUpdate(Object object) EitherTopiaJpaSupport.save(Object)orTopiaJpaSupport.update(Object)the given instance.voidsetSlowQueriesThreshold(Duration slowQueriesThreshold) Tells to the context after which delay a query should be considered as slow.voidsetUseFlushMode(boolean useFlushMode) Tells to the context if it has to use a flush mode before each query.<T> Stream<T>LikefindAll(String, Map)but getting a stream that may lazily fetch data.truncateLongArgs(Map<String, Object> args, int truncateSize) Some of the values may be very long.voidUpdate the persistent instance with the identifier of the given detached instance.
-
Field Details
-
hibernateSupport
Object to get Hibernate's Session, Configuration, ... -
firesSupport
Object that handles each event propagation. Listeners are registered inside this instance. This instance is the persistenceContext's one. -
useFlushMode
protected boolean useFlushModeThis flag permits to use (or not) the flush mode when doing queries.The normal usage is to says yes (that's why the default value is
true), in that case when doing queries (says in methodfindAll(String, java.util.Map)orfind(String, int, int, java.util.Map)) it will use the flush modeFlushMode.AUTO).But sometimes, when doing a lot of queries (for some imports for example), we do NOT want the session to be flushed each time we do a find, then you can set this flag to
falseusing the methodsetUseFlushMode(boolean)- Since:
- 2.5
-
slowQueriesThreshold
Delay after which Topia should consider a query as slow then log a warn. If no value is present, the slow queries won't be tracked.- Since:
- 3.8
-
-
Constructor Details
-
HibernateTopiaJpaSupport
public HibernateTopiaJpaSupport(TopiaHibernateSupport hibernateSupport, TopiaFiresSupport firesSupport, Optional<Duration> slowQueriesThreshold)
-
-
Method Details
-
getHibernateSupport
-
setUseFlushMode
public void setUseFlushMode(boolean useFlushMode) Description copied from interface:TopiaJpaSupportTells to the context if it has to use a flush mode before each query. By default, we use a flush mode, but in some case it costs to much doing this, that's why you can disable it setting the value tofalse.- Specified by:
setUseFlushModein interfaceTopiaJpaSupport- Parameters:
useFlushMode- the new value to set
-
setSlowQueriesThreshold
Description copied from interface:TopiaJpaSupportTells to the context after which delay a query should be considered as slow. Default value is to skip slow queries watching unless specified in application configuration.- Specified by:
setSlowQueriesThresholdin interfaceTopiaJpaSupport- Parameters:
slowQueriesThreshold- the new value to set
-
prepareQuery
-
checkHqlParameters
-
findAll
Description copied from interface:TopiaJpaSupportAllow to do some JPA-QL query WARNING : Depending on the registered service, this method may not support something else than queries on TopiaEntity- Specified by:
findAllin interfaceTopiaJpaSupport- Type Parameters:
T- type of result- Parameters:
jpaql- the JPA-QL queryparameters- a map which keys are the attribute names and values are the attributes expected values- Returns:
- The result list
-
stream
LikefindAll(String, Map)but getting a stream that may lazily fetch data. Actual behavior rely on JPA implementation. According toQuery.stream(), caller shouldBaseStream.close()the stream.- Specified by:
streamin interfaceTopiaJpaSupport- Since:
- 3.4
-
findAny
Description copied from interface:TopiaJpaSupportAllow to do some JPA-QL query and return a single result. If nothing is found by the query, will return null. WARNING : Depending on the registered service, this method may not support something else than queries on TopiaEntity- Specified by:
findAnyin interfaceTopiaJpaSupport- Type Parameters:
T- type of result- Parameters:
jpaql- the JPA-QL queryparameters- a map which keys are the attribute names and values are the attributes expected values- Returns:
- The result instance or null
-
findUnique
Description copied from interface:TopiaJpaSupportAllow to do some JPA-QL query and return an unique result. If nothing is found by the query, will return null. If more than one result is found, will throw an exception. WARNING : Depending on the registered service, this method may not support something else than queries on TopiaEntity- Specified by:
findUniquein interfaceTopiaJpaSupport- Type Parameters:
T- type of result- Parameters:
jpaql- the JPA-QL queryparameters- a map which keys are the attribute names and values are the attributes expected values- Returns:
- The result instance or null
-
hqlContainsOrderBy
-
find
public <T> List<T> find(String jpaql, int startIndex, int endIndex, Map<String, Object> parameters) throws QueryMissingOrderExceptionDescription copied from interface:TopiaJpaSupportAllow to do some JPA-QL query using the given bounds.- No lower bound :
startIndex = 0. - No upper bound :
endIndex = -1.
- Specified by:
findin interfaceTopiaJpaSupport- Type Parameters:
T- type of result- Parameters:
jpaql- the JPA-QL querystartIndex- first index of entity to returnendIndex- last index of entity to returnparameters- a map which keys are the attribute names and values are the attributes expected values- Returns:
- The result list
- Throws:
QueryMissingOrderException- if no order by clause is specified
- No lower bound :
-
find0
-
execute
Description copied from interface:TopiaJpaSupportExecute JPA-QL operation on data (Update, Delete).- Specified by:
executein interfaceTopiaJpaSupport- Parameters:
jpaql- the JPA-QL queryparameters- a map which keys are the attribute names and values are the attributes expected values- Returns:
- The number of entities updated or deleted.
-
save
Description copied from interface:TopiaJpaSupportPersist the given transient instance, first assigning a generated identifier. This method is JPA implementation independent. This method is "inspired" of the Hibernate's Session#save method.- Specified by:
savein interfaceTopiaJpaSupport- Parameters:
object- a transient instance of a persistent class
-
update
Description copied from interface:TopiaJpaSupportUpdate the persistent instance with the identifier of the given detached instance. This method is "inspired" of the Hibernate's Session#update method.- Specified by:
updatein interfaceTopiaJpaSupport- Parameters:
object- a detached instance containing updated state
-
saveOrUpdate
Description copied from interface:TopiaJpaSupportEitherTopiaJpaSupport.save(Object)orTopiaJpaSupport.update(Object)the given instance. This method is "inspired" of the Hibernate's Session#saveOrUpdate method.- Specified by:
saveOrUpdatein interfaceTopiaJpaSupport- Parameters:
object- a transient or detached instance containing new or updated state- See Also:
-
delete
Description copied from interface:TopiaJpaSupportRemove a persistent instance. This method is "inspired" of the Hibernate's Session#delete method.- Specified by:
deletein interfaceTopiaJpaSupport- Parameters:
object- the instance to be removed
-
monitorQuery
-
truncateLongArgs
Some of the values may be very long. This methods truncates any Iterable value to a maximum oftruncateSizeelements and display how many more.- Parameters:
args- the raw map of argstruncateSize- who many elements to include before truncating- Returns:
- a view over the given map which each value is potentially truncated
-