/// <summary> /// Gets the specified object /// </summary> public virtual TData Get <TIdentifier>(MARC.HI.EHRS.SVC.Core.Data.Identifier <TIdentifier> containerId, IPrincipal principal, bool loadFast) { // Try the cache if available var guidIdentifier = containerId as Identifier <Guid>; var cacheItem = ApplicationContext.Current.GetService <IDataCachingService>()?.GetCacheItem <TData>(guidIdentifier.Id) as TData; if (loadFast && cacheItem != null) { return(cacheItem); } else { var tr = 0; return(this.Query(o => o.Key == guidIdentifier.Id, 0, 1, principal, out tr)?.SingleOrDefault()); } }
/// <summary> /// Gets the specified object /// </summary> public override TModel Get <TIdentifier>(MARC.HI.EHRS.SVC.Core.Data.Identifier <TIdentifier> containerId, IPrincipal principal, bool loadFast) { var tr = 0; var uuid = containerId as Identifier <Guid>; if (uuid.Id != Guid.Empty) { var cacheItem = ApplicationContext.Current.GetService <IDataCachingService>()?.GetCacheItem <TModel>(uuid.Id) as TModel; if (cacheItem != null && (cacheItem.VersionKey.HasValue && uuid.VersionId == cacheItem.VersionKey.Value || uuid.VersionId == Guid.Empty)) { return(cacheItem); } } // Get most recent version if (uuid.VersionId == Guid.Empty) { return(base.Query(o => o.Key == uuid.Id && o.ObsoletionTime == null, 0, 1, principal, out tr).FirstOrDefault()); } else { return(base.Query(o => o.Key == uuid.Id && o.VersionKey == uuid.VersionId, 0, 1, principal, out tr).FirstOrDefault()); } }
/// <summary> /// Gets the specified object /// </summary> public virtual TData Get <TIdentifier>(MARC.HI.EHRS.SVC.Core.Data.Identifier <TIdentifier> containerId, IPrincipal principal, bool loadFast) { // Try the cache if available var guidIdentifier = containerId as Identifier <Guid>; var cacheItem = ApplicationContext.Current.GetService <IDataCachingService>()?.GetCacheItem <TData>(guidIdentifier.Id) as TData; if (loadFast && cacheItem != null) { return(cacheItem); } else { #if DEBUG Stopwatch sw = new Stopwatch(); sw.Start(); #endif PreRetrievalEventArgs preArgs = new PreRetrievalEventArgs(containerId, principal); this.Retrieving?.Invoke(this, preArgs); if (preArgs.Cancel) { this.m_tracer.TraceEvent(TraceEventType.Warning, 0, "Pre-Event handler indicates abort retrieve {0}", containerId.Id); return(null); } // Query object using (var connection = m_configuration.Provider.GetReadonlyConnection()) try { this.ThrowIfExceeded(); connection.Open(); this.m_tracer.TraceEvent(TraceEventType.Verbose, 0, "GET {0}", containerId); if (loadFast) { connection.AddData("loadFast", true); connection.LoadState = LoadState.PartialLoad; } else { connection.LoadState = LoadState.FullLoad; } var result = this.Get(connection, guidIdentifier.Id, principal); var postData = new PostRetrievalEventArgs <TData>(result, principal); this.Retrieved?.Invoke(this, postData); foreach (var itm in connection.CacheOnCommit) { ApplicationContext.Current.GetService <IDataCachingService>()?.Add(itm); } return(result); } catch (NotSupportedException e) { throw new DataPersistenceException("Cannot perform LINQ query", e); } catch (Exception e) { this.m_tracer.TraceEvent(TraceEventType.Error, 0, "Error : {0}", e); throw; } finally { #if DEBUG sw.Stop(); this.m_tracer.TraceEvent(TraceEventType.Verbose, 0, "Retrieve took {0} ms", sw.ElapsedMilliseconds); #endif Interlocked.Decrement(ref m_currentRequests); } } }
/// <summary> /// Gets the specified object taking version of the entity into consideration /// </summary> public override TModel Get <TIdentifier>(MARC.HI.EHRS.SVC.Core.Data.Identifier <TIdentifier> containerId, IPrincipal principal, bool loadFast) { var tr = 0; var uuid = containerId as Identifier <Guid>; if (uuid.Id != Guid.Empty) { var cacheItem = ApplicationContext.Current.GetService <IDataCachingService>()?.GetCacheItem <TModel>(uuid.Id) as TModel; if (cacheItem != null && (cacheItem.VersionKey.HasValue && uuid.VersionId == cacheItem.VersionKey.Value || uuid.VersionId == Guid.Empty) && (loadFast && cacheItem.LoadState >= LoadState.PartialLoad || !loadFast && cacheItem.LoadState == LoadState.FullLoad)) { return(cacheItem); } } #if DEBUG Stopwatch sw = new Stopwatch(); sw.Start(); #endif PreRetrievalEventArgs preArgs = new PreRetrievalEventArgs(containerId, principal); this.FireRetrieving(preArgs); if (preArgs.Cancel) { this.m_tracer.TraceEvent(TraceEventType.Warning, 0, "Pre-Event handler indicates abort retrieve {0}", containerId.Id); return(null); } // Query object using (var connection = m_configuration.Provider.GetReadonlyConnection()) try { connection.Open(); this.m_tracer.TraceEvent(TraceEventType.Verbose, 0, "GET {0}", containerId); TModel retVal = null; connection.LoadState = LoadState.FullLoad; // Get most recent version if (uuid.VersionId == Guid.Empty) { retVal = this.Get(connection, uuid.Id, principal); } else { retVal = this.CacheConvert(this.QueryInternal(connection, o => o.Key == uuid.Id && o.VersionKey == uuid.VersionId, Guid.Empty, 0, 1, out tr).FirstOrDefault(), connection, principal); } var postData = new PostRetrievalEventArgs <TModel>(retVal, principal); this.FireRetrieved(postData); return(retVal); } catch (NotSupportedException e) { throw new DataPersistenceException("Cannot perform LINQ query", e); } catch (Exception e) { this.m_tracer.TraceEvent(TraceEventType.Error, 0, "Error : {0}", e); throw; } finally { #if DEBUG sw.Stop(); this.m_tracer.TraceEvent(TraceEventType.Verbose, 0, "Retrieve took {0} ms", sw.ElapsedMilliseconds); #endif } }