Ejemplo n.º 1
0
 private static IEnumerable <IGremlinQuery <string> > CreateIndexQueries(this IDseGraphModel model, IImmutableDictionary <Type, IImmutableSet <Expression> > indexDictionary, string keyword, IIdentifierFactory identifierFactory)
 {
     return(model.VertexLabels
            .Where(vertexKvp => !vertexKvp.Key.GetTypeInfo().IsAbstract)
            .Select(vertexKvp => (
                        Label: vertexKvp.Value,
                        IndexProperties: vertexKvp.Key
                        .GetTypeHierarchy(model)
                        .SelectMany(x => indexDictionary
                                    .TryGetValue(x)
                                    .AsEnumerable()
                                    .SelectMany(y => y))
                        .Select(indexExpression => ((indexExpression as LambdaExpression)?.Body.StripConvert() as MemberExpression)?.Member.Name)
                        .ToImmutableList()))
            .Where(tuple => !tuple.IndexProperties.IsEmpty)
            .Select(tuple => tuple.IndexProperties
                    .Aggregate(
                        GremlinQuery
                        .Create("schema")
                        .AddStep <string>("vertexLabel", tuple.Label)
                        .AddStep <string>("index", identifierFactory.CreateIndexName())
                        .AddStep <string>(keyword),
                        (closureQuery, indexProperty) => closureQuery.AddStep <string>("by", indexProperty))
                    .AddStep <string>("add")));
 }
Ejemplo n.º 2
0
 private static IEnumerable <IGremlinQuery <string> > CreateEdgeIndexQueries(this IDseGraphModel model, IIdentifierFactory identifierFactory)
 {
     return(model.EdgeIndexes.Keys
            .SelectMany(edgeType => model
                        .GetDerivedTypes(edgeType, true)
                        .Where(inheritedType => !inheritedType.GetTypeInfo().IsAbstract)
                        .SelectMany(inheritedType => model
                                    .EdgeIndexes[inheritedType]
                                    .Where(index => index.direction != EdgeDirection.None)
                                    .SelectMany(index => model
                                                .GetDerivedTypes(index.vertexType, true)
                                                .Where(inheritedVertexType => !inheritedVertexType.GetTypeInfo().IsAbstract)
                                                .Select(inheritedVertexType => GremlinQuery <string>
                                                        .Create("schema")
                                                        .AddStep("vertexLabel", model.GetLabelOfType(inheritedVertexType))
                                                        .AddStep("index", identifierFactory.CreateIndexName())
                                                        .AddStep(
                                                            index.direction == EdgeDirection.Out
                                 ? "outE"
                                 : index.direction == EdgeDirection.In
                                     ? "inE"
                                     : "bothE",
                                                            model.GetLabelOfType(edgeType))
                                                        .AddStep("by", ((index.indexExpression as LambdaExpression)?.Body.StripConvert() as MemberExpression)?.Member.Name)
                                                        .AddStep("add"))))));
 }