I have a little strange problem. All the entity in program extends "BaseEntity" and there is a field "resultStatus" in it. Now I have a requirement need to set value after any "find" methods in JPARepository (like findAll(), findById(),findByIndexAndCode()....). If result not null, set resultStatus to "OK". result is null, set resultStatus to "Warning". When exception happen, set resultStatus to "Failed".
I tried to extends JPARepository and call the method like:
default List<T> findAll() {
List<T> entity=null;
try {
entity = JpaRepository.super.findAll(); //error here
if (entity.get(0) != null) {
entity.get(0).setSqlReturnCode("OK");
} else {
BaseEntity entity1 = new BaseEntity();
entity1.setSqlReturnCode("Warning");
entity.add((T) entity1);
}
} catch (Exception e) {
e.printStackTrace();
BaseEntity entity1 = new BaseEntity();
entity1.setSqlReturnCode("Failed");
entity.add((T) entity1);
}
return entity;
}
And this solution didn't work.
Now I think maybe I can use AOP to catch the result after search JPA, but I dont know what the pointcut is. Can you help me ? Or offer others soluction.
I know it sound strange beacuse I can use .length()'
.size()
.isEmpty()`...to do. But this is the requirment from customer .
I tried to extends JPARepository with a new interface and call it's method. But interface looks cant do this just like class.