Search in sources :

Example 66 with FieldInfo

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

the class RelationshipWriterAnnotatedFieldsTest method shouldFindWriterForCollection.

@Test
public void shouldFindWriterForCollection() {
    ClassInfo classInfo = this.domainInfo.getClass(S.class.getName());
    FieldInfo objectAccess = EntityAccessManager.getRelationalWriter(classInfo, "LIST", Relationship.Direction.OUTGOING, new T());
    assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
    assertThat(objectAccess instanceof FieldInfo).as("The access mechanism should be via the field").isTrue();
    assertThat(objectAccess.relationship()).isEqualTo("LIST");
    assertThat(objectAccess.type()).isEqualTo(List.class);
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 67 with FieldInfo

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

the class RelationshipWriterPlainFieldsTest method shouldFindWriterForCollection.

@Test
public void shouldFindWriterForCollection() {
    ClassInfo classInfo = this.domainInfo.getClass(S.class.getName());
    FieldInfo objectAccess = EntityAccessManager.getRelationalWriter(classInfo, "LIST", Relationship.Direction.OUTGOING, new T());
    assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
    assertThat(objectAccess instanceof FieldInfo).as("The access mechanism should be via the field").isTrue();
    assertThat(objectAccess.relationship()).isEqualTo("LIST");
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 68 with FieldInfo

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

the class AnnotatedFieldAndNoSetterTest method shouldPreferAnnotatedFieldInAbsenceOfSetterForRelationshipEntity.

@Test
public void shouldPreferAnnotatedFieldInAbsenceOfSetterForRelationshipEntity() {
    ClassInfo classInfo = this.domainInfo.getClass(End.class.getName());
    RelEntity relEntity = new RelEntity();
    Set<RelEntity> parameter = new HashSet();
    parameter.addAll(Arrays.asList(relEntity));
    FieldInfo objectAccess = EntityAccessManager.getRelationalWriter(classInfo, "REL_ENTITY_TYPE", Relationship.Direction.INCOMING, relEntity);
    assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
    assertThat(objectAccess instanceof FieldInfo).as("The access mechanism should be via the field").isTrue();
    End end = new End();
    objectAccess.write(end, parameter);
    assertThat(parameter).isEqualTo(end.getRelEntities());
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 69 with FieldInfo

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

the class EntityUtils method identity.

/**
 * Return native id of given node or relationship entity.
 * If the id field is null the field is set to unique negative refId, which is then returned.
 * You most likely want to use {@link org.neo4j.ogm.context.MappingContext#nativeId(Object)}
 *
 * @param entity   entity
 * @param metaData metadata
 * @return native id or refId
 */
public static Long identity(Object entity, MetaData metaData) {
    ClassInfo classInfo = metaData.classInfo(entity);
    FieldInfo identityField = classInfo.identityField();
    Object id = identityField.readProperty(entity);
    if (id == null) {
        Long generated = idSequence.decrementAndGet();
        identityField.write(entity, generated);
        return generated;
    } else {
        return (Long) id;
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 70 with FieldInfo

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

the class NodeDeleteStatements method delete.

@Override
public CypherQuery delete(Long id, Object object, ClassInfo classInfo) {
    FieldInfo versionField = classInfo.getVersionField();
    Long version = (Long) versionField.read(object);
    OptimisticLockingConfig optimisticLockingConfig = new OptimisticLockingConfig(1, classInfo.staticLabels().toArray(new String[] {}), versionField.property());
    Map<String, Object> params = new HashMap<>();
    params.put("id", id);
    params.put("version", version);
    params.put("type", "node");
    return new DefaultRowModelRequest("MATCH (n) " + "  WHERE id(n) = $id AND n.`" + versionField.property() + "` = $version " + "SET " + " n.`" + versionField.property() + "` = n.`" + versionField.property() + "` + 1 " + "WITH n " + " WHERE n.`" + versionField.property() + "` = $version + 1 " + "OPTIONAL MATCH (n)-[r0]-() " + "DELETE r0, n " + // Use DISTINCT because node may have multiple relationships
    "RETURN DISTINCT id(n) AS id", params, optimisticLockingConfig);
}
Also used : HashMap(java.util.HashMap) OptimisticLockingConfig(org.neo4j.ogm.request.OptimisticLockingConfig) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) DefaultRowModelRequest(org.neo4j.ogm.cypher.query.DefaultRowModelRequest)

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