Ejemplo n.º 1
0
        public IReadOnlyList <AttributeHolder> Get([NotNull] EntityMetadata entityMetadata, long rowstamp, SearchRequestDto searchDto = null)
        {
            if (entityMetadata == null)
            {
                throw new ArgumentNullException("entityMetadata");
            }
            if (searchDto == null)
            {
                searchDto = new SearchRequestDto();
            }
            var query = new EntityQueryBuilder().AllRows(entityMetadata, searchDto);

            if (searchDto.QueryGeneratorService != null && entityMetadata is SlicedEntityMetadata)
            {
                var sliced      = (SlicedEntityMetadata)entityMetadata;
                var customQuery = GenericSwMethodInvoker.Invoke <string>(sliced.AppSchema, searchDto.QueryGeneratorService, entityMetadata,
                                                                         searchDto);
                if (customQuery != null)
                {
                    query.Sql = customQuery;
                }
            }

            var rows = Query(entityMetadata, query, rowstamp, searchDto);

            return(rows.Cast <IEnumerable <KeyValuePair <string, object> > >()
                   .Select(r => BuildDataMap(entityMetadata, r))
                   .ToList());
        }
Ejemplo n.º 2
0
        public int Count([NotNull] EntityMetadata entityMetadata, [NotNull] SearchRequestDto searchDto)
        {
            if (entityMetadata == null)
            {
                throw new ArgumentNullException("entityMetadata");
            }
            if (searchDto == null)
            {
                throw new ArgumentNullException("searchDto");
            }
            var query = new EntityQueryBuilder().CountRows(entityMetadata, searchDto);

            if (searchDto.QueryGeneratorService != null && entityMetadata is SlicedEntityMetadata)
            {
                var sliced = (SlicedEntityMetadata)entityMetadata;

                var customQuery = GenericSwMethodInvoker.Invoke <string>(sliced.AppSchema, searchDto.QueryGeneratorService + "Count", entityMetadata,
                                                                         searchDto);
                if (customQuery != null)
                {
                    query.Sql = customQuery;
                }
            }

            return(GetDao(entityMetadata).CountByNativeQuery(query.Sql, query.Parameters, searchDto.QueryAlias));
        }
Ejemplo n.º 3
0
        public IList <IEnumerable <KeyValuePair <string, object> > > GetSynchronizationData(SlicedEntityMetadata entityMetadata, Rowstamps rowstamps)
        {
            var query = new EntityQueryBuilder().AllRowsForSync(entityMetadata, rowstamps);
            //TODO: hack to avoid garbage data and limit size of list queries.
            var sql         = query.Sql;
            var queryResult = GetDao(entityMetadata).FindByNativeQuery(sql, query.Parameters);
            var rows        = queryResult.Cast <IEnumerable <KeyValuePair <string, object> > >();

            return(rows as IList <IEnumerable <KeyValuePair <string, object> > > ?? rows.ToList());
        }
Ejemplo n.º 4
0
        public IEnumerable <dynamic> RawGet([NotNull] EntityMetadata entityMetadata, [NotNull] SearchRequestDto searchDto)
        {
            if (entityMetadata == null)
            {
                throw new ArgumentNullException("entityMetadata");
            }
            if (searchDto == null)
            {
                throw new ArgumentNullException("searchDto");
            }
            var query = new EntityQueryBuilder().AllRows(entityMetadata, searchDto);
            var rows  = Query(entityMetadata, query, searchDto);

            return(rows);
        }
Ejemplo n.º 5
0
        public AttributeHolder Get([NotNull] EntityMetadata entityMetadata, [NotNull] string id)
        {
            //TODO: we're always handling the entity ID as a string.
            //Maybe we should leverage the entity attribute type.
            if (entityMetadata == null)
            {
                throw new ArgumentNullException("entityMetadata");
            }
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }

            var query = new EntityQueryBuilder().ById(entityMetadata, id);


            var rows = Query(entityMetadata, query, new SearchRequestDto());

            return(rows.Cast <IEnumerable <KeyValuePair <string, object> > >()
                   .Select(r => BuildDataMap(entityMetadata, r))
                   .ToList().FirstOrDefault());
        }
Ejemplo n.º 6
0
        //needed to avoid "Fields" nesting in collectionData
        public SearchEntityResult GetAsRawDictionary([NotNull] EntityMetadata entityMetadata, [NotNull] SearchRequestDto searchDto, Boolean fetchMaxRowstamp = false)
        {
            if (entityMetadata == null)
            {
                throw new ArgumentNullException("entityMetadata");
            }
            if (searchDto == null)
            {
                throw new ArgumentNullException("searchDto");
            }
            var query      = new EntityQueryBuilder().AllRows(entityMetadata, searchDto);
            var rows       = Query(entityMetadata, query, searchDto);
            var enumerable = rows as dynamic[] ?? rows.ToArray();

            Log.DebugFormat("returning {0} rows", enumerable.Count());
            long?maxRowstamp = 0;

            IList <Dictionary <string, object> > list = new List <Dictionary <string, object> >();

            foreach (var row in enumerable)
            {
                var dict = (IDictionary <string, object>)row;
                var item = new Dictionary <string, object>();
                if (fetchMaxRowstamp)
                {
                    if (dict.ContainsKey(RowStampUtil.RowstampColumnName))
                    {
                        var rowstamp = RowStampUtil.Convert(dict[RowStampUtil.RowstampColumnName]);
                        if (rowstamp > maxRowstamp)
                        {
                            maxRowstamp = rowstamp;
                        }
                    }
                }

                foreach (var column in dict)
                {
                    item[FixKey(column.Key, entityMetadata)] = column.Value;
                }
                if (entityMetadata.Name == "relatedrecord")
                {
                    item["hmachash"] = AuthUtils.HmacShaEncode(item["relatedreckey"].ToString());
                }
                else if (entityMetadata.Name == "ticket" || entityMetadata.Name == "imac")
                {
                    item["hmachash"] = AuthUtils.HmacShaEncode(item["ticketid"].ToString());
                }
                else if (entityMetadata.IdFieldName != null && item.ContainsKey(entityMetadata.IdFieldName))
                {
                    //for compositions in general
                    item["hmachash"] = AuthUtils.HmacShaEncode(item[entityMetadata.IdFieldName].ToString());
                }

                list.Add(item);
            }

            return(new SearchEntityResult {
                MaxRowstampReturned = maxRowstamp == 0 ? null : maxRowstamp,
                ResultList = list,
                IdFieldName = entityMetadata.IdFieldName
            });
        }