Search Arguments

In case a search or query needs to be performed on a data element, various parameters of this search may need to be configured. This can be done using the SearchDetails class. This class contains the actual search parameters through a Details class that is generated for every search method. For instance, for the search method findByModelEq of the data element Car, a details class CarFindByModelEqDetails is generated.

public class SearchDetails<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private String projection = "info";
    private T details;
    private List<SortField> sortFields;
    private Paging paging = new Paging();

    public SearchDetails(T details) {
        this.details = details;
        sortFields = new LinkedList<SortField>();
    }

    public static <U> SearchDetails fetchAll(U details) {
        SearchDetails searchDetails = new SearchDetails(details);
        searchDetails.setPaging(Paging.fetchAll());
        return searchDetails;
    }
}

Such a details class for a search method provides of course the appropriate get and set methods for the search parameters.

public class CarFindByModelEqDetails implements java.io.Serializable {

    private DataRef mModel;

    public void setModel(DataRef model) {
        this.mModel = model;
    }

    public DataRef getModel() {
        return this.mModel;
    }
}

Besides the search parameters, the SearchDetails class allows the sepcification of:

  • the projection of the result instances of the data element that are returned, with the info-projection as default projection.
  • the list of field(s) that need to be used for sorting.
  • the configuration of the paging parameters. The list of sorting fields is defined through the SortField class, that allows the specification of a field name and a boolean indicating whether the sorting order should be ascending or descending.
public class SortField implements Serializable {
    private String fieldName;
    private boolean isAscending;

    public SortField(String fieldName, boolean isAscending) {
        this.fieldName = fieldName;
        this.isAscending = isAscending;
    }
}

SortField class allowing the specification of a sorting field. Of course, a default constructor and the appropriate get and set methods are provided as well. The same is valid for the Paging class, where default methods are provided to specify page 0, and to fetch all results instances at once.

public class Paging implements Serializable {
    public static final int DEFAULT_PAGE_SIZE = 10;
    private int page = 0;
    private int rowsPerPage = DEFAULT_PAGE_SIZE;
    boolean fetchAll = false;

    public static Paging defaultPaging() {
        return new Paging();
    }

    public static Paging fetchAll() {
        Paging paging = new Paging();
        paging.setFetchAll(true);
        return paging;
    }
}

results matching ""

    No results matching ""