Skip to content

Commit

Permalink
WIP on #403
Browse files Browse the repository at this point in the history
  • Loading branch information
frant-hartm committed Sep 20, 2017
1 parent 1bf4f9c commit 441dc4f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
44 changes: 35 additions & 9 deletions core/src/main/java/org/neo4j/ogm/context/GraphEntityMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ public <T> List<T> map(Class<T> type, GraphModel graphModel) {

public <T> List<T> map(Class<T> type, GraphModel graphModel, Set<Long> nodeIds, Set<Long> edgeIds) {

mapEntities(type, graphModel, nodeIds, edgeIds);
Set<Long> modelNodeIds = new LinkedHashSet<>();
Set<Long> modelEdgeIds = new LinkedHashSet<>();
mapEntities(type, graphModel, modelNodeIds, modelEdgeIds);
List<T> results = new ArrayList<>();
Set<Long> seenNodeIds = new HashSet<>();
Set<Long> seenEdgeIds = new HashSet<>();

for (Long id : nodeIds) {
for (Long id : modelNodeIds) {
Object o = mappingContext.getNodeEntity(id);

if (!seenNodeIds.contains(id)) {
if (!nodeIds.contains(id)) {
executePostLoad(o);
seenNodeIds.add(id);
nodeIds.add(id);
}

if (o != null && type.isAssignableFrom(o.getClass())) {
Expand All @@ -141,14 +141,14 @@ public <T> List<T> map(Class<T> type, GraphModel graphModel, Set<Long> nodeIds,

// only look for REs if no node entities were found
if (results.isEmpty()) {
for (Long id : edgeIds) {
for (Long id : modelEdgeIds) {
Object o = mappingContext.getRelationshipEntity(id);

if (!seenEdgeIds.contains(id)) {
if (!edgeIds.contains(id)) {
if (o != null) {
executePostLoad(o);
}
seenEdgeIds.add(id);
edgeIds.add(id);
}

if (o != null && type.isAssignableFrom(o.getClass())) {
Expand All @@ -160,6 +160,32 @@ public <T> List<T> map(Class<T> type, GraphModel graphModel, Set<Long> nodeIds,
return results;
}

private void executePostLoad(Set<Long> nodeIds, Set<Long> edgeIds) {
Set<Long> seenIds = new HashSet<>();
for (Long id : nodeIds) {
Object o = mappingContext.getNodeEntity(id);

if (!nodeIds.contains(id)) {
executePostLoad(o);
nodeIds.add(id);
}
}
/*
// only look for REs if no node entities were found
if (results.isEmpty()) {
for (Long id : modelEdgeIds) {
Object o = mappingContext.getRelationshipEntity(id);
if (!edgeIds.contains(id)) {
if (o != null) {
executePostLoad(o);
}
edgeIds.add(id);
}
}
}*/
}
private <T> void mapEntities(Class<T> type, GraphModel graphModel, Set<Long> nodeIds, Set<Long> edgeIds) {
try {
mapNodes(graphModel, nodeIds);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/neo4j/ogm/metadata/FieldInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ public Object readProperty(Object instance) {
throw new IllegalStateException(
"The readComposite method should be used for fields with a CompositeAttributeConverter");
}
Object value = read(containingClassInfo.getField(this), instance);
Object value = read(this.field, instance);
if (hasPropertyConverter()) {
value = getPropertyConverter().toGraphProperty(value);
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/neo4j/ogm/metadata/MethodInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class MethodInfo {
*/
MethodInfo(Method method, ObjectAnnotations annotations) {
this.method = method;
this.method.setAccessible(true);
this.name = method.getName();
this.annotations = annotations;
}
Expand Down

0 comments on commit 441dc4f

Please sign in to comment.