Class InvocationContext


  • public final class InvocationContext
    extends Object
    Contains the context of a service method execution
    • Method Detail

      • ensure

        public static InvocationContext ensure()
        Returns the current context, throwing an IllegalStateException if none
      • getApplicationContext

        public static ApplicationContext getApplicationContext()
        Returns the current application context
      • getCurrentCacheFlusher

        public static CacheFlusher getCurrentCacheFlusher()
        Returns the current CacheFlusher in the stack
      • getFormatter

        public static FormatterImpl getFormatter​(ConfigurationAccessor configuration)
        Returns a formatter which is suitable for the given configuration accessor, or null if it is to represent the current session's configuration
      • getSessionData

        public static SessionData getSessionData()
        Returns the current session data
      • markWrite

        public static void markWrite()
      • newCacheFlusher

        public static CacheFlusher newCacheFlusher()
        Creates a new CacheFlusher, keeping trace of it on a stack
      • remove

        public static void remove()
        Removes the current context
      • set

        public static void set​(InvocationContext context)
        Sets the current invocation context
      • addBeforeEndListener

        public void addBeforeEndListener​(Runnable callback)
        Adds a callback to run right before committing the current database transaction
      • addCommitListener

        public void addCommitListener​(boolean requiresTransaction,
                                      boolean afterAwakingPollingTasks,
                                      Runnable callback)
        Adds a callback to run after the current transaction commits
      • addCommitListener

        public void addCommitListener​(boolean requiresTransaction,
                                      Runnable callback)
        Adds a callback to run after the current transaction commits
      • addRollbackListener

        public void addRollbackListener​(boolean requiresTransaction,
                                        boolean afterAwakingPollingTasks,
                                        Runnable callback)
        Adds a callback to run after the current transaction rolls-back
      • addRollbackListener

        public void addRollbackListener​(boolean requiresTransaction,
                                        Runnable callback)
        Adds a callback to run after the current transaction rolls-back
      • addTransactionEndListener

        public void addTransactionEndListener​(boolean requiresTransaction,
                                              boolean afterAwakingPollingTasks,
                                              Runnable callback)
        Adds a callback both as commit and rollback listener
      • addTransactionEndListener

        public void addTransactionEndListener​(boolean requiresTransaction,
                                              Runnable callback)
        Adds a callback both as commit and rollback listener
      • awakePollingTask

        public void awakePollingTask​(PollingTask pollingTask)
        Registers the given PollingTask to be awaked when this invocation ends
      • clearAttributes

        public void clearAttributes()
      • clearCache

        public void clearCache​(CacheType<?,​?> type)
        Registers the given CacheType to be cleared when this invocation ends
      • delegateAcquiredResources

        public void delegateAcquiredResources​(InvocationContext context)
        Passes the acquired resources to the given context, so that when it is released, those resources will be released as well
      • evictCacheKeys

        public void evictCacheKeys​(CacheType<?,​?> type,
                                   Set<? extends Serializable> keys)
        Registers the given keys to be evicted from the cache described at CacheType to be cleared when this invocation ends
      • formatter

        public FormatterImpl formatter​(ConfigurationAccessor configuration)
        Returns a formatter which is suitable for the given configuration accessor, or null if it is to represent the current session's configuration
      • getAttribute

        public <T> T getAttribute​(Object key)
        Returns the value of an attribute. If is an entity, makes sure it is attached to the current entityManager
      • getAttribute

        public <T> T getAttribute​(Object key,
                                  Supplier<T> supplier)
        Returns the value of an attribute, producing it if not bound to the key
      • getEntityManager

        public javax.persistence.EntityManager getEntityManager()
        Returns the current EntityManager
      • hasLock

        public boolean hasLock​(LockKey key)
        Returns whether the current thread owns the given lock
      • hasWrite

        public boolean hasWrite()
      • isEvicted

        public boolean isEvicted​(CacheType<?,​?> type,
                                 Serializable key)
        Returns whether the given cache key has been evicted in this invocation
      • registerLock

        public void registerLock​(LockKey key)
        Registers the given lock
      • releaseAfterTransaction

        public void releaseAfterTransaction​(boolean commit)
        Releases any acquired resources. Must be invoked after the caller transaction has ended
      • releaseWithinTransaction

        public void releaseWithinTransaction()
        Releases resources which should be released while still within a transaction
      • releaseWithoutTransaction

        public void releaseWithoutTransaction()
        Releases those acquired resources when there is no transaction.
      • setAttribute

        public void setAttribute​(Object key,
                                 Object value)
      • setEntityManager

        public void setEntityManager​(javax.persistence.EntityManager entityManager)
      • setLastStoredFileContentAction

        public void setLastStoredFileContentAction​(StoredFileContentAction lastContentAction)
      • setTransactionLevel

        public void setTransactionLevel​(TransactionLevel transactionLevel)
      • setTransactionStatus

        public void setTransactionStatus​(TransactionStatus transactionStatus)