public HibernateMappingPart()
 {
     defaultCascade = new CascadeExpression <HibernateMappingPart>(this, value =>
     {
         var current = attributes.Get("DefaultCascade") as string;
         attributes.Set("DefaultCascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value));
     });
     defaultAccess = new AccessStrategyBuilder <HibernateMappingPart>(this, value => attributes.Set("DefaultAccess", Layer.UserSupplied, value));
 }
示例#2
0
        public AnyPart(Type entity, Member member)
        {
            this.entity = entity;
            this.member = member;
            access      = new AccessStrategyBuilder <AnyPart <T> >(this, value => attributes.Set("Access", Layer.UserSupplied, value));
            cascade     = new CascadeExpression <AnyPart <T> >(this, value =>
            {
                var current = attributes.Get("Cascade") as string;
                attributes.Set("Cascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value));
            });

            SetDefaultAccess();
        }
示例#3
0
        public ManyToOnePart(Type entity, Member member)
        {
            this.entity = entity;
            this.member = member;
            access      = new AccessStrategyBuilder <ManyToOnePart <TOther> >(this, value => attributes.Set("Access", Layer.UserSupplied, value));
            fetch       = new FetchTypeExpression <ManyToOnePart <TOther> >(this, value => attributes.Set("Fetch", Layer.UserSupplied, value));
            cascade     = new CascadeExpression <ManyToOnePart <TOther> >(this, value =>
            {
                var current = attributes.Get("Cascade") as string;
                attributes.Set("Cascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value));
            });
            notFound = new NotFoundExpression <ManyToOnePart <TOther> >(this, value => attributes.Set("NotFound", Layer.UserSupplied, value));

            SetDefaultAccess();
        }
示例#4
0
        /// <summary>
        /// Specify how the foreign key is configured.
        /// </summary>
        /// <param name="keyConfiguration">Configuration <see cref="Action"/></param>
        /// <returns>Builder</returns>
        public void Key(Action <KeyBuilder> keyConfiguration)
        {
            KeyMapping key;

            if (attributes.IsSpecified(x => x.Key))
            {
                key = attributes.Get(x => x.Key);
            }
            else
            {
                key = new KeyMapping();
            }

            keyConfiguration(new KeyBuilder(key));

            attributes.Set(x => x.Key, key);
        }
示例#5
0
        public void KeyColumn(string column)
        {
            KeyMapping key;

            if (joinedSubclassAttributes.IsSpecified(x => x.Key))
            {
                key = joinedSubclassAttributes.Get(x => x.Key);
            }
            else
            {
                key = new KeyMapping();
            }

            key.AddColumn(new ColumnMapping {
                Name = column
            });

            joinedSubclassAttributes.Set(x => x.Key, key);
        }
示例#6
0
        protected ToManyBase(Type entity, Member member, Type type)
        {
            this.entity = entity;
            this.member = member;
            AsBag();
            access  = new AccessStrategyBuilder <T>((T)this, value => collectionAttributes.Set("Access", Layer.UserSupplied, value));
            fetch   = new FetchTypeExpression <T>((T)this, value => collectionAttributes.Set("Fetch", Layer.UserSupplied, value));
            cascade = new CollectionCascadeExpression <T>((T)this, value =>
            {
                var current = collectionAttributes.Get("Cascade") as string;
                collectionAttributes.Set("Cascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value));
            });

            SetDefaultCollectionType();
            SetCustomCollectionType(type);
            SetDefaultAccess();
            Cache = new CachePart(entity);

            collectionAttributes.Set("Name", Layer.Defaults, member.Name);
            relationshipAttributes.Set("Class", Layer.Defaults, new TypeReference(typeof(TChild)));
        }
 public void CreateNewAttributeStore()
 {
     var store = new AttributeStore();
     var value = new object();
     store.Set("name1", value, new NameValueMapAttribute { Name = "A.B.C" });
     store.Get("name1").Layer.ShouldEqual(3);
     store.Get("name1").Value.ShouldEqual(value);
     store.Set("name1", value, new NameValueMapAttribute { Name = "A.B" });
     store.Get("name1").Layer.ShouldEqual(2);
     store.Get("name1").Value.ShouldEqual(value);
     store.Equals(store.Clone()).ShouldBeTrue();
 }
示例#8
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());
        }
示例#9
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());
        }