Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowSchemaStatementAfterSchemaStatement() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowSchemaStatementAfterSchemaStatement()
        {
            // given
            KernelTransaction tx = kernelTransaction(AUTH_DISABLED);

            tx.SchemaWrite();

            // when / then
            tx.SchemaWrite();
        }
Пример #2
0
            public override ConstraintDefinition CreatePropertyExistenceConstraint(RelationshipType type, string propertyKey)
            {
                KernelTransaction transaction = SafeAcquireTransaction(TransactionSupplier);

                using (Statement ignore = transaction.AcquireStatement())
                {
                    try
                    {
                        TokenWrite tokenWrite    = transaction.TokenWrite();
                        int        typeId        = tokenWrite.RelationshipTypeGetOrCreateForName(type.Name());
                        int[]      propertyKeyId = getOrCreatePropertyKeyIds(tokenWrite, propertyKey);
                        transaction.SchemaWrite().relationshipPropertyExistenceConstraintCreate(SchemaDescriptorFactory.forRelType(typeId, propertyKeyId));
                        return(new RelationshipPropertyExistenceConstraintDefinition(this, type, propertyKey));
                    }
                    catch (Exception e) when(e is AlreadyConstrainedException || e is CreateConstraintFailureException || e is RepeatedSchemaComponentException)
                    {
                        throw new ConstraintViolationException(e.getUserMessage(new SilentTokenNameLookup(transaction.TokenRead())), e);
                    }
                    catch (IllegalTokenNameException e)
                    {
                        throw new System.ArgumentException(e);
                    }
                    catch (Exception e) when(e is InvalidTransactionTypeKernelException || e is SchemaKernelException)
                    {
                        throw new ConstraintViolationException(e.Message, e);
                    }
                }
            }
Пример #3
0
            public override ConstraintDefinition CreatePropertyExistenceConstraint(Label label, params string[] propertyKeys)
            {
                KernelTransaction transaction = SafeAcquireTransaction(TransactionSupplier);

                using (Statement ignore = transaction.AcquireStatement())
                {
                    try
                    {
                        TokenWrite tokenWrite     = transaction.TokenWrite();
                        int        labelId        = tokenWrite.LabelGetOrCreateForName(label.Name());
                        int[]      propertyKeyIds = getOrCreatePropertyKeyIds(tokenWrite, propertyKeys);
                        transaction.SchemaWrite().nodePropertyExistenceConstraintCreate(forLabel(labelId, propertyKeyIds));
                        return(new NodePropertyExistenceConstraintDefinition(this, label, propertyKeys));
                    }
                    catch (Exception e) when(e is AlreadyConstrainedException || e is CreateConstraintFailureException || e is RepeatedSchemaComponentException)
                    {
                        throw new ConstraintViolationException(e.getUserMessage(new SilentTokenNameLookup(transaction.TokenRead())), e);
                    }
                    catch (IllegalTokenNameException e)
                    {
                        throw new System.ArgumentException(e);
                    }
                    catch (TooManyLabelsException e)
                    {
                        throw new System.InvalidOperationException(e);
                    }
                    catch (Exception e) when(e is InvalidTransactionTypeKernelException || e is SchemaKernelException)
                    {
                        throw new ConstraintViolationException(e.Message, e);
                    }
                }
            }
Пример #4
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);
                    }
                }
            }
Пример #5
0
            public override IndexDefinition CreateIndexDefinition(Label label, Optional <string> indexName, params string[] propertyKeys)
            {
                KernelTransaction transaction = SafeAcquireTransaction(TransactionSupplier);

                using (Statement ignore = transaction.AcquireStatement())
                {
                    try
                    {
                        TokenWrite            tokenWrite     = transaction.TokenWrite();
                        int                   labelId        = tokenWrite.LabelGetOrCreateForName(label.Name());
                        int[]                 propertyKeyIds = getOrCreatePropertyKeyIds(tokenWrite, propertyKeys);
                        LabelSchemaDescriptor descriptor     = forLabel(labelId, propertyKeyIds);
                        IndexReference        indexReference = transaction.SchemaWrite().indexCreate(descriptor, indexName);
                        return(new IndexDefinitionImpl(this, indexReference, new Label[] { label }, propertyKeys, false));
                    }

                    catch (IllegalTokenNameException e)
                    {
                        throw new System.ArgumentException(e);
                    }
                    catch (Exception e) when(e is InvalidTransactionTypeKernelException || e is SchemaKernelException)
                    {
                        throw new ConstraintViolationException(e.GetUserMessage(new SilentTokenNameLookup(transaction.TokenRead())), e);
                    }
                }
            }
Пример #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void dropIndex(org.neo4j.internal.kernel.api.IndexReference index) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private void DropIndex(IndexReference index)
        {
            using (Transaction tx = _db.beginTx())
            {
                KernelTransaction ktx = _bridge.getKernelTransactionBoundToThisThread(true);
                using (Statement ignore = ktx.AcquireStatement())
                {
                    ktx.SchemaWrite().indexDrop(index);
                }
                tx.Success();
            }
        }
Пример #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.internal.kernel.api.IndexReference createPersonNameIndex() throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private IndexReference CreatePersonNameIndex()
        {
            using (Transaction tx = _db.beginTx())
            {
                IndexReference    index;
                KernelTransaction ktx = _bridge.getKernelTransactionBoundToThisThread(true);
                using (Statement ignore = ktx.AcquireStatement())
                {
                    int labelId       = ktx.TokenWrite().labelGetOrCreateForName(PERSON_LABEL);
                    int propertyKeyId = ktx.TokenWrite().propertyKeyGetOrCreateForName(NAME_PROPERTY);
                    LabelSchemaDescriptor descriptor = forLabel(labelId, propertyKeyId);
                    index = ktx.SchemaWrite().indexCreate(descriptor);
                }
                tx.Success();
                return(index);
            }
        }
Пример #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRejectSchemaStatementAfterDataStatement() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRejectSchemaStatementAfterDataStatement()
        {
            // given
            KernelTransaction tx = kernelTransaction(AUTH_DISABLED);

            tx.DataWrite();

            // when
            try
            {
                tx.SchemaWrite();

                fail("expected exception");
            }
            // then
            catch (InvalidTransactionTypeKernelException e)
            {
                assertEquals("Cannot perform schema updates in a transaction that has performed data updates.", e.Message);
            }
        }
Пример #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAllowCreationOfConstraintsWhenInHA() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAllowCreationOfConstraintsWhenInHA()
        {
            //noinspection deprecation
            GraphDatabaseAPI db = new FakeHaDatabase(this);
            ThreadToStatementContextBridge stmtBridge = Db.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge));

            using (Transaction ignored = Db.beginTx())
            {
                KernelTransaction ktx = stmtBridge.GetKernelTransactionBoundToThisThread(true);
                try
                {
                    ktx.SchemaWrite().uniquePropertyConstraintCreate(forLabel(1, 1));
                    fail("expected exception here");
                }
                catch (InvalidTransactionTypeKernelException e)
                {
                    assertThat(e.Message, containsString("HA"));
                }
            }

            Db.shutdown();
        }
Пример #10
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);
                    }
                }
            }
Пример #11
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);
                    }
                }
            }
Пример #12
0
            public override ConstraintDefinition CreateNodeKeyConstraint(IndexDefinition indexDefinition)
            {
                if (indexDefinition.MultiTokenIndex)
                {
                    throw new ConstraintViolationException("A node key constraint does not support multi-token index definitions. " + "That is, only a single label is supported, but the following labels were provided: " + labelNameList(indexDefinition.Labels, "", "."));
                }
                KernelTransaction transaction = SafeAcquireTransaction(TransactionSupplier);

                using (Statement ignore = transaction.AcquireStatement())
                {
                    try
                    {
                        TokenWrite tokenWrite     = transaction.TokenWrite();
                        int        labelId        = tokenWrite.LabelGetOrCreateForName(single(indexDefinition.Labels).name());
                        int[]      propertyKeyIds = getOrCreatePropertyKeyIds(tokenWrite, indexDefinition);
                        transaction.SchemaWrite().nodeKeyConstraintCreate(forLabel(labelId, propertyKeyIds));
                        return(new NodeKeyConstraintDefinition(this, indexDefinition));
                    }
                    catch (Exception e) when(e is AlreadyConstrainedException || e is CreateConstraintFailureException || e is AlreadyIndexedException || e is RepeatedSchemaComponentException)
                    {
                        throw new ConstraintViolationException(e.getUserMessage(new SilentTokenNameLookup(transaction.TokenRead())), e);
                    }
                    catch (IllegalTokenNameException e)
                    {
                        throw new System.ArgumentException(e);
                    }
                    catch (TooManyLabelsException e)
                    {
                        throw new System.InvalidOperationException(e);
                    }
                    catch (Exception e) when(e is InvalidTransactionTypeKernelException || e is SchemaKernelException)
                    {
                        throw new ConstraintViolationException(e.Message, e);
                    }
                }
            }