Пример #1
0
            public static AnyValue Convert(IEnumerable <Notification> notifications)
            {
                IList <AnyValue> @out = new List <AnyValue>();

                foreach (Notification notification in notifications)
                {
                    InputPosition   pos             = notification.Position;                // position is optional
                    bool            includePosition = !pos.Equals(InputPosition.empty);
                    int             size            = includePosition ? 5 : 4;
                    MapValueBuilder builder         = new MapValueBuilder(size);

                    builder.Add("code", stringValue(notification.Code));
                    builder.Add("title", stringValue(notification.Title));
                    builder.Add("description", stringValue(notification.Description));
                    builder.Add("severity", stringValue(notification.Severity.ToString()));

                    if (includePosition)
                    {
                        // only add the position if it is not empty
                        builder.Add("position", VirtualValues.map(new string[] { "offset", "line", "column" }, new AnyValue[] { intValue(pos.Offset), intValue(pos.Line), intValue(pos.Column) }));
                    }

                    @out.Add(builder.Build());
                }
                return(VirtualValues.fromList(@out));
            }
            // Recurse through maps and sequences

            public override AnyValue MapMap(MapValue value)
            {
                MapValueBuilder builder = new MapValueBuilder();

                value.Foreach((k, v) => builder.Add(k, v.map(this)));
                return(builder.Build());
            }
Пример #3
0
 private void AddIfNonZero(MapValueBuilder builder, string name, int count)
 {
     if (count > 0)
     {
         builder.Add(name, intValue(count));
     }
 }
Пример #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.values.virtual.MapValue metadataOf(CypherAdapterStream stream) throws Exception
        private MapValue MetadataOf(CypherAdapterStream stream)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.values.virtual.MapValueBuilder meta = new org.neo4j.values.virtual.MapValueBuilder();
            MapValueBuilder meta = new MapValueBuilder();

            stream.Accept(new BoltResult_VisitorAnonymousInnerClass(this, meta));
            return(meta.Build());
        }
Пример #5
0
        private MapValue MapValues(params object[] values)
        {
            int             i       = 0;
            MapValueBuilder builder = new MapValueBuilder();

            while (i < values.Length)
            {
                builder.Add(( string )values[i++], ( AnyValue )values[i++]);
            }
            return(builder.Build());
        }
Пример #6
0
        private MapValue QueryStats(QueryStatistics queryStatistics)
        {
            MapValueBuilder builder = new MapValueBuilder();

            AddIfNonZero(builder, "nodes-created", queryStatistics.NodesCreated);
            AddIfNonZero(builder, "nodes-deleted", queryStatistics.NodesDeleted);
            AddIfNonZero(builder, "relationships-created", queryStatistics.RelationshipsCreated);
            AddIfNonZero(builder, "relationships-deleted", queryStatistics.RelationshipsDeleted);
            AddIfNonZero(builder, "properties-set", queryStatistics.PropertiesSet);
            AddIfNonZero(builder, "labels-added", queryStatistics.LabelsAdded);
            AddIfNonZero(builder, "labels-removed", queryStatistics.LabelsRemoved);
            AddIfNonZero(builder, "indexes-added", queryStatistics.IndexesAdded);
            AddIfNonZero(builder, "indexes-removed", queryStatistics.IndexesRemoved);
            AddIfNonZero(builder, "constraints-added", queryStatistics.ConstraintsAdded);
            AddIfNonZero(builder, "constraints-removed", queryStatistics.ConstraintsRemoved);
            return(builder.Build());
        }
Пример #7
0
        private static AnyValue ValueOf(object obj)
        {
            if (obj is MappedGraphType)
            {
                return((( MappedGraphType )obj).Value);
            }
            Value value = Values.unsafeOf(obj, true);

            if (value != null)
            {
                return(value);
            }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: if (obj instanceof java.util.List<?>)
            if (obj is IList <object> )
            {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: return fromList(((java.util.List<?>) obj).stream().map(ValueMapperTest::valueOf).collect(toList()));
                return(fromList(((IList <object>)obj).Select(ValueMapperTest.valueOf).ToList()));
            }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: if (obj instanceof java.util.Map<?,?>)
            if (obj is IDictionary <object, ?> )
            {
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.Map<String,?> map = (java.util.Map<String,?>) obj;
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
                IDictionary <string, ?> map     = (IDictionary <string, ?>)obj;
                MapValueBuilder         builder = new MapValueBuilder(map.Count);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (java.util.Map.Entry<String,?> entry : map.entrySet())
                foreach (KeyValuePair <string, ?> entry in map.SetOfKeyValuePairs())
                {
                    builder.Add(entry.Key, ValueOf(entry.Value));
                }

                return(builder.Build());
            }
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            throw new AssertionError("cannot convert: " + obj + " (a " + obj.GetType().FullName + ")");
        }
Пример #8
0
        public static MapValue Convert(ExecutionPlanDescription plan)
        {
            bool            hasProfilerStatistics = plan.HasProfilerStatistics();
            int             size = hasProfilerStatistics ? 9 : 4;
            MapValueBuilder @out = new MapValueBuilder(size);

            @out.Add("operatorType", stringValue(plan.Name));
            @out.Add("args", ValueUtils.asMapValue(plan.Arguments));
            @out.Add("identifiers", ValueUtils.asListValue(plan.Identifiers));
            @out.Add("children", Children(plan));
            if (hasProfilerStatistics)
            {
                Org.Neo4j.Graphdb.ExecutionPlanDescription_ProfilerStatistics profile = plan.ProfilerStatistics;
                @out.Add("dbHits", longValue(profile.DbHits));
                @out.Add("pageCacheHits", longValue(profile.PageCacheHits));
                @out.Add("pageCacheMisses", longValue(profile.PageCacheMisses));
                @out.Add("pageCacheHitRatio", doubleValue(profile.PageCacheHitRatio));
                @out.Add("rows", longValue(profile.Rows));
            }
            return(@out.Build());
        }
Пример #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.values.virtual.MapValue unpackMap() throws java.io.IOException
            public override MapValue UnpackMap()
            {
                int size = ( int )UnpackMapHeader();

                if (size == 0)
                {
                    return(VirtualValues.EMPTY_MAP);
                }
                MapValueBuilder map;

                if (size == UNKNOWN_SIZE)
                {
                    map = new MapValueBuilder();
                    bool more = true;
                    while (more)
                    {
                        PackType keyType = PeekNextType();
                        string   key;
                        AnyValue val;
                        switch (keyType)
                        {
                        case PackType.END_OF_STREAM:
                            Unpack();
                            more = false;
                            break;

                        case PackType.STRING:
                            key = UnpackString();
                            val = Unpack();
                            if (map.Add(key, val) != null)
                            {
                                throw new BoltIOException(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.Invalid, "Duplicate map key `" + key + "`.");
                            }
                            break;

                        case PackType.NULL:
                            throw new BoltIOException(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.Invalid, "Value `null` is not supported as key in maps, must be a non-nullable string.");

                        default:
                            throw new BoltIOException(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.InvalidFormat, "Bad key type: " + keyType);
                        }
                    }
                }
                else
                {
                    map = new MapValueBuilder(size);
                    for (int i = 0; i < size; i++)
                    {
                        PackType keyType = PeekNextType();
                        string   key;
                        switch (keyType)
                        {
                        case PackType.NULL:
                            throw new BoltIOException(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.Invalid, "Value `null` is not supported as key in maps, must be a non-nullable string.");

                        case PackType.STRING:
                            key = UnpackString();
                            break;

                        default:
                            throw new BoltIOException(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.InvalidFormat, "Bad key type: " + keyType);
                        }

                        AnyValue val = Unpack();
                        if (map.Add(key, val) != null)
                        {
                            throw new BoltIOException(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.Invalid, "Duplicate map key `" + key + "`.");
                        }
                    }
                }
                return(map.Build());
            }
Пример #10
0
 public BoltResult_VisitorAnonymousInnerClass(CypherAdapterStreamTest outerInstance, MapValueBuilder meta)
 {
     this.outerInstance = outerInstance;
     this._meta         = meta;
 }
Пример #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings({"unchecked", "WeakerAccess"}) public static org.neo4j.values.AnyValue materializeAnyResult(org.neo4j.kernel.impl.core.EmbeddedProxySPI proxySpi, Object anyValue)
        public static AnyValue MaterializeAnyResult(EmbeddedProxySPI proxySpi, object anyValue)
        {
            if (anyValue == null || anyValue == NO_VALUE)
            {
                return(NO_VALUE);
            }
            else if (anyValue is AnyValue)
            {
                return(MaterializeAnyValueResult(proxySpi, anyValue));
            }
            else if (anyValue is System.Collections.IList)
            {
                return(VirtualValues.fromList((IList <AnyValue>)(((System.Collections.IList)anyValue).Select(v => MaterializeAnyResult(proxySpi, v)).ToList())));
            }
            else if (anyValue is System.Collections.IDictionary)
            {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<String,?> incoming = (java.util.Map<String,?>) anyValue;
                IDictionary <string, ?> incoming = (IDictionary <string, ?>)anyValue;
                MapValueBuilder         builder  = new MapValueBuilder(incoming.Count);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (java.util.Map.Entry<String,?> entry : incoming.entrySet())
                foreach (KeyValuePair <string, ?> entry in incoming.SetOfKeyValuePairs())
                {
                    builder.Add(entry.Key, MaterializeAnyResult(proxySpi, entry.Value));
                }
                return(builder.Build());
            }
            else if (anyValue is PrimitiveNodeStream)
            {
                return(VirtualValues.fromList((( PrimitiveNodeStream )anyValue).LongStream().mapToObj(id => (AnyValue)ValueUtils.fromNodeProxy(proxySpi.NewNodeProxy(id))).collect(Collectors.toList())));
            }
            else if (anyValue is PrimitiveRelationshipStream)
            {
                return(VirtualValues.fromList((( PrimitiveRelationshipStream )anyValue).LongStream().mapToObj(id => (AnyValue)ValueUtils.fromRelationshipProxy(proxySpi.NewRelationshipProxy(id))).collect(Collectors.toList())));
            }
            else if (anyValue is LongStream)
            {
                long[] array = (( LongStream )anyValue).toArray();
                return(Values.longArray(array));
            }
            else if (anyValue is DoubleStream)
            {
                double[] array = (( DoubleStream )anyValue).toArray();
                return(Values.doubleArray(array));
            }
            else if (anyValue is IntStream)
            {
                // IntStream is only used for list of primitive booleans
                return(VirtualValues.fromList((( IntStream )anyValue).mapToObj(i => Values.booleanValue(i != 0)).collect(Collectors.toList())));
            }
            else if (anyValue.GetType().IsArray)
            {
                Type componentType = anyValue.GetType().GetElementType();
                int  length        = Array.getLength(anyValue);

                if (componentType.IsPrimitive)
                {
                    object copy = Array.CreateInstance(componentType, length);
                    //noinspection SuspiciousSystemArraycopy
                    Array.Copy(anyValue, 0, copy, 0, length);
                    return(ValueUtils.of(copy));
                }
                else if (anyValue is string[])
                {
                    return(Values.stringArray(( string[] )anyValue));
                }
                else
                {
                    AnyValue[] copy = new AnyValue[length];
                    for (int i = 0; i < length; i++)
                    {
                        copy[i] = MaterializeAnyResult(proxySpi, Array.get(anyValue, i));
                    }
                    return(VirtualValues.list(copy));
                }
            }
            else
            {
                return(ValueUtils.of(anyValue));
            }
        }