Class ManagerBackedItemForest

Object
ManagerBackedItemForest
All Implemented Interfaces:
ItemForest, RowRetriever

public class ManagerBackedItemForest extends Object implements ItemForest
  • Constructor Details

    • ManagerBackedItemForest

      public ManagerBackedItemForest(@NotNull Forest forest, @NotNull RowManager rowManager)
    • ManagerBackedItemForest

      public ManagerBackedItemForest(@NotNull Forest forest, @NotNull RowManager rowManager, @Nullable ItemAccessMode defaultAccessMode)
  • Method Details

    • getForest

      @NotNull public Forest getForest()
      Specified by:
      getForest in interface ItemForest
    • getRow

      @NotNull public StructureRow getRow(long rowId, @NotNull ItemAccessMode access) throws MissingRowException
      Description copied from interface: RowRetriever

      Retrieves StructureRow with additional information about how the calling code is going to use method StructureRow.getItem(java.lang.Class<I>). The implementation may be optimized according to the access parameter.

      If row's item is invisible or does not exist, StructureRow is returned anyway, but StructureRow.getItem(java.lang.Class<I>) return null.

      Specified by:
      getRow in interface RowRetriever
      Parameters:
      rowId - row ID
      access - defines how item object is going to be accessed
      Returns:
      row instance
      Throws:
      MissingRowException - if the specified row ID does not exist
      See Also:
    • scanRows

      public void scanRows(@Nullable LongIterable rows, boolean sorted, @NotNull ItemAccessMode access, @Nullable LongCollector missingCollector, @NotNull Predicate<StructureRow> iteratee) throws MissingRowException
      Description copied from interface: RowRetriever

      Loads multiple rows by their IDs and calls iteratee with a StructureRow for each row ID in the input. Use this method whenever you need to read a potentially large amount of rows and the order of retrieval is not important.

      For example, use scanRows to iterate through the whole forest to see if it has a generator row, or to process user input that has an array of row IDs.

      The order in which iteratee is called is not guaranteed to be the same as the iteration order of rows. Likewise, missingCollector may receive row IDs out of order.

      The implementation of iteratee must be reasonably fast and avoid taking locks or accessing long-running services. It's possible to call other RowRetriever methods inside iteratee.

      It's possible to pass LongIterator as LongIterable - the iterator() method is guaranteed to be called only once.

      Item access mode

      You can choose an appropriate value for the access parameter based on what you're going to do with rows in the iteratee. This allows the provider of StructureRow instances to optimize how StructureRow.getItem(java.lang.Class<I>) method works.

      Dealing with missing rows

      If a row ID in the input stream does not correspond to an existing row, the behavior depends on whether the missingCollector parameter is set. If it's null, then the method will immediately throw a MissingRowException. If it's not null, the collector will be called with the missing row ID.

      To simply ignore the missing rows, you can use RowRetriever.IGNORE_MISSING_ROWS collector or use one of the RowRetriever.scanAllExistingRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, java.util.function.Consumer<com.almworks.jira.structure.api.row.StructureRow>) methods.

      Note that if the current user does not have access to a row, but the row itself exists, it's not considered missing.

      Super-root

      Note that normally a row retriever does not handle SuperRootRow in any special way, so it will be a case of a missing row. Some implementations may, however, support accessing the super-root.

      Implementation notes

      The default implementation is based on calling RowRetriever.getRow(long). Specific implementations should optimize this method for retrieving multiple rows at once.

      Do not override other bulk scanning methods, unless that allows for additional optimization.

      Specified by:
      scanRows in interface RowRetriever
      Parameters:
      rows - row IDs of the rows to scan
      sorted - if true, then the caller guarantees the row IDs to be sorted - this can be used for optimization
      access - indicates how the getItem() method of the provided StructureRow is going to be used and allows to skip the access checking
      missingCollector - a collector to receive non-existing row IDs, or null
      iteratee - predicate to call for each resolved row; if it returns false, the iteration stops and the method returns
      Throws:
      MissingRowException - if a row was not found and missingCollector is null
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object