public static FromExpressionInfo AnalyzeFromExpression (
        Expression fromExpression,
        ISqlPreparationStage stage,
        UniqueIdentifierGenerator generator,
        IMethodCallTransformerProvider provider,
        ISqlPreparationContext context,
        Func<ITableInfo, SqlTable> tableGenerator)
    {
      ArgumentUtility.CheckNotNull ("fromExpression", fromExpression);
      ArgumentUtility.CheckNotNull ("stage", stage);
      ArgumentUtility.CheckNotNull ("generator", generator);
      ArgumentUtility.CheckNotNull ("provider", provider);
      ArgumentUtility.CheckNotNull ("context", context);

      var visitor = new SqlPreparationFromExpressionVisitor (generator, stage, provider, context, tableGenerator);
      visitor.VisitExpression (fromExpression);
      if (visitor.FromExpressionInfo != null)
        return visitor.FromExpressionInfo.Value;

      var message = string.Format (
          "Error parsing expression '{0}'. Expressions of type '{1}' cannot be used as the SqlTables of a from clause.",
          FormattingExpressionTreeVisitor.Format (fromExpression),
          fromExpression.Type.Name);
      throw new NotSupportedException (message);
    }
 public void SetUp ()
 {
   _generator = new UniqueIdentifierGenerator ();
   _stage = new DefaultSqlPreparationStage (
       CompoundMethodCallTransformerProvider.CreateDefault(), ResultOperatorHandlerRegistry.CreateDefault(), _generator);
   _handler = new AverageResultOperatorHandler ();
   _context = SqlStatementModelObjectMother.CreateSqlPreparationContext ();
 }
 public void SetUp ()
 {
   _stageMock = MockRepository.GenerateStrictMock<ISqlPreparationStage>();
   _generator = new UniqueIdentifierGenerator();
   _context = SqlStatementModelObjectMother.CreateSqlPreparationContext();
   _methodCallTransformerProvider = CompoundMethodCallTransformerProvider.CreateDefault();
   _visitor = new TestableSqlPreparationFromExpressionVisitor (
       _generator, _stageMock, _methodCallTransformerProvider, _context, info => new SqlTable (info, JoinSemantics.Inner));
 }
 public TestableSqlPreparationFromExpressionVisitor (
     UniqueIdentifierGenerator generator,
     ISqlPreparationStage stage,
     IMethodCallTransformerProvider provider,
     ISqlPreparationContext context,
     Func<ITableInfo, SqlTable> tableGenerator)
     : base (generator, stage, provider, context, tableGenerator)
 {
 }
 public void SetUp ()
 {
   _stageMock = MockRepository.GenerateMock<ISqlPreparationStage> ();
   _generator = new UniqueIdentifierGenerator ();
   _handler = new CastResultOperatorHandler ();
   _sqlStatementBuilder = new SqlStatementBuilder (SqlStatementModelObjectMother.CreateSqlStatement ())
   {
     DataInfo = new StreamedSequenceInfo (typeof (Cook[]), Expression.Constant (new Cook ()))
   };
   _context = SqlStatementModelObjectMother.CreateSqlPreparationContext ();
 }
 public void SetUp ()
 {
   _handler = new TestableResultOperatorHandler();
   _resultOperator = new TestChoiceResultOperator (false);
   _statementBuilder = new SqlStatementBuilder();
   _statementBuilder.SelectProjection = Expression.Constant ("select");
   _statementBuilder.DataInfo = new StreamedSequenceInfo (typeof (Cook[]), Expression.Constant (new Cook()));
   _generator = new UniqueIdentifierGenerator();
   _stageMock = MockRepository.GenerateMock<ISqlPreparationStage>();
   _context = SqlStatementModelObjectMother.CreateSqlPreparationContext ();
 }
 public void SetUp ()
 {
   _generator = new UniqueIdentifierGenerator ();
   _stage = new DefaultSqlPreparationStage (new CompoundMethodCallTransformerProvider (), new ResultOperatorHandlerRegistry (), _generator);
   _handler = new SumResultOperatorHandler ();
   _sqlStatementBuilder = new SqlStatementBuilder (SqlStatementModelObjectMother.CreateSqlStatement ())
   {
     DataInfo = new StreamedSequenceInfo (typeof (int[]), Expression.Constant (5))
   };
   _context = SqlStatementModelObjectMother.CreateSqlPreparationContext ();
 }
    protected SqlPreparationExpressionVisitor (
        ISqlPreparationContext context, ISqlPreparationStage stage, IMethodCallTransformerProvider provider)
    {
      ArgumentUtility.CheckNotNull ("context", context);
      ArgumentUtility.CheckNotNull ("stage", stage);
      ArgumentUtility.CheckNotNull ("provider", provider);

      _context = context;
      _stage = stage;
      _methodCallTransformerProvider = provider;
    }
    public SqlPreparationSubStatementTableFactory (
        ISqlPreparationStage stage, 
        ISqlPreparationContext context, 
        UniqueIdentifierGenerator uniqueIdentifierGenerator)
    {
      ArgumentUtility.CheckNotNull ("stage", stage);
      ArgumentUtility.CheckNotNull ("context", context);

      _stage = stage;
      _uniqueIdentifierGenerator = uniqueIdentifierGenerator;
      _context = context;
    }
 protected SqlPreparationFromExpressionVisitor (
     UniqueIdentifierGenerator generator,
     ISqlPreparationStage stage,
     IMethodCallTransformerProvider provider,
     ISqlPreparationContext context,
     Func<ITableInfo, SqlTable> tableGenerator)
     : base (context, stage, provider)
 {
   _generator = generator;
   FromExpressionInfo = null;
   _tableGenerator = tableGenerator;
 }
    public static Expression TranslateExpression (
        Expression expression,
        ISqlPreparationContext context,
        ISqlPreparationStage stage,
        IMethodCallTransformerProvider provider)
    {
      ArgumentUtility.CheckNotNull ("expression", expression);
      ArgumentUtility.CheckNotNull ("context", context);
      ArgumentUtility.CheckNotNull ("stage", stage);
      ArgumentUtility.CheckNotNull ("provider", provider);

      var visitor = new SqlPreparationExpressionVisitor (context, stage, provider);
      var result = visitor.VisitExpression (expression);
      return result;
    }
    public void SetUp ()
    {
      _stageMock = MockRepository.GenerateStrictMock<ISqlPreparationStage>();
      _context = SqlStatementModelObjectMother.CreateSqlPreparationContext ();
      _generator = new UniqueIdentifierGenerator();
      _factory = new SqlPreparationSubStatementTableFactory (_stageMock, _context, _generator);

      var builderForStatementWithOrderings = new SqlStatementBuilder (SqlStatementModelObjectMother.CreateSqlStatementWithCook ())
      {
        Orderings = {
            new Ordering (Expression.Constant ("order1"), OrderingDirection.Desc),
            new Ordering (Expression.Constant ("order2"), OrderingDirection.Asc),
        }
      };
      _statementWithOrderings = builderForStatementWithOrderings.GetSqlStatement ();
    }
    public void SetUp ()
    {
      _generator = new UniqueIdentifierGenerator();
      _context = SqlStatementModelObjectMother.CreateSqlPreparationContext();
      _defaultStage = new DefaultSqlPreparationStage (
          CompoundMethodCallTransformerProvider.CreateDefault(), ResultOperatorHandlerRegistry.CreateDefault(), _generator);

      _mainFromClause = ExpressionHelper.CreateMainFromClause<Cook>();
      _selectClause = ExpressionHelper.CreateSelectClause (_mainFromClause);
      _orderByClause = ExpressionHelper.CreateOrderByClause();
      _queryModel = new QueryModel (_mainFromClause, _selectClause);

      _stageMock = MockRepository.GenerateStrictMock<ISqlPreparationStage>();
      _visitor = new TestableSqlPreparationQueryModelVisitor (_context, _stageMock);
      _visitorPartialMock = MockRepository.GeneratePartialMock<TestableSqlPreparationQueryModelVisitor> (_context, _stageMock);
    }
    public static SqlStatement TransformQueryModel (
        QueryModel queryModel,
        ISqlPreparationContext parentPreparationContext,
        ISqlPreparationStage stage,
        UniqueIdentifierGenerator generator,
        ResultOperatorHandlerRegistry resultOperatorHandlerRegistry)
    {
      ArgumentUtility.CheckNotNull ("queryModel", queryModel);
      ArgumentUtility.CheckNotNull ("stage", stage);
      ArgumentUtility.CheckNotNull ("generator", generator);
      ArgumentUtility.CheckNotNull ("resultOperatorHandlerRegistry", resultOperatorHandlerRegistry);

      var visitor = new SqlPreparationQueryModelVisitor (parentPreparationContext, stage, generator, resultOperatorHandlerRegistry);
      queryModel.Accept (visitor);

      return visitor.GetSqlStatement();
    }
    protected SqlPreparationQueryModelVisitor (
        ISqlPreparationContext parentContext,
        ISqlPreparationStage stage,
        UniqueIdentifierGenerator generator,
        ResultOperatorHandlerRegistry resultOperatorHandlerRegistry)
    {
      ArgumentUtility.CheckNotNull ("stage", stage);
      ArgumentUtility.CheckNotNull ("generator", generator);
      ArgumentUtility.CheckNotNull ("resultOperatorHandlerRegistry", resultOperatorHandlerRegistry);

      _stage = stage;
      _generator = generator;
      _resultOperatorHandlerRegistry = resultOperatorHandlerRegistry;

      _sqlStatementBuilder = new SqlStatementBuilder();
      _context = new SqlPreparationContext (parentContext, _sqlStatementBuilder);
    }
    public void SetUp ()
    {
      _stageMock = MockRepository.GenerateMock<ISqlPreparationStage> ();
      _generator = new UniqueIdentifierGenerator ();
      _context = SqlStatementModelObjectMother.CreateSqlPreparationContext ();

      _handler = new SkipResultOperatorHandler ();
      
      _sqlTable = new SqlTable (new UnresolvedTableInfo (typeof (Cook)), JoinSemantics.Inner);
      _selectProjection = new SqlTableReferenceExpression (_sqlTable);

      _ordering = new Ordering (Expression.Constant (7), OrderingDirection.Asc);
      _sqlStatementBuilder = new SqlStatementBuilder
      {
        SelectProjection = _selectProjection,
        DataInfo = new StreamedSequenceInfo (typeof (Cook[]), Expression.Constant (new Cook ())),
        SqlTables = { _sqlTable },
      };

      _tupleCtor = _tupleCtor = typeof (KeyValuePair<Cook, int>).GetConstructor (new[] { typeof (Cook), typeof (int) });
    }
        private void IncludeRowNumberInSelectProjection(SqlStatementBuilder sqlStatementBuilder, ISqlPreparationStage stage, ISqlPreparationContext context)
        {
            var rowNumberExpression = CreateRowNumberExpression(sqlStatementBuilder);

            var        tupleType           = typeof(KeyValuePair <,>).MakeGenericType(sqlStatementBuilder.SelectProjection.Type, rowNumberExpression.Type);
            Expression newSelectProjection = Expression.New(
                tupleType.GetConstructors()[0],
                new[] { sqlStatementBuilder.SelectProjection, rowNumberExpression },
                new[] { tupleType.GetMethod("get_Key"), tupleType.GetMethod("get_Value") });

            sqlStatementBuilder.SelectProjection = stage.PrepareSelectExpression(newSelectProjection, context);
        }
 public TestableSqlPreparationQueryModelVisitor(ISqlPreparationContext context, ISqlPreparationStage stage, UniqueIdentifierGenerator generator, ResultOperatorHandlerRegistry registry)
     : base(context, stage, generator, registry)
 {
 }
Exemplo n.º 19
0
        public override void HandleResultOperator(ContainsResultOperator resultOperator, SqlStatementBuilder sqlStatementBuilder, UniqueIdentifierGenerator generator, ISqlPreparationStage stage, ISqlPreparationContext context)
        {
            ArgumentUtility.CheckNotNull("resultOperator", resultOperator);
            ArgumentUtility.CheckNotNull("sqlStatementBuilder", sqlStatementBuilder);
            ArgumentUtility.CheckNotNull("generator", generator);
            ArgumentUtility.CheckNotNull("stage", stage);
            ArgumentUtility.CheckNotNull("context", context);

            var dataInfo = sqlStatementBuilder.DataInfo;
            var preparedItemExpression = stage.PrepareResultOperatorItemExpression(resultOperator.Item, context);
            // No name required for the select projection inside of an IN expression
            // (If the expression is a constant collection, a name would even be fatal.)
            var sqlSubStatement        = sqlStatementBuilder.GetStatementAndResetBuilder();
            var subStatementExpression = sqlSubStatement.CreateExpression();

            sqlStatementBuilder.SelectProjection = new SqlInExpression(preparedItemExpression, subStatementExpression);

            UpdateDataInfo(resultOperator, sqlStatementBuilder, dataInfo);
        }
Exemplo n.º 20
0
 public override void HandleResultOperator(TestChoiceResultOperator resultOperator, SqlStatementBuilder sqlStatementBuilder, UniqueIdentifierGenerator generator, ISqlPreparationStage stage, ISqlPreparationContext context)
 {
     throw new NotImplementedException();
 }
 public abstract void HandleResultOperator(
     T resultOperator,
     SqlStatementBuilder sqlStatementBuilder,
     UniqueIdentifierGenerator generator,
     ISqlPreparationStage stage,
     ISqlPreparationContext context);
 public TestableSqlPreparationExpressionVisitorTest (ISqlPreparationContext context, ISqlPreparationStage stage, IMethodCallTransformerProvider provider)
     : base (context, stage, provider)
 {
 }
 public TestableSqlPreparationQueryModelVisitor(ISqlPreparationContext context, ISqlPreparationStage stage)
     : base(context, stage, new UniqueIdentifierGenerator(), ResultOperatorHandlerRegistry.CreateDefault())
 {
 }
 public TestableSqlPreparationQueryModelVisitor (ISqlPreparationContext context, ISqlPreparationStage stage,UniqueIdentifierGenerator generator, ResultOperatorHandlerRegistry registry)
   : base (context, stage, generator, registry)
 {
 }
 public TestableSqlPreparationQueryModelVisitor (ISqlPreparationContext context, ISqlPreparationStage stage)
     : base (context, stage, new UniqueIdentifierGenerator(), ResultOperatorHandlerRegistry.CreateDefault())
 {
 }
Exemplo n.º 26
0
        public override void HandleResultOperator(AnyResultOperator resultOperator, SqlStatementBuilder sqlStatementBuilder, UniqueIdentifierGenerator generator, ISqlPreparationStage stage, ISqlPreparationContext context)
        {
            ArgumentUtility.CheckNotNull("resultOperator", resultOperator);
            ArgumentUtility.CheckNotNull("sqlStatementBuilder", sqlStatementBuilder);
            ArgumentUtility.CheckNotNull("generator", generator);
            ArgumentUtility.CheckNotNull("stage", stage);
            ArgumentUtility.CheckNotNull("context", context);

            // No name required for the select projection inside of an EXISTS expression
            var sqlSubStatement        = sqlStatementBuilder.GetStatementAndResetBuilder();
            var subStatementExpression = new SqlSubStatementExpression(sqlSubStatement);

            var sqlExistsExpression = new SqlExistsExpression(subStatementExpression);

            sqlStatementBuilder.SelectProjection = stage.PrepareSelectExpression(sqlExistsExpression, context);
            UpdateDataInfo(resultOperator, sqlStatementBuilder, sqlSubStatement.DataInfo);
        }