Package org.apache.cayenne.runtime
Class CayenneRuntime
java.lang.Object
org.apache.cayenne.runtime.CayenneRuntime
- Direct Known Subclasses:
- ServerRuntime
Object representing Cayenne stack. Serves as an entry point to Cayenne for user applications and a factory of ObjectContexts.
 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.
 
 To create CayenneRuntime use builder available with one of the builder() methods:
 
 
 CayenneRuntime cayenneRuntime = CayenneRuntime.builder()
         .addConfig("cayenne-project.xml")
         .build();
 
 - Since:
- 3.1 is introduced, 5.0 is repurposed as a single implementation of Cayenne runtime and moved to org.apache.cayenne.runtimepackage.
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected final Injectorprotected final Collection<Module>protected static final ThreadLocal<Injector>A holder of an Injector bound to the current thread.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedCayenneRuntime(Collection<Module> modules) Creates a runtime configuring it with a standard set of services contained inCoreModule.
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidbindThreadInjector(Injector injector) Binds a DIInjectorbound to the current thread.static CayenneRuntimeBuilderbuilder()Creates a builder of CayenneRuntime.static CayenneRuntimeBuilderCreates a builder of CayenneRuntime.Returns the runtimeDataChannel.Returns the main runtime DataDomain.Returns a default DataSource for this runtime.getDataSource(String dataNodeName) Provides access to the JDBC DataSource assigned to a given DataNode.Returns DI injector used by this runtime.Returns the collection of modules used to initialize this runtime.static InjectorReturns theInjectorbound to the current thread.Returns a new ObjectContext instance based on the runtime's main DataChannel.newContext(DataChannel parentChannel) Returns a new ObjectContext which is a child of the specified DataChannel.<T> TRuns provided operation wrapped in a single transaction.<T> TperformInTransaction(TransactionalOperation<T> op, TransactionDescriptor descriptor) Runs provided operation wrapped in a single transaction.<T> TperformInTransaction(TransactionalOperation<T> op, TransactionListener callback) Runs provided operation wrapped in a single transaction.<T> TperformInTransaction(TransactionalOperation<T> op, TransactionListener callback, TransactionDescriptor descriptor) Runs provided operation wrapped in a single transaction.voidshutdown()Shuts down the DI injector of this runtime, giving all services that need to release some resources a chance to do that.
- 
Field Details- 
threadInjectorA 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
- 
modules
 
- 
- 
Constructor Details- 
CayenneRuntimeCreates a runtime configuring it with a standard set of services contained inCoreModule. CoreModule is created with one or more 'configurationLocations'. An optional array of extra modules may contain service overrides and/or user services.
 
- 
- 
Method Details- 
bindThreadInjectorBinds a DIInjectorbound to the current thread. It is primarily intended for deserialization of ObjectContexts.- Since:
- 3.1
 
- 
getThreadInjectorReturns theInjectorbound to the current thread. Will return null if none is bound.- Since:
- 3.1
 
- 
builderCreates a builder of CayenneRuntime.- Returns:
- a builder of CayenneRuntime.
- Since:
- 5.0
- See Also:
 
- 
builderCreates a builder of CayenneRuntime.- Parameters:
- name- optional symbolic name of the created runtime.
- Returns:
- a named builder of CayenneRuntime.
- Since:
- 5.0
- See Also:
 
- 
performInTransactionRuns provided operation wrapped in a single transaction. Transaction handling delegated to the internalTransactionManager. Nested calls to 'performInTransaction' are safe and attached to the same in-progress transaction. TransactionalOperation can be some arbitrary user code, which most often than not will consist of multiple Cayenne operations.- Since:
- 4.0
 
- 
performInTransactionRuns provided operation wrapped in a single transaction. Transaction handling delegated to the internalTransactionManager. Nested calls to 'performInTransaction' are safe and attached to the same in-progress transaction. TransactionalOperation can be some arbitrary user code, which most often than not will consist of multiple Cayenne operations.- Since:
- 4.0
 
- 
performInTransactionRuns provided operation wrapped in a single transaction. Transaction handling delegated to the internalTransactionManager. Nested calls to 'performInTransaction' are safe and attached to the same in-progress transaction. TransactionalOperation can be some arbitrary user code, which most often than not will consist of multiple Cayenne operations.- Type Parameters:
- T- result type
- Parameters:
- op- an operation to perform within the transaction.
- descriptor- describes additional transaction parameters
- Returns:
- a value returned by the "op" operation.
- Since:
- 4.2
 
- 
performInTransactionpublic <T> T performInTransaction(TransactionalOperation<T> op, TransactionListener callback, TransactionDescriptor descriptor) Runs provided operation wrapped in a single transaction. Transaction handling delegated to the internalTransactionManager. Nested calls to 'performInTransaction' are safe and attached to the same in-progress transaction. TransactionalOperation can be some arbitrary user code, which most often than not will consist of multiple Cayenne operations.- Type Parameters:
- T- returned value type
- Parameters:
- op- an operation to perform within the transaction.
- callback- a callback to notify as transaction progresses through stages.
- descriptor- describes additional transaction parameters
- Returns:
- a value returned by the "op" operation.
- Since:
- 4.2
 
- 
getDataDomainReturns the main runtime DataDomain. Note that by default the returned DataDomain is the same as the main DataChannel returned bygetChannel(). Although users may redefine DataChannel provider in the DI registry, for instance to decorate this DataDomain with a custom wrapper.
- 
getDataSourceReturns a default DataSource for this runtime. If no default DataSource exists, an exception is thrown.- Since:
- 4.0
 
- 
getDataSourceProvides access to the JDBC DataSource assigned to a given DataNode. A null argument will work if there's only one DataNode configured.Normally Cayenne applications don't need to access DataSource or any other JDBC code directly, however in some unusual conditions it may be needed, and this method provides a shortcut to raw JDBC. 
- 
getModulesReturns the collection of modules used to initialize this runtime.- Since:
- 4.0
 
- 
getInjectorReturns DI injector used by this runtime.
- 
shutdownShuts down the DI injector of this runtime, giving all services that need to release some resources a chance to do that.
- 
getChannelReturns the runtimeDataChannel.
- 
newContextReturns a new ObjectContext instance based on the runtime's main DataChannel.- Since:
- 4.0
 
- 
newContextReturns 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
 
 
-