Module io.ebean.api
Package io.ebean

Interface BeanState


public interface BeanState
Provides access to the internal state of an entity bean.
  • Method Summary

    Modifier and Type
    Method
    Description
    Return the set of changed properties.
    Return a map of the updated properties and their new and old values.
    boolean
    Return true if the bean has been changed but not yet saved.
    boolean
    Return true if the bean has lazy loading disabled.
    boolean
    Return true if the bean is new (and not yet saved).
    boolean
    Return true if the bean is new or dirty (and probably needs to be saved).
    boolean
    Return true if the bean is readOnly.
    boolean
    Return true if this is a lazy loading reference bean.
    For partially populated beans returns the properties that are loaded on the bean.
    Returns a map with load errors.
    void
    Reset the bean putting it into NEW state such that a save() results in an insert.
    void
    setDisableLazyLoad(boolean disableLazyLoading)
    This can be called with true to disable lazy loading on the bean.
    void
    Advanced - Used to programmatically build a partially or fully loaded entity bean.
    void
    setPropertyLoaded(String propertyName, boolean loaded)
    Set the loaded state of the property given it's name.
    void
    setReadOnly(boolean readOnly)
    Set the readOnly status for the bean.
    int
    Return the sort order value for an order column.
  • Method Details

    • isReference

      boolean isReference()
      Return true if this is a lazy loading reference bean.

      If so the this bean only holds the Id property and will invoke lazy loading if any other property is get or set.

    • isNew

      boolean isNew()
      Return true if the bean is new (and not yet saved).
    • isNewOrDirty

      boolean isNewOrDirty()
      Return true if the bean is new or dirty (and probably needs to be saved).
    • isDirty

      boolean isDirty()
      Return true if the bean has been changed but not yet saved.
    • setDisableLazyLoad

      void setDisableLazyLoad(boolean disableLazyLoading)
      This can be called with true to disable lazy loading on the bean.
    • isDisableLazyLoad

      boolean isDisableLazyLoad()
      Return true if the bean has lazy loading disabled.
    • setPropertyLoaded

      void setPropertyLoaded(String propertyName, boolean loaded)
      Set the loaded state of the property given it's name.

      Typically this would be used to set the loaded state of a property to false to ensure that the specific property is excluded from a stateless update.

      
      
         // populate a bean via say JSON
         User user = ...;
      
         // set loaded state on the email property to false so that
         // the email property is not included in a stateless update
         DB.beanState(user).setPropertyLoaded("email", false);
      
         user.update();
      
       

      This will throw an IllegalArgumentException if the property is unknown.

    • loadedProps

      Set<String> loadedProps()
      For partially populated beans returns the properties that are loaded on the bean.

      Accessing another property will cause lazy loading to occur.

    • changedProps

      Set<String> changedProps()
      Return the set of changed properties.
    • dirtyValues

      Map<String,ValuePair> dirtyValues()
      Return a map of the updated properties and their new and old values.
    • isReadOnly

      boolean isReadOnly()
      Return true if the bean is readOnly.

      If a setter is called on a readOnly bean it will throw an exception.

    • setReadOnly

      void setReadOnly(boolean readOnly)
      Set the readOnly status for the bean.
    • setLoaded

      void setLoaded()
      Advanced - Used to programmatically build a partially or fully loaded entity bean. First create an entity bean via Database.createEntityBean(Class), then populate its properties and then call this method specifying which properties where loaded or null for a fully loaded entity bean.
    • resetForInsert

      void resetForInsert()
      Reset the bean putting it into NEW state such that a save() results in an insert.
    • loadErrors

      Map<String,Exception> loadErrors()
      Returns a map with load errors.
    • sortOrder

      int sortOrder()
      Return the sort order value for an order column.