
com.redis.om.spring.search.stream.actions.BaseAbstractAction Maven / Gradle / Ivy
package com.redis.om.spring.search.stream.actions;
import java.lang.reflect.Field;
import java.util.Optional;
import com.redis.om.spring.ops.json.JSONOperations;
import com.redis.om.spring.util.ObjectUtils;
public abstract class BaseAbstractAction implements TakesJSONOperations {
protected Field field;
protected JSONOperations json;
private Field idField;
protected BaseAbstractAction(Field field) {
this.field = field;
Class> entityClass = field.getDeclaringClass();
Optional maybeId = ObjectUtils.getIdFieldForEntityClass(entityClass);
if (maybeId.isPresent()) {
this.idField = maybeId.get();
} else {
throw new NullPointerException(String.format("Entity Class %s does not have an ID field", entityClass.getSimpleName()));
}
}
@Override
public void setJSONOperations(JSONOperations json) {
this.json = json;
}
protected String getKey(Object entity) {
String id = ObjectUtils.getIdFieldForEntity(idField, entity).toString();
return field.getDeclaringClass().getName() + ":" + id;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy