Class ToManyRelationAdapter

All Implemented Interfaces:
EntityList, Relation, Iterable<Entity>

public class ToManyRelationAdapter extends AbstractRelationAdapter
Maps a to-many hibernate collection to the Relation interface Note: size() might execute a database query - therefore we do not use size() if we intend to access all entities anyway (toList() or iterator()).
  • Constructor Details

  • Method Details

    • getInnerInterceptor

      public RelationInterceptor getInnerInterceptor()
      Specified by:
      getInnerInterceptor in class AbstractRelationAdapter
    • setInverseRelation

      protected void setInverseRelation(Entity entity, boolean added)
    • set

      public void set(Iterable<Entity> entities)
      Description copied from interface: Relation
      Creates an intersection of the currently linked ones and the given ones, and then calls Relation.remove(Entity) and Relation.add(Entity) in a loop.
      Parameters:
      entities - The list of entities that will be the only linked ones.
    • clear

      public void clear()
      Description copied from interface: Relation
      Removes all entities in this relation. Does the same as calling remove() for all linked entities.
    • get

      public Entity get(int index, boolean eager)
      Description copied from interface: EntityList
      Get the entity at the specified index.
      Parameters:
      index - The index.
      eager - true, if a page should be eagerly loaded, if the entity's state is hollow, false otherwise.
      Returns:
      The entity at the specified index potentially in unusable state, or null.
    • size

      public int size()
      Description copied from interface: EntityList
      Get the number of entities this list contains.
      Returns:
      The number of entities.
    • iterator

      public Iterator<Entity> iterator()
      The iterator of the superclass uses EntityList.size() which might cause a query in this implementation. Therefore we avoid this unnecessary query as the collection will initialized anyway.
      Specified by:
      iterator in interface Iterable<Entity>
      Overrides:
      iterator in class AbstractEntityList