Versionen im Vergleich

Schlüssel

  • Diese Zeile wurde hinzugefügt.
  • Diese Zeile wurde entfernt.
  • Formatierung wurde geändert.
Auszug
hiddentrue

Nuclos disable rule execution selectively: ThreadLocal switch, avoid endless loops, try/finally, disable UpdateRule, BusinessObjectProvider.update.

globe with meridians Language: Deutsch · English

hammer and wrench Selectively disabling rule execution

Avoid endless loops: disable individual rules per context via ThreadLocal switches.

Status
colourPurple
titleHow-to
Status
colourBlue
titleDeveloper
Status
colourGreen
titleUpdated: Jul 2026
Status
colourGrey
titleapplies to Nuclos 4.2026.x

Panel
bgColor#F4F5F7

On this page

Inhalt
maxLevel2
minLevel2

Why disable rules selectively?

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.

Warnung
titleCaution

Use with care – do not undermine the business logic of the rules. For simple cases prefer SaveFlags.

1. A switch in the rule to be disabled

Codeblock
languagejava
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).

2. Disabling from the updating rule

Codeblock
languagejava
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!
}
Tipp
titleDon't forget finally

Always re-activate in the finally block so the switch is reliably reset even on error.

Related pages

open book Server-side rules


Rule context.

Open →

gear SaveFlags


Alternative on save.

Open →