예제 #1
0
        private TxStateTransactionDataSnapshot Snapshot()
        {
            EmbeddedProxySPI spi = mock(typeof(EmbeddedProxySPI));

            when(spi.NewNodeProxy(anyLong())).thenAnswer(invocation => new NodeProxy(spi, invocation.getArgument(0)));
            when(spi.NewRelationshipProxy(anyLong())).thenAnswer(invocation => new RelationshipProxy(spi, invocation.getArgument(0)));
            when(spi.NewRelationshipProxy(anyLong(), anyLong(), anyInt(), anyLong())).thenAnswer(invocation => new RelationshipProxy(spi, invocation.getArgument(0), invocation.getArgument(1), invocation.getArgument(2), invocation.getArgument(3)));
            return(new TxStateTransactionDataSnapshot(_state, spi, _ops, _transaction));
        }
예제 #2
0
 // NOTE: This assumes anyValue is an instance of AnyValue
 public static AnyValue MaterializeAnyValueResult(EmbeddedProxySPI proxySpi, object anyValue)
 {
     if (anyValue is VirtualNodeValue)
     {
         if (anyValue is NodeValue)
         {
             return(( AnyValue )anyValue);
         }
         return(ValueUtils.fromNodeProxy(proxySpi.NewNodeProxy((( VirtualNodeValue )anyValue).id())));
     }
     if (anyValue is VirtualRelationshipValue)
     {
         if (anyValue is RelationshipValue)
         {
             return(( AnyValue )anyValue);
         }
         return(ValueUtils.fromRelationshipProxy(proxySpi.NewRelationshipProxy((( VirtualRelationshipValue )anyValue).id())));
     }
     // If it is a list or map, run it through a ValueMapper that will create proxy objects for entities if needed.
     // This will first do a dry run and return as it is if no conversion is needed.
     // If in the future we will always create proxy objects directly whenever we create values we can skip this
     // Doing this conversion lazily instead, by wrapping with TransformedListValue or TransformedMapValue is probably not a
     // good idea because of the complexities involved (see TOMBSTONE in VirtualValues about why TransformedListValue was killed).
     // NOTE: There is also a case where a ListValue can be storable (ArrayValueListValue) where no conversion is needed
     if ((anyValue is ListValue && !(( ListValue )anyValue).storable()) || anyValue is MapValue)
     {
         return(CompiledMaterializeValueMapper.MapAnyValue(proxySpi, ( AnyValue )anyValue));
     }
     return(( AnyValue )anyValue);
 }
예제 #3
0
        public static RelationshipValue MaterializeRelationshipValue(EmbeddedProxySPI proxySpi, object anyValue)
        {
            // Null check has to be done outside by the generated code
            if (anyValue is RelationshipValue)
            {
                return(( RelationshipValue )anyValue);
            }
            else if (anyValue is VirtualRelationshipValue)
            {
                return(ValueUtils.fromRelationshipProxy(proxySpi.NewRelationshipProxy((( VirtualRelationshipValue )anyValue).id())));
            }
            else if (anyValue is Relationship)
            {
                return(ValueUtils.fromRelationshipProxy(( Relationship )anyValue));
            }
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            throw new System.ArgumentException("Do not know how to materialize relationship value from type " + anyValue.GetType().FullName);
        }
예제 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup()
        public virtual void Setup()
        {
            EmbeddedProxySPI manager = mock(typeof(EmbeddedProxySPI));

            when(manager.NewNodeProxy(anyLong())).thenAnswer(invocationOnMock =>
            {
                long id        = invocationOnMock.getArgument(0);
                NodeProxy mock = mock(typeof(NodeProxy));
                when(mock.Id).thenReturn(id);
                return(mock);
            });
            when(manager.NewRelationshipProxy(anyLong())).thenAnswer(invocationOnMock =>
            {
                long id = invocationOnMock.getArgument(0);
                RelationshipProxy mock = mock(typeof(RelationshipProxy));
                when(mock.Id).thenReturn(id);
                return(mock);
            });
            _converter = new ParameterConverter(manager);
        }
예제 #5
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));
            }
        }