예제 #1
0
        public int saveQueryData(QueryDataSet model)
        {
            QueryData query = new QueryData();

            query.Name                 = model.QueryName;
            query.Description          = model.QueryDescription;
            query.QueryText            = model.QueryText;
            query.Archived             = false;
            query.UserIDCreatedBy      = SessionProxy.UserId;
            query.UserIDLastModifiedBy = SessionProxy.UserId;
            query.CreatedDate          = DateTime.Now;
            query.LastModified         = DateTime.Now;
            _db.QueryDatas.Add(query);
            _db.SaveChanges();
            return(0);
        }
예제 #2
0
        /// <summary>
        /// Evaluates the given lambda as if it were called on the given entity. Used for evaluating orderby expressions for the last result in a feed.
        /// </summary>
        /// <param name="entity">The entity to evaluate the lambda for.</param>
        /// <param name="lamda">The lamda to evaluate.</param>
        /// <returns>The result of evaluating the lamda for the given entity.</returns>
        private object EvaluateLambdaForEntity(QueryStructuralValue entity, LinqLambdaExpression lamda)
        {
            var expression = CommonQueryBuilder.Root("fakeSet", entity.Type.CreateCollectionType()).Select(lamda).Single();

            var fakeQueryDataSet = new QueryDataSet();

            fakeQueryDataSet.RootQueryData["fakeSet"] = entity.Type.CreateCollectionType().CreateCollectionWithValues(new[] { entity });

            QueryValue evaluated;

            using (this.ExpressionEvaluator.WithTemporaryDataSet(fakeQueryDataSet))
            {
                evaluated = this.ExpressionEvaluator.Evaluate(expression);
            }

            return(((QueryScalarValue)evaluated).Value);
        }
예제 #3
0
        public override int GetHashCode()
        {
            int hashcode = 157;

            unchecked {
                hashcode = (hashcode * 397) + Status.GetHashCode();
                hashcode = (hashcode * 397) + HasResultSet.GetHashCode();
                hashcode = (hashcode * 397) + IsAlign.GetHashCode();
                if (__isset.queryDataSet)
                {
                    hashcode = (hashcode * 397) + QueryDataSet.GetHashCode();
                }
                if (__isset.nonAlignQueryDataSet)
                {
                    hashcode = (hashcode * 397) + NonAlignQueryDataSet.GetHashCode();
                }
            }
            return(hashcode);
        }
        public override int GetHashCode()
        {
            int hashcode = 157;

            unchecked {
                hashcode = (hashcode * 397) + Status.GetHashCode();
                if (__isset.queryId)
                {
                    hashcode = (hashcode * 397) + QueryId.GetHashCode();
                }
                if (__isset.columns)
                {
                    hashcode = (hashcode * 397) + TCollections.GetHashCode(Columns);
                }
                if (__isset.operationType)
                {
                    hashcode = (hashcode * 397) + OperationType.GetHashCode();
                }
                if (__isset.ignoreTimeStamp)
                {
                    hashcode = (hashcode * 397) + IgnoreTimeStamp.GetHashCode();
                }
                if (__isset.dataTypeList)
                {
                    hashcode = (hashcode * 397) + TCollections.GetHashCode(DataTypeList);
                }
                if (__isset.queryDataSet)
                {
                    hashcode = (hashcode * 397) + QueryDataSet.GetHashCode();
                }
                if (__isset.nonAlignQueryDataSet)
                {
                    hashcode = (hashcode * 397) + NonAlignQueryDataSet.GetHashCode();
                }
                if (__isset.columnNameIndexMap)
                {
                    hashcode = (hashcode * 397) + TCollections.GetHashCode(ColumnNameIndexMap);
                }
            }
            return(hashcode);
        }
예제 #5
0
        /// <summary>
        /// Build a sub query data set from payload, but having enough information and correct order for evaluation.
        /// </summary>
        /// <param name="payload">The ODataPayloadElement converted from payload.</param>
        /// <returns>A sub query data set containing converted query value.</returns>
        private IQueryDataSet BuildQueryDataSet(ODataPayloadElement payload)
        {
            var dataSet = new QueryDataSet();

            var xmlBaseAnnotations = payload.Annotations.OfType <XmlBaseAnnotation>();

            var entityInstance = payload as EntityInstance;

            if (entityInstance != null)
            {
                // get QueryEntityType for entity instance. Notice that even we are expecting an anonymous type from projection, we still need to find out the 'original' entity type, since we need to build a query data set.
                var elementType = this.currentExpression.ExpressionType as QueryEntityType;
                if (elementType == null)
                {
                    var collectionType = this.currentExpression.ExpressionType as QueryCollectionType;
                    ExceptionUtilities.CheckObjectNotNull(collectionType, "Cannot cast expression type to QueryCollectionType.");

                    elementType = collectionType.ElementType as QueryEntityType;
                    if (elementType == null)
                    {
                        var anonymousType = collectionType.ElementType as QueryAnonymousStructuralType;
                        ExceptionUtilities.CheckArgumentNotNull(anonymousType, "It must be an anonymous type if it is not an entity type.");

                        // TODO: It may have problems if client side's entity types have diferent names with those on server side.
                        // A solution is implementing another query expression visitor, removing all the $select expression, and using the type from expression.ExpressionType.
                        elementType = this.GetQueryEntityTypeByFullTypeName(entityInstance.FullTypeName);
                    }
                }

                // build query value and store it in query data set.
                var entity     = this.BuildFromEntityInstance(entityInstance, elementType, xmlBaseAnnotations);
                var collection = QueryCollectionValue.Create(this.DefaultDataSet[elementType.EntitySet.Name].Type.ElementType, new List <QueryValue>()
                {
                    entity
                }, true);
                dataSet.RootQueryData.Add(elementType.EntitySet.Name, collection);
            }
            else
            {
                var entitySetInstance = payload as EntitySetInstance;
                ExceptionUtilities.CheckObjectNotNull(entitySetInstance, "Payload was neither a feed nor entity. Type was: {0}", payload.ElementType);

                var collectionType = this.currentExpression.ExpressionType as QueryCollectionType;
                ExceptionUtilities.CheckObjectNotNull(collectionType, "Cannot cast expression type to QueryCollectionType.");

                var elementType = collectionType.ElementType as QueryEntityType;
                if (elementType == null)
                {
                    var anonymousType = collectionType.ElementType as QueryAnonymousStructuralType;
                    ExceptionUtilities.CheckArgumentNotNull(anonymousType, "It must be an anonymous type if it is not an entity type.");

                    var title = entitySetInstance.Annotations.OfType <TitleAnnotation>().SingleOrDefault();
                    ExceptionUtilities.CheckObjectNotNull(title, "Cannot find title information from entity set instance.");

                    ExceptionUtilities.CheckObjectNotNull(title.Value, "Cannot get title value from entity set instance.");
                    QueryStructuralType rootDataType;
                    this.QueryRepository.RootDataTypes.TryGetValue(title.Value, out rootDataType);
                    if (rootDataType == null)
                    {
                        this.RootDataTypesDerivedTypes().TryGetValue(title.Value, out rootDataType);
                    }

                    ExceptionUtilities.CheckObjectNotNull(rootDataType, "Cannot find title value '{0}' in root datatypes", title.Value);
                    elementType = rootDataType as QueryEntityType;
                    ExceptionUtilities.CheckObjectNotNull(elementType, "Cannot find element type for entity set '{0}'.", title.Value);
                }

                var collection = this.BuildFromEntitySetInstance(entitySetInstance, elementType, xmlBaseAnnotations);
                dataSet.RootQueryData.Add(elementType.EntitySet.Name, collection);
            }

            return(dataSet);
        }
예제 #6
0
        public async Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
        {
            oprot.IncrementRecursionDepth();
            try
            {
                var struc = new TStruct("TSFetchResultsResp");
                await oprot.WriteStructBeginAsync(struc, cancellationToken);

                var field = new TField();
                field.Name = "status";
                field.Type = TType.Struct;
                field.ID   = 1;
                await oprot.WriteFieldBeginAsync(field, cancellationToken);

                await Status.WriteAsync(oprot, cancellationToken);

                await oprot.WriteFieldEndAsync(cancellationToken);

                field.Name = "hasResultSet";
                field.Type = TType.Bool;
                field.ID   = 2;
                await oprot.WriteFieldBeginAsync(field, cancellationToken);

                await oprot.WriteBoolAsync(HasResultSet, cancellationToken);

                await oprot.WriteFieldEndAsync(cancellationToken);

                field.Name = "isAlign";
                field.Type = TType.Bool;
                field.ID   = 3;
                await oprot.WriteFieldBeginAsync(field, cancellationToken);

                await oprot.WriteBoolAsync(IsAlign, cancellationToken);

                await oprot.WriteFieldEndAsync(cancellationToken);

                if (QueryDataSet != null && __isset.queryDataSet)
                {
                    field.Name = "queryDataSet";
                    field.Type = TType.Struct;
                    field.ID   = 4;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await QueryDataSet.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (NonAlignQueryDataSet != null && __isset.nonAlignQueryDataSet)
                {
                    field.Name = "nonAlignQueryDataSet";
                    field.Type = TType.Struct;
                    field.ID   = 5;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await NonAlignQueryDataSet.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                await oprot.WriteFieldStopAsync(cancellationToken);

                await oprot.WriteStructEndAsync(cancellationToken);
            }
            finally
            {
                oprot.DecrementRecursionDepth();
            }
        }
예제 #7
0
 public void putDataSetCallback(QueryResult result, QueryDataSet set)
 {
   //capture the dataset
 }
        public async Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
        {
            oprot.IncrementRecursionDepth();
            try
            {
                var struc = new TStruct("TSExecuteStatementResp");
                await oprot.WriteStructBeginAsync(struc, cancellationToken);

                var field = new TField();
                field.Name = "status";
                field.Type = TType.Struct;
                field.ID   = 1;
                await oprot.WriteFieldBeginAsync(field, cancellationToken);

                await Status.WriteAsync(oprot, cancellationToken);

                await oprot.WriteFieldEndAsync(cancellationToken);

                if (__isset.queryId)
                {
                    field.Name = "queryId";
                    field.Type = TType.I64;
                    field.ID   = 2;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await oprot.WriteI64Async(QueryId, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (Columns != null && __isset.columns)
                {
                    field.Name = "columns";
                    field.Type = TType.List;
                    field.ID   = 3;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    {
                        await oprot.WriteListBeginAsync(new TList(TType.String, Columns.Count), cancellationToken);

                        foreach (string _iter14 in Columns)
                        {
                            await oprot.WriteStringAsync(_iter14, cancellationToken);
                        }
                        await oprot.WriteListEndAsync(cancellationToken);
                    }
                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (OperationType != null && __isset.operationType)
                {
                    field.Name = "operationType";
                    field.Type = TType.String;
                    field.ID   = 4;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await oprot.WriteStringAsync(OperationType, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (__isset.ignoreTimeStamp)
                {
                    field.Name = "ignoreTimeStamp";
                    field.Type = TType.Bool;
                    field.ID   = 5;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await oprot.WriteBoolAsync(IgnoreTimeStamp, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (DataTypeList != null && __isset.dataTypeList)
                {
                    field.Name = "dataTypeList";
                    field.Type = TType.List;
                    field.ID   = 6;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    {
                        await oprot.WriteListBeginAsync(new TList(TType.String, DataTypeList.Count), cancellationToken);

                        foreach (string _iter15 in DataTypeList)
                        {
                            await oprot.WriteStringAsync(_iter15, cancellationToken);
                        }
                        await oprot.WriteListEndAsync(cancellationToken);
                    }
                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (QueryDataSet != null && __isset.queryDataSet)
                {
                    field.Name = "queryDataSet";
                    field.Type = TType.Struct;
                    field.ID   = 7;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await QueryDataSet.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (NonAlignQueryDataSet != null && __isset.nonAlignQueryDataSet)
                {
                    field.Name = "nonAlignQueryDataSet";
                    field.Type = TType.Struct;
                    field.ID   = 8;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await NonAlignQueryDataSet.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (ColumnNameIndexMap != null && __isset.columnNameIndexMap)
                {
                    field.Name = "columnNameIndexMap";
                    field.Type = TType.Map;
                    field.ID   = 9;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    {
                        await oprot.WriteMapBeginAsync(new TMap(TType.String, TType.I32, ColumnNameIndexMap.Count), cancellationToken);

                        foreach (string _iter16 in ColumnNameIndexMap.Keys)
                        {
                            await oprot.WriteStringAsync(_iter16, cancellationToken);

                            await oprot.WriteI32Async(ColumnNameIndexMap[_iter16], cancellationToken);
                        }
                        await oprot.WriteMapEndAsync(cancellationToken);
                    }
                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                await oprot.WriteFieldStopAsync(cancellationToken);

                await oprot.WriteStructEndAsync(cancellationToken);
            }
            finally
            {
                oprot.DecrementRecursionDepth();
            }
        }