Class CayenneRuntime

  • Direct Known Subclasses:
    ClientRuntime, ServerRuntime

    public abstract class CayenneRuntime
    extends Object
    A superclass of various Cayenne runtime stacks. A Runtime is the main access point to Cayenne for a user application. It provides a default Cayenne configuration as well as a way to customize this configuration via a built-in dependency injection (DI) container. In fact implementation-wise, Runtime object is just a convenience thin wrapper around a DI Injector.
    Since:
    3.1
    • Field Detail

      • threadInjector

        protected static final ThreadLocal<Injector> threadInjector
        A holder of an Injector bound to the current thread. Used mainly to allow serializable contexts to attach to correct Cayenne stack on deserialization.
        Since:
        3.1
    • Constructor Detail

      • CayenneRuntime

        protected CayenneRuntime​(Collection<Module> modules)
        Creates a CayenneRuntime with configuration based on the supplied collection of DI modules.
    • Method Detail

      • bindThreadInjector

        public static void bindThreadInjector​(Injector injector)
        Binds a DI Injector bound to the current thread. It is primarily intended for deserialization of ObjectContexts.
        Since:
        3.1
      • getThreadInjector

        public static Injector getThreadInjector()
        Returns the Injector bound to the current thread. Will return null if none is bound.
        Since:
        3.1
      • getModules

        public Collection<Module> getModules()
        Returns the collection of modules used to initialize this runtime.
        Since:
        4.0
      • getInjector

        public Injector getInjector()
        Returns DI injector used by this runtime.
      • shutdown

        @BeforeScopeEnd
        public void shutdown()
        Shuts down the DI injector of this runtime, giving all services that need to release some resources a chance to do that.
      • newContext

        public ObjectContext newContext()
        Returns a new ObjectContext instance based on the runtime's main DataChannel.
        Since:
        4.0
      • newContext

        public ObjectContext newContext​(DataChannel parentChannel)
        Returns a new ObjectContext which is a child of the specified DataChannel. This method is used for creation of nested ObjectContexts, with parent ObjectContext passed as an argument.
        Since:
        4.0