Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.cayenne.configuration
Class CayenneRuntime

    java.lang.Object
      org.apache.cayenne.configuration.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 Summary
`protected Injector` | `injector`
`protected Module[]` | `modules`
`protected static ThreadLocal<Injector>` | `threadInjector` A holder of an Injector bound to the current thread.

Constructor Summary
`CayenneRuntime(Collection<Module> modules)` Creates a CayenneRuntime with configuration based on the supplied collection of DI modules.
`CayenneRuntime(Module... modules)` Creates a CayenneRuntime with configuration based on the supplied array of DI modules.

Method Summary
`static void` | `bindThreadInjector(Injector injector)` Binds a DI `Injector` bound to the current thread.
`DataChannel` | `getChannel()` Returns the runtime `DataChannel`.
`ObjectContext` | `getContext()` Returns an ObjectContext based on the runtime DataChannel.
`ObjectContext` | `getContext(DataChannel parentChannel)` Returns an ObjectContext based on the runtime DataChannel.
`Injector` | `getInjector()` Returns DI injector used by this runtime.
`Module[]` | `getModules()` Returns an array of modules used to initialize this runtime.
`static Injector` | `getThreadInjector()` Returns the `Injector` bound to the current thread.
`protected static Module[]` | `mergeModules(Module mainModule, Collection<Module> extraModules)` Internal helper method to add special extra modules in subclass constructors.
`protected static Module[]` | `mergeModules(Module mainModule, Module... extraModules)` Internal helper method to add special extra modules in subclass constructors.
`void` | `shutdown()` Shuts down the DI injector of this runtime, giving all services that need to release some resources a chance to do that.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

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

### injector

    protected Injector injector

### modules

    protected Module[] modules

Constructor Detail

### CayenneRuntime

    public CayenneRuntime(Module... modules)

  Creates a CayenneRuntime with configuration based on the supplied array of DI modules.

### CayenneRuntime

    public 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.

  `CayenneFilter` will automatically bind the right injector to each request thread. If you are not using CayenneFilter, your application is responsible for calling this method at appropriate points of the lifecycle.

  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

### mergeModules

    protected static Module[] mergeModules(Module mainModule,
                                           Module... extraModules)

  Internal helper method to add special extra modules in subclass constructors.

### mergeModules

    protected static Module[] mergeModules(Module mainModule,
                                           Collection<Module> extraModules)

  Internal helper method to add special extra modules in subclass constructors.

### getModules

    public Module[] getModules()

  Returns an array of modules used to initialize this runtime.

### 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.

### getChannel

    public DataChannel getChannel()

  Returns the runtime `DataChannel`.

### getContext

    public ObjectContext getContext()

  Returns an ObjectContext based on the runtime DataChannel. Default configuration will return a new instance of the ObjectContext on every call, as the corresponding factory is bound using "no scope" scope. Custom modules may change this behavior.

### getContext

    public ObjectContext getContext(DataChannel parentChannel)

  Returns an ObjectContext based on the runtime DataChannel. Default configuration will return a new instance of the ObjectContext on every call, as the corresponding factory is bound using "no scope" scope. Custom modules may change this behavior.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2011 Apache Cayenne. All Rights Reserved.