public class JpaExecutor extends Object implements InitializingBean, BeanFactoryAware
Message payload.idExpression| Constructor and Description |
|---|
JpaExecutor(EntityManager entityManager)
Constructor taking an
EntityManager directly. |
JpaExecutor(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()
Verify and sets the parameters.
|
protected List<?> |
doPoll(ParameterSource jpaQLParameterSource,
int firstResult,
int maxNumberOfResults) |
Object |
executeOutboundJpaOperation(Message<?> message)
Execute the actual Jpa Operation.
|
Object |
poll()
Execute the JPA operation.
|
Object |
poll(Message<?> requestMessage)
Execute a (typically retrieving) JPA operation.
|
void |
setBeanFactory(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(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(Expression firstResultExpression)
Set 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 |
setIdExpression(Expression idExpression)
Set the expression that will be evaluated to get the
primaryKey for
EntityManager.find(Class, Object) |
void |
setIntegrationEvaluationContext(EvaluationContext evaluationContext) |
void |
setJpaParameters(List<JpaParameter> jpaParameters) |
void |
setJpaQuery(String jpaQuery) |
void |
setMaxNumberOfResults(int maxNumberOfResults)
Set the max number of results to retrieve from the database.
|
void |
setMaxResultsExpression(Expression maxResultsExpression)
Set the expression for maximum number of results expression.
|
void |
setNamedQuery(String namedQuery)
A named query can either refer to a named JPQL based query or a native SQL
query.
|
void |
setNativeQuery(String nativeQuery)
You can also use native Sql queries to poll data from the database.
|
void |
setParameterSource(ParameterSource parameterSource)
Specify the
ParameterSource that would be used to provide
additional parameters. |
void |
setParameterSourceFactory(ParameterSourceFactory parameterSourceFactory) |
void |
setPersistMode(PersistMode persistMode) |
void |
setUsePayloadAsParameterSource(Boolean usePayloadAsParameterSource) |
public JpaExecutor(EntityManagerFactory entityManagerFactory)
EntityManagerFactory from which the
EntityManager can be obtained.entityManagerFactory - Must not be null.public JpaExecutor(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 setIntegrationEvaluationContext(EvaluationContext evaluationContext)
public void setEntityClass(Class<?> entityClass)
entityClass - Must not be null.public void setJpaQuery(String jpaQuery)
jpaQuery - The provided JPA query must neither be null nor empty.public void setNativeQuery(String nativeQuery)
nativeQuery - The provided SQL query must neither be null nor empty.public void setNamedQuery(String namedQuery)
namedQuery - Must neither be null nor emptypublic void setPersistMode(PersistMode persistMode)
public void setJpaParameters(List<JpaParameter> jpaParameters)
public void setUsePayloadAsParameterSource(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.
expectSingleResult - true if a single object is expected.public void setFirstResultExpression(Expression firstResultExpression)
firstResultExpression - The first result expression.Query.setFirstResult(int)public void setIdExpression(Expression idExpression)
primaryKey for
EntityManager.find(Class, Object)idExpression - the SpEL expression for entity primaryKey.public void setMaxResultsExpression(Expression maxResultsExpression)
maxResultsExpression - The maximum results expression.public void setMaxNumberOfResults(int maxNumberOfResults)
maxNumberOfResults - Must not be negative.Query.setMaxResults(int)public void setBeanFactory(BeanFactory beanFactory) throws BeansException
setBeanFactory in interface BeanFactoryAwareBeansExceptionpublic void afterPropertiesSet()
ParameterSourceFactory.afterPropertiesSet in interface InitializingBeanpublic Object executeOutboundJpaOperation(Message<?> message)
Keep in mind that the number of entities effected by the operation may not necessarily correlate with the number of rows effected in the database.
message - The message.@Nullable public Object poll()
poll(Message).@Nullable public Object poll(@Nullable Message<?> requestMessage)
parameterSourceFactory. If the
requestMessage parameter is null then
parameterSource is being used for providing query parameters.requestMessage - May be null.protected List<?> doPoll(ParameterSource jpaQLParameterSource, int firstResult, int maxNumberOfResults)