Interface IIvyEntityManager


public interface IIvyEntityManager
An Interface which offers all persistence methods to an process developer. This interface is similar to the EntityManager but is more easy to use. It is not necessary to begin first an transaction before persist an entity or do some other operations. This means the Transaction is managed itself by this entity manager. It also supports detached entities for all operations, the EntityManager supports only detached entities for the method EntityManager.merge(Object).

An IIvyEntityManager instance is associated with a persistence context. A persistence context is a set of entity instances in which for any persistent entity identity there is a unique entity instance. Within the persistence context, the entity instances and their lifecycle are managed. This interface defines the methods that are used to interact with the persistence context. The IIvyEntityManager API is used to create and remove persistent entity instances, to find entities by their primary key, and to query over entities.

Since:
03.04.2008
API:
This is a public API.
  • Method Summary

    Modifier and Type
    Method
    Description
    javax.persistence.EntityManager
    Create a new EntityManager.
    javax.persistence.EntityManager
    createEntityManager(Map<?,?> properties)
    Create a new EntityManager with the specified Map of properties.
    Create an instance of Query for executing a named query (in the Java Persistence query language or in native SQL).
    Create an instance of Query for executing a native SQL statement, e.g., for update or delete.
    createNativeQuery(String sqlString, Class resultClass)
    Create an instance of Query for executing a native SQL query.
    createNativeQuery(String sqlString, String resultSetMapping)
    Create an instance of Query for executing a native SQL query.
    createQuery(String qlString)
    Create an instance of Query for executing a Java Persistence query language statement.
    <T> T
    find(Class<T> entityClass, Object primaryKey)
    Find an entity by the given primary key on the database
    <T> List<T>
    findAll(Class<T> entityClass)
    Find all entities instances of the given type on the database
    <T> T
    merge(T entity)
    Merge the state of the given entity into the database
    <T> T
    persist(T entity)
    Make an entity instance persistent in the database
    <T> T
    refresh(T entity)
    Refresh the state of the instance from the database, overwriting changes made to the entity, if any.
    <T> T
    remove(T entity)
    Remove the given entity instance from the database
  • Method Details

    • find

      <T> T find(Class<T> entityClass, Object primaryKey)
      Find an entity by the given primary key on the database
      Type Parameters:
      T - the type of the entity
      Parameters:
      entityClass - the type of the entity
      primaryKey - the primary key of the entity
      Returns:
      the found entity instance or null if the entity does not exist
      Throws:
      IllegalArgumentException - if the first argument does not denote an entity type or the second argument is not a valid type for that entity's primary key
      See Also:
      • EntityManager.find(Class, Object)
      API:
      This public API is available in IvyScript and Java. It has the visibility NOVICE.
    • findAll

      <T> List<T> findAll(Class<T> entityClass)
      Find all entities instances of the given type on the database
      Type Parameters:
      T - the type of the entities
      Parameters:
      entityClass - the type of the entities
      Returns:
      a list of the found entity instances
      Throws:
      IllegalArgumentException - if the first argument does not denote an entity type
      See Also:
      • EntityManager.find(Class, Object)
      API:
      This public API is available in IvyScript and Java. It has the visibility NOVICE.
    • persist

      <T> T persist(T entity)
      Make an entity instance persistent in the database
      Type Parameters:
      T - the type of the entity
      Parameters:
      entity - the entity instance which will be persistent, this object will be directly modified
      Returns:
      the persistent entity instance, it is the same object as the given entity
      Throws:
      javax.persistence.EntityExistsException - if the entity already exists. (The EntityExistsException may be thrown when the persist operation is invoked, or the EntityExistsException or another PersistenceException may be thrown at flush or commit time.)
      IllegalArgumentException - if not an entity
      See Also:
      • EntityManager.persist(Object)
      API:
      This public API is available in IvyScript and Java. It has the visibility NOVICE.
    • merge

      <T> T merge(T entity)
      Merge the state of the given entity into the database
      Type Parameters:
      T - the type of the entity
      Parameters:
      entity - the entity instance which will be merged, this object is not changed
      Returns:
      the merged entity instance, is not the same object as the given entity
      Throws:
      IllegalArgumentException - if instance is not an entity or is a removed entity
      See Also:
      • EntityManager.merge(Object)
      API:
      This public API is available in IvyScript and Java. It has the visibility NOVICE.
    • refresh

      <T> T refresh(T entity)
      Refresh the state of the instance from the database, overwriting changes made to the entity, if any.
      Type Parameters:
      T - the type of the entity
      Parameters:
      entity - the entity instance which will be refreshed, this object will be directly modified
      Returns:
      the refreshed entity instance, it is the same object as the given entity
      Throws:
      IllegalArgumentException - if not an entity or entity is not managed
      javax.persistence.EntityNotFoundException - if the entity no longer exists in the database.
      See Also:
      • EntityManager.refresh(Object)
      API:
      This public API is available in IvyScript and Java. It has the visibility NOVICE.
    • remove

      <T> T remove(T entity)
      Remove the given entity instance from the database
      Type Parameters:
      T - the type of the entity
      Parameters:
      entity - the entity instance which will be removed, the entity is not modified
      Returns:
      the removed entity instance, the same object as the given entity
      Throws:
      IllegalArgumentException - if not an entity
      See Also:
      • EntityManager.remove(Object)
      API:
      This public API is available in IvyScript and Java. It has the visibility NOVICE.
    • createQuery

      IIvyQuery createQuery(String qlString)
      Create an instance of Query for executing a Java Persistence query language statement.
      Parameters:
      qlString - a Java Persistence query language query string
      Returns:
      the new query instance
      Throws:
      IllegalArgumentException - if query string is not valid
      API:
      This public API is available in IvyScript and Java. It has the visibility NOVICE.
    • createNamedQuery

      IIvyQuery createNamedQuery(String name)
      Create an instance of Query for executing a named query (in the Java Persistence query language or in native SQL).
      Parameters:
      name - the name of a query defined in metadata
      Returns:
      the new query instance
      Throws:
      IllegalArgumentException - if a query has not been defined with the given name
      API:
      This public API is available in IvyScript and Java. It has the visibility EXPERT.
    • createNativeQuery

      IIvyQuery createNativeQuery(String sqlString)
      Create an instance of Query for executing a native SQL statement, e.g., for update or delete.
      Parameters:
      sqlString - a native SQL query string
      Returns:
      the new query instance
      API:
      This public API is available in IvyScript and Java. It has the visibility EXPERT.
    • createNativeQuery

      IIvyQuery createNativeQuery(String sqlString, Class resultClass)
      Create an instance of Query for executing a native SQL query.
      Parameters:
      sqlString - a native SQL query string
      resultClass - the class of the resulting instance(s)
      Returns:
      the new query instance
      API:
      This public API is available in IvyScript and Java. It has the visibility EXPERT.
    • createNativeQuery

      IIvyQuery createNativeQuery(String sqlString, String resultSetMapping)
      Create an instance of Query for executing a native SQL query.
      Parameters:
      sqlString - a native SQL query string
      resultSetMapping - the name of the result set mapping
      Returns:
      the new query instance
      API:
      This public API is available in IvyScript and Java. It has the visibility EXPERT.
    • createEntityManager

      javax.persistence.EntityManager createEntityManager()
      Create a new EntityManager. This method returns a new EntityManager instance each time it is invoked. The isOpen method will return true on the returned instance.
      Returns:
      a new EntityManager instance
      See Also:
      • EntityManager
      API:
      This public API is available in IvyScript and Java. It has the visibility EXPERT.
    • createEntityManager

      javax.persistence.EntityManager createEntityManager(Map<?,?> properties)
      Create a new EntityManager with the specified Map of properties. This method returns a new EntityManager instance each time it is invoked. The isOpen method will return true on the returned instance.
      Parameters:
      properties - a map of additional properties
      Returns:
      a new EntityManager instance
      See Also:
      • EntityManager
      API:
      This public API is available in IvyScript and Java. It has the visibility EXPERT.