private void ShowRelCounts(KernelTransaction ktx, DbStructureVisitor visitor)
        {
            // all wildcards
            NoSide(ktx, visitor, _wildcardRelType, ANY_RELATIONSHIP_TYPE);

            TokenRead tokenRead = ktx.TokenRead();

            // one label only
            foreach (Label label in _db.AllLabels)
            {
                int labelId = tokenRead.NodeLabel(label.Name());

                LeftSide(ktx, visitor, label, labelId, _wildcardRelType, ANY_RELATIONSHIP_TYPE);
                RightSide(ktx, visitor, label, labelId, _wildcardRelType, ANY_RELATIONSHIP_TYPE);
            }

            // fixed rel type
            foreach (RelationshipType relType in _db.AllRelationshipTypes)
            {
                int relTypeId = tokenRead.RelationshipType(relType.Name());
                NoSide(ktx, visitor, relType, relTypeId);

                foreach (Label label in _db.AllLabels)
                {
                    int labelId = tokenRead.NodeLabel(label.Name());

                    // wildcard on right
                    LeftSide(ktx, visitor, label, labelId, relType, relTypeId);

                    // wildcard on left
                    RightSide(ktx, visitor, label, labelId, relType, relTypeId);
                }
            }
        }
Exemple #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void addingANodeWithPropertyShouldGetIndexed() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void AddingANodeWithPropertyShouldGetIndexed()
        {
            // Given
            string indexProperty        = "indexProperty";
            GatheringIndexWriter writer = NewWriter();

            createIndex(_db, _myLabel, indexProperty);

            // When
            int    value1        = 12;
            string otherProperty = "otherProperty";
            int    otherValue    = 17;
            Node   node          = CreateNode(map(indexProperty, value1, otherProperty, otherValue), _myLabel);

            // Then, for now, this should trigger two NodePropertyUpdates
            using (Transaction tx = _db.beginTx())
            {
                KernelTransaction ktx       = _ctxSupplier.getKernelTransactionBoundToThisThread(true);
                TokenRead         tokenRead = ktx.TokenRead();
                int propertyKey1            = tokenRead.PropertyKey(indexProperty);
                int label = tokenRead.NodeLabel(_myLabel.name());
                LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(label, propertyKey1);
                assertThat(writer.UpdatesCommitted, equalTo(asSet(IndexEntryUpdate.add(node.Id, descriptor, Values.of(value1)))));
                tx.Success();
            }
            // We get two updates because we both add a label and a property to be indexed
            // in the same transaction, in the future, we should optimize this down to
            // one NodePropertyUpdate.
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void batchInserterShouldUseConfiguredIndexProvider() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void BatchInserterShouldUseConfiguredIndexProvider()
        {
            Config        config   = Config.defaults(stringMap(default_schema_provider.name(), _schemaIndex.providerName()));
            BatchInserter inserter = NewBatchInserter(config);

            inserter.CreateDeferredSchemaIndex(TestLabels.LABEL_ONE).on("key").create();
            inserter.Shutdown();
            GraphDatabaseService db = GraphDatabaseService(config);

            AwaitIndexesOnline(db);
            try
            {
                using (Transaction tx = Db.beginTx())
                {
                    DependencyResolver             dependencyResolver             = (( GraphDatabaseAPI )db).DependencyResolver;
                    ThreadToStatementContextBridge threadToStatementContextBridge = dependencyResolver.ResolveDependency(typeof(ThreadToStatementContextBridge));
                    KernelTransaction kernelTransaction = threadToStatementContextBridge.GetKernelTransactionBoundToThisThread(true);
                    TokenRead         tokenRead         = kernelTransaction.TokenRead();
                    SchemaRead        schemaRead        = kernelTransaction.SchemaRead();
                    int            labelId    = tokenRead.NodeLabel(TestLabels.LABEL_ONE.name());
                    int            propertyId = tokenRead.PropertyKey("key");
                    IndexReference index      = schemaRead.Index(labelId, propertyId);
                    assertTrue(UnexpectedIndexProviderMessage(index), _schemaIndex.providerName().contains(index.ProviderKey()));
                    assertTrue(UnexpectedIndexProviderMessage(index), _schemaIndex.providerName().contains(index.ProviderVersion()));
                    tx.Success();
                }
            }
            finally
            {
                Db.shutdown();
            }
        }
Exemple #4
0
        private void AssertCorrectProvider(GraphDatabaseAPI db, Label label, string property)
        {
            KernelTransaction kernelTransaction = Db.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(false);
            TokenRead         tokenRead         = kernelTransaction.TokenRead();
            int            labelId    = tokenRead.NodeLabel(label.Name());
            int            propId     = tokenRead.PropertyKey(property);
            SchemaRead     schemaRead = kernelTransaction.SchemaRead();
            IndexReference index      = schemaRead.Index(labelId, propId);

            assertEquals("correct provider key", "lucene+native", index.ProviderKey());
            assertEquals("correct provider version", "1.0", index.ProviderVersion());
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertIndexProvider(org.neo4j.graphdb.GraphDatabaseService db, String expectedProviderIdentifier) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
        private void AssertIndexProvider(GraphDatabaseService db, string expectedProviderIdentifier)
        {
            GraphDatabaseAPI graphDatabaseAPI = ( GraphDatabaseAPI )db;

            using (Transaction tx = graphDatabaseAPI.BeginTx())
            {
                KernelTransaction ktx       = graphDatabaseAPI.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);
                TokenRead         tokenRead = ktx.TokenRead();
                int            labelId      = tokenRead.NodeLabel(LABEL.name());
                int            propertyId   = tokenRead.PropertyKey(KEY);
                IndexReference index        = ktx.SchemaRead().index(labelId, propertyId);

                assertEquals("expected IndexProvider.Descriptor", expectedProviderIdentifier, (new IndexProviderDescriptor(index.ProviderKey(), index.ProviderVersion())).name());
                tx.Success();
            }
        }
Exemple #6
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public Iterable<org.neo4j.graphdb.schema.ConstraintDefinition> getConstraints(final org.neo4j.graphdb.Label label)
        public virtual IEnumerable <ConstraintDefinition> getConstraints(Label label)
        {
            KernelTransaction transaction = SafeAcquireTransaction(_transactionSupplier);

            using (Statement ignore = transaction.AcquireStatement())
            {
                TokenRead  tokenRead  = transaction.TokenRead();
                SchemaRead schemaRead = transaction.SchemaRead();
                int        labelId    = tokenRead.NodeLabel(label.Name());
                if (labelId == [email protected]_Fields.NO_TOKEN)
                {
                    return(emptyList());
                }
                return(AsConstraintDefinitions(schemaRead.ConstraintsGetForLabel(labelId), tokenRead));
            }
        }
        private IDictionary <string, int> GetLabelIdsByName(params string[] names)
        {
            ThreadToStatementContextBridge transactionStatementContextBridge = TransactionStatementContextBridge;
            IDictionary <string, int>      labelNameIdMap = new Dictionary <string, int>();
            KernelTransaction ktx = transactionStatementContextBridge.GetKernelTransactionBoundToThisThread(true);

            using (Statement ignore = ktx.AcquireStatement())
            {
                TokenRead tokenRead = ktx.TokenRead();
                foreach (string name in names)
                {
                    labelNameIdMap[name] = tokenRead.NodeLabel(name);
                }
            }
            return(labelNameIdMap);
        }
Exemple #8
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public Iterable<org.neo4j.graphdb.schema.IndexDefinition> getIndexes(final org.neo4j.graphdb.Label label)
        public override IEnumerable <IndexDefinition> GetIndexes(Label label)
        {
            KernelTransaction transaction = _transactionSupplier.get();

            using (Statement ignore = transaction.AcquireStatement())
            {
                TokenRead  tokenRead  = transaction.TokenRead();
                SchemaRead schemaRead = transaction.SchemaRead();
                IList <IndexDefinition> definitions = new List <IndexDefinition>();
                int labelId = tokenRead.NodeLabel(label.Name());
                if (labelId == [email protected]_Fields.NO_TOKEN)
                {
                    return(emptyList());
                }
                IEnumerator <IndexReference> indexes = schemaRead.IndexesGetForLabel(labelId);
                AddDefinitions(definitions, tokenRead, IndexReference.sortByType(indexes));
                return(definitions);
            }
        }
Exemple #9
0
            public override void DropNodePropertyExistenceConstraint(Label label, string[] properties)
            {
                KernelTransaction transaction = SafeAcquireTransaction(TransactionSupplier);

                using (Statement ignore = transaction.AcquireStatement())
                {
                    try
                    {
                        TokenRead tokenRead      = transaction.TokenRead();
                        int       labelId        = tokenRead.NodeLabel(label.Name());
                        int[]     propertyKeyIds = ResolveAndValidatePropertyKeys(tokenRead, properties);
                        transaction.SchemaWrite().constraintDrop(ConstraintDescriptorFactory.existsForLabel(labelId, propertyKeyIds));
                    }
                    catch (DropConstraintFailureException e)
                    {
                        throw new ConstraintViolationException(e.GetUserMessage(new SilentTokenNameLookup(transaction.TokenRead())), e);
                    }
                    catch (Exception e) when(e is InvalidTransactionTypeKernelException || e is SchemaKernelException)
                    {
                        throw new ConstraintViolationException(e.Message, e);
                    }
                }
            }
Exemple #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void addingALabelToPreExistingNodeShouldGetIndexed() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void AddingALabelToPreExistingNodeShouldGetIndexed()
        {
            // GIVEN
            string indexProperty        = "indexProperty";
            GatheringIndexWriter writer = NewWriter();

            createIndex(_db, _myLabel, indexProperty);

            // WHEN
            string otherProperty = "otherProperty";
            int    value         = 12;
            int    otherValue    = 17;
            Node   node          = CreateNode(map(indexProperty, value, otherProperty, otherValue));

            // THEN
            assertThat(writer.UpdatesCommitted.Count, equalTo(0));

            // AND WHEN
            using (Transaction tx = _db.beginTx())
            {
                node.AddLabel(_myLabel);
                tx.Success();
            }

            // THEN
            using (Transaction tx = _db.beginTx())
            {
                KernelTransaction ktx       = _ctxSupplier.getKernelTransactionBoundToThisThread(true);
                TokenRead         tokenRead = ktx.TokenRead();
                int propertyKey1            = tokenRead.PropertyKey(indexProperty);
                int label = tokenRead.NodeLabel(_myLabel.name());
                LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(label, propertyKey1);
                assertThat(writer.UpdatesCommitted, equalTo(asSet(IndexEntryUpdate.add(node.Id, descriptor, Values.of(value)))));
                tx.Success();
            }
        }
Exemple #11
0
        public virtual GraphResult BuildSchemaGraph()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Map<String,VirtualNodeHack> nodes = new java.util.HashMap<>();
            IDictionary <string, VirtualNodeHack> nodes = new Dictionary <string, VirtualNodeHack>();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Map<String,java.util.Set<VirtualRelationshipHack>> relationships = new java.util.HashMap<>();
            IDictionary <string, ISet <VirtualRelationshipHack> > relationships = new Dictionary <string, ISet <VirtualRelationshipHack> >();

            using (Statement statement = _kernelTransaction.acquireStatement())
            {
                Read            dataRead        = _kernelTransaction.dataRead();
                TokenRead       tokenRead       = _kernelTransaction.tokenRead();
                TokenNameLookup tokenNameLookup = new SilentTokenNameLookup(tokenRead);
                SchemaRead      schemaRead      = _kernelTransaction.schemaRead();
                using (Transaction transaction = _graphDatabaseAPI.beginTx())
                {
                    // add all labelsInDatabase
                    using (ResourceIterator <Label> labelsInDatabase = _graphDatabaseAPI.AllLabelsInUse.GetEnumerator())
                    {
                        while (labelsInDatabase.MoveNext())
                        {
                            Label label   = labelsInDatabase.Current;
                            int   labelId = tokenRead.NodeLabel(label.Name());
                            IDictionary <string, object> properties = new Dictionary <string, object>();

                            IEnumerator <IndexReference> indexReferences = schemaRead.IndexesGetForLabel(labelId);
                            List <string> indexes = new List <string>();
                            while (indexReferences.MoveNext())
                            {
                                IndexReference index = indexReferences.Current;
                                if (!index.Unique)
                                {
                                    string[] propertyNames = PropertyNameUtils.getPropertyKeys(tokenNameLookup, index.Properties());
                                    indexes.Add(string.join(",", propertyNames));
                                }
                            }
                            properties["indexes"] = indexes;

                            IEnumerator <ConstraintDescriptor> nodePropertyConstraintIterator = schemaRead.ConstraintsGetForLabel(labelId);
                            List <string> constraints = new List <string>();
                            while (nodePropertyConstraintIterator.MoveNext())
                            {
                                ConstraintDescriptor constraint = nodePropertyConstraintIterator.Current;
                                constraints.Add(constraint.PrettyPrint(tokenNameLookup));
                            }
                            properties["constraints"] = constraints;

                            GetOrCreateLabel(label.Name(), properties, nodes);
                        }
                    }

                    //add all relationships

                    using (ResourceIterator <RelationshipType> relationshipTypeIterator = _graphDatabaseAPI.AllRelationshipTypesInUse.GetEnumerator())
                    {
                        while (relationshipTypeIterator.MoveNext())
                        {
                            RelationshipType relationshipType        = relationshipTypeIterator.Current;
                            string           relationshipTypeGetName = relationshipType.Name();
                            int relId = tokenRead.RelationshipType(relationshipTypeGetName);
                            using (ResourceIterator <Label> labelsInUse = _graphDatabaseAPI.AllLabelsInUse.GetEnumerator())
                            {
                                IList <VirtualNodeHack> startNodes = new LinkedList <VirtualNodeHack>();
                                IList <VirtualNodeHack> endNodes   = new LinkedList <VirtualNodeHack>();

                                while (labelsInUse.MoveNext())
                                {
                                    Label  labelToken = labelsInUse.Current;
                                    string labelName  = labelToken.Name();
                                    IDictionary <string, object> properties = new Dictionary <string, object>();
                                    VirtualNodeHack node    = GetOrCreateLabel(labelName, properties, nodes);
                                    int             labelId = tokenRead.NodeLabel(labelName);

                                    if (dataRead.CountsForRelationship(labelId, relId, [email protected]_Fields.ANY_LABEL) > 0)
                                    {
                                        startNodes.Add(node);
                                    }
                                    if (dataRead.CountsForRelationship([email protected]_Fields.ANY_LABEL, relId, labelId) > 0)
                                    {
                                        endNodes.Add(node);
                                    }
                                }

                                foreach (VirtualNodeHack startNode in startNodes)
                                {
                                    foreach (VirtualNodeHack endNode in endNodes)
                                    {
                                        AddRelationship(startNode, endNode, relationshipTypeGetName, relationships);
                                    }
                                }
                            }
                        }
                    }
                    transaction.Success();
                    return(GetGraphResult(nodes, relationships));
                }
            }
        }