Search in sources :

Example 21 with ClassInfo

use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.

the class DomainInfoSchemaBuilder method buildRelationships.

private void buildRelationships() {
    for (ClassInfo classInfo : classInfoMap.values()) {
        if (!classInfo.isRelationshipEntity()) {
            String label = classInfo.neo4jName();
            NodeImpl node = (NodeImpl) schema.findNode(label);
            collectRelationshipsInHierarchy(node, classInfo);
        } else {
            String type = classInfo.neo4jName();
            if (schema.getRelationship(type) == null) {
                if (classInfo.getStartNodeReader() == null || classInfo.getEndNodeReader() == null) {
                    logger.warn("Start or end node not found for classInfo={}, is the metadata correct?", classInfo);
                    continue;
                }
                NodeImpl start = getNodeByFieldAndContainingClass(classInfo, classInfo.getStartNodeReader());
                NodeImpl end = getNodeByFieldAndContainingClass(classInfo, classInfo.getEndNodeReader());
                schema.addRelationship(new RelationshipImpl(type, Direction.OUTGOING, start, end));
            }
        }
    }
}
Also used : ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 22 with ClassInfo

use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.

the class ExecuteQueriesDelegate method count.

public long count(Class<?> clazz, Iterable<Filter> filters) {
    ClassInfo classInfo = session.metaData().classInfo(clazz.getSimpleName());
    if (classInfo != null) {
        resolvePropertyAnnotations(clazz, filters);
        CypherQuery query;
        if (classInfo.isRelationshipEntity()) {
            query = new CountStatements().countEdges(classInfo.neo4jName(), filters);
        } else {
            query = new CountStatements().countNodes(classInfo.neo4jName(), filters);
        }
        return count(query, classInfo.isRelationshipEntity());
    }
    throw new RuntimeException(clazz.getName() + " is not a persistable class");
}
Also used : CypherQuery(org.neo4j.ogm.cypher.query.CypherQuery) CountStatements(org.neo4j.ogm.session.request.strategy.impl.CountStatements) ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 23 with ClassInfo

use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.

the class LoadByIdsDelegate method includeMappedEntity.

private <T, ID extends Serializable> boolean includeMappedEntity(Collection<ID> ids, T mapped) {
    final ClassInfo classInfo = session.metaData().classInfo(mapped);
    if (classInfo.hasPrimaryIndexField()) {
        final Object primaryIndexValue = classInfo.readPrimaryIndexValueOf(mapped);
        if (ids.contains(primaryIndexValue)) {
            return true;
        }
    }
    Object id = EntityUtils.identity(mapped, session.metaData());
    return ids.contains(id);
}
Also used : ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 24 with ClassInfo

use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.

the class LoadByIdsDelegate method sortResultsByIds.

private <T, ID extends Serializable> Set<T> sortResultsByIds(Class<T> type, Collection<ID> ids, Iterable<T> mapped) {
    Map<ID, T> items = new HashMap<>();
    ClassInfo classInfo = session.metaData().classInfo(type.getName());
    Function<Object, Optional<Object>> primaryIndexOrIdReader = classInfo.getPrimaryIndexOrIdReader();
    for (T t : mapped) {
        primaryIndexOrIdReader.apply(t).ifPresent(id -> items.put((ID) id, t));
    }
    Set<T> results = new LinkedHashSet<>();
    for (ID id : ids) {
        T item = items.get(id);
        if (item != null) {
            results.add(item);
        }
    }
    return results;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Optional(java.util.Optional) HashMap(java.util.HashMap) ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 25 with ClassInfo

use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.

the class LoadByInstancesDelegate method loadAll.

public <T> Collection<T> loadAll(Collection<T> objects, SortOrder sortOrder, Pagination pagination, int depth) {
    if (objects == null || objects.isEmpty()) {
        return objects;
    }
    ClassInfo commonClassInfo = findCommonClassInfo(objects);
    Function<Object, Optional<Object>> primaryIndexOrIdReader = commonClassInfo.getPrimaryIndexOrIdReader();
    Set<Serializable> ids = objects.stream().map(primaryIndexOrIdReader::apply).filter(Optional::isPresent).map(Optional::get).map(Serializable.class::cast).collect(toCollection(LinkedHashSet::new));
    return session.loadAll((Class<T>) commonClassInfo.getUnderlyingClass(), ids, sortOrder, pagination, depth);
}
Also used : Serializable(java.io.Serializable) Optional(java.util.Optional) 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