All Downloads are FREE. Search and download functionalities are using the official Maven repository.

apoc.export.cypher.formatter.AbstractCypherFormatter Maven / Gradle / Ivy

There is a newer version: 5.25.1
Show newest version
package apoc.export.cypher.formatter;

import apoc.export.util.ExportConfig;
import apoc.export.util.ExportFormat;
import apoc.export.util.Reporter;
import apoc.util.Util;
import apoc.util.collection.Iterables;
import org.apache.commons.lang3.StringUtils;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;

import java.io.PrintWriter;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import static apoc.export.cypher.formatter.CypherFormatterUtils.Q_UNIQUE_ID_LABEL;
import static apoc.export.cypher.formatter.CypherFormatterUtils.Q_UNIQUE_ID_REL;
import static apoc.export.cypher.formatter.CypherFormatterUtils.UNIQUE_ID_PROP;
import static apoc.export.cypher.formatter.CypherFormatterUtils.simpleKeyValue;

/**
 * @author AgileLARUS
 *
 * @since 16-06-2017
 */
abstract class AbstractCypherFormatter implements CypherFormatter {

	private static final String STATEMENT_CONSTRAINTS = "CREATE CONSTRAINT %s%s FOR (node:%s) REQUIRE (%s) %s;";
	private static final String STATEMENT_DROP_CONSTRAINTS = "DROP CONSTRAINT %s;";

	private static final String STATEMENT_NODE_FULLTEXT_IDX = "CREATE FULLTEXT INDEX %s FOR (n:%s) ON EACH [%s];";
	private static final String STATEMENT_REL_FULLTEXT_IDX = "CREATE FULLTEXT INDEX %s FOR ()-[rel:%s]-() ON EACH [%s];";
	public static final String PROPERTY_QUOTING_FORMAT = "%s.`%s`";
	private static final String ID_REL_KEY = "id";

	@Override
	public String statementForCleanUp(int batchSize) {
		return "MATCH (n:" + Q_UNIQUE_ID_LABEL + ") " +
				" WITH n LIMIT " + batchSize +
				" REMOVE n:" + Q_UNIQUE_ID_LABEL + " REMOVE n." + Util.quote(UNIQUE_ID_PROP) + ";";
	}

	@Override
	public String statementForNodeIndex(String indexType, String label, Iterable keys, boolean ifNotExists, String idxName) {
		return String.format("CREATE %s INDEX%s%s FOR (n:%s) ON (%s);", 
				indexType, idxName, getIfNotExists(ifNotExists), Util.quote(label), getPropertiesQuoted(keys, "n."));
	}
	
	@Override
	public String statementForIndexRelationship(String indexType, String type, Iterable keys, boolean ifNotExists, String idxName) {
		return String.format("CREATE %s INDEX%s%s FOR ()-[rel:%s]-() ON (%s);", 
				indexType, idxName, getIfNotExists(ifNotExists), Util.quote(type), getPropertiesQuoted(keys, "rel."));
	}

	@Override
	public String statementForNodeFullTextIndex(String name, Iterable




© 2015 - 2024 Weber Informatics LLC | Privacy Policy