public void TestCase()
        {
            LogicalQueryBuilder query = new LogicalQueryBuilder();

            TableDefinition entityTable = new TableDefinition() {Name = "Entity"};
            TableColumn pk1 = new TableColumn() {IsPrimaryKey = true, Name = "id1"};
            TableColumn name1 = new TableColumn() {Name = "name1"};
            TableColumn name2 = new TableColumn() {Name = "name2"};
            entityTable.addColumn(pk1);
            entityTable.addColumn(name1);
            entityTable.addColumn(name2);

            TableDefinition secondEntity = new TableDefinition() {Name = "SecondEntity"};
            TableColumn pk2 = new TableColumn() {IsPrimaryKey = true, Name = "id"};
            TableColumn fk1 = new TableColumn() {IsForeignKey = true, Name = "fk1", ReferencedColumn = pk1};
            secondEntity.addColumn(pk2);
            secondEntity.addColumn(fk1);

            LogicalTable log1 = new LogicalTable() {Name = "Entity_Prop", PartOfTable = entityTable, TableType = LogicalTableType.ENTITY};
            log1.AddColumn(pk1);
            log1.AddColumn(name1);
            log1.AddColumn(name2);

            LogicalTable log2 = new LogicalTable() {Name = "Entity_SecondEntity", PartOfTable = secondEntity, TableType = LogicalTableType.JOIN};
            log2.AddColumn(pk2);
            log2.AddColumn(fk1);

            LogicalTable log3 = new LogicalTable() {Name = "SecondEntity_Prop", PartOfTable = secondEntity, TableType = LogicalTableType.ENTITY};
            log3.AddColumn(pk2);

            TableDefinition thirdEntity = new TableDefinition() {Name = "ThirdEntity"};
            TableColumn pk3 = new TableColumn() {IsPrimaryKey = true, Name = "pk3"};
            thirdEntity.addColumn(pk3);

            TableDefinition joinTable = new TableDefinition() {Name = "SecondEntity_ThirdEntity"};
            TableColumn join1 = new TableColumn() {IsForeignKey = true, Name = "fk2", ReferencedColumn = pk2};
            TableColumn join2 = new TableColumn() {IsForeignKey = true, Name = "fk3", ReferencedColumn = pk3};
            joinTable.addColumn(join1);
            joinTable.addColumn(join2);

            LogicalTable log4 = new LogicalTable() {Name = "SecondEntity_ThirdEntity", PartOfTable = joinTable, TableType = LogicalTableType.JOIN};
            log4.AddColumn(join1);
            log4.AddColumn(join2);

            LogicalTable log5 = new LogicalTable() {Name = "ThirdEntity", PartOfTable = thirdEntity, TableType = LogicalTableType.ENTITY};
            log5.AddColumn(pk3);

            query.JoinTable (log1);
            query.JoinTable (log2);
            query.JoinTable (log3);
            query.JoinTable (log4);
            query.JoinTable (log5);

            string actual = query.ToNativeQuery().ToQueryString ();
            Console.WriteLine(actual);
            string expected = "Dunno";

            Assert.AreEqual (expected, actual);
        }
        public virtual ClassMapping<object> createMapping(Type type)
        {
            ClassMapping<object> mapping = new ClassMapping<object>();
            // type
            mapping.ClassType = type;
            // table
            LogicalTable logicalTable = new LogicalTable();
            mapping.CorrespondingTable = logicalTable;

            TableDefinition table = new TableDefinition();

            Table tableAttr = AttributeUtils.getSingleAttribute<Table>(type);
            if (tableAttr != null) {
                table.Name = tableAttr.Name;
            } else {
                table.Name = generateTableName(type.Name);
            }

            logicalTable.Name = table.Name;

            // all fields including id
            foreach (FieldInfo field in getClassFields(type)) {
                if (isFieldPersistent(field)) {
                    FieldMapping<object, object> fieldMapping = new FieldMapping<object, object>() {ClassField = field};

                    TableColumn column = new TableColumn();
                    logicalTable.AddColumn(column);
                    Column colAttr = AttributeUtils.getSingleAttribute<Column>(field);
                    if (colAttr != null) {
                        column.Name = colAttr.Name;
                    } else {
                        column.Name = field.Name;
                    }
                    fieldMapping.Column = column;
                    table.addColumn(column);
                    mapping.AddPropertyMapping (fieldMapping);
                    Id idAttr = AttributeUtils.getSingleAttribute<Id>(field);
                    if (idAttr != null) {
                        mapping.IdMapping = fieldMapping;
                        column.IsPrimaryKey = true;
                        fieldMapping.IsId = true;
                    }
                }
            }
            return mapping;
        }
        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;
        }
        public void TestCase()
        {
            TableColumn idCol = new TableColumn();
            idCol.Name = "id";
            idCol.Type = "INT";
            idCol.IsPrimaryKey = true;

            TableColumn nameCol = new TableColumn();
            nameCol.Name = "name";
            nameCol.Type = "STRING";

            TableDefinition table = new TableDefinition();
            table.Name = "TestTable";

            table.addColumn(idCol);
            table.addColumn(nameCol);

            string retrievedSchema = table.getTableSchema();
            string expectedSchema = "CREATE TABLE TestTable (id INT PRIMARY KEY ASC, name STRING);";

            Assert.AreEqual(expectedSchema, retrievedSchema);
        }
        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 int howManyTimesUsed(TableDefinition table)
 {
     return this.physicalTables.FindAll ((x) => x.Table.Equals(table)).Count;
 }