Spring Integration

org.springframework.integration.jpa.core
Class JpaExecutor

java.lang.Object
  extended by org.springframework.integration.jpa.core.JpaExecutor
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean

public class JpaExecutor
extends java.lang.Object
implements org.springframework.beans.factory.InitializingBean

Executes Jpa Operations that produce payload objects from the result of the provided:

When objects are being retrieved, it also possibly to: If neither entityClass nor any other query is specified then the entity-class is "guessed" from the Message payload.

Since:
2.2
Author:
Gunnar Hillert

Constructor Summary
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.
 
Method Summary
 void afterPropertiesSet()
          Verifies and sets the parameters.
protected  java.util.List<?> doPoll(ParameterSource jpaQLParameterSource)
           
 java.lang.Object executeOutboundJpaOperation(Message<?> message)
          Executes the actual Jpa Operation.
 java.lang.Object poll()
          Execute the JPA operation.
 java.lang.Object poll(Message<?> requestMessage)
          Execute a (typically retrieving) JPA operation.
 void setDeleteAfterPoll(boolean deleteAfterPoll)
          If set to 'true', the retrieved objects are deleted from the database upon being polled.
 void setDeletePerRow(boolean deletePerRow)
          If not set, this property default to 'true', which means that deletion occur on a per object basis.
 void setEntityClass(java.lang.Class<?> entityClass)
          Sets the class type which is being used to poll the database or to also update the persistence store.
 void setExpectSingleResult(boolean expectSingleResult)
           
 void setJpaParameters(java.util.List<JpaParameter> jpaParameters)
           
 void setJpaQuery(java.lang.String jpaQuery)
           
 void setMaxRows(int maxNumberOfResults)
           
 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)
           
 void setParameterSourceFactory(ParameterSourceFactory parameterSourceFactory)
           
 void setPersistMode(PersistMode persistMode)
           
 void setUsePayloadAsParameterSource(java.lang.Boolean usePayloadAsParameterSource)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JpaExecutor

public JpaExecutor(javax.persistence.EntityManagerFactory entityManagerFactory)
Constructor taking an EntityManagerFactory from which the EntityManager can be obtained.

Parameters:
entityManagerFactory - Must not be null.

JpaExecutor

public JpaExecutor(javax.persistence.EntityManager entityManager)
Constructor taking an EntityManager directly.

Parameters:
entityManager - Must not be null.

JpaExecutor

public JpaExecutor(JpaOperations jpaOperations)
If custom behavior is required a custom implementation of JpaOperations can be passed in. The implementations themselves typically provide access to the EntityManager. See also DefaultJpaOperations and AbstractJpaOperations.

Parameters:
jpaOperations - Must not be null.
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
Verifies and sets the parameters. E.g. initializes the to be used ParameterSourceFactory.

Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean

executeOutboundJpaOperation

public java.lang.Object executeOutboundJpaOperation(Message<?> message)
Executes the actual Jpa Operation. Call this method, if you need access to process return values. This methods return a Map that contains either the number of affected entities or the affected entity itself. 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.

Parameters:
message -
Returns:
Either the number of affected entities when using a JPAQL query. When using a merge/persist the updated/inserted itself is returned.

poll

public java.lang.Object poll(Message<?> requestMessage)
Execute a (typically retrieving) JPA operation. The requestMessage can be used to provide additional query parameters using JpaExecutor#parameterSourceFactorymeterSourceFactory. If the requestMessage parameter is null then parameterSource is being used for providing query parameters.

Parameters:
requestMessage - May be null.
Returns:
The payload object, which may be null.

poll

public java.lang.Object poll()
Execute the JPA operation. Delegates to poll(Message).


doPoll

protected java.util.List<?> doPoll(ParameterSource jpaQLParameterSource)

setEntityClass

public void setEntityClass(java.lang.Class<?> entityClass)
Sets the class type which is being used to poll the database or to also update the persistence store.

Parameters:
entityClass - Must not be null.

setJpaQuery

public void setJpaQuery(java.lang.String jpaQuery)
Parameters:
jpaQuery - The provided JPA query must neither be null nor empty.

setNativeQuery

public void setNativeQuery(java.lang.String nativeQuery)
You can also use native Sql queries to poll data from the database. If set this property will allow you to use native SQL. Optionally you can also set the entityClass property at the same time. If specified the entityClass will be used as the result class for the native query.

Parameters:
nativeQuery - The provided SQL query must neither be null nor empty.

setNamedQuery

public void setNamedQuery(java.lang.String namedQuery)
A named query can either refer to a named JPQL based query or a native SQL query.

Parameters:
namedQuery - Must neither be null nor empty

setPersistMode

public void setPersistMode(PersistMode persistMode)

setJpaParameters

public void setJpaParameters(java.util.List<JpaParameter> jpaParameters)

setUsePayloadAsParameterSource

public void setUsePayloadAsParameterSource(java.lang.Boolean usePayloadAsParameterSource)

setDeletePerRow

public void setDeletePerRow(boolean deletePerRow)
If not set, this property default to 'true', which means that deletion occur on a per object basis. If set to 'false' the elements of the payload are deleted as a batch operation. Be aware that this exhibit issues in regards to cascaded deletes. //TODO further information needed

Parameters:
deletePerRow - Defaults to 'true'.

setDeleteAfterPoll

public void setDeleteAfterPoll(boolean deleteAfterPoll)
If set to 'true', the retrieved objects are deleted from the database upon being polled. May not work in all situations, e.g. for Native SQL Queries.

Parameters:
deleteAfterPoll - Defaults to 'false'.

setMaxRows

public void setMaxRows(int maxNumberOfResults)
Parameters:
maxNumberOfResults - Must not be negative.

setParameterSourceFactory

public void setParameterSourceFactory(ParameterSourceFactory parameterSourceFactory)
Parameters:
parameterSourceFactory -

setParameterSource

public void setParameterSource(ParameterSource parameterSource)
Parameters:
parameterSource -

setExpectSingleResult

public void setExpectSingleResult(boolean expectSingleResult)

Spring Integration