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

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

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

Schema.getConstraints介绍

暂无

代码示例

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

@Override
  public Iterable<ConstraintDefinition> getConstraints()
  {
    return gdb.schema().getConstraints();
  }
}

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

public ListRepresentation getConstraints()
{
  return new ListRepresentation( CONSTRAINT_DEFINITION,
      map( CONSTRAINT_DEF_TO_REPRESENTATION, graphDb.schema().getConstraints() ) );
}

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

@Override
  protected Iterable<ConstraintDefinition> manifest()
  {
    return db.schema().getConstraints( );
  }
};

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

private Iterable<ConstraintDefinition> filteredNodeConstraints( String labelName,
    Predicate<ConstraintDefinition> filter )
{
  Iterable<ConstraintDefinition> constraints = graphDb.schema().getConstraints( label( labelName ) );
  return filter( filter, constraints );
}

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

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

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

@Override
  protected Iterable<ConstraintDefinition> manifest()
  {
    return db.schema().getConstraints( type );
  }
};

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

private Iterable<ConstraintDefinition> filteredRelationshipConstraints( String typeName,
    Predicate<ConstraintDefinition> filter )
{
  RelationshipType type = RelationshipType.withName( typeName );
  Iterable<ConstraintDefinition> constraints = graphDb.schema().getConstraints( type );
  return filter( filter, constraints );
}

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

private Iterable<ConstraintDefinition> filteredRelationshipConstraints( String typeName, final ConstraintType type )
{
  return filter( item -> item.isConstraintType( type ), graphDb.schema().getConstraints( RelationshipType.withName( typeName ) ) );
}

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

private Iterable<ConstraintDefinition> filteredNodeConstraints( String labelName, final ConstraintType type )
{
  return filter( item -> item.isConstraintType( type ), graphDb.schema().getConstraints( label( labelName ) ) );
}

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

private void deleteAllConstraints()
  {
    for ( ConstraintDefinition constraint : db.schema().getConstraints() )
    {
      constraint.drop();
    }
  }
}

代码示例来源: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 dropConstraints()
{
  try ( Transaction tx = db.beginTx() )
  {
    for ( ConstraintDefinition constraint : db.schema().getConstraints( LABEL ) )
    {
      constraint.drop();
    }
    tx.success();
  }
}

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

@Before
public void setup()
{
  try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() )
  {
    for ( ConstraintDefinition definition : graphDb.schema().getConstraints() )
    {
      definition.drop();
    }
    tx.success();
  }
}

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

private ConstraintDefinition getConstraint( Label label, String propertyKey )
  {
    try ( Transaction tx = graphDb.beginTx() )
    {
      ConstraintDefinition found = null;
      for ( ConstraintDefinition constraint : graphDb.schema().getConstraints( label ) )
      {
        if ( propertyKey.equals( single( constraint.getPropertyKeys() ) ) )
        {
          assertNull( "Found multiple constraints.", found );
          found = constraint;
        }
      }
      tx.success();
      return found;
    }
  }
}

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

@Test
public void shouldRecoverCreationOfUniquenessConstraintFollowedByDeletionOfThatSameConstraint() throws Exception
{
  // given
  createUniqueConstraint();
  dropConstraints();
  // when - perform recovery
  restart( snapshot( storeDir.absolutePath() ) );
  // then - just make sure the constraint is gone
  try ( Transaction tx = db.beginTx() )
  {
    assertFalse( db.schema().getConstraints( LABEL ).iterator().hasNext() );
    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

@Test
public void shouldDropUniquenessConstraintWithBackingIndexNotInUse()
{
  // given
  try ( Transaction tx = db.beginTx() )
  {
    db.schema().constraintFor( label ).assertPropertyIsUnique( key ).create();
    tx.success();
  }
  // when intentionally breaking the schema by setting the backing index rule to unused
  RecordStorageEngine storageEngine = db.getDependencyResolver().resolveDependency( RecordStorageEngine.class );
  SchemaStore schemaStore = storageEngine.testAccessNeoStores().getSchemaStore();
  SchemaRule indexRule = single( filter( rule -> rule instanceof StoreIndexDescriptor, schemaStore.loadAllSchemaRules() ) );
  setSchemaRecordNotInUse( schemaStore, indexRule.getId() );
  // At this point the SchemaCache doesn't know about this change so we have to reload it
  storageEngine.loadSchemaCache();
  try ( Transaction tx = db.beginTx() )
  {
    single( db.schema().getConstraints( label ).iterator() ).drop();
    tx.success();
  }
  // then
  try ( Transaction ignore = db.beginTx() )
  {
    assertFalse( db.schema().getConstraints().iterator().hasNext() );
    assertFalse( db.schema().getIndexes().iterator().hasNext() );
  }
}

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

public Iterable<ConstraintDefinition> getPropertyUniquenessConstraints( String labelName, final String propertyKey )
{
  try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.read() ) )
  {
    Iterable<ConstraintDefinition> definitions = Iterables.filter( item ->
    {
      if ( item.isConstraintType( ConstraintType.UNIQUENESS ) )
      {
        Iterable<String> keys = item.getPropertyKeys();
        return single( keys ).equals( propertyKey );
      }
      else
      {
        return false;
      }
    }, database.getGraph().schema().getConstraints( label( labelName ) ) );
    tx.success();
    return definitions;
  }
}

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

private static void shouldHaveUniquenessConstraintForNamePropertyOnPersonLabel( GraphDatabaseService db )
{
  try ( Transaction tx = db.beginTx() )
  {
    ConstraintDefinition constraint = Iterables.single( db.schema().getConstraints() );
    assertEquals( ConstraintType.UNIQUENESS, constraint.getConstraintType() );
    assertEquals( "Person", constraint.getLabel().name() );
    assertEquals( "name", Iterables.single( constraint.getPropertyKeys() ) );
    tx.success();
  }
}

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

@Test
public void convertConstraintToIndex()
{
  try ( Transaction tx = graphDb.beginTx() )
  {
    graphDb.schema().constraintFor( LABEL ).assertPropertyIsUnique( PROPERTY_KEY ).create();
    tx.success();
  }
  try ( Transaction tx = graphDb.beginTx() )
  {
    ConstraintDefinition constraint = firstOrNull( graphDb.schema().getConstraints( LABEL ) );
    constraint.drop();
    graphDb.schema().indexFor( LABEL ).on( PROPERTY_KEY ).create();
    tx.success();
  }
  // assert no exception is thrown
}

相关文章