Class ServerRuntime
java.lang.Object
org.apache.cayenne.configuration.CayenneRuntime
org.apache.cayenne.configuration.server.ServerRuntime
Object representing Cayenne stack. Serves as an entry point to Cayenne for user applications and a factory of ObjectContexts.
Implementation is a thin wrapper of the dependency injection container.
The "Server" prefix in the name is in contrast to ROP "client" (that is started via ClientRuntime). So ServerRuntime is the default Cayenne stack that you should be using in all apps with the exception of client-side ROP.
- Since:
- 3.1
-
Field Summary
Fields inherited from class org.apache.cayenne.configuration.CayenneRuntime
injector, modules, threadInjector
-
Constructor Summary
ModifierConstructorDescriptionprotected
ServerRuntime
(Collection<Module> modules) Creates a server runtime configuring it with a standard set of services contained inServerModule
. -
Method Summary
Modifier and TypeMethodDescriptionstatic ServerRuntimeBuilder
builder()
Creates a builder of ServerRuntime.static ServerRuntimeBuilder
Creates a builder of ServerRuntime.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.<T> T
Runs provided operation wrapped in a single transaction.<T> T
performInTransaction
(TransactionalOperation<T> op, TransactionDescriptor descriptor) Runs provided operation wrapped in a single transaction.<T> T
performInTransaction
(TransactionalOperation<T> op, TransactionListener callback) Runs provided operation wrapped in a single transaction.<T> T
performInTransaction
(TransactionalOperation<T> op, TransactionListener callback, TransactionDescriptor descriptor) Runs provided operation wrapped in a single transaction.Methods inherited from class org.apache.cayenne.configuration.CayenneRuntime
bindThreadInjector, getChannel, getInjector, getModules, getThreadInjector, newContext, newContext, shutdown
-
Constructor Details
-
ServerRuntime
Creates a server runtime configuring it with a standard set of services contained inServerModule
. CayenneServerModule is created with one or more 'configurationLocations'. An optional array of extra modules may contain service overrides and/or user services.- Since:
- 4.0
-
-
Method Details
-
builder
Creates a builder of ServerRuntime.- Returns:
- a builder of ServerRuntime.
- Since:
- 4.0
-
builder
Creates a builder of ServerRuntime.- Parameters:
name
- optional symbolic name of the created runtime.- Returns:
- a named builder of ServerRuntime.
-
performInTransaction
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.- Since:
- 4.0
-
performInTransaction
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.- Since:
- 4.0
-
performInTransaction
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
- 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
-
performInTransaction
public <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
-
getDataDomain
Returns the main runtime DataDomain. Note that by default the returned DataDomain is the same as the main DataChannel returned byCayenneRuntime.getChannel()
. Although users may redefine DataChannel provider in the DI registry, for instance to decorate this DataDomain with a custom wrapper. -
getDataSource
Returns a default DataSource for this runtime. If no default DataSource exists, an exception is thrown.- Since:
- 4.0
-
getDataSource
Provides 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.
-