Search in sources :

Example 76 with ClassInfo

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

the class SaveEventDelegate method dirty.

// returns true if the object in question is dirty (has changed)
// an object is dirty if either or both of:
// - its properties have changed
// - its relationships has changed
private boolean dirty(Object parent) {
    // have any properties changed
    if (this.session.context().isDirty(parent)) {
        logger.debug("dirty: {}", parent);
        return true;
    }
    ClassInfo parentInfo = this.session.metaData().classInfo(parent);
    long parentId = session.context().nativeId(parent);
    // an RE cannot contain additional refs because hyperedges are forbidden in Neo4j
    if (!parentInfo.isRelationshipEntity()) {
        // build the set of mapped relationships for this object. if there any new ones, the object is dirty
        for (FieldInfo reader : relationalReaders(parent)) {
            clearPreviousRelationships(parentId, reader);
            for (MappedRelationship mappable : map(parentInfo, parentId, reader.read(parent), reader)) {
                if (isNew(mappable)) {
                    logger.debug("added new relationship: {} to {}", mappable, parent);
                    this.addedRelationships.add(mappable);
                    return true;
                }
                this.registeredRelationships.add(mappable);
                // no longer deleted
                this.deletedRelationships.remove(mappable);
            }
        }
        for (MappedRelationship previous : session.context().getRelationships()) {
            if (isDeleted(previous) && (previous.getStartNodeId() == parentId || previous.getEndNodeId() == parentId)) {
                logger.debug("deleted: {} from {}", previous, parent);
                return true;
            }
        }
    }
    return false;
}
Also used : MappedRelationship(org.neo4j.ogm.context.MappedRelationship) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 77 with ClassInfo

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

the class SessionDelegate method resolveRelationshipType.

private void resolveRelationshipType(Filter filter) {
    ClassInfo classInfo = session.metaData().classInfo(filter.getOwnerEntityType().getName());
    FieldInfo fieldInfo = classInfo.relationshipFieldByName(filter.getNestedPropertyName());
    String defaultRelationshipType = RelationshipUtils.inferRelationshipType(filter.getNestedPropertyName());
    updateRelationship(filter, fieldInfo, defaultRelationshipType);
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 78 with ClassInfo

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

the class SessionDelegate method resolvePropertyAnnotations.

void resolvePropertyAnnotations(Class entityType, Iterable<Filter> filters) {
    for (Filter filter : filters) {
        if (filter.getOwnerEntityType() == null) {
            filter.setOwnerEntityType(entityType);
        }
        String propertyName = resolvePropertyName(filter.getOwnerEntityType(), filter.getPropertyName());
        Filter.setNameFromProperty(filter, propertyName);
        ClassInfo classInfo = session.metaData().classInfo(entityType.getName());
        FieldInfo fieldInfo = classInfo.getFieldInfo(filter.getPropertyName());
        if (fieldInfo != null) {
            filter.setPropertyConverter(fieldInfo.getPropertyConverter());
        }
        if (filter.isNested()) {
            resolveRelationshipType(filter);
            ClassInfo nestedClassInfo = session.metaData().classInfo(filter.getNestedPropertyType().getName());
            filter.setNestedEntityTypeLabel(session.metaData().entityType(nestedClassInfo.name()));
            if (session.metaData().isRelationshipEntity(nestedClassInfo.name())) {
                filter.setNestedRelationshipEntity(true);
            }
        } else if (filter.isDeepNested()) {
            Class parentOwnerType = filter.getOwnerEntityType();
            for (Filter.NestedPathSegment nestedPathSegment : filter.getNestedPath()) {
                resolveRelationshipType(parentOwnerType, nestedPathSegment);
                ClassInfo nestedClassInfo = session.metaData().classInfo(nestedPathSegment.getPropertyType().getName());
                nestedPathSegment.setNestedEntityTypeLabel(session.metaData().entityType(nestedClassInfo.name()));
                if (session.metaData().isRelationshipEntity(nestedClassInfo.name())) {
                    nestedPathSegment.setNestedRelationshipEntity(true);
                }
                parentOwnerType = nestedPathSegment.getPropertyType();
            }
        }
    }
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 79 with ClassInfo

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

the class SessionDelegate method resolveRelationshipType.

private void resolveRelationshipType(Class parentOwnerType, Filter.NestedPathSegment segment) {
    ClassInfo classInfo = session.metaData().classInfo(parentOwnerType.getName());
    FieldInfo fieldInfo = classInfo.relationshipFieldByName(segment.getPropertyName());
    String defaultRelationshipType = RelationshipUtils.inferRelationshipType(segment.getPropertyName());
    updateRelationship(segment, fieldInfo, defaultRelationshipType);
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 80 with ClassInfo

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

the class EntityUtils method setIdentity.

public static void setIdentity(Object entity, Long identity, MetaData metaData) {
    ClassInfo classInfo = metaData.classInfo(entity);
    if (classInfo.hasIdentityField()) {
        FieldInfo identityField = classInfo.identityField();
        identityField.write(entity, identity);
    } else if (identity == null) {
        // Reset any generated field if the new value is null in case the generated values is not an internal id.
        classInfo.fieldsInfo().fields().stream().filter(f -> f.getAnnotations().has(Id.class) && f.getAnnotations().has(GeneratedValue.class)).findFirst().ifPresent(generatedField -> generatedField.write(entity, null));
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Id(org.neo4j.ogm.annotation.Id) MetaData(org.neo4j.ogm.metadata.MetaData) Collection(java.util.Collection) GeneratedValue(org.neo4j.ogm.annotation.GeneratedValue) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ArrayList(java.util.ArrayList) GeneratedValue(org.neo4j.ogm.annotation.GeneratedValue) Id(org.neo4j.ogm.annotation.Id) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) 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