use of org.neo4j.ogm.context.DirectedRelationship in project neo4j-ogm by neo4j.
the class EntityAccessManager method getRelationalReader.
/**
* Returns a FieldInfo for a scalar type definition on a ClassInfo that is not a primitive graph property
*
* @param classInfo A ClassInfo declaring the type definition
* @param relationshipType The name of the relationship in the graph
* @param relationshipDirection The direction of the relationship in the graph
* @return A FieldInfo or null if none exists
*/
public static FieldInfo getRelationalReader(ClassInfo classInfo, String relationshipType, Direction relationshipDirection) {
final DirectedRelationship directedRelationship = new DirectedRelationship(relationshipType, relationshipDirection);
final Map<DirectedRelationship, FieldInfo> relationshipFieldInfoMap = relationalReaderCache.computeIfAbsent(classInfo, key -> new ConcurrentHashMap<>());
if (relationshipFieldInfoMap.containsKey(directedRelationship)) {
return relationshipFieldInfoMap.get(directedRelationship);
}
while (classInfo != null) {
// 1st, try to find a field explicitly annotated with the neo4j relationship type and direction
FieldInfo fieldInfo = classInfo.relationshipField(relationshipType, relationshipDirection, STRICT_MODE);
if (fieldInfo != null && !fieldInfo.getAnnotations().isEmpty()) {
relationshipFieldInfoMap.put(directedRelationship, fieldInfo);
return fieldInfo;
}
// If it's outgoing, then proceed to find other matches
if (relationshipDirection != Direction.INCOMING) {
// 3rd, try to find a field annotated with the neo4j relationship type and direction, allowing for implied relationships
fieldInfo = classInfo.relationshipField(relationshipType, relationshipDirection, INFERRED_MODE);
if (fieldInfo != null && !fieldInfo.getAnnotations().isEmpty()) {
relationshipFieldInfoMap.put(directedRelationship, fieldInfo);
return fieldInfo;
}
// 4th, try to find a "XYZ" field name where XYZ is derived from the relationship type
if (fieldInfo != null) {
relationshipFieldInfoMap.put(directedRelationship, fieldInfo);
return fieldInfo;
}
}
classInfo = classInfo.directSuperclass();
}
return null;
}
Aggregations