Example #1
0
        public static IEnumerable <T> ParseValuesFromBlittableArray <T>(InMemoryDocumentSessionOperations session, BlittableJsonReaderArray blittableArray)
        {
            for (var i = 0; i < blittableArray.Length; i++)
            {
                var blittableJsonToken = blittableArray.GetValueTokenTupleByIndex(i).Item2;

                switch (blittableJsonToken)
                {
                case BlittableJsonToken.StartArray:
                    foreach (var inner in ParseValuesFromBlittableArray <T>(session, blittableArray[i] as BlittableJsonReaderArray))
                    {
                        yield return(inner);
                    }
                    break;

                case BlittableJsonToken.StartObject:
                    yield return((T)session.DeserializeFromTransformer(typeof(T), null, blittableArray[i] as BlittableJsonReaderObject));

                    break;

                case BlittableJsonToken.String:
                    var lazyString = blittableArray[i] as LazyStringValue;
                    if (lazyString != null)
                    {
                        yield return((T)(object)lazyString.ToString());
                    }
                    break;

                case BlittableJsonToken.CompressedString:
                    var lazyCompressedString = blittableArray[i] as LazyCompressedStringValue;
                    if (lazyCompressedString != null)
                    {
                        yield return((T)(object)lazyCompressedString.ToString());
                    }
                    break;

                default:
                    // TODO, check if other types need special handling as well
                    yield return((T)blittableArray[i]);

                    break;
                }
            }
        }
Example #2
0
        public QueryOperation(InMemoryDocumentSessionOperations session, string indexName, IndexQuery indexQuery,
                              string[] projectionFields, bool waitForNonStaleResults, TimeSpan?timeout,
                              Func <IndexQuery, IEnumerable <object>, IEnumerable <object> > transformResults,
                              HashSet <string> includes, bool disableEntitiesTracking, bool metadataOnly = false, bool indexEntriesOnly = false)
        {
            _session                 = session;
            _indexName               = indexName;
            _indexQuery              = indexQuery;
            _waitForNonStaleResults  = waitForNonStaleResults;
            _timeout                 = timeout;
            _transformResults        = transformResults;
            _includes                = includes;
            _projectionFields        = projectionFields;
            _disableEntitiesTracking = disableEntitiesTracking;
            _metadataOnly            = metadataOnly;
            _indexEntriesOnly        = indexEntriesOnly;

            AssertNotQueryById();
        }
Example #3
0
        public QueryOperation(
            InMemoryDocumentSessionOperations session,
            string indexName,
            IndexQuery indexQuery,
            FieldsToFetchToken fieldsToFetch,
            bool disableEntitiesTracking,
            bool metadataOnly     = false,
            bool indexEntriesOnly = false)
        {
            _session          = session;
            _indexName        = indexName;
            _indexQuery       = indexQuery;
            _fieldsToFetch    = fieldsToFetch;
            NoTracking        = disableEntitiesTracking;
            _metadataOnly     = metadataOnly;
            _indexEntriesOnly = indexEntriesOnly;

            AssertPageSizeSet();
        }
Example #4
0
        public QueryCommand(InMemoryDocumentSessionOperations session, IndexQuery indexQuery, bool metadataOnly = false, bool indexEntriesOnly = false)
        {
            _indexQuery       = indexQuery ?? throw new ArgumentNullException(nameof(indexQuery));
            _session          = session ?? throw new ArgumentNullException(nameof(session));
            _conventions      = _session.Conventions ?? throw new ArgumentNullException(nameof(_session.Conventions));
            _metadataOnly     = metadataOnly;
            _indexEntriesOnly = indexEntriesOnly;

            if (indexQuery.WaitForNonStaleResultsTimeout.HasValue && indexQuery.WaitForNonStaleResultsTimeout != TimeSpan.MaxValue)
            {
                var timeout = indexQuery.WaitForNonStaleResultsTimeout.Value;
                if (timeout < RequestExecutor.GlobalHttpClientTimeout) // if it is greater than it will throw in RequestExecutor
                {
                    timeout = RequestExecutor.GlobalHttpClientTimeout - timeout > AdditionalTimeToAddToTimeout
                        ? timeout.Add(AdditionalTimeToAddToTimeout) : RequestExecutor.GlobalHttpClientTimeout; // giving the server an opportunity to finish the response
                }

                Timeout = timeout;
            }
        }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RavenQueryInspector{T}"/> class.
 /// </summary>
 public void Init(
     IRavenQueryProvider provider,
     QueryStatistics queryStats,
     QueryHighlightings highlightings,
     string indexName,
     string collectionName,
     Expression expression,
     InMemoryDocumentSessionOperations session,
     bool isMapReduce)
 {
     _provider       = provider?.For <T>() ?? throw new ArgumentNullException(nameof(provider));
     _queryStats     = queryStats;
     _highlightings  = highlightings;
     _indexName      = indexName;
     _collectionName = collectionName;
     _session        = session;
     _isMapReduce    = isMapReduce;
     _provider.AfterQueryExecuted(AfterQueryExecuted);
     _expression = expression ?? Expression.Constant(this);
 }
Example #6
0
        public QueryOperation(InMemoryDocumentSessionOperations sessionOperations, string indexName, IndexQuery indexQuery,
                              string[] projectionFields, HashSet <KeyValuePair <string, Type> > sortByHints,
                              bool waitForNonStaleResults, Action <string, string> setOperationHeaders, TimeSpan timeout,
                              Func <IndexQuery, IEnumerable <object>, IEnumerable <object> > transformResults,
                              HashSet <string> includes, bool disableEntitiesTracking)
        {
            this.indexQuery             = indexQuery;
            this.sortByHints            = sortByHints;
            this.waitForNonStaleResults = waitForNonStaleResults;
            this.setOperationHeaders    = setOperationHeaders;
            this.timeout                 = timeout;
            this.transformResults        = transformResults;
            this.includes                = includes;
            this.projectionFields        = projectionFields;
            this.sessionOperations       = sessionOperations;
            this.indexName               = indexName;
            this.disableEntitiesTracking = disableEntitiesTracking;

            AssertNotQueryById();
            AddOperationHeaders();
        }
Example #7
0
        public QueryOperation(InMemoryDocumentSessionOperations sessionOperations,
                              string indexName,
                              IndexQuery indexQuery,
                              string[] projectionFields,
                              HashSet <KeyValuePair <string, Type> > sortByHints,
                              bool waitForNonStaleResults,
                              Action <string, string> setOperationHeaders,
                              TimeSpan timeout)
        {
            this.indexQuery             = indexQuery;
            this.sortByHints            = sortByHints;
            this.waitForNonStaleResults = waitForNonStaleResults;
            this.setOperationHeaders    = setOperationHeaders;
            this.timeout           = timeout;
            this.projectionFields  = projectionFields;
            this.sessionOperations = sessionOperations;
            this.indexName         = indexName;


            AddOperationHeaders();
        }
Example #8
0
        public static IEnumerable <T> ParseResults <T>(InMemoryDocumentSessionOperations session, GetDocumentResult transformedResult)
        {
            foreach (BlittableJsonReaderObject result in transformedResult.Results)
            {
                if (result == null)
                {
                    yield return(default(T));

                    continue;
                }

                BlittableJsonReaderArray values;
                if (result.TryGet("$values", out values) == false)
                {
                    throw new InvalidOperationException("Transformed document must have a $values property");
                }

                foreach (var value in ParseValuesFromBlittableArray <T>(session, values))
                {
                    yield return(value);
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="RavenQueryInspector{T}"/> class.
 /// </summary>
 public void Init(
     IRavenQueryProvider provider,
     RavenQueryStatistics queryStats,
     RavenQueryHighlightings highlightings,
     string indexName,
     Expression expression,
     InMemoryDocumentSessionOperations session
     ,
     bool isMapReduce
     )
 {
     if (provider == null)
     {
         throw new ArgumentNullException("provider");
     }
     this.provider      = provider.For <T>();
     this.queryStats    = queryStats;
     this.highlightings = highlightings;
     this.indexName     = indexName;
     this.session       = session;
     this.isMapReduce   = isMapReduce;
     this.provider.AfterQueryExecuted(this.AfterQueryExecuted);
     this.expression = expression ?? Expression.Constant(this);
 }
Example #10
0
        internal static T Deserialize <T>(string id, BlittableJsonReaderObject document, BlittableJsonReaderObject metadata, FieldsToFetchToken fieldsToFetch, bool disableEntitiesTracking, InMemoryDocumentSessionOperations session)
        {
            if (metadata.TryGetProjection(out var projection) == false || projection == false)
            {
                return(session.TrackEntity <T>(id, document, metadata, disableEntitiesTracking));
            }

            if (fieldsToFetch?.Projections != null && fieldsToFetch.Projections.Length == 1) // we only select a single field
            {
                var type            = typeof(T);
                var typeInfo        = type.GetTypeInfo();
                var projectionField = fieldsToFetch.Projections[0];

                if (fieldsToFetch.SourceAlias != null)
                {
                    if (projectionField.StartsWith(fieldsToFetch.SourceAlias))
                    {
                        // remove source-alias from projection name
                        projectionField = projectionField.Substring(fieldsToFetch.SourceAlias.Length + 1);
                    }
                    if (Regex.IsMatch(projectionField, "'([^']*)"))
                    {
                        // projection field is quoted, remove quotes
                        projectionField = projectionField.Substring(1, projectionField.Length - 2);
                    }
                }

                if (type == typeof(string) || typeInfo.IsValueType || typeInfo.IsEnum)
                {
                    return(document.TryGet(projectionField, out T value) == false
                        ? default
                        : value);
                }

                if (document.TryGetMember(projectionField, out object inner) == false)
                {
                    return(default);
Example #11
0
 public LoadOperation(InMemoryDocumentSessionOperations session)
 {
     _session = session;
 }
Example #12
0
 public BatchOperation(InMemoryDocumentSessionOperations session)
 {
     _session = session;
 }
 public LoadTransformerOperation(InMemoryDocumentSessionOperations documentSession, string transformer, string[] ids)
 {
     this.documentSession = documentSession;
     this.transformer     = transformer;
     this.ids             = ids;
 }
Example #14
0
 public BeforeDeleteEventArgs(InMemoryDocumentSessionOperations session, string documentId, object entity)
 {
     Session    = session;
     DocumentId = documentId;
     Entity     = entity;
 }
		public AsyncDocumentKeyGeneration(InMemoryDocumentSessionOperations session,TryGetValue tryGetValue, ModifyObjectId modifyObjectId)
		{
			this.session = session;
			this.tryGetValue = tryGetValue;
			this.modifyObjectId = modifyObjectId;
		}
Example #16
0
 public StreamOperation(InMemoryDocumentSessionOperations session, StreamQueryStatistics statistics)
 {
     _session    = session;
     _statistics = statistics;
 }
Example #17
0
 public MultiGetOperation(InMemoryDocumentSessionOperations session)
 {
     _session = session;
 }
Example #18
0
 public LoadOperation(InMemoryDocumentSessionOperations sessionOperations, Func <IDisposable> disableAllCaching, string id)
 {
     this.sessionOperations = sessionOperations;
     this.disableAllCaching = disableAllCaching;
     this.id = id;
 }
Example #19
0
 public StreamOperation(InMemoryDocumentSessionOperations session)
 {
     _session = session;
 }
Example #20
0
 public LazyQueryOperation(InMemoryDocumentSessionOperations session, QueryOperation queryOperation, Action <QueryResult> afterQueryExecuted)
 {
     _session            = session;
     _queryOperation     = queryOperation;
     _afterQueryExecuted = afterQueryExecuted;
 }
 private static void TrackSession(InMemoryDocumentSessionOperations obj)
 {
     using (MiniProfiler.Current.Step("RavenDb: Created Session")) { }
 }
Example #22
0
		private static void TrackSession(InMemoryDocumentSessionOperations session) {
			GlimpseTimer.Moment("Session Created", GlimpseTimerCategory);
			ContextualSessionList.Add(session.Id);
		}
Example #23
0
 private void AfterSessionCreated(InMemoryDocumentSessionOperations session)
 {
     Action<InMemoryDocumentSessionOperations> action = this.SessionCreatedInternal;
       if (action == null)
     return;
       action(session);
 }
Example #24
0
 private static void SessionCreated(InMemoryDocumentSessionOperations operations, NancyContext context)
 {
     GetCurrentSessionIdList(context).Add(operations.Id);
     //context.Response.WithHeader("X-RavenDb-Profiling-Id", operations.Id.ToString());
 }
Example #25
0
        protected override void AfterSessionCreated(InMemoryDocumentSessionOperations session)
        {
            if (Conventions.ShouldAggressiveCacheTrackChanges && aggressiveCachingUsed)
            {
                var databaseName = session.DatabaseName ?? Constants.SystemDatabase;
                observeChangesAndEvictItemsFromCacheForDatabases.GetOrAdd(databaseName ,
                    _ => new EvictItemsFromCacheBasedOnChanges(databaseName,
                        Changes(databaseName),
                        jsonRequestFactory.ExpireItemsFromCache));
            }

            base.AfterSessionCreated(session);
        }
Example #26
0
 public void OnBeforeSaveChanges(InMemoryDocumentSessionOperations session)
 {
     session.OnBeforeDeleteInvoke(new BeforeDeleteEventArgs(session, Id, null));
 }
Example #27
0
 public BeforeQueryExecutedEventArgs(InMemoryDocumentSessionOperations session, IDocumentQueryCustomization queryCustomization)
 {
     Session            = session;
     QueryCustomization = queryCustomization;
 }
Example #28
0
 public void OnBeforeSaveChanges(InMemoryDocumentSessionOperations session)
 {
     ReturnDocument = session.IsLoaded(Id);
 }
Example #29
0
 public LazyStartsWithOperation(string keyPrefix, string matches, int start, int pageSize, InMemoryDocumentSessionOperations sessionOperations)
 {
     this.keyPrefix         = keyPrefix;
     this.matches           = matches;
     this.start             = start;
     this.pageSize          = pageSize;
     this.sessionOperations = sessionOperations;
 }
Example #30
0
		private void OnSessionCreated(InMemoryDocumentSessionOperations operations)
		{
			RavenProfiler.ContextualSessionList.Add(operations.Id);
			if (HttpContext.Current != null) 
			{
				HttpContext.Current.Response.AddHeader("X-RavenDb-Profiling-Id", operations.Id.ToString());
			}
		}
Example #31
0
 public TestQueryCommand(InMemoryDocumentSessionOperations session, DocumentConventions conventions, IndexQuery indexQuery, bool metadataOnly = false, bool indexEntriesOnly = false) : base(session, indexQuery, metadataOnly, indexEntriesOnly)
 {
     Timeout = TimeSpan.FromMilliseconds(100);
 }
Example #32
0
 protected AggregationQueryBase(InMemoryDocumentSessionOperations session)
 {
     _session = session;
 }
Example #33
0
		private void OnSessionCreated(InMemoryDocumentSessionOperations operations)
		{
			RavenProfiler.ContextualSessionList.Add(operations.Id);
			if (HttpContext.Current == null)
				return;
			
			try
			{
				HttpContext.Current.Response.AddHeader("X-RavenDb-Profiling-Id", operations.Id.ToString());
			}
			catch (HttpException)
			{
				// headers were already written, nothing much that we can do here, ignoring
			}
		}
Example #34
0
 public SessionOperationExecutor(InMemoryDocumentSessionOperations session)
     : base(session.DocumentStore, session.DatabaseName)
 {
     _session = session;
 }
Example #35
0
 protected SuggestionQueryBase(InMemoryDocumentSessionOperations session)
 {
     _session = session;
 }
 public AsyncDocumentIdGeneration(InMemoryDocumentSessionOperations session, TryGetValue tryGetValue, ModifyObjectId modifyObjectId)
 {
     _session        = session;
     _tryGetValue    = tryGetValue;
     _modifyObjectId = modifyObjectId;
 }
Example #37
0
		protected void AfterSessionCreated(InMemoryDocumentSessionOperations session)
		{
			var onSessionCreatedInternal = SessionCreatedInternal;
			if (onSessionCreatedInternal != null)
				onSessionCreatedInternal(session);
		}
 public void OnBeforeSaveChanges(InMemoryDocumentSessionOperations session)
 {
 }
 public AsyncDocumentKeyGeneration(InMemoryDocumentSessionOperations session, TryGetValue tryGetValue, ModifyObjectId modifyObjectId)
 {
     this.session        = session;
     this.tryGetValue    = tryGetValue;
     this.modifyObjectId = modifyObjectId;
 }
Example #40
0
 private static void TrackSession(InMemoryDocumentSessionOperations obj)
 {
     NewRelic.Api.Agent.NewRelic.IncrementCounter("RavenDB/SessionCount");
 }