public string GenerateQuery(QueryModel queryModel, bool selectDocumentMetadata, out ScalarResultBehavior scalarResultBehavior)
        {
            // If ITypeSerializer is an IExtendedTypeSerializer, use it as the member name resolver
            // Otherwise fallback to the legacy behavior which assumes we're using Newtonsoft.Json
            // Note that DefaultSerializer implements IExtendedTypeSerializer, but has the same logic as JsonNetMemberNameResolver

            var serializer = Serializer as IExtendedTypeSerializer;

#pragma warning disable CS0618 // Type or member is obsolete
            var memberNameResolver = serializer != null ?
                                     (IMemberNameResolver) new ExtendedTypeSerializerMemberNameResolver(serializer) :
                                     (IMemberNameResolver) new JsonNetMemberNameResolver(_configuration.SerializationSettings.ContractResolver);
#pragma warning restore CS0618 // Type or member is obsolete

            var methodCallTranslatorProvider = new DefaultMethodCallTranslatorProvider();

            var queryGenerationContext = new N1QlQueryGenerationContext
            {
                MemberNameResolver           = memberNameResolver,
                MethodCallTranslatorProvider = methodCallTranslatorProvider,
                Serializer             = serializer,
                SelectDocumentMetadata = selectDocumentMetadata,
                ClusterVersion         = VersionProvider.Current.GetVersion(_bucket)
            };

            var visitor = new N1QlQueryModelVisitor(queryGenerationContext);
            visitor.VisitQueryModel(queryModel);

            var query = visitor.GetQuery();
            _log.Debug("Generated query: {0}", query);

            scalarResultBehavior = visitor.ScalarResultBehavior;
            return(query);
        }
        public string GenerateQuery(QueryModel queryModel, out ScalarResultBehavior scalarResultBehavior)
        {
            // If ITypeSerializer is an IExtendedTypeSerializer, use it as the member name resolver
            // Otherwise fallback to the legacy behavior which assumes we're using Newtonsoft.Json
            // Note that DefaultSerializer implements IExtendedTypeSerializer, but has the same logic as JsonNetMemberNameResolver

            var serializer = Serializer as IExtendedTypeSerializer;

#pragma warning disable CS0618 // Type or member is obsolete
            var memberNameResolver = serializer != null ?
                                     (IMemberNameResolver) new ExtendedTypeSerializerMemberNameResolver(serializer) :
                                     (IMemberNameResolver) new JsonNetMemberNameResolver(JsonConvert.DefaultSettings().ContractResolver);
#pragma warning restore CS0618 // Type or member is obsolete

            var methodCallTranslatorProvider = new DefaultMethodCallTranslatorProvider();

            var queryGenerationContext = new N1QlQueryGenerationContext
            {
                MemberNameResolver           = memberNameResolver,
                MethodCallTranslatorProvider = methodCallTranslatorProvider,
                Serializer = serializer,
                // TODO: Don't use .Result
                ClusterVersion = _clusterVersionProvider.GetVersionAsync().Result ?? FeatureVersions.DefaultVersion,
                LoggerFactory  = _cluster.ClusterServices.GetRequiredService <ILoggerFactory>()
            };

            var visitor = new N1QlQueryModelVisitor(queryGenerationContext);
            visitor.VisitQueryModel(queryModel);

            var query = visitor.GetQuery();
            _logger.LogDebug("Generated query: {0}", query);

            scalarResultBehavior = visitor.ScalarResultBehavior;
            return(query);
        }
Ejemplo n.º 3
0
        internal string CreateN1QlQuery(IBucket bucket, Expression expression, ClusterVersion clusterVersion,
                                        bool selectDocumentMetadata, out ScalarResultBehavior resultBehavior)
        {
            var serializer = new Core.Serialization.DefaultSerializer();

            var bucketContext = new Mock <IBucketContext>();

            bucketContext.SetupGet(p => p.Bucket).Returns(bucket);
            bucketContext.SetupGet(p => p.Configuration).Returns(new ClientConfiguration
            {
                Serializer = () => serializer
            });

            var queryModel = QueryParserHelper.CreateQueryParser(bucketContext.Object).GetParsedQuery(expression);

            var queryGenerationContext = new N1QlQueryGenerationContext()
            {
                MemberNameResolver           = MemberNameResolver,
                MethodCallTranslatorProvider = new DefaultMethodCallTranslatorProvider(),
                Serializer             = serializer,
                SelectDocumentMetadata = selectDocumentMetadata,
                ClusterVersion         = clusterVersion
            };

            var visitor = new N1QlQueryModelVisitor(queryGenerationContext);

            visitor.VisitQueryModel(queryModel);

            resultBehavior = visitor.ScalarResultBehavior;
            return(visitor.GetQuery());
        }
Ejemplo n.º 4
0
        internal string CreateN1QlQuery(IBucket bucket, Expression expression, ClusterVersion clusterVersion,
                                        bool selectDocumentMetadata, out ScalarResultBehavior resultBehavior)
        {
            var mockCluster = new Mock <ICluster>();

            mockCluster
            .Setup(p => p.ClusterServices)
            .Returns(ServiceProvider);

            var queryModel = QueryParserHelper.CreateQueryParser(mockCluster.Object).GetParsedQuery(expression);

            var queryGenerationContext = new N1QlQueryGenerationContext()
            {
                MemberNameResolver           = MemberNameResolver,
                MethodCallTranslatorProvider = new DefaultMethodCallTranslatorProvider(),
                Serializer             = ServiceProvider.GetRequiredService <ITypeSerializer>(),
                SelectDocumentMetadata = selectDocumentMetadata,
                ClusterVersion         = clusterVersion,
                LoggerFactory          = LoggerFactory
            };

            var visitor = new N1QlQueryModelVisitor(queryGenerationContext);

            visitor.VisitQueryModel(queryModel);

            resultBehavior = visitor.ScalarResultBehavior;
            return(visitor.GetQuery());
        }
Ejemplo n.º 5
0
        public string ExecuteCollection(QueryModel queryModel)
        {
            //TODO: this should be refactored so that does not rely on NewtonSoft and so that it's using a
            //"pluggable" resolver and translator via configuration.
            var memberNameResolver           = new JsonNetMemberNameResolver(_configuration.SerializationSettings.ContractResolver);
            var methodCallTranslatorProvider = new DefaultMethodCallTranslatorProvider();
            var query = N1QlQueryModelVisitor.GenerateN1QlQuery(queryModel, memberNameResolver,
                                                                methodCallTranslatorProvider, _configuration.Serializer.Invoke());

            Log.Debug(m => m("Generated query: {0}", query));

            return(query);
        }
        public string ExecuteCollection(QueryModel queryModel)
        {
            var queryGenerationContext = new N1QlQueryGenerationContext()
            {
                MemberNameResolver           = Test.MemberNameResolver,
                MethodCallTranslatorProvider = new DefaultMethodCallTranslatorProvider(),
                Serializer = new Core.Serialization.DefaultSerializer()
            };

            var visitor = new N1QlQueryModelVisitor(queryGenerationContext);

            visitor.VisitQueryModel(queryModel);
            return(visitor.GetQuery());
        }
Ejemplo n.º 7
0
        protected string CreateN1QlQuery(IBucket bucket, Expression expression)
        {
            var queryModel = QueryParserHelper.CreateQueryParser().GetParsedQuery(expression);

            var queryGenerationContext = new N1QlQueryGenerationContext()
            {
                MemberNameResolver           = new JsonNetMemberNameResolver(_contractResolver),
                MethodCallTranslatorProvider = new DefaultMethodCallTranslatorProvider(),
                Serializer = new Core.Serialization.DefaultSerializer()
            };

            var visitor = new N1QlQueryModelVisitor(queryGenerationContext);

            visitor.VisitQueryModel(queryModel);
            return(visitor.GetQuery());
        }
Ejemplo n.º 8
0
        protected string CreateN1QlQuery(IBucket bucket, Expression expression, Version clusterVersion, bool selectDocumentMetadata)
        {
            var queryModel = QueryParserHelper.CreateQueryParser().GetParsedQuery(expression);

            var queryGenerationContext = new N1QlQueryGenerationContext()
            {
                MemberNameResolver           = MemberNameResolver,
                MethodCallTranslatorProvider = new DefaultMethodCallTranslatorProvider(),
                Serializer             = new Core.Serialization.DefaultSerializer(),
                SelectDocumentMetadata = selectDocumentMetadata,
                ClusterVersion         = clusterVersion
            };

            var visitor = new N1QlQueryModelVisitor(queryGenerationContext);

            visitor.VisitQueryModel(queryModel);
            return(visitor.GetQuery());
        }
        public string ExecuteCollection(QueryModel queryModel, out bool resultExtractionRequired)
        {
            // If ITypeSerializer is an IExtendedTypeSerializer, use it as the member name resolver
            // Otherwise fallback to the legacy behavior which assumes we're using Newtonsoft.Json
            // Note that DefaultSerializer implements IExtendedTypeSerializer, but has the same logic as JsonNetMemberNameResolver

            var serializer         = _configuration.Serializer.Invoke() as IExtendedTypeSerializer;
            var memberNameResolver = serializer != null ?
                                     (IMemberNameResolver) new ExtendedTypeSerializerMemberNameResolver(serializer) :
                                     (IMemberNameResolver) new JsonNetMemberNameResolver(_configuration.SerializationSettings.ContractResolver);

            var methodCallTranslatorProvider = new DefaultMethodCallTranslatorProvider();

            var visitor = new N1QlQueryModelVisitor(memberNameResolver, methodCallTranslatorProvider, _configuration.Serializer.Invoke());

            visitor.VisitQueryModel(queryModel);

            var query = visitor.GetQuery();

            Log.Debug(m => m("Generated query: {0}", query));

            resultExtractionRequired = visitor.ResultExtractionRequired;
            return(query);
        }