Beispiel #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());
        }
Beispiel #2
0
 protected ComponentMappingBase(AttributeStore store)
 {
     attributes = new AttributeStore <ComponentMappingBase>(store);
     attributes.SetDefault(x => x.Unique, false);
     attributes.SetDefault(x => x.Update, true);
     attributes.SetDefault(x => x.Insert, true);
     attributes.SetDefault(x => x.OptimisticLock, true);
 }
        public JoinPart(string tableName)
        {
            fetch = new FetchTypeExpression <JoinPart <T> >(this, value => attributes.Set(x => x.Fetch, value));

            attributes.SetDefault(x => x.TableName, tableName);
            attributes.Set(x => x.Key, new KeyMapping {
                ContainingEntityType = typeof(T)
            });
        }
Beispiel #4
0
        public JoinPart(string tableName)
        {
            fetch = new FetchTypeExpression <JoinPart <T> >(this, value => attributes.Set(x => x.Fetch, value));

            keyMapping = new KeyMapping {
                ContainingEntityType = typeof(T)
            };
            keyMapping.AddDefaultColumn(new ColumnMapping {
                Name = typeof(T).Name + "_id"
            });
            attributes.SetDefault(x => x.TableName, tableName);
            attributes.Set(x => x.Key, keyMapping);
        }
        void InitialiseDefaults(Type containingEntityType, Member member)
        {
            mapping.ContainingEntityType = containingEntityType;
            mapping.Member = member;
            mapping.AddDefaultColumn(new ColumnMapping(columnAttributes.InnerStore)
            {
                Name = member.Name
            });
            mapping.SetDefaultValue("Name", mapping.Member.Name);
            mapping.SetDefaultValue("Type", GetDefaultType());

            if (member.PropertyType.IsEnum() && member.PropertyType.IsNullable())
            {
                columnAttributes.SetDefault(x => x.NotNull, false);
            }
        }
Beispiel #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(x => x.Access, value));
            fetch          = new FetchTypeExpression <T>((T)this, value => collectionAttributes.Set(x => x.Fetch, value));
            optimisticLock = new OptimisticLockBuilder <T>((T)this, value => collectionAttributes.Set(x => x.OptimisticLock, value));
            cascade        = new CollectionCascadeExpression <T>((T)this, value => collectionAttributes.Set(x => x.Cascade, value));

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

            collectionAttributes.SetDefault(x => x.Name, member.Name);
            relationshipAttributes.SetDefault(x => x.Class, new TypeReference(typeof(TChild)));
        }
        void SetDefaultGenerator()
        {
            var generatorMapping = new GeneratorMapping();
            var defaultGenerator = new GeneratorBuilder(generatorMapping, identityType);

            if (identityType == typeof(Guid))
            {
                defaultGenerator.GuidComb();
            }
            else if (identityType == typeof(int) || identityType == typeof(long))
            {
                defaultGenerator.Identity();
            }
            else
            {
                defaultGenerator.Assigned();
            }

            attributes.SetDefault(x => x.Generator, generatorMapping);
        }
Beispiel #8
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(x => x.Access, value));
            fetch          = new FetchTypeExpression <T>((T)this, value => collectionAttributes.Set(x => x.Fetch, value));
            optimisticLock = new OptimisticLockBuilder <T>((T)this, value => collectionAttributes.Set(x => x.OptimisticLock, value));
            cascade        = new CollectionCascadeExpression <T>((T)this, value => collectionAttributes.Set(x => x.Cascade, value));

            SetDefaultCollectionType(type);
            SetCustomCollectionType(type);

            collectionAttributes.SetDefault(x => x.Name, member.Name);

            keyMapping = new KeyMapping();
            keyMapping.AddDefaultColumn(new ColumnMapping {
                Name = entity.Name + "_id"
            });
        }
Beispiel #9
0
 public ImportPart(Type importType)
 {
     attributes.SetDefault(x => x.Class, new TypeReference(importType));
 }
 public void SetDefaultValue <TResult>(Expression <Func <ListMapping, TResult> > property, TResult value)
 {
     attributes.SetDefault(property, value);
 }
 public ClassMapping(AttributeStore store)
 {
     attributes = new AttributeStore <ClassMapping>(store);
     attributes.SetDefault(x => x.Mutable, true);
 }
 protected CollectionMappingBase(AttributeStore underlyingStore)
     : base(underlyingStore)
 {
     _attributes = new AttributeStore<ICollectionMapping>(underlyingStore);
     _attributes.SetDefault(x => x.Cascade, CollectionCascadeType.None);
 }
Beispiel #13
0
 protected CollectionMappingBase(AttributeStore underlyingStore)
 {
     attributes = new AttributeStore <ICollectionMapping>(underlyingStore);
     attributes.SetDefault(x => x.Mutable, true);
 }
Beispiel #14
0
 public void SetDefaultValue <TResult>(Expression <Func <ComponentMappingBase, TResult> > property, TResult value)
 {
     attributes.SetDefault(property, value);
 }
 public OneToManyMapping()
 {
     attributes = new AttributeStore<OneToManyMapping>();
     attributes.SetDefault(x => x.ExceptionOnNotFound, true);
 }
 public CompositeIdMapping(AttributeStore underlyingStore)
 {
     attributes = new AttributeStore <CompositeIdMapping>(underlyingStore);
     attributes.SetDefault(x => x.Mapped, false);
     attributes.SetDefault(x => x.UnsavedValue, "undefined");
 }
 public CompositeIdMapping(AttributeStore underlyingStore)
 {
     attributes = new AttributeStore <CompositeIdMapping>(underlyingStore);
     attributes.SetDefault(x => x.Mapped, !string.IsNullOrEmpty(Name));
     attributes.SetDefault(x => x.UnsavedValue, "undefined");
 }