public Relationship AddToIndex(ConnectionElement connection, Relationship relationship, string indexName, string key, object value)
        {
            string response;
            var status = Neo4jRestApi.AddRelationshipToIndex(connection.DbUrl, relationship.Id, indexName, key, value, out response);

            if (status == HttpStatusCode.Created || status == HttpStatusCode.OK)
            {
                return ParseRelationshipJson(response).First();
            }

            //// Add a relationship to an index but mapping already exists
            //if (unique && status == HttpStatusCode.OK)
            //{
            //	return null;
            //}

            throw new Exception(string.Format("Error adding relationship to index (http response:{0})", status));
        }
        public bool RemoveFromIndex(ConnectionElement connection, Relationship relationship, string indexName, string key, object value)
        {
            var status = Neo4jRestApi.RemoveRelationshipFromIndex(connection.DbUrl, relationship.Id, indexName, key, value);

            if (status != HttpStatusCode.NoContent)
            {
                throw new Exception(string.Format("Error remove relationship from index (relationship id:{0} index name:{1} key:{2} http response:{3})", relationship.Id, indexName, key, status));
            }

            return true;
        }
示例#3
0
 public GremlinScript(Relationship relationship)
 {
     Append("g.e({0})", relationship.Id);
     //_sb.AppendFormat("g.e({0})", relationship.Id);
 }
示例#4
0
        public static Relationship InitializeFromSelf(string self)
        {
            var relationship = new Relationship
                               	{
                               		Self = self,
                               		StartNode = null,
                               		EndNode = null,
                               		Name = null,
                               		_properties = null,
                               		OriginalRelationshipJson = null
                               	};

            return relationship;
        }
示例#5
0
        public static Relationship InitializeFromRelationshipJson(JObject relationshipJson)
        {
            var relationship = new Relationship();
            JToken self;
            if (!relationshipJson.TryGetValue("self", out self) || self.Type != JTokenType.String)
            {
                throw new Exception("Invalid relationship json");
            }

            relationship.Self = self.Value<string>();

            JToken properties;
            if (!relationshipJson.TryGetValue("data", out properties) || properties.Type != JTokenType.Object)
            {
                throw new Exception("Invalid relationship json");
            }

            JToken startNode;
            if (!relationshipJson.TryGetValue("start", out startNode))
            {
                throw new Exception("Invalid relationship json");
            }

            switch (startNode.Type)
            {
                case JTokenType.String:
                    relationship.StartNode = Node.InitializeFromSelf(startNode.Value<string>());
                    break;

                case JTokenType.Object:
                    relationship.StartNode = Node.InitializeFromNodeJson((JObject)startNode);
                    break;

                default:
                    throw new Exception("Invalid relationship json");
            }

            JToken endNode;
            if (!relationshipJson.TryGetValue("end", out endNode))
            {
                throw new Exception("Invalid relationship json");
            }

            switch (endNode.Type)
            {
                case JTokenType.String:
                    relationship.EndNode = Node.InitializeFromSelf(endNode.Value<string>());
                    break;

                case JTokenType.Object:
                    relationship.EndNode = Node.InitializeFromNodeJson((JObject)endNode);
                    break;

                default:
                    throw new Exception("Invalid relationship json");
            }

            JToken name;
            if (!relationshipJson.TryGetValue("type", out name) || name.Type != JTokenType.String)
            {
                throw new Exception("Invalid relationship json");
            }

            relationship.Name = name.Value<string>();

            relationship._properties = Properties.ParseJson(properties.ToString(Formatting.None));

            relationship.OriginalRelationshipJson = relationshipJson.ToString(Formatting.None);

            return relationship;
        }
 public Relationship AddToIndex(ConnectionElement connection, Relationship relationship, string indexName, string key, object value, bool unique = false)
 {
     return _batchStore.AddToIndex(connection, relationship, indexName, key, value, unique);
 }
 public bool RemoveFromIndex(ConnectionElement connection, Relationship relationship, string indexName, string key, object value)
 {
     throw new BatchRemoveFromIndexNotSupportedException();
 }