// add a new data table to the set only if the set does not contain apropriate table yet private void AddTableToSet(LogicalQueryTable queryTable) { if (this.currentSet.Tables.Find((x) => x.Name.Equals(queryTable.Table.Name)) == null) { DataTable dataTable = ToDataTable (queryTable.Table); this.currentSet.Tables.Add (dataTable); // add table shortcut this.tablesShortcut.Add (queryTable, dataTable); } }
// should throw an exception if source is not included in the tree public virtual LogicalQueryTable JoinTable(LogicalQueryTable source, LogicalTable joinWith) { // first check if source is the last added node, if not search the whole tree if (!this.logicalTables.Contains(source)) { throw new ArgumentException("Source table is not present in the query."); } attachTable(source, joinWith); return this.lastTableAdded; }
private LogicalQueryTable CreatePartOfEntityTable() { LogicalQueryTable queryTable = new LogicalQueryTable() {Alias = "Entity_0"}; LogicalTable logicalTable = new LogicalTable() {Name = "EntityPart", TableType = LogicalTableType.ENTITY}; queryTable.Table = logicalTable; TableDefinition physicalTable = new TableDefinition() {Name = "Entity"}; logicalTable.PartOfTable = physicalTable; TableColumn nameColumn = new TableColumn() {Name="name", Table = physicalTable}; physicalTable.addColumn(nameColumn); logicalTable.AddColumn(nameColumn); return queryTable; }
private LogicalQueryTable CreateSingleEntityTable() { LogicalQueryTable queryTable = new LogicalQueryTable() {Alias = "Entity_0"}; LogicalTable logicalTable = new LogicalTable() {Name = "Entity", TableType = LogicalTableType.ENTITY}; queryTable.Table = logicalTable; TableDefinition physicalTable = new TableDefinition() {Name = "Entity"}; logicalTable.PartOfTable = physicalTable; TableColumn idColumn = new TableColumn() {IsPrimaryKey = true, Name="id", Table = physicalTable}; TableColumn nameColumn = new TableColumn() {Name="name", Table = physicalTable}; physicalTable.addColumn(idColumn); physicalTable.addColumn(nameColumn); logicalTable.AddColumn(idColumn); logicalTable.AddColumn(nameColumn); return queryTable; }
private DataTable GetDataTable(LogicalQueryTable queryTable) { return this.tablesShortcut[queryTable]; }
public bool IsLogicalTableEqual(LogicalQueryTable queryTable) { return Table.IsPartOfTheSameTable(queryTable.Table); }
private void attachTable(LogicalQueryTable source, LogicalTable joinWith) { // check if join can be performed, if not then exception is thrown validateAttachArguments(source, joinWith); // join tables LogicalQueryTable target = new LogicalQueryTable() {Table = joinWith}; // if the join table is in fact a part of another physical table already included in source logical table // then dont join them // always join tables if the target table is of entity type if (!isJoinRequired (source, target)) { target.Alias = source.Alias; } else { string alias = createTableAlias(joinWith); target.Alias = alias; PhysicalQueryTable physicalQueryTable = new PhysicalQueryTable() {Table = joinWith.PartOfTable, Alias = alias}; this.physicalTables.Add (physicalQueryTable); this.fromSource = createNewJoin (this.fromSource, source, target); } this.logicalTables.Add (target); this.lastTableAdded = target; }
private void validateAttachArguments(LogicalQueryTable source, LogicalTable joinWith) { if (source.Table.Equals(joinWith)) { throw new ArgumentException("Cannot join a logical table with itself"); } else if (source.Table.TableType.Equals (joinWith.TableType)) { throw new ArgumentException("Cannot join two entity logical or two join logical tables"); } }
private void setRootTable(LogicalTable rootTable) { string alias = createTableAlias(rootTable); LogicalQueryTable queryTable = new LogicalQueryTable() {Table = rootTable, Alias = alias}; PhysicalQueryTable physicalQueryTable = new PhysicalQueryTable() {Table = rootTable.PartOfTable, Alias = alias}; this.logicalTables.Add (queryTable); this.physicalTables.Add (physicalQueryTable); this.fromSource = physicalQueryTable.ToTableReference(); this.lastTableAdded = queryTable; }
private bool isJoinRequired(LogicalQueryTable source, LogicalQueryTable target) { return !source.IsLogicalTableEqual(target); }
private ITableExpression createNewJoin(ITableExpression oldJoin, LogicalQueryTable sourceTable, LogicalQueryTable targetTable) { LogicalQueryTable relationTable = (sourceTable.Table.TableType == LogicalTableType.JOIN ? sourceTable : targetTable); LogicalQueryTable entityTable = (sourceTable.Table.TableType == LogicalTableType.ENTITY ? sourceTable : targetTable); TableColumn primaryKey = entityTable.Table.GetPrimaryKey(); TableColumn foreignKey = relationTable.Table.GetForeignKey(primaryKey); ILogicalCondition on = Logical.Equal(Expression.Column(entityTable.Alias, primaryKey.Name), Expression.Column (relationTable.Alias, foreignKey.Name)); return From.Left (oldJoin, targetTable.ToTableReference(), on); }