Пример #1
0
        /// <summary>
        /// Convert value represented by type and raw bits to corresponding <seealso cref="NumberValue"/>. If type is not <seealso cref="BYTE"/>, <seealso cref="SHORT"/>,
        /// <seealso cref="INT"/>, <seealso cref="LONG"/>, <seealso cref="FLOAT"/> or <seealso cref="DOUBLE"/>, the raw bits will be interpreted as a long.
        /// </summary>
        /// <param name="rawBits"> Raw bits of value </param>
        /// <param name="type"> Type of value </param>
        /// <returns> <seealso cref="NumberValue"/> with type and value given by provided raw bits and type. </returns>
        internal static NumberValue AsNumberValue(long rawBits, sbyte type)
        {
            switch (type)
            {
            case BYTE:
                return(Values.byteValue(( sbyte )rawBits));

            case SHORT:
                return(Values.shortValue(( short )rawBits));

            case INT:
                return(Values.intValue(( int )rawBits));

            case LONG:
                return(Values.longValue(rawBits));

            case FLOAT:
                return(Values.floatValue(Float.intBitsToFloat(( int )rawBits)));

            case DOUBLE:
                return(Values.doubleValue(Double.longBitsToDouble(rawBits)));

            default:
                // If type is not recognized, interpret as long.
                return(Values.longValue(rawBits));
            }
        }
Пример #2
0
        private TextValue String(RecordPropertyCursor cursor, long reference, PageCursor page)
        {
            ByteBuffer buffer = cursor.Buffer = _read.loadString(reference, cursor.Buffer, page);

            buffer.flip();
            return(Values.stringValue(UTF8.decode(buffer.array(), 0, buffer.limit())));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void roundingErrorsFromLongToDoubleShouldNotPreventTxFromCommitting() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RoundingErrorsFromLongToDoubleShouldNotPreventTxFromCommitting()
        {
            // Given
            // a node with a constrained label and a long value
            long propertyValue = 285414114323346805L;
            long firstNode     = ConstrainedNode("label1", "key1", propertyValue);

            Transaction transaction = NewTransaction(AnonymousContext.writeToken());

            long node = CreateLabeledNode(transaction, "label1");

            assertNotEquals(firstNode, node);

            // When
            // a new node with the same constraint is added, with a value not equal but which would be mapped to the same double
            propertyValue++;
            // note how propertyValue is definitely not equal to propertyValue++ but they do equal if they are cast to double
            int propertyKeyId = transaction.TokenWrite().propertyKeyGetOrCreateForName("key1");

            transaction.DataWrite().nodeSetProperty(node, propertyKeyId, Values.of(propertyValue));

            // Then
            // the commit should still succeed
            Commit();
        }
Пример #4
0
 public override AnyValue MapText(TextValue value)
 {
     if (value.Length() > _maxTextParameterLength)
     {
         return(Values.stringValue(value.StringValue().Substring(0, _maxTextParameterLength)));
     }
     return(value);
 }
Пример #5
0
        private void AssertCanEncodeAndDecodeToSameValue(object value, int payloadSize)
        {
            PropertyBlock target  = new PropertyBlock();
            bool          encoded = ShortArray.encode(0, value, target, payloadSize);

            assertTrue(encoded);
            assertEquals(Values.of(value), ShortArray.decode(target));
        }
Пример #6
0
 protected internal override Value AssertCorrectType(Value value)
 {
     if (!Values.isGeometryValue(value))
     {
         throw new System.ArgumentException("Key layout does only support geometries, tried to create key from " + value);
     }
     return(value);
 }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private long createLabeledNode(org.neo4j.internal.kernel.api.Transaction transaction, String label, String key, Object value) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private long CreateLabeledNode(Transaction transaction, string label, string key, object value)
        {
            long node          = CreateLabeledNode(transaction, label);
            int  propertyKeyId = transaction.TokenWrite().propertyKeyGetOrCreateForName(key);

            transaction.DataWrite().nodeSetProperty(node, propertyKeyId, Values.of(value));
            return(node);
        }
Пример #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: long createEntity(org.neo4j.internal.kernel.api.Transaction transaction, String type, String property, String value) throws Exception
            internal override long CreateEntity(Transaction transaction, string type, string property, string value)
            {
                long node        = CreateEntity(transaction, type);
                int  propertyKey = transaction.TokenWrite().propertyKeyGetOrCreateForName(property);

                transaction.DataWrite().nodeSetProperty(node, propertyKey, Values.of(value));
                return(node);
            }
Пример #9
0
 public override void Validate(Value value)
 {
     _textValueValidator.validate(value);
     if (Values.isArrayValue(value))
     {
         _textValueValidator.validate(ArrayEncoder.encode(value).GetBytes());
     }
 }
Пример #10
0
        // EXACT

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testExact()
        public virtual void TestExact()
        {
            AssertExactPredicate("string");
            AssertExactPredicate(1);
            AssertExactPredicate(1.0);
            AssertExactPredicate(true);
            AssertExactPredicate(new long[] { 1L });
            AssertExactPredicate(Values.pointValue(CoordinateReferenceSystem.WGS84, 12.3, 45.6));
        }
Пример #11
0
 private static Value[] ToValues(object[] objects)
 {
     Value[] values = new Value[objects.Length];
     for (int i = 0; i < objects.Length; i++)
     {
         object @object = objects[i];
         values[i] = @object is Value ? ( Value )@object : Values.of(@object);
     }
     return(values);
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSpanMultiplePropertyRecords()
        public virtual void ShouldSpanMultiplePropertyRecords()
        {
            // given
            PropertyValueRecordSizeCalculator calculator = NewCalculator();

            // when
            int size = calculator.ApplyAsInt(new Value[] { Values.of(10), Values.of("test"), Values.of(( sbyte )5), Values.of(String(80)), Values.of("a bit longer short string"), Values.of(1234567890123456789L), Values.of(5), Values.of("value") });

            // then
            assertEquals(_propertyRecordSize * 3 + DYNAMIC_RECORD_SIZE, size);
        }
Пример #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAddOrRemoveFromIndexForNonAutoIndexedProperty() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAddOrRemoveFromIndexForNonAutoIndexedProperty()
        {
            // Given
            _index.startAutoIndexingProperty(_indexedPropertyName);

            // When
            _index.propertyChanged(_ops, 11, _nonIndexedProperty, Values.of("Goodbye!"), Values.of("Hello!"));

            // Then
            verifyZeroInteractions(_ops);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIncludeDynamicRecordSizes()
        public virtual void ShouldIncludeDynamicRecordSizes()
        {
            // given
            PropertyValueRecordSizeCalculator calculator = NewCalculator();

            // when
            int size = calculator.ApplyAsInt(new Value[] { Values.of(String(80)), Values.of(new string[] { String(150) }) });

            // then
            assertEquals(_propertyRecordSize + DYNAMIC_RECORD_SIZE + DYNAMIC_RECORD_SIZE * 2, size);
        }
Пример #15
0
 private LongValue ReadLong()
 {
     if (PropertyBlock.valueIsInlined(CurrentBlock()))
     {
         return(Values.longValue(( long )(( ulong )PropertyBlock.fetchLong(CurrentBlock()) >> 1)));
     }
     else
     {
         return(Values.longValue(Blocks[_block + 1]));
     }
 }
Пример #16
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.bolt.runtime.BoltStateMachineState processRunMessage(org.neo4j.bolt.v3.messaging.request.RunMessage message, org.neo4j.bolt.runtime.StateMachineContext context) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private BoltStateMachineState ProcessRunMessage(RunMessage message, StateMachineContext context)
        {
            long start = context.Clock().millis();
            StatementProcessor statementProcessor = context.ConnectionState().StatementProcessor;
            StatementMetadata  statementMetadata  = statementProcessor.Run(message.Statement(), message.Params());
            long end = context.Clock().millis();

            context.ConnectionState().onMetadata(FIELDS_KEY, stringArray(statementMetadata.FieldNames()));
            context.ConnectionState().onMetadata(FIRST_RECORD_AVAILABLE_KEY, Values.longValue(end - start));
            return(_streamingState);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIgnoreInlinedUnchangedProperty()
        public virtual void ShouldIgnoreInlinedUnchangedProperty()
        {
            // GIVEN
            int            key    = 10;
            Value          value  = Values.of(12341);
            PropertyRecord before = PropertyRecord(Property(key, value));
            PropertyRecord after  = PropertyRecord(Property(key, value));

            // WHEN
            assertThat(Convert(_none, _none, Change(before, after)), equalTo(EntityUpdates.ForEntity(0, false).build()));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIncludePropertyRecordSize()
        public virtual void ShouldIncludePropertyRecordSize()
        {
            // given
            PropertyValueRecordSizeCalculator calculator = NewCalculator();

            // when
            int size = calculator.ApplyAsInt(new Value[] { Values.of(10) });

            // then
            assertEquals(PropertyRecordFormat.RECORD_SIZE, size);
        }
Пример #19
0
        private void Encode(string @string)
        {
            PropertyBlock block         = new PropertyBlock();
            TextValue     expectedValue = Values.stringValue(@string);

            _propertyStore.encodeValue(block, KEY_ID, expectedValue);
            assertEquals(0, block.ValueRecords.Count);
            Value readValue = block.Type.value(block, _propertyStore);

            assertEquals(expectedValue, readValue);
        }
Пример #20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleBooleans()
        internal virtual void ShouldHandleBooleans()
        {
            // Given
            Value         array   = Values.booleanArray(new bool[] { true, false, true });
            PrettyPrinter printer = new PrettyPrinter();

            // When
            array.WriteTo(printer);

            // Then
            assertThat(printer.Value(), equalTo("[true, false, true]"));
        }
Пример #21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleByteArrays()
        internal virtual void ShouldHandleByteArrays()
        {
            // Given
            Value         array   = Values.byteArray(new sbyte[] { 2, 3, 42 });
            PrettyPrinter printer = new PrettyPrinter();

            // When
            array.WriteTo(printer);

            // Then
            assertThat(printer.Value(), equalTo("[2, 3, 42]"));
        }
Пример #22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleArrays()
        internal virtual void ShouldHandleArrays()
        {
            // Given
            PrettyPrinter printer = new PrettyPrinter();
            TextArray     array   = Values.stringArray("a", "b", "c");

            // When
            array.WriteTo(printer);

            // Then
            assertThat(printer.Value(), equalTo("[\"a\", \"b\", \"c\"]"));
        }
Пример #23
0
 public override void Validate(Value value)
 {
     if (value == null || value == Values.NO_VALUE)
     {
         throw new System.ArgumentException("Null value");
     }
     if (Values.isTextValue(value) && (( TextValue )value).length() >= _checkThreshold)
     {
         int length = IndexKeyLength(value);
         ValidateLength(length);
     }
 }
Пример #24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandlePoints()
        internal virtual void ShouldHandlePoints()
        {
            // Given
            PointValue    pointValue = Values.pointValue(CoordinateReferenceSystem.Cartesian, 11d, 12d);
            PrettyPrinter printer    = new PrettyPrinter();

            // When
            pointValue.WriteTo(printer);

            // Then
            assertThat(printer.Value(), equalTo("{geometry: {type: \"Point\", coordinates: [11.0, 12.0], " + "crs: {type: link, properties: " + "{href: \"http://spatialreference.org/ref/sr-org/7203/\", code: " + "7203}}}}"));
        }
Пример #25
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleNodeValue()
        internal virtual void ShouldHandleNodeValue()
        {
            // Given
            NodeValue     node    = VirtualValues.nodeValue(42L, Values.stringArray("L1", "L2", "L3"), Props("foo", intValue(42), "bar", list(intValue(1337), stringValue("baz"))));
            PrettyPrinter printer = new PrettyPrinter();

            // When
            node.WriteTo(printer);

            // Then
            assertThat(printer.Value(), equalTo("(id=42 :L1:L2:L3 {bar: [1337, \"baz\"], foo: 42})"));
        }
Пример #26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleNodeValueWithoutProperties()
        internal virtual void ShouldHandleNodeValueWithoutProperties()
        {
            // Given
            NodeValue     node    = VirtualValues.nodeValue(42L, Values.stringArray("L1", "L2", "L3"), EMPTY_MAP);
            PrettyPrinter printer = new PrettyPrinter();

            // When
            node.WriteTo(printer);

            // Then
            assertThat(printer.Value(), equalTo("(id=42 :L1:L2:L3)"));
        }
Пример #27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleEdgeValueWithoutLabelsNorProperties()
        internal virtual void ShouldHandleEdgeValueWithoutLabelsNorProperties()
        {
            // Given
            NodeValue     node    = VirtualValues.nodeValue(42L, Values.stringArray(), EMPTY_MAP);
            PrettyPrinter printer = new PrettyPrinter();

            // When
            node.WriteTo(printer);

            // Then
            assertThat(printer.Value(), equalTo("(id=42)"));
        }
Пример #28
0
        // EXISTS

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testExists()
        public virtual void TestExists()
        {
            ExistsPredicate p = IndexQuery.Exists(_propId);

            assertTrue(Test(p, "string"));
            assertTrue(Test(p, 1));
            assertTrue(Test(p, 1.0));
            assertTrue(Test(p, true));
            assertTrue(Test(p, new long[] { 1L }));
            assertTrue(Test(p, Values.pointValue(CoordinateReferenceSystem.WGS84, 12.3, 45.6)));

            assertFalse(Test(p, null));
        }
Пример #29
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotReportConflictOnSameValueSameEntityId() throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotReportConflictOnSameValueSameEntityId()
        {
            // given
            Value value    = Values.of(123);
            long  entityId = 10;

            // when
            NativeIndexValue merged = _detector.merge(Key(entityId, value), Key(entityId, value), NativeIndexValue.Instance, NativeIndexValue.Instance);

            // then
            assertNull(merged);
            _detector.checkConflict(array());                 // <-- should not throw conflict exception
        }
Пример #30
0
        public static void AssertEqualsMaybeNull <T>(object o1, object o2, T entity, string key) where T : Org.Neo4j.Graphdb.PropertyContainer
        {
            string entityDescription = "For " + entity + " and " + key;

            if (o1 == null || o2 == null)
            {
                assertSame(entityDescription + ". " + Strings.prettyPrint(o1) + " != " + Strings.prettyPrint(o2), o1, o2);
            }
            else
            {
                assertEquals(entityDescription, Values.of(o1), Values.of(o2));
            }
        }