예제 #1
0
        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());
        }
예제 #2
0
        public void ShouldWriteDynamicComponents()
        {
            var mapping = new SubclassMapping();

            mapping.AddComponent(new DynamicComponentMapping());

            writer.VerifyXml(mapping)
            .Element("dynamic-component").Exists();
        }
예제 #3
0
        public void ShouldWriteDynamicComponents()
        {
            var mapping = new SubclassMapping(SubclassType.JoinedSubclass);

            mapping.AddComponent(new ComponentMapping(ComponentType.DynamicComponent));

            writer.VerifyXml(mapping)
            .Element("dynamic-component").Exists();
        }
        public void ShouldWriteComponents()
        {
            var mapping = new SubclassMapping();

            mapping.AddComponent(new ComponentMapping());

            writer.VerifyXml(mapping)
                .Element("component").Exists();
        }
        public void ShouldWriteComponents()
        {
            var mapping = new SubclassMapping(SubclassType.Subclass);

            mapping.AddComponent(new ComponentMapping(ComponentType.Component));

            writer.VerifyXml(mapping)
            .Element("component").Exists();
        }
        public void Should_write_the_components()
        {
            var classMapping = new SubclassMapping();
            classMapping.AddComponent(new ComponentMapping());

            _mocker.Get<IHbmWriter<ComponentMapping>>()
                .Expect(x => x.Write(classMapping.Components.First())).Return(new HbmComponent());

            _subclassWriter.VerifyXml(classMapping)
                .Element("component").Exists();
        }
예제 #7
0
        SubclassMapping ISubclassMappingProvider.GetSubclassMapping()
        {
            var mapping = new SubclassMapping(SubclassType.JoinedSubclass, attributes.Clone());

            mapping.Set(x => x.Key, Layer.Defaults, new KeyMapping {
                ContainingEntityType = typeof(TSubclass)
            });
            mapping.Set(x => x.Name, Layer.Defaults, typeof(TSubclass).AssemblyQualifiedName);
            mapping.Set(x => x.Type, Layer.Defaults, typeof(TSubclass));

            foreach (var column in columns)
            {
                mapping.Key.AddColumn(Layer.Defaults, column);
            }

            foreach (var property in providers.Properties)
            {
                mapping.AddProperty(property.GetPropertyMapping());
            }

            foreach (var component in providers.Components)
            {
                mapping.AddComponent(component.GetComponentMapping());
            }

            foreach (var oneToOne in providers.OneToOnes)
            {
                mapping.AddOneToOne(oneToOne.GetOneToOneMapping());
            }

            foreach (var collection in providers.Collections)
            {
                mapping.AddCollection(collection.GetCollectionMapping());
            }

            foreach (var reference in providers.References)
            {
                mapping.AddReference(reference.GetManyToOneMapping());
            }

            foreach (var any in providers.Anys)
            {
                mapping.AddAny(any.GetAnyMapping());
            }

            return(mapping);
        }
예제 #8
0
        SubclassMapping ISubclassMappingProvider.GetSubclassMapping()
        {
            var mapping = new SubclassMapping(SubclassType.JoinedSubclass, 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);
        }
예제 #9
0
        SubclassMapping ISubclassMappingProvider.GetSubclassMapping()
        {
            var mapping = new SubclassMapping(SubclassType.Subclass, attributes.Clone());

            if (discriminatorValue != null)
            {
                mapping.Set(x => x.DiscriminatorValue, Layer.Defaults, discriminatorValue);
            }

            mapping.Set(x => x.Type, Layer.Defaults, typeof(TSubclass));
            mapping.Set(x => x.Name, Layer.Defaults, typeof(TSubclass).AssemblyQualifiedName);

            foreach (var property in providers.Properties)
            {
                mapping.AddProperty(property.GetPropertyMapping());
            }

            foreach (var component in providers.Components)
            {
                mapping.AddComponent(component.GetComponentMapping());
            }

            foreach (var oneToOne in providers.OneToOnes)
            {
                mapping.AddOneToOne(oneToOne.GetOneToOneMapping());
            }

            foreach (var collection in providers.Collections)
            {
                mapping.AddCollection(collection.GetCollectionMapping());
            }

            foreach (var reference in providers.References)
            {
                mapping.AddReference(reference.GetManyToOneMapping());
            }

            foreach (var any in providers.Anys)
            {
                mapping.AddAny(any.GetAnyMapping());
            }

            subclassMappings.Each(mapping.AddSubclass);

            return(mapping);
        }
        public void ShouldWriteDynamicComponents()
        {
            var mapping = new SubclassMapping(SubclassType.JoinedSubclass);

            mapping.AddComponent(new ComponentMapping(ComponentType.DynamicComponent));

            writer.VerifyXml(mapping)
                .Element("dynamic-component").Exists();
        }
예제 #11
0
        SubclassMapping IIndeterminateSubclassMappingProvider.GetSubclassMapping(SubclassType type)
        {
            var mapping = new SubclassMapping(type);

            GenerateNestedSubclasses(mapping);

            attributes.Set("Type", Layer.Defaults, typeof(T));
            attributes.Set("Name", Layer.Defaults, typeof(T).AssemblyQualifiedName);
            attributes.Set("DiscriminatorValue", Layer.Defaults, typeof(T).Name);

            // TODO: un-hardcode this
            Type baseType = typeof(T).BaseType
                            ?? attributes.Get("Extends") as Type;

            if (baseType != null)
            {
                var key = new KeyMapping();
                key.AddColumn(Layer.Defaults, new ColumnMapping(baseType.Name + "_id"));
                attributes.Set("Key", Layer.Defaults, key);
            }

            attributes.Set("TableName", Layer.Defaults, GetDefaultTableName());

            // TODO: this is nasty, we should find a better way
            mapping.OverrideAttributes(attributes.Clone());

            foreach (var join in joins)
            {
                mapping.AddJoin(join);
            }

            foreach (var provider in providers.OrderedProviders)
            {
                var mappingProviderObj = provider.Item2;
                switch (provider.Item1)
                {
                case MappingProviderStore.ProviderType.Property:
                    mapping.AddProperty(((IPropertyMappingProvider)mappingProviderObj).GetPropertyMapping());
                    break;

                case MappingProviderStore.ProviderType.Component:
                    mapping.AddComponent(((IComponentMappingProvider)mappingProviderObj).GetComponentMapping());
                    break;

                case MappingProviderStore.ProviderType.OneToOne:
                    mapping.AddOneToOne(((IOneToOneMappingProvider)mappingProviderObj).GetOneToOneMapping());
                    break;

                case MappingProviderStore.ProviderType.Collection:
                    mapping.AddCollection(((ICollectionMappingProvider)mappingProviderObj).GetCollectionMapping());
                    break;

                case MappingProviderStore.ProviderType.ManyToOne:
                    mapping.AddReference(((IManyToOneMappingProvider)mappingProviderObj).GetManyToOneMapping());
                    break;

                case MappingProviderStore.ProviderType.Any:
                    mapping.AddAny(((IAnyMappingProvider)mappingProviderObj).GetAnyMapping());
                    break;

                case MappingProviderStore.ProviderType.Subclass:
                case MappingProviderStore.ProviderType.Filter:
                case MappingProviderStore.ProviderType.StoredProcedure:
                case MappingProviderStore.ProviderType.Join:
                case MappingProviderStore.ProviderType.Identity:
                case MappingProviderStore.ProviderType.CompositeId:
                case MappingProviderStore.ProviderType.NaturalId:
                case MappingProviderStore.ProviderType.Version:
                case MappingProviderStore.ProviderType.Discriminator:
                case MappingProviderStore.ProviderType.Tupilizer:
                default:
                    throw new Exception("Internal Error");
                }
            }

            return(mapping.DeepClone());
        }
예제 #12
0
        SubclassMapping IIndeterminateSubclassMappingProvider.GetSubclassMapping(SubclassType type)
        {
            var mapping = new SubclassMapping(type);

            GenerateNestedSubclasses(mapping);

            attributes.Set("Type", Layer.Defaults, typeof(T));
            attributes.Set("Name", Layer.Defaults, typeof(T).AssemblyQualifiedName);
            attributes.Set("DiscriminatorValue", Layer.Defaults, typeof(T).Name);

            // TODO: un-hardcode this
            Type baseType = typeof(T).BaseType
                            ?? attributes.Get("Extends") as Type;

            if (baseType != null)
            {
                var key = new KeyMapping();
                key.AddColumn(Layer.Defaults, new ColumnMapping(baseType.Name + "_id"));
                attributes.Set("Key", Layer.Defaults, key);
            }

            attributes.Set("TableName", Layer.Defaults, GetDefaultTableName());

            // TODO: this is nasty, we should find a better way
            mapping.OverrideAttributes(attributes.Clone());

            foreach (var join in joins)
            {
                mapping.AddJoin(join);
            }

            foreach (var property in providers.Properties)
            {
                mapping.AddProperty(property.GetPropertyMapping());
            }

            foreach (var component in providers.Components)
            {
                mapping.AddComponent(component.GetComponentMapping());
            }

            foreach (var oneToOne in providers.OneToOnes)
            {
                mapping.AddOneToOne(oneToOne.GetOneToOneMapping());
            }

            foreach (var collection in providers.Collections)
            {
                mapping.AddCollection(collection.GetCollectionMapping());
            }

            foreach (var reference in providers.References)
            {
                mapping.AddReference(reference.GetManyToOneMapping());
            }

            foreach (var any in providers.Anys)
            {
                mapping.AddAny(any.GetAnyMapping());
            }

            return(mapping.DeepClone());
        }