use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class MappingContext method deregisterDependentRelationshipEntity.
/**
* Deregister a relationship entity if it has either start or end node equal to the supplied startOrEndEntity
*
* @param startOrEndEntity the entity that might be the start or end node of a relationship entity
*/
private void deregisterDependentRelationshipEntity(Object startOrEndEntity) {
Iterator<Long> relationshipEntityIdIterator = relationshipEntityRegister.keySet().iterator();
while (relationshipEntityIdIterator.hasNext()) {
Long relationshipEntityId = relationshipEntityIdIterator.next();
Object relationshipEntity = relationshipEntityRegister.get(relationshipEntityId);
final ClassInfo classInfo = metaData.classInfo(relationshipEntity);
FieldInfo startNodeReader = classInfo.getStartNodeReader();
FieldInfo endNodeReader = classInfo.getEndNodeReader();
if (startOrEndEntity == startNodeReader.read(relationshipEntity) || startOrEndEntity == endNodeReader.read(relationshipEntity)) {
relationshipEntityIdIterator.remove();
}
}
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class MappingContext method removeAllInAndOutcomingRelationshipsOf.
private void removeAllInAndOutcomingRelationshipsOf(Long id) {
Set<Object> relEntitiesToPurge = new HashSet<>();
Iterator<MappedRelationship> mappedRelationshipIterator = relationshipRegister.iterator();
while (mappedRelationshipIterator.hasNext()) {
MappedRelationship mappedRelationship = mappedRelationshipIterator.next();
if (mappedRelationship.getStartNodeId() == id || mappedRelationship.getEndNodeId() == id) {
// first purge any RE mappings (if its a RE)
if (mappedRelationship.getRelationshipId() != null) {
Object relEntity = relationshipEntityRegister.get(mappedRelationship.getRelationshipId());
if (relEntity != null) {
relEntitiesToPurge.add(relEntity);
}
}
// finally remove the mapped relationship
mappedRelationshipIterator.remove();
}
}
// Purge the relationship entities.
for (Object relEntity : relEntitiesToPurge) {
ClassInfo relClassInfo = metaData.classInfo(relEntity);
purge(relEntity, relClassInfo.getUnderlyingClass());
}
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class EntityAccessManager method getIterableField.
/**
* Returns an FieldWriter for an iterable of a non-primitive scalar type defined by a ClassInfo
*
* @param classInfo the ClassInfo (or a superclass thereof) declaring the iterable relationship
* @param relationshipType the name of the relationship as it is in the graph
* @param relationshipDirection the direction of the relationship as it is in the graph
* @param parameterType the type that will be iterated over
* @return a valid FieldWriter or null if none is found
*/
public static FieldInfo getIterableField(ClassInfo classInfo, Class<?> parameterType, String relationshipType, Direction relationshipDirection) {
final ClassInfo lookupClassInfo = classInfo;
final DirectedRelationshipForType directedRelationshipForType = new DirectedRelationshipForType(relationshipType, relationshipDirection, parameterType);
final Map<DirectedRelationshipForType, FieldInfo> typeFieldInfoMap = iterableWriterCache.computeIfAbsent(lookupClassInfo, key -> new ConcurrentHashMap<>());
if (typeFieldInfoMap.containsKey(directedRelationshipForType)) {
return typeFieldInfoMap.get(directedRelationshipForType);
}
while (classInfo != null) {
// 1st find a field annotated with type and direction
FieldInfo fieldInfo = getIterableFieldInfo(classInfo, parameterType, relationshipType, relationshipDirection, STRICT_MODE);
if (fieldInfo != null) {
cacheIterableFieldWriter(lookupClassInfo, parameterType, relationshipType, relationshipDirection, directedRelationshipForType, fieldInfo, fieldInfo);
return fieldInfo;
}
if (relationshipDirection != Direction.INCOMING) {
// 3rd, find a field with implied type and direction
fieldInfo = getIterableFieldInfo(classInfo, parameterType, relationshipType, relationshipDirection, INFERRED_MODE);
if (fieldInfo != null) {
cacheIterableFieldWriter(lookupClassInfo, parameterType, relationshipType, relationshipDirection, directedRelationshipForType, fieldInfo, fieldInfo);
return fieldInfo;
}
}
classInfo = classInfo.directSuperclass();
}
return null;
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class EntityFactory method resolve.
private String resolve(String... taxa) {
String fqn = taxaLeafClass.get(Arrays.toString(taxa));
if (fqn == null) {
ClassInfo classInfo = metadata.resolve(taxa);
if (classInfo == null) {
throw new BaseClassNotFoundException(Arrays.toString(taxa));
}
fqn = classInfo.name();
taxaLeafClass.put(Arrays.toString(taxa), fqn);
}
return fqn;
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class DomainInfoSchemaBuilder method createRelationship.
private void createRelationship(NodeImpl fromNode, FieldInfo relFieldInfo) {
Class<?> otherClass = DescriptorMappings.getType(relFieldInfo.getTypeDescriptor());
String otherType = otherClass.getName();
ClassInfo otherClassInfo = classInfoMap.get(otherType);
if (otherClassInfo == null) {
logger.debug("Type " + otherType + " not found. Did you specify 'packages' parameter to " + "SessionFactory correctly?");
return;
}
NodeImpl toNode;
if (otherClassInfo.isRelationshipEntity()) {
if (relFieldInfo.relationshipDirection() == Direction.OUTGOING) {
toNode = getNodeByFieldAndContainingClass(otherClassInfo, otherClassInfo.getEndNodeReader());
} else {
// this will cover both incoming and UNDIRECTED
// start and end type for UNDIRECTED should be same
toNode = getNodeByFieldAndContainingClass(otherClassInfo, otherClassInfo.getStartNodeReader());
}
} else {
toNode = (NodeImpl) schema.findNode(otherClassInfo.neo4jName());
}
RelationshipImpl relationship = new RelationshipImpl(relFieldInfo.relationshipType(), relFieldInfo.relationshipDirection(), fromNode, toNode);
// add relationship only to fromNode, not adding to toNode because
// - it might not declare the relationship
// - if it does it is different direction, may have different type other side (e.g. super type of fromNode)
// - the relationship will be created when toNode is processed
fromNode.addRelationship(relFieldInfo.getName(), relationship);
}
Aggregations