com.alon.spring.crud.domain.service.Hookable Maven / Gradle / Ivy
package com.alon.spring.crud.domain.service;
import org.springframework.data.domain.Page;
import java.util.function.Function;
import static com.alon.spring.crud.domain.service.HookManager.*;
import static com.alon.spring.crud.domain.service.LifeCycleHook.*;
import static com.alon.spring.crud.domain.service.LifeCycleHook.AFTER_DELETE;
public interface Hookable {
default void addBeforeSearchHook(Function function) {
addHook(this, BEFORE_SEARCH, function);
}
default void addAfterSearchHook(Function, Page> function) {
addHook(this, AFTER_SEARCH, function);
}
default void addBeforeReadHook(Function function) {
addHook(this, BEFORE_READ, function);
}
default void addAfterReadHook(Function function) {
addHook(this, AFTER_READ, function);
}
default void addBeforeCreateHook(Function function) {
addHook(this, BEFORE_CREATE, function);
}
default void addAfterCreateHook(Function function) {
addHook(this, AFTER_CREATE, function);
}
default void addBeforeUpdateHook(Function function) {
addHook(this, BEFORE_UPDATE, function);
}
default void addAfterUpdateHook(Function function) {
addHook(this, AFTER_UPDATE, function);
}
default void addBeforeDeleteHook(Function function) {
addHook(this, BEFORE_DELETE, function);
}
default void addAfterDeleteHook(Function function) {
addHook(this, AFTER_DELETE, function);
}
default SearchCriteria executeBeforeSearchHooks(SearchCriteria entity) {
return executeHook(this, entity, BEFORE_SEARCH);
}
default Page executeAfterSearchHooks(Page page) {
return executeHook(this, page, AFTER_SEARCH);
}
default ENTITY_ID_TYPE executeBeforeReadHooks(ENTITY_ID_TYPE id) {
return executeHook(this, id, BEFORE_READ);
}
default ENTITY_TYPE executeAfterReadHooks(ENTITY_TYPE entity) {
return executeHook(this, entity, AFTER_READ);
}
default ENTITY_TYPE executeBeforeCreateHooks(ENTITY_TYPE entity) {
return executeHook(this, entity, BEFORE_CREATE);
}
default ENTITY_TYPE executeAfterCreateHooks(ENTITY_TYPE entity) {
return executeHook(this, entity, AFTER_CREATE);
}
default ENTITY_TYPE executeBeforeUpdateHooks(ENTITY_TYPE entity) {
return executeHook(this, entity, BEFORE_UPDATE);
}
default ENTITY_TYPE executeAfterUpdateHooks(ENTITY_TYPE entity) {
return executeHook(this, entity, AFTER_UPDATE);
}
default ENTITY_ID_TYPE executeBeforeDeleteHooks(ENTITY_ID_TYPE id) {
return executeHook(this, id, BEFORE_DELETE);
}
default ENTITY_ID_TYPE executeAfterDeleteHooks(ENTITY_ID_TYPE id) {
return executeHook(this, id, AFTER_DELETE);
}
default void clearHooks(LifeCycleHook... hookTypes) {
HookManager.clearHooks(this, hookTypes);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy