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

            tx.DataWrite();

            // when / then
            tx.DataWrite();
        }
Пример #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private long createPersonNode(org.neo4j.kernel.api.KernelTransaction ktx, Object value) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private long CreatePersonNode(KernelTransaction ktx, object value)
        {
            int  labelId       = ktx.TokenWrite().labelGetOrCreateForName(PERSON_LABEL);
            int  propertyKeyId = ktx.TokenWrite().propertyKeyGetOrCreateForName(NAME_PROPERTY);
            long nodeId        = ktx.DataWrite().nodeCreate();

            ktx.DataWrite().nodeAddLabel(nodeId, labelId);
            ktx.DataWrite().nodeSetProperty(nodeId, propertyKeyId, Values.of(value));
            return(nodeId);
        }
Пример #3
0
        public override void AddLabel(Label label)
        {
            KernelTransaction transaction = _spi.kernelTransaction();

            try
            {
                using (Statement ignore = transaction.AcquireStatement())
                {
                    transaction.DataWrite().nodeAddLabel(Id, transaction.TokenWrite().labelGetOrCreateForName(label.Name()));
                }
            }
            catch (ConstraintValidationException e)
            {
                throw new ConstraintViolationException(e.GetUserMessage(new SilentTokenNameLookup(transaction.TokenRead())), e);
            }
            catch (IllegalTokenNameException e)
            {
                throw new ConstraintViolationException(format("Invalid label name '%s'.", label.Name()), e);
            }
            catch (TooManyLabelsException e)
            {
                throw new ConstraintViolationException("Unable to add label.", e);
            }
            catch (EntityNotFoundException e)
            {
                throw new NotFoundException("No node with id " + Id + " found.", e);
            }
            catch (KernelException e)
            {
                throw new ConstraintViolationException(e.Message, e);
            }
        }
Пример #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Object removeProperty(String key) throws org.neo4j.graphdb.NotFoundException
        public override object RemoveProperty(string key)
        {
            KernelTransaction transaction = _spi.kernelTransaction();

            try
            {
                using (Statement ignore = transaction.AcquireStatement())
                {
                    int propertyKeyId = transaction.TokenWrite().propertyKeyGetOrCreateForName(key);
                    return(transaction.DataWrite().nodeRemoveProperty(_nodeId, propertyKeyId).asObjectCopy());
                }
            }
            catch (EntityNotFoundException e)
            {
                throw new NotFoundException(e);
            }
            catch (IllegalTokenNameException e)
            {
                throw new System.ArgumentException(format("Invalid property key '%s'.", key), e);
            }
            catch (InvalidTransactionTypeKernelException e)
            {
                throw new ConstraintViolationException(e.Message, e);
            }
            catch (AutoIndexingKernelException e)
            {
                throw new System.InvalidOperationException("Auto indexing encountered a failure while removing property: " + e.Message, e);
            }
        }
Пример #5
0
        public override object RemoveProperty(string key)
        {
            KernelTransaction transaction = SafeAcquireTransaction();
            int propertyKeyId;

            try
            {
                propertyKeyId = transaction.TokenWrite().propertyKeyGetOrCreateForName(key);
            }
            catch (IllegalTokenNameException e)
            {
                throw new System.ArgumentException(format("Invalid property key '%s'.", key), e);
            }
            try
            {
                using (Statement ignore = transaction.AcquireStatement())
                {
                    return(transaction.DataWrite().graphRemoveProperty(propertyKeyId).asObjectCopy());
                }
            }
            catch (InvalidTransactionTypeKernelException e)
            {
                throw new ConstraintViolationException(e.Message, e);
            }
        }
//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());
        }
//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 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);
        }
Пример #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public long makeNode(String label) throws org.neo4j.internal.kernel.api.exceptions.ProcedureException
        public virtual long MakeNode(string label)
        {
            long result;

            try
            {
                using (Transaction tx = _graph.beginTransaction(KernelTransaction.Type.@explicit, AnonymousContext.write()))
                {
                    KernelTransaction ktx = _txBridge.getKernelTransactionBoundToThisThread(true);
                    long nodeId           = ktx.DataWrite().nodeCreate();
                    int  labelId          = ktx.TokenWrite().labelGetOrCreateForName(label);
                    ktx.DataWrite().nodeAddLabel(nodeId, labelId);
                    result = nodeId;
                    tx.Success();
                }
            }
            catch (Exception e)
            {
                _log.error("Failed to create node: " + e.Message);
                throw new ProcedureException(Org.Neo4j.Kernel.Api.Exceptions.Status_Procedure.ProcedureCallFailed, "Failed to create node: " + e.Message, e);
            }
            return(result);
        }
Пример #10
0
        public override void SetProperty(string key, object value)
        {
            KernelTransaction transaction = _spi.kernelTransaction();
            int propertyKeyId;

            try
            {
                propertyKeyId = transaction.TokenWrite().propertyKeyGetOrCreateForName(key);
            }
            catch (IllegalTokenNameException e)
            {
                throw new System.ArgumentException(format("Invalid property key '%s'.", key), e);
            }

            try
            {
                using (Statement ignore = transaction.AcquireStatement())
                {
                    transaction.DataWrite().nodeSetProperty(_nodeId, propertyKeyId, Values.of(value, false));
                }
            }
            catch (ConstraintValidationException e)
            {
                throw new ConstraintViolationException(e.GetUserMessage(new SilentTokenNameLookup(transaction.TokenRead())), e);
            }
            catch (System.ArgumentException e)
            {
                // Trying to set an illegal value is a critical error - fail this transaction
                _spi.failTransaction();
                throw e;
            }
            catch (EntityNotFoundException e)
            {
                throw new NotFoundException(e);
            }
            catch (InvalidTransactionTypeKernelException e)
            {
                throw new ConstraintViolationException(e.Message, e);
            }
            catch (AutoIndexingKernelException e)
            {
                throw new System.InvalidOperationException("Auto indexing encountered a failure while setting property: " + e.Message, e);
            }
            catch (KernelException e)
            {
                throw new ConstraintViolationException(e.Message, e);
            }
        }
Пример #11
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);
            }
        }
Пример #12
0
        public override void Delete()
        {
            KernelTransaction transaction = SafeAcquireTransaction();

            try
            {
                bool deleted = transaction.DataWrite().nodeDelete(Id);
                if (!deleted)
                {
                    throw new NotFoundException("Unable to delete Node[" + _nodeId + "] since it has already been deleted.");
                }
            }
            catch (InvalidTransactionTypeKernelException e)
            {
                throw new ConstraintViolationException(e.Message, e);
            }
            catch (AutoIndexingKernelException e)
            {
                throw new System.InvalidOperationException("Auto indexing encountered a failure while deleting the node: " + e.Message, e);
            }
        }
Пример #13
0
        public override void Delete()
        {
            KernelTransaction transaction = _spi.kernelTransaction();

            try
            {
                bool deleted = transaction.DataWrite().relationshipDelete(_id);
                if (!deleted)
                {
                    throw new NotFoundException("Unable to delete relationship[" + Id + "] since it is already deleted.");
                }
            }
            catch (InvalidTransactionTypeKernelException e)
            {
                throw new ConstraintViolationException(e.Message, e);
            }
            catch (AutoIndexingKernelException e)
            {
                throw new System.InvalidOperationException("Auto indexing encountered a failure while deleting the relationship: " + e.Message, e);
            }
        }
Пример #14
0
        public override void RemoveLabel(Label label)
        {
            KernelTransaction transaction = _spi.kernelTransaction();

            try
            {
                using (Statement ignore = transaction.AcquireStatement())
                {
                    int labelId = transaction.TokenRead().nodeLabel(label.Name());
                    if (labelId != [email protected]_Fields.NO_TOKEN)
                    {
                        transaction.DataWrite().nodeRemoveLabel(Id, labelId);
                    }
                }
            }
            catch (EntityNotFoundException e)
            {
                throw new NotFoundException("No node with id " + Id + " found.", e);
            }
            catch (KernelException e)
            {
                throw new ConstraintViolationException(e.Message, e);
            }
        }
Пример #15
0
        public override Relationship CreateRelationshipTo(Node otherNode, RelationshipType type)
        {
            if (otherNode == null)
            {
                throw new System.ArgumentException("Other node is null.");
            }
            // TODO: This is the checks we would like to do, but we have tests that expect to mix nodes...
            //if ( !(otherNode instanceof NodeProxy) || (((NodeProxy) otherNode).actions != actions) )
            //{
            //    throw new IllegalArgumentException( "Nodes do not belong to same graph database." );
            //}

            KernelTransaction transaction = SafeAcquireTransaction();

            try
            {
                using (Statement ignore = transaction.AcquireStatement())
                {
                    int  relationshipTypeId = transaction.TokenWrite().relationshipTypeGetOrCreateForName(type.Name());
                    long relationshipId     = transaction.DataWrite().relationshipCreate(_nodeId, relationshipTypeId, otherNode.Id);
                    return(_spi.newRelationshipProxy(relationshipId, _nodeId, relationshipTypeId, otherNode.Id));
                }
            }
            catch (IllegalTokenNameException e)
            {
                throw new System.ArgumentException(e);
            }
            catch (EntityNotFoundException e)
            {
                throw new NotFoundException("Node[" + e.entityId() + "] is deleted and cannot be used to create a relationship");
            }
            catch (InvalidTransactionTypeKernelException e)
            {
                throw new ConstraintViolationException(e.Message, e);
            }
        }