Пример #1
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 org.neo4j.graphdb.schema.Schema_IndexState getIndexState(final org.neo4j.graphdb.schema.IndexDefinition index)
        public override Org.Neo4j.Graphdb.schema.Schema_IndexState GetIndexState(IndexDefinition index)
        {
            KernelTransaction transaction = SafeAcquireTransaction(_transactionSupplier);

            try
            {
                using (Statement ignore = transaction.AcquireStatement())
                {
                    SchemaRead         schemaRead = transaction.SchemaRead();
                    IndexReference     reference  = GetIndexReference(schemaRead, transaction.TokenRead(), (IndexDefinitionImpl)index);
                    InternalIndexState indexState = schemaRead.IndexGetState(reference);
                    switch (indexState)
                    {
                    case InternalIndexState.POPULATING:
                        return(POPULATING);

                    case InternalIndexState.ONLINE:
                        return(ONLINE);

                    case InternalIndexState.FAILED:
                        return(FAILED);

                    default:
                        throw new System.ArgumentException(string.Format("Illegal index state {0}", indexState));
                    }
                }
            }
            catch (Exception e) when(e is SchemaRuleNotFoundException || e is IndexNotFoundKernelException)
            {
                throw NewIndexNotFoundException(index, e);
            }
        }
Пример #2
0
        private void ShowUniqueConstraints(DbStructureVisitor visitor, KernelTransaction ktx, TokenNameLookup nameLookup)
        {
            IEnumerator <ConstraintDescriptor> constraints = ktx.SchemaRead().constraintsGetAll();

            while (constraints.MoveNext())
            {
                ConstraintDescriptor constraint = constraints.Current;
                string userDescription          = constraint.PrettyPrint(nameLookup);

                if (constraint is UniquenessConstraintDescriptor)
                {
                    visitor.VisitUniqueConstraint(( UniquenessConstraintDescriptor )constraint, userDescription);
                }
                else if (constraint is NodeExistenceConstraintDescriptor)
                {
                    NodeExistenceConstraintDescriptor existenceConstraint = ( NodeExistenceConstraintDescriptor )constraint;
                    visitor.VisitNodePropertyExistenceConstraint(existenceConstraint, userDescription);
                }
                else if (constraint is RelExistenceConstraintDescriptor)
                {
                    RelExistenceConstraintDescriptor existenceConstraint = ( RelExistenceConstraintDescriptor )constraint;
                    visitor.VisitRelationshipPropertyExistenceConstraint(existenceConstraint, userDescription);
                }
                else if (constraint is NodeKeyConstraintDescriptor)
                {
                    NodeKeyConstraintDescriptor nodeKeyConstraint = ( NodeKeyConstraintDescriptor )constraint;
                    visitor.VisitNodeKeyConstraint(nodeKeyConstraint, userDescription);
                }
                else
                {
                    throw new System.ArgumentException("Unknown constraint type: " + constraint.GetType() + ", " + "constraint: " + constraint);
                }
            }
        }
Пример #3
0
            public override void DropIndexDefinitions(IndexDefinition indexDefinition)
            {
                KernelTransaction transaction = SafeAcquireTransaction(TransactionSupplier);

                using (Statement ignore = transaction.AcquireStatement())
                {
                    try
                    {
                        IndexReference reference = GetIndexReference(transaction.SchemaRead(), transaction.TokenRead(), (IndexDefinitionImpl)indexDefinition);
                        transaction.SchemaWrite().indexDrop(reference);
                    }
                    catch (NotFoundException)
                    {
                        // Silently ignore invalid label and property names
                    }
                    catch (Exception e) when(e is SchemaRuleNotFoundException || e is DropIndexFailureException)
                    {
                        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);
                    }
                }
            }
Пример #4
0
//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();
            }
        }
Пример #5
0
 internal override void LockAcquired(bool exclusive, ResourceType resourceType, params long[] ids)
 {
     if (!Executed)
     {
         ThreadToStatementContextBridge bridge = outerInstance.DatabaseRule.resolveDependency(typeof(ThreadToStatementContextBridge));
         KernelTransaction ktx = bridge.GetKernelTransactionBoundToThisThread(true);
         ktx.SchemaRead().schemaStateFlush();
     }
     Executed = true;
 }
Пример #6
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());
        }
Пример #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertIndexedNodesMatchesStoreNodes() throws Exception
        private void AssertIndexedNodesMatchesStoreNodes()
        {
            int   nodesInStore = 0;
            Label label        = Label.label(PERSON_LABEL);

            using (Transaction tx = _db.beginTx())
            {
                KernelTransaction ktx        = (( GraphDatabaseAPI )_db).DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);
                IList <string>    mismatches = new List <string>();
                int            labelId       = ktx.TokenRead().nodeLabel(PERSON_LABEL);
                int            propertyKeyId = ktx.TokenRead().propertyKey(NAME_PROPERTY);
                IndexReference index         = ktx.SchemaRead().index(labelId, propertyKeyId);
                using (NodeValueIndexCursor cursor = ktx.Cursors().allocateNodeValueIndexCursor())
                {
                    // Node --> Index
                    foreach (Node node in filter(n => n.hasLabel(label) && n.hasProperty(NAME_PROPERTY), _db.AllNodes))
                    {
                        nodesInStore++;
                        string name = ( string )node.GetProperty(NAME_PROPERTY);
                        ktx.DataRead().nodeIndexSeek(index, cursor, IndexOrder.NONE, false, IndexQuery.exact(propertyKeyId, name));
                        bool found = false;
                        while (cursor.Next())
                        {
                            long indexedNode = cursor.NodeReference();
                            if (indexedNode == node.Id)
                            {
                                if (found)
                                {
                                    mismatches.Add("Index has multiple entries for " + name + " and " + indexedNode);
                                }
                                found = true;
                            }
                        }
                        if (!found)
                        {
                            mismatches.Add("Index is missing entry for " + name + " " + node);
                        }
                    }
                    if (mismatches.Count > 0)
                    {
                        fail(join(mismatches.ToArray(), format("%n")));
                    }
                    // Node count == indexed node count
                    ktx.DataRead().nodeIndexSeek(index, cursor, IndexOrder.NONE, false, IndexQuery.exists(propertyKeyId));
                    int nodesInIndex = 0;
                    while (cursor.Next())
                    {
                        nodesInIndex++;
                    }
                    assertEquals(nodesInStore, nodesInIndex);
                }
            }
        }
Пример #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void showIndices(DbStructureVisitor visitor, org.neo4j.kernel.api.KernelTransaction ktx, org.neo4j.internal.kernel.api.TokenNameLookup nameLookup) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
        private void ShowIndices(DbStructureVisitor visitor, KernelTransaction ktx, TokenNameLookup nameLookup)
        {
            SchemaRead schemaRead = ktx.SchemaRead();

            foreach (IndexReference reference in loop(sortByType(schemaRead.IndexesGetAll())))
            {
                string userDescription        = reference.Schema().userDescription(nameLookup);
                double uniqueValuesPercentage = schemaRead.IndexUniqueValuesSelectivity(reference);
                long   size = schemaRead.IndexSize(reference);
                visitor.VisitIndex(( IndexDescriptor )reference, userDescription, uniqueValuesPercentage, size);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = org.neo4j.graphdb.NotInTransactionException.class) public void shouldThrowNotInTransactionWhenTransactionClosedAndAttemptingOperations() throws org.neo4j.internal.kernel.api.exceptions.KernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowNotInTransactionWhenTransactionClosedAndAttemptingOperations()
        {
            KernelTransaction transaction = newTransaction(AnonymousContext.write());

            Read       read       = transaction.DataRead();
            Write      write      = transaction.DataWrite();
            SchemaRead schemaRead = transaction.SchemaRead();

            transaction.Success();
            transaction.Close();

            TransactionOperation.operate(read, write, schemaRead);
        }
Пример #10
0
        public override IEnumerable <IndexDefinition> GetIndexes()
        {
            KernelTransaction transaction = _transactionSupplier.get();
            SchemaRead        schemaRead  = transaction.SchemaRead();

            using (Statement ignore = transaction.AcquireStatement())
            {
                IList <IndexDefinition> definitions = new List <IndexDefinition>();

                IEnumerator <IndexReference> indexes = schemaRead.IndexesGetAll();
                AddDefinitions(definitions, transaction.TokenRead(), IndexReference.sortByType(indexes));
                return(definitions);
            }
        }
Пример #11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static org.neo4j.kernel.api.KernelTransaction mockKernelTransaction() throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
        private static KernelTransaction MockKernelTransaction()
        {
            SchemaRead schemaRead = mock(typeof(SchemaRead));

            when(schemaRead.IndexGetState(any(typeof(IndexReference)))).thenReturn(InternalIndexState.FAILED);
            when(schemaRead.IndexGetFailure(any(typeof(IndexReference)))).thenReturn(Exceptions.stringify(_cause));

            KernelTransaction kt = mock(typeof(KernelTransaction));

            when(kt.TokenRead()).thenReturn(mock(typeof(TokenRead)));
            when(kt.SchemaRead()).thenReturn(schemaRead);
            when(kt.Terminated).thenReturn(false);
            when(kt.AcquireStatement()).thenReturn(mock(typeof(Statement)));
            return(kt);
        }
//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();
            }
        }
Пример #13
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));
            }
        }
Пример #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void concurrentIndexPopulationAndInsertsShouldNotProduceDuplicates() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ConcurrentIndexPopulationAndInsertsShouldNotProduceDuplicates()
        {
            // Given
            Config config           = Config.defaults();
            GraphDatabaseService db = NewEmbeddedGraphDatabaseWithSlowJobScheduler(config);

            try
            {
                // When
                using (Transaction tx = Db.beginTx())
                {
                    Db.schema().indexFor(label(LABEL)).on(KEY).create();
                    tx.Success();
                }
                Node node;
                using (Transaction tx = Db.beginTx())
                {
                    node = Db.createNode(label(LABEL));
                    node.SetProperty(KEY, VALUE);
                    tx.Success();
                }

                using (Transaction tx = Db.beginTx())
                {
                    Db.schema().awaitIndexesOnline(1, MINUTES);
                    tx.Success();
                }

                // Then
                using (Transaction tx = Db.beginTx())
                {
                    KernelTransaction    ktx    = (( GraphDatabaseAPI )db).DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);
                    IndexReference       index  = ktx.SchemaRead().index(ktx.TokenRead().nodeLabel(LABEL), ktx.TokenRead().propertyKey(KEY));
                    NodeValueIndexCursor cursor = ktx.Cursors().allocateNodeValueIndexCursor();
                    ktx.DataRead().nodeIndexSeek(index, cursor, IndexOrder.NONE, false, IndexQuery.exact(1, VALUE));
                    assertTrue(cursor.Next());
                    assertEquals(node.Id, cursor.NodeReference());
                    assertFalse(cursor.Next());
                    tx.Success();
                }
            }
            finally
            {
                Db.shutdown();
            }
        }
Пример #15
0
        public override string GetIndexFailure(IndexDefinition index)
        {
            KernelTransaction transaction = SafeAcquireTransaction(_transactionSupplier);

            try
            {
                using (Statement ignore = transaction.AcquireStatement())
                {
                    SchemaRead     schemaRead = transaction.SchemaRead();
                    IndexReference descriptor = GetIndexReference(schemaRead, transaction.TokenRead(), (IndexDefinitionImpl)index);
                    return(schemaRead.IndexGetFailure(descriptor));
                }
            }
            catch (Exception e) when(e is SchemaRuleNotFoundException || e is IndexNotFoundKernelException)
            {
                throw NewIndexNotFoundException(index, e);
            }
        }
Пример #16
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);
            }
        }
Пример #17
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void checkIndexCounts(Store store, org.neo4j.kernel.internal.GraphDatabaseAPI db) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private static void CheckIndexCounts(Store store, GraphDatabaseAPI db)
        {
            InwardKernel kernel = Db.DependencyResolver.resolveDependency(typeof(InwardKernel));

            using (KernelTransaction tx = kernel.BeginTransaction(@implicit, AnonymousContext.read()), Statement ignore = tx.AcquireStatement())
            {
                SchemaRead schemaRead = tx.SchemaRead();
                IEnumerator <IndexReference> indexes  = IndexReference.sortByType(GetAllIndexes(schemaRead));
                Register_DoubleLongRegister  register = Registers.newDoubleLongRegister();
                for (int i = 0; indexes.MoveNext(); i++)
                {
                    IndexReference reference = indexes.Current;

                    // wait index to be online since sometimes we need to rebuild the indexes on migration
                    AwaitOnline(schemaRead, reference);

                    AssertDoubleLongEquals(store.IndexCounts[i][0], store.IndexCounts[i][1], schemaRead.IndexUpdatesAndSize(reference, register));
                    AssertDoubleLongEquals(store.IndexCounts[i][2], store.IndexCounts[i][3], schemaRead.IndexSample(reference, register));
                    double selectivity = schemaRead.IndexUniqueValuesSelectivity(reference);
                    assertEquals(store.IndexSelectivity[i], selectivity, 0.0000001d);
                }
            }
        }
Пример #18
0
            internal static ResourceIterator <T> InUse <T>(KernelTransaction transaction, TokenAccess <T> access)
            {
                SchemaReadCore schemaReadCore = transaction.SchemaRead().snapshot();

                return(new TokenIteratorAnonymousInnerClass(transaction, access, schemaReadCore));
            }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = org.neo4j.graphdb.TransactionTerminatedException.class) public void shouldThrowTerminateExceptionWhenTransactionTerminated() throws org.neo4j.internal.kernel.api.exceptions.KernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowTerminateExceptionWhenTransactionTerminated()
        {
            KernelTransaction transaction = newTransaction(AnonymousContext.write());

            transaction.Success();
            transaction.MarkForTermination(Org.Neo4j.Kernel.Api.Exceptions.Status_General.UnknownError);

            TransactionOperation.operate(transaction.DataRead(), transaction.DataWrite(), transaction.SchemaRead());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = org.neo4j.graphdb.NotInTransactionException.class) public void shouldThrowNotInTransactionWhenTransactionClosedAndAccessingOperations() throws org.neo4j.internal.kernel.api.exceptions.KernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowNotInTransactionWhenTransactionClosedAndAccessingOperations()
        {
            KernelTransaction transaction = newTransaction(AnonymousContext.write());

            transaction.Success();
            transaction.Close();

            TransactionOperation.operate(transaction.DataRead(), transaction.DataWrite(), transaction.SchemaRead());
        }