Example #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="queryContract"></param>
 void VerifyQueryContract(IDbQueryContract queryContract)
 {
     if (null == queryContract)
     {
         throw new ArgumentNullException(string.Format("The attribute '{0}' is not declared in the previous section.", typeof(DbQueryOperationContractAttribute).FullName));
     }
 }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="descriptor"></param>
        /// <param name="queryContract"></param>
        /// <returns></returns>
        public IDbQueryContract CreateDbQueryContract(IEntryDescriptor descriptor, IDbQueryContract queryContract)
        {
            var _contractBuilder = new DbQueryContractBuilder();

            _contractBuilder.Name                    = string.IsNullOrEmpty(queryContract.Name) ? descriptor.Name : queryContract.Name;
            _contractBuilder.Schema                  = string.IsNullOrEmpty(queryContract.Schema) ? DbQueryContract.QUERYTEXT_SCHEMA : queryContract.Schema;
            _contractBuilder.Namespace               = descriptor.Namespace;
            _contractBuilder.Abbreviation            = queryContract.Abbreviation;
            _contractBuilder.QueryAction             = QueryAction;
            _contractBuilder.IsElementContainable    = descriptor.IsListType;
            _contractBuilder.OmitsAbbreviationNaming = queryContract.OmitsAbbreviationNaming;

            return(_contractBuilder.GetDbQueryContract());
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="queryContext"></param>
        /// <param name="queryContract"></param>
        void InitializeRequiredProperties(IDbQueryContext queryContext, IDbQueryContract queryContract)
        {
            if (null == queryContext)
            {
                throw new ArgumentNullException("queryContext");
            }

            if (null == queryContract)
            {
                throw new ArgumentNullException("queryContract");
            }

            queryContext.QueryText     = queryContract.QueryText;
            queryContext.QueryBehavior = queryContract.QueryBehavior;
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="operationContext"></param>
        /// <param name="queryContract"></param>
        void InitializeRequiredProperties(DbQueryOperationContext operationContext, IDbQueryContract queryContract)
        {
            if (null == operationContext)
            {
                throw new ArgumentNullException("operationContext");
            }

            if (null == queryContract)
            {
                throw new ArgumentNullException("queryContract");
            }

            operationContext.ExecutionTimeout    = queryContract.ExecutionTimeout;
            operationContext.RequiresTransaction = queryContract.RequiresTransaction;
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="operatingSession"></param>
        /// <param name="entity"></param>
        /// <param name="memberDescriptor"></param>
        /// <param name="serviceContract"></param>
        /// <param name="queryContract"></param>
        protected virtual void ExecuteQueryImpl(DbQueryOperatingSession operatingSession, object entity, IEntryDescriptor memberDescriptor, IDataServiceContract serviceContract, IDbQueryContract queryContract)
        {
            var _queryContract = queryContract ?? operatingSession.GetDbQueryContract(memberDescriptor);

            InitializeRequiredProperties(operatingSession.OperationContext, _queryContract);

            var _queryContext = operatingSession.CreateDbQueryContext(serviceContract);

            InitializeRequiredProperties(_queryContext, _queryContract);

            var _parameterMapper   = operatingSession.CreateDbQueryParameterMapper(memberDescriptor);
            var _operationExecutor = operatingSession.CreateDbQueryOperationExecutor(memberDescriptor);
            var _propertyValidator = operatingSession.CreateDbQueryPropertyValidator(memberDescriptor);

            _propertyValidator.Validate(entity);

            _parameterMapper.Map(_queryContext, entity);

            _operationExecutor.Execute(entity, _queryContext);

            var _queryResult = _queryContext.Execute();

            if (null != _queryResult && _queryResult.HasResult)
            {
                var _resultMapper = operatingSession.CreateDbQueryResultMapper(memberDescriptor);

                _resultMapper.Map(entity, _queryResult);
            }
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="entity"></param>
        /// <param name="queryAction"></param>
        /// <param name="serviceContract"></param>
        /// <param name="queryContract"></param>
        /// <returns></returns>
        protected OperationResult <TEntity> ExecuteQuery <TEntity>(TEntity entity, DbQueryActions queryAction, IDataServiceContract serviceContract, IDbQueryContract queryContract)
            where TEntity : class
        {
            using (var _operationContext = new DbQueryOperationContext())
            {
                if (!IsExceptionalType(entity))
                {
                    var _memberDescriptor = _operationContext.DescriptorManager.GetDescriptor(entity);
                    var _serviceContract  = serviceContract ?? _memberDescriptor.ServiceContract;
                    var _operationSession = _operationContext.CreateSession(_serviceContract, queryAction);

                    _operationSession.Open();

                    ExecuteQueryImpl(_operationSession, entity, _memberDescriptor, _serviceContract, queryContract);

                    _operationSession.Close();
                }
                else
                {
                    var _entities = entity as IList;

                    for (var i = 0; i < _entities.Count; i++)
                    {
                        if (!_operationContext.HasErrors)
                        {
                            var _memberDescriptor = _operationContext.DescriptorManager.GetDescriptor(_entities[i]);
                            var _serviceContract  = serviceContract ?? _memberDescriptor.ServiceContract;
                            var _operationSession = _operationContext.CreateSession(_serviceContract, queryAction);

                            _operationSession.Open();

                            ExecuteQueryImpl(_operationSession, _entities[i], _memberDescriptor, _serviceContract, queryContract);

                            _operationSession.Close();

                            continue;
                        }

                        break;
                    }
                }

                if (_operationContext.HasErrors)
                {
                    return(new OperationResult <TEntity>(entity, _operationContext.Errors));
                }
            }

            return(new OperationResult <TEntity>(entity));
        }