Class 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:
    Serialized Form
    • Field Detail

      • 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.
    • Constructor Detail

      • 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 Detail

      • 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
      • 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.