public override AnyValue MapRelationship(VirtualRelationshipValue value)
 {
     if (value is RelationshipValue)
     {
         return(value);
     }
     return(ValueUtils.fromRelationshipProxy(ProxySpi.newRelationshipProxy(value.Id())));
 }
示例#2
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);
            }
        }