public void To(IColumn column) { RemoveOldMapping(); if (column == null) { ms.InvalidateCache(); return; } var mapping = ms.GetMappingFor(property.Component); if (mapping == null) { mapping = new ComponentMappingImpl(); mapping.ToComponent = property.Component; mapping.FromTable = column.Parent; mapping.AddPropertyAndColumn(property, column); ms.AddMapping(mapping); } else { mapping.SetMapping(property, column); ms.InvalidateCache(); } }
public ComponentMapping DeserialiseComponentMapping(XmlNode mappingNode, IDatabase database, EntitySet set) { NodeProcessor proc = new NodeProcessor(mappingNode); ComponentMapping mapping = new ComponentMappingImpl(); mapping.FromTable = database.GetTable(proc.GetString("FromTable"), proc.GetString("FromSchema")); NodeProcessor specProcessor = new NodeProcessor(mappingNode.SelectSingleNode("ToComponent")); var specification = set.GetComponentSpecification(specProcessor.Attributes.GetString("specification")); var parentEntity = set.GetEntity(specProcessor.Attributes.GetString("parent-entity")); string name = specProcessor.Attributes.GetString("name"); if (parentEntity == null) throw new DeserialisationException(string.Format("Could not find the Entity named {0}", name)); if (specification == null) throw new DeserialisationException(string.Format("Could not find the Component Specification named {0}", name)); var component = specification.ImplementedComponents.FirstOrDefault(c => ReferenceEquals(c.ParentEntity, parentEntity) && c.Name == name); if (component == null) throw new DeserialisationException(string.Format("Could not find the component named {0}", name)); mapping.ToComponent = component; var columnNodes = mappingNode.SelectNodes("FromColumns/Column"); var propNodes = mappingNode.SelectNodes("ToProperties/Property"); if (columnNodes == null) throw new DeserialisationException("There were no columns in this Mapping xml"); if (propNodes == null) throw new DeserialisationException("There were no properties in this Mapping xml"); List<IColumn> columns = new List<IColumn>(); foreach (XmlNode columnNode in columnNodes) { columns.Add(mapping.FromTable.GetColumn(columnNode.InnerText)); } List<ComponentPropertyMarker> properties = new List<ComponentPropertyMarker>(); foreach (XmlNode propNode in propNodes) { properties.Add(mapping.ToComponent.GetProperty(propNode.InnerText)); } if (columns.Count != properties.Count) throw new DeserialisationException("Mapping contains different numbers of columns and properties"); for (int i = 0; i < columns.Count; i++) { mapping.AddPropertyAndColumn(properties[i], columns[i]); } ProcessScriptBase(mapping, mappingNode); return mapping; }
public void Form_Is_Set_Up() { IComponentSpecificationForm form = MockRepository.GenerateMock<IComponentSpecificationForm>(); IMainPanel panel = MockRepository.GenerateMock<IMainPanel>(); var mappingSet = new MappingSetImpl(); var entity = new EntityImpl("Entity1"); entity.AddProperty(new PropertyImpl("Property1")); var table = new Table("Table1"); table.AddColumn(new Column("Column1")); table.AddColumn(new Column("Street")); mappingSet.EntitySet.AddEntity(entity); mappingSet.ChangeMappedColumnFor(entity.Properties.First()).To(table.Columns[0]); ComponentSpecification spec = new ComponentSpecificationImpl("Address"); spec.AddProperty(new ComponentPropertyImpl("Street")); Component component = spec.CreateImplementedComponentFor(entity, "Street"); mappingSet.EntitySet.AddComponentSpecification(spec); var mapping = new ComponentMappingImpl {ToComponent = component, FromTable = table}; mapping.AddPropertyAndColumn(component.Properties[0], table.Columns[0]); mappingSet.AddMapping(mapping); form.Expect(f => f.SetProperties(null)) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable<ComponentProperty>)action.Arguments[0]).Count(), Is.EqualTo(1))); form.Expect(f => f.SetUsages(null)) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable<Entity>)action.Arguments[0]).Count(), Is.EqualTo(1))); form.Expect(f => f.SetFullEntityList(null)) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable<Entity>)action.Arguments[0]).Count(), Is.EqualTo(1))); ComponentSpecificationPresenter presenter = new ComponentSpecificationPresenter(panel, form); presenter.AttachToModel(spec); form.AssertWasCalled(f => f.Clear()); form.AssertWasCalled(f => f.SpecName = spec.Name); form.AssertWasCalled(f => f.SetVirtualProperties(spec.Ex)); form.VerifyAllExpectations(); }
private void ProcessComponent(component hComponent, Entity newEntity, ITable mappedTable, Dictionary<Class, ComponentSpecification> specifications, string hmNamespace, ParseResults parseResults) { if (hComponent.@class == null) { log.ErrorFormat("Could not load component named {0} on class {1} because it does not have a class attribute.", hComponent.name, newEntity.Name); return; } var possibleClasses = GetPossibleClasses(hComponent.@class, hmNamespace, mappedTable.Schema, parseResults); if (possibleClasses.Count == 0) { log.ErrorFormat("Could not load component named {0} on class {1} because we could not find the class named {2}.", hComponent.name, newEntity.Name, hComponent.@class); return; } ComponentSpecification spec = null; foreach (var possibleClass in possibleClasses) { spec = specifications.GetValueOrDefault(possibleClass); if (spec != null) break; } bool createProperties = false; if (spec == null) { // Create a new spec from these. spec = new ComponentSpecificationImpl(GetShortClassName(hComponent.@class)); newEntity.EntitySet.AddComponentSpecification(spec); createProperties = true; } Component component = spec.CreateImplementedComponentFor(newEntity, hComponent.name); newEntity.Key.Component = component; var mapping = new ComponentMappingImpl(); foreach (var prop in hComponent.Properties()) { if (createProperties) { ComponentProperty idProperty = new ComponentPropertyImpl(prop.name); idProperty.Type = prop.type1; idProperty.ValidationOptions.MaximumLength = prop.length.As<int>(); SetPropertyInfoFromParsedCode(possibleClasses, idProperty); spec.AddProperty(idProperty); } var compProperty = component.GetProperty(prop.name); var column = mappedTable.GetColumn(prop.column.UnBackTick()); if (column == null) { // Create the column column = entityProcessor.CreateColumn(compProperty.RepresentedProperty); mapping.FromTable.AddColumn(column); } mapping.AddPropertyAndColumn(compProperty, column); } newEntity.EntitySet.MappingSet.AddMapping(mapping); }
private bool ProcessComponentKey(compositeid hCompId, Entity newEntity, ITable mappedTable, Dictionary<Class, ComponentSpecification> specifications, string hmNamespace, ParseResults parseResults) { var possibleClasses = GetPossibleClasses(hCompId.@class, hmNamespace, mappedTable.Schema, parseResults); if (possibleClasses.Count == 0) return false; ComponentSpecification spec = null; foreach (var possibleClass in possibleClasses) { spec = specifications.GetValueOrDefault(possibleClass); if (spec != null) break; } bool createProperties = false; if (spec == null) { // Create a new spec from these. spec = new ComponentSpecificationImpl(GetShortClassName(hCompId.@class)); newEntity.EntitySet.AddComponentSpecification(spec); createProperties = true; } Component component = spec.CreateImplementedComponentFor(newEntity, hCompId.name); newEntity.Key.Component = component; var mapping = new ComponentMappingImpl(); foreach (var prop in hCompId.KeyProperties()) { if (createProperties) { ComponentProperty idProperty = new ComponentPropertyImpl(prop.name); idProperty.Type = prop.type1; idProperty.ValidationOptions.MaximumLength = prop.length.As<int>(); SetPropertyInfoFromParsedCode(possibleClasses, idProperty); spec.AddProperty(idProperty); } var compProperty = component.GetProperty(prop.name); var column = mappedTable.GetColumn(prop.column1.UnBackTick()); if (column == null) { // Create the column column = entityProcessor.CreateColumn(compProperty.RepresentedProperty); mapping.FromTable.AddColumn(column); } mapping.AddPropertyAndColumn(compProperty, column); } newEntity.EntitySet.MappingSet.AddMapping(mapping); return true; }
public ComponentMapping DeserialiseComponentMapping(XmlNode mappingNode, IDatabase database, EntitySet set) { NodeProcessor proc = new NodeProcessor(mappingNode); ComponentMapping mapping = new ComponentMappingImpl(); mapping.FromTable = database.GetTable(proc.GetString("FromTable"), proc.GetString("FromSchema")); NodeProcessor specProcessor = new NodeProcessor(mappingNode.SelectSingleNode("ToComponent")); var specification = set.GetComponentSpecification(specProcessor.Attributes.GetString("specification")); var parentEntity = set.GetEntity(specProcessor.Attributes.GetString("parent-entity")); string name = specProcessor.Attributes.GetString("name"); if (parentEntity == null) { throw new DeserialisationException(string.Format("Could not find the Entity named {0}", name)); } if (specification == null) { throw new DeserialisationException(string.Format("Could not find the Component Specification named {0}", name)); } var component = specification.ImplementedComponents.FirstOrDefault(c => ReferenceEquals(c.ParentEntity, parentEntity) && c.Name == name); if (component == null) { throw new DeserialisationException(string.Format("Could not find the component named {0}", name)); } mapping.ToComponent = component; var columnNodes = mappingNode.SelectNodes("FromColumns/Column"); var propNodes = mappingNode.SelectNodes("ToProperties/Property"); if (columnNodes == null) { throw new DeserialisationException("There were no columns in this Mapping xml"); } if (propNodes == null) { throw new DeserialisationException("There were no properties in this Mapping xml"); } List <IColumn> columns = new List <IColumn>(); foreach (XmlNode columnNode in columnNodes) { columns.Add(mapping.FromTable.GetColumn(columnNode.InnerText)); } List <ComponentPropertyMarker> properties = new List <ComponentPropertyMarker>(); foreach (XmlNode propNode in propNodes) { properties.Add(mapping.ToComponent.GetProperty(propNode.InnerText)); } if (columns.Count != properties.Count) { throw new DeserialisationException("Mapping contains different numbers of columns and properties"); } for (int i = 0; i < columns.Count; i++) { mapping.AddPropertyAndColumn(properties[i], columns[i]); } ProcessScriptBase(mapping, mappingNode); return(mapping); }
public static ComponentMapping GetMapping() { ComponentMapping mapping = new ComponentMappingImpl(); mapping.FromTable = new Table("Table1"); mapping.FromTable.AddColumn(new Column("AddressStreet")); mapping.ToComponent = new ComponentImpl(new ComponentSpecificationImpl("Address"), new EntityImpl("Entity1"), "HomeAddress"); mapping.ToComponent.AddProperty(new ComponentPropertyMarker(new ComponentPropertyImpl("Street"))); mapping.AddPropertyAndColumn(mapping.ToComponent.Properties[0], mapping.FromTable.Columns[0]); return mapping; }
public void A_ToComponent__It_Should_Throw_An_Exception() { var mapping = new ComponentMappingImpl(); mapping.FromTable = new Table(); new MappingSetSerialisationScheme().SerialiseComponentMapping(mapping); }