Esempio n. 1
0
        public IEnumerable <T> ExecuteMany <T>(QueryDescription query, ObjectBinder objectBinder)
        {
            var key = CacheKey.Create(new HiveQueryCacheKey(query));
            Func <List <T> > execution = () =>
            {
                var executeItems = PerformExecuteMany <T>(query, objectBinder) ?? Enumerable.Empty <T>();
                return(executeItems.ToList());    // Ensure the executed sequence is cached
            };
            var cacheCheck = ContextCacheAvailable() ? HiveContext.GenerationScopedCache.GetOrCreate(key, execution) : null;

            var performExecute = cacheCheck != null ? cacheCheck.Value.Item : execution.Invoke();
            //var performExecute = PerformExecuteMany<T>(query, objectBinder) ?? Enumerable.Empty<T>();

            var items = performExecute
                        .ForAllThatAre <T, IReferenceByHiveId>(entity => ProviderRepositoryHelper.SetProviderAliasOnId(ProviderMetadata, entity))
                        .ForAllThatAre <T, IRelatableEntity>(entity => this.SetRelationProxyLazyLoadDelegate(entity));

            if (query.From.RequiredEntityIds.Any() && !query.SortClauses.Any())
            {
                // Return in same order as supplied ids
                return(query.From.RequiredEntityIds.Select(x => items.OfType <IReferenceByHiveId>().FirstOrDefault(y => y.Id.Value == x.Value)).WhereNotNull().OfType <T>());
            }

            return(items);
        }
Esempio n. 2
0
        public T ExecuteScalar <T>(QueryDescription query, ObjectBinder objectBinder)
        {
            var      key        = CacheKey.Create(new HiveQueryCacheKey(query));
            Func <T> execution  = () => PerformExecuteScalar <T>(query, objectBinder);
            var      cacheCheck = ContextCacheAvailable() ? HiveContext.GenerationScopedCache.GetOrCreate(key, execution) : null;
            //var performExecute = PerformExecuteScalar<T>(query, objectBinder);
            var performExecute = cacheCheck != null ? cacheCheck.Value.Item : execution.Invoke();

            if ((!typeof(T).IsValueType && performExecute == null) || performExecute.Equals(default(T)))
            {
                return(default(T));
            }

            if (typeof(IReferenceByHiveId).IsAssignableFrom(typeof(T)))
            {
                ProviderRepositoryHelper.SetProviderAliasOnId(ProviderMetadata, (IReferenceByHiveId)performExecute);
            }

            if (typeof(IRelatableEntity).IsAssignableFrom(typeof(T)))
            {
                this.SetRelationProxyLazyLoadDelegate((IRelatableEntity)performExecute);
            }

            return(performExecute);
        }
 private void OnAddOrUpdateComplete <TEntity>(Revision <TEntity> revision) where TEntity : class, T
 {
     ProviderRepositoryHelper.SetProviderAliasOnId(ProviderMetadata, revision.MetaData);
     ProviderRepositoryHelper.SetProviderAliasOnId(ProviderMetadata, revision.Item);
     this.SetRelationProxyLazyLoadDelegate(revision);
     RevisionDataAddedOrUpdated.Add(revision.MetaData);
     EntityDataAddedOrUpdated.Add(revision.Item);
 }
Esempio n. 4
0
        public IEnumerable <Revision <TEntity> > GetAll <TEntity>(HiveId entityId, RevisionStatusType revisionStatusType = null) where TEntity : class, T
        {
            var performGetAll = PerformGetAll <TEntity>(entityId, revisionStatusType);

            return(performGetAll == null && !performGetAll.Any()
                ? Enumerable.Empty <Revision <TEntity> >()
                : performGetAll.Select(x => ProviderRepositoryHelper.SetProviderAliasOnId(ProviderMetadata, this.SetRelationProxyLazyLoadDelegate(x))));
        }
Esempio n. 5
0
        public IEnumerable <T> Get <T>(bool allOrNothing, params HiveId[] ids) where T : TypedEntity
        {
            var performGet = PerformGet <T>(allOrNothing, ids) ?? Enumerable.Empty <T>();

            return(performGet.WhereNotNull().Select(x =>
            {
                x.EntitySchema = Schemas.GetComposite <EntitySchema>(x.EntitySchema.Id);
                return ProviderRepositoryHelper.SetProviderAliasOnId(ProviderMetadata, this.SetRelationProxyLazyLoadDelegate(x));
            }));
        }
Esempio n. 6
0
        public IEnumerable <T> GetAll <T>() where T : TypedEntity
        {
            var performGetAll = PerformGetAll <T>() ?? Enumerable.Empty <T>();

            return(performGetAll.Select(x =>
            {
                x.EntitySchema = Schemas.Get <EntitySchema>(x.EntitySchema.Id) ?? x.EntitySchema;
                return ProviderRepositoryHelper.SetProviderAliasOnId(ProviderMetadata, this.SetRelationProxyLazyLoadDelegate(x));
            }));
        }
        public IEnumerable <T> Get <T>(bool allOrNothing, params HiveId[] ids) where T : AbstractSchemaPart
        {
            var performGet = PerformGet <T>(allOrNothing, ids) ?? Enumerable.Empty <T>();

            // Enumerate the sequence once
            var all = performGet.ToArray();

            // Operate on a subset of the same array that we will then return
            all
            .Where(x => typeof(IRelatableEntity).IsAssignableFrom(x.GetType())).ToArray()
            .ForEach(x => this.SetRelationProxyLazyLoadDelegate((IRelatableEntity)x));

            // Return the total set manipulating their id beforehand
            return(all.Select(x => ProviderRepositoryHelper.SetProviderAliasOnId(ProviderMetadata, x)));
        }
Esempio n. 8
0
 protected void OnAddOrUpdateComplete(TypedEntity entity)
 {
     this.SetRelationProxyLazyLoadDelegate(entity);
     ProviderRepositoryHelper.SetProviderAliasOnId(ProviderMetadata, entity);
     EntitiesAddedOrUpdated.Add(entity);
 }
 private void OnAddOrUpdateComplete(AbstractSchemaPart entity)
 {
     this.SetRelationProxyLazyLoadDelegate(entity as IRelatableEntity);
     ProviderRepositoryHelper.SetProviderAliasOnId(ProviderMetadata, entity);
     EntitiesAddedOrUpdated.Add(entity);
 }
Esempio n. 10
0
        public IEnumerable <Revision <TEntity> > GetLatestRevisions <TEntity>(bool allOrNothing, RevisionStatusType revisionStatusType = null, params HiveId[] entityIds) where TEntity : class, T
        {
            var performGet = PerformGetLatestRevisions <TEntity>(allOrNothing, revisionStatusType, entityIds) ?? Enumerable.Empty <Revision <TEntity> >();

            return(performGet.Select(x => ProviderRepositoryHelper.SetProviderAliasOnId(ProviderMetadata, this.SetRelationProxyLazyLoadDelegate(x))));
        }
Esempio n. 11
0
        public Revision <TEntity> GetLatestRevision <TEntity>(HiveId entityId, RevisionStatusType revisionStatusType = null) where TEntity : class, T
        {
            var performGet = PerformGetLatestRevision <TEntity>(entityId, revisionStatusType);

            return(ProviderRepositoryHelper.SetProviderAliasOnId(ProviderMetadata, this.SetRelationProxyLazyLoadDelegate(performGet)));
        }
Esempio n. 12
0
 public Revision <TEntity> Get <TEntity>(HiveId entityId, HiveId revisionId) where TEntity : class, T
 {
     return(ProviderRepositoryHelper.SetProviderAliasOnId(ProviderMetadata, this.SetRelationProxyLazyLoadDelegate(PerformGet <TEntity>(entityId, revisionId))));
 }