@Override public Iterable<IndexDefinition> getIndexes() { return gdb.schema().getIndexes(); }
@Override protected Iterable<IndexDefinition> manifest() { return db.schema().getIndexes( label ); } };
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; }
private List<IndexDefinition> indexes( GraphDatabaseService database ) { try ( Transaction ignored = database.beginTx() ) { return Iterables.asList( database.schema().getIndexes() ); } }
private long countIndexes() { try ( Transaction transaction = database.beginTx() ) { return Iterables.count( database.schema().getIndexes() ); } }
public Iterable<IndexDefinition> getSchemaIndexes( String labelName ) { return database.getGraph().schema().getIndexes( label( labelName ) ); }
private void deleteAllIndexRules() { for ( IndexDefinition index : db.schema().getIndexes() ) { if ( !index.isConstraintIndex() ) { index.drop(); } } }
private static boolean hasIndex( GraphDatabaseService db, Label label, String... keys ) { try ( Transaction tx = db.beginTx() ) { List<String> keyList = asList( keys ); for ( IndexDefinition index : db.schema().getIndexes( label ) ) { if ( asList( index.getPropertyKeys() ).equals( keyList ) ) { return true; } } tx.success(); } return false; }
public ListRepresentation getSchemaIndexes() { Iterable<IndexDefinition> definitions = graphDb.schema().getIndexes(); Iterable<IndexDefinitionRepresentation> representations = map( definition -> new IndexDefinitionRepresentation( definition, graphDb.schema().getIndexState( definition ), graphDb.schema().getIndexPopulationProgress( definition ) ), definitions ); return new ListRepresentation( RepresentationType.INDEX_DEFINITION, representations ); }
private static void dropAllIndexes( GraphDatabaseService database ) { try ( Transaction transaction = database.beginTx() ) { for ( IndexDefinition definition : database.schema().getIndexes() ) { definition.drop(); } transaction.success(); } }
public ListRepresentation getSchemaIndexes( String labelName ) { Iterable<IndexDefinition> definitions = graphDb.schema().getIndexes( label( labelName ) ); Iterable<IndexDefinitionRepresentation> representations = map( definition -> new IndexDefinitionRepresentation( definition, graphDb.schema().getIndexState( definition ), graphDb.schema().getIndexPopulationProgress( definition ) ), definitions ); return new ListRepresentation( RepresentationType.INDEX_DEFINITION, representations ); }
private boolean indexExists( Label label ) { try ( Transaction transaction = db.beginTx() ) { Iterable<IndexDefinition> indexes = db.schema().getIndexes( label ); IndexDefinition index = Iterables.firstOrNull( indexes ); boolean exists = index != null; transaction.success(); return exists; } } }
@Test public void addedUncommittedIndexesShouldBeVisibleWithinTheTransaction() { // GIVEN IndexDefinition indexA = createIndex( db, label, "a" ); createUniquenessConstraint( label, "b" ); // WHEN try ( Transaction tx = db.beginTx() ) { assertThat( count( db.schema().getIndexes( label ) ), is( 2L ) ); IndexDefinition indexC = db.schema().indexFor( label ).on( "c" ).create(); // THEN assertThat( count( db.schema().getIndexes( label ) ), is( 3L ) ); assertThat( db.schema().getIndexState( indexA ), is( Schema.IndexState.ONLINE ) ); assertThat( db.schema().getIndexState( indexC ), is( Schema.IndexState.POPULATING ) ); } }
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; } }
private void indexStateShouldBe( Matcher<Schema.IndexState> matchesExpectation ) { try ( Transaction tx = db.beginTx() ) { for ( IndexDefinition index : db.schema().getIndexes() ) { assertThat( db.schema().getIndexState( index ), matchesExpectation ); } tx.success(); } }
public static void cleanupSchema( GraphDatabaseService db ) { try ( Transaction tx = db.beginTx() ) { for ( ConstraintDefinition constraint : db.schema().getConstraints() ) { constraint.drop(); } for ( IndexDefinition index : db.schema().getIndexes() ) { index.drop(); } tx.success(); } }
private void verifyContent() { GraphDatabaseAPI newDb = db.getGraphDatabaseAPI(); try ( Transaction tx = newDb.beginTx() ) { assertEquals( 1L, Iterators.stream( newDb.schema().getIndexes( label ).iterator() ).count() ); assertNotNull( newDb.findNode( label, propKey, numberValue ) ); assertNotNull( newDb.findNode( label, propKey, stringValue ) ); assertNotNull( newDb.findNode( label, propKey, spatialValue ) ); assertNotNull( newDb.findNode( label, propKey, temporalValue ) ); tx.success(); } }
@Test public void creatingAndDroppingIndexesInSameTransactionMustNotThrow() { db = createDatabase(); try ( Transaction tx = db.beginTx() ) { createSimpleNodesIndex(); db.execute( format( DROP, "nodes" ) ).close(); tx.success(); } try ( Transaction tx = db.beginTx() ) { createSimpleRelationshipIndex(); db.execute( format( DROP, "rels" ) ).close(); tx.success(); } awaitIndexesOnline(); try ( Transaction tx = db.beginTx() ) { assertFalse( db.schema().getIndexes().iterator().hasNext() ); tx.success(); } }
private void dropIndexes() { GraphDatabaseService db = new TestGraphDatabaseFactory() .newEmbeddedDatabaseBuilder( directory.databaseDir() ) .setConfig( GraphDatabaseSettings.pagecache_memory, "8m" ) .newGraphDatabase(); try ( Transaction tx = db.beginTx() ) { for ( IndexDefinition index : db.schema().getIndexes() ) { index.drop(); } tx.success(); } finally { db.shutdown(); } }
@Test public void convertIndexToConstraint() { 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 }