Package org.neo4j.ogm.context
Class MappingContext
java.lang.Object
org.neo4j.ogm.context.MappingContext
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddNodeEntity
(Object entity) Adds an entity to the MappingContext.addNodeEntity
(Object entity, Long id) Adds an entity to the MappingContext.void
addRelationship
(MappedRelationship relationship) addRelationshipEntity
(Object relationshipEntity, Long id) void
clear()
boolean
containsRelationship
(MappedRelationship relationship) boolean
detachNodeEntity
(Long id) boolean
getNodeEntity
(Long graphId) Gets a node entity from the MappingContext by its graph id.getNodeEntityById
(ClassInfo classInfo, Object id) Get a node entity from the MappingContext by its primary idgetRelationshipEntity
(Long relationshipId) getRelationshipEntityById
(ClassInfo classInfo, Object id) Get a relationship entity from MappingContext by primary idboolean
Check if the entity has been modified by comparing its current state to the state it had when registered.neighbours
(Object entity) Get related objects of an entity / relationship.optionalNativeId
(Object entity) This method does not trigger a possibleIdStrategy
while accessing the identiy- or primary index field.void
removeType
(Class<?> type) purges all information about objects of the supplied type from the mapping context.void
replaceNodeEntity
(Object entity, Long identity) void
replaceRelationshipEntity
(Object entity, Long id) void
purges all information about this object from the mapping context and also sets its id to null.
-
Constructor Details
-
MappingContext
-
-
Method Details
-
getNodeEntity
Gets a node entity from the MappingContext by its graph id. NOTE: to get entity by field with @Id usegetNodeEntityById(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
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
Adds an entity to the MappingContext.- Parameters:
entity
- The object to add.- Returns:
- The object added, never null.
-
addNodeEntity
Adds an entity to the MappingContext.- Parameters:
entity
- The object to add.id
-- Returns:
- The object added, never null.
-
replaceNodeEntity
-
replaceRelationshipEntity
-
isDirty
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
-
getRelationships
-
addRelationship
-
clear
public void clear() -
getSnapshotOfRelationshipEntityRegister
-
getRelationshipEntity
-
getRelationshipEntityById
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
-
removeType
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
-
detachRelationshipEntity
-
reset
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
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
This method does not trigger a possibleIdStrategy
while accessing the identiy- or primary index field.- Parameters:
entity
- The entity in question- Returns:
- An optional native id.
-
nativeId
-