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); }
private SubStatementWithRowNumber CreateSubStatementWithRowNumber( SqlStatementBuilder sqlStatementBuilder, UniqueIdentifierGenerator generator, ISqlPreparationStage stage, ISqlPreparationContext context) { var originalSelectProjection = sqlStatementBuilder.SelectProjection; IncludeRowNumberInSelectProjection(sqlStatementBuilder, stage, context); // Orderings are not allowed in SQL substatements unless a TOP expression is present if (sqlStatementBuilder.TopExpression == null) { sqlStatementBuilder.Orderings.Clear(); } sqlStatementBuilder.RecalculateDataInfo(originalSelectProjection); // No NamedExpression required here because the row number tuple's items already have named members var newSqlStatement = sqlStatementBuilder.GetStatementAndResetBuilder(); var tableInfo = new ResolvedSubStatementTableInfo(generator.GetUniqueIdentifier("q"), newSqlStatement); var sqlTable = new SqlTable(tableInfo, JoinSemantics.Inner); var originalProjectionSelector = Expression.MakeMemberAccess( new SqlTableReferenceExpression(sqlTable), newSqlStatement.SelectProjection.Type.GetProperty("Key")); var rowNumberSelector = Expression.MakeMemberAccess( new SqlTableReferenceExpression(sqlTable), newSqlStatement.SelectProjection.Type.GetProperty("Value")); return(new SubStatementWithRowNumber(sqlTable, originalProjectionSelector, rowNumberSelector)); }
public static Expression ResolveExpression ( Expression expression, IMappingResolver resolver, IMappingResolutionStage stage, IMappingResolutionContext context, UniqueIdentifierGenerator generator) { ArgumentUtility.CheckNotNull ("expression", expression); ArgumentUtility.CheckNotNull ("resolver", resolver); ArgumentUtility.CheckNotNull ("stage", stage); ArgumentUtility.CheckNotNull ("context", context); ArgumentUtility.CheckNotNull ("generator", generator); var entityIdentityResolver = new EntityIdentityResolver (stage, resolver, context); var comparisonSplitter = new CompoundExpressionComparisonSplitter(); var namedExpressionCombiner = new NamedExpressionCombiner (context); var groupAggregateSimplifier = new GroupAggregateSimplifier (stage, context); var visitor1 = new ResolvingExpressionVisitor ( resolver, stage, context, generator, entityIdentityResolver, comparisonSplitter, namedExpressionCombiner, groupAggregateSimplifier, false); var result1 = visitor1.VisitExpression (expression); var visitor2 = new ResolvingExpressionVisitor ( resolver, stage, context, generator, entityIdentityResolver, comparisonSplitter, namedExpressionCombiner, groupAggregateSimplifier, true); var result2 = visitor2.VisitExpression (result1); return result2; }
private static void AppendCreateTableScript(StringBuilder sb, Type type) { var mappingResolver = new MappingResolverStub(); var generator = new UniqueIdentifierGenerator(); var tableInfo = (ResolvedSimpleTableInfo)mappingResolver.ResolveTableInfo(new UnresolvedTableInfo(type), generator); var entity = mappingResolver.ResolveSimpleTableInfo(tableInfo, generator); var columnDeclarations = from c in entity.Columns let sqlTypeName = GetColumnType(c) select string.Format("[{0}] {1}", c.ColumnName, sqlTypeName); var primaryKeyColumns = entity.Columns.Where(c => c.IsPrimaryKey).Select(c => c.ColumnName).ToArray(); string primaryKeyConstraint = ""; if (primaryKeyColumns.Length > 0) { primaryKeyConstraint = string.Format( " CONSTRAINT PK_{0} PRIMARY KEY ({1})", tableInfo.TableName.Replace(".", "_"), string.Join(",", primaryKeyColumns)); } sb.AppendFormat( "CREATE TABLE [{0}]{1}({1}{2}{1} {3})", tableInfo.TableName, Environment.NewLine, string.Join("," + Environment.NewLine, columnDeclarations.Select(c => " " + c)), primaryKeyConstraint); sb.AppendLine(); }
public static Expression ResolveExpression( Expression expression, IMappingResolver resolver, IMappingResolutionStage stage, IMappingResolutionContext context, UniqueIdentifierGenerator generator) { ArgumentUtility.CheckNotNull("expression", expression); ArgumentUtility.CheckNotNull("resolver", resolver); ArgumentUtility.CheckNotNull("stage", stage); ArgumentUtility.CheckNotNull("context", context); ArgumentUtility.CheckNotNull("generator", generator); var entityIdentityResolver = new EntityIdentityResolver(stage, resolver, context); var comparisonSplitter = new CompoundExpressionComparisonSplitter(); var namedExpressionCombiner = new NamedExpressionCombiner(context); var groupAggregateSimplifier = new GroupAggregateSimplifier(stage, context); var visitor1 = new ResolvingExpressionVisitor( resolver, stage, context, generator, entityIdentityResolver, comparisonSplitter, namedExpressionCombiner, groupAggregateSimplifier, false); var result1 = visitor1.Visit(expression); var visitor2 = new ResolvingExpressionVisitor( resolver, stage, context, generator, entityIdentityResolver, comparisonSplitter, namedExpressionCombiner, groupAggregateSimplifier, true); var result2 = visitor2.Visit(result1); return(result2); }
public void SetUp() { _generator = new UniqueIdentifierGenerator(); _mappingResolver = new MappingResolver (new AttributeMappingSource().GetModel (typeof (DataContextTestClass))); _unmappedInfo = _unmappedType.GetProperty ("GUID"); new AttributeMappingSource().GetModel (typeof (DataContextTestClass)); }
public override void HandleResultOperator( TakeResultOperator resultOperator, SqlStatementBuilder sqlStatementBuilder, UniqueIdentifierGenerator generator, ISqlPreparationStage stage, ISqlPreparationContext context) { EnsureNoTopExpression(sqlStatementBuilder, generator, stage, context); EnsureNoGroupExpression(sqlStatementBuilder, generator, stage, context); UpdateDataInfo(resultOperator, sqlStatementBuilder, sqlStatementBuilder.DataInfo); var preparedTopExpression = stage.PrepareTopExpression(resultOperator.Count, context); if (sqlStatementBuilder.RowNumberSelector != null) { var whereCondition = Expression.LessThanOrEqual( sqlStatementBuilder.RowNumberSelector, Expression.Add(sqlStatementBuilder.CurrentRowNumberOffset, preparedTopExpression)); sqlStatementBuilder.AddWhereCondition(whereCondition); } else { var topExpressionAsConstantExpression = preparedTopExpression as ConstantExpression; if (topExpressionAsConstantExpression != null) { sqlStatementBuilder.TopExpression = new SqlLiteralExpression((int)topExpressionAsConstantExpression.Value); } else { sqlStatementBuilder.TopExpression = preparedTopExpression; } } }
public void SetUp() { _generator = new UniqueIdentifierGenerator(); _mappingResolver = new MappingResolver(new AttributeMappingSource().GetModel(typeof(DataContextTestClass))); _unmappedInfo = _unmappedType.GetProperty("GUID"); new AttributeMappingSource().GetModel(typeof(DataContextTestClass)); }
public override void HandleResultOperator( GroupResultOperator 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); EnsureNoTopExpression(sqlStatementBuilder, generator, stage, context); EnsureNoGroupExpression(sqlStatementBuilder, generator, stage, context); EnsureNoDistinctQuery(sqlStatementBuilder, generator, stage, context); UpdateDataInfo(resultOperator, sqlStatementBuilder, sqlStatementBuilder.DataInfo); var preparedKeySelector = stage.PrepareResultOperatorItemExpression(resultOperator.KeySelector, context); preparedKeySelector = HandlePotentialConstantExpression(preparedKeySelector); preparedKeySelector = HandlePotentialSubStatementExpression(preparedKeySelector, sqlStatementBuilder, generator); var preparedElementSelector = stage.PrepareResultOperatorItemExpression(resultOperator.ElementSelector, context); sqlStatementBuilder.GroupByExpression = preparedKeySelector; sqlStatementBuilder.SelectProjection = SqlGroupingSelectExpression.CreateWithNames(preparedKeySelector, preparedElementSelector); }
private SqlCommandData GenerateSqlCommand(QueryModel queryModel) { ISqlPreparationContext preparationContext = new SqlPreparationContext(new SqlStatementBuilder()); IMappingResolutionContext mappingResolutionContext = new MappingResolutionContext(); var generator = new UniqueIdentifierGenerator(); var preparationStage = new DefaultSqlPreparationStage(_methodCallTransformerProvider, _resultOperatorHandlerRegistry, generator); var preparedStatement = preparationStage.PrepareSqlStatement(queryModel, preparationContext); var resolutionStage = new DefaultMappingResolutionStage(_mappingResolver, generator); var resolvedStatement = resolutionStage.ResolveSqlStatement(preparedStatement, mappingResolutionContext); var builder = new SqlCommandBuilder(); var generationStage = new DefaultSqlGenerationStage(); generationStage.GenerateTextForOuterSqlStatement(builder, resolvedStatement); var command = builder.GetCommand(); if (_showQuery) { Console.WriteLine(command.CommandText); Console.WriteLine(string.Join(", ", command.Parameters.Select(p => p.Name + "=" + p.Value))); Console.WriteLine(command.GetInMemoryProjection <object>()); } return(command); }
protected ResolvingExpressionVisitor( IMappingResolver resolver, IMappingResolutionStage stage, IMappingResolutionContext context, UniqueIdentifierGenerator generator, IEntityIdentityResolver entityIdentityResolver, ICompoundExpressionComparisonSplitter compoundComparisonSplitter, INamedExpressionCombiner namedExpressionCombiner, IGroupAggregateSimplifier groupAggregateSimplifier, bool resolveEntityRefMemberExpressions) { ArgumentUtility.CheckNotNull("resolver", resolver); ArgumentUtility.CheckNotNull("stage", stage); ArgumentUtility.CheckNotNull("context", context); ArgumentUtility.CheckNotNull("generator", generator); ArgumentUtility.CheckNotNull("entityIdentityResolver", entityIdentityResolver); ArgumentUtility.CheckNotNull("compoundComparisonSplitter", compoundComparisonSplitter); ArgumentUtility.CheckNotNull("namedExpressionCombiner", namedExpressionCombiner); ArgumentUtility.CheckNotNull("groupAggregateSimplifier", groupAggregateSimplifier); _resolver = resolver; _stage = stage; _context = context; _generator = generator; _entityIdentityResolver = entityIdentityResolver; _compoundComparisonSplitter = compoundComparisonSplitter; _namedExpressionCombiner = namedExpressionCombiner; _groupAggregateSimplifier = groupAggregateSimplifier; _resolveEntityRefMemberExpressions = resolveEntityRefMemberExpressions; }
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 override void HandleResultOperator( T 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); EnsureNoTopExpression(sqlStatementBuilder, generator, stage, context); EnsureNoGroupExpression(sqlStatementBuilder, generator, stage, context); EnsureNoDistinctQuery(sqlStatementBuilder, generator, stage, context); UpdateDataInfo(resultOperator, sqlStatementBuilder, sqlStatementBuilder.DataInfo); sqlStatementBuilder.Orderings.Clear(); sqlStatementBuilder.SelectProjection = new AggregationExpression( sqlStatementBuilder.DataInfo.DataType, sqlStatementBuilder.SelectProjection, AggregationModifier); }
public void SetUp () { _stageMock = MockRepository.GenerateStrictMock<IMappingResolutionStage>(); _resolverMock = MockRepository.GenerateMock<IMappingResolver>(); _mappingResolutionContext = new MappingResolutionContext(); _generator = new UniqueIdentifierGenerator(); _groupAggregateSimplifier = MockRepository.GenerateStrictMock<IGroupAggregateSimplifier> (); }
public void SetUp () { _generator = new UniqueIdentifierGenerator (); _stage = new DefaultSqlPreparationStage ( CompoundMethodCallTransformerProvider.CreateDefault(), ResultOperatorHandlerRegistry.CreateDefault(), _generator); _handler = new AverageResultOperatorHandler (); _context = SqlStatementModelObjectMother.CreateSqlPreparationContext (); }
public DefaultMappingResolutionStage(IMappingResolver resolver, UniqueIdentifierGenerator uniqueIdentifierGenerator) { ArgumentUtility.CheckNotNull("resolver", resolver); ArgumentUtility.CheckNotNull("uniqueIdentifierGenerator", uniqueIdentifierGenerator); _uniqueIdentifierGenerator = uniqueIdentifierGenerator; _resolver = resolver; }
public void SetUp() { _resolverMock = MockRepository.GenerateStrictMock <IMappingResolver>(); _unresolvedJoinInfo = SqlStatementModelObjectMother.CreateUnresolvedJoinInfo_KitchenCook(); _generator = new UniqueIdentifierGenerator(); _stageMock = MockRepository.GenerateStrictMock <IMappingResolutionStage> (); _mappingResolutionContext = new MappingResolutionContext(); }
public new void EnsureNoSetOperations( SqlStatementBuilder sqlStatementBuilder, UniqueIdentifierGenerator generator, ISqlPreparationStage stage, ISqlPreparationContext context) { base.EnsureNoSetOperations(sqlStatementBuilder, generator, stage, context); }
public DefaultMappingResolutionStage (IMappingResolver resolver, UniqueIdentifierGenerator uniqueIdentifierGenerator) { ArgumentUtility.CheckNotNull ("resolver", resolver); ArgumentUtility.CheckNotNull ("uniqueIdentifierGenerator", uniqueIdentifierGenerator); _uniqueIdentifierGenerator = uniqueIdentifierGenerator; _resolver = resolver; }
public new void MoveCurrentStatementToSqlTable( SqlStatementBuilder sqlStatementBuilder, UniqueIdentifierGenerator generator, ISqlPreparationContext context, Func <ITableInfo, SqlTable> tableGenerator, ISqlPreparationStage stage) { base.MoveCurrentStatementToSqlTable(sqlStatementBuilder, generator, context, tableGenerator, stage); }
public void SetUp () { _resolverMock = MockRepository.GenerateStrictMock<IMappingResolver>(); _unresolvedJoinInfo = SqlStatementModelObjectMother.CreateUnresolvedJoinInfo_KitchenCook(); _generator = new UniqueIdentifierGenerator(); _stageMock = MockRepository.GenerateStrictMock<IMappingResolutionStage> (); _mappingResolutionContext = new MappingResolutionContext(); }
public void SetUp() { _stageMock = MockRepository.GenerateStrictMock <IMappingResolutionStage>(); _resolverMock = MockRepository.GenerateMock <IMappingResolver>(); _mappingResolutionContext = new MappingResolutionContext(); _generator = new UniqueIdentifierGenerator(); _groupAggregateSimplifier = MockRepository.GenerateStrictMock <IGroupAggregateSimplifier> (); }
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 IResolvedTableInfo ResolveTableInfo(UnresolvedTableInfo tableInfo, UniqueIdentifierGenerator generator) { ArgumentUtility.CheckNotNull("tableInfo", tableInfo); ArgumentUtility.CheckNotNull("generator", generator); var classDefinition = GetClassDefinition(tableInfo.ItemType); return(_storageSpecificExpressionResolver.ResolveTable(classDefinition, generator.GetUniqueIdentifier("t"))); }
public TestableSqlPreparationFromExpressionVisitor( UniqueIdentifierGenerator generator, ISqlPreparationStage stage, IMethodCallTransformerProvider provider, ISqlPreparationContext context, Func <ITableInfo, SqlTable> tableGenerator) : base(generator, stage, provider, context, tableGenerator) { }
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.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 void SetUp () { _stageMock = MockRepository.GenerateMock<IMappingResolutionStage>(); _resolverMock = MockRepository.GenerateMock<IMappingResolver>(); _unresolvedTableInfo = SqlStatementModelObjectMother.CreateUnresolvedTableInfo (typeof (Cook)); _resolvedTableInfo = SqlStatementModelObjectMother.CreateResolvedTableInfo (typeof (Cook)); _generator = new UniqueIdentifierGenerator(); _sqlStatement = SqlStatementModelObjectMother.CreateSqlStatement_Resolved (typeof (Cook)); _mappingResolutionContext = new MappingResolutionContext(); }
public void SetUp() { _stageMock = MockRepository.GenerateMock <IMappingResolutionStage>(); _resolverMock = MockRepository.GenerateMock <IMappingResolver>(); _unresolvedTableInfo = SqlStatementModelObjectMother.CreateUnresolvedTableInfo(typeof(Cook)); _resolvedTableInfo = SqlStatementModelObjectMother.CreateResolvedTableInfo(typeof(Cook)); _generator = new UniqueIdentifierGenerator(); _sqlStatement = SqlStatementModelObjectMother.CreateSqlStatement_Resolved(typeof(Cook)); _mappingResolutionContext = new MappingResolutionContext(); }
public void ShouldIncrementProperly() { _systemUnderTest = new UniqueIdentifierGenerator(Sequence.LowerCaseSequence(), "a"); _systemUnderTest.GetNext().Should().Be("b"); _systemUnderTest.GetNext().Should().Be("c"); _systemUnderTest.GetNext().Should().Be("d"); _systemUnderTest.GetNext().Should().Be("e"); _systemUnderTest.GetNext().Should().Be("f"); _systemUnderTest.GetNext().Should().Be("g"); }
public static IResolvedTableInfo ResolveTableInfo (ITableInfo tableInfo, IMappingResolver resolver, UniqueIdentifierGenerator generator, IMappingResolutionStage stage, IMappingResolutionContext context) { ArgumentUtility.CheckNotNull ("tableInfo", tableInfo); ArgumentUtility.CheckNotNull ("resolver", resolver); ArgumentUtility.CheckNotNull ("stage", stage); ArgumentUtility.CheckNotNull ("context", context); var visitor = new ResolvingTableInfoVisitor (resolver, generator, stage, context); return (IResolvedTableInfo) tableInfo.Accept (visitor); }
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 () { _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 (); }
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(); }
public virtual void SetUp() { _cooks = ExpressionHelper.CreateQueryable <Cook>(); _knives = ExpressionHelper.CreateQueryable <Knife> (); _kitchens = ExpressionHelper.CreateQueryable <Kitchen>(); _restaurants = ExpressionHelper.CreateQueryable <Restaurant>(); _chefs = ExpressionHelper.CreateQueryable <Chef>(); _companies = ExpressionHelper.CreateQueryable <Company>(); _generator = new UniqueIdentifierGenerator(); }
public Expression ResolveReference (SqlTableBase sqlTable, IMappingResolver mappingResolver, IMappingResolutionContext context, UniqueIdentifierGenerator generator) { ArgumentUtility.CheckNotNull ("sqlTable", sqlTable); ArgumentUtility.CheckNotNull ("mappingResolver", mappingResolver); ArgumentUtility.CheckNotNull ("context", context); ArgumentUtility.CheckNotNull ("generator", generator); var entity = (SqlEntityExpression) mappingResolver.ResolveSimpleTableInfo (this, generator); context.AddSqlEntityMapping (entity, sqlTable); return entity; }
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(); }
protected ResolvingTableInfoVisitor (IMappingResolver resolver, UniqueIdentifierGenerator generator, IMappingResolutionStage stage, IMappingResolutionContext context) { ArgumentUtility.CheckNotNull ("generator", generator); ArgumentUtility.CheckNotNull ("resolver", resolver); ArgumentUtility.CheckNotNull ("stage", stage); ArgumentUtility.CheckNotNull ("context", context); _resolver = resolver; _generator = generator; _stage= stage; _context = context; }
protected ResolvingTableInfoVisitor(IMappingResolver resolver, UniqueIdentifierGenerator generator, IMappingResolutionStage stage, IMappingResolutionContext context) { ArgumentUtility.CheckNotNull("generator", generator); ArgumentUtility.CheckNotNull("resolver", resolver); ArgumentUtility.CheckNotNull("stage", stage); ArgumentUtility.CheckNotNull("context", context); _resolver = resolver; _generator = generator; _stage = stage; _context = context; }
protected void EnsureNoDistinctQuery( SqlStatementBuilder sqlStatementBuilder, UniqueIdentifierGenerator generator, ISqlPreparationStage stage, ISqlPreparationContext context) { ArgumentUtility.CheckNotNull("sqlStatementBuilder", sqlStatementBuilder); ArgumentUtility.CheckNotNull("generator", generator); ArgumentUtility.CheckNotNull("stage", stage); if (sqlStatementBuilder.IsDistinctQuery) { MoveCurrentStatementToSqlTable(sqlStatementBuilder, generator, context, info => new SqlTable(info, JoinSemantics.Inner), stage); } }
public SqlPreparationSubStatementTableFactory( ISqlPreparationStage stage, ISqlPreparationContext context, UniqueIdentifierGenerator uniqueIdentifierGenerator) { ArgumentUtility.CheckNotNull("stage", stage); ArgumentUtility.CheckNotNull("context", context); _stage = stage; _uniqueIdentifierGenerator = uniqueIdentifierGenerator; _context = context; }
public void ShouldWorkWithCustomSequence() { var sequence = new Sequence(new [] { 'a', 'b' }); _systemUnderTest = new UniqueIdentifierGenerator(sequence, "a"); _systemUnderTest.GetNext().Should().Be("b"); _systemUnderTest.GetNext().Should().Be("aa"); _systemUnderTest.GetNext().Should().Be("ab"); _systemUnderTest.GetNext().Should().Be("ba"); _systemUnderTest.GetNext().Should().Be("bb"); _systemUnderTest.GetNext().Should().Be("aaa"); }
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 IResolvedTableInfo ResolveTableInfo(UnresolvedTableInfo tableInfo, UniqueIdentifierGenerator generator) { ArgumentUtility.CheckNotNull("tableInfo", tableInfo); ArgumentUtility.CheckNotNull("generator", generator); MetaTable table = GetMetaTable(tableInfo.ItemType); // TODO RM-3127: Refactor when re-linq supports schema names var tableName = table.TableName.StartsWith("dbo.") ? table.TableName.Substring(4) : table.TableName; return(new ResolvedSimpleTableInfo(tableInfo.ItemType, tableName, generator.GetUniqueIdentifier("t"))); }
public DefaultSqlPreparationStage ( IMethodCallTransformerProvider methodCallTransformerProvider, ResultOperatorHandlerRegistry resultOperatorHandlerRegistry, UniqueIdentifierGenerator uniqueIdentifierGenerator) { ArgumentUtility.CheckNotNull ("methodCallTransformerProvider", methodCallTransformerProvider); ArgumentUtility.CheckNotNull ("resultOperatorHandlerRegistry", resultOperatorHandlerRegistry); ArgumentUtility.CheckNotNull ("uniqueIdentifierGenerator", uniqueIdentifierGenerator); _methodCallTransformerProvider = methodCallTransformerProvider; _resultOperatorHandlerRegistry = resultOperatorHandlerRegistry; _uniqueIdentifierGenerator = uniqueIdentifierGenerator; }
public void SetUp () { _resolverMock = MockRepository.GenerateMock<IMappingResolver>(); _uniqueIdentifierGenerator = new UniqueIdentifierGenerator(); _unresolvedTableInfo = SqlStatementModelObjectMother.CreateUnresolvedTableInfo (typeof (Cook)); _sqlTable = SqlStatementModelObjectMother.CreateSqlTable (_unresolvedTableInfo); _fakeResolvedSimpleTableInfo = SqlStatementModelObjectMother.CreateResolvedTableInfo (typeof (Cook)); _stage = new DefaultMappingResolutionStage (_resolverMock, _uniqueIdentifierGenerator); _mappingResolutionContext = new MappingResolutionContext(); }
public void SetUp () { _stageMock = MockRepository.GenerateStrictMock<IMappingResolutionStage>(); _resolverMock = MockRepository.GenerateStrictMock<IMappingResolver>(); _sqlTable = SqlStatementModelObjectMother.CreateSqlTable_WithResolvedTableInfo (typeof (Cook)); _mappingResolutionContext = new MappingResolutionContext(); _generator = new UniqueIdentifierGenerator(); _entityIdentityResolverMock = MockRepository.GenerateStrictMock<IEntityIdentityResolver> (); _compoundComparisonSplitterMock = MockRepository.GenerateStrictMock<ICompoundExpressionComparisonSplitter> (); _namedExpressionCombinerMock = MockRepository.GenerateStrictMock<INamedExpressionCombiner>(); _groupAggregateSimplifierMock = MockRepository.GenerateStrictMock<IGroupAggregateSimplifier>(); _visitor = CreateVisitor (true); }
public static ResolvedJoinInfo ResolveJoinInfo ( IJoinInfo joinInfo, IMappingResolver resolver, UniqueIdentifierGenerator generator, IMappingResolutionStage stage, IMappingResolutionContext context) { ArgumentUtility.CheckNotNull ("joinInfo", joinInfo); ArgumentUtility.CheckNotNull ("resolver", resolver); ArgumentUtility.CheckNotNull ("generator", generator); ArgumentUtility.CheckNotNull ("stage", stage); ArgumentUtility.CheckNotNull ("context", context); var visitor = new ResolvingJoinInfoVisitor (resolver, generator, stage, context); return (ResolvedJoinInfo) joinInfo.Accept (visitor); }
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 virtual IResolvedTableInfo ResolveTableInfo (UnresolvedTableInfo tableInfo, UniqueIdentifierGenerator generator) { switch (tableInfo.ItemType.Name) { case "Cook": case "Knife": case "Kitchen": case "Restaurant": case "Company": return CreateResolvedTableInfo (tableInfo.ItemType, generator); case "Chef": return new ResolvedSimpleTableInfo (tableInfo.ItemType, "dbo."+tableInfo.ItemType.Name + "Table", generator.GetUniqueIdentifier ("t")); } throw new UnmappedItemException ("The type " + tableInfo.ItemType + " cannot be queried from the stub provider."); }
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 ResolveReference () { var sqlTable = new SqlTable (_tableInfo, JoinSemantics.Inner); var generator = new UniqueIdentifierGenerator (); var resolverMock = MockRepository.GenerateStrictMock<IMappingResolver> (); var mappingResolutionContext = new MappingResolutionContext (); resolverMock.Replay (); var result = _tableInfo.ResolveReference (sqlTable, resolverMock, mappingResolutionContext, generator); Assert.That (result, Is.TypeOf (typeof (SqlColumnDefinitionExpression))); Assert.That (((SqlColumnDefinitionExpression) result).ColumnName, Is.EqualTo ("test")); Assert.That (((SqlColumnDefinitionExpression) result).OwningTableAlias, Is.EqualTo (_tableInfo.TableAlias)); Assert.That (result.Type, Is.EqualTo (typeof (int))); }
public void ResolveReference () { var sqlTable = new SqlTable (_tableInfo, JoinSemantics.Inner); var fakeResult = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression (typeof (Cook)); var generator = new UniqueIdentifierGenerator(); var resolverMock = MockRepository.GenerateStrictMock<IMappingResolver>(); var mappingResolutionContext = new MappingResolutionContext(); resolverMock .Expect (mock => mock.ResolveSimpleTableInfo (_tableInfo, generator)) .Return (fakeResult); resolverMock.Replay (); var result = _tableInfo.ResolveReference (sqlTable, resolverMock, mappingResolutionContext, generator); resolverMock.VerifyAllExpectations (); Assert.That (result, Is.SameAs (fakeResult)); Assert.That (mappingResolutionContext.GetSqlTableForEntityExpression ((SqlEntityExpression) result), Is.SameAs (sqlTable)); }
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) }); }