use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class DatabaseActions method getSchemaIndexes.
public ListRepresentation getSchemaIndexes(String labelName) {
Iterable<IndexDefinition> definitions = graphDb.schema().getIndexes(label(labelName));
Iterable<IndexDefinitionRepresentation> representations = map(new Function<IndexDefinition, IndexDefinitionRepresentation>() {
@Override
public IndexDefinitionRepresentation apply(IndexDefinition definition) {
return new IndexDefinitionRepresentation(definition, graphDb.schema().getIndexState(definition), graphDb.schema().getIndexPopulationProgress(definition));
}
}, definitions);
return new ListRepresentation(RepresentationType.INDEX_DEFINITION, representations);
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class SchemaIndexIT method createIndex.
private IndexDefinition createIndex(String labelName, String propertyKey) {
try (Transaction tx = graphdb().beginTx()) {
IndexDefinition indexDefinition = graphdb().schema().indexFor(label(labelName)).on(propertyKey).create();
tx.success();
return indexDefinition;
}
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class SchemaIndexRepresentationTest method shouldIncludeLabel.
@Test
public void shouldIncludeLabel() throws Exception {
// GIVEN
String labelName = "person", propertyKey = "name";
IndexDefinition definition = mock(IndexDefinition.class);
when(definition.getLabel()).thenReturn(label(labelName));
when(definition.getPropertyKeys()).thenReturn(asList(propertyKey));
IndexDefinitionRepresentation representation = new IndexDefinitionRepresentation(definition);
Map<String, Object> serialized = RepresentationTestAccess.serialize(representation);
// THEN
assertEquals(asList(propertyKey), serialized.get("property_keys"));
assertEquals(labelName, serialized.get("label"));
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class DatabaseActionsTest method shouldDropSchemaIndex.
@Test
public void shouldDropSchemaIndex() throws Exception {
// GIVEN
String labelName = "user", propertyKey = "login";
IndexDefinition index = graphdbHelper.createSchemaIndex(labelName, propertyKey);
// WHEN
actions.dropSchemaIndex(labelName, propertyKey);
// THEN
try (Transaction transaction = graph.beginTx()) {
assertFalse("Index should have been dropped", Iterables.asSet(graphdbHelper.getSchemaIndexes(labelName)).contains(index));
}
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class IndexRecoveryIT method createIndex.
private IndexDefinition createIndex(Label label) {
try (Transaction tx = db.beginTx()) {
IndexDefinition index = db.schema().indexFor(label).on(key).create();
tx.success();
return index;
}
}
Aggregations