AshwoodEntitySorter (cayenne-doc: Cayenne Documentation 5.0-M2 API)
Description: declaration: package: org.apache.cayenne.ashwood, class: AshwoodEntitySorter

# Class AshwoodEntitySorter

java.lang.Object
org.apache.cayenne.ashwood.AshwoodEntitySorter

All Implemented Interfaces:
  `EntitySorter`

Direct Known Subclasses:
  `WeightedAshwoodEntitySorter`

public class AshwoodEntitySorter extends Object implements EntitySorter
Implements dependency sorting algorithms for ObjEntities, DbEntities and Persistent objects. Presently it works for acyclic database schemas with possible multi-reflexive tables.

Since:
  3.1

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected Map<DbEntity, org.apache.cayenne.ashwood.AshwoodEntitySorter.ComponentRecord>`
  `components`
  `protected Comparator<DbEntity>`
  `dbEntityComparator`
  `protected EntityResolver`
  `entityResolver`
  `protected Comparator<ObjEntity>`
  `objEntityComparator`
  `protected Map<DbEntity, List<DbRelationship>>`
  `reflexiveDbEntities`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AshwoodEntitySorter()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected <E> Digraph<E,Boolean>`
  `buildDigraph(ObjEntity objEntity, List<E> objects, Function<E, Persistent> converter)`
  `protected void`
  `doIndexSorter()`
  Reindexes internal sorter without synchronization.
  `protected Persistent`
  `findReflexiveMaster(Persistent object, ObjRelationship toOneRel, String targetEntityName)`
  `Comparator<DbEntity>`
  `getDbEntityComparator()`
  `protected Comparator<DbEntity>`
  `getDbEntityComparator(boolean dependantFirst)`
  `Comparator<ObjEntity>`
  `getObjEntityComparator()`
  `protected Comparator<ObjEntity>`
  `getObjEntityComparator(boolean dependantFirst)`
  `protected String[]`
  `getReflexiveRelationshipsNames(ObjEntity objEntity)`
  `protected void`
  `indexSorter()`
  Reindexes internal sorter in a thread-safe manner.
  `boolean`
  `isReflexive(DbEntity metadata)`
  `void`
  `setEntityResolver(EntityResolver entityResolver)`
  Sets EntityResolver for this sorter.
  `void`
  `sortDbEntities(List<DbEntity> dbEntities, boolean deleteOrder)`
  Sorts a list of DbEntities.
  `void`
  `sortObjectsForEntity(ObjEntity objEntity, List<?> objects, boolean deleteOrder)`
  Sorts a list of objects belonging to the ObjEntity.
  `protected <E> void`
  `sortObjectsForEntity(ObjEntity objEntity, List<E> objects, boolean deleteOrder, Function<E, Persistent> converter)`
  `void`
  `sortObjEntities(List<ObjEntity> objEntities, boolean deleteOrder)`
  Sorts a list of ObjEntities.
  `protected <E> boolean`
  `topologicalSort(List<E> data, Digraph<E,Boolean> graph, boolean reverse)`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### entityResolver

    protected EntityResolver entityResolver

  - ### components

    protected Map<DbEntity, org.apache.cayenne.ashwood.AshwoodEntitySorter.ComponentRecord> components

  - ### reflexiveDbEntities

    protected Map<DbEntity, List<DbRelationship>> reflexiveDbEntities

  - ### dbEntityComparator

    protected Comparator<DbEntity> dbEntityComparator

  - ### objEntityComparator

    protected Comparator<ObjEntity> objEntityComparator

- ## Constructor Details

  - ### AshwoodEntitySorter

    public AshwoodEntitySorter()

- ## Method Details

  - ### indexSorter

    protected void indexSorter()
    Reindexes internal sorter in a thread-safe manner.

  - ### doIndexSorter

    protected void doIndexSorter()
    Reindexes internal sorter without synchronization.

  - ### setEntityResolver

    public void setEntityResolver(EntityResolver entityResolver)
    Description copied from interface: `EntitySorter`
    Sets EntityResolver for this sorter. All entities present in the resolver will be used to determine sort ordering.
    Specified by:
      `setEntityResolver` in interface `EntitySorter`
    Since:
      3.1

  - ### sortDbEntities

    public void sortDbEntities(List<DbEntity> dbEntities, boolean deleteOrder)
    Description copied from interface: `EntitySorter`
    Sorts a list of DbEntities.
    Specified by:
      `sortDbEntities` in interface `EntitySorter`

  - ### sortObjEntities

    public void sortObjEntities(List<ObjEntity> objEntities, boolean deleteOrder)
    Description copied from interface: `EntitySorter`
    Sorts a list of ObjEntities.
    Specified by:
      `sortObjEntities` in interface `EntitySorter`

  - ### sortObjectsForEntity

    public void sortObjectsForEntity(ObjEntity objEntity, List<?> objects, boolean deleteOrder)
    Description copied from interface: `EntitySorter`
    Sorts a list of objects belonging to the ObjEntity.
    Specified by:
      `sortObjectsForEntity` in interface `EntitySorter`

  - ### sortObjectsForEntity

    protected <E> void sortObjectsForEntity(ObjEntity objEntity, List<E> objects, boolean deleteOrder, Function<E, Persistent> converter)

  - ### buildDigraph

    protected <E> Digraph<E,Boolean> buildDigraph(ObjEntity objEntity, List<E> objects, Function<E, Persistent> converter)

  - ### topologicalSort

    protected <E> boolean topologicalSort(List<E> data, Digraph<E,Boolean> graph, boolean reverse)

  - ### getReflexiveRelationshipsNames

    protected String[] getReflexiveRelationshipsNames(ObjEntity objEntity)

  - ### findReflexiveMaster

    protected Persistent findReflexiveMaster(Persistent object, ObjRelationship toOneRel, String targetEntityName)

  - ### getDbEntityComparator

    public Comparator<DbEntity> getDbEntityComparator()
    Specified by:
      `getDbEntityComparator` in interface `EntitySorter`
    Returns:
      comparator for `DbEntity`

  - ### getObjEntityComparator

    public Comparator<ObjEntity> getObjEntityComparator()
    Specified by:
      `getObjEntityComparator` in interface `EntitySorter`
    Returns:
      comparator for `ObjEntity`

  - ### getDbEntityComparator

    protected Comparator<DbEntity> getDbEntityComparator(boolean dependantFirst)

  - ### getObjEntityComparator

    protected Comparator<ObjEntity> getObjEntityComparator(boolean dependantFirst)

  - ### isReflexive

    public boolean isReflexive(DbEntity metadata)
    Specified by:
      `isReflexive` in interface `EntitySorter`
    Parameters:
      `metadata` - to check
    Returns:
      is entity has reflexive relationships