Interface EntityEditor.DetailEditors<R extends EntityEditor<R>>

Type Parameters:
R - EntityEditor type
Enclosing interface:
EntityEditor<R extends EntityEditor<R>>

public static sealed interface EntityEditor.DetailEditors<R extends EntityEditor<R>>

Manages detail editors for one-to-one entity composition within an EntityEditor.

A detail editor represents a detail entity that is edited alongside the master and persisted within the same transaction. The relationship between master and detail is described by an EditorLink, which can be either foreign-key based or condition-based.

When the link is a ForeignKeyEditorLink, the foreign key to the master is declared framework-managed via three coordinated configurations on the detail editor:

Together, these make the foreign key invisible to user-supplied logic — it is filled in by the framework at persistence time and ignored everywhere else.

When the link has no foreign key, none of the framework-managed declarations apply. The user supplies the load condition (how to load the detail row given the master) and the beforeInsert action (how to prepare the detail for insertion). It is the user's responsibility to ensure these two stay consistent: any row created via beforeInsert must match the load condition, otherwise the row will persist but never load back on subsequent master selection.

Persistence flow

The detail entity is loaded from the database when the master entity changes, and the master editor's EntityEditor.Modified state aggregates the detail editor's state.

During master persistence, detail editors participate within the same transaction (see EntityConnection.transaction(is.codion.framework.db.EntityConnection, is.codion.framework.db.EntityConnection.Transactional) — a transaction call on a connection that already has an open transaction joins the outer one rather than starting a new one):

  • Insert: A present detail entity is inserted, with the link's beforeInsert applied with the freshly-inserted master.
  • Update: Depending on the detail's presence and existence, the detail is inserted, updated, or deleted.
  • Delete: An existing detail entity is deleted before the master.

Presence is determined by the detail editor's EntityEditor.present() state, configured at registration time via EditorLink.Builder.present(Predicate). A detail that is present but does not yet exist triggers an insert. A detail that exists but is no longer present triggers a delete. A detail that exists, is present, and is modified triggers an update.

See Also:
  • Method Details

    • add

      void add(EditorLink link)

      Registers a detail editor described by the given link.

      For foreign-key based links the framework-managed FK declarations described in the class javadoc are applied to the detail editor. For condition-based links no automatic FK management is applied — the user-supplied load condition and beforeInsert drive the relationship.

      Parameters:
      link - the detail editor link
      Throws:
      IllegalArgumentException - if a detail editor with the same name is already registered, or, for an FK-based link, if the foreign key's referenced or owning entity types don't match the master and detail editors respectively
      See Also:
    • get

      R get(ForeignKey foreignKey)

      Looks up a previously registered detail editor by foreign key.

      Returns the registered ForeignKeyEditorLink-based detail editor whose foreign key matches, regardless of any explicit name override. For multi-slot configurations where several detail editors share the same foreign key, this method throws — use get(String) with an explicit name instead.

      Parameters:
      foreignKey - the foreign key
      Returns:
      the detail editor previously registered for the given foreign key
      Throws:
      IllegalStateException - if no detail editor is registered for the foreign key, or if multiple detail editors are registered for it
    • get

      R get(String name)
      Parameters:
      name - the link name
      Returns:
      the detail editor previously registered with the given name
      Throws:
      IllegalStateException - if no detail editor is registered under the given name
    • caption

      String caption(String name)
      Parameters:
      name - the link name
      Returns:
      the caption of the link registered with the given name
      Throws:
      IllegalStateException - if no detail editor is registered under the given name, or if multiple detail editors share the name (use caption(ForeignKey))
    • caption

      String caption(ForeignKey foreignKey)
      Parameters:
      foreignKey - the foreign key
      Returns:
      the caption of the link registered for the given foreign key
      Throws:
      IllegalStateException - if no detail editor is registered for the foreign key, or if multiple detail editors are registered for it (use caption(String))