DatabaseRequest

This is the key class that accepts the details of the request. The request in itself is considered to have the following:

  • A locator for narrowing down to the exact DML that needs to be executed
  • Ability to pass the necessary information related to the DML execution,such as filters, sort, pagination model
  • Indicate logical data sources (not to be confused with JNDI Data sources)
  • Indicate the Data Access Layer implementation that needs to be used.


A DML Locator is considered as a combination of the following parameters:

  • Data Access Map Key – This is nothing but the key that along with the operation should help identify the actual DML. In many cases, this could effectively narrow down to an SQL statement or may only still be a broad categorization (like a module or a feature). This is mandatory.
  • Operation - The operation that you are looking to execute (one of the DatabaseConstants provided above). This is mandatory.
  • Operation Extension – This is an additional string that could be used for sub-classification within a Data Access Map Key. For example, if the Data Access Map Key is used as a module name, then this can be used for the specific SQL within that module and so on. This is optional.


This combination provides tremendous flexibility in modeling the various DMLs used within the application. In case for your application, the needs are simple, you can ignore the Operation Extension and use only the Data Access Map Key and the Operation (which is mandatory anyway).


How the exact locator logic is used based on these three parameters is specific to the Data Access Layer. And this is where the flexibility is provided for the Data Access Layer implementation to use the parameters as appropriate.


The default iBATIS Data Access Manager interprets the locator as –follows:
<Data Access Map Key><Operation><Operation Extension> 


This locator pattern is used for identifying a SQL Map from the iBATIS configuration XML and the SQL Map is used for executing the operation requested for.


The key attributes provided by a DatabaseRequest are provided –in the following table:

Attribute or Operation

Purpose

int startRowNo;

This sets the starting row number for Pagination purposes

int endRowNo;

This sets the ending row number for Pagination purposes

PaginationModel paginationModel;

This sets the starting and ending row number for Pagination purposes using PaginationModel Object

SortingModel sortingModel;

This sets the sorting conditions that should be applied to the DML using the SortingModel Object

String dataAccessMapKey;

This sets the Data Access Map Key that is part of the DML Locator

int operation;

This sets the operation to be executed. This has to one of the constants from DatabaseConstants.

String operationExtension;

This sets the operation extension that is part of the DML Locator

String dataSource;

This sets the logical data source that should be used for executing the DML.
This need not have to be set every time. There is a system level default that can be provided as part of the Canvas Configuration System that is used as a default.

String dbAccessImpl;

This sets the actual underlying data access manager that needs to be used for that specific execution. This is typically not changed at a per request level. Rather there is a system level default provided as a configuration to the Canvas Configuration System that is defaulted.

Map data;

This Map contains the data (could be flat or hierarchical) that should be used as part of the request. The Data Access Layer implementation can choose how it wants to use the data as part of any operation execution.

List<Map> batchData;

This is a List of Maps that should be executed as a batch. This will be used by the Data access Layer implementation only of the operation is a Batch related operation.

boolean queryAsMap;

This flag indicates whether the request should be executed with the intent of ultimately getting the result as a Map. By default this is set to false. When false, the control of the result packaging is left to the data access layer implementation.

void addDataToBatch(Map aRow);

This method can be used to add a particular data set as a batch. This will be used by the Data access Layer implementation only of the operation is a Batch related operation.

void clearFilters();

This method can be used to clear any earlier filters that have been added to this request.

void addFilter(String colName, Object Value)

This method is used to add a filter for the specific column for the specific value.

DatabaseResult execute();

This is the method that actually triggers the execution of this request.

DatabaseResult getDatabaseResult();

This is a helper method that returns the result that created post execution.