Module io.ebean.api

Class BeanList<E>

java.lang.Object
io.ebean.common.BeanList<E>
All Implemented Interfaces:
BeanCollection<E>, BeanCollectionAdd, ToStringAware, Serializable, Iterable<E>, Collection<E>, List<E>

public final class BeanList<E> extends Object implements List<E>, BeanCollectionAdd
List 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

    • BeanList

      public BeanList(List<E> list)
      Specify the underlying List implementation.
    • BeanList

      public BeanList()
      Uses an ArrayList as the underlying List implementation.
    • BeanList

      public BeanList(BeanCollectionLoader loader, EntityBean ownerBean, String propertyName)
      Used to create deferred fetch proxy.
  • 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<E>
    • 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<E>
    • addEntityBean

      public void addEntityBean(EntityBean bean)
      Description copied from interface: BeanCollectionAdd
      Add a loaded bean to the collection.
      Specified by:
      addEntityBean in interface BeanCollectionAdd
    • loadFrom

      public void loadFrom(BeanCollection<?> other)
      Description copied from interface: BeanCollection
      Load bean from another collection.
      Specified by:
      loadFrom in interface BeanCollection<E>
    • 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<E>
    • 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<E>
    • 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<E>
    • setActualList

      public void setActualList(List<?> list)
      Set the actual underlying list.

      This is primarily for the deferred fetching function.

    • getActualList

      public List<E> getActualList()
      Return the actual underlying list.
    • getActualDetails

      public Collection<E> getActualDetails()
      Description copied from interface: BeanCollection
      Returns the underlying collection of beans from the Set, Map or List.
      Specified by:
      getActualDetails in interface BeanCollection<E>
    • getActualEntries

      public Collection<?> getActualEntries()
      Description copied from interface: BeanCollection
      Returns the underlying entries so for Maps this is a collection of Map.Entry.

      For maps this returns the entrySet as we need the keys of the map.

      Specified by:
      getActualEntries in interface BeanCollection<E>
    • isPopulated

      public boolean isPopulated()
      Return true if the underlying list is populated.
      Specified by:
      isPopulated in interface BeanCollection<E>
    • 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<E>
    • toString

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

      public boolean equals(Object obj)
      Equal if obj is a List and equal in a list sense.

      Specifically obj does not need to be a BeanList but any list. This does not use the FindMany, fetchedMaxRows or finishedFetch properties in the equals test.

      Specified by:
      equals in interface Collection<E>
      Specified by:
      equals in interface List<E>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Collection<E>
      Specified by:
      hashCode in interface List<E>
      Overrides:
      hashCode in class Object
    • add

      public void add(int index, E element)
      Specified by:
      add in interface List<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<E>
    • add

      public boolean add(E o)
      Specified by:
      add in interface Collection<E>
      Specified by:
      add in interface List<E>
    • addAll

      public boolean addAll(Collection<? extends E> c)
      Specified by:
      addAll in interface Collection<E>
      Specified by:
      addAll in interface List<E>
    • addAll

      public boolean addAll(int index, Collection<? extends E> c)
      Specified by:
      addAll in interface List<E>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<E>
      Specified by:
      clear in interface List<E>
    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<E>
      Specified by:
      contains in interface List<E>
    • containsAll

      public boolean containsAll(Collection<?> c)
      Specified by:
      containsAll in interface Collection<E>
      Specified by:
      containsAll in interface List<E>
    • get

      public E get(int index)
      Specified by:
      get in interface List<E>
    • indexOf

      public int indexOf(Object o)
      Specified by:
      indexOf in interface List<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<E>
      Specified by:
      isEmpty in interface Collection<E>
      Specified by:
      isEmpty in interface List<E>
    • iterator

      public Iterator<E> iterator()
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
      Specified by:
      iterator in interface List<E>
    • lastIndexOf

      public int lastIndexOf(Object o)
      Specified by:
      lastIndexOf in interface List<E>
    • listIterator

      public ListIterator<E> listIterator()
      Specified by:
      listIterator in interface List<E>
    • listIterator

      public ListIterator<E> listIterator(int index)
      Specified by:
      listIterator in interface List<E>
    • 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<E>
    • remove

      public E remove(int index)
      Specified by:
      remove in interface List<E>
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<E>
      Specified by:
      remove in interface List<E>
    • removeAll

      public boolean removeAll(Collection<?> beans)
      Specified by:
      removeAll in interface Collection<E>
      Specified by:
      removeAll in interface List<E>
    • retainAll

      public boolean retainAll(Collection<?> retainBeans)
      Specified by:
      retainAll in interface Collection<E>
      Specified by:
      retainAll in interface List<E>
    • set

      public E set(int index, E element)
      Specified by:
      set in interface List<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<E>
      Specified by:
      size in interface Collection<E>
      Specified by:
      size in interface List<E>
    • subList

      public List<E> subList(int fromIndex, int toIndex)
      Specified by:
      subList in interface List<E>
    • toArray

      public Object[] toArray()
      Specified by:
      toArray in interface Collection<E>
      Specified by:
      toArray in interface List<E>
    • toArray

      public <T> T[] toArray(T[] a)
      Specified by:
      toArray in interface Collection<E>
      Specified by:
      toArray in interface List<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<E>
    • 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()