internal static ICypherFluentQuery MergeKey(this ICypherFluentQuery q, IKey key, string valueLabel)
 {
     if (key is ActorKey)
     {
         return(q
                .Merge($"({valueLabel}:Actor:CanJoin {{ key: {{{valueLabel}Key}}, name: {{{valueLabel}Name}} }})")
                .WithParam($"{valueLabel}Key", key.Key)
                .WithParam($"{valueLabel}Name", key.Name));
     }
     if (key is ThingKey)
     {
         return(q
                .Merge($"({valueLabel}:Thing:CanBeGranted {{ key: {{{valueLabel}Key}}, name: {{{valueLabel}Name}} }})")
                .WithParam($"{valueLabel}Key", key.Key)
                .WithParam($"{valueLabel}Name", key.Name));
     }
     if (key is NodeKey)
     {
         return(q
                .Merge($"({valueLabel}:Node:CanBeJoined:CanJoin {{ key: {{{valueLabel}Key}}, name: {{{valueLabel}Name}} }})")
                .WithParam($"{valueLabel}Key", key.Key)
                .WithParam($"{valueLabel}Name", key.Name));
     }
     else
     {
         throw new NotImplementedException();
     }
 }
示例#2
0
        public static ICypherFluentQuery Merge <TVector>(this ICypherFluentQuery query, string path = null) where TVector : Vector
        {
            string from    = null;
            string rel     = null;
            string relPath = null;
            string to      = null;
            var    vars    = ProcessVars(path);

            if (vars.Successful())
            {
                var result = vars.Data;
                from    = result.From;
                rel     = result.Rel;
                relPath = result.RelPath;
                to      = result.To;
            }
            query = query.Merge(Common.Vector <TVector>(rel, from, to, relPath, fromLabel: false, toLabel: false));
            return(query);
        }
示例#3
0
        private static ICypherFluentQuery CommonMerge <T>(
            this ICypherFluentQuery query
            , T entity
            , string key
            , string mergeCql
            , List <CypherProperty> mergeOverride    = null
            , List <CypherProperty> onMatchOverride  = null
            , List <CypherProperty> onCreateOverride = null) where T : class
        {
            //A merge requires the properties of both merge, create and match in the cutdown object
            var mergeProperties  = mergeOverride ?? CypherTypeItemHelper.PropertiesForPurpose <T, CypherMergeAttribute>(entity);
            var createProperties = GetCreateProperties(entity, onCreateOverride);
            var matchProperties  = onMatchOverride ?? CypherTypeItemHelper.PropertiesForPurpose <T, CypherMergeOnMatchAttribute>(entity);

            dynamic mergeObjectParam = entity.CreateDynamic(mergeProperties);
            var     matchParamName   = GetMatchParamName(key);

            query = query.Merge(mergeCql);
            query = query.WithParam(matchParamName, mergeObjectParam);

            if (matchProperties.Count > 0)
            {
                var entityType = entity.GetType();
                foreach (var matchProperty in matchProperties)
                {
                    var propertyParam = key + matchProperty.JsonName;
                    var propertyValue = GetValue(entity, matchProperty, entityType);
                    query = query.OnMatch().Set(GetSetWithParamCql(key, matchProperty.JsonName, propertyParam));
                    query = query.WithParam(propertyParam, propertyValue);
                }
            }

            if (createProperties.Count > 0)
            {
                var     createParamName   = key + "OnCreate";
                dynamic createObjectParam = entity.CreateDynamic(createProperties);
                query = query.OnCreate().Set(GetSetWithParamCql(key, createParamName));
                query = query.WithParam(createParamName, createObjectParam);
            }

            return(query);
        }
        public void Execute(ICypherFluentQuery cypher)
        {

            ProcessStacks();

            foreach (var query in _queryStack)
            {

                if (query.QueryType == QueryTypeEnum.Match)
                {
                    cypher = cypher.Match(query.QueryString);
                    continue;
                }
                if (query.QueryType == QueryTypeEnum.OptionalMatch)
                {
                    cypher = cypher.OptionalMatch(query.QueryString);
                    continue;
                }

                if (query.QueryType == QueryTypeEnum.Where)
                {
                    cypher = cypher.Where(query.QueryString);
                    continue;
                }

                if (query.QueryType == QueryTypeEnum.Create)
                {
                    cypher = cypher.Create(query.QueryString);
                    continue;
                }

                if (query.QueryType == QueryTypeEnum.Merge)
                {
                    cypher = cypher.Merge(query.QueryString);
                    continue;
                }

                if (query.QueryType == QueryTypeEnum.Delete)
                {
                    cypher = cypher.Delete(query.QueryString);
                    continue;
                }

                if (query.QueryType == QueryTypeEnum.With)
                {
                    cypher = cypher.With(query.QueryString);
                    continue;
                }

            }

            cypher.ExecuteWithoutResults();
        }