use of org.neo4j.ogm.metadata.FieldInfo in project neo4j-ogm by neo4j.
the class SaveEventDelegate method dirty.
// returns true if the object in question is dirty (has changed)
// an object is dirty if either or both of:
// - its properties have changed
// - its relationships has changed
private boolean dirty(Object parent) {
// have any properties changed
if (this.session.context().isDirty(parent)) {
logger.debug("dirty: {}", parent);
return true;
}
ClassInfo parentInfo = this.session.metaData().classInfo(parent);
long parentId = session.context().nativeId(parent);
// an RE cannot contain additional refs because hyperedges are forbidden in Neo4j
if (!parentInfo.isRelationshipEntity()) {
// build the set of mapped relationships for this object. if there any new ones, the object is dirty
for (FieldInfo reader : relationalReaders(parent)) {
clearPreviousRelationships(parentId, reader);
for (MappedRelationship mappable : map(parentInfo, parentId, reader.read(parent), reader)) {
if (isNew(mappable)) {
logger.debug("added new relationship: {} to {}", mappable, parent);
this.addedRelationships.add(mappable);
return true;
}
this.registeredRelationships.add(mappable);
// no longer deleted
this.deletedRelationships.remove(mappable);
}
}
for (MappedRelationship previous : session.context().getRelationships()) {
if (isDeleted(previous) && (previous.getStartNodeId() == parentId || previous.getEndNodeId() == parentId)) {
logger.debug("deleted: {} from {}", previous, parent);
return true;
}
}
}
return false;
}
use of org.neo4j.ogm.metadata.FieldInfo in project neo4j-ogm by neo4j.
the class SessionDelegate method resolveRelationshipType.
private void resolveRelationshipType(Filter filter) {
ClassInfo classInfo = session.metaData().classInfo(filter.getOwnerEntityType().getName());
FieldInfo fieldInfo = classInfo.relationshipFieldByName(filter.getNestedPropertyName());
String defaultRelationshipType = RelationshipUtils.inferRelationshipType(filter.getNestedPropertyName());
updateRelationship(filter, fieldInfo, defaultRelationshipType);
}
use of org.neo4j.ogm.metadata.FieldInfo in project neo4j-ogm by neo4j.
the class SessionDelegate method resolvePropertyAnnotations.
void resolvePropertyAnnotations(Class entityType, Iterable<Filter> filters) {
for (Filter filter : filters) {
if (filter.getOwnerEntityType() == null) {
filter.setOwnerEntityType(entityType);
}
String propertyName = resolvePropertyName(filter.getOwnerEntityType(), filter.getPropertyName());
Filter.setNameFromProperty(filter, propertyName);
ClassInfo classInfo = session.metaData().classInfo(entityType.getName());
FieldInfo fieldInfo = classInfo.getFieldInfo(filter.getPropertyName());
if (fieldInfo != null) {
filter.setPropertyConverter(fieldInfo.getPropertyConverter());
}
if (filter.isNested()) {
resolveRelationshipType(filter);
ClassInfo nestedClassInfo = session.metaData().classInfo(filter.getNestedPropertyType().getName());
filter.setNestedEntityTypeLabel(session.metaData().entityType(nestedClassInfo.name()));
if (session.metaData().isRelationshipEntity(nestedClassInfo.name())) {
filter.setNestedRelationshipEntity(true);
}
} else if (filter.isDeepNested()) {
Class parentOwnerType = filter.getOwnerEntityType();
for (Filter.NestedPathSegment nestedPathSegment : filter.getNestedPath()) {
resolveRelationshipType(parentOwnerType, nestedPathSegment);
ClassInfo nestedClassInfo = session.metaData().classInfo(nestedPathSegment.getPropertyType().getName());
nestedPathSegment.setNestedEntityTypeLabel(session.metaData().entityType(nestedClassInfo.name()));
if (session.metaData().isRelationshipEntity(nestedClassInfo.name())) {
nestedPathSegment.setNestedRelationshipEntity(true);
}
parentOwnerType = nestedPathSegment.getPropertyType();
}
}
}
}
use of org.neo4j.ogm.metadata.FieldInfo in project neo4j-ogm by neo4j.
the class SessionDelegate method resolveRelationshipType.
private void resolveRelationshipType(Class parentOwnerType, Filter.NestedPathSegment segment) {
ClassInfo classInfo = session.metaData().classInfo(parentOwnerType.getName());
FieldInfo fieldInfo = classInfo.relationshipFieldByName(segment.getPropertyName());
String defaultRelationshipType = RelationshipUtils.inferRelationshipType(segment.getPropertyName());
updateRelationship(segment, fieldInfo, defaultRelationshipType);
}
use of org.neo4j.ogm.metadata.FieldInfo 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));
}
}
Aggregations