Search in sources :

Example 1 with Id

use of org.neo4j.ogm.annotation.Id 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

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 GeneratedValue (org.neo4j.ogm.annotation.GeneratedValue)1 Id (org.neo4j.ogm.annotation.Id)1 ClassInfo (org.neo4j.ogm.metadata.ClassInfo)1 FieldInfo (org.neo4j.ogm.metadata.FieldInfo)1 MetaData (org.neo4j.ogm.metadata.MetaData)1