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