Module io.ebean.api

Class BeanMap<K,E>

java.lang.Object
io.ebean.common.BeanMap<K,E>
All Implemented Interfaces:
BeanCollection<E>, ToStringAware, Serializable, Map<K,E>

public final class BeanMap<K,E> extends Object implements Map<K,E>
Map capable of lazy loading.
See Also:
  • Field Details

    • lock

      protected final ReentrantLock lock
    • readOnly

      protected boolean readOnly
    • disableLazyLoad

      protected boolean disableLazyLoad
    • loader

      protected transient BeanCollectionLoader loader
      The Database this is associated with. (used for lazy fetch).
    • filterMany

      protected transient ExpressionList<?> filterMany
    • registeredWithLoadContext

      protected boolean registeredWithLoadContext
      Flag set when registered with the batch loading context.
    • ebeanServerName

      protected String ebeanServerName
    • ownerBean

      protected EntityBean ownerBean
      The owning bean (used for lazy fetch).
    • propertyName

      protected String propertyName
      The name of this property in the owning bean (used for lazy fetch).
    • modifyHolder

      protected io.ebean.common.ModifyHolder<E> modifyHolder
    • modifyListenMode

      protected BeanCollection.ModifyListenMode modifyListenMode
    • modifyListening

      protected boolean modifyListening
  • Constructor Details

    • BeanMap

      public BeanMap(Map<K,E> map)
      Create with a given Map.
    • BeanMap

      public BeanMap()
      Create using a underlying LinkedHashMap.
    • BeanMap

      public BeanMap(BeanCollectionLoader ebeanServer, EntityBean ownerBean, String propertyName)
  • Method Details

    • toString

      public void toString(ToStringBuilder builder)
      Description copied from interface: ToStringAware
      Append to the ToStringBuilder.
      Specified by:
      toString in interface ToStringAware
    • reset

      public void reset(EntityBean ownerBean, String propertyName)
      Description copied from interface: BeanCollection
      Reset the collection back to an empty state ready for reloading.

      This is done as part of bean refresh.

      Specified by:
      reset in interface BeanCollection<K>
    • isSkipSave

      public boolean isSkipSave()
      Description copied from interface: BeanCollection
      Return true if the collection is uninitialised or is empty without any held modifications.

      Returning true means can safely skip cascade save for this bean collection.

      Specified by:
      isSkipSave in interface BeanCollection<K>
    • loadFrom

      public void loadFrom(BeanCollection<?> other)
      Description copied from interface: BeanCollection
      Load bean from another collection.
      Specified by:
      loadFrom in interface BeanCollection<K>
    • internalPutNull

      public void internalPutNull()
    • internalPut

      public void internalPut(Object key, Object bean)
    • internalPutWithCheck

      public void internalPutWithCheck(Object key, Object bean)
    • internalAddWithCheck

      public void internalAddWithCheck(Object bean)
      Description copied from interface: BeanCollection
      Add the bean with a check to see if it is already contained.
      Specified by:
      internalAddWithCheck in interface BeanCollection<K>
    • internalAdd

      public void internalAdd(Object bean)
      Description copied from interface: BeanCollection
      Add the bean to the collection. This is disallowed for BeanMap.
      Specified by:
      internalAdd in interface BeanCollection<K>
    • isPopulated

      public boolean isPopulated()
      Return true if the underlying map has been populated. Returns false if it has a deferred fetch pending.
      Specified by:
      isPopulated in interface BeanCollection<K>
    • isReference

      public boolean isReference()
      Return true if this is a reference (lazy loading) bean collection. This is the same as !isPopulated();
      Specified by:
      isReference in interface BeanCollection<K>
    • checkEmptyLazyLoad

      public boolean checkEmptyLazyLoad()
      Description copied from interface: BeanCollection
      Check after the lazy load that the underlying collection is not null (handle case where join to many not outer).

      That is, if the collection was not loaded due to filterMany predicates etc then make sure the collection is set to empty.

      Specified by:
      checkEmptyLazyLoad in interface BeanCollection<K>
    • setActualMap

      public void setActualMap(Map<?,?> map)
      Set the actual underlying map. Used for performing lazy fetch.
    • getActualMap

      public Map<K,E> getActualMap()
      Return the actual underlying map.
    • getActualDetails

      public Collection<E> getActualDetails()
      Returns the collection of beans (map values).
      Specified by:
      getActualDetails in interface BeanCollection<K>
    • getActualEntries

      public Collection<?> getActualEntries()
      Returns the map entrySet.
      Specified by:
      getActualEntries in interface BeanCollection<K>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object object)
      Equal if object is a Map and equal in a Map sense.
      Specified by:
      equals in interface Map<K,E>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Map<K,E>
      Overrides:
      hashCode in class Object
    • clear

      public void clear()
      Specified by:
      clear in interface Map<K,E>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<K,E>
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<K,E>
    • entrySet

      public Set<Map.Entry<K,E>> entrySet()
      Specified by:
      entrySet in interface Map<K,E>
    • get

      public E get(Object key)
      Specified by:
      get in interface Map<K,E>
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: BeanCollection
      Return true if the List Set or Map is empty.
      Specified by:
      isEmpty in interface BeanCollection<K>
      Specified by:
      isEmpty in interface Map<K,E>
    • keySet

      public Set<K> keySet()
      Specified by:
      keySet in interface Map<K,E>
    • put

      public E put(K key, E value)
      Specified by:
      put in interface Map<K,E>
    • putAll

      public void putAll(Map<? extends K,? extends E> puts)
      Specified by:
      putAll in interface Map<K,E>
    • addBean

      public void addBean(E bean)
      Description copied from interface: BeanCollection
      Add a bean to the list/set with modifyListen notification.
      Specified by:
      addBean in interface BeanCollection<K>
    • removeBean

      public void removeBean(E bean)
      Description copied from interface: BeanCollection
      Remove a bean to the list/set with modifyListen notification.
      Specified by:
      removeBean in interface BeanCollection<K>
    • remove

      public E remove(Object key)
      Specified by:
      remove in interface Map<K,E>
    • size

      public int size()
      Description copied from interface: BeanCollection
      Return the number of elements in the List Set or Map.
      Specified by:
      size in interface BeanCollection<K>
      Specified by:
      size in interface Map<K,E>
    • values

      public Collection<E> values()
      Specified by:
      values in interface Map<K,E>
    • getShallowCopy

      public BeanCollection<E> getShallowCopy()
      Description copied from interface: BeanCollection
      Return a shallow copy of this collection that is modifiable.
      Specified by:
      getShallowCopy in interface BeanCollection<K>
    • getOwnerBean

      public EntityBean getOwnerBean()
      Description copied from interface: BeanCollection
      Return the bean that owns this collection.
      Specified by:
      getOwnerBean in interface BeanCollection<E>
    • getPropertyName

      public String getPropertyName()
      Description copied from interface: BeanCollection
      Return the bean property name this collection represents.
      Specified by:
      getPropertyName in interface BeanCollection<E>
    • getFilterMany

      public ExpressionList<?> getFilterMany()
      Description copied from interface: BeanCollection
      Return the filter (if any) that was used in building this collection.

      This is so that the filter can be applied on refresh.

      Specified by:
      getFilterMany in interface BeanCollection<E>
    • setFilterMany

      public void setFilterMany(ExpressionList<?> filterMany)
      Description copied from interface: BeanCollection
      Set the filter that was used in building this collection.
      Specified by:
      setFilterMany in interface BeanCollection<E>
    • setDisableLazyLoad

      public void setDisableLazyLoad(boolean disableLazyLoad)
      Description copied from interface: BeanCollection
      Set the disableLazyLoad state.
      Specified by:
      setDisableLazyLoad in interface BeanCollection<E>
    • isRegisteredWithLoadContext

      public boolean isRegisteredWithLoadContext()
      Description copied from interface: BeanCollection
      Return true if the collection has been registered with the batch loading context.
      Specified by:
      isRegisteredWithLoadContext in interface BeanCollection<E>
    • setLoader

      public void setLoader(BeanCollectionLoader loader)
      Description copied from interface: BeanCollection
      Set the loader that will be used to lazy/query load this collection.

      This is effectively the batch loading context this collection is registered with.

      Specified by:
      setLoader in interface BeanCollection<E>
    • isReadOnly

      public boolean isReadOnly()
      Description copied from interface: BeanCollection
      Return true if the collection should be treated as readOnly and no elements can be added or removed etc.
      Specified by:
      isReadOnly in interface BeanCollection<E>
    • setReadOnly

      public void setReadOnly(boolean readOnly)
      Description copied from interface: BeanCollection
      Set to true if you want the BeanCollection to be treated as read only. This means no elements can be added or removed etc.
      Specified by:
      setReadOnly in interface BeanCollection<E>
    • hasModifications

      public boolean hasModifications()
      Description copied from interface: BeanCollection
      Return true if the collection is modify listening and has modifications.
      Specified by:
      hasModifications in interface BeanCollection<E>
    • getModifyListening

      public BeanCollection.ModifyListenMode getModifyListening()
      Description copied from interface: BeanCollection
      Return the current modify listening mode. Can be null for on newly created beans.
      Specified by:
      getModifyListening in interface BeanCollection<E>
    • setModifyListening

      public void setModifyListening(BeanCollection.ModifyListenMode mode)
      set modifyListening to be on or off.
      Specified by:
      setModifyListening in interface BeanCollection<E>
    • getModifyListenMode

      public BeanCollection.ModifyListenMode getModifyListenMode()
      Return the modify listening mode this collection is using.
    • modifyAddition

      public void modifyAddition(E bean)
      Description copied from interface: BeanCollection
      Add an object to the additions list.

      This will potentially end up as an insert into a intersection table for a ManyToMany.

      Specified by:
      modifyAddition in interface BeanCollection<E>
    • modifyRemoval

      public void modifyRemoval(Object bean)
      Description copied from interface: BeanCollection
      Add an object to the deletions list.

      This will potentially end up as an delete from an intersection table for a ManyToMany.

      Specified by:
      modifyRemoval in interface BeanCollection<E>
    • modifyReset

      public void modifyReset()
      Description copied from interface: BeanCollection
      Reset the set of additions and deletions. This is called after the additions and removals have been processed.
      Specified by:
      modifyReset in interface BeanCollection<E>
    • getModifyAdditions

      public Set<E> getModifyAdditions()
      Description copied from interface: BeanCollection
      Return the list of objects added to the list set or map. These will used to insert rows into the intersection table of a ManyToMany.
      Specified by:
      getModifyAdditions in interface BeanCollection<E>
    • getModifyRemovals

      public Set<E> getModifyRemovals()
      Description copied from interface: BeanCollection
      Return the list of objects removed from the list set or map. These will used to delete rows from the intersection table of a ManyToMany.
      Specified by:
      getModifyRemovals in interface BeanCollection<E>
    • holdsModifications

      public boolean holdsModifications()
      Return true if there are underlying additions or removals.
      Specified by:
      holdsModifications in interface BeanCollection<E>
    • wasTouched

      public boolean wasTouched()
      Description copied from interface: BeanCollection
      Has been modified by an addition or removal.
      Specified by:
      wasTouched in interface BeanCollection<E>
    • setFromOriginal

      protected void setFromOriginal(io.ebean.common.AbstractBeanCollection<E> other)
      Copies all relevant properties for a clone. See BeanCollection.getShallowCopy()