Search in sources :

Example 71 with FieldInfo

use of org.neo4j.ogm.metadata.FieldInfo 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 72 with FieldInfo

use of org.neo4j.ogm.metadata.FieldInfo 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 73 with FieldInfo

use of org.neo4j.ogm.metadata.FieldInfo 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 74 with FieldInfo

use of org.neo4j.ogm.metadata.FieldInfo 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 75 with FieldInfo

use of org.neo4j.ogm.metadata.FieldInfo 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

FieldInfo (org.neo4j.ogm.metadata.FieldInfo)142 Test (org.junit.Test)102 ClassInfo (org.neo4j.ogm.metadata.ClassInfo)100 ArrayList (java.util.ArrayList)12 Date (java.util.Date)7 HashSet (java.util.HashSet)6 HashMap (java.util.HashMap)5 Collection (java.util.Collection)4 Satellite (org.neo4j.ogm.domain.satellites.Satellite)4 MappingException (org.neo4j.ogm.exception.core.MappingException)4 CompileContext (org.neo4j.ogm.cypher.compiler.CompileContext)3 Person (org.neo4j.ogm.domain.convertible.enums.Person)3 Member (org.neo4j.ogm.domain.forum.Member)3 Topic (org.neo4j.ogm.domain.forum.Topic)3 Post (org.neo4j.ogm.domain.forum.activity.Post)3 MetaData (org.neo4j.ogm.metadata.MetaData)3 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2