Search in sources :

Example 31 with ClassInfo

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

the class Neo4jSession method determineLabelsOrTypeForLoading.

/**
 * Determines the one relationship type or maybe multiple labels to use in various statements during loading of things.
 * <p>
 * Multiple labels are pre-joined with <pre>`:`</pre>. There are meant to be passed to various clause builders, which
 * cannot deal with list of labels, but use the one label or type and use it in between tickmarks.
 * @param type The type of the objects that shall be loaded
 * @return Label(s) or type, empty optional of no valid label or type could be determined.
 */
public Optional<String> determineLabelsOrTypeForLoading(Class<?> type) {
    Optional<String> labelsOrType;
    if (useStrictQuerying) {
        ClassInfo classInfo = metaData().classInfo(type);
        String result = null;
        if (classInfo != null) {
            result = classInfo.isRelationshipEntity() ? classInfo.neo4jName() : String.join("`:`", classInfo.staticLabels());
        }
        labelsOrType = Optional.ofNullable(result);
    } else {
        labelsOrType = Optional.ofNullable(metaData.entityType(type.getName()));
    }
    return labelsOrType.map(String::trim).filter(s -> !s.isEmpty());
}
Also used : ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 32 with ClassInfo

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

the class AnnotatedFieldNonAnnotatedSetterAndNonSetterTest method shouldPreferAnnotatedFieldOverNonAnnotatedSetterAndNonSetter.

@Test
public void shouldPreferAnnotatedFieldOverNonAnnotatedSetterAndNonSetter() {
    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 33 with ClassInfo

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

the class AnnotatedFieldWithNoSetterAndNonSetterTest method shouldPreferAnnotatedFieldOverNonSetterInAbsenceOfSetterForRelationshipEntity.

@Test
public void shouldPreferAnnotatedFieldOverNonSetterInAbsenceOfSetterForRelationshipEntity() {
    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 34 with ClassInfo

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

the class EntityAccessManagerTest method shouldPreferAnnotatedFieldToMethodNotAnnotatedWithPropertyWhenFindingPropertyToSet.

/**
 * @see DATAGRAPH-674
 */
@Test
public void shouldPreferAnnotatedFieldToMethodNotAnnotatedWithPropertyWhenFindingPropertyToSet() {
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    DummyDomainObject domainObject = new DummyDomainObject();
    FieldInfo objectAccess = classInfo.getFieldInfo("testIgnored");
    assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
    assertThat(objectAccess instanceof FieldInfo).isTrue();
    assertThat(objectAccess.type()).isEqualTo(String.class);
    objectAccess.write(domainObject, "TEST");
    assertThat(domainObject.propertyMethodsIgnored).isEqualTo("TEST");
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 35 with ClassInfo

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

the class EntityAccessManagerTest method shouldPreferAnnotatedFieldToGetterWhenReadingFromAnObject.

@Test
public void shouldPreferAnnotatedFieldToGetterWhenReadingFromAnObject() {
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    DummyDomainObject domainObject = new DummyDomainObject();
    domainObject.propertyWithDifferentAnnotatedGetter = "more arbitrary text";
    Collection<FieldInfo> readers = classInfo.propertyFields();
    FieldInfo objectAccess = classInfo.getFieldInfo("differentAnnotationOnGetter");
    assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
    assertThat(objectAccess.readProperty(domainObject)).isEqualTo(domainObject.propertyWithDifferentAnnotatedGetter);
    for (FieldInfo reader : readers) {
        if (reader.propertyName().equals("differentAnnotationOnGetter")) {
            assertThat(reader instanceof FieldInfo).isTrue();
        }
    }
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

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