CompositeElementMapping ICompositeElementMappingProvider.GetCompositeElementMapping() { var mapping = new CompositeElementMapping(attributes.CloneInner()); PopulateMapping(mapping); return(mapping); }
SubclassMapping IIndeterminateSubclassMappingProvider.GetSubclassMapping(SubclassType type) { var mapping = new SubclassMapping(type); GenerateNestedSubclasses(mapping); attributes.SetDefault(x => x.Type, typeof(T)); attributes.SetDefault(x => x.Name, typeof(T).AssemblyQualifiedName); attributes.SetDefault(x => x.DiscriminatorValue, typeof(T).Name); // TODO: un-hardcode this var key = new KeyMapping(); key.AddDefaultColumn(new ColumnMapping { Name = typeof(T).BaseType.Name + "_id" }); attributes.SetDefault(x => x.TableName, GetDefaultTableName()); attributes.SetDefault(x => x.Key, key); // TODO: this is nasty, we should find a better way mapping.OverrideAttributes(attributes.CloneInner()); foreach (var join in joins) { mapping.AddJoin(join); } foreach (var property in properties) { mapping.AddProperty(property.GetPropertyMapping()); } foreach (var component in components) { mapping.AddComponent(component.GetComponentMapping()); } foreach (var oneToOne in oneToOnes) { mapping.AddOneToOne(oneToOne.GetOneToOneMapping()); } foreach (var collection in collections) { mapping.AddCollection(collection.GetCollectionMapping()); } foreach (var reference in references) { mapping.AddReference(reference.GetManyToOneMapping()); } foreach (var any in anys) { mapping.AddAny(any.GetAnyMapping()); } return(mapping.DeepClone()); }
JoinMapping IJoinMappingProvider.GetJoinMapping() { var mapping = new JoinMapping(attributes.CloneInner()); mapping.ContainingEntityType = typeof(T); foreach (var property in properties) { mapping.AddProperty(property.GetPropertyMapping()); } foreach (var component in components) { mapping.AddComponent(component.GetComponentMapping()); } foreach (var reference in references) { mapping.AddReference(reference.GetManyToOneMapping()); } foreach (var any in anys) { mapping.AddAny(any.GetAnyMapping()); } return(mapping); }
ManyToOneMapping IManyToOneMappingProvider.GetManyToOneMapping() { var mapping = new ManyToOneMapping(attributes.CloneInner()); mapping.ContainingEntityType = entity; mapping.Member = property; if (!mapping.IsSpecified("Name")) { mapping.Name = property.Name; } if (!mapping.IsSpecified("Class")) { mapping.SetDefaultValue(x => x.Class, new TypeReference(typeof(TOther))); } if (columns.Count == 0) { mapping.AddDefaultColumn(CreateColumn(property.Name + "_id")); } foreach (var column in columns) { var columnMapping = CreateColumn(column); mapping.AddColumn(columnMapping); } return(mapping); }
private ColumnMapping CreateColumn(string column) { return(new ColumnMapping(columnAttributes.CloneInner()) { Name = column }); }
CacheMapping ICacheMappingProvider.GetCacheMapping() { var mapping = new CacheMapping(attributes.CloneInner()); mapping.ContainedEntityType = entityType; return(mapping); }
NaturalIdMapping INaturalIdMappingProvider.GetNaturalIdMapping() { var mapping = new NaturalIdMapping(attributes.CloneInner()); properties.Each(mapping.AddProperty); manyToOnes.Each(mapping.AddReference); return(mapping); }
CompositeIdMapping ICompositeIdMappingProvider.GetCompositeIdMapping() { var mapping = new CompositeIdMapping(attributes.CloneInner()); mapping.ContainingEntityType = typeof(T); keys.Each(mapping.AddKey); return(mapping); }
public void MappedShouldDefaultToFalseIfNameAttributeIsBlank() { var store = new AttributeStore <CompositeIdMapping>(); store.Set(x => x.Name, string.Empty); var mapping = new CompositeIdMapping(store.CloneInner()); mapping.Mapped.ShouldBeFalse(); }
public void MappedShouldDefaultToTrueIfNameAttributeIsSet() { var store = new AttributeStore <CompositeIdMapping>(); store.Set(x => x.Name, "someName"); var mapping = new CompositeIdMapping(store.CloneInner()); mapping.Mapped.ShouldBeTrue(); }
VersionMapping IVersionMappingProvider.GetVersionMapping() { var mapping = new VersionMapping(attributes.CloneInner()); mapping.ContainingEntityType = entity; mapping.SetDefaultValue("Name", property.Name); mapping.SetDefaultValue("Type", property.PropertyType == typeof(DateTime) ? new TypeReference("timestamp") : new TypeReference(property.PropertyType)); mapping.AddDefaultColumn(new ColumnMapping(columnAttributes.CloneInner()) { Name = property.Name }); columns.ForEach(column => mapping.AddColumn(new ColumnMapping(columnAttributes.CloneInner()) { Name = column })); return(mapping); }
AnyMapping IAnyMappingProvider.GetAnyMapping() { var mapping = new AnyMapping(attributes.CloneInner()); if (typeColumns.Count() == 0) { throw new InvalidOperationException("<any> mapping is not valid without specifying an Entity Type Column"); } if (identifierColumns.Count() == 0) { throw new InvalidOperationException("<any> mapping is not valid without specifying an Entity Identifier Column"); } if (!mapping.IsSpecified("IdType")) { throw new InvalidOperationException("<any> mapping is not valid without specifying an IdType"); } mapping.ContainingEntityType = entity; if (!mapping.IsSpecified("Name")) { mapping.Name = property.Name; } if (!mapping.IsSpecified("MetaType")) { if (metaValues.Count() > 0) { metaValues.Each(mapping.AddMetaValue); mapping.MetaType = new TypeReference(typeof(string)); } else { mapping.MetaType = new TypeReference(property.PropertyType); } } foreach (var column in typeColumns) { mapping.AddTypeColumn(new ColumnMapping { Name = column }); } foreach (var column in identifierColumns) { mapping.AddIdentifierColumn(new ColumnMapping { Name = column }); } return(mapping); }
public IndexMapping GetIndexMapping() { var mapping = new IndexMapping(attributes.CloneInner()); mapping.ContainingEntityType = entity; columns.Each(x => mapping.AddColumn(new ColumnMapping { Name = x })); return(mapping); }
ElementMapping IElementMappingProvider.GetElementMapping() { var mapping = new ElementMapping(attributes.CloneInner()); mapping.ContainingEntityType = entity; foreach (var column in Columns) { mapping.AddColumn(column); } return(mapping); }
IdMapping IIdentityMappingProvider.GetIdentityMapping() { var mapping = new IdMapping(attributes.CloneInner()) { ContainingEntityType = entityType }; if (columns.Count > 0) { foreach (var column in columns) { mapping.AddColumn(new ColumnMapping(columnAttributes.CloneInner()) { Name = column }); } } else if (HasNameSpecified) { mapping.AddDefaultColumn(new ColumnMapping(columnAttributes.CloneInner()) { Name = name }); } if (member != null) { mapping.Name = name; } mapping.SetDefaultValue("Type", new TypeReference(identityType)); if (GeneratedBy.IsDirty) { mapping.Generator = GeneratedBy.GetGeneratorMapping(); } return(mapping); }
public StoredProcedureMapping GetStoredProcedureMapping() { var mapping = new StoredProcedureMapping(attributes.CloneInner()); mapping.SPType = _element; mapping.Query = _innerText; if (!mapping.IsSpecified("Check")) { mapping.SetDefaultValue(x => x.Check, "rowcount"); } return(mapping); }
DiscriminatorMapping IDiscriminatorMappingProvider.GetDiscriminatorMapping() { var mapping = new DiscriminatorMapping(attributes.CloneInner()) { ContainingEntityType = entity, }; mapping.SetDefaultValue("Type", discriminatorValueType); mapping.AddColumn(new ColumnMapping(columnAttributes.CloneInner()) { Name = columnName }); return(mapping); }
protected virtual ICollectionMapping GetCollectionMapping() { var mapping = collectionBuilder(collectionAttributes.CloneInner()); if (!mapping.IsSpecified("Name")) { mapping.SetDefaultValue(x => x.Name, GetDefaultName()); } mapping.ContainingEntityType = entity; mapping.ChildType = typeof(TChild); mapping.Member = member; mapping.Key = keyMapping; mapping.Key.ContainingEntityType = entity; mapping.Relationship = GetRelationship(); mapping.Relationship.SetDefaultClass(new TypeReference(typeof(TChild))); if (cache != null) { mapping.Cache = cache; } if (componentMapping != null) { mapping.CompositeElement = componentMapping.GetCompositeElementMapping(); mapping.Relationship = null; // HACK: bad design } // HACK: Index only on list and map - shouldn't have to do this! if (indexMapping != null && mapping is IIndexedCollectionMapping) { ((IIndexedCollectionMapping)mapping).Index = indexMapping; } if (elementMapping != null) { mapping.Element = elementMapping; mapping.Relationship = null; } foreach (var filterMapping in filters) { mapping.Filters.Add(filterMapping); } return(mapping); }
ISubclassMapping ISubclassMappingProvider.GetSubclassMapping() { var mapping = new JoinedSubclassMapping(attributes.CloneInner()); mapping.Key = new KeyMapping { ContainingEntityType = typeof(TSubclass) }; mapping.Name = typeof(TSubclass).AssemblyQualifiedName; mapping.Type = typeof(TSubclass); foreach (var column in columns) { mapping.Key.AddColumn(column); } foreach (var property in properties) { mapping.AddProperty(property.GetPropertyMapping()); } foreach (var component in components) { mapping.AddComponent(component.GetComponentMapping()); } foreach (var oneToOne in oneToOnes) { mapping.AddOneToOne(oneToOne.GetOneToOneMapping()); } foreach (var collection in collections) { mapping.AddCollection(collection.GetCollectionMapping()); } foreach (var reference in references) { mapping.AddReference(reference.GetManyToOneMapping()); } foreach (var any in anys) { mapping.AddAny(any.GetAnyMapping()); } return(mapping); }
SubclassMapping ISubclassMappingProvider.GetSubclassMapping() { var mapping = new SubclassMapping(SubclassType.Subclass, attributes.CloneInner()); if (discriminatorValue != null) { mapping.DiscriminatorValue = discriminatorValue; } mapping.SetDefaultValue(x => x.Type, typeof(TSubclass)); mapping.SetDefaultValue(x => x.Name, typeof(TSubclass).AssemblyQualifiedName); foreach (var property in properties) { mapping.AddProperty(property.GetPropertyMapping()); } foreach (var component in components) { mapping.AddComponent(component.GetComponentMapping()); } foreach (var oneToOne in oneToOnes) { mapping.AddOneToOne(oneToOne.GetOneToOneMapping()); } foreach (var collection in collections) { mapping.AddCollection(collection.GetCollectionMapping()); } foreach (var reference in references) { mapping.AddReference(reference.GetManyToOneMapping()); } foreach (var any in anys) { mapping.AddAny(any.GetAnyMapping()); } subclassMappings.Each(mapping.AddSubclass); return(mapping); }
OneToOneMapping IOneToOneMappingProvider.GetOneToOneMapping() { var mapping = new OneToOneMapping(attributes.CloneInner()); mapping.ContainingEntityType = entity; if (!mapping.IsSpecified("Class")) { mapping.SetDefaultValue(x => x.Class, new TypeReference(typeof(TOther))); } if (!mapping.IsSpecified("Name")) { mapping.SetDefaultValue(x => x.Name, property.Name); } return(mapping); }
JoinMapping IJoinMappingProvider.GetJoinMapping() { var mapping = new JoinMapping(attributes.CloneInner()); mapping.ContainingEntityType = typeof(T); if (columns.Count == 0) { mapping.Key.AddDefaultColumn(new ColumnMapping { Name = typeof(T).Name + "_id" }); } else { foreach (var column in columns) { mapping.Key.AddColumn(new ColumnMapping { Name = column }); } } foreach (var property in properties) { mapping.AddProperty(property.GetPropertyMapping()); } foreach (var component in components) { mapping.AddComponent(component.GetComponentMapping()); } foreach (var reference in references) { mapping.AddReference(reference.GetManyToOneMapping()); } foreach (var any in anys) { mapping.AddAny(any.GetAnyMapping()); } return(mapping); }
PropertyMapping IPropertyMappingProvider.GetPropertyMapping() { var mapping = new PropertyMapping(attributes.CloneInner()) { ContainingEntityType = parentType, Member = property }; if (columns.Count() == 0 && !mapping.IsSpecified("Formula")) { mapping.AddDefaultColumn(new ColumnMapping(columnAttributes.CloneInner()) { Name = property.Name }); } foreach (var column in columns) { mapping.AddColumn(column); } foreach (var column in mapping.Columns) { if (!column.IsSpecified("NotNull") && property.PropertyType.IsNullable() && property.PropertyType.IsEnum()) { column.SetDefaultValue(x => x.NotNull, false); } column.MergeAttributes(columnAttributes); } if (!mapping.IsSpecified("Name")) { mapping.Name = mapping.Member.Name; } if (!mapping.IsSpecified("Type")) { mapping.SetDefaultValue("Type", GetDefaultType()); } return(mapping); }
protected ComponentMapping CreateComponentMapping() { var mapping = CreateComponentMappingRoot(attributes.CloneInner()); mapping.Name = propertyName; foreach (var property in properties) { mapping.AddProperty(property.GetPropertyMapping()); } foreach (var component in components) { mapping.AddComponent(component.GetComponentMapping()); } foreach (var oneToOne in oneToOnes) { mapping.AddOneToOne(oneToOne.GetOneToOneMapping()); } foreach (var collection in collections) { mapping.AddCollection(collection.GetCollectionMapping()); } foreach (var reference in references) { mapping.AddReference(reference.GetManyToOneMapping()); } foreach (var any in anys) { mapping.AddAny(any.GetAnyMapping()); } return(mapping); }
CompositeElementMapping ICompositeElementMappingProvider.GetCompositeElementMapping() { var mapping = new CompositeElementMapping(attributes.CloneInner()); mapping.ContainingEntityType = entity; if (!mapping.IsSpecified("Class")) { mapping.Class = new TypeReference(typeof(T)); } foreach (var property in properties) { mapping.AddProperty(property.GetPropertyMapping()); } foreach (var reference in references) { mapping.AddReference(reference.GetManyToOneMapping()); } return(mapping); }
protected override ComponentMapping CreateComponentMappingRoot(AttributeStore store) { return(new ExternalComponentMapping(ComponentType.Component, attributes.CloneInner())); }
internal ImportMapping GetImportMapping() { return(new ImportMapping(attributes.CloneInner())); }
ClassMapping IMappingProvider.GetClassMapping() { var mapping = new ClassMapping(attributes.CloneInner()); mapping.Type = typeof(T); mapping.Name = typeof(T).AssemblyQualifiedName; foreach (var property in properties) { mapping.AddProperty(property.GetPropertyMapping()); } foreach (var component in components) { mapping.AddComponent(component.GetComponentMapping()); } if (version != null) { mapping.Version = version.GetVersionMapping(); } foreach (var oneToOne in oneToOnes) { mapping.AddOneToOne(oneToOne.GetOneToOneMapping()); } foreach (var collection in collections) { mapping.AddCollection(collection.GetCollectionMapping()); } foreach (var reference in references) { mapping.AddReference(reference.GetManyToOneMapping()); } foreach (var any in anys) { mapping.AddAny(any.GetAnyMapping()); } foreach (var subclass in subclasses.Values) { mapping.AddSubclass(subclass.GetSubclassMapping()); } foreach (var join in joins) { mapping.AddJoin(join); } if (discriminator != null) { mapping.Discriminator = ((IDiscriminatorMappingProvider)discriminator).GetDiscriminatorMapping(); } if (Cache.IsDirty) { mapping.Cache = ((ICacheMappingProvider)Cache).GetCacheMapping(); } if (id != null) { mapping.Id = id.GetIdentityMapping(); } if (compositeId != null) { mapping.Id = compositeId.GetCompositeIdMapping(); } if (naturalId != null) { mapping.NaturalId = naturalId.GetNaturalIdMapping(); } if (!mapping.IsSpecified("TableName")) { mapping.SetDefaultValue(x => x.TableName, GetDefaultTableName()); } foreach (var filter in filters) { mapping.AddFilter(filter.GetFilterMapping()); } foreach (var storedProcedure in storedProcedures) { mapping.AddStoredProcedure(storedProcedure.GetStoredProcedureMapping()); } mapping.Tuplizer = tuplizerMapping; return(mapping); }
HibernateMapping IHibernateMappingProvider.GetHibernateMapping() { return(new HibernateMapping(attributes.CloneInner())); }