use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class SchemaIndexIT method drop_index.
@Documented("Drop index")
@Test
@GraphDescription.Graph(nodes = {})
public void drop_index() throws Exception {
data.get();
String labelName = labels.newInstance(), propertyKey = properties.newInstance();
IndexDefinition schemaIndex = createIndex(labelName, propertyKey);
assertThat(Neo4jMatchers.getIndexes(graphdb(), label(labelName)), containsOnly(schemaIndex));
gen.get().expectedStatus(204).delete(getSchemaIndexLabelPropertyUri(labelName, propertyKey)).entity();
assertThat(Neo4jMatchers.getIndexes(graphdb(), label(labelName)), not(containsOnly(schemaIndex)));
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class GraphDbHelper method createSchemaIndex.
public IndexDefinition createSchemaIndex(String labelName, String propertyKey) {
try (Transaction tx = database.getGraph().beginTransaction(implicit, AUTH_DISABLED)) {
IndexDefinition index = database.getGraph().schema().indexFor(label(labelName)).on(propertyKey).create();
tx.success();
return index;
}
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class IndexConstraintsTest method getIndex.
private IndexDefinition getIndex(Label label, String propertyKey) {
try (Transaction tx = graphDb.beginTx()) {
IndexDefinition found = null;
for (IndexDefinition index : graphDb.schema().getIndexes(label)) {
if (propertyKey.equals(single(index.getPropertyKeys()))) {
assertNull("Found multiple indexes.", found);
found = index;
}
}
tx.success();
return found;
}
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class IndexConstraintsTest method convertIndexToConstraintWithExistingData.
@Test
public void convertIndexToConstraintWithExistingData() {
try (Transaction tx = graphDb.beginTx()) {
for (int i = 0; i < 2000; i++) {
Node node = graphDb.createNode(LABEL);
node.setProperty(PROPERTY_KEY, i);
}
tx.success();
}
try (Transaction tx = graphDb.beginTx()) {
graphDb.schema().indexFor(LABEL).on(PROPERTY_KEY).create();
tx.success();
}
try (Transaction tx = graphDb.beginTx()) {
IndexDefinition index = firstOrNull(graphDb.schema().getIndexes(LABEL));
index.drop();
graphDb.schema().constraintFor(LABEL).assertPropertyIsUnique(PROPERTY_KEY).create();
tx.success();
}
// assert no exception is thrown
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class DatabaseActions method dropSchemaIndex.
public boolean dropSchemaIndex(String labelName, String propertyKey) {
boolean found = false;
for (IndexDefinition index : graphDb.schema().getIndexes(label(labelName))) {
// TODO Assumption about single property key
if (propertyKey.equals(Iterables.single(index.getPropertyKeys()))) {
index.drop();
found = true;
break;
}
}
return found;
}
Aggregations