Interface Context

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
ContextAdapter, ContextService

public interface Context extends AutoCloseable
The main entry point into the old persistence API.
  • Method Details

    • getPersistenceSession

      PersistenceSession getPersistenceSession()
    • getId

      String getId()
      Returns:
      The id of the context.
    • getTx

      Returns:
      The TransactionManager for this context.
    • tx

      Invoker tx()
      Returns an Invoker that runs in a transaction of this Context. If a transaction is already in progress, ane empty invoker is returned. If an exception is thrown from the invoker, the transaction will be rolled back.
    • getEntityManager

      EntityManager getEntityManager(String model)
      Parameters:
      model - The name of the entity type.
      Returns:
      The entity manager of the entity type.
    • getCacheControl

      CacheControl getCacheControl()
      Returns:
      CacheControl allows manual invalidating of cached entities.
    • compileQuery

      @Deprecated Query compileQuery(String query)
      Compile the specified query string to an executable query.
      Parameters:
      query - The query string.
      Returns:
      The executable query.
      Throws:
      CompileException - If the query strings contains errors.
    • addContextListener

      void addContextListener(ContextListener listener)
    • removeContextListener

      void removeContextListener(ContextListener listener)
    • addCommitListener

      void addCommitListener(CommitListener l)
    • removeCommitListener

      void removeCommitListener(CommitListener l)
    • suspend

      void suspend()
      Unbind the context from the current thread.
    • resume

      void resume()
      Bind the context to the current thread.
    • close

      void close()
      Specified by:
      close in interface AutoCloseable
    • isDestroyed

      boolean isDestroyed()
      Returns:
      true if the underlying Session is closed
    • isCurrent

      boolean isCurrent()
      Returns:
      true if the context is bound to the current thread.
    • checkCurrent

      void checkCurrent()
      Throws:
      IllegalStateException - If the context is not bound to the current thread.
    • setAttribute

      void setAttribute(String key, @Nullable @Nullable Object value)
    • getAttribute

      Object getAttribute(String key)
    • setQueryTimeout

      void setQueryTimeout(int queryTimeout)
    • getQueryTimeout

      @Nullable @Nullable Integer getQueryTimeout()
    • addEntityListener

      void addEntityListener(EntityListener l)
      Adds an EntityListener to be used in all EntityManagers.
    • removeEntityListener

      void removeEntityListener(EntityListener l)
      Removes an EntityListener that was added using addEntityListener(EntityListener).
    • addEntityFacadeListener

      void addEntityFacadeListener(EntityFacadeListener l)
      Adds an EntityFacadeListener to a global list of listeners that are used for all EntityManagers this context creates.
    • removeEntityFacadeListener

      void removeEntityFacadeListener(EntityFacadeListener l)
      Removes an EntityFacadeListener from the list of global listeners (previously added by addEntityFacadeListener(EntityFacadeListener)

      Be sure to perform this in a finally clause so that the remove is not skipped!

    • unwrap

      Context unwrap()
    • beginTx

      Deprecated.
      use tx()
    • clear

      void clear()
      Clear all cached data from this context. This should be used to free memory if a lot of entities are used. Depending on the implementation, the entities might become detached.
    • createSqlWriter

      SqlWriter createSqlWriter()
      Returns:
      a SqlWriter configured for the current database.
    • getPersistenceService

      PersistenceService getPersistenceService()