//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void writeRelationshipsForPath(org.neo4j.values.virtual.RelationshipValue[] relationships) throws java.io.IOException internal virtual void WriteRelationshipsForPath(RelationshipValue[] relationships) { RelationshipIndexes.reset(relationships.Length); foreach (RelationshipValue node in relationships) { // relationship indexes are one-based RelationshipIndexes.putIfAbsent(node.Id(), RelationshipIndexes.size() + 1); } int size = RelationshipIndexes.size(); PackListHeader(size); if (size > 0) { { RelationshipValue edge = relationships[0]; foreach (long id in RelationshipIndexes.keys()) { int i = 1; while (edge.Id() != id) { edge = relationships[i++]; } //Note that we are not doing relationship.writeTo(this) here since the serialization protocol //requires these to be _unbound relationships_, thus relationships without any start node nor // end node. PackStructHeader(UNBOUND_RELATIONSHIP_SIZE, UNBOUND_RELATIONSHIP); Pack(edge.Id()); edge.Type().writeTo(this); edge.Properties().writeTo(this); } } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void writePath(org.neo4j.values.virtual.NodeValue[] nodes, org.neo4j.values.virtual.RelationshipValue[] relationships) throws java.io.IOException public override void WritePath(NodeValue[] nodes, RelationshipValue[] relationships) { //A path is serialized in the following form // Given path: (a {id: 42})-[r1 {id: 10}]->(b {id: 43})<-[r1 {id: 11}]-(c {id: 44}) //The serialization will look like: // // { // [a, b, c] // [r1, r2] // [1, 1, -2, 2] // } // The first list contains all nodes where the first node (a) is guaranteed to be the start node of // the path // The second list contains all edges of the path // The third list defines the path order, where every other item specifies the offset into the // relationship and node list respectively. Since all paths is guaranteed to start with a 0, meaning // that // a is the start node in this case, those are excluded. So the first integer in the array refers to the // position // in the relationship array (1 indexed where sign denotes direction) and the second one refers to // the offset // into the // node list (zero indexed) and so on. PackStructHeader(PATH_SIZE, PATH); WriteNodesForPath(nodes); WriteRelationshipsForPath(relationships); PackListHeader(2 * relationships.Length); if (relationships.Length == 0) { return; } NodeValue node = nodes[0]; for (int i = 1; i <= 2 * relationships.Length; i++) { if (i % 2 == 0) { node = nodes[i / 2]; int index = NodeIndexes.getOrDefault(node.Id(), NO_SUCH_ID); Pack(index); } else { RelationshipValue r = relationships[i / 2]; int index = RelationshipIndexes.getOrDefault(r.Id(), NO_SUCH_ID); if (node.Id() == r.StartNode().id()) { Pack(index); } else { Pack(-index); } } } }
private static Stream <AnyValue> Parameters() { NodeValue node1 = nodeValue(1, stringArray(), emptyMap()); NodeValue node2 = nodeValue(2, stringArray(), emptyMap()); NodeValue node3 = nodeValue(3, stringArray(), emptyMap()); RelationshipValue relationship1 = relationshipValue(100, node1, node2, stringValue("ONE"), emptyMap()); RelationshipValue relationship2 = relationshipValue(200, node2, node2, stringValue("TWO"), emptyMap()); return(Stream.of(node1, relationship1, path(new NodeValue[] { node1, node2, node3 }, new RelationshipValue[] { relationship1, relationship2 }), map(new string[] { "alpha", "beta" }, new AnyValue[] { stringValue("one"), numberValue(2) }), NO_VALUE, list(numberValue(1), stringValue("fine"), node2), stringValue("hello world"), stringArray("hello", "brave", "new", "world"), booleanValue(false), booleanArray(new bool[] { true, false, true }), charValue('\n'), charArray(new char[] { 'h', 'e', 'l', 'l', 'o' }), byteValue(( sbyte )3), byteArray(new sbyte[] { 0x00, unchecked (( sbyte )0x99), unchecked (( sbyte )0xcc) }), shortValue(( short )42), shortArray(new short[] { 1337, unchecked (( short )0xcafe), unchecked (( short )0xbabe) }), intValue(987654321), intArray(new int[] { 42, 11 }), longValue(9876543210L), longArray(new long[] { 0xcafebabe, 0x1ee7 }), floatValue(float.MaxValue), floatArray(new float[] { float.NegativeInfinity, float.Epsilon }), doubleValue(Double.MIN_NORMAL), doubleArray(new double[] { double.PositiveInfinity, double.MaxValue }), datetime(2018, 1, 16, 10, 36, 43, 123456788, ZoneId.of("Europe/Stockholm")), localDateTime(2018, 1, 16, 10, 36, 43, 123456788), date(2018, 1, 16), time(10, 36, 43, 123456788, ZoneOffset.ofHours(1)), localTime(10, 36, 43, 123456788), duration(399, 4, 48424, 133701337), pointValue(Cartesian, 11, 32), pointArray(new Point[] { pointValue(Cartesian, 11, 32), pointValue(WGS84, 13, 56) }))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleRelationships() public virtual void ShouldHandleRelationships() { // Given RelationshipValue relValue = relationshipValue(1L, nodeValue(42L, stringArray("L"), EMPTY_MAP), nodeValue(42L, stringArray("L"), EMPTY_MAP), stringValue("R"), EMPTY_MAP); // When relValue.WriteTo(_converter); // Then assertThat(_converter.value(), equalTo(VirtualValues.relationship(1L))); }
protected override void CreateRelationshipInternal(InstanceHandle sourceInstance, InstanceHandle relationshipInstance, InstanceHandle[] targetInstances, DateTime effectiveDate) { if (!GetDefaultTenant()._rels.ContainsKey(sourceInstance)) { GetDefaultTenant()._rels[sourceInstance] = new Dictionary <InstanceHandle, List <RelationshipValue> >(); } if (!GetDefaultTenant()._rels[sourceInstance].ContainsKey(relationshipInstance)) { GetDefaultTenant()._rels[sourceInstance][relationshipInstance] = new List <RelationshipValue>(); } // FIXME: determine (by the Singular attribute on relationshipInstance) if this is a Singular relationship, and throw exception if there is already a relationship assigned RelationshipValue relval = new RelationshipValue(sourceInstance, relationshipInstance, targetInstances, effectiveDate); if (!GetDefaultTenant()._rels[sourceInstance][relationshipInstance].Contains(relval)) { GetDefaultTenant()._rels[sourceInstance][relationshipInstance].Add(relval); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldSerializeRelationship() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldSerializeRelationship() { RelationshipValue rel = relationshipValue(12L, nodeValue(1L, stringArray(), VirtualValues.EMPTY_MAP), nodeValue(2L, stringArray(), VirtualValues.EMPTY_MAP), stringValue("KNOWS"), VirtualValues.map(new string[] { "name", "age" }, new AnyValue[] { stringValue("Bob"), intValue(14) })); assertThat(Serialized(rel), equalTo("B1 71 91 B5 52 0C 01 02 85 4B 4E 4F 57 53 A2 84" + lineSeparator() + "6E 61 6D 65 83 42 6F 62 83 61 67 65 0E")); }