Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
        public virtual IEnumerable <ConstraintDefinition> getConstraints(RelationshipType type)
        {
            KernelTransaction transaction = SafeAcquireTransaction(_transactionSupplier);

            using (Statement ignore = transaction.AcquireStatement())
            {
                TokenRead  tokenRead  = transaction.TokenRead();
                SchemaRead schemaRead = transaction.SchemaRead();
                int        typeId     = tokenRead.RelationshipType(type.Name());
                if (typeId == [email protected]_Fields.NO_TOKEN)
                {
                    return(emptyList());
                }
                return(AsConstraintDefinitions(schemaRead.ConstraintsGetForRelationshipType(typeId), tokenRead));
            }
        }
Exemplo n.º 3
0
        private int[] RelTypeIds(RelationshipType[] types, TokenRead token)
        {
            int[] ids      = new int[types.Length];
            int   outIndex = 0;

            foreach (RelationshipType type in types)
            {
                int id = token.RelationshipType(type.Name());
                if (id != NO_SUCH_RELATIONSHIP_TYPE)
                {
                    ids[outIndex++] = id;
                }
            }

            if (outIndex != ids.Length)
            {
                // One or more relationship types do not exist, so we can exclude them right away.
                ids = Arrays.copyOf(ids, outIndex);
            }
            return(ids);
        }
Exemplo n.º 4
0
            public override void DropRelationshipPropertyExistenceConstraint(RelationshipType type, string propertyKey)
            {
                KernelTransaction transaction = SafeAcquireTransaction(TransactionSupplier);

                using (Statement ignore = transaction.AcquireStatement())
                {
                    try
                    {
                        TokenRead tokenRead = transaction.TokenRead();

                        int typeId        = tokenRead.RelationshipType(type.Name());
                        int propertyKeyId = tokenRead.PropertyKey(propertyKey);
                        transaction.SchemaWrite().constraintDrop(ConstraintDescriptorFactory.existsForRelType(typeId, propertyKeyId));
                    }
                    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);
                    }
                }
            }
Exemplo n.º 5
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));
                }
            }
        }