Class BaseRequest<R extends BaseRequest,T extends BaseResponse>
- All Implemented Interfaces:
com.isomorphic.base.IAutoConfigurable
,com.isomorphic.datasource.Committable
- Direct Known Subclasses:
DSRequest
,RPCRequest
DSRequest
and RPCRequest
extend this class in order to function as expected in DataSources as well as other request processing. This class was introduced together with DSTransaction
in order to ease the relationships between the request/response classes and the transaction layer.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionabstract <T extends BaseResponse>
Texecute()
Executes this request and returns a response.Frees all shared resources (for example, DataSource instances and database connections) used by this request.Returns theRequestContext
associated with this request.com.isomorphic.datasource.DSCacheManager
Returns theDSCacheManager
associated with this DSRequest, if there is one.Returns the DSTransaction associated with this request.This is an alias method forgetDSTransaction()
.Returns the RPCManager associated with this DSRequest, if there is one.boolean
Returns true if this is a request that originated from a client such as via an HTTP request.setClientRequest
(Boolean clientRequest) Used to mark this request as coming from a client.setContext
(RequestContext context) Applies aRequestContext
to this request.void
setDSCacheManager
(com.isomorphic.datasource.DSCacheManager dsCacheManager) Associates this request with the specified DSCacheManager.void
setDsTransaction
(DSTransaction dsTransaction) Sets a DSTransaction to be associated with this request.void
setDSTransaction
(DSTransaction dsTransaction) This is an alias method forsetDsTransaction(DSTransaction)
.void
setRPCManager
(RPCManager rpcManager) Associates this request with the specified RPCManager.
-
Method Details
-
execute
Executes this request and returns a response. If an application is defined for this request, the execution is dispatched through that application. Otherwise, the execution is dispatched through the DataSource layer.- Returns:
- a response that extends
BaseResponse
- Throws:
Exception
- if an error occurs during request execution
-
freeAllResources
Frees all shared resources (for example, DataSource instances and database connections) used by this request.- Returns:
- this request instance for method chaining
-
getRPCManager
Returns the RPCManager associated with this DSRequest, if there is one. Note that a DSRequest does not need to operate in the context of an RPCManager, and this method will return null unless you are running in the context of a web application. It is not recommended that you use this value for systems where there is any chance of having to operate outside of a web app, or be usable with automated test software.- Returns:
- The RPCManager to use for this request, or null if this request is not running in the context of a web application
-
getDSCacheManager
public com.isomorphic.datasource.DSCacheManager getDSCacheManager()Returns theDSCacheManager
associated with this DSRequest, if there is one. Note thatRPCManager
implementsDSCacheManager
, and if you are operating in the context of anRPCManager
(as you typically would be in a regular, client-initiated request), the RPCManager will automatically be yourDSCacheManager
. Otherwise, you can explicitly define aDSCacheManager
, either by using the DSRequest constructor that accepts a DSCacheManager (DSRequest(String, String, DSCacheManager)
), or by explicitly callingsetDSCacheManager(DSCacheManager)
(but note that the constructor is the preferred method, because cached DataSource instances are used during construction if available). The only DSCacheManager implementation in the framework other thanRPCManager
isDSTransaction
, but there is nothing to stop you creating your own implementation if you have some reason to do so.Note that a DSRequest does not need to operate in the context of an DSCacheManager, and this method will return null if none has been set. However, it is not recommended that you run a DSRequest without a DSCacheManager, especially if you have highly interconnected dataSources (eg, with lots of
includeFrom
fields), because it can lead to an explosion of creating dataSource instances that are not really needed- Returns:
- The DSCacheManager to use for this request
-
setRPCManager
Associates this request with the specified RPCManager. For hand-created requests (ie, created in your Java code with "new DSRequest()"), you need to call this method to enable Spring-based DMI and other logic that depends on the current servlet environment, and to have the request participate the current automatic transaction (if any).If you want a request to become liable to security checks you will also have to call
setClientRequest(java.lang.Boolean)
with a parameter of true.Note that there is also a convenience constructor that allows you to pass an RPCManager in during construction.
- Parameters:
rpcManager
- The RPCManager to use for this request
-
setDSCacheManager
public void setDSCacheManager(com.isomorphic.datasource.DSCacheManager dsCacheManager) Associates this request with the specified DSCacheManager. Note that there is also a constructor that allows you to pass a DSCacheManager in during construction, and you should use that constructor in preference to manually calling this method if possible. See {linkgetDSCacheManager()
for a description of why the constructor is preferred- Parameters:
dsCacheManager
- The DSCacheManager to use for this request
-
getDSTransaction
This is an alias method forgetDSTransaction()
.- Returns:
- the DSTransaction
- See Also:
-
getDsTransaction
Returns the DSTransaction associated with this request.- Returns:
- the DSTransaction
-
setDSTransaction
This is an alias method forsetDsTransaction(DSTransaction)
.- Parameters:
dsTransaction
- the DSTransaction to associate.- See Also:
-
setDsTransaction
Sets a DSTransaction to be associated with this request. The request will be added to the transaction and processed as a part of the transaction.This will also call
DSTransaction.registerRequest(BaseRequest)
in order to register this request on the transaction.- Parameters:
dsTransaction
- the DSTransaction to associate.
-
getContext
Returns theRequestContext
associated with this request.- Returns:
- the RequestContext
-
setContext
Applies aRequestContext
to this request.Normally this is taken care of for you. For examples on when you would explicitly set this please see
RequestContext
documentation.- Parameters:
context
- the RequestContext to set for this request- Returns:
- this request instance for method chaining
- See Also:
-
isClientRequest
public boolean isClientRequest()Returns true if this is a request that originated from a client such as via an HTTP request. This method is called to determine if Declarative Security checks should be made on this request.- Returns:
- true if this request originated from a client.
-
setClientRequest
Used to mark this request as coming from a client. If this is set to true the request will also be checked against Declarative Security.If this request is apart of a DSTransaction this value always take priority over any value specified using
DSTransaction.setClientRequest(Boolean)
. If you want the DSTransaction to take priority you simply leave this unset or set it to null.- Parameters:
clientRequest
- pass in true if this request originated from a client.- Returns:
- this request for method chaining.
-