Class MappingContext

java.lang.Object
org.neo4j.ogm.context.MappingContext

public class MappingContext extends Object
The MappingContext maintains a map of all the objects created during the hydration of an object map (domain hierarchy). The MappingContext lifetime is concurrent with a session lifetime.
Author:
Vince Bickers, Luanne Misquitta, Mark Angrish, Michael J. Simons
  • Constructor Details

    • MappingContext

      public MappingContext(MetaData metaData)
  • Method Details

    • getNodeEntity

      public Object getNodeEntity(Long graphId)
      Gets a node entity from the MappingContext by its graph id. NOTE: to get entity by field with @Id use getNodeEntityById(ClassInfo, Object) - you also need to check if such id exists and is of correct type
      Parameters:
      graphId - The graph id to look for.
      Returns:
      The entity or null if not found.
    • getNodeEntityById

      public Object getNodeEntityById(ClassInfo classInfo, Object id)
      Get a node entity from the MappingContext by its primary id
      Parameters:
      classInfo - class info of the entity (this must be provided because id itself is not unique)
      id - primary id of the entity
      Returns:
      the entity or null if not found
    • addNodeEntity

      public Object addNodeEntity(Object entity)
      Adds an entity to the MappingContext.
      Parameters:
      entity - The object to add.
      Returns:
      The object added, never null.
    • addNodeEntity

      public Object addNodeEntity(Object entity, Long id)
      Adds an entity to the MappingContext.
      Parameters:
      entity - The object to add.
      id -
      Returns:
      The object added, never null.
    • replaceNodeEntity

      public void replaceNodeEntity(Object entity, Long identity)
    • replaceRelationshipEntity

      public void replaceRelationshipEntity(Object entity, Long id)
    • isDirty

      public boolean isDirty(Object entity)
      Check if the entity has been modified by comparing its current state to the state it had when registered. TBD : describe how the hash is computed. Not sure if it is a real deep hash.
      Parameters:
      entity - The entity to check
      Returns:
      true if the entity was changed, false otherwise.
    • containsRelationship

      public boolean containsRelationship(MappedRelationship relationship)
    • getRelationships

      public Set<MappedRelationship> getRelationships()
    • addRelationship

      public void addRelationship(MappedRelationship relationship)
    • clear

      public void clear()
    • getSnapshotOfRelationshipEntityRegister

      public Map<Long,Object> getSnapshotOfRelationshipEntityRegister()
    • getRelationshipEntity

      public Object getRelationshipEntity(Long relationshipId)
    • getRelationshipEntityById

      public Object getRelationshipEntityById(ClassInfo classInfo, Object id)
      Get a relationship entity from MappingContext by primary id
      Parameters:
      classInfo - classInfo of the relationship entity (it is needed to because primary id may not be unique across all relationship types)
      id - primary id of the entity
      Returns:
      relationship entity
    • addRelationshipEntity

      public Object addRelationshipEntity(Object relationshipEntity, Long id)
    • removeType

      public void removeType(Class<?> type)
      purges all information about objects of the supplied type from the mapping context. If the type is an interface, purges all implementing classes in the interface hierarchy
      Parameters:
      type - the type whose object references and relationship mappings we want to purge
    • detachNodeEntity

      public boolean detachNodeEntity(Long id)
    • detachRelationshipEntity

      public boolean detachRelationshipEntity(Long id)
    • reset

      public void reset(Object entity)
      purges all information about this object from the mapping context and also sets its id to null. Should be called for new objects that have had their id assigned as part of a long-running transaction, if that transaction is subsequently rolled back.
      Parameters:
      entity - the instance whose references and relationship mappings we want to reset
    • neighbours

      public Set<Object> neighbours(Object entity)
      Get related objects of an entity / relationship. Used in deletion scenarios.
      Parameters:
      entity - The entity to look neighbours for.
      Returns:
      If entity is a relationship, end and start nodes. If entity is a node, the relations pointing to it.
    • optionalNativeId

      public Optional<Long> optionalNativeId(Object entity)
      This method does not trigger a possible IdStrategy while accessing the identiy- or primary index field.
      Parameters:
      entity - The entity in question
      Returns:
      An optional native id.
    • nativeId

      public Long nativeId(Object entity)