protected void BindClass(XmlNode node, PersistentClass model)
        {
            string className = node.Attributes["name"] == null ? null : FullClassName(node.Attributes["name"].Value, mappings);

            // CLASS
            model.ClassName = ClassForFullNameChecked(className, "persistent class {0} not found").AssemblyQualifiedName;

            string entityName = node.Attributes["entity-name"] == null ? null : node.Attributes["name"].Value;
            if (entityName == null)
                entityName = model.MappedClass.FullName;
            if (entityName == null)
            {
                throw new MappingException("Unable to determine entity name");
            }
            model.EntityName = entityName;

            // PROXY INTERFACE
            XmlAttribute proxyNode = node.Attributes["proxy"];
            XmlAttribute lazyNode = node.Attributes["lazy"];
            bool lazy = lazyNode == null ? mappings.DefaultLazy : "true".Equals(lazyNode.Value);

            // go ahead and set the lazy here, since pojo.proxy can override it.
            model.IsLazy = lazy;

            if (proxyNode != null)
            {
                model.ProxyInterfaceName = ClassForNameChecked(proxyNode.Value, mappings, "proxy class not found: {0}").AssemblyQualifiedName;
                model.IsLazy = true;
            }
            else if (model.IsLazy)
                model.ProxyInterfaceName = model.MappedClass.AssemblyQualifiedName;

            // DISCRIMINATOR
            XmlAttribute discriminatorNode = node.Attributes["discriminator-value"];
            model.DiscriminatorValue = (discriminatorNode == null) ? model.EntityName : discriminatorNode.Value;

            // DYNAMIC UPDATE
            XmlAttribute dynamicNode = node.Attributes["dynamic-update"];
            model.DynamicUpdate = (dynamicNode == null) ? false : "true".Equals(dynamicNode.Value);

            // DYNAMIC INSERT
            XmlAttribute insertNode = node.Attributes["dynamic-insert"];
            model.DynamicInsert = (insertNode == null) ? false : "true".Equals(insertNode.Value);

            // IMPORT

            // we automatically want to add an import of the Assembly Qualified Name (includes version,
            // culture, public-key) to the className supplied in the hbm.xml file.  The most common use-case
            // will have it contain the "FullClassname, AssemblyName", it might contain version, culture,
            // public key, etc...) but should not assume it does.
            mappings.AddImport(model.MappedClass.AssemblyQualifiedName, StringHelper.GetFullClassname(className));

            // if we are supposed to auto-import the Class then add an import to get from the Classname
            // to the Assembly Qualified Class Name
            if (mappings.IsAutoImport)
                mappings.AddImport(model.MappedClass.AssemblyQualifiedName, StringHelper.GetClassname(className));

            // BATCH SIZE
            XmlAttribute batchNode = node.Attributes["batch-size"];
            if (batchNode != null)
                model.BatchSize = int.Parse(batchNode.Value);

            // SELECT BEFORE UPDATE
            XmlAttribute sbuNode = node.Attributes["select-before-update"];
            if (sbuNode != null)
                model.SelectBeforeUpdate = "true".Equals(sbuNode.Value);

            // OPTIMISTIC LOCK MODE
            XmlAttribute olNode = node.Attributes["optimistic-lock"];
            model.OptimisticLockMode = GetOptimisticLockMode(olNode);

            // META ATTRIBUTES
            model.MetaAttributes = GetMetas(node);

            // PERSISTER
            XmlAttribute persisterNode = node.Attributes["persister"];
            if (persisterNode == null)
            {
                //persister = typeof( EntityPersister );
            }
            else
                model.EntityPersisterClass =
                    ClassForNameChecked(persisterNode.Value, mappings, "could not instantiate persister class: {0}");

            // CUSTOM SQL
            HandleCustomSQL(node, model);

            foreach (XmlNode syncNode in node.SelectNodes(HbmConstants.nsSynchronize, namespaceManager))
                model.AddSynchronizedTable(XmlHelper.GetAttributeValue(syncNode, "table"));

            bool? isAbstract = null;
            XmlAttribute abstractNode = node.Attributes["abstract"];
            if (abstractNode != null)
            {
                if ("true".Equals(abstractNode.Value) || "1".Equals(abstractNode.Value))
                    isAbstract = true;
                else if ("false".Equals(abstractNode.Value) || "0".Equals(abstractNode.Value))
                    isAbstract = false;
            }
            model.IsAbstract = isAbstract;
        }
		private void BindPersistentClassCommonValues(IEntityMapping classMapping, PersistentClass model, IDictionary<string, MetaAttribute> inheritedMetas)
		{
			// DISCRIMINATOR
			var discriminable = classMapping as IEntityDiscriminableMapping;
			model.DiscriminatorValue = (discriminable == null || string.IsNullOrEmpty(discriminable.DiscriminatorValue)) ? model.EntityName : discriminable.DiscriminatorValue;

			// DYNAMIC UPDATE
			model.DynamicUpdate = classMapping.DynamicUpdate;

			// DYNAMIC INSERT
			model.DynamicInsert = classMapping.DynamicInsert;

			// IMPORT
			// For entities, the EntityName is the key to find a persister
			// NH Different behavior: we are using the association between EntityName and its more certain implementation (AssemblyQualifiedName)
			// Dynamic entities have no class, reverts to EntityName. -AK
			string qualifiedName = model.MappedClass == null ? model.EntityName : model.MappedClass.AssemblyQualifiedName;
			mappings.AddImport(qualifiedName, model.EntityName);
			if (mappings.IsAutoImport && model.EntityName.IndexOf('.') > 0)
				mappings.AddImport(qualifiedName, StringHelper.Unqualify(model.EntityName));

			// BATCH SIZE
			if (classMapping.BatchSize.HasValue)
				model.BatchSize = classMapping.BatchSize.Value;

			// SELECT BEFORE UPDATE
			model.SelectBeforeUpdate = classMapping.SelectBeforeUpdate;

			// META ATTRIBUTES
			model.MetaAttributes = GetMetas(classMapping, inheritedMetas);

			// PERSISTER
			if(!string.IsNullOrEmpty(classMapping.Persister))
				model.EntityPersisterClass = ClassForNameChecked(classMapping.Persister, mappings,
				                                                 "could not instantiate persister class: {0}");

			// CUSTOM SQL
			HandleCustomSQL(classMapping, model);
			if (classMapping.SqlLoader != null)
				model.LoaderName = classMapping.SqlLoader.queryref;

			foreach (var synchronize in classMapping.Synchronize)
			{
				model.AddSynchronizedTable(synchronize.table);
			}

			model.IsAbstract = classMapping.IsAbstract;
		}
Beispiel #3
0
		private void BindPersistentClassCommonValues(XmlNode node, IDecoratable classMapping, PersistentClass model, IDictionary<string, MetaAttribute> inheritedMetas)
		{
			// DISCRIMINATOR
			XmlAttribute discriminatorNode = node.Attributes["discriminator-value"];
			model.DiscriminatorValue = (discriminatorNode == null) ? model.EntityName : discriminatorNode.Value;

			// DYNAMIC UPDATE
			XmlAttribute dynamicNode = node.Attributes["dynamic-update"];
			model.DynamicUpdate = (dynamicNode == null) ? false : "true".Equals(dynamicNode.Value);

			// DYNAMIC INSERT
			XmlAttribute insertNode = node.Attributes["dynamic-insert"];
			model.DynamicInsert = (insertNode == null) ? false : "true".Equals(insertNode.Value);

			// IMPORT
			// For entities, the EntityName is the key to find a persister
			// NH Different behavior: we are using the association between EntityName and its more certain implementation (AssemblyQualifiedName)
			// Dynamic entities have no class, reverts to EntityName. -AK
			string qualifiedName = model.MappedClass == null ? model.EntityName : model.MappedClass.AssemblyQualifiedName;
			mappings.AddImport(qualifiedName, model.EntityName);
			if (mappings.IsAutoImport && model.EntityName.IndexOf('.') > 0)
				mappings.AddImport(qualifiedName, StringHelper.Unqualify(model.EntityName));

			// BATCH SIZE
			XmlAttribute batchNode = node.Attributes["batch-size"];
			if (batchNode != null)
				model.BatchSize = int.Parse(batchNode.Value);

			// SELECT BEFORE UPDATE
			XmlAttribute sbuNode = node.Attributes["select-before-update"];
			if (sbuNode != null)
				model.SelectBeforeUpdate = "true".Equals(sbuNode.Value);

			// OPTIMISTIC LOCK MODE
			XmlAttribute olNode = node.Attributes["optimistic-lock"];
			model.OptimisticLockMode = GetOptimisticLockMode(olNode);

			// META ATTRIBUTES
			model.MetaAttributes = classMapping != null
			                       	? GetMetas(classMapping, inheritedMetas)
			                       	: GetMetas(node.SelectNodes(HbmConstants.nsMeta, namespaceManager), inheritedMetas);

			// PERSISTER
			XmlAttribute persisterNode = node.Attributes["persister"];
			if (persisterNode == null)
			{
				//persister = typeof( EntityPersister );
			}
			else
				model.EntityPersisterClass = ClassForNameChecked(persisterNode.Value, mappings,
				                                                 "could not instantiate persister class: {0}");

			// CUSTOM SQL
			HandleCustomSQL(node, model);

			foreach (XmlNode syncNode in node.SelectNodes(HbmConstants.nsSynchronize, namespaceManager))
				model.AddSynchronizedTable(XmlHelper.GetAttributeValue(syncNode, "table"));

			bool? isAbstract = null;
			XmlAttribute abstractNode = node.Attributes["abstract"];
			if (abstractNode != null)
			{
				if ("true".Equals(abstractNode.Value) || "1".Equals(abstractNode.Value))
					isAbstract = true;
				else if ("false".Equals(abstractNode.Value) || "0".Equals(abstractNode.Value))
					isAbstract = false;
			}
			model.IsAbstract = isAbstract;
		}