Class DefaultJpaOperations
java.lang.Object
org.springframework.integration.jpa.core.DefaultJpaOperations
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean,JpaOperations
public class DefaultJpaOperations
extends java.lang.Object
Class similar to JPA template limited to the operations required for the JPA adapters/gateway
not using JpaTemplate as the class is deprecated since Spring 3.1.
- Since:
- 2.2
-
Constructor Summary
Constructors Constructor Description DefaultJpaOperations() -
Method Summary
Modifier and Type Method Description voidafterPropertiesSet()voiddelete(java.lang.Object entity)voiddeleteInBatch(java.lang.Iterable<?> entities)intexecuteUpdate(java.lang.String updateQuery, ParameterSource source)Executes the given update statement and uses the given parameter source to set the required query parameters.intexecuteUpdateWithNamedQuery(java.lang.String updateQuery, ParameterSource source)intexecuteUpdateWithNativeQuery(java.lang.String updateQuery, ParameterSource source)<T> Tfind(java.lang.Class<T> entityType, java.lang.Object id)Find an Entity of given type with the given primary key type.voidflush()ExecutesEntityManager.flush().protected javax.persistence.EntityManagergetEntityManager()java.util.List<?>getResultListForClass(java.lang.Class<?> entityClass, int firstResult, int maxNumberOfResults)java.util.List<?>getResultListForNamedQuery(java.lang.String selectNamedQuery, ParameterSource parameterSource, int firstResult, int maxNumberOfResults)java.util.List<?>getResultListForNativeQuery(java.lang.String selectQuery, java.lang.Class<?> entityClass, ParameterSource parameterSource, int firstResult, int maxNumberOfResults)java.util.List<?>getResultListForQuery(java.lang.String query, ParameterSource source)Executes the provided query to return a list of resultsjava.util.List<?>getResultListForQuery(java.lang.String queryString, ParameterSource source, int firstResult, int maxNumberOfResults)Executes the provided query to return a list of results.java.lang.ObjectgetSingleResultForQuery(java.lang.String queryString, ParameterSource source)Executes the provided query to return a single elementjava.lang.Objectmerge(java.lang.Object entity)The entity to be merged with theEntityManager.java.lang.Objectmerge(java.lang.Object entity, int flushSize, boolean clearOnFlush)The entity to be merged with theEntityManager.protected voidonInit()Subclasses may implement this for initialization logic.voidpersist(java.lang.Object entity)Persists the entity.voidpersist(java.lang.Object entity, int flushSize, boolean clearOnFlush)Persists the entity.voidsetEntityManager(javax.persistence.EntityManager entityManager)voidsetEntityManagerFactory(javax.persistence.EntityManagerFactory entityManagerFactory)
-
Constructor Details
-
DefaultJpaOperations
public DefaultJpaOperations()
-
-
Method Details
-
delete
public void delete(java.lang.Object entity)- Parameters:
entity- The entity to delete.
-
deleteInBatch
public void deleteInBatch(java.lang.Iterable<?> entities)- Parameters:
entities- The entities to delete.
-
executeUpdate
Description copied from interface:JpaOperationsExecutes the given update statement and uses the given parameter source to set the required query parameters.- Parameters:
updateQuery- Must Not be empty.source- Must Not be null.- Returns:
- The number of entities updated
-
executeUpdateWithNamedQuery
- Parameters:
updateQuery- The update query.source- The parameter source.- Returns:
- The number of entities updated.
-
executeUpdateWithNativeQuery
- Parameters:
updateQuery- The update query.source- The parameter source.- Returns:
- The number of entities updated
-
find
public <T> T find(java.lang.Class<T> entityType, java.lang.Object id)Description copied from interface:JpaOperationsFind an Entity of given type with the given primary key type.- Type Parameters:
T- The type to return.- Parameters:
entityType- The type.id- The object identifier.- Returns:
- The entity if it exists, null otherwise.
-
getResultListForClass
public java.util.List<?> getResultListForClass(java.lang.Class<?> entityClass, int firstResult, int maxNumberOfResults)- Parameters:
entityClass- The entity class.firstResult- The index of the first result to return.maxNumberOfResults- The number of objects to return.- Returns:
- The list of found entities.
-
getResultListForNamedQuery
public java.util.List<?> getResultListForNamedQuery(java.lang.String selectNamedQuery, ParameterSource parameterSource, int firstResult, int maxNumberOfResults)- Parameters:
selectNamedQuery- The select named query.parameterSource- The paramter source.firstResult- The index of the first result to return.maxNumberOfResults- The number of objects to return.- Returns:
- The list of found entities.
-
getResultListForNativeQuery
public java.util.List<?> getResultListForNativeQuery(java.lang.String selectQuery, @Nullable java.lang.Class<?> entityClass, ParameterSource parameterSource, int firstResult, int maxNumberOfResults)- Parameters:
selectQuery- The select query.entityClass- The entity class.parameterSource- The parameter source.firstResult- The index of the first result to return.maxNumberOfResults- The number of objects to return.- Returns:
- The list of found entities.
-
getResultListForQuery
Description copied from interface:JpaOperationsExecutes the provided query to return a list of results- Parameters:
query- The query.source- the Parameter source for this query to be executed, if none then set as null- Returns:
- The list of found entities.
-
getResultListForQuery
public java.util.List<?> getResultListForQuery(java.lang.String queryString, ParameterSource source, int firstResult, int maxNumberOfResults)Description copied from interface:JpaOperationsExecutes the provided query to return a list of results.- Parameters:
queryString- Must not be null or emptysource- the Parameter source for this query to be executed, if none then set null.firstResult- The first result.maxNumberOfResults- Must be a non-negative value, any negative or zero will be ignored.- Returns:
- The list of found entities.
-
getSingleResultForQuery
public java.lang.Object getSingleResultForQuery(java.lang.String queryString, ParameterSource source)Description copied from interface:JpaOperationsExecutes the provided query to return a single element- Parameters:
queryString- Must not be emptysource- the Parameter source for this query to be executed, if none then set as null- Returns:
- Will always return a result. If no object was found in the database an exception is raised.
-
merge
@Nullable public java.lang.Object merge(java.lang.Object entity)Description copied from interface:JpaOperationsThe entity to be merged with theEntityManager. The provided object can also be anIterablein which case each object of theIterableis treated as an entity and merged with theEntityManager.Nullvalues returned while iterating over theIterableare ignored.- Parameters:
entity- Must not be null.- Returns:
- The merged managed instance of the entity.
-
merge
@Nullable public java.lang.Object merge(java.lang.Object entity, int flushSize, boolean clearOnFlush)Description copied from interface:JpaOperationsThe entity to be merged with theEntityManager. The provided object can also be anIterablein which case each object of theIterableis treated as an entity and merged with theEntityManager. In addition theEntityManager.flush()is called after the merge and after each batch, as it is specified usingflushSizeparameter and if provided object isIterable.clearOnFlushparameter specifies, if theEntityManager.clear()should be called after eachEntityManager.flush().- Parameters:
entity- The entity.flushSize- The flush size.clearOnFlush- true to clear after flushing.- Returns:
- The merged object.
-
persist
public void persist(java.lang.Object entity)Description copied from interface:JpaOperationsPersists the entity. The provided object can also be anIterablein which case each object of theIterableis treated as an entity and persisted with theEntityManager.Nullvalues returned while iterating over theIterableare ignored.- Parameters:
entity- Must not be null
-
persist
public void persist(java.lang.Object entity, int flushSize, boolean clearOnFlush)Description copied from interface:JpaOperationsPersists the entity. The provided object can also be anIterablein which case each object of theIterableis treated as an entity and persisted with theEntityManager.Nullvalues returned while iterating over theIterableare ignored. In addition theEntityManager.flush()is called after the persist and after each batch, as it is specified usingflushSizeparameter and if provided object isIterable.clearOnFlushparameter specifies, if theEntityManager.clear()should be called after eachEntityManager.flush().- Parameters:
entity- The entity.flushSize- The flush size.clearOnFlush- true to clear after flushing.
-
setEntityManager
public void setEntityManager(javax.persistence.EntityManager entityManager) -
getEntityManager
protected javax.persistence.EntityManager getEntityManager() -
setEntityManagerFactory
public void setEntityManagerFactory(javax.persistence.EntityManagerFactory entityManagerFactory) -
afterPropertiesSet
public final void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
onInit
protected void onInit()Subclasses may implement this for initialization logic. -
flush
public void flush()Description copied from interface:JpaOperationsExecutesEntityManager.flush().- Specified by:
flushin interfaceJpaOperations
-