org.neo4j.graphdb.schema.Schema.getIndexes()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(167)

本文整理了Java中org.neo4j.graphdb.schema.Schema.getIndexes()方法的一些代码示例,展示了Schema.getIndexes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Schema.getIndexes()方法的具体详情如下:
包路径:org.neo4j.graphdb.schema.Schema
类名称:Schema
方法名:getIndexes

Schema.getIndexes介绍

暂无

代码示例

代码示例来源:origin: neo4j/neo4j

@Override
public Iterable<IndexDefinition> getIndexes()
{
  return gdb.schema().getIndexes();
}

代码示例来源:origin: neo4j/neo4j

@Override
  protected Iterable<IndexDefinition> manifest()
  {
    return db.schema().getIndexes( label );
  }
};

代码示例来源:origin: neo4j/neo4j

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;
}

代码示例来源:origin: neo4j/neo4j

private List<IndexDefinition> indexes( GraphDatabaseService database )
{
  try ( Transaction ignored = database.beginTx() )
  {
    return Iterables.asList( database.schema().getIndexes() );
  }
}

代码示例来源:origin: neo4j/neo4j

private long countIndexes()
{
  try ( Transaction transaction = database.beginTx() )
  {
    return Iterables.count( database.schema().getIndexes() );
  }
}

代码示例来源:origin: neo4j/neo4j

public Iterable<IndexDefinition> getSchemaIndexes( String labelName )
{
  return database.getGraph().schema().getIndexes( label( labelName ) );
}

代码示例来源:origin: neo4j/neo4j

private void deleteAllIndexRules()
{
  for ( IndexDefinition index : db.schema().getIndexes() )
  {
    if ( !index.isConstraintIndex() )
    {
      index.drop();
    }
  }
}

代码示例来源:origin: neo4j/neo4j

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;
}

代码示例来源:origin: neo4j/neo4j

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 );
}

代码示例来源:origin: neo4j/neo4j

private static void dropAllIndexes( GraphDatabaseService database )
{
  try ( Transaction transaction = database.beginTx() )
  {
    for ( IndexDefinition definition : database.schema().getIndexes() )
    {
      definition.drop();
    }
    transaction.success();
  }
}

代码示例来源:origin: neo4j/neo4j

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 );
}

代码示例来源:origin: neo4j/neo4j

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;
    }
  }
}

代码示例来源:origin: neo4j/neo4j

@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 ) );
  }
}

代码示例来源:origin: neo4j/neo4j

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;
  }
}

代码示例来源:origin: neo4j/neo4j

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();
  }
}

代码示例来源:origin: neo4j/neo4j

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();
  }
}

代码示例来源:origin: neo4j/neo4j

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();
  }
}

代码示例来源:origin: neo4j/neo4j

@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();
  }
}

代码示例来源:origin: neo4j/neo4j

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();
  }
}

代码示例来源:origin: neo4j/neo4j

@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
}

相关文章