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

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

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

Schema.constraintFor介绍

[英]Returns a ConstraintCreator where details about the constraint can be specified. When all details have been entered ConstraintCreator#create()must be called for it to actually be created. Creating a constraint will block on the ConstraintCreator#create() until all existing data has been verified for compliance. If any existing data doesn't comply with the constraint an exception will be thrown, and the constraint will not be created.
[中]

代码示例

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

@Override
  protected ConstraintCreator obtainEntityInTransaction( GraphDatabaseService graphDatabaseService )
  {
    return graphDatabaseService
        .schema()
        .constraintFor( Label.label( "Label" ) );
  }
}

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

public ConstraintDefinitionRepresentation createPropertyUniquenessConstraint( String labelName,
    Iterable<String> propertyKeys )
{
  ConstraintCreator constraintCreator = graphDb.schema().constraintFor( label( labelName ) );
  for ( String key : propertyKeys )
  {
    constraintCreator = constraintCreator.assertPropertyIsUnique( key );
  }
  ConstraintDefinition constraintDefinition = constraintCreator.create();
  return new ConstraintDefinitionRepresentation( constraintDefinition );
}

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

public static Function<GraphDatabaseService,Void> uniquenessConstraint( Label label, String propertyKey )
{
  return graphDb ->
  {
    graphDb.schema().constraintFor( label ).assertPropertyIsUnique( propertyKey ).create();
    return null;
  };
}

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

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

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

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

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

private static Function<GraphDatabaseService, Void> createUniquenessConstraint(
    final String label, final String propertyKey )
{
  return db ->
  {
    db.schema().constraintFor( label( label ) ).assertPropertyIsUnique( propertyKey ).create();
    return null;
  };
}

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

private static Consumer<GraphDatabaseService> uniquenessConstraint( String label, String prop )
{
  return db -> db.schema().constraintFor( Label.label( label ) ).assertPropertyIsUnique( prop ).create();
}

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

@Test
public void testExportUniquenessConstraint()
{
  gdb.schema().constraintFor( Label.label( "Foo" ) ).assertPropertyIsUnique( "bar" ).create();
  assertEquals( "create constraint on (n:`Foo`) assert n.`bar` is unique;" + lineSeparator(),
      doExportGraph( gdb ) );
}

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

public static ConstraintDefinition createConstraint( GraphDatabaseService db, Label label, String propertyKey )
{
  try ( Transaction tx = db.beginTx() )
  {
    ConstraintDefinition constraint =
        db.schema().constraintFor( label ).assertPropertyIsUnique( propertyKey ).create();
    tx.success();
    return constraint;
  }
}

代码示例来源: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 ConstraintDefinition createUniquenessConstraint( Label label, String prop )
{
  try ( Transaction tx = db.beginTx() )
  {
    ConstraintDefinition constraint =
        db.schema().constraintFor( label ).assertPropertyIsUnique( prop ).create();
    tx.success();
    return constraint;
  }
}

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

private void createUniqueConstraint()
{
  try ( Transaction tx = db.beginTx() )
  {
    db.schema().constraintFor( LABEL ).assertPropertyIsUnique( PROPERTY_KEY ).create();
    tx.success();
  }
}

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

private void addConstraints( String... labelProps )
  {
    assert labelProps.length % 2 == 0;

    try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() )
    {
      for ( int i = 0; i < labelProps.length; i += 2 )
      {
        graphDb.schema().constraintFor( label( labelProps[i] ) ).assertPropertyIsUnique( labelProps[i + 1] )
            .create();
      }
      tx.success();
    }
  }
}

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

private ConstraintDefinition recreate( ConstraintDefinition constraint, int times )
{
  for ( int i = 0; i < times; i++ )
  {
    constraint.drop();
    constraint = graphDb.schema()
        .constraintFor( constraint.getLabel() )
        .assertPropertyIsUnique( single( constraint.getPropertyKeys() ) )
        .create();
  }
  return constraint;
}

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

private ConstraintDefinition createLabelUniquenessPropertyConstraint( String labelName, String propertyKey )
{
  try ( Transaction tx = graphdb().beginTx() )
  {
    ConstraintDefinition constraintDefinition = graphdb().schema().constraintFor( label( labelName ) )
        .assertPropertyIsUnique( propertyKey ).create();
    tx.success();
    return constraintDefinition;
  }
}

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

@Override
protected void startup( File storeDir )
{
  GraphDatabaseService database = new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDir );
  try ( Transaction transaction = database.beginTx() )
  {
    database.schema().constraintFor( label("User") ).assertPropertyIsUnique( "uuid" ).create();
    transaction.success();
  }
  started = true;
}

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

public ConstraintDefinition createPropertyUniquenessConstraint( String labelName, List<String> propertyKeys )
{
  try ( Transaction tx = database.getGraph().beginTransaction( implicit, AUTH_DISABLED ) )
  {
    ConstraintCreator creator = database.getGraph().schema().constraintFor( label( labelName ) );
    for ( String propertyKey : propertyKeys )
    {
      creator = creator.assertPropertyIsUnique( propertyKey );
    }
    ConstraintDefinition result = creator.create();
    tx.success();
    return result;
  }
}

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

private void createUniquenessConstraint()
{
  try ( Transaction tx = db.beginTx() )
  {
    db.schema().constraintFor( TestLabels.LABEL_ONE ).assertPropertyIsUnique( KEY ).create();
    tx.success();
  }
  try ( Transaction tx = db.beginTx() )
  {
    db.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES );
    tx.success();
  }
}

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

private static void createUniqueConstraint( GraphDatabaseAPI database, Label label, String nameProperty )
  {
    try ( Transaction transaction = database.beginTx() )
    {
      database.schema().constraintFor( label ).assertPropertyIsUnique( nameProperty ).create();
      transaction.success();
    }
    try ( Transaction transaction = database.beginTx() )
    {
      database.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES );
      transaction.success();
    }
  }
}

相关文章