Search in sources :

Example 1 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.

the class CypherResultSubGraph method from.

public static SubGraph from(Result result, GraphDatabaseService gds, boolean addBetween) {
    final CypherResultSubGraph graph = new CypherResultSubGraph();
    final List<String> columns = result.columns();
    for (Map<String, Object> row : loop(result)) {
        for (String column : columns) {
            final Object value = row.get(column);
            graph.addToGraph(value);
        }
    }
    for (IndexDefinition def : gds.schema().getIndexes()) {
        if (graph.getLabels().contains(def.getLabel())) {
            graph.addIndex(def);
        }
    }
    for (ConstraintDefinition def : gds.schema().getConstraints()) {
        if (graph.getLabels().contains(def.getLabel())) {
            graph.addConstraint(def);
        }
    }
    if (addBetween) {
        graph.addRelationshipsBetweenNodes();
    }
    return graph;
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition)

Example 2 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.

the class SubGraphExporter method exportIndexes.

private Collection<String> exportIndexes() {
    final List<String> result = new ArrayList<>();
    for (IndexDefinition index : graph.getIndexes()) {
        if (!index.isConstraintIndex()) {
            Iterator<String> propertyKeys = index.getPropertyKeys().iterator();
            if (!propertyKeys.hasNext()) {
                throw new IllegalStateException("Indexes should have at least one property key");
            }
            String key = quote(propertyKeys.next());
            if (propertyKeys.hasNext()) {
                throw new RuntimeException("Exporting compound indexes is not implemented yet");
            }
            String label = quote(index.getLabel().name());
            result.add("create index on :" + label + "(" + key + ")");
        }
    }
    Collections.sort(result);
    return result;
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) ArrayList(java.util.ArrayList)

Example 3 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.

the class IndexRecoveryIT method createIndexAndAwaitPopulation.

private void createIndexAndAwaitPopulation(Label label) {
    IndexDefinition index = createIndex(label);
    try (Transaction tx = db.beginTx()) {
        db.schema().awaitIndexOnline(index, 10, SECONDS);
        tx.success();
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Transaction(org.neo4j.graphdb.Transaction)

Example 4 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.

the class IndexRestartIT method createIndex.

private IndexDefinition createIndex() {
    try (Transaction tx = db.beginTx()) {
        IndexDefinition index = db.schema().indexFor(myLabel).on("number_of_bananas_owned").create();
        tx.success();
        return index;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition)

Example 5 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.

the class IndexSamplingCancellationTest method indexOn.

private IndexDefinition indexOn(Label label, String propertyKey) {
    IndexDefinition index;
    try (Transaction tx = db.beginTx()) {
        index = db.schema().indexFor(label).on(propertyKey).create();
        tx.success();
    }
    return index;
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Transaction(org.neo4j.graphdb.Transaction)

Aggregations

IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)84 Test (org.junit.Test)56 Transaction (org.neo4j.graphdb.Transaction)32 StringContains.containsString (org.hamcrest.core.StringContains.containsString)11 Node (org.neo4j.graphdb.Node)9 Statement (org.neo4j.kernel.api.Statement)7 ArrayList (java.util.ArrayList)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Label (org.neo4j.graphdb.Label)4 ReadOperations (org.neo4j.kernel.api.ReadOperations)4 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)4 HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)4 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)4 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)3 Iterator (java.util.Iterator)2 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)2 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)2 TransactionData (org.neo4j.graphdb.event.TransactionData)2 TransactionEventHandler (org.neo4j.graphdb.event.TransactionEventHandler)2 ConstraintDefinition (org.neo4j.graphdb.schema.ConstraintDefinition)2