public class JpaExecutor extends java.lang.Object implements org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanFactoryAware, IntegrationEvaluationContextAware
Message payload.| Constructor and Description |
|---|
JpaExecutor(javax.persistence.EntityManager entityManager)
Constructor taking an
EntityManager directly. |
JpaExecutor(javax.persistence.EntityManagerFactory entityManagerFactory)
Constructor taking an
EntityManagerFactory from which the
EntityManager can be obtained. |
JpaExecutor(JpaOperations jpaOperations)
If custom behavior is required a custom implementation of
JpaOperations
can be passed in. |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet()
Verifies and sets the parameters.
|
protected java.util.List<?> |
doPoll(ParameterSource jpaQLParameterSource,
int firstResult,
int maxNumberOfResults) |
java.lang.Object |
executeOutboundJpaOperation(org.springframework.messaging.Message<?> message)
Executes the actual Jpa Operation.
|
java.lang.Object |
poll()
Execute the JPA operation.
|
java.lang.Object |
poll(org.springframework.messaging.Message<?> requestMessage)
Execute a (typically retrieving) JPA operation.
|
void |
setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) |
void |
setClearOnFlush(boolean clearOnFlush)
If set to
true the EntityManager.clear() will be called,
and only if the EntityManager.flush() was called after performing persistence operations. |
void |
setDeleteAfterPoll(boolean deleteAfterPoll)
If set to 'true', the retrieved objects are deleted from the database upon
being polled.
|
void |
setDeleteInBatch(boolean deleteInBatch)
If not set, this property defaults to
false, which means that
deletion occurs on a per object basis if a collection of entities is being
deleted. |
void |
setEntityClass(java.lang.Class<?> entityClass)
Sets the class type which is being used for retrieving entities from the
database.
|
void |
setExpectSingleResult(boolean expectSingleResult)
This parameter indicates that only one result object shall be returned as
a result from the executed JPA operation.
|
void |
setFirstResultExpression(org.springframework.expression.Expression firstResultExpression)
Sets the expression that will be evaluated to get the first result in the query executed.
|
void |
setFlush(boolean flush)
If set to
true the EntityManager.flush() will be called
after persistence operation. |
void |
setFlushSize(int flushSize)
If the provided value is greater than
0, then EntityManager.flush()
will be called after persistence operations as well as within batch operations. |
void |
setIntegrationEvaluationContext(org.springframework.expression.EvaluationContext evaluationContext)
Sets the evaluation context for evaluating the expression to get the from record of the
result set retrieved by the retrieving gateway.
|
void |
setJpaParameters(java.util.List<JpaParameter> jpaParameters) |
void |
setJpaQuery(java.lang.String jpaQuery) |
void |
setMaxNumberOfResults(int maxNumberOfResults)
Set the max number of results to retrieve from the database.
|
void |
setMaxResultsExpression(org.springframework.expression.Expression maxResultsExpression)
Sets the expression for maximum number of results expression.
|
void |
setNamedQuery(java.lang.String namedQuery)
A named query can either refer to a named JPQL based query or a native SQL
query.
|
void |
setNativeQuery(java.lang.String nativeQuery)
You can also use native Sql queries to poll data from the database.
|
void |
setParameterSource(ParameterSource parameterSource)
Specifies the
ParameterSource that would be used to provide
additional parameters. |
void |
setParameterSourceFactory(ParameterSourceFactory parameterSourceFactory) |
void |
setPersistMode(PersistMode persistMode) |
void |
setUsePayloadAsParameterSource(java.lang.Boolean usePayloadAsParameterSource) |
public JpaExecutor(javax.persistence.EntityManagerFactory entityManagerFactory)
EntityManagerFactory from which the
EntityManager can be obtained.entityManagerFactory - Must not be null.public JpaExecutor(javax.persistence.EntityManager entityManager)
EntityManager directly.entityManager - Must not be null.public JpaExecutor(JpaOperations jpaOperations)
JpaOperations
can be passed in. The implementations themselves typically provide access
to the EntityManager.
See also DefaultJpaOperations and AbstractJpaOperations.jpaOperations - Must not be null.public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
throws org.springframework.beans.BeansException
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAwareorg.springframework.beans.BeansExceptionpublic void afterPropertiesSet()
ParameterSourceFactory.afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanpublic java.lang.Object executeOutboundJpaOperation(org.springframework.messaging.Message<?> message)
message - public java.lang.Object poll(org.springframework.messaging.Message<?> requestMessage)
parameterSourceFactory. If the
requestMessage parameter is null then
parameterSource is being used for providing query parameters.requestMessage - May be null.public java.lang.Object poll()
poll(Message).protected java.util.List<?> doPoll(ParameterSource jpaQLParameterSource, int firstResult, int maxNumberOfResults)
public void setEntityClass(java.lang.Class<?> entityClass)
entityClass - Must not be null.public void setJpaQuery(java.lang.String jpaQuery)
jpaQuery - The provided JPA query must neither be null nor empty.public void setNativeQuery(java.lang.String nativeQuery)
nativeQuery - The provided SQL query must neither be null nor empty.public void setNamedQuery(java.lang.String namedQuery)
namedQuery - Must neither be null nor emptypublic void setPersistMode(PersistMode persistMode)
public void setJpaParameters(java.util.List<JpaParameter> jpaParameters)
public void setUsePayloadAsParameterSource(java.lang.Boolean usePayloadAsParameterSource)
public void setFlush(boolean flush)
true the EntityManager.flush() will be called
after persistence operation.
Has the same effect, if the flushSize is specified to 1.
For convenience in cases when the provided entity to persist is not an instance of Iterable.flush - defaults to 'false'.public void setFlushSize(int flushSize)
0, then EntityManager.flush()
will be called after persistence operations as well as within batch operations.
This property has precedence over the flush, if it is specified to a value greater than 0.
If the entity to persist is not an instance of Iterable and this property is greater than 0,
then the entity will be flushed as if the flush attribute was set to true.flushSize - defaults to '0'.public void setClearOnFlush(boolean clearOnFlush)
true the EntityManager.clear() will be called,
and only if the EntityManager.flush() was called after performing persistence operations.clearOnFlush - defaults to 'false'.setFlush(boolean),
setFlushSize(int)public void setDeleteInBatch(boolean deleteInBatch)
false, which means that
deletion occurs on a per object basis if a collection of entities is being
deleted.
If set to 'true' the elements of the payload are deleted as a batch
operation. Be aware that this exhibits issues in regards to cascaded deletes.
The specification 'JSR 317: Java Persistence API, Version 2.0' does not
support cascaded deletes in batch operations. The specification states in
chapter 4.10:
"A delete operation only applies to entities of the specified class and
its subclasses. It does not cascade to related entities."deleteInBatch - Defaults to 'false' if not set.public void setDeleteAfterPoll(boolean deleteAfterPoll)
deleteAfterPoll - Defaults to 'false'.public void setParameterSourceFactory(ParameterSourceFactory parameterSourceFactory)
parameterSourceFactory - Must not be nullpublic void setParameterSource(ParameterSource parameterSource)
ParameterSource that would be used to provide
additional parameters.parameterSource - Must not be null.public void setExpectSingleResult(boolean expectSingleResult)
true and
the result list from the JPA operations contains only 1 element, then that
1 element is extracted and returned as payload.
If the result map contains more than 1 element and
expectSingleResult is true, then a
MessagingException is thrown.
If set to false, the complete result list is returned as the
payload.public void setFirstResultExpression(org.springframework.expression.Expression firstResultExpression)
firstResultExpression - Query.setFirstResult(int)public void setMaxResultsExpression(org.springframework.expression.Expression maxResultsExpression)
maxResultsExpression - public void setMaxNumberOfResults(int maxNumberOfResults)
maxNumberOfResults - Must not be negative.Query.setMaxResults(int)public void setIntegrationEvaluationContext(org.springframework.expression.EvaluationContext evaluationContext)
setIntegrationEvaluationContext in interface IntegrationEvaluationContextAwareevaluationContext -