Class BaseRequest<R extends BaseRequest,T extends BaseResponse>

java.lang.Object
com.isomorphic.base.Base
com.isomorphic.rpc.BaseRequest<R,T>
All Implemented Interfaces:
com.isomorphic.base.IAutoConfigurable, com.isomorphic.datasource.Committable
Direct Known Subclasses:
DSRequest, RPCRequest

public abstract class BaseRequest<R extends BaseRequest,T extends BaseResponse> extends com.isomorphic.base.Base implements com.isomorphic.datasource.Committable
This is the base for all requests going through the rpc and DataSource layer in Smartclient Server. Both 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 Details

    • execute

      public abstract <T extends BaseResponse> T execute() throws Exception
      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

      public R freeAllResources()
      Frees all shared resources (for example, DataSource instances and database connections) used by this request.
      Returns:
      this request instance for method chaining
    • getRPCManager

      public RPCManager 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 the 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 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

      Returns:
      The DSCacheManager to use for this request
    • setRPCManager

      public void setRPCManager(RPCManager rpcManager)
      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 {link getDSCacheManager() for a description of why the constructor is preferred
      Parameters:
      dsCacheManager - The DSCacheManager to use for this request
    • getDSTransaction

      public DSTransaction getDSTransaction()
      This is an alias method for getDSTransaction().
      Returns:
      the DSTransaction
      See Also:
    • getDsTransaction

      public DSTransaction getDsTransaction()
      Returns the DSTransaction associated with this request.
      Returns:
      the DSTransaction
    • setDSTransaction

      public void setDSTransaction(DSTransaction dsTransaction)
      This is an alias method for setDsTransaction(DSTransaction).
      Parameters:
      dsTransaction - the DSTransaction to associate.
      See Also:
    • setDsTransaction

      public void setDsTransaction(DSTransaction dsTransaction)
      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

      public RequestContext getContext()
      Returns the RequestContext associated with this request.
      Returns:
      the RequestContext
    • setContext

      public R setContext(RequestContext context)
      Applies a 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.

      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

      public R setClientRequest(Boolean clientRequest)
      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.