Search in sources :

Example 16 with ClassInfo

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();
        }
    }
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 17 with ClassInfo

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());
    }
}
Also used : HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 18 with ClassInfo

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;
}
Also used : DirectedRelationshipForType(org.neo4j.ogm.context.DirectedRelationshipForType) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 19 with ClassInfo

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;
}
Also used : BaseClassNotFoundException(org.neo4j.ogm.exception.core.BaseClassNotFoundException) ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 20 with ClassInfo

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);
}
Also used : ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Aggregations

ClassInfo (org.neo4j.ogm.metadata.ClassInfo)145 FieldInfo (org.neo4j.ogm.metadata.FieldInfo)100 Test (org.junit.Test)76 ArrayList (java.util.ArrayList)11 HashSet (java.util.HashSet)8 MetaData (org.neo4j.ogm.metadata.MetaData)8 CompileContext (org.neo4j.ogm.cypher.compiler.CompileContext)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 NodeBuilder (org.neo4j.ogm.cypher.compiler.NodeBuilder)5 MappingException (org.neo4j.ogm.exception.core.MappingException)5 RowModel (org.neo4j.ogm.model.RowModel)5 Collection (java.util.Collection)4 LinkedHashSet (java.util.LinkedHashSet)4 List (java.util.List)4 Optional (java.util.Optional)4 CypherQuery (org.neo4j.ogm.cypher.query.CypherQuery)4 Member (org.neo4j.ogm.domain.forum.Member)4 Satellite (org.neo4j.ogm.domain.satellites.Satellite)4 Collections (java.util.Collections)3