org.neo4j.graphdb.Relationship.hasProperty()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(158)

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

Relationship.hasProperty介绍

暂无

代码示例

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

@Override
  void perform( Graph graph, ExpectedTransactionData expectations )
  {
    Relationship relationship = graph.randomRelationship();
    if ( relationship != null )
    {
      String key = graph.randomPropertyKey();
      if ( relationship.hasProperty( key ) )
      {
        Object valueBefore = relationship.removeProperty( key );
        expectations.removedProperty( relationship, key, valueBefore );
        debug( relationship + " " + key + "=" + valueBefore );
      }
    }
  }
},

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

@Test
public void testRelationshipAddProperty()
{
  Node node1 = getGraphDb().createNode();
  Node node2 = getGraphDb().createNode();
  Relationship rel1 = node1.createRelationshipTo( node2, TEST );
  Relationship rel2 = node2.createRelationshipTo( node1, TEST );
  Integer int1 = 1;
  Integer int2 = 2;
  String string1 = "1";
  String string2 = "2";
  // add property
  rel1.setProperty( key1, int1 );
  rel2.setProperty( key1, string1 );
  rel1.setProperty( key2, string2 );
  rel2.setProperty( key2, int2 );
  assertTrue( rel1.hasProperty( key1 ) );
  assertTrue( rel2.hasProperty( key1 ) );
  assertTrue( rel1.hasProperty( key2 ) );
  assertTrue( rel2.hasProperty( key2 ) );
  assertTrue( !rel1.hasProperty( key3 ) );
  assertTrue( !rel2.hasProperty( key3 ) );
  assertEquals( int1, rel1.getProperty( key1 ) );
  assertEquals( string1, rel2.getProperty( key1 ) );
  assertEquals( string2, rel1.getProperty( key2 ) );
  assertEquals( int2, rel2.getProperty( key2 ) );
  getTransaction().failure();
}

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

assertTrue( !rel1.hasProperty( key1 ) );
assertTrue( !rel1.hasProperty( null ) );
rel1.setProperty( key1, int1 );
rel1.setProperty( key2, int2 );
rel1.setProperty( key3, string );
assertTrue( rel1.hasProperty( key1 ) );
assertTrue( rel1.hasProperty( key2 ) );
assertTrue( rel1.hasProperty( key3 ) );
assertTrue( !rel1.hasProperty( key3 ) );
assertTrue( !rel1.hasProperty( null ) );
rel1.delete();
node2.delete();

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

assertFalse( graphDb.getRelationshipById( relationshipId ).hasProperty( "prop" ) );

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

@Test
public void shouldRemoveNonExistingPropertyFromRelationship() throws Exception
{
  // Given
  long  relationshipId;
  String propertyKey = "prop";
  try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() )
  {
    Node node1 = graphDb.createNode();
    Node node2 = graphDb.createNode();
    Relationship proxy = node1.createRelationshipTo( node2, RelationshipType.withName( "R" ) );
    relationshipId = proxy.getId();
    tx.success();
  }
  // When
  try ( Transaction tx = beginTransaction() )
  {
    int token = tx.token().propertyKeyGetOrCreateForName( propertyKey );
    assertThat( tx.dataWrite().relationshipRemoveProperty( relationshipId, token ),
        equalTo( NO_VALUE ) );
    tx.success();
  }
  // Then
  try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() )
  {
    assertFalse( graphDb.getRelationshipById( relationshipId ).hasProperty( "prop" ) );
  }
}

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

@Test
public void shouldRemovePropertyFromRelationship() throws Exception
{
  // Given
  long  relationshipId;
  String propertyKey = "prop";
  try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() )
  {
    Node node1 = graphDb.createNode();
    Node node2 = graphDb.createNode();
    Relationship proxy = node1.createRelationshipTo( node2, RelationshipType.withName( "R" ) );
    relationshipId = proxy.getId();
    proxy.setProperty( propertyKey, 42 );
    tx.success();
  }
  // When
  try ( Transaction tx = beginTransaction() )
  {
    int token = tx.token().propertyKeyGetOrCreateForName( propertyKey );
    assertThat( tx.dataWrite().relationshipRemoveProperty( relationshipId, token ),
        equalTo( intValue( 42 ) ) );
    tx.success();
  }
  // Then
  try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() )
  {
    assertFalse( graphDb.getRelationshipById( relationshipId ).hasProperty( "prop" ) );
  }
}

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

private void verifyData( int expectedNodeCount, int expectedRelationshipCount,
    Validator<Node> nodeAdditionalValidation,
    Validator<Relationship> relationshipAdditionalValidation )
{
  GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
  try ( Transaction tx = db.beginTx() )
  {
    int nodeCount = 0;
    int relationshipCount = 0;
    for ( Node node : db.getAllNodes() )
    {
      assertTrue( node.hasProperty( "name" ) );
      nodeAdditionalValidation.validate( node );
      nodeCount++;
    }
    assertEquals( expectedNodeCount, nodeCount );
    for ( Relationship relationship : db.getAllRelationships() )
    {
      assertTrue( relationship.hasProperty( "created" ) );
      relationshipAdditionalValidation.validate( relationship );
      relationshipCount++;
    }
    assertEquals( expectedRelationshipCount, relationshipCount );
    tx.success();
  }
}

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

@Test
public void testRelMultiRemoveProperty()
{
  Node node1 = getGraphDb().createNode();
  Node node2 = getGraphDb().createNode();
  Relationship rel = node1.createRelationshipTo( node2, MyRelTypes.TEST );
  rel.setProperty( "key0", "0" );
  rel.setProperty( "key1", "1" );
  rel.setProperty( "key2", "2" );
  rel.setProperty( "key3", "3" );
  rel.setProperty( "key4", "4" );
  newTransaction();
  rel.removeProperty( "key3" );
  rel.removeProperty( "key2" );
  rel.removeProperty( "key3" );
  newTransaction();
  assertEquals( "0", rel.getProperty( "key0" ) );
  assertEquals( "1", rel.getProperty( "key1" ) );
  assertEquals( "4", rel.getProperty( "key4" ) );
  assertTrue( !rel.hasProperty( "key2" ) );
  assertTrue( !rel.hasProperty( "key3" ) );
  rel.delete();
  node1.delete();
  node2.delete();
}

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

assertFalse( rel.hasProperty( "int" + ( j * 10 + i ) ) );
assertFalse( rel.hasProperty( "int" + ( j * 10 + i ) ) );

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

assertFalse( relationship.hasProperty( testPropertyKey ) );
tx.success();

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

assertFalse( relationship.hasProperty( testPropertyKey ) );
tx.success();

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test public void testRemoveRelProperty() throws Exception {
  testCall(db, "CREATE (n)-[r:TEST {name:'foo'}]->(m) WITH r CALL apoc.create.setRelProperty(r,'name',null) YIELD rel RETURN rel",
      (row) -> assertEquals(false, ((Relationship) row.get("rel")).hasProperty("name")));
  testCall(db, "CREATE (n)-[r:TEST {name:'foo'}]->(m) WITH r CALL apoc.create.removeRelProperties(r,['name']) YIELD rel RETURN rel",
      (row) -> assertEquals(false, ((Relationship) row.get("rel")).hasProperty("name")));
}
@Test public void testSetRelProperties() throws Exception {

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

@Test
public void testAddProperty()
{
  String key3 = "key3";
  Node node1 = getGraphDb().getNodeById( node1Id );
  Node node2 = getGraphDb().getNodeById( node2Id );
  Relationship rel = node1.getSingleRelationship( MyRelTypes.TEST,
    Direction.BOTH );
  // add new property
  node2.setProperty( key3, int1 );
  rel.setProperty( key3, int2 );
  assertTrue( node1.hasProperty( key1 ) );
  assertTrue( node2.hasProperty( key1 ) );
  assertTrue( node1.hasProperty( key2 ) );
  assertTrue( node2.hasProperty( key2 ) );
  assertTrue( node1.hasProperty( arrayKey ) );
  assertTrue( node2.hasProperty( arrayKey ) );
  assertTrue( rel.hasProperty( arrayKey ) );
  assertTrue( !node1.hasProperty( key3 ) );
  assertTrue( node2.hasProperty( key3 ) );
  assertEquals( int1, node1.getProperty( key1 ) );
  assertEquals( int2, node2.getProperty( key1 ) );
  assertEquals( string1, node1.getProperty( key2 ) );
  assertEquals( string2, node2.getProperty( key2 ) );
  assertEquals( int1, rel.getProperty( key1 ) );
  assertEquals( string1, rel.getProperty( key2 ) );
  assertEquals( int2, rel.getProperty( key3 ) );
}

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

graphDb.getRelationshipById( relationshipId ).hasProperty( propKey ) );

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

@Override
public boolean hasProperty( String key )
{
  return actual.hasProperty( key );
}

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

boolean hasRelationshipProperty( GraphDatabaseService graphDb, long relationshiId,
  String key )
{
  return graphDb.getRelationshipById( relationshiId ).hasProperty( key );
}

代码示例来源:origin: graphaware/neo4j-algorithms

/**
 * {@inheritDoc}
 */
@Override
public long getCost(Relationship relationship) {
  if (!relationship.hasProperty(costPropertyKey)) {
    return getDefaultCost();
  }
  return objectToLong(relationship.getProperty(costPropertyKey));
}

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

@Test
public void edgeWithLabeledNodeIsTagged() {
 Relationship rel =
   n1.getRelationships(RelationshipType.withName(relationshipType1)).iterator().next();
 assertThat(rel.hasProperty(EdgeLabeler.edgeProperty), is(true));
 assertThat(GraphUtil.getProperty(rel, EdgeLabeler.edgeProperty, String.class).get(),
   is(relationshipType1Label));
}

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

@Test
public void edgeWithoutNodeIsTaggedWithType() {
 Relationship rel =
   n1.getRelationships(RelationshipType.withName(relationshipType3)).iterator().next();
 assertThat(rel.hasProperty(EdgeLabeler.edgeProperty), is(true));
 assertThat(GraphUtil.getProperty(rel, EdgeLabeler.edgeProperty, String.class).get(),
   is(relationshipType3));
}

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

@Test
public void edgeWithNodeIsTaggedWithType() {
 Relationship rel =
   n1.getRelationships(RelationshipType.withName(relationshipType2)).iterator().next();
 assertThat(rel.hasProperty(EdgeLabeler.edgeProperty), is(true));
 assertThat(GraphUtil.getProperty(rel, EdgeLabeler.edgeProperty, String.class).get(),
   is(relationshipType2));
}

相关文章