public abstract class BaseRequest extends Base
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.
BaseResponse
Modifier and Type | Method and Description |
---|---|
abstract BaseResponse | execute() Executes this request and returns a response. |
BaseRequest | freeAllResources() Frees all shared resources (for example, DataSource instances and database connections) used by this request. |
RequestContext | getContext() Returns the RequestContext associated with this request. |
DSCacheManager | getDSCacheManager() Returns the DSCacheManager associated with this DSRequest, if there is one. |
DSTransaction | getDsTransaction() Returns the DSTransaction associated with this request. |
DSTransaction | getDSTransaction() This is an alias method for BaseRequest.getDSTransaction() . |
RPCManager | getRPCManager() Returns the RPCManager associated with this DSRequest, if there is one. |
boolean | isClientRequest() Returns true if this is a request that originated from a client such as via an HTTP request. |
BaseRequest | setClientRequest(java.lang.Boolean clientRequest) Used to mark this request as coming from a client. |
BaseRequest | setContext(RequestContext context) Applies a RequestContext to this request. |
void | setDSCacheManager(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 for BaseRequest.setDsTransaction(DSTransaction) . |
void | setRPCManager(RPCManager rpcManager) Associates this request with the specified RPCManager. |
public abstract BaseResponse execute() throws java.lang.Exception
BaseResponse
java.lang.Exception
public BaseRequest freeAllResources()
public RPCManager getRPCManager()
public DSCacheManager getDSCacheManager()
DSCacheManager
associated with this DSRequest, if there is one. Note that RPCManager
implements DSCacheManager
, and if you are operating in the context of an RPCManager
(as you typically would be in a regular, client-initiated request), the RPCManager will automatically be your DSCacheManager
. Otherwise, you can explicitly define a DSCacheManager
, either by using the DSRequest constructor that accepts a DSCacheManager (DSRequest(String, String, DSCacheManager)
), or by explicitly calling BaseRequest.setDSCacheManager(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 than RPCManager
is DSTransaction
, 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
public void setRPCManager(RPCManager rpcManager)
If you want a request to become liable to security checks you will also have to call BaseRequest.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.
rpcManager
- The RPCManager to use for this requestpublic void setDSCacheManager(DSCacheManager dsCacheManager)
BaseRequest.getDSCacheManager()
for a description of why the constructor is preferreddsCacheManager
- The DSCacheManager to use for this requestpublic DSTransaction getDSTransaction()
BaseRequest.getDSTransaction()
.BaseRequest.getDsTransaction()
public DSTransaction getDsTransaction()
public void setDSTransaction(DSTransaction dsTransaction)
BaseRequest.setDsTransaction(DSTransaction)
.dsTransaction
- the DSTransaction to associate.BaseRequest.setDsTransaction(DSTransaction)
public void setDsTransaction(DSTransaction dsTransaction)
This will also call DSTransaction.registerRequest(BaseRequest)
in order to register this request on the transaction.
dsTransaction
- the DSTransaction to associate.public RequestContext getContext()
RequestContext
associated with this request.public BaseRequest setContext(RequestContext context)
RequestContext
to this request. Normally this is taken care of for you. For examples on when you would explicitly set this please see RequestContext
documentation.
context
- the RequestContext to set on this request.RequestContext.instance(Servlet, HttpServletRequest, HttpServletResponse)
public boolean isClientRequest()
public BaseRequest setClientRequest(java.lang.Boolean clientRequest)
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.
clientRequest
- pass in true if this request originated from a client.