I am using aspect to do few updates in elastic search after an entity is modified and persisted to db. I have methods to update one entity and a method to support bulk updating multiple entities? Internally, List method iterates over the method which persists the single object. How do I make the aspect to run only at list level?
Sample code below
@UpdateElastic
@Service
public Object saveOneObject(EntityObj obj){
var savedObj = saveObj(obj); // method to persist entityObject
return savedObj; // this object would now be passed to UpdateElastic aspect which
// would perform some operation to cache this object in elastic search.
}
@UpdateElasticList
@Service
public Object saveMultipleObjects(List<EntityObj> objs){
List< EntityObj> savedObjects = new ArrayList<>();
for (EntityObj obj: objs){
var savedObj = saveOneObj(obj); // how do I avoid aspect to be called here but // still call it if the saveOneObj is called from outside this file.
savedObjects.add(savedObj);
}
// method to persist entityObject
return savedObjects; // this list of objects would now be passed to UpdateElasticList aspect which would perform some operation to cache this object in elastic search.
}