-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
173 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package apoc.nodes; | ||
|
||
import apoc.Extended; | ||
import apoc.util.EntityUtil; | ||
import apoc.util.Util; | ||
import org.neo4j.graphdb.Node; | ||
import org.neo4j.graphdb.Relationship; | ||
import org.neo4j.graphdb.Transaction; | ||
import org.neo4j.procedure.Context; | ||
import org.neo4j.procedure.Description; | ||
import org.neo4j.procedure.Name; | ||
import org.neo4j.procedure.UserFunction; | ||
|
||
@Extended | ||
public class NodesExtended { | ||
|
||
@Context | ||
public Transaction tx; | ||
|
||
@UserFunction("apoc.node.rebind") | ||
@Description("apoc.node.rebind(node - to rebind a node (i.e. executing a Transaction.getNodeById(node.getId()) ") | ||
public Node nodeRebind(@Name("node") Node node) { | ||
return Util.rebind(tx, node); | ||
} | ||
|
||
@UserFunction("apoc.rel.rebind") | ||
@Description("apoc.rel.rebind(rel) - to rebind a rel (i.e. executing a Transaction.getRelationshipById(rel.getId()) ") | ||
public Relationship relationshipRebind(@Name("rel") Relationship rel) { | ||
return Util.rebind(tx, rel); | ||
} | ||
|
||
@UserFunction("apoc.any.rebind") | ||
@Description("apoc.any.rebind(Object) - to rebind any rel, node, path, map, list or combination of them (i.e. executing a Transaction.getNodeById(node.getId()) / Transaction.getRelationshipById(rel.getId()))") | ||
public Object anyRebind(@Name("any") Object any) { | ||
return EntityUtil.anyRebind(tx, any); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package apoc.util; | ||
|
||
import org.neo4j.graphalgo.impl.util.PathImpl; | ||
import org.neo4j.graphdb.Entity; | ||
import org.neo4j.graphdb.Path; | ||
import org.neo4j.graphdb.Relationship; | ||
import org.neo4j.graphdb.Transaction; | ||
import org.neo4j.internal.helpers.collection.Iterables; | ||
|
||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class EntityUtil { | ||
|
||
public static <T> T anyRebind(Transaction tx, T any) { | ||
if (any instanceof Map) { | ||
return (T) ((Map<String, Object>) any).entrySet().stream() | ||
.collect(Collectors.toMap(e -> e.getKey(), e -> anyRebind(tx, e.getValue()))); | ||
} | ||
if (any instanceof Path) { | ||
final Path path = (Path) any; | ||
PathImpl.Builder builder = new PathImpl.Builder(Util.rebind(tx, path.startNode())); | ||
for (Relationship rel: path.relationships()) { | ||
builder = builder.push(Util.rebind(tx, rel)); | ||
} | ||
return (T) builder.build(); | ||
} | ||
if (any instanceof Iterable) { | ||
return (T) Iterables.stream((Iterable) any) | ||
.map(i -> anyRebind(tx, i)).collect(Collectors.toList()); | ||
} | ||
if (any instanceof Entity) { | ||
return (T) Util.rebind(tx, (Entity) any); | ||
} | ||
return any; | ||
} | ||
} |
Oops, something went wrong.