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());
}
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());
}
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());
}
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");
}
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();
}
}
}
Aggregations