Class AbstractRelationAdapter

java.lang.Object
ch.tocco.nice2.persist.core.api.entity.AbstractEntityList
ch.tocco.nice2.persist.core.impl.hibernate.pojo.relation.AbstractRelationAdapter
All Implemented Interfaces:
EntityList, Relation, Iterable<Entity>
Direct Known Subclasses:
ToManyRelationAdapter, ToOneRelationAdapter

public abstract class AbstractRelationAdapter extends AbstractEntityList implements Relation
Abstract base class for mapping hibernate collections to the Relation interface
  • Field Details

  • Constructor Details

  • Method Details

    • getInnerInterceptor

      public abstract RelationInterceptor getInnerInterceptor()
    • add

      public void add(Entity entity)
      Description copied from interface: Relation
      Add an entity to the relation.

      If the entity is in the relation already then the call is ignored; no exception thrown, no events fired. (i'm sure about the exception, but not about the events. -andrej)

      If this is a to-one relation then you are advised to use the Relation.set(ch.tocco.nice2.persist.core.api.entity.Entity) method. If you still decide to use add() then you also need to call remove() with the old value if there was an entity linked already. Relation.set(ch.tocco.nice2.persist.core.api.entity.Entity) takes care of all this for you.

      Specified by:
      add in interface Relation
      Parameters:
      entity - The entity to be added, may be in state conception.
    • remove

      public void remove(Entity entity)
      Description copied from interface: Relation
      Remove an entity from the relation.

      TODO document what happens when the entity is not in the relation.

      Specified by:
      remove in interface Relation
      Parameters:
      entity - The entity to be removed, may be in state conception.
    • set

      public void set(@Nullable @Nullable Entity entity)
      Description copied from interface: Relation
      Set the relation's entities to the specified single entity. Any other entities will be removed. This method may only be called for relations to a single entity (n-1).

      NOTE: This calls Relation.remove(ch.tocco.nice2.persist.core.api.entity.Entity) and Relation.add(ch.tocco.nice2.persist.core.api.entity.Entity) internally. That's also why the interceptor does not have this.

      Specified by:
      set in interface Relation
      Parameters:
      entity - The entity to be set, may be in state conception.
    • get

      @Nullable public @Nullable Entity get()
      Description copied from interface: Relation
      Get the current single target entity of this relation. This method may only be called for relations to a single entity (n-1).
      Specified by:
      get in interface Relation
      Returns:
      The current single target entity potentially in unusable state, or null.
    • expect

      public Relation expect(int amount)
      Description copied from interface: EntityList
      Throws if the list does not contain exactly that amount.

      Example: EntityList entityList = myQuery.execute(1).expect(1);

      Specified by:
      expect in interface EntityList
      Specified by:
      expect in interface Relation
      Overrides:
      expect in class AbstractEntityList
      Parameters:
      amount - The expected amount.
      Returns:
      The list itself.
      See Also:
    • expectAtLeast

      public Relation expectAtLeast(int min)
      Description copied from interface: EntityList
      Throws if the list contains fewer than min items.

      Example: EntityList entityList = myQuery.execute().expectAtLeast(3);

      Specified by:
      expectAtLeast in interface EntityList
      Specified by:
      expectAtLeast in interface Relation
      Overrides:
      expectAtLeast in class AbstractEntityList
      Parameters:
      min - The expected minimal amount, including.
      Returns:
      The list itself.
      See Also:
    • expectAtMost

      public Relation expectAtMost(int max)
      Description copied from interface: EntityList
      Throws if the list contains more than max items.

      Example: EntityList entityList = myQuery.execute(3).expectAtMost(3);

      Specified by:
      expectAtMost in interface EntityList
      Specified by:
      expectAtMost in interface Relation
      Overrides:
      expectAtMost in class AbstractEntityList
      Parameters:
      max - The expected maximal amount, including.
      Returns:
      The list itself.
      See Also:
    • getModel

      public EntityModel getModel()
      Description copied from interface: EntityList
      Get the model of the entity type contained in this list.
      Specified by:
      getModel in interface EntityList
      Returns:
      The model of the entity type contained in this list.
    • getManager

      public EntityManager getManager()
      Description copied from interface: EntityList
      Get the entity manager.
      Specified by:
      getManager in interface EntityList
      Returns:
      The entity manager.
    • getSource

      public Entity getSource()
      Specified by:
      getSource in interface Relation
    • getRelationModel

      public RelationModel getRelationModel()
      Specified by:
      getRelationModel in interface Relation
    • unwrap

      public Relation unwrap()
      Description copied from interface: EntityList
      Unwrap to the underlying entity list.

      Wrappers of entity lists should delegate this to the list they're wrapping, implementations return this. It may be that they cannot, and then return themselves (MultiEntityList).

      Specified by:
      unwrap in interface EntityList
      Specified by:
      unwrap in interface Relation
      Returns:
      The underlying entity list implementation.
    • setPageSize

      public void setPageSize(int pageSize)
      Description copied from interface: EntityList
      Set the page size. The page size determines how many objects will be loaded, once a hollow entity has been accessed.
      Specified by:
      setPageSize in interface EntityList
      Parameters:
      pageSize - The new page size.
    • getPageSize

      public int getPageSize()
      Description copied from interface: EntityList
      Get the current page size.
      Specified by:
      getPageSize in interface EntityList
      Returns:
      The current page size.
    • getPageCount

      public int getPageCount()
      Description copied from interface: EntityList
      Get the number of pages in this list.
      Specified by:
      getPageCount in interface EntityList
      Returns:
      The number of pages in this list (size/pageSize + (size%pageSize>0 ? 1 : 0)).
    • getKeys

      public PrimaryKey[] getKeys()
      Description copied from interface: Relation
      WARNING: this impl may return null entries! This happens when entities of state conception are in the list. Also, after a commit this data is outdated, see class header.
      Specified by:
      getKeys in interface EntityList
      Specified by:
      getKeys in interface Relation
      Returns:
      A defensive copy of the array. The size matches the EntityList.size() method.
    • getKey

      public PrimaryKey getKey(int index)
      Description copied from interface: EntityList
      Returns the PrimaryKey at the specified position.
      Specified by:
      getKey in interface EntityList
    • indexOf

      public int indexOf(PrimaryKey key)
      Description copied from interface: EntityList
      Get the index within the list of the entity with the specified key.
      Specified by:
      indexOf in interface EntityList
      Parameters:
      key - The primary key.
      Returns:
      The index or -1, if there's no such entity in the list.
    • fireRelationChangingEvent

      protected void fireRelationChangingEvent(Entity relatedEntity, boolean added, boolean adjusting)
    • verifyTransactionIsRunning

      protected void verifyTransactionIsRunning(Context context)