Skip to content

CrudAdapter

CrudAdapter is the data layer interface for Crud. It defines five methods — one for each data operation — and is the only seam between the orchestrator and your persistence layer.

public interface CrudAdapter<View, Editor, CreationForm, Filters, Row, IdType> {
ListingData<Row> search(
String searchText, Filters filters, Pageable pageable, HttpRequest httpRequest);
void deleteAllById(List<IdType> selectedIds, HttpRequest httpRequest);
View getView(IdType id, HttpRequest httpRequest);
Editor getEditor(IdType id, HttpRequest httpRequest);
CreationForm getCreationForm(HttpRequest httpRequest);
}

TypeDescription
ViewObject returned for the read-only detail screen
EditorObject returned for the edit form — must implement CrudEditorForm<IdType>
CreationFormObject returned for the create form — must implement CrudCreationForm<IdType>
FiltersDTO used as the filter bar above the grid
RowDTO used as a grid row in the listing
IdTypeType of the entity identifier

MethodCalled when…Must return
searchUser searches, filters, paginates, or sortsListingData<Row> with the matching rows
deleteAllByIdUser selects rows and clicks Delete— (void)
getViewUser clicks a row — opens the read-only detailA View object
getEditorUser clicks Edit — opens the edit formAn Editor implementing CrudEditorForm<IdType>
getCreationFormUser clicks New — opens the create formA CreationForm implementing CrudCreationForm<IdType>

@Service
public class ProductCrudAdapter
implements CrudAdapter<ProductView, ProductEditor, ProductCreationForm,
ProductFilters, ProductRow, String> {
private final ProductService service;
public ProductCrudAdapter(ProductService service) {
this.service = service;
}
@Override
public ListingData<ProductRow> search(
String searchText, ProductFilters filters,
Pageable pageable, HttpRequest httpRequest) {
return service.search(searchText, filters, pageable);
}
@Override
public void deleteAllById(List<String> ids, HttpRequest httpRequest) {
service.deleteAll(ids);
}
@Override
public ProductView getView(String id, HttpRequest httpRequest) {
return service.findView(id);
}
@Override
public ProductEditor getEditor(String id, HttpRequest httpRequest) {
return service.findEditor(id);
}
@Override
public ProductCreationForm getCreationForm(HttpRequest httpRequest) {
return new ProductCreationForm();
}
}

AutoCrud<T> and FilteredAutoCrud<F,T> cover the common case where the entity type is used for every screen — implement repository() and you’re done. Implement CrudAdapter directly when:

  • View, Editor, and CreationForm are genuinely different types.
  • The search requires a custom query.
  • You need full control over delete behaviour (auditing, soft-delete, etc.).
AutoCrud<T> / FilteredAutoCrud<F,T>CrudAdapter (direct)
View / Editor / CreationForm typesAll TSeparate types
SearchIn-memory (override fetchRows() directly in your AutoCrud subclass to customise)Fully custom
Save / CreateVia AutoNamedView + repository()Fully custom
BoilerplateMinimalFull