예제 #1
0
        private ISQLExpression ProcessAttributesWithLoadAttribute(SelectStatement mainQuery, SelectStatement currentQuery, Table currentTable, EntityMapping entityMap, Table attributeTable, AttributeMapping attributeMapping, string atrbId)
        {
            if (_IsFirstAttribute)
            {
                _IsFirstAttribute = false;

                // if current table is a JoinedTable : 
                //		from clause = mainQuery INNER JOIN attributeTable
                if (currentTable is JoinedTable)
                {
                    JoinedTable lastJoinTable = new JoinedTable(mainQuery, TypeJoinedTable.LeftOuter, attributeTable);
                    lastJoinTable.TableAlias = mainQuery.TableAlias;

                    BinaryLogicExpression onCondition = new BinaryLogicExpression(
                        new Column(entityMap.Ids[0], mainQuery.TableAlias, entityMap.GetIdField(entityMap.Ids[0])),
                        BinaryLogicOperator.Equals,
                        new Column(attributeMapping, attributeTable.TableAlias, atrbId));

                    if (mainQuery.WhereClause.SearchCondition.Count != 0)
                    {
                        foreach (ILogicExpression expression in mainQuery.WhereClause.SearchCondition)
                        {
                            onCondition = new BinaryLogicExpression(onCondition, BinaryLogicOperator.And, expression);
                        }
                    }

                    lastJoinTable.SearchConditions.Add(new BinaryLogicExpression(
                        new Column(entityMap.Ids[0], mainQuery.TableAlias, entityMap.GetIdField(entityMap.Ids[0])),
                        BinaryLogicOperator.Equals,
                        new Column(entityMap.Ids[0], attributeTable.TableAlias, atrbId)));

                    currentQuery.TableAlias = mainQuery.TableAlias;
                    currentQuery.FromClause.Add(lastJoinTable);

                    tableContext.Push(lastJoinTable);

                    for (int i = 0; i < 2; i++)
                    {
                        Column column = mainQuery.SelectList[i] as Column;
                        if (column != null && column.ColumnName == entityMap.Ids[0].Field && entityMap.Ids[0].Generator.Name == GeneratorMapping.GeneratorType.inherited)
                        {
                            column.Alias = null;
                            currentQuery.SelectList.Add(new Column(column.TagMapping, lastJoinTable.TableAlias, column.ColumnName, entityMap.GetIdFieldAs(entityMap.Ids[0])));
                        }
                        else
                        {
                            currentQuery.SelectList.Add(mainQuery.SelectList[i]);
                        }
                    }

                    if (entityMap.Ids[0].Generator.Name == GeneratorMapping.GeneratorType.inherited)
                    {
                        for (int i = 2; i < mainQuery.SelectList.Count; i++)
                        {
                            Column column = mainQuery.SelectList[i] as Column;
                            if (column != null)
                            {
                                currentQuery.SelectList.Add(new Column(column.TagMapping, lastJoinTable.TableAlias, column.GetSelectName()));
                            }
                        }
                    }

                    if (attributeMapping.Discriminator != null)
                    {
                        currentQuery.SelectList.Add(new Column(attributeMapping, attributeTable.TableAlias, attributeMapping.Discriminator));
                    }

                    queryContext.Push(currentQuery);

                    string alias = (attributeMapping.Field != attributeMapping.Name) ? attributeMapping.Name : String.Empty;
                    return new Column(attributeMapping, attributeTable.TableAlias, attributeMapping.Field);

                }
                // else 
                //		from clause = currentTable INNER JOIN attributeTable
                else
                {
                    JoinedTable joinTable = new JoinedTable(currentTable, TypeJoinedTable.LeftOuter, attributeTable);
                    joinTable.SearchConditions.Add(new BinaryLogicExpression(
                        new Column(entityMap.Ids[0], currentTable.TableAlias, entityMap.GetIdField(entityMap.Ids[0])),
                        BinaryLogicOperator.Equals,
                        new Column(attributeMapping, attributeTable.TableAlias, atrbId)));

                    currentQuery.TableAlias = currentTable.TableAlias;
                    currentQuery.FromClause.Add(joinTable);
                    currentQuery.WhereClause.SearchCondition = mainQuery.WhereClause.SearchCondition;

                    foreach (ISQLExpression exp in mainQuery.SelectList)
                    {
                        if (!currentQuery.SelectList.Contains(exp))
                            currentQuery.SelectList.Add(exp);
                    }

                    tableContext.Push(joinTable);
                }
            }
            else
            {
                Table rightTable = ((JoinedTable)currentTable).RigthTable;

                JoinedTable joinTable = new JoinedTable(rightTable, TypeJoinedTable.LeftOuter, attributeTable);
                joinTable.SearchConditions.Add(new BinaryLogicExpression(
                    new Column(attributeMapping, rightTable.TableAlias, atrbId),
                    BinaryLogicOperator.Equals,
                    new Column(attributeMapping, attributeTable.TableAlias, atrbId)));

                ((JoinedTable)currentTable).RigthTable = joinTable;

                currentQuery.TableAlias = currentTable.TableAlias;
                currentQuery.FromClause.Add(currentTable);
                currentQuery.WhereClause.SearchCondition = mainQuery.WhereClause.SearchCondition;

                tableContext.Push(currentTable);
            }



            foreach (ISQLExpression exp in mainQuery.SelectList)
            {
                if (!currentQuery.SelectList.Contains(exp))
                {
                    currentQuery.SelectList.Add(exp);
                }
            }


            if (attributeMapping.Discriminator != null)
            {
                currentQuery.SelectList.Add(new Column(attributeMapping, attributeTable.TableAlias, attributeMapping.Discriminator));
            }
            queryContext.Push(currentQuery);

            string alias1 = (attributeMapping.Field != attributeMapping.Name) ? attributeMapping.Name : String.Empty;
            return new Column(attributeMapping, attributeTable.TableAlias, attributeMapping.Field, alias1);

        }
예제 #2
0
		public bool Contains(AttributeMapping value)
		{
			return base.List.Contains( (object)value);
		}
예제 #3
0
		public void Remove(AttributeMapping value)
		{
			base.List.Remove( (object)value);
		}
예제 #4
0
		public void Insert(int index, AttributeMapping value)
		{
			base.List.Insert(index, (object)value);
		}
예제 #5
0
		public int Add(AttributeMapping value)
		{
			return base.List.Add(value as object);
		}