use of org.neo4j.ogm.metadata.AnnotationInfo in project neo4j-ogm by neo4j.
the class SessionDelegate method resolvePropertyName.
private String resolvePropertyName(Class entityType, String propertyName) {
ClassInfo classInfo = session.metaData().classInfo(entityType.getName());
FieldInfo fieldInfo = classInfo.propertyFieldByName(propertyName);
if (fieldInfo != null && fieldInfo.getAnnotations() != null) {
AnnotationInfo annotation = fieldInfo.getAnnotations().get(Property.class);
if (annotation != null) {
return annotation.get(Property.NAME, propertyName);
}
}
return propertyName;
}
use of org.neo4j.ogm.metadata.AnnotationInfo in project neo4j-ogm by neo4j.
the class SessionDelegate method updateRelationship.
private void updateRelationship(FilterWithRelationship filter, FieldInfo fieldInfo, String relationshipType) {
filter.setRelationshipType(relationshipType);
filter.setRelationshipDirection(Direction.UNDIRECTED);
if (fieldInfo.getAnnotations() != null) {
AnnotationInfo annotation = fieldInfo.getAnnotations().get(Relationship.class);
if (annotation != null) {
filter.setRelationshipType(annotation.get(Relationship.TYPE, relationshipType));
Direction direction = Direction.valueOf(annotation.get(Relationship.DIRECTION, Direction.UNDIRECTED.name()));
filter.setRelationshipDirection(direction);
}
if (fieldInfo.getAnnotations().get(StartNode.class) != null) {
filter.setRelationshipDirection(Direction.OUTGOING);
}
if (fieldInfo.getAnnotations().get(EndNode.class) != null) {
filter.setRelationshipDirection(Direction.INCOMING);
}
}
}
use of org.neo4j.ogm.metadata.AnnotationInfo in project neo4j-ogm by neo4j.
the class EntityGraphMapper method map.
@Override
public CompileContext map(Object entity, int horizon) {
this.currentDepth.set(0);
if (entity == null) {
throw new NullPointerException("Cannot map null object");
}
// won't be modified by the mapping request.
for (MappedRelationship mappedRelationship : mappingContext.getRelationships()) {
LOGGER.debug("context-init: ({})-[:{}]->({})", mappedRelationship.getStartNodeId(), mappedRelationship.getRelationshipType(), mappedRelationship.getEndNodeId());
compiler.context().registerRelationship(mappedRelationship);
}
LOGGER.debug("context initialised with {} relationships", mappingContext.getRelationships().size());
// and then ensure the relationship between the two is created or updated as necessary
if (isRelationshipEntity(entity)) {
ClassInfo reInfo = metaData.classInfo(entity);
Object startNode = reInfo.getStartNodeReader().read(entity);
if (startNode == null) {
throw new RuntimeException("@StartNode of relationship entity may not be null");
}
Object endNode = reInfo.getEndNodeReader().read(entity);
if (endNode == null) {
throw new RuntimeException("@EndNode of relationship entity may not be null");
}
// map both sides as far as the specified horizon
NodeBuilder startNodeBuilder = mapEntity(startNode, horizon);
NodeBuilder endNodeBuilder = mapEntity(endNode, horizon);
// create or update the relationship if its not already been visited in the current compile context
if (!compiler.context().visitedRelationshipEntity(mappingContext.nativeId(entity))) {
AnnotationInfo annotationInfo = reInfo.annotationsInfo().get(RelationshipEntity.class);
String relationshipType = annotationInfo.get(RelationshipEntity.TYPE, null);
DirectedRelationship directedRelationship = new DirectedRelationship(relationshipType, Direction.OUTGOING);
RelationshipBuilder relationshipBuilder = getRelationshipBuilder(compiler, entity, directedRelationship, mappingContext.isDirty(entity));
// 2. create or update the actual relationship (edge) in the graph
updateRelationshipEntity(compiler.context(), entity, relationshipBuilder, reInfo);
Long srcIdentity = mappingContext.nativeId(startNode);
Long tgtIdentity = mappingContext.nativeId(endNode);
RelationshipNodes relNodes = new RelationshipNodes(srcIdentity, tgtIdentity, startNode.getClass(), endNode.getClass());
// 2. update the fact of the relationship in the compile context
updateRelationship(compiler.context(), startNodeBuilder, endNodeBuilder, relationshipBuilder, relNodes);
}
} else {
// not an RE, simply map the entity
mapEntity(entity, horizon);
}
deleteObsoleteRelationships();
return compiler.context();
}
use of org.neo4j.ogm.metadata.AnnotationInfo in project neo4j-ogm by neo4j.
the class EntityGraphMapper method updateRelationshipEntity.
private void updateRelationshipEntity(CompileContext context, Object relationshipEntity, RelationshipBuilder relationshipBuilder, ClassInfo relEntityClassInfo) {
Long reIdentity = mappingContext.nativeId(relationshipEntity);
context.visitRelationshipEntity(reIdentity);
AnnotationInfo annotation = relEntityClassInfo.annotationsInfo().get(RelationshipEntity.class);
if (relationshipBuilder.type() == null) {
relationshipBuilder.setType(annotation.get(RelationshipEntity.TYPE, relEntityClassInfo.name()));
}
// if the RE is new, register it in the context so that we can set its ID correctly when it is created,
if (reIdentity < 0) {
context.registerNewObject(reIdentity, relationshipEntity);
}
updateFieldsOnBuilder(relationshipEntity, relationshipBuilder, relEntityClassInfo);
}
Aggregations