Esempio n. 1
0
		private string GetClassTableName(PersistentClass model, HbmClass classSchema)
		{
			if (classSchema.table == null)
				return mappings.NamingStrategy.ClassToTableName(model.EntityName);
			else
				return mappings.NamingStrategy.TableName(classSchema.table.Trim());
		}
Esempio n. 2
0
        public MappedClassInfo(HbmClass classInfo, string fileName)
        {
            FileName = fileName;
            _classInfo = classInfo;

            Properties = new List<MappedPropertyInfo>();
            if (classInfo.Id != null)
            {
                Properties.Add(new MappedPropertyInfo(classInfo.Id, fileName));
            }
            if (classInfo.Items != null)
            {
                Properties.AddRange(_classInfo.Items.Select(x => new MappedPropertyInfo(x, fileName)));
            }
            string[] parts = classInfo.name.Split(new[] {','});
            ClassName = parts[0];
            if (parts.Length > 1)
            {
                AssemblyName = parts[1].Trim();
            }

            Mutable = classInfo.mutable;
            Cache = classInfo.cache;

            TableName = classInfo.table;
        }
Esempio n. 3
0
        public void Bind(HbmClass classSchema, IDictionary<string, MetaAttribute> inheritedMetas)
        {
            var rootClass = new RootClass();
            BindClass(classSchema, rootClass, inheritedMetas);
            // OPTIMISTIC LOCK MODE
            rootClass.OptimisticLockMode = classSchema.optimisticlock.ToOptimisticLock();

            inheritedMetas = GetMetas(classSchema, inheritedMetas, true); // get meta's from <class>

            //TABLENAME
            string schema = classSchema.schema ?? mappings.SchemaName;
            string catalog = classSchema.catalog ?? mappings.CatalogName;
            string tableName = GetClassTableName(rootClass, classSchema);
            if (string.IsNullOrEmpty(tableName))
            {
                throw new MappingException(
                    string.Format(
                        "Could not determine the name of the table for entity '{0}'; remove the 'table' attribute or assign a value to it.",
                        rootClass.EntityName));
            }

            Table table = mappings.AddTable(schema, catalog, tableName, classSchema.Subselect, rootClass.IsAbstract.GetValueOrDefault(), classSchema.schemaaction);
            ((ITableOwner) rootClass).Table = table;

            log.InfoFormat("Mapping class: {0} -> {1}", rootClass.EntityName, rootClass.Table.Name);

            rootClass.IsMutable = classSchema.mutable;
            rootClass.Where = classSchema.where ?? rootClass.Where;

            if (classSchema.check != null)
                table.AddCheckConstraint(classSchema.check);

            rootClass.IsExplicitPolymorphism = classSchema.polymorphism == HbmPolymorphismType.Explicit;

            BindCache(classSchema.cache, rootClass);
            new ClassIdBinder(this).BindId(classSchema.Id, rootClass, table);
            new ClassCompositeIdBinder(this).BindCompositeId(classSchema.CompositeId, rootClass);
            new ClassDiscriminatorBinder(rootClass, Mappings).BindDiscriminator(classSchema.discriminator, table);
            BindTimestamp(classSchema.Timestamp, rootClass, table, inheritedMetas);
            BindVersion(classSchema.Version, rootClass, table, inheritedMetas);

            if (!String.IsNullOrEmpty(classSchema.primaryKeyName)) {
                rootClass.PrimaryKeyName = classSchema.primaryKeyName;
                table.PrimaryKeyName = classSchema.primaryKeyName;
            }
            rootClass.CreatePrimaryKey(dialect);
            BindNaturalId(classSchema.naturalid, rootClass, inheritedMetas);
            new PropertiesBinder(mappings, rootClass, dialect).Bind(classSchema.Properties, inheritedMetas);

            BindJoins(classSchema.Joins, rootClass, inheritedMetas);
            BindSubclasses(classSchema.Subclasses, rootClass, inheritedMetas);
            BindJoinedSubclasses(classSchema.JoinedSubclasses, rootClass, inheritedMetas);
            BindUnionSubclasses(classSchema.UnionSubclasses, rootClass, inheritedMetas);

            new FiltersBinder(rootClass, Mappings).Bind(classSchema.filter);

            mappings.AddClass(rootClass);
        }
		public NaturalIdMapper(System.Type rootClass, HbmClass classMapping, HbmMapping mapDoc) : base(rootClass, mapDoc)
		{
			if (classMapping == null)
			{
				throw new ArgumentNullException("classMapping");
			}
			this.classMapping = classMapping;
			naturalIdmapping = new HbmNaturalId();
		}
		public void CanSetMutable()
		{
			var mapdoc = new HbmMapping();
			var hbmClass = new HbmClass();
			var nid = new NaturalIdMapper(typeof(EntitySimpleWithNaturalId), hbmClass, mapdoc);
			// to have the natural-id assigned ot must have at least a property
			nid.Property(For<EntitySimpleWithNaturalId>.Property(x => x.Something), pm => { });

			var hbmNaturalId = hbmClass.naturalid;
			nid.Mutable(true);
			hbmNaturalId.mutable.Should().Be.True();
		}
        public ClassMapper(Type rootClass, HbmMapping mapDoc, MemberInfo idProperty)
            : base(rootClass, mapDoc)
        {
            classMapping = new HbmClass();
            var toAdd = new[] { classMapping };
            classMapping.name = rootClass.GetShortClassName(mapDoc);
            if(rootClass.IsAbstract)
            {
                classMapping.@abstract = true;
                classMapping.abstractSpecified = true;
            }

            var hbmId = new HbmId();
            classMapping.Item = hbmId;
            idMapper = new IdMapper(idProperty, hbmId);

            mapDoc.Items = mapDoc.Items == null ? toAdd : mapDoc.Items.Concat(toAdd).ToArray();
        }
		public void Bind(XmlNode node, HbmClass classSchema, IDictionary<string, MetaAttribute> inheritedMetas)
		{
			RootClass rootClass = new RootClass();
			BindClass(node, classSchema, rootClass, inheritedMetas);
			inheritedMetas = GetMetas(classSchema, inheritedMetas, true); // get meta's from <class>

			//TABLENAME
			string schema = classSchema.schema ?? mappings.SchemaName;
			string catalog = classSchema.catalog ?? mappings.CatalogName;
			string tableName = GetClassTableName(rootClass, classSchema);
			if (string.IsNullOrEmpty(tableName))
			{
				throw new MappingException(
					string.Format(
						"Could not determine the name of the table for entity '{0}'; remove the 'table' attribute or assign a value to it.",
						rootClass.EntityName));
			}

			Table table = mappings.AddTable(schema, catalog, tableName, null, rootClass.IsAbstract.GetValueOrDefault(), classSchema.schemaaction);
			((ITableOwner) rootClass).Table = table;

			log.InfoFormat("Mapping class: {0} -> {1}", rootClass.EntityName, rootClass.Table.Name);

			rootClass.IsMutable = classSchema.mutable;
			rootClass.Where = classSchema.where ?? rootClass.Where;

			if (classSchema.check != null)
				table.AddCheckConstraint(classSchema.check);

			rootClass.IsExplicitPolymorphism = classSchema.polymorphism == HbmPolymorphismType.Explicit;

			BindCache(classSchema.cache, rootClass);
			new ClassIdBinder(this).BindId(classSchema.Id, rootClass, table);
			new ClassCompositeIdBinder(this).BindCompositeId(classSchema.CompositeId, rootClass);
			new ClassDiscriminatorBinder(this).BindDiscriminator(classSchema.discriminator, rootClass, table);
			BindTimestamp(classSchema.Timestamp, rootClass, table, inheritedMetas);
			BindVersion(classSchema.Version, rootClass, table, inheritedMetas);

			rootClass.CreatePrimaryKey(dialect);

			PropertiesFromXML(node, rootClass, inheritedMetas);
			mappings.AddClass(rootClass);
		}
		private void AddRootClasses(HbmClass rootClass, IDictionary<string, MetaAttribute> inheritedMetas)
		{
			var binder = new RootClassBinder(Mappings, dialect);

			binder.Bind(rootClass, inheritedMetas);
		}