Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private QueryStatusResult(org.neo4j.kernel.api.query.QuerySnapshot query, org.neo4j.kernel.impl.core.EmbeddedProxySPI manager, java.time.ZoneId zoneId) throws org.neo4j.kernel.api.exceptions.InvalidArgumentsException
        private QueryStatusResult(QuerySnapshot query, EmbeddedProxySPI manager, ZoneId zoneId)
        {
            this.QueryId           = ofInternalId(query.InternalQueryId()).ToString();
            this.Username          = query.Username();
            this.Query             = query.QueryText();
            this.Parameters        = AsRawMap(query.QueryParameters(), new ParameterWriter(manager));
            this.StartTime         = formatTime(query.StartTimestampMillis(), zoneId);
            this.ElapsedTimeMillis = MicrosAsMillis(query.ElapsedTimeMicros()).Value;
            this.ElapsedTime       = formatInterval(ElapsedTimeMillis);
            ClientConnectionInfo clientConnection = query.ClientConnection();

            this.ConnectionDetails   = clientConnection.AsConnectionDetails();
            this.Protocol            = clientConnection.Protocol();
            this.ClientAddress       = clientConnection.ClientAddress();
            this.RequestUri          = clientConnection.RequestURI();
            this.MetaData            = query.TransactionAnnotationData();
            this.CpuTimeMillis       = MicrosAsMillis(query.CpuTimeMicros());
            this.Status              = query.Status();
            this.ResourceInformation = query.ResourceInformation();
            this.ActiveLockCount     = query.ActiveLockCount();
            this.WaitTimeMillis      = MicrosAsMillis(query.WaitTimeMicros()).Value;
            this.IdleTimeMillis      = MicrosAsMillis(query.IdleTimeMicros());
            this.Planner             = query.Planner();
            this.Runtime             = query.Runtime();
            this.Indexes             = query.Indexes();
            this.AllocatedBytes      = query.AllocatedBytes();
            this.PageHits            = query.PageHits();
            this.PageFaults          = query.PageFaults();
            this.ConnectionId        = clientConnection.ConnectionId();
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void start() throws Throwable
        public override void Start()
        {
            // When we have multiple dbs, this has to be suitably modified to get the right kernel and procedures
            NeoStoreDataSource dataSource       = _dataSourceManager.DataSource;
            EmbeddedProxySPI   embeddedProxySPI = dataSource.DependencyResolver.resolveDependency(typeof(EmbeddedProxySPI), Org.Neo4j.Graphdb.DependencyResolver_SelectionStrategy.ONLY);

            _dataCollectors.Add(DataCollectorModule.setupDataCollector(_procedures, _jobScheduler, dataSource.Kernel, _monitors, new DefaultValueMapper(embeddedProxySPI), _config));
        }
Ejemplo n.º 4
0
 public Procedures(EmbeddedProxySPI proxySPI, ThrowingConsumer <Procedures, ProcedureException> builtin, File pluginDir, Log log, ProcedureConfig config)
 {
     this._builtin     = builtin;
     this._pluginDir   = pluginDir;
     this._log         = log;
     this._typeMappers = new TypeMappers(proxySPI);
     this._compiler    = new ReflectiveProcedureCompiler(_typeMappers, _safeComponents, _allComponents, log, config);
 }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
0
 /// <param name="proxySPI">
 ///         the API into the kernel. </param>
 /// <param name="nodes">
 ///         the ids of the nodes in the path, in order. </param>
 /// <param name="relationships">
 ///         the ids of the relationships in the path, in order. </param>
 /// <param name="directedTypes">
 ///         an encoding of the types and directions of the relationships.
 ///         An entry at position {@code i} of this array should be {@code typeId} if the relationship at {@code i}
 ///         has its start node at {@code i} and its end node at {@code i + 1}, and should be {@code ~typeId} if the
 ///         relationship at {@code i} has its start node at {@code i + 1} and its end node at {@code i}. </param>
 public PathProxy(EmbeddedProxySPI proxySPI, long[] nodes, long[] relationships, int[] directedTypes)
 {
     Debug.Assert(nodes.Length == relationships.Length + 1);
     Debug.Assert(relationships.Length == directedTypes.Length);
     this._proxySPI      = proxySPI;
     this._nodes         = nodes;
     this._relationships = relationships;
     this._directedTypes = directedTypes;
 }
        public TxStateTransactionDataSnapshot(ReadableTransactionState state, EmbeddedProxySPI proxySpi, StorageReader storageReader, KernelTransaction transaction)
        {
            this._state       = state;
            this._proxySpi    = proxySpi;
            this._store       = storageReader;
            this._transaction = transaction;

            // Load changes that require store access eagerly, because we won't have access to the after-state
            // after the tx has been committed.
            TakeSnapshot();
        }
Ejemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAccessExampleMetaData()
        public virtual void ShouldAccessExampleMetaData()
        {
            EmbeddedProxySPI spi = mock(typeof(EmbeddedProxySPI));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.api.KernelTransactionImplementation transaction = mock(org.neo4j.kernel.impl.api.KernelTransactionImplementation.class);
            KernelTransactionImplementation transaction = mock(typeof(KernelTransactionImplementation));

            when(transaction.MetaData).thenReturn(genericMap("username", "Igor"));
            TxStateTransactionDataSnapshot transactionDataSnapshot = new TxStateTransactionDataSnapshot(_state, spi, _ops, transaction);

            assertEquals(1, transactionDataSnapshot.MetaData().Count);
            assertThat("Expected metadata map to contain defined username", transactionDataSnapshot.MetaData(), equalTo(genericMap("username", "Igor")));
        }
Ejemplo n.º 9
0
        private void VerifyIds(EmbeddedProxySPI actions, long relationshipId, long nodeId1, int typeId, long nodeId2)
        {
            RelationshipProxy proxy = new RelationshipProxy(actions, relationshipId, nodeId1, typeId, nodeId2);

            assertEquals(relationshipId, proxy.Id);
            // our mock above is known to return RelationshipTypeToken
            assertEquals(nodeId1, proxy.StartNode.Id);
            assertEquals(nodeId1, proxy.StartNodeId);
            assertEquals(nodeId2, proxy.EndNode.Id);
            assertEquals(nodeId2, proxy.EndNodeId);
            assertEquals(nodeId2, proxy.GetOtherNode(NodeWithId(nodeId1)).Id);
            assertEquals(nodeId2, proxy.GetOtherNodeId(nodeId1));
            assertEquals(nodeId1, proxy.GetOtherNode(NodeWithId(nodeId2)).Id);
            assertEquals(nodeId1, proxy.GetOtherNodeId(nodeId2));
        }
Ejemplo n.º 10
0
        public virtual Stream <QueryStatusResult> ListQueries()
        {
            SecurityContext.assertCredentialsNotExpired();

            EmbeddedProxySPI nodeManager = Resolver.resolveDependency(typeof(EmbeddedProxySPI));
            ZoneId           zoneId      = ConfiguredTimeZone;

            try
            {
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
                return(KernelTransactions.activeTransactions().stream().flatMap(KernelTransactionHandle::executingQueries).filter(query => IsAdminOrSelf(query.username())).map(catchThrown(typeof(InvalidArgumentsException), query => new QueryStatusResult(query, nodeManager, zoneId))));
            }
            catch (UncaughtCheckedException uncaught)
            {
                throwIfPresent(uncaught.GetCauseIfOfType(typeof(InvalidArgumentsException)));
                throw uncaught;
            }
        }
Ejemplo n.º 11
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);
        }
        public static AnyValue MapAnyValue(EmbeddedProxySPI proxySPI, AnyValue value)
        {
            // First do a dry run to determine if any conversion will actually be needed,
            // because if it isn't we can just return the value as it is without having
            // to recursively rewrite lists and maps, which could be very expensive.
            // This is based on the assumption that returning full nodes and relationships is a
            // relatively rare use-case compared to returning a selection of their properties.
            // Hopefully the dry run will also heat up the caches for the real run, thus reducing its overhead.
            DryRunMaterializeValueMapper dryRunMapper = new DryRunMaterializeValueMapper();

            value.Map(dryRunMapper);
            if (dryRunMapper.NeedsConversion)
            {
                WritingMaterializeValueMapper realMapper = new WritingMaterializeValueMapper(proxySPI);
                return(value.Map(realMapper));
            }
            return(value);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToReferToIdsBeyondMaxInt()
        public virtual void ShouldBeAbleToReferToIdsBeyondMaxInt()
        {
            // GIVEN
            EmbeddedProxySPI actions = mock(typeof(EmbeddedProxySPI));

            when(actions.NewNodeProxy(anyLong())).then(invocation => NodeWithId(invocation.getArgument(0)));
            when(actions.GetRelationshipTypeById(anyInt())).then(invocation => new NamedToken("whatever", invocation.getArgument(0)));

            long[] ids   = new long[] { 1437589437, 2047587483, 2147496246L, 2147342921, 3276473721L, 4762746373L, 57587348738L, 59892898932L };
            int[]  types = new int[] { 0, 10, 101, 3024, 20123, 45008 };

            // WHEN/THEN
            for (int i = 0; i < ids.Length - 2; i++)
            {
                long id      = ids[i];
                long nodeId1 = ids[i + 1];
                long nodeId2 = ids[i + 2];
                int  type    = types[i];
                VerifyIds(actions, id, nodeId1, type, nodeId2);
                VerifyIds(actions, id, nodeId2, type, nodeId1);
            }
        }
Ejemplo n.º 15
0
 public TypeMappers(EmbeddedProxySPI proxySPI) : base(proxySPI)
 {
     RegisterScalarsAndCollections();
 }
 internal WritingMaterializeValueMapper(EmbeddedProxySPI proxySpi)
 {
     this.ProxySpi = proxySpi;
 }
Ejemplo n.º 17
0
 public GraphPropertiesProxy(EmbeddedProxySPI actions)
 {
     this._actions = actions;
 }
Ejemplo n.º 18
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));
            }
        }
Ejemplo n.º 19
0
 internal ParameterConverter(EmbeddedProxySPI proxySpi)
 {
     this._proxySpi = proxySpi;
     _stack.push(new ObjectWriter());
 }
Ejemplo n.º 20
0
 public NodeProxy(EmbeddedProxySPI spi, long nodeId)
 {
     this._nodeId = nodeId;
     this._spi    = spi;
 }
Ejemplo n.º 21
0
 internal ParameterWriter(EmbeddedProxySPI nodeManager)
 {
     this.NodeManager = nodeManager;
 }
Ejemplo n.º 22
0
 public DefaultValueMapper(EmbeddedProxySPI proxySPI)
 {
     this._proxySPI = proxySPI;
 }
Ejemplo n.º 23
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: QueryStatusResult(org.neo4j.kernel.api.query.ExecutingQuery query, org.neo4j.kernel.impl.core.EmbeddedProxySPI manager, java.time.ZoneId zoneId) throws org.neo4j.kernel.api.exceptions.InvalidArgumentsException
        internal QueryStatusResult(ExecutingQuery query, EmbeddedProxySPI manager, ZoneId zoneId) : this(query.Snapshot(), manager, zoneId)
        {
        }
Ejemplo n.º 24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SetUp()
        {
            _proxySPI = mock(typeof(EmbeddedProxySPI));
        }
Ejemplo n.º 25
0
 public RelationshipProxy(EmbeddedProxySPI spi, long id, long startNode, int type, long endNode)
 {
     this._spi = spi;
     Visit(id, type, startNode, endNode);
 }
Ejemplo n.º 26
0
 public RelationshipProxy(EmbeddedProxySPI spi, long id)
 {
     this._spi = spi;
     this._id  = id;
 }
Ejemplo n.º 27
0
 public TransactionEventHandlers(EmbeddedProxySPI spi)
 {
     this._proxySpi = spi;
 }