Row Processors
Row Processors allow you to transform entities during ResultSet parsing in a single pass. This is useful for:
- Running calculations (cumulative sums, totals)
- Delta calculations (comparing with previous row)
- Row numbering
- Data enrichment
- Security masking
Basic Row Processor
public class RunningSumProcessor implements RowProcessor<Sale> {
private BigDecimal runningTotal = BigDecimal.ZERO;
private int rowNumber = 0;
@Override
public void process(Sale sale, RowContext context) {
// Update running total
runningTotal = runningTotal.add(sale.getAmount());
sale.setRunningTotal(runningTotal);
// Add row number
rowNumber++;
sale.setRowNumber(rowNumber);
}
}
// Usage
DevExtremeResult<Sale> result = gridDataProvider
.query(Sale.class)
.loadOptions(loadOptions)
.rowProcessor(new RunningSumProcessor())
.executeDevExtreme();Using RowContext State
RowProcessor<Employee> processor = (employee, context) -> {
// Get previous employee for comparison
Employee previous = context.getState("previousEmployee", Employee.class).orElse(null);
if (previous != null) {
// Calculate delta from previous row
BigDecimal salaryDelta = employee.getSalary().subtract(previous.getSalary());
employee.setSalaryDelta(salaryDelta);
}
// Store current as previous for next row
context.setState("previousEmployee", employee);
};Using Context Metadata
RowProcessor<Employee> processor = (employee, context) -> {
boolean isAdmin = context.getMetadata("isAdmin", Boolean.class).orElse(false);
if (!isAdmin) {
employee.setSalary(null); // Mask salary for non-admins
}
};
DevExtremeResult<Employee> result = gridDataProvider
.query(Employee.class)
.loadOptions(loadOptions)
.rowProcessor(processor)
.contextMetadata("userId", currentUser.getId())
.contextMetadata("isAdmin", currentUser.hasRole("ADMIN"))
.executeDevExtreme();Chaining Multiple Processors
RowProcessor<Employee> combined = new CalculatedFieldsProcessor()
.andThen(new DepartmentEnrichmentProcessor())
.andThen(new SecurityMaskingProcessor());
DevExtremeResult<Employee> result = gridDataProvider
.query(Employee.class)
.loadOptions(loadOptions)
.rowProcessor(combined)
.executeDevExtreme();RowContext API
| Method | Description |
|---|---|
getConnection() | Get database connection for data enrichment |
getEntityMetaData() | Get table name, field mappings, relationships |
getSchema() | Get current schema being queried |
getMetadata() | Get custom metadata map |
getMetadata(key, type) | Get specific metadata value |
setState(key, value) | Store state for next row |
getState(key, type) | Get state from previous rows |
hasState(key) | Check if state key exists |
removeState(key) | Remove state value |
clearState() | Clear all state |
Last updated on