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.
package apoc.refactor.rename;
import apoc.periodic.Periodic;
import apoc.periodic.Periodic.BatchAndTotalResult;
import apoc.util.MapUtil;
import apoc.util.Util;
import org.neo4j.graphdb.*;
import org.neo4j.graphdb.schema.ConstraintDefinition;
import org.neo4j.graphdb.schema.IndexDefinition;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.logging.Log;
import org.neo4j.procedure.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author AgileLARUS
*
* @since 03-04-2017
*/
public class Rename {
@Context public GraphDatabaseService db;
@Context public Log log;
@Context public TerminationGuard terminationGuard;
/**
* Rename the Label of a node by creating a new one and deleting the old.
*/
@Procedure(mode = Mode.WRITE)
@Description("apoc.refactor.rename.label(oldLabel, newLabel, [nodes]) | rename a label from 'oldLabel' to 'newLabel' for all nodes. If 'nodes' is provided renaming is applied to this set only")
public Stream label(@Name("oldLabel") String oldLabel, @Name("newLabel") String newLabel, @Name(value = "nodes", defaultValue = "") List nodes) {
String cypherIterate = nodes != null && !nodes.isEmpty() ? "UNWIND {nodes} AS n WITH n WHERE n:`"+oldLabel+"` RETURN n" : "MATCH (n:`"+oldLabel+"`) RETURN n";
String cypherAction = "SET n:`"+newLabel+"` REMOVE n:`"+oldLabel+"`";
Map parameters = MapUtil.map("batchSize", 100000, "parallel", true, "iterateList", true, "params", MapUtil.map("nodes", nodes));
return getResultOfBatchAndTotalWithInfo( newPeriodic().iterate(cypherIterate, cypherAction, parameters), db, oldLabel, null, null);
}
/**
* Rename the Relationship Type by creating a new one and deleting the old.
*/
@Procedure(mode = Mode.WRITE)
@Description("apoc.refactor.rename.type(oldType, newType, [rels]) | rename all relationships with type 'oldType' to 'newType'. If 'rels' is provided renaming is applied to this set only")
public Stream type(@Name("oldType") String oldType, @Name("newType") String newType, @Name(value = "rels", defaultValue = "") List rels) {
String cypherIterate = rels != null && ! rels.isEmpty() ? "UNWIND {rels} AS oldRel WITH oldRel WHERE type(oldRel)=\""+oldType+"\" RETURN oldRel,startNode(oldRel) as a,endNode(oldRel) as b" : "MATCH (a)-[oldRel:`"+oldType+"`]->(b) RETURN oldRel,a,b";
String cypherAction = "CREATE(a)-[newRel:`"+newType+"`]->(b)"+ "SET newRel+=oldRel DELETE oldRel";
Map parameters = MapUtil.map("batchSize", 100000, "parallel", true, "iterateList", true, "params", MapUtil.map("rels", rels));
return getResultOfBatchAndTotalWithInfo(newPeriodic().iterate(cypherIterate, cypherAction, parameters), db, null, oldType, null);
}
/**
* Rename property of a node by creating a new one and deleting the old.
*/
@Procedure(mode = Mode.WRITE)
@Description("apoc.refactor.rename.nodeProperty(oldName, newName, [nodes]) | rename all node's property from 'oldName' to 'newName'. If 'nodes' is provided renaming is applied to this set only")
public Stream nodeProperty(@Name("oldName") String oldName, @Name("newName") String newName, @Name(value="nodes", defaultValue = "") List