Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package apoc.create;
import static org.neo4j.graphdb.RelationshipType.withName;
import apoc.get.Get;
import apoc.result.*;
import apoc.util.Util;
import apoc.util.collection.Iterables;
import apoc.uuid.UuidUtil;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.LongStream;
import java.util.stream.Stream;
import org.neo4j.graphdb.*;
import org.neo4j.kernel.impl.coreapi.InternalTransaction;
import org.neo4j.procedure.*;
public class Create {
public static final String[] EMPTY_ARRAY = new String[0];
@Context
public Transaction tx;
@Procedure(name = "apoc.create.node", mode = Mode.WRITE)
@Description("Creates a `NODE` with the given dynamic labels.")
public Stream node(@Name("labels") List labelNames, @Name("props") Map props) {
return Stream.of(new NodeResult(setProperties(tx.createNode(Util.labels(labelNames)), props)));
}
@Procedure(name = "apoc.create.addLabels", mode = Mode.WRITE)
@Description("Adds the given labels to the given `NODE` values.")
public Stream addLabels(@Name("nodes") Object nodes, @Name("labels") List labelNames) {
Label[] labels = Util.labels(labelNames);
return new Get((InternalTransaction) tx).nodes(nodes).map((r) -> {
Node node = r.node;
for (Label label : labels) {
node.addLabel(label);
}
return r;
});
}
@Procedure(name = "apoc.create.setProperty", mode = Mode.WRITE)
@Description("Sets the given property to the given `NODE` values.")
public Stream setProperty(
@Name("nodes") Object nodes, @Name("key") String key, @Name("value") Object value) {
return new Get((InternalTransaction) tx).nodes(nodes).map((r) -> {
setProperty(r.node, key, toPropertyValue(value));
return r;
});
}
@Procedure(name = "apoc.create.setRelProperty", mode = Mode.WRITE)
@Description("Sets the given property on the `RELATIONSHIP` values.")
public Stream setRelProperty(
@Name("rels") Object rels, @Name("key") String key, @Name("value") Object value) {
return new Get((InternalTransaction) tx).rels(rels).map((r) -> {
setProperty(r.rel, key, toPropertyValue(value));
return r;
});
}
@Procedure(name = "apoc.create.setProperties", mode = Mode.WRITE)
@Description("Sets the given properties to the given `NODE` values.")
public Stream setProperties(
@Name("nodes") Object nodes, @Name("keys") List keys, @Name("values") List