Class DefaultJpaOperations

java.lang.Object
org.springframework.integration.jpa.core.DefaultJpaOperations
All Implemented Interfaces:
InitializingBean, JpaOperations

public class DefaultJpaOperations extends 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, Artem Bilan
  • Constructor Details

    • DefaultJpaOperations

      public DefaultJpaOperations()
  • Method Details

    • delete

      public void delete(Object entity)
      Parameters:
      entity - The entity to delete.
    • deleteInBatch

      public void deleteInBatch(Iterable<?> entities)
      Parameters:
      entities - The entities to delete.
    • executeUpdate

      public int executeUpdate(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(String updateQuery, ParameterSource source)
      Parameters:
      updateQuery - The update query.
      source - The parameter source.
      Returns:
      The number of entities updated.
    • executeUpdateWithNativeQuery

      public int executeUpdateWithNativeQuery(String updateQuery, ParameterSource source)
      Parameters:
      updateQuery - The update query.
      source - The parameter source.
      Returns:
      The number of entities updated
    • find

      public <T> T find(Class<T> entityType, Object id)
      Description copied from interface: JpaOperations
      Find 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 List<?> getResultListForClass(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 List<?> getResultListForNamedQuery(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 List<?> getResultListForNativeQuery(String selectQuery, @Nullable 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

      public List<?> getResultListForQuery(String query, ParameterSource source)
      Description copied from interface: JpaOperations
      Execute 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 List<?> getResultListForQuery(String queryString, ParameterSource source, int firstResult, 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.
      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 Object getSingleResultForQuery(String queryString, ParameterSource source)
      Description copied from interface: JpaOperations
      Execute 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

      @Nullable public Object merge(Object entity)
      Description copied from interface: JpaOperations
      The entity to be merged with the EntityManager. The provided object can also be an Iterable in which case each object of the Iterable is treated as an entity and merged with the EntityManager. Null values returned while iterating over the Iterable are ignored.
      Parameters:
      entity - Must not be null.
      Returns:
      The merged managed instance of the entity.
    • merge

      @Nullable public Object merge(Object entity, int flushSize, boolean clearOnFlush)
      Description copied from interface: JpaOperations
      The entity to be merged with the EntityManager. The provided object can also be an Iterable in which case each object of the Iterable is treated as an entity and merged with the EntityManager. In addition the EntityManager.flush() is called after the merge and after each batch, as it is specified using flushSize parameter and if provided object is Iterable. clearOnFlush parameter specifies, if the EntityManager.clear() should be called after each EntityManager.flush().
      Parameters:
      entity - The entity.
      flushSize - The flush size.
      clearOnFlush - true to clear after flushing.
      Returns:
      The merged object.
    • persist

      public void persist(Object entity)
      Description copied from interface: JpaOperations
      Persists the entity. The provided object can also be an Iterable in which case each object of the Iterable is treated as an entity and persisted with the EntityManager. Null values returned while iterating over the Iterable are ignored.
      Parameters:
      entity - Must not be null
    • persist

      public void persist(Object entity, int flushSize, boolean clearOnFlush)
      Description copied from interface: JpaOperations
      Persists the entity. The provided object can also be an Iterable in which case each object of the Iterable is treated as an entity and persisted with the EntityManager. Null values returned while iterating over the Iterable are ignored. In addition the EntityManager.flush() is called after the persist and after each batch, as it is specified using flushSize parameter and if provided object is Iterable. clearOnFlushparameter specifies, if the EntityManager.clear() should be called after each EntityManager.flush().
      Parameters:
      entity - The entity.
      flushSize - The flush size.
      clearOnFlush - true to clear after flushing.
    • setEntityManager

      public void setEntityManager(EntityManager entityManager)
    • getEntityManager

      protected EntityManager getEntityManager()
    • setEntityManagerFactory

      public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory)
    • afterPropertiesSet

      public final void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface InitializingBean
    • onInit

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

      public void flush()
      Description copied from interface: JpaOperations
      Specified by:
      flush in interface JpaOperations