Class PrimaryKeyEntityList

java.lang.Object
ch.tocco.nice2.persist.core.api.entity.AbstractEntityList
ch.tocco.nice2.persist.core.api.util.PrimaryKeyEntityList
All Implemented Interfaces:
EntityList, Iterable<Entity>

public class PrimaryKeyEntityList extends AbstractEntityList
EntityList implementation for a list of primary keys. The entity is loaded (via `retrieve`) on each `get()`.
  • Constructor Details

  • Method Details

    • size

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

      public boolean contains(PrimaryKey pk)
      Description copied from interface: EntityList
      Determine, whether the list contains an entity with the specified key.
      Specified by:
      contains in interface EntityList
      Overrides:
      contains in class AbstractEntityList
      Parameters:
      pk - The primary key.
      Returns:
      true, if there's an entity with the specified key, false otherwise.
    • getKeys

      public PrimaryKey[] getKeys()
      Description copied from interface: EntityList
      Read in subclasses if this array can contain null values or not.
      Returns:
      A defensive copy of the array. The size matches the EntityList.size() method.
    • get

      public Entity get(int index, boolean eager) throws PersistException
      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.
      Throws:
      PersistException
    • get

      @Nullable public @Nullable Entity get(PrimaryKey key, boolean eager) throws PersistException
      Description copied from interface: EntityList
      Get the entity with the specified key in that list.
      Specified by:
      get in interface EntityList
      Overrides:
      get in class AbstractEntityList
      Parameters:
      key - The key of the entity.
      eager - true, if a page should be eagerly loaded, if the entity's state is hollow, false otherwise.
      Returns:
      The entity with the specified key potentially in unusable state, or null.
      Throws:
      PersistException
    • getKey

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

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

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

      public EntityManager getManager()
      Description copied from interface: EntityList
      Get the entity manager.
      Returns:
      The entity manager.
    • unwrap

      public EntityList 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).

      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.
      Parameters:
      pageSize - The new page size.
    • getPageSize

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

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