use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class IdentityMap method getSnapshotOf.
/**
* Returns the snapshot for the given id. The snapshot contains the corresponding entity's dynamic labels and properties
* as stored during initial load of the entity.
*
* @param entity the entity whos snapshot should be retrieved
* @param entityId the native id of the entity
* @return A snapshot of dynamic labels and properties or an empty optional.
*/
Optional<EntitySnapshot> getSnapshotOf(Object entity, Long entityId) {
EntitySnapshot entitySnapshot;
ClassInfo classInfo = metaData.classInfo(entity);
if (metaData.isRelationshipEntity(classInfo.name())) {
entitySnapshot = this.snapshotsOfRelationshipEntities.get(entityId);
} else {
entitySnapshot = this.snapshotsOfNodeEntities.get(entityId);
}
return Optional.ofNullable(entitySnapshot);
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class MappingContext method replaceRelationshipEntity.
public void replaceRelationshipEntity(Object entity, Long id) {
relationshipEntityRegister.remove(id);
ClassInfo classInfo = metaData.classInfo(entity);
if (classInfo.hasPrimaryIndexField()) {
final Object primaryIndexValue = classInfo.readPrimaryIndexValueOf(entity);
LabelPrimaryId labelPrimaryId = LabelPrimaryId.of(classInfo, primaryIndexValue);
primaryIdToRelationship.remove(labelPrimaryId);
primaryIdToNativeId.remove(labelPrimaryId);
}
addRelationshipEntity(entity, id);
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class MappingContext method addRelationshipEntity.
public Object addRelationshipEntity(Object relationshipEntity, Long id) {
if (relationshipEntityRegister.putIfAbsent(id, relationshipEntity) == null) {
relationshipEntity = relationshipEntityRegister.get(id);
remember(relationshipEntity, id);
ClassInfo classInfo = metaData.classInfo(relationshipEntity);
if (classInfo.hasPrimaryIndexField()) {
final Object primaryIndexValue = classInfo.readPrimaryIndexValueOf(relationshipEntity);
LabelPrimaryId labelPrimaryId = LabelPrimaryId.of(classInfo, primaryIndexValue);
primaryIdToRelationship.put(labelPrimaryId, relationshipEntity);
primaryIdToNativeId.put(labelPrimaryId, id);
}
}
return relationshipEntity;
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class MappingContext method addNodeEntity.
/**
* Adds an entity to the MappingContext.
*
* @param entity The object to add.
* @param id
* @return The object added, never null.
*/
public Object addNodeEntity(Object entity, Long id) {
ClassInfo classInfo = metaData.classInfo(entity);
if (!nodeEntityRegister.containsKey(id)) {
nodeEntityRegister.put(id, entity);
final Object primaryIndexValue = classInfo.readPrimaryIndexValueOf(entity);
if (primaryIndexValue != null) {
LabelPrimaryId key = LabelPrimaryId.of(classInfo, primaryIndexValue);
primaryIndexNodeRegister.putIfAbsent(key, entity);
primaryIdToNativeId.put(key, id);
}
remember(entity, id);
}
return entity;
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class MappingContext method optionalNativeId.
/**
* This method does not trigger a possible {@link IdStrategy} while accessing the identiy- or primary index field.
*
* @param entity The entity in question
* @return An optional native id.
*/
public Optional<Long> optionalNativeId(Object entity) {
ClassInfo classInfo = metaData.classInfo(entity);
if (classInfo == null) {
throw new IllegalArgumentException("Class " + entity.getClass() + " is not a valid entity class. " + "Please check the entity mapping.");
}
if (classInfo.hasIdentityField()) {
FieldInfo identityField = classInfo.identityField();
Object value = identityField.readProperty(entity);
return Optional.ofNullable((Long) value);
} else {
Object primaryIndexValue = classInfo.readPrimaryIndexValueOf(entity);
return Optional.ofNullable(primaryIndexValue).map(v -> primaryIdToNativeId.get(LabelPrimaryId.of(classInfo, v)));
}
}
Aggregations