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);
        }
        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);
        }
Пример #3
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, 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);
        }