0
我需要實現neo4j的自動增量功能。 我有一個用戶定義的過程(thaks到this answer)做了如下:如何使用用戶功能在neo4j中實現自動增量
public class Sequence {
public @Context GraphDatabaseService db;
@Procedure(name = "sequence.id", mode = Mode.WRITE)
@Description("sequence.id(name, length) - return next 'length' value(s) form sequence with name 'name'")
public Stream<ListResult> sequence_id(@Name("name") final String name,
@Name(value = "length", defaultValue = "1") Long length) {
try (
final Result results = db.execute(
"WITH {length} as length\n" +
"MERGE (id:UniqueId{name:{name}})\n" +
"SET id.count = coalesce(id.count, 1) + length\n" +
"WITH length, id.count - length AS base\n" +
"UNWIND range(0, length - 1) AS idx\n" +
"RETURN collect(base + idx) AS value", with("name", name, "length", length))) {
return results.<List>columnAs("value").map(ListResult::new).stream();
}
private Map<String, Object> with(String key1, Object value1, String key2, Object value2) {
Map<String, Object> map = new HashMap<>();
map.put(key1, value1);
map.put(key2, value2);
return map;
}
...
}
,但我究竟需要的是具有相同功能的函數。
如何用函數做到這一點?是否可以從用戶定義的函數調用過程?有人能指點我一些有用的例子嗎?
感謝,