Nuclos disable rule execution selectively: ThreadLocal switch, avoid endless loops, try/finally, disable UpdateRule, BusinessObjectProvider.update. |
Language: Deutsch · English
Avoid endless loops: disable individual rules per context via ThreadLocal switches.
On this page |
Sometimes you want to prevent certain rules (or parts of them) from running – typically when updating individual fields from within a rule, to avoid endless loops or performance problems. This is done with cross-rule ThreadLocal variables.
Use with care – do not undermine the business logic of the rules. For simple cases prefer SaveFlags. |
public class MyUpdateRule implements UpdateRule {
// ThreadLocal-Schalter, initial aktiv
public static final ThreadLocal<Boolean> ACTIVE =
ThreadLocal.withInitial(() -> Boolean.TRUE);
public void update(UpdateContext context) throws BusinessException {
if (ACTIVE.get()) {
// ... eigentliche Logik ...
}
}
} |
ThreadLocal variables only affect the current thread/user context – the rule is not disabled globally (unlike the rule's active flag).
MyBusinessObject mbo = QueryProvider.getById(MyBusinessObject.class, id);
mbo.setMyField(value);
try {
MyUpdateRule.ACTIVE.set(Boolean.FALSE); // Regel deaktivieren
BusinessObjectProvider.update(mbo);
} finally {
MyUpdateRule.ACTIVE.set(Boolean.TRUE); // immer wieder aktivieren!
} |
Always re-activate in the |