示例#1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static java.util.List<java.util.Map<String,Object>> indexes(org.neo4j.internal.kernel.api.TokenRead tokens, org.neo4j.internal.kernel.api.SchemaRead schemaRead, Anonymizer anonymizer) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
        private static IList <IDictionary <string, object> > Indexes(TokenRead tokens, SchemaRead schemaRead, Anonymizer anonymizer)
        {
            IList <IDictionary <string, object> > indexes = new List <IDictionary <string, object> >();

            SilentTokenNameLookup tokenLookup = new SilentTokenNameLookup(tokens);

            IEnumerator <IndexReference> iterator = schemaRead.IndexesGetAll();

            while (iterator.MoveNext())
            {
                IndexReference index = iterator.Current;

                IDictionary <string, object> data = new Dictionary <string, object>();
                data["labels"] = Map(index.Schema().EntityTokenIds, id => anonymizer.Label(tokenLookup.LabelGetName(id), id));

                data["properties"] = Map(index.Schema().PropertyIds, id => anonymizer.PropertyKey(tokenLookup.PropertyKeyGetName(id), id));

                Org.Neo4j.Register.Register_DoubleLongRegister register = Registers.newDoubleLongRegister();
                schemaRead.IndexUpdatesAndSize(index, register);
                data["totalSize"] = register.ReadSecond();
                data["updatesSinceEstimation"] = register.ReadFirst();
                schemaRead.IndexSample(index, register);
                data["estimatedUniqueSize"] = register.ReadFirst();

                indexes.Add(data);
            }

            return(indexes);
        }
示例#2
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: private org.neo4j.graphdb.schema.IndexDefinition descriptorToDefinition(final org.neo4j.internal.kernel.api.TokenRead tokenRead, org.neo4j.internal.kernel.api.IndexReference index)
        private IndexDefinition DescriptorToDefinition(TokenRead tokenRead, IndexReference index)
        {
            try
            {
                SchemaDescriptor schema          = index.Schema();
                int[]            entityTokenIds  = Schema.EntityTokenIds;
                bool             constraintIndex = index.Unique;
                string[]         propertyNames   = PropertyNameUtils.GetPropertyKeys(tokenRead, index.Properties());
                switch (Schema.entityType())
                {
                case NODE:
                    Label[] labels = new Label[entityTokenIds.Length];
                    for (int i = 0; i < labels.Length; i++)
                    {
                        labels[i] = label(tokenRead.NodeLabelName(entityTokenIds[i]));
                    }
                    return(new IndexDefinitionImpl(_actions, index, labels, propertyNames, constraintIndex));

                case RELATIONSHIP:
                    RelationshipType[] relTypes = new RelationshipType[entityTokenIds.Length];
                    for (int i = 0; i < relTypes.Length; i++)
                    {
                        relTypes[i] = withName(tokenRead.RelationshipTypeName(entityTokenIds[i]));
                    }
                    return(new IndexDefinitionImpl(_actions, index, relTypes, propertyNames, constraintIndex));

                default:
                    throw new System.ArgumentException("Cannot create IndexDefinition for " + Schema.entityType() + " entity-typed schema.");
                }
            }
            catch (KernelException e)
            {
                throw new Exception(e);
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void verifyThatFulltextIndexIsPresent(org.neo4j.internal.kernel.api.IndexReference fulltextIndexDescriptor) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException
        private void VerifyThatFulltextIndexIsPresent(IndexReference fulltextIndexDescriptor)
        {
            using (KernelTransactionImplementation transaction = KernelTransaction)
            {
                IndexReference descriptor = transaction.SchemaRead().indexGetForName(NAME);
                assertEquals(fulltextIndexDescriptor.Schema(), descriptor.Schema());
                assertEquals((( IndexDescriptor )fulltextIndexDescriptor).type(), ((IndexDescriptor)descriptor).type());
                transaction.Success();
            }
        }
示例#4
0
 private void AssertCorrectIndex(int labelId, int[] propertyKeyIds, bool expectedUnique, IndexReference index)
 {
     assertEquals("provider key", "lucene+native", index.ProviderKey());
     assertEquals("provider version", "1.0", index.ProviderVersion());
     assertEquals(expectedUnique, index.Unique);
     assertEquals("label id", labelId, index.Schema().EntityTokenIds[0]);
     for (int i = 0; i < propertyKeyIds.Length; i++)
     {
         assertEquals("property key id", propertyKeyIds[i], index.Properties()[i]);
     }
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void createFulltextIndex() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CreateFulltextIndex()
        {
            IndexReference fulltextIndex = CreateIndex(new int[] { 7, 8, 9 }, new int[] { 2, 3, 4 });

            using (KernelTransactionImplementation transaction = KernelTransaction)
            {
                IndexReference descriptor = transaction.SchemaRead().indexGetForName(NAME);
                assertEquals(descriptor.Schema(), fulltextIndex.Schema());
                transaction.Success();
            }
        }
示例#6
0
        public virtual Stream <RelationshipOutput> QueryFulltextForRelationships(string name, string query)
        {
            IndexReference indexReference = GetValidIndexReference(name);

            AwaitOnline(indexReference);
            EntityType entityType = indexReference.Schema().entityType();

            if (entityType != EntityType.RELATIONSHIP)
            {
                throw new System.ArgumentException("The '" + name + "' index (" + indexReference + ") is an index on " + entityType + ", so it cannot be queried for relationships.");
            }
            ScoreEntityIterator resultIterator = Accessor.query(Tx, name, query);

            return(resultIterator.Select(result => RelationshipOutput.ForExistingEntityOrNull(Db, result)).Where(Objects.nonNull));
        }
示例#7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public ScoreEntityIterator query(org.neo4j.kernel.api.KernelTransaction ktx, String indexName, String queryString) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException, org.apache.lucene.queryparser.classic.ParseException
        public override ScoreEntityIterator Query(KernelTransaction ktx, string indexName, string queryString)
        {
            KernelTransactionImplementation kti = ( KernelTransactionImplementation )ktx;
            AllStoreHolder      allStoreHolder  = ( AllStoreHolder )kti.DataRead();
            IndexReference      indexReference  = kti.SchemaRead().indexGetForName(indexName);
            FulltextIndexReader fulltextIndexReader;

            if (kti.HasTxStateWithChanges() && !((FulltextSchemaDescriptor)indexReference.Schema()).EventuallyConsistent)
            {
                FulltextAuxiliaryTransactionState auxiliaryTxState = ( FulltextAuxiliaryTransactionState )allStoreHolder.AuxiliaryTxState(TX_STATE_PROVIDER_KEY);
                fulltextIndexReader = auxiliaryTxState.IndexReader(indexReference, kti);
            }
            else
            {
                IndexReader indexReader = allStoreHolder.IndexReader(indexReference, false);
                fulltextIndexReader = ( FulltextIndexReader )indexReader;
            }
            return(fulltextIndexReader.Query(queryString));
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void await(org.neo4j.internal.kernel.api.IndexReference descriptor) throws Exception
        internal virtual void Await(IndexReference descriptor)
        {
            try
            {
                using (KernelTransactionImplementation tx = KernelTransaction)
                {
                    while (tx.SchemaRead().index(descriptor.Schema()) == IndexReference.NO_INDEX)
                    {
                        Thread.Sleep(100);
                    }
                    while (tx.SchemaRead().indexGetState(descriptor) != InternalIndexState.ONLINE)
                    {
                        Thread.Sleep(100);
                    }
                }
            }
            catch (InterruptedException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
        }
示例#9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void triggerSampling(org.neo4j.internal.kernel.api.IndexReference index) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
        private void TriggerSampling(IndexReference index)
        {
            _indexingService.triggerIndexSampling(index.Schema(), IndexSamplingMode.TRIGGER_REBUILD_ALL);
        }
示例#10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void awaitOnline(org.neo4j.internal.kernel.api.IndexReference indexReference) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
        private void AwaitOnline(IndexReference indexReference)
        {
            // We do the isAdded check on the transaction state first, because indexGetState will grab a schema read-lock, which can deadlock on the write-lock
            // held by the index populator. Also, if we index was created in this transaction, then we will never see it come online in this transaction anyway.
            // Indexes don't come online until the transaction that creates them has committed.
            if (!(( KernelTransactionImplementation )Tx).txState().indexDiffSetsBySchema(indexReference.Schema()).isAdded((IndexDescriptor)indexReference))
            {
                // If the index was not created in this transaction, then wait for it to come online before querying.
                Schema          schema = Db.schema();
                IndexDefinition index  = Schema.getIndexByName(indexReference.Name());
                Schema.awaitIndexOnline(index, _indexOnlineQueryTimeoutSeconds, TimeUnit.SECONDS);
            }
            // If the index was created in this transaction, then we skip this check entirely.
            // We will get an exception later, when we try to get an IndexReader, so this is fine.
        }
示例#11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private long indexUpdates(org.neo4j.internal.kernel.api.IndexReference reference) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private long IndexUpdates(IndexReference reference)
        {
            return((( GraphDatabaseAPI )_db).DependencyResolver.resolveDependency(typeof(IndexingService)).indexUpdatesAndSize(reference.Schema()).readFirst());
        }
示例#12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public String indexGetFailure(org.neo4j.internal.kernel.api.IndexReference index) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
        public override string IndexGetFailure(IndexReference index)
        {
            AllStoreHolder.AssertValidIndex(index);
            return(_snapshot.indexGetFailure(index.Schema()));
        }