コード例 #1
0
ファイル: NodeProxy.cs プロジェクト: Neo4Net/Neo4Net
        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);
            }
        }
コード例 #2
0
        private KernelTransaction SafeAcquireTransaction()
        {
            KernelTransaction transaction = _actions.kernelTransaction();

            if (transaction.Terminated)
            {
                Status terminationReason = transaction.ReasonIfTerminated.orElse(Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.Terminated);
                throw new TransactionTerminatedException(terminationReason);
            }
            return(transaction);
        }
コード例 #3
0
 public virtual bool InitializeData()
 {
     // It enough to check only start node, since it's absence will indicate that data was not yet loaded.
     if (_startNode == AbstractBaseRecord.NO_ID)
     {
         KernelTransaction transaction = _spi.kernelTransaction();
         using (Statement ignore = transaction.AcquireStatement())
         {
             RelationshipScanCursor relationships = transaction.AmbientRelationshipCursor();
             transaction.DataRead().singleRelationship(_id, relationships);
             // At this point we don't care if it is there or not just load what we got.
             bool wasPresent = relationships.Next();
             this._type      = relationships.Type();
             this._startNode = relationships.SourceNodeReference();
             this._endNode   = relationships.TargetNodeReference();
             // But others might care, e.g. the Bolt server needs to know for serialisation purposes.
             return(wasPresent);
         }
     }
     return(true);
 }