/// <summary>
        /// Generates required data for a OneToMany relationship with embedded documents
        /// And with relationship attribute
        /// </summary>
        /// <returns></returns>
        public static RequiredDataContainer OneToManyRelationshipAttributesEmbedded()
        {
            // Create ER Stuff
            Entity Person = new Entity("Person");

            Person.AddAttribute("personId");
            Person.AddAttribute("name");

            Entity Car = new Entity("Car");

            Car.AddAttribute("name");
            Car.AddAttribute("year");

            Relationship Drives = new Relationship("Drives");

            Drives.AddAttribute("drivesFor");
            Drives.AddRelationshipEnd(new RelationshipEnd(Person));
            Drives.AddRelationshipEnd(new RelationshipEnd(Car));

            ERModel Model = new ERModel("PersonCarModel", new List <BaseERElement> {
                Person, Car, Drives
            });

            // Create MongoDB schema
            MongoDBCollection PersonCollection = new MongoDBCollection("Person");

            PersonCollection.DocumentSchema.AddAttribute("_id");
            PersonCollection.DocumentSchema.AddAttribute("name");
            PersonCollection.DocumentSchema.AddAttribute("cars");

            MongoSchema Schema = new MongoSchema("PersonCarSchema", new List <MongoDBCollection> {
                PersonCollection
            });

            // Create Map
            MapRule PersonRule = new MapRule(Model.FindByName("Person"), Schema.FindByName("Person"));

            PersonRule.AddRule("personId", "_id");
            PersonRule.AddRule("name", "name");

            MapRule CarRule = new MapRule(Model.FindByName("Car"), Schema.FindByName("Person"));

            CarRule.AddRule("name", "cars.name");
            CarRule.AddRule("year", "cars.year");

            MapRule RelationshipRule = new MapRule(Model.FindByName("Drives"), Schema.FindByName("Person"));

            RelationshipRule.AddRule("drivesFor", "cars.drivesFor");

            ModelMapping Map = new ModelMapping("PersonCarMap", new List <MapRule> {
                PersonRule, CarRule, RelationshipRule
            });

            return(new RequiredDataContainer(Model, Schema, Map));
        }
Example #2
0
        override public bool VisitRelationship(QueryBuilderMappingParser.RelationshipContext context)
        {
            if (Pass == 2)
            {
                // RelationshipCardinality deveria fazer parte de RelationshipConnection
                Relationship relationship = new Relationship(context.name.Text);

                foreach (QueryBuilderMappingParser.AttributeContext ac in context.attribute())
                {
                    relationship.AddAttribute(ac.name.Text, ac.type.Text, ac.multivalued != null, ac.primarykey != null);
                }


                foreach (var end in context.relationshipEnd())
                {
                    RelationshipEnd rend = new RelationshipEnd();
                    try
                    {
                        var target = EntityRelationshipModel.FindByName(end.name.Text);
                        if (target.GetType() != typeof(Entity))
                        {
                            Errors.Add($"Error 003: (line {end.name.Line}:{end.name.Column}): relationship end '{end.name.Text}' is not an Entity!");
                        }
                        else
                        {
                            rend.TargetEntity = (Entity)target;

                            relationship.AddRelationshipEnd(rend);
                        }
                    }
                    catch (Exception)
                    {
                        Errors.Add($"Error 004: (line {end.name.Line}:{end.name.Column}): relationship end '{end.name.Text}' not found!");
                    }
                }

                EntityRelationshipModel.Elements.Add(relationship);
            }
            return(true);
        }
        /// <summary>
        /// Generates required data to test a One to One relationship
        /// joining multiple entities with relationship attribute and multiple root attributes
        /// </summary>
        /// <returns></returns>
        public static RequiredDataContainer OneToOneRelationshipMultipleRootAttributes()
        {
            // Create ER Stuff
            Entity Person = new Entity("Person");

            Person.AddAttribute("personId", true);
            Person.AddAttribute("name");
            Person.AddAttribute("insuranceId");

            Entity Car = new Entity("Car");

            Car.AddAttribute("name");
            Car.AddAttribute("year");
            Car.AddAttribute("engine");
            Car.AddAttribute("fuel");

            Entity Insurance = new Entity("Insurance");

            Insurance.AddAttribute("insuranceId", true);
            Insurance.AddAttribute("name");

            Relationship HasInsurance = new Relationship("HasInsurance");

            HasInsurance.AddAttribute("insuranceValue");
            HasInsurance.AddRelationshipEnd(new RelationshipEnd(Person));
            HasInsurance.AddRelationshipEnd(new RelationshipEnd(Car));
            HasInsurance.AddRelationshipEnd(new RelationshipEnd(Insurance));

            ERModel Model = new ERModel("PersonCarModel", new List <BaseERElement> {
                Person, Car, HasInsurance, Insurance
            });

            // Create MongoDB schema
            MongoDBCollection PersonCollection = new MongoDBCollection("Person");

            PersonCollection.DocumentSchema.AddAttribute("_id");
            PersonCollection.DocumentSchema.AddAttribute("name");
            PersonCollection.DocumentSchema.AddAttribute("car.name");
            PersonCollection.DocumentSchema.AddAttribute("car.year");
            PersonCollection.DocumentSchema.AddAttribute("carDetails.engine");
            PersonCollection.DocumentSchema.AddAttribute("CarDetails.fuel");
            PersonCollection.DocumentSchema.AddAttribute("insuranceId");
            PersonCollection.DocumentSchema.AddAttribute("insuranceValue");

            MongoDBCollection InsuranceCollection = new MongoDBCollection("Insurance");

            InsuranceCollection.DocumentSchema.AddAttribute("_id");
            InsuranceCollection.DocumentSchema.AddAttribute("name");

            MongoSchema Schema = new MongoSchema("PersonCarSchema", new List <MongoDBCollection> {
                PersonCollection, InsuranceCollection
            });

            // Create Map
            MapRule PersonRule = new MapRule(Model.FindByName("Person"), Schema.FindByName("Person"));

            PersonRule.AddRule("personId", "_id");
            PersonRule.AddRule("name", "name");
            PersonRule.AddRule("carId", "carId");
            PersonRule.AddRule("insuranceId", "insuranceId");

            MapRule CarRule = new MapRule(Model.FindByName("Car"), Schema.FindByName("Person"), false);

            CarRule.AddRule("name", "car.name");
            CarRule.AddRule("year", "car.year");
            CarRule.AddRule("engine", "carDetails.engine");
            CarRule.AddRule("fuel", "carDetails.fuel");

            MapRule InsuranceRule = new MapRule(Model.FindByName("Insurance"), Schema.FindByName("Insurance"));

            InsuranceRule.AddRule("insuranceId", "_id");
            InsuranceRule.AddRule("name", "name");

            MapRule InsurancePersonRule = new MapRule(Model.FindByName("Insurance"), Schema.FindByName("Person"), false);

            InsurancePersonRule.AddRule("insuranceId", "insuranceId");

            MapRule RelationshipRule = new MapRule(Model.FindByName("HasInsurance"), Schema.FindByName("Person"), false);

            RelationshipRule.AddRule("insuranceValue", "insuranceValue");

            ModelMapping Map = new ModelMapping("PersonCarMap", new List <MapRule> {
                PersonRule, CarRule, InsuranceRule, RelationshipRule, InsurancePersonRule
            });

            return(new RequiredDataContainer(Model, Schema, Map));
        }
Example #4
0
        /// <summary>
        /// Generates data to test a query in which the target entity is embedded in the middle collection
        /// </summary>
        /// <returns></returns>
        public static RequiredDataContainer ManyToManyEmbeddedTarget()
        {
            // ER Model
            Entity Person = new Entity("Person");

            Person.AddAttribute("personId", true);
            Person.AddAttributes("name", "age");

            Entity Car = new Entity("Car");

            Car.AddAttribute("carId", true);
            Car.AddAttributes("model", "year");

            Relationship Drives = new Relationship("Drives");

            Drives.AddAttribute("something");

            Drives.AddRelationshipEnd(new RelationshipEnd(Person));
            Drives.AddRelationshipEnd(new RelationshipEnd(Car));

            ERModel Model = new ERModel("Model", new List <BaseERElement>()
            {
                Person, Car, Drives
            });

            // Mongo Schema
            MongoDBCollection PersonCol = new MongoDBCollection("Person");

            PersonCol.AddAttributes("_id", "name", "age");

            MongoDBCollection DrivesCol = new MongoDBCollection("Drives");

            DrivesCol.AddAttributes("_id", "something", "car.carId", "car.model", "car.year");

            MongoSchema Schema = new MongoSchema("Schema", new List <MongoDBCollection>()
            {
                PersonCol, DrivesCol
            });

            // Map
            MapRule PersonRule = new MapRule(Person, PersonCol);

            PersonRule.AddRule("personId", "_id");
            PersonRule.AddRule("name", "name");
            PersonRule.AddRule("age", "age");

            MapRule CarRule = new MapRule(Car, DrivesCol, false);

            CarRule.AddRule("carId", "car.carId");
            CarRule.AddRule("model", "car.model");
            CarRule.AddRule("year", "car.year");

            MapRule DrivesRule = new MapRule(Drives, DrivesCol);

            DrivesRule.AddRule("something", "something");

            MapRule PersonDrivesRule = new MapRule(Person, DrivesCol, false);

            PersonDrivesRule.AddRule("personId", "personId");

            ModelMapping Map = new ModelMapping("Map", new List <MapRule>()
            {
                PersonRule, CarRule, DrivesRule, PersonDrivesRule
            });

            return(new RequiredDataContainer(Model, Schema, Map));
        }
Example #5
0
        /// <summary>
        /// Generates data to test a many to many relationship join with multiple entities
        /// and relationship attributes
        /// </summary>
        /// <returns></returns>
        public static RequiredDataContainer ManyToManyRelationshipAttributeMultipleEntities()
        {
            Entity Person = new Entity("Person");

            Person.AddAttribute("personId", true);
            Person.AddAttribute("name");

            Entity Car = new Entity("Car");

            Car.AddAttribute("carId", true);
            Car.AddAttribute("name");
            Car.AddAttribute("year");

            Entity InsCompany = new Entity("InsCompany");

            InsCompany.AddAttribute("companyId", true);
            InsCompany.AddAttribute("name");

            Relationship Insurance = new Relationship("Insurance");

            Insurance.AddAttribute("insuranceId");
            Insurance.AddAttribute("insuranceValue");
            Insurance.AddAttribute("aRandomValue");
            Insurance.AddRelationshipEnd(new RelationshipEnd(Person));
            Insurance.AddRelationshipEnd(new RelationshipEnd(Car));
            Insurance.AddRelationshipEnd(new RelationshipEnd(InsCompany));

            ERModel Model = new ERModel("PersonCar", new List <BaseERElement> {
                Person, Car, Insurance, InsCompany
            });

            // MongoDB Schema
            MongoDBCollection PersonCol = new MongoDBCollection("Person");

            PersonCol.DocumentSchema.AddAttribute("_id");
            PersonCol.DocumentSchema.AddAttribute("name");

            MongoDBCollection CarCol = new MongoDBCollection("Car");

            CarCol.DocumentSchema.AddAttribute("_id");
            CarCol.DocumentSchema.AddAttribute("name");
            CarCol.DocumentSchema.AddAttribute("year");

            MongoDBCollection InsuranceCol = new MongoDBCollection("Insurance");

            InsuranceCol.DocumentSchema.AddAttribute("_id");
            InsuranceCol.DocumentSchema.AddAttribute("personId");
            InsuranceCol.DocumentSchema.AddAttribute("carId");
            InsuranceCol.DocumentSchema.AddAttribute("companyId");
            InsuranceCol.DocumentSchema.AddAttribute("insuranceValue");
            InsuranceCol.DocumentSchema.AddAttribute("aRandomValue");

            MongoDBCollection InsCompanyCol = new MongoDBCollection("InsCompany");

            InsCompanyCol.DocumentSchema.AddAttribute("_id");
            InsCompanyCol.DocumentSchema.AddAttribute("name");

            MongoSchema DBSchema = new MongoSchema("PersonCarSchema",
                                                   new List <MongoDBCollection> {
                PersonCol, CarCol, InsuranceCol, InsCompanyCol
            });

            // Map
            MapRule PersonRule = new MapRule(Person, PersonCol);

            PersonRule.AddRule("personId", "_id");
            PersonRule.AddRule("name", "name");

            MapRule CarRule = new MapRule(Car, CarCol);

            CarRule.AddRule("carId", "_id");
            CarRule.AddRule("name", "name");
            CarRule.AddRule("year", "year");

            MapRule InsuranceRule = new MapRule(Insurance, InsuranceCol);

            InsuranceRule.AddRule("insuranceId", "_id");
            InsuranceRule.AddRule("insuranceValue", "insuranceValue");
            InsuranceRule.AddRule("aRandomValue", "aRandomValue");

            MapRule InsCompanyRule = new MapRule(InsCompany, InsCompanyCol);

            InsCompanyRule.AddRule("companyId", "_id");
            InsCompanyRule.AddRule("name", "name");

            MapRule PersonInsuranceRule = new MapRule(Person, InsuranceCol, false);

            PersonInsuranceRule.AddRule("personId", "personId");

            MapRule CarInsuranceRule = new MapRule(Car, InsuranceCol, false);

            CarInsuranceRule.AddRule("carId", "carId");

            MapRule InsCompanyInsuranceRule = new MapRule(InsCompany, InsuranceCol, false);

            InsCompanyInsuranceRule.AddRule("companyId", "companyId");

            ModelMapping Map = new ModelMapping("PersonCarMap", new List <MapRule> {
                PersonRule,
                CarRule, InsuranceRule, InsCompanyRule, PersonInsuranceRule, CarInsuranceRule, InsCompanyInsuranceRule
            });

            return(new RequiredDataContainer(Model, DBSchema, Map));
        }
        public static DataContainer CreateDataContainer()
        {
            Entity Person = new Entity("Person");

            Person.AddAttribute("personId", true);
            Person.AddAttribute("name");

            Entity Car = new Entity("Car");

            Car.AddAttribute("carId", true);
            Car.AddAttributes("plate", "color");

            Relationship Drives = new Relationship("Drives");

            Drives.AddAttribute("note");
            Drives.AddRelationshipEnd(new RelationshipEnd(Person));
            Drives.AddRelationshipEnd(new RelationshipEnd(Car));

            ERModel Model = new ERModel("Model", new List <BaseERElement>()
            {
                Person, Car, Drives
            });

            MongoDBCollection PersonCol = new MongoDBCollection("Person");

            PersonCol.AddAttributes("_id", "name", "cars_multivalued_.id", "cars_multivalued_.note");

            MongoDBCollection CarCol = new MongoDBCollection("Car");

            CarCol.AddAttributes("_id", "plate", "color");

            MongoSchema Schema = new MongoSchema("Schema", new List <MongoDBCollection>()
            {
                PersonCol, CarCol
            });

            MapRule PersonRule = new MapRule(Person, PersonCol);

            PersonRule.AddRule("personId", "_id");
            PersonRule.AddRule("name", "name");

            MapRule CarRule = new MapRule(Car, CarCol);

            CarRule.AddRule("carId", "_id");
            CarRule.AddRule("plate", "plate");
            CarRule.AddRule("color", "color");

            MapRule CarPersonRule = new MapRule(Car, PersonCol, false);

            CarPersonRule.AddRule("carId", "cars_multivalued_.id");

            MapRule DrivesPersonRule = new MapRule(Drives, PersonCol, false);

            DrivesPersonRule.AddRule("note", "cars_multivalued_.note");

            ModelMapping Map = new ModelMapping("Map", new List <MapRule>()
            {
                PersonRule, CarRule, CarPersonRule, DrivesPersonRule
            });

            return(new DataContainer(Model, Schema, Map));
        }
Example #7
0
        /// <summary>
        /// Generates data to test a RJOIN operation with a one to one relationship
        /// connecting to a composition of two other entities
        /// </summary>
        /// <returns></returns>
        public static RequiredDataContainer OneToOneComputedEntity()
        {
            Entity Person = new Entity("Person");

            Person.AddAttribute("personId", true);
            Person.AddAttributes("name");

            Entity Car = new Entity("Car");

            Car.AddAttribute("carId", true);
            Car.AddAttributes("model", "year");

            Entity Garage = new Entity("Garage");

            Garage.AddAttribute("garageId", true);
            Garage.AddAttributes("name");

            Relationship Drives = new Relationship("Drives");

            Drives.AddRelationshipEnd(new RelationshipEnd(Person));
            Drives.AddRelationshipEnd(new RelationshipEnd(Car));

            Relationship Repaired = new Relationship("Repaired");

            Repaired.AddRelationshipEnd(new RelationshipEnd(Car));
            Repaired.AddRelationshipEnd(new RelationshipEnd(Garage));
            Repaired.AddAttribute("repairedId", true);
            Repaired.AddAttributes("repaired");

            ERModel Model = new ERModel("ERModel", new List <BaseERElement> {
                Person, Car, Garage, Drives, Repaired
            });

            // Mongo Schema
            MongoDBCollection PersonCol = new MongoDBCollection("Person");

            PersonCol.AddAttributes("_id", "name", "carId");

            MongoDBCollection CarCol = new MongoDBCollection("Car");

            CarCol.AddAttributes("_id", "model", "year");

            MongoDBCollection GarageCol = new MongoDBCollection("Garage");

            GarageCol.AddAttributes("_id", "name");

            MongoDBCollection RepairedCol = new MongoDBCollection("Repaired");

            RepairedCol.AddAttributes("_id", "carId", "garageId", "repaired");

            MongoSchema Schema = new MongoSchema("Schema", new List <MongoDBCollection> {
                PersonCol, CarCol, GarageCol, RepairedCol
            });

            // Map Rules
            MapRule PersonRule = new MapRule(Person, PersonCol);

            PersonRule.AddRule("personId", "_id");
            PersonRule.AddRule("name", "name");

            MapRule CarRule = new MapRule(Car, CarCol);

            CarRule.AddRule("carId", "_id");
            CarRule.AddRule("model", "model");
            CarRule.AddRule("year", "year");

            MapRule GarageRule = new MapRule(Garage, GarageCol);

            GarageRule.AddRule("garageId", "_id");
            GarageRule.AddRule("name", "name");

            MapRule RepairedRule = new MapRule(Repaired, RepairedCol);

            RepairedRule.AddRule("repairedId", "_id");
            RepairedRule.AddRule("repaired", "repaired");

            MapRule CarPersonRule = new MapRule(Car, PersonCol, false);

            CarPersonRule.AddRule("carId", "carId");

            MapRule CarRepairedRule = new MapRule(Car, RepairedCol, false);

            CarRepairedRule.AddRule("carId", "carId");

            MapRule GarageRepairedRule = new MapRule(Garage, RepairedCol, false);

            GarageRepairedRule.AddRule("garageId", "garageId");

            ModelMapping Map = new ModelMapping("Map", new List <MapRule> {
                PersonRule, CarRule, GarageRule, RepairedRule, CarPersonRule, CarRepairedRule, GarageRepairedRule
            });

            return(new RequiredDataContainer(Model, Schema, Map));
        }