Spring Integration

org.springframework.integration.jpa.core
Class DefaultJpaOperations

java.lang.Object
  extended by 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
Author:
Amol Nayak, Gunnar Hillert

Field Summary
protected  javax.persistence.EntityManager entityManager
           
 
Constructor Summary
DefaultJpaOperations()
           
 
Method Summary
 void afterPropertiesSet()
           
 void delete(java.lang.Object entity)
           
 void deleteInBatch(java.lang.Iterable<?> entities)
           
 int executeUpdate(java.lang.String updateQuery, ParameterSource source)
          Executes the given update statement and uses the given parameter source to set the required query parameters.
 int executeUpdateWithNamedQuery(java.lang.String updateQuery, ParameterSource source)
           
 int executeUpdateWithNativeQuery(java.lang.String updateQuery, ParameterSource source)
           
<T> T
find(java.lang.Class<T> entityType, java.lang.Object id)
          Find an Entity of given type with the given primary key type.
 java.util.List<?> getResultListForClass(java.lang.Class<?> entityClass, int maxNumberOfResults)
           
 java.util.List<?> getResultListForNamedQuery(java.lang.String selectNamedQuery, ParameterSource parameterSource, int maxNumberOfResults)
           
 java.util.List<?> getResultListForNativeQuery(java.lang.String selectQuery, java.lang.Class<?> entityClass, ParameterSource parameterSource, int maxNumberOfResults)
           
 java.util.List<?> getResultListForQuery(java.lang.String query, ParameterSource source)
          Executes the provided query to return a list of results
 java.util.List<?> getResultListForQuery(java.lang.String queryString, ParameterSource source, int maxNumberOfResults)
          Executes the provided query to return a list of results.
 java.lang.Object getSingleResultForQuery(java.lang.String queryString, ParameterSource source)
          Executes the provided query to return a single element
 java.lang.Object merge(java.lang.Object entity)
          The entity to be merged with the entity manager
protected  void onInit()
          Subclasses may implement this for initialization logic.
 void persist(java.lang.Object entity)
          Persists the entity
 void setEntityManager(javax.persistence.EntityManager entityManager)
           
 void setEntityManagerFactory(javax.persistence.EntityManagerFactory entityManagerFactory)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entityManager

protected javax.persistence.EntityManager entityManager
Constructor Detail

DefaultJpaOperations

public DefaultJpaOperations()
Method Detail

delete

public void delete(java.lang.Object entity)

deleteInBatch

public void deleteInBatch(java.lang.Iterable<?> entities)

executeUpdate

public int executeUpdate(java.lang.String updateQuery,
                         ParameterSource source)
Description copied from interface: JpaOperations
Executes 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

public int executeUpdateWithNamedQuery(java.lang.String updateQuery,
                                       ParameterSource source)
Returns:
The number of entities updated

executeUpdateWithNativeQuery

public int executeUpdateWithNativeQuery(java.lang.String updateQuery,
                                        ParameterSource 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: JpaOperations
Find an Entity of given type with the given primary key type.

Returns:
The entity if it exist, null is returned otherwise

getResultListForClass

public java.util.List<?> getResultListForClass(java.lang.Class<?> entityClass,
                                               int maxNumberOfResults)
Returns:
List of found entities

getResultListForNamedQuery

public java.util.List<?> getResultListForNamedQuery(java.lang.String selectNamedQuery,
                                                    ParameterSource parameterSource,
                                                    int maxNumberOfResults)
Returns:
List of found entities

getResultListForNativeQuery

public java.util.List<?> getResultListForNativeQuery(java.lang.String selectQuery,
                                                     java.lang.Class<?> entityClass,
                                                     ParameterSource parameterSource,
                                                     int maxNumberOfResults)
Returns:
List of found entities

getResultListForQuery

public java.util.List<?> getResultListForQuery(java.lang.String query,
                                               ParameterSource source)
Description copied from interface: JpaOperations
Executes the provided query to return a list of results

source - the Parameter source for this query to be executed, if none then set as null
Returns:
List of found entities

getResultListForQuery

public java.util.List<?> getResultListForQuery(java.lang.String queryString,
                                               ParameterSource source,
                                               int maxNumberOfResults)
Description copied from interface: JpaOperations
Executes the provided query to return a list of results.

Parameters:
queryString - Must not be null or empty
source - the Parameter source for this query to be executed, if none then set null
maxNumberOfResults - Must be a non-negative value
Returns:
List of found entities

getSingleResultForQuery

public java.lang.Object getSingleResultForQuery(java.lang.String queryString,
                                                ParameterSource source)
Description copied from interface: JpaOperations
Executes the provided query to return a single element

Parameters:
queryString - Must not be empty
source - 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

public java.lang.Object merge(java.lang.Object entity)
Description copied from interface: JpaOperations
The entity to be merged with the entity manager

Parameters:
entity - Must not be null.
Returns:
The merged managed instance of the entity.

persist

public void persist(java.lang.Object entity)
Description copied from interface: JpaOperations
Persists the entity

Parameters:
entity - Must not be null

setEntityManager

public void setEntityManager(javax.persistence.EntityManager entityManager)

setEntityManagerFactory

public void setEntityManagerFactory(javax.persistence.EntityManagerFactory entityManagerFactory)

afterPropertiesSet

public final void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean

onInit

protected void onInit()
Subclasses may implement this for initialization logic.


Spring Integration