Skip to content

CRUD Interception (before* / after*)

Inject business logic around add, update, and delete operations: before* methods run before data is persisted and can modify data or abort the operation; after* methods run after successful persistence — ideal for side effects such as cache writes and message push.

Hook Methods

MethodTriggerTypical use
beforeAdd(MODEL)Before an add is savedFill defaults, call external services
afterAdd(MODEL)After an add is savedCache writes, message push
beforeUpdate(MODEL)Before an update is savedRewrite data dynamically
afterUpdate(MODEL)After an update is savedSync downstream systems
beforeDelete(MODEL)Before a deleteRelated-data checks, can abort the delete
afterDelete(MODEL)After a deleteClean up related resources

Pure validation logic belongs in validate — see Form Validation (validate).

Code Example

java
@Service
public class EruptTestDataProxy implements DataProxy<EruptTest> {

    @Override
    public void beforeAdd(EruptTest eruptTest) {
        // Supplement data before saving
        eruptTest.setCreateBy(getCurrentUser());
    }

    @Override
    public void beforeUpdate(EruptTest eruptTest) {
        // Dynamically modify data before saving
        eruptTest.setName(eruptTest.getName() + "xxxxxxx");
    }

    @Override
    public void beforeDelete(EruptTest eruptTest) {
        // Check before delete; throwing an exception aborts the operation
        if (hasRelatedOrder(eruptTest.getId())) {
            throw new EruptApiErrorTip("Related orders exist — deletion is not allowed");
        }
    }

    @Override
    public void afterAdd(EruptTest eruptTest) {
        // Push messages, write caches, etc. after a successful add
    }

}

TIP

Throw EruptApiErrorTip (or EruptException) in any before* method to abort the operation and show the error message to the user.

Contributors

The avatar of contributor named as YuePeng YuePeng
The avatar of contributor named as Claude Opus 5 (1M context) Claude Opus 5 (1M context)

Changelog

Released under the Apache-2.0 License.