Class Fragment

java.lang.Object
org.nuxeo.ecm.core.storage.sql.Fragment
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
CollectionFragment, SimpleFragment

public abstract class Fragment extends Object implements Serializable
A rich value corresponding to one row or a collection of rows in a table.

In addition to the basic Row, this holds the old values (to check dirty state), the state and a reference to the session.

This class has two kinds of state-changing methods:

  • the "set" ones, which only change the state,
  • the "mark" ones, which change the state and do the corresponding changes in the pristine/modified maps of the context.
Author:
Florent Guillaume
See Also:
  • Field Details

    • row

      protected Row row
      The row holding the data.
    • oldvalues

      protected Serializable[] oldvalues
      The row old values, from the time of construction / refetch. The size of the the array is following #row.values.length.
    • context

      protected PersistenceContext context
  • Constructor Details

    • Fragment

      protected Fragment(Row row, Fragment.State state, PersistenceContext context)
      Constructs a Fragment from a Row.
      Parameters:
      row - the row
      state - the initial state for the fragment
      context - the persistence context to which the fragment is tied, or null
  • Method Details

    • getState

      public Fragment.State getState()
      Gets the state.
      Returns:
      the state
    • setId

      public void setId(Serializable id)
      Sets the id. This only used at most once to change a temporary id to the persistent one.
      Parameters:
      id - the new persistent id
    • getId

      public Serializable getId()
      Gets the id.
      Returns:
      the id
    • clearDirty

      public void clearDirty()
      Clears the dirty state.
    • getRowUpdate

      public abstract RowMapper.RowUpdate getRowUpdate()
      Returns the row update to do in the database to write this value.
      Returns:
      a row update, or null if the value is unchanged since last clear
      Since:
      8.3
    • refetch

      protected abstract Fragment.State refetch()
      Refetches this fragment from the database. Needed when an invalidation has been received and the fragment is accessed again.
      Returns:
      the new state, Fragment.State.PRISTINE or Fragment.State.ABSENT
    • refetchDeleted

      protected abstract Fragment.State refetchDeleted()
      Resets the data for a fragment that was invalidated by deletion.
      Returns:
      the new state, Fragment.State.PRISTINE or Fragment.State.ABSENT
    • accessed

      protected void accessed()
      Checks that access to the fragment is possible. Called internally before a get, so that invalidated fragments can be refetched.
    • markModified

      protected void markModified()
      Marks the fragment modified. Called internally after a put/set.
    • setDeleted

      protected void setDeleted(boolean primary)
      Marks the fragment deleted. Called after a remove.
    • setDetached

      protected void setDetached()
      Detaches the fragment from its persistence context. The caller makes sure that the fragment is removed from the context map.
    • setPristine

      protected void setPristine()
      Sets the (created/modified) fragment in the pristine state. Called after a save.
    • setInvalidatedModified

      protected void setInvalidatedModified()
      Sets the fragment in the "invalidated from a modification" state. This is called:
      • when a database operation does non-tracked changes, which means that on access a refetch will be needed,
      • during post-commit invalidation.
    • setInvalidatedDeleted

      protected void setInvalidatedDeleted()
      Sets the fragment in the "invalidated from a deletion" state. This is called:
      • when a database operation does a delete,
      • during post-commit invalidation.
    • toString

      public String toString()
      Overrides:
      toString in class Object