org.neo4j.graphdb.schema.Schema类的使用及代码示例

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

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

Schema介绍

[英]Interface for managing the schema of your graph database. This currently includes the indexing support added in Neo4j 2.0. Please see the Neo4j manual for details. Compatibility note: New methods may be added to this interface without notice, backwards compatibility is only guaranteed for clients of this interface, not for implementors.
[中]用于管理图形数据库架构的接口。这目前包括Neo4j 2.0中添加的索引支持。有关详细信息,请参阅Neo4j手册。兼容性说明:新方法可能会在不通知的情况下添加到此接口,向后兼容性仅保证此接口的客户端,不保证实现者。

代码示例

代码示例来源: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

private List<ConstraintDefinition> constraints( GraphDatabaseService database )
{
  try ( Transaction ignored = database.beginTx() )
  {
    return Iterables.asList( database.schema().getConstraints() );
  }
}

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

private void createIndex()
{
  try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() )
  {
    graphDb.schema().indexFor( Label.label( "Node" ) ).on( "prop" ).create();
    tx.success();
  }
  try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() )
  {
    graphDb.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES );
  }
}

代码示例来源: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

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 void createConstraint( GraphDatabaseService database )
{
  try ( Transaction transaction = database.beginTx() )
  {
    Schema schema = database.schema();
    schema.constraintFor( constraintIndexLabel ).assertPropertyIsUnique( UNIQUE_PROPERTY_NAME ).create();
    transaction.success();
  }
}

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

public IndexDefinitionRepresentation createSchemaIndex( String labelName, Iterable<String> propertyKey )
{
  IndexCreator indexCreator = graphDb.schema().indexFor( label( labelName ) );
  for ( String key : propertyKey )
  {
    indexCreator = indexCreator.on( key );
  }
  return new IndexDefinitionRepresentation( indexCreator.create() );
}

代码示例来源: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
}

代码示例来源:origin: org.neo4j.examples/neo4j-examples

try ( Transaction tx = graphDb.beginTx() )
  Schema schema = graphDb.schema();
  indexDefinition = schema.indexFor( Label.label( "User" ) )
      .on( "username" )
      .create();
  tx.success();
try ( Transaction tx = graphDb.beginTx() )
  Schema schema = graphDb.schema();
  schema.awaitIndexOnline( indexDefinition, 10, TimeUnit.SECONDS );
  Schema schema = graphDb.schema();
  System.out.println( String.format( "Percent complete: %1.0f%%",
      schema.getIndexPopulationProgress( indexDefinition ).getCompletedPercentage() ) );
try ( Transaction tx = graphDb.beginTx() )
  Label label = Label.label( "User" );
  tx.success();
  tx.success();
  Label label = Label.label( "User" );
  for ( IndexDefinition indexDefinition : graphDb.schema()
      .getIndexes( label ) )

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

try ( Transaction tx = db.beginTx() )
  indexDefinition = db.schema().indexFor( label ).on( property ).create();
  tx.success();
try ( Transaction tx = db.beginTx() )
  db.schema().awaitIndexOnline( indexDefinition, 10, TimeUnit.SECONDS );
  tx.success();
    db.createNode( label ).setProperty( property, names[i % names.length] );
    tx.success();

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

@Test
public void testSchemaIndexMatchIndexingService() throws IndexNotFoundKernelException
{
  try ( Transaction transaction = database.beginTx() )
  {
    database.schema().constraintFor( Label.label( CLOTHES_LABEL ) ).assertPropertyIsUnique( PROPERTY_NAME ).create();
    database.schema().indexFor( Label.label( WEATHER_LABEL ) ).on( PROPERTY_NAME ).create();
    transaction.success();
  }
  try ( Transaction ignored = database.beginTx() )
  {
    database.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES );
  }
  IndexingService indexingService = getIndexingService( database );
  int clothedLabelId = getLabelId( CLOTHES_LABEL );
  int weatherLabelId = getLabelId( WEATHER_LABEL );
  int propertyId = getPropertyKeyId( PROPERTY_NAME );
  IndexProxy clothesIndex = indexingService.getIndexProxy( forLabel( clothedLabelId, propertyId ) );
  IndexProxy weatherIndex = indexingService.getIndexProxy( forLabel( weatherLabelId, propertyId ) );
  assertEquals( InternalIndexState.ONLINE, clothesIndex.getState());
  assertEquals( InternalIndexState.ONLINE, weatherIndex.getState());
}

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

@Test
public void shouldThrowWhenPopulatingWithNonUniquePoints() throws Exception
{
  Config config = Config.defaults( stringMap( default_schema_provider.name(), schemaIndex.providerName() ) );
  BatchInserter inserter = newBatchInserter( config );
  PointValue point = Values.pointValue( CoordinateReferenceSystem.WGS84, 0.0, 0.0 );
  inserter.createNode( MapUtil.map( "prop", point ), TestLabels.LABEL_ONE );
  inserter.createNode( MapUtil.map( "prop", point ), TestLabels.LABEL_ONE );
  inserter.createDeferredConstraint( TestLabels.LABEL_ONE ).assertPropertyIsUnique( "prop" ).create();
  inserter.shutdown();
  GraphDatabaseService db = graphDatabaseService( config );
  try ( Transaction tx = db.beginTx() )
  {
    Iterator<IndexDefinition> indexes = db.schema().getIndexes().iterator();
    assertTrue( indexes.hasNext() );
    IndexDefinition index = indexes.next();
    Schema.IndexState indexState = db.schema().getIndexState( index );
    assertEquals( Schema.IndexState.FAILED, indexState );
    assertFalse( indexes.hasNext() );
    tx.success();
  }
  finally
  {
    db.shutdown();
  }
}

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

private void createUniquenessConstraint( Label label, String propertyKey )
{
  try ( Transaction tx = db.beginTx() )
  {
    db.schema().constraintFor( label ).assertPropertyIsUnique( propertyKey ).create();
    tx.success();
  }
}

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

private void waitForOnlineIndexes()
{
  try ( Transaction transaction = database.beginTx() )
  {
    database.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES );
    transaction.success();
  }
}

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

private boolean indexesAreOnline( GraphDatabaseService db )
{
  try ( Transaction tx = db.beginTx() )
  {
    for ( IndexDefinition index : db.schema().getIndexes() )
    {
      switch ( db.schema().getIndexState( index ) )
      {
      case ONLINE:
        break; // Good
      case POPULATING:
        return false; // Still populating
      case FAILED:
        fail( index + " entered failed state: " + db.schema().getIndexFailure( index ) );
      default:
        throw new UnsupportedOperationException();
      }
    }
    tx.success();
  }
  return true;
}

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

private void awaitIndexOnline( IndexDefinition definition )
{
  try ( Transaction tx = db.beginTx() )
  {
    db.schema().awaitIndexOnline( definition, 10, TimeUnit.SECONDS );
    tx.success();
  }
}

代码示例来源: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

@Override
  protected ConstraintDefinition obtainEntityInTransaction( GraphDatabaseService graphDatabaseService )
  {
    return graphDatabaseService
        .schema()
        .constraintFor( Label.label( "Label" ) )
        .assertPropertyIsUnique( "property" )
        .create();
  }
}

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

db.schema().indexFor( LABEL_ONE ).on( propKey ).create();
tx.success();
db.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES );
tx.success();
Iterator<IndexDefinition> iterator = db.schema().getIndexes( LABEL_ONE ).iterator();
assertTrue( iterator.hasNext() );
IndexDefinition next = iterator.next();
assertEquals( "state is FAILED", Schema.IndexState.FAILED, db.schema().getIndexState( next ) );
assertThat( db.schema().getIndexFailure( next ),
    Matchers.containsString( "Index key-value size it to large. Please see index documentation for limitations." ) );
tx.success();

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

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

相关文章