本文整理了Java中org.neo4j.graphdb.Relationship.getProperty
方法的一些代码示例,展示了Relationship.getProperty
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Relationship.getProperty
方法的具体详情如下:
包路径:org.neo4j.graphdb.Relationship
类名称:Relationship
方法名:getProperty
暂无
代码示例来源:origin: neo4j/neo4j
@Override
public Double getCost( Relationship relationship, Direction direction )
{
return ( (Number) relationship.getProperty( costPropertyName, defaultCost ) ).doubleValue();
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldStoreSuppliedPropertiesWhenCreatingRelationship() throws Exception
{
Map<String, Object> properties = new HashMap<>();
properties.put( "string", "value" );
properties.put( "integer", 17 );
long relId = actions.createRelationship( graphdbHelper.createNode(), graphdbHelper.createNode(), "LOVES",
properties )
.getId();
try ( Transaction tx = database.getGraph().beginTx() )
{
Relationship rel = database.getGraph().getRelationshipById( relId );
for ( String key : rel.getPropertyKeys() )
{
assertTrue( "extra property stored", properties.containsKey( key ) );
}
for ( Map.Entry<String, Object> entry : properties.entrySet() )
{
assertEquals( entry.getValue(), rel.getProperty( entry.getKey() ) );
}
}
}
代码示例来源:origin: neo4j/neo4j
@Override
public Double getCost( Relationship relationship, Direction direction )
{
Object costProp = relationship.getProperty(costPropertyName);
if ( costProp instanceof Number )
{
return ((Number) costProp).doubleValue();
}
else
{
return Double.parseDouble(costProp.toString());
}
}
}
代码示例来源:origin: neo4j/neo4j
@Override
public Integer getCost( Relationship relationship, Direction direction )
{
Object costProp = relationship.getProperty( costPropertyName );
if ( costProp instanceof Number )
{
return ((Number) costProp).intValue();
}
else
{
return Integer.parseInt( costProp.toString() );
}
}
}
代码示例来源:origin: neo4j/neo4j
public Representation getRelationshipProperty( long relationshipId,
String key ) throws NoSuchPropertyException,
RelationshipNotFoundException
{
Relationship relationship = relationship( relationshipId );
try
{
return PropertiesRepresentation.value( relationship.getProperty( key ) );
}
catch ( NotFoundException e )
{
throw new NoSuchPropertyException( relationship, key );
}
}
代码示例来源:origin: neo4j/neo4j
private Relationship findRelationship( Node startNode, final Node endNode, final RelationshipDataLine relationship )
{
return Iterators.singleOrNull( Iterators.filter(
item -> item.getEndNode().equals( endNode ) &&
item.getProperty( "name" ).equals( relationship.name ),
startNode.getRelationships( withName( relationship.type ) ).iterator() ) );
}
代码示例来源:origin: neo4j/neo4j
@Override
public Iterable<Relationship> expand( Path path, BranchState<Integer> state )
{
if ( path.length() > 0 )
{
int newState = state.getState() + ((Number)path.lastRelationship().getProperty( "weight" )).intValue();
state.setState( newState );
encounteredState.put( path.endNode(), newState );
}
return path.endNode().getRelationships();
}
代码示例来源:origin: neo4j/neo4j
@Test
public void testGetDirectedRelationship()
{
Node node1 = getGraphDb().getNodeById( node1Id );
Relationship rel = node1.getSingleRelationship( MyRelTypes.TEST,
Direction.OUTGOING );
assertEquals( int1, rel.getProperty( key1 ) );
}
代码示例来源:origin: neo4j/neo4j
@Override
public Iterable<Relationship> expand( Path path, BranchState<Double> state )
{
double newState = state.getState();
if ( path.length() > 0 )
{
newState += (Double) path.lastRelationship().getProperty( "length" );
state.setState( newState );
}
seenBranchStates.put( path.endNode(), newState );
return path.endNode().getRelationships( OUTGOING );
}
代码示例来源:origin: neo4j/neo4j
@Override
void perform( Graph graph, ExpectedTransactionData expectations )
{
Relationship relationship = graph.randomRelationship();
if ( relationship != null )
{
String key = graph.randomPropertyKey();
Object valueBefore = relationship.getProperty( key, null );
Object value = graph.randomPropertyValue();
relationship.setProperty( key, value );
expectations.assignedProperty( relationship, key, value, valueBefore );
debug( relationship + " " + key + "=" + value + " prev " + valueBefore );
}
}
},
代码示例来源:origin: neo4j/neo4j
@Test
public void testChangeProperty2()
{
// Create relationship with "test"="test1"
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
Relationship rel = node1.createRelationshipTo( node2, TEST );
rel.setProperty( "test", "test1" );
newTransaction(); // commit
// Remove "test" and set "test"="test3" instead
rel.removeProperty( "test" );
rel.setProperty( "test", "test3" );
assertEquals( "test3", rel.getProperty( "test" ) );
newTransaction(); // commit
// Remove "test" and set "test"="test4" instead
assertEquals( "test3", rel.getProperty( "test" ) );
rel.removeProperty( "test" );
rel.setProperty( "test", "test4" );
newTransaction(); // commit
// Should still be "test4"
assertEquals( "test4", rel.getProperty( "test" ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldUpdatePropertyToRelationshipInTransaction() throws Exception
{
// Given
long relationshipId;
String propertyKey = "prop";
try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() )
{
Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
relationshipId = node1.createRelationshipTo( node2, RelationshipType.withName( "R" ) ).getId();
tx.success();
}
// When
try ( Transaction tx = beginTransaction() )
{
int token = tx.token().propertyKeyGetOrCreateForName( propertyKey );
assertThat( tx.dataWrite().relationshipSetProperty( relationshipId, token, stringValue( "hello" ) ), equalTo( NO_VALUE ) );
assertThat( tx.dataWrite().relationshipSetProperty( relationshipId, token, stringValue( "world" ) ), equalTo( stringValue( "hello" ) ) );
assertThat( tx.dataWrite().relationshipSetProperty( relationshipId, token, intValue( 1337 ) ), equalTo( stringValue( "world" ) ) );
tx.success();
}
// Then
try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() )
{
assertThat( graphDb.getRelationshipById( relationshipId ).getProperty( "prop" ), equalTo( 1337 ) );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldAddPropertyToRelationship() throws Exception
{
// Given
long relationshipId;
String propertyKey = "prop";
try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() )
{
Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
relationshipId = node1.createRelationshipTo( node2, RelationshipType.withName( "R" ) ).getId();
tx.success();
}
// When
try ( Transaction tx = beginTransaction() )
{
int token = tx.token().propertyKeyGetOrCreateForName( propertyKey );
assertThat( tx.dataWrite().relationshipSetProperty( relationshipId, token, stringValue( "hello" ) ), equalTo( NO_VALUE ) );
tx.success();
}
// Then
try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() )
{
assertThat( graphDb.getRelationshipById( relationshipId ).getProperty( "prop" ), equalTo( "hello" ) );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldBeAbleToForceTypeChangeOfProperty()
{
// Given
Relationship relationship;
try ( Transaction tx = db.beginTx() )
{
relationship = db.createNode().createRelationshipTo( db.createNode(), withName( "R" ) );
relationship.setProperty( "prop", 1337 );
tx.success();
}
// When
try ( Transaction tx = db.beginTx() )
{
relationship.setProperty( "prop", 1337.0 );
tx.success();
}
// Then
try ( Transaction ignore = db.beginTx() )
{
assertThat( relationship.getProperty( "prop" ), instanceOf( Double.class ) );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void testChangeProperty()
{
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
Relationship rel = node1.createRelationshipTo( node2, TEST );
rel.setProperty( "test", "test1" );
newTransaction();
rel.setProperty( "test", "test2" );
rel.removeProperty( "test" );
rel.setProperty( "test", "test3" );
assertEquals( "test3", rel.getProperty( "test" ) );
rel.removeProperty( "test" );
rel.setProperty( "test", "test4" );
newTransaction();
assertEquals( "test4", rel.getProperty( "test" ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void testRelationshipChangeProperty2()
{
Integer int1 = 1;
Integer int2 = 2;
String string1 = "1";
String string2 = "2";
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
Relationship rel1 = node1.createRelationshipTo( node2, TEST );
rel1.setProperty( key1, int1 );
rel1.setProperty( key1, int2 );
assertEquals( int2, rel1.getProperty( key1 ) );
rel1.removeProperty( key1 );
rel1.setProperty( key1, string1 );
rel1.setProperty( key1, string2 );
assertEquals( string2, rel1.getProperty( key1 ) );
rel1.removeProperty( key1 );
rel1.setProperty( key1, true );
rel1.setProperty( key1, false );
assertEquals( false, rel1.getProperty( key1 ) );
rel1.removeProperty( key1 );
rel1.delete();
node2.delete();
node1.delete();
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldUpdatePropertyToRelationship() 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 r = node1.createRelationshipTo( node2, RelationshipType.withName( "R" ) );
r.setProperty( propertyKey, 42 );
relationshipId = r.getId();
tx.success();
}
// When
try ( Transaction tx = beginTransaction() )
{
int token = tx.token().propertyKeyGetOrCreateForName( propertyKey );
assertThat( tx.dataWrite().relationshipSetProperty( relationshipId, token, stringValue( "hello" ) ),
equalTo( intValue( 42 ) ) );
tx.success();
}
// Then
try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() )
{
assertThat( graphDb.getRelationshipById( relationshipId ).getProperty( "prop" ), equalTo( "hello" ) );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void testRevertOverflowingChange()
{
Relationship rel = getGraphDb().createNode()
.createRelationshipTo( getGraphDb().createNode(),
RelationshipType.withName( "INVALIDATES" ) );
long recordsInUseAtStart = propertyRecordsInUse();
long valueRecordsInUseAtStart = dynamicArrayRecordsInUse();
rel.setProperty( "theByte", (byte) -8 );
rel.setProperty( "theDoubleThatGrows", Math.PI );
rel.setProperty( "theInteger", -444345 );
rel.setProperty( "theDoubleThatGrows", new long[] { 1L << 63, 1L << 63, 1L << 63 } );
rel.setProperty( "theDoubleThatGrows", Math.E );
// When
newTransaction();
// Then
/*
* The following line should pass if we have packing on property block
* size shrinking.
*/
// assertEquals( recordsInUseAtStart + 1, propertyRecordsInUse() );
assertEquals( recordsInUseAtStart + 1, propertyRecordsInUse() );
assertEquals( valueRecordsInUseAtStart, dynamicArrayRecordsInUse() );
assertEquals( (byte) -8, rel.getProperty( "theByte" ) );
assertEquals( -444345, rel.getProperty( "theInteger" ) );
assertEquals( Math.E, rel.getProperty( "theDoubleThatGrows" ) );
}
代码示例来源: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
@Test
public void testSameTxWithArray()
{
commit();
newTransaction();
Node nodeA = getGraphDb().createNode();
Node nodeB = getGraphDb().createNode();
Relationship relA = nodeA.createRelationshipTo( nodeB, MyRelTypes.TEST );
nodeA.setProperty( arrayKey, array );
relA.setProperty( arrayKey, array );
assertNotNull( nodeA.getProperty( arrayKey ) );
assertNotNull( relA.getProperty( arrayKey ) );
relA.delete();
nodeA.delete();
nodeB.delete();
}
内容来源于网络,如有侵权,请联系作者删除!