Class EntityManagerImpl

java.lang.Object
cz.cvut.kbss.jopa.model.EntityManagerImpl
All Implemented Interfaces:
AbstractEntityManager, EntityManager, ConfigurationHolder, Wrapper, AutoCloseable

public class EntityManagerImpl extends Object implements AbstractEntityManager, Wrapper
  • Method Details

    • persist

      public void persist(Object entity)
      Description copied from interface: EntityManager
      Make an instance managed and persistent.

      The entity is persisted into the default context.

      Specified by:
      persist in interface EntityManager
      Parameters:
      entity - entity instance
      See Also:
    • persist

      public void persist(Object entity, Descriptor descriptor)
      Description copied from interface: EntityManager
      Make an instance managed and persistent.

      The descriptor represents repository and context into which the entity and its fields should be persisted.

      Specified by:
      persist in interface EntityManager
      Parameters:
      entity - entity instance
      descriptor - Entity descriptor
    • merge

      public <T> T merge(T entity)
      Description copied from interface: EntityManager
      Merge the state of the given entity into the current persistence context.

      The entity is merged into the default repository context.

      Specified by:
      merge in interface EntityManager
      Parameters:
      entity - The entity to merge
      Returns:
      the instance that the state was merged to
    • merge

      public <T> T merge(T entity, Descriptor descriptor)
      Description copied from interface: EntityManager
      Merge the state of the given entity into the current persistence context and into the repository specified by descriptor.
      Specified by:
      merge in interface EntityManager
      Parameters:
      entity - The entity to merge
      descriptor - Entity descriptor
      Returns:
      the instance that the state was merged to
    • remove

      public void remove(Object entity)
      Description copied from interface: EntityManager
      Remove the entity instance.
      Specified by:
      remove in interface EntityManager
      Parameters:
      entity - The instance to remove
    • find

      public <T> T find(Class<T> cls, Object identifier)
      Description copied from interface: EntityManager
      Find by identifier.

      Search for an entity of the specified class and identifier. If the entity instance is contained in the persistence context, it is returned from there.

      Specified by:
      find in interface EntityManager
      Parameters:
      cls - Entity class
      identifier - Entity identifier
      Returns:
      the found entity instance or null if the entity does not exist in the given ontology context
    • find

      public <T> T find(Class<T> cls, Object identifier, Descriptor descriptor)
      Description copied from interface: EntityManager
      Find by identifier.

      Search for an entity of the specified class and identifier. If the entity instance is contained in the persistence context, it is returned from there.

      The descriptor parameter represents repository and context in which the entity should be looked for.

      Specified by:
      find in interface EntityManager
      Parameters:
      cls - Entity class
      identifier - Entity identifier
      descriptor - Entity descriptor
      Returns:
      the found entity instance or null if the entity does not exist in the given ontology context
      See Also:
    • getReference

      public <T> T getReference(Class<T> entityClass, Object identifier)
      Description copied from interface: EntityManager
      Get an instance, whose state may be lazily fetched.

      If the requested instance does not exist in the database, the EntityNotFoundException is thrown when the instance state is first accessed. (The persistence provider runtime is permitted to throw the EntityNotFoundException when getReference is called.)

      The application should not expect that the instance state will be available upon detachment, unless it was accessed by the application while the entity manager was open.

      Specified by:
      getReference in interface EntityManager
      Parameters:
      entityClass - entity class
      identifier - identifier of the instance
      Returns:
      the found entity instance
    • getReference

      public <T> T getReference(Class<T> entityClass, Object identifier, Descriptor descriptor)
      Description copied from interface: EntityManager
      Get an instance, whose state may be lazily fetched.

      If the requested instance does not exist in the database, the EntityNotFoundException is thrown when the instance state is first accessed. (The persistence provider runtime is permitted to throw the EntityNotFoundException when getReference is called.)

      The application should not expect that the instance state will be available upon detachment, unless it was accessed by the application while the entity manager was open.

      The descriptor parameter represents configuration of the entity loading (e.g., repository context).

      Specified by:
      getReference in interface EntityManager
      Parameters:
      entityClass - entity class
      identifier - identifier of the instance
      descriptor - Entity descriptor
      Returns:
      the found entity instance
    • flush

      public void flush()
      Description copied from interface: EntityManager
      Synchronize the persistence context to the underlying database.
      Specified by:
      flush in interface EntityManager
    • refresh

      public void refresh(Object entity)
      Description copied from interface: EntityManager
      Refresh the state of the instance from the data source, overwriting changes made to the entity, if any.
      Specified by:
      refresh in interface EntityManager
      Parameters:
      entity - The entity instance to refresh
    • clear

      public void clear()
      Description copied from interface: EntityManager
      Clear the persistence context, causing all managed entities to become detached. Changes made to entities that have not been flushed to the database will not be persisted.
      Specified by:
      clear in interface EntityManager
    • detach

      public void detach(Object entity)
      Description copied from interface: EntityManager
      Remove the given entity from the persistence context, causing a managed entity to become detached. Unflushed changes made to the entity if any (including removal of the entity), will not be synchronized to the database. Entities which previously referenced the detached entity will continue to reference it.
      Specified by:
      detach in interface EntityManager
      Parameters:
      entity - The instance to detach
    • contains

      public boolean contains(Object entity)
      Description copied from interface: EntityManager
      Check if the instance belongs to the current persistence context.
      Specified by:
      contains in interface EntityManager
      Parameters:
      entity - The instance to check
      Returns:
      True if the instance is managed, false otherwise
    • close

      public void close()
      Description copied from interface: EntityManager
      Close an application-managed EntityManager. After the close method has been invoked, all methods on the EntityManager instance and any Query objects obtained from it will throw the IllegalStateException except for getTransaction and isOpen (which will return false). If this method is called when the EntityManager is associated with an active transaction, the persistence context remains managed until the transaction completes.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface EntityManager
    • isOpen

      public boolean isOpen()
      Description copied from interface: EntityManager
      Determine whether the EntityManager is open.
      Specified by:
      isOpen in interface EntityManager
      Returns:
      true until the EntityManager has been closed.
    • getTransaction

      public EntityTransaction getTransaction()
      Description copied from interface: EntityManager
      Return the resource-level transaction object. The EntityTransaction instance may be used serially to begin and commit multiple transactions.
      Specified by:
      getTransaction in interface EntityManager
      Returns:
      EntityTransaction instance
    • getEntityManagerFactory

      public EntityManagerFactoryImpl getEntityManagerFactory()
      Description copied from interface: EntityManager
      Return the entity manager factory for the entity manager.
      Specified by:
      getEntityManagerFactory in interface EntityManager
      Returns:
      EntityManagerFactory instance
    • getMetamodel

      public Metamodel getMetamodel()
      Description copied from interface: EntityManager
      Return an instance of Metamodel interface for access to the metamodel of the persistence unit.
      Specified by:
      getMetamodel in interface EntityManager
      Returns:
      Metamodel instance
    • isLoaded

      public boolean isLoaded(Object object, String attributeName)
      Specified by:
      isLoaded in interface AbstractEntityManager
    • isLoaded

      public boolean isLoaded(Object object)
      Specified by:
      isLoaded in interface AbstractEntityManager
    • createQuery

      public QueryImpl createQuery(String qlString)
      Description copied from interface: EntityManager
      Create an instance of Query for executing a Java Persistence query language statement.
      Specified by:
      createQuery in interface EntityManager
      Parameters:
      qlString - a Java Persistence query string
      Returns:
      the new query instance
    • createQuery

      public <T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery)
      Description copied from interface: EntityManager
      Create an instance of TypedQuery for executing a criteria query.
      Specified by:
      createQuery in interface EntityManager
      Parameters:
      criteriaQuery - criteria query object
      Returns:
      the new query instance
    • createQuery

      public <T> TypedQueryImpl<T> createQuery(String query, Class<T> resultClass)
      Description copied from interface: EntityManager
      Creates an instance of query for executing Java persistence query language statement.
      Specified by:
      createQuery in interface EntityManager
      Parameters:
      query - query string
      resultClass - result type
      Returns:
      the new query instance
    • createNativeQuery

      public QueryImpl createNativeQuery(String sparqlString)
      Description copied from interface: EntityManager
      Create an instance of Query for executing a native SPARQL(-DL) query in SPARQL syntax.
      Specified by:
      createNativeQuery in interface EntityManager
      Parameters:
      sparqlString - a native SPARQL query string
      Returns:
      the new query instance
    • createNativeQuery

      public <T> TypedQueryImpl<T> createNativeQuery(String sparqlString, Class<T> resultClass)
      Description copied from interface: EntityManager
      Create an instance of Query for executing a native SPARQL(-DL) query returning only specific object type.
      Specified by:
      createNativeQuery in interface EntityManager
      Parameters:
      sparqlString - a native SQL query string
      resultClass - the class of the resulting instance(s)
      Returns:
      the new query instance
    • createNativeQuery

      public QueryImpl createNativeQuery(String sparqlString, String resultSetMapping)
      Description copied from interface: EntityManager
      Create an instance of Query for executing a native SPARQL query.
      Specified by:
      createNativeQuery in interface EntityManager
      Parameters:
      sparqlString - a native SQL query string
      resultSetMapping - the name of the result set mapping
      Returns:
      the new query instance
    • createNamedQuery

      public QueryImpl createNamedQuery(String name)
      Description copied from interface: EntityManager
      Create an instance of Query for executing a named query (in native SPARQL).
      Specified by:
      createNamedQuery in interface EntityManager
      Parameters:
      name - the name of a query defined in metadata
      Returns:
      the new query instance
    • createNamedQuery

      public <T> TypedQueryImpl<T> createNamedQuery(String name, Class<T> resultClass)
      Description copied from interface: EntityManager
      Create an instance of TypedQuery for executing a SPARQL named query.

      The select list of the query must contain only a single item, which must be assignable to the type specified by the resultClass argument.

      Specified by:
      createNamedQuery in interface EntityManager
      Parameters:
      name - the name of a query defined in metadata
      resultClass - the type of the query result
      Returns:
      the new query instance
    • isConsistent

      public boolean isConsistent(URI context)
      Description copied from interface: EntityManager
      Checks consistency of the specified context.

      The context URI can be null, which indicates that consistency of the whole repository should be verified.

      Specified by:
      isConsistent in interface EntityManager
      Parameters:
      context - Context URI, can be null
      Returns:
      true if consistent, false otherwise
    • getContexts

      public List<URI> getContexts()
      Description copied from interface: EntityManager
      Returns a list of repository contexts available to this entity manager.
      Specified by:
      getContexts in interface EntityManager
      Returns:
      List of repository context URIs
    • isInferred

      public <T> boolean isInferred(T entity, FieldSpecification<? super T,?> attribute, Object value)
      Description copied from interface: EntityManager
      Checks whether the specified attribute value of the specified entity is inferred in the underlying repository.

      Note that given the nature of the repository implementation, this method may return true if the corresponding statement is both inferred and asserted. Also note that this method will use the descriptor associated with the specified entity in this persistence context to resolve the repository context, but some underlying repositories do not store inferences in data contexts, so the attribute context may be ignored.

      Specified by:
      isInferred in interface EntityManager
      Parameters:
      entity - Entity whose attribute to examine. Must be managed by this persistence context
      attribute - Attribute whose value to examine
      value - The value whose inference to examine
      Returns:
      true if the entity attribute value is inferred, false otherwise
    • getCriteriaBuilder

      public CriteriaBuilder getCriteriaBuilder()
      Description copied from interface: EntityManager
      Return a criteriaFactory for making CriteriaQuery.
      Specified by:
      getCriteriaBuilder in interface EntityManager
      Returns:
      CriteriaBuilder instance
    • unwrap

      public <T> T unwrap(Class<T> cls)
      Description copied from interface: EntityManager
      Return an object of the specified type to allow access to the provider-specific API. If the provider's EntityManager implementation does not support the specified class, the OWLPersistenceException is thrown.
      Specified by:
      unwrap in interface EntityManager
      Specified by:
      unwrap in interface Wrapper
      Parameters:
      cls - The class of the object to be returned. This can be also an implementation of the underlying driver
      Returns:
      an instance of the specified class
    • getDelegate

      public EntityManagerImpl getDelegate()
      Description copied from interface: EntityManager
      Return the underlying provider object for the EntityManager, if available. The result of this method is implementation specific.
      Specified by:
      getDelegate in interface EntityManager
      Returns:
      underlying provider object for EntityManager
    • finalize

      protected void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • getCurrentPersistenceContext

      public UnitOfWork getCurrentPersistenceContext()
      Description copied from interface: AbstractEntityManager
      Return the UnitOfWork that holds the current persistence context.
      Specified by:
      getCurrentPersistenceContext in interface AbstractEntityManager
      Returns:
      UnitOfWork
    • removeCurrentPersistenceContext

      public void removeCurrentPersistenceContext()
      Called from EntityTransaction in case of a rollback. Releasing the UoW is up to the EntityTransaction.
      Specified by:
      removeCurrentPersistenceContext in interface AbstractEntityManager
    • transactionStarted

      public void transactionStarted(EntityTransaction t)
      Description copied from interface: AbstractEntityManager
      Let the managing server session know that a transaction has been started.
      Specified by:
      transactionStarted in interface AbstractEntityManager
      Parameters:
      t - The entity transaction that was started.
    • transactionFinished

      public void transactionFinished(EntityTransaction t)
      Description copied from interface: AbstractEntityManager
      Let the managing server session know that a transaction has finished successfully.
      Specified by:
      transactionFinished in interface AbstractEntityManager
      Parameters:
      t - The committed entity transaction.
    • getConfiguration

      public Configuration getConfiguration()
      Description copied from interface: ConfigurationHolder
      Gets provider configuration.
      Specified by:
      getConfiguration in interface ConfigurationHolder
      Returns:
      Configuration
    • getProperties

      public Map<String,Object> getProperties()
      Description copied from interface: EntityManager
      Get the properties and hints and associated values that are in effect for the entity manager.

      Changing the contents of the map does not change the configuration in effect.

      Specified by:
      getProperties in interface EntityManager
      Returns:
      Map of properties and hints in effect for entity manager
    • setProperty

      public void setProperty(String propertyName, Object value)
      Description copied from interface: EntityManager
      Set an entity manager property or hint.

      If a vendor-specific property or hint is not recognized, it is silently ignored.

      Specified by:
      setProperty in interface EntityManager
      Parameters:
      propertyName - Name of property or hint
      value - Value for property or hint
    • createDescriptor

      public Descriptor createDescriptor(Class<?> cls)
      Description copied from interface: EntityManager
      Creates a Descriptor for instances of the specified entity class.
      Specified by:
      createDescriptor in interface EntityManager
      Parameters:
      cls - Entity class to create descriptor for
      Returns:
      Entity descriptor