コード例 #1
0
ファイル: SchemaImpl.cs プロジェクト: Neo4Net/Neo4Net
//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));
            }
        }
コード例 #2
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));
                }
            }
        }