I'm trying to make filter by 'result', I mean I have a class Calculation and a lot of subclasses for example entity Multiplication, Sum, Division itd.
//lombok
@Entity
@Inheritance
@DiscriminatorColumn(name = "type")
public abstract class Calculation {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
}
//lombok
@Entity
@DiscriminatorValue("SUM")
public class Sum extends Calculation {
private double firstNumber;
private double secondNumber;
}
itd.
I want to have in my service class pagination with filtering BY RESULT. I mean if we have in SUM (2 and 3) i want to have somewhere RESULT of this.
@Override
public Page<CalculationDto> findAll(Criteria criteria, Pageable pageable) {
Specification<Calculation> specification = Specification.SpecificationBuilder
.withResult(criteria.getResult())
.build();
return calculationRepository.findAll(specification, pageable)
.map(CalculationFacade::mapToDto)
.toList();
}
And the question is how to do something like this. I was trying do this with @Formula, but it wasnt working for me properly (maybe i was doing this wrong). Maybe i shouldn't use SINGLE_TABLE idk. I just need an idea and a little help.
I want to filter by RESULT of calculation.