Esempio n. 1
0
		public override bool IsClassOrSuperclassJoin(Join join)
		{
			return base.IsClassOrSuperclassJoin(join) || Superclass.IsClassOrSuperclassJoin(join);
		}
Esempio n. 2
0
 public override void AddSubclassJoin(Join join)
 {
     base.AddSubclassJoin(join);
     Superclass.AddSubclassJoin(join);
 }
Esempio n. 3
0
 public virtual void AddJoin(Join join)
 {
     joins.Add(join);
     join.PersistentClass = this;
 }
Esempio n. 4
0
		protected void PropertiesFromXML(XmlNode node, PersistentClass model, IDictionary<string, MetaAttribute> inheritedMetas, UniqueKey uniqueKey, bool mutable, bool nullable, bool naturalId)
		{
			string entityName = model.EntityName;

			Table table = model.Table;

			foreach (XmlNode subnode in node.ChildNodes)
			{
				//I am only concerned with elements that are from the nhibernate namespace
				if (subnode.NamespaceURI != Configuration.MappingSchemaXMLNS)
					continue;

				string name = subnode.LocalName; //.Name;
				string propertyName = GetPropertyName(subnode);

				IValue value = null;
				CollectionBinder collectionBinder = new CollectionBinder(this);
				if (collectionBinder.CanCreate(name))
				{
					Mapping.Collection collection = collectionBinder.Create(name, subnode, entityName, propertyName, model,
					                                                        model.MappedClass, inheritedMetas);

					mappings.AddCollection(collection);
					value = collection;
				}
				else if ("many-to-one".Equals(name))
				{
					value = new ManyToOne(table);
					BindManyToOne(subnode, (ManyToOne) value, propertyName, true);
				}
				else if ("any".Equals(name))
				{
					value = new Any(table);
					BindAny(subnode, (Any) value, true);
				}
				else if ("one-to-one".Equals(name))
				{
					value = new OneToOne(table, model);
					BindOneToOne(subnode, (OneToOne) value);
				}
				else if ("property".Equals(name))
				{
					value = new SimpleValue(table);
					BindSimpleValue(subnode, (SimpleValue) value, true, propertyName);
				}
				else if ("component".Equals(name) || "dynamic-component".Equals(name))
				{
					string subpath = StringHelper.Qualify(entityName, propertyName);
					// NH: Modified from H2.1 to allow specifying the type explicitly using class attribute
					System.Type reflectedClass = GetPropertyType(subnode, model.MappedClass, propertyName);
					value = new Component(model);
					BindComponent(subnode, (Component) value, reflectedClass, entityName, propertyName, subpath, true, inheritedMetas);
				}
				else if ("join".Equals(name))
				{
					Join join = new Join();
					join.PersistentClass = model;
					BindJoin(subnode, join, inheritedMetas);
					model.AddJoin(join);
				}
				else if ("subclass".Equals(name))
					new SubclassBinder(this).HandleSubclass(model, subnode, inheritedMetas);

				else if ("joined-subclass".Equals(name))
					new JoinedSubclassBinder(this).HandleJoinedSubclass(model, subnode, inheritedMetas);

				else if ("union-subclass".Equals(name))
					new UnionSubclassBinder(this).HandleUnionSubclass(model, subnode, inheritedMetas);

				else if ("filter".Equals(name))
					ParseFilter(subnode, model);
				else if ("natural-id".Equals(name))
				{
					UniqueKey uk = new UniqueKey();
					uk.Name = "_UniqueKey";
					uk.Table = table;
					//by default, natural-ids are "immutable" (constant)

					bool mutableId = false;
					if (subnode.Attributes["mutable"] != null)
					{
						mutableId = "true".Equals(subnode.Attributes["mutable"]);						
					}

					PropertiesFromXML(subnode, model, inheritedMetas, uk, mutableId, false, true);
					table.AddUniqueKey(uk);
				}

				if (value != null)
				{
					Property property = CreateProperty(value, propertyName, model.ClassName, subnode, inheritedMetas);
					if (!mutable)
						property.IsUpdateable = false;
					if (naturalId)
						property.IsNaturalIdentifier = true;
					model.AddProperty(property);
					if (uniqueKey != null)
						uniqueKey.AddColumns(new SafetyEnumerable<Column>(property.ColumnIterator));
				}
			}
		}
		protected void BindJoins(IEnumerable<HbmJoin> joins, PersistentClass persistentClass, IDictionary<string, MetaAttribute> inheritedMetas)
		{
			foreach (var hbmJoin in joins)
			{
				var join = new Join { PersistentClass = persistentClass };
				BindJoin(hbmJoin, join, inheritedMetas);
				persistentClass.AddJoin(join);
			}
		}
Esempio n. 6
0
		public Component(Join join)
			: base(join.Table)
		{
			owner = join.PersistentClass;
		}
		/// <summary>
		/// A non null propertyHolder means than we process the Pk creation without delay
		/// </summary>
		/// <param name="secondaryTable"></param>
		/// <param name="joinTable"></param>
		/// <param name="propertyHolder"></param>
		/// <param name="noDelayInPkColumnCreation"></param>
		/// <returns></returns>
		private Join AddJoin(SecondaryTableAttribute secondaryTable,
			JoinTableAttribute joinTable,
			IPropertyHolder propertyHolder,
			bool noDelayInPkColumnCreation)
		{
			Join join = new Join();
			join.PersistentClass = persistentClass;
			string schema;
			string catalog;
			string table;
			string realTable;

			System.Persistence.UniqueConstraintAttribute[] uniqueConstraintsAnn;
			if (secondaryTable != null)
			{
				schema = secondaryTable.Schema;
				catalog = secondaryTable.Catalog;
				table = secondaryTable.Name;
				realTable = mappings.NamingStrategy.TableName(table); //always an explicit table name
				uniqueConstraintsAnn = secondaryTable.UniqueConstraints;
			}
			else if (joinTable != null)
			{
				schema = joinTable.Schema;
				catalog = joinTable.Catalog;
				table = joinTable.Name;
				realTable = mappings.NamingStrategy.TableName(table); //always an explicit table name
				uniqueConstraintsAnn = joinTable.UniqueConstraints;
			}
			else
			{
				throw new AssertionFailure("Both JoinTable and SecondaryTable are null");
			}

			var uniqueConstraints = new List<string[]>(uniqueConstraintsAnn == null ? 0 : uniqueConstraintsAnn.Length);
			if (uniqueConstraintsAnn != null && uniqueConstraintsAnn.Length != 0)
			{
				foreach (UniqueConstraintAttribute uc in uniqueConstraintsAnn)
				{
					uniqueConstraints.Add(uc.ColumnNames);
				}
			}
			Table tableMapping = TableBinder.FillTable(
					schema,
					catalog,
					realTable,
					table, false, uniqueConstraints, null, null, mappings);
			//no check constraints available on joins
			join.Table = tableMapping;

			//somehow keep joins() for later.
			//Has to do the work later because it needs persistentClass id!
			object joinColumns = null;
			//get the appropriate pk columns
			if (secondaryTable != null)
			{
				joinColumns = secondaryTable.PkJoinColumns;
			}
			else if (joinTable != null)
			{
				joinColumns = joinTable.JoinColumns;
			}
			log.InfoFormat("Adding secondary table to entity {0} -> {1}", persistentClass.EntityName, join.Table.Name);

			TableAttribute matchingTable = FindMatchingComplimentTableAnnotation(join);

			if (matchingTable != null)
			{
				join.IsSequentialSelect = FetchMode.Join != matchingTable.Fetch;
				join.IsInverse = matchingTable.IsInverse;
				join.IsOptional = matchingTable.IsOptional;
				if (!BinderHelper.IsDefault(matchingTable.SqlInsert.Sql))
				{
					join.SetCustomSQLInsert(matchingTable.SqlInsert.Sql.Trim(),
							matchingTable.SqlInsert.Callable,
							ExecuteUpdateResultCheckStyle.Parse(matchingTable.SqlInsert.Check.ToString().ToLower()));
				}
				if (!BinderHelper.IsDefault(matchingTable.SqlUpdate.Sql))
				{
					join.SetCustomSQLUpdate(matchingTable.SqlUpdate.Sql.Trim(),
							matchingTable.SqlUpdate.Callable,
							ExecuteUpdateResultCheckStyle.Parse(matchingTable.SqlUpdate.Check.ToString().ToLower())
					);
				}
				if (!BinderHelper.IsDefault(matchingTable.SqlDelete.Sql))
				{
					join.SetCustomSQLDelete(matchingTable.SqlDelete.Sql.Trim(),
							matchingTable.SqlDelete.Callable,
							ExecuteUpdateResultCheckStyle.Parse(matchingTable.SqlDelete.Check.ToString().ToLower())
					);
				}
			}
			else
			{
				//default
				join.IsSequentialSelect = false;
				join.IsInverse = false;
				join.IsOptional = false; //perhaps not quite per-spec, but a Good Thing anyway
			}

			if (noDelayInPkColumnCreation)
			{
				CreatePrimaryColumnsToSecondaryTable(joinColumns, propertyHolder, join);
			}
			else
			{
				secondaryTables.Add(table, join);
				secondaryTableJoins.Add(table, joinColumns);
			}
			return join;
		}
Esempio n. 8
0
 public virtual void AddSubclassJoin(Join join)
 {
     subclassJoins.Add(join);
 }
		private void SetFKNameIfDefined(Join join)
		{
			TableAttribute matchingTable = FindMatchingComplimentTableAnnotation(join);
			if (matchingTable != null && !BinderHelper.IsDefault(matchingTable.ForeignKey.Name))
			{
				((SimpleValue)join.Key).ForeignKeyName = matchingTable.ForeignKey.Name;
			}
		}
Esempio n. 10
0
		private TableAttribute FindMatchingComplimentTableAnnotation(Join join)
		{
			String tableName = join.Table.GetQuotedName();
			var table = annotatedClass.GetAttribute<TableAttribute>();
			TableAttribute matchingTable = null;
			if (table != null && tableName.Equals(table.AppliesTo))
			{
				matchingTable = table;
			}
			else
			{
				//TODO: Review the way to treat Multiples attributes
				//Tables tables = annotatedClass.getAnnotation( Tables.class );
				//if ( tables != null ) {
				//    for (org.hibernate.annotations.Table current : tables.value()) {
				//        if ( tableName.equals( current.appliesTo() ) ) {
				//            matchingTable = current;
				//            break;
				//        }
				//    }
				//}
			}
			return matchingTable;
		}
Esempio n. 11
0
		private void BindJoinToPersistentClass(Join join, Ejb3JoinColumn[] ejb3JoinColumns)
		{
			SimpleValue key = new DependantValue(join.Table, persistentClass.Identifier);
			join.Key = key;
			SetFKNameIfDefined(join);
			key.IsCascadeDeleteEnabled = false;
			TableBinder.BindFk(persistentClass, null, ejb3JoinColumns, key, false, mappings);
			join.CreatePrimaryKey(dialect);
			join.CreateForeignKey();
			persistentClass.AddJoin(join);
		}
Esempio n. 12
0
		private void CreatePrimaryColumnsToSecondaryTable(object uncastedColumn, IPropertyHolder propertyHolder, Join join)
		{
			Ejb3JoinColumn[] ejb3JoinColumns;
			PrimaryKeyJoinColumnAttribute[] pkColumnsAnn = null;
			JoinColumnAttribute[] joinColumnsAnn = null;
			if (uncastedColumn is PrimaryKeyJoinColumnAttribute[])
			{
				pkColumnsAnn = (PrimaryKeyJoinColumnAttribute[])uncastedColumn;
			}
			if (uncastedColumn is JoinColumnAttribute[])
			{
				joinColumnsAnn = (JoinColumnAttribute[])uncastedColumn;
			}
			if (pkColumnsAnn == null && joinColumnsAnn == null)
			{
				ejb3JoinColumns = new Ejb3JoinColumn[1];
				ejb3JoinColumns[0] = Ejb3JoinColumn.BuildJoinColumn(
						null,
						null,
						persistentClass.Identifier,
						secondaryTables,
						propertyHolder, mappings
				);
			}
			else
			{
				int nbrOfJoinColumns = pkColumnsAnn != null ?
						pkColumnsAnn.Length :
						joinColumnsAnn.Length;
				if (nbrOfJoinColumns == 0)
				{
					ejb3JoinColumns = new Ejb3JoinColumn[1];
					ejb3JoinColumns[0] = Ejb3JoinColumn.BuildJoinColumn(
							null,
							null,
							persistentClass.Identifier,
							secondaryTables,
							propertyHolder, mappings
					);
				}
				else
				{
					ejb3JoinColumns = new Ejb3JoinColumn[nbrOfJoinColumns];
					if (pkColumnsAnn != null)
					{
						for (int colIndex = 0; colIndex < nbrOfJoinColumns; colIndex++)
						{
							ejb3JoinColumns[colIndex] = Ejb3JoinColumn.BuildJoinColumn(
									pkColumnsAnn[colIndex],
									null,
									persistentClass.Identifier,
									secondaryTables,
									propertyHolder, mappings
							);
						}
					}
					else
					{
						for (int colIndex = 0; colIndex < nbrOfJoinColumns; colIndex++)
						{
							ejb3JoinColumns[colIndex] = Ejb3JoinColumn.BuildJoinColumn(
									null,
									joinColumnsAnn[colIndex],
									persistentClass.Identifier,
									secondaryTables,
									propertyHolder, mappings
							);
						}
					}
				}
			}

			foreach (Ejb3JoinColumn joinColumn in ejb3JoinColumns)
			{
				joinColumn.ForceNotNull();
			}
			BindJoinToPersistentClass(join, ejb3JoinColumns);
		}
Esempio n. 13
0
 public Component(Join join)
     : base(join.Table)
 {
     owner = join.PersistentClass;
 }
Esempio n. 14
0
 public override bool IsClassOrSuperclassJoin(Join join)
 {
     return(base.IsClassOrSuperclassJoin(join) || Superclass.IsClassOrSuperclassJoin(join));
 }
Esempio n. 15
0
		private void BindJoin(HbmJoin joinMapping, Join join, IDictionary<string, MetaAttribute> inheritedMetas)
		{
			PersistentClass persistentClass = join.PersistentClass;

			// TABLENAME
			string schema = joinMapping.schema ?? mappings.SchemaName;
			string catalog = joinMapping.catalog ?? mappings.CatalogName;

			string action = "all"; // joinMapping.schemaaction ?? "all";

			string tableName = joinMapping.table;
			Table table = mappings.AddTable(schema, catalog, GetClassTableName(persistentClass, tableName), joinMapping.Subselect, false, action);
			join.Table = table;

			join.IsSequentialSelect = joinMapping.fetch == HbmJoinFetch.Select;
			join.IsInverse = joinMapping.inverse;
			join.IsOptional = joinMapping.optional;

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

			// KEY
			SimpleValue key;
			if (!String.IsNullOrEmpty(joinMapping.key.propertyref))
			{
				string propertyRef = joinMapping.key.propertyref;
				var propertyRefKey = new SimpleValue(persistentClass.Table)
					{
						IsAlternateUniqueKey = true
					};
				var property = persistentClass.GetProperty(propertyRef);
				join.RefIdProperty = property;
				//we only want one column
				var column = (Column) property.ColumnIterator.First();
				if (!column.Unique)
					throw new MappingException(
						string.Format(
							"Property {0}, on class {1} must be marked as unique to be joined to with a property-ref.",
							property.Name,
							persistentClass.ClassName));
				propertyRefKey.AddColumn(column);
				propertyRefKey.TypeName = property.Type.Name;
				key = new ReferenceDependantValue(table, propertyRefKey);
			}
			else
			{
				key = new DependantValue(table, persistentClass.Identifier);
			}

			key.ForeignKeyName = joinMapping.key.foreignkey;
			join.Key = key;
			key.IsCascadeDeleteEnabled = joinMapping.key.ondelete == HbmOndelete.Cascade;
			new ValuePropertyBinder(key, Mappings).BindSimpleValue(joinMapping.key, persistentClass.EntityName, false);

			join.CreatePrimaryKey(dialect);
			join.CreateForeignKey();

			// PROPERTIES
			new PropertiesBinder(Mappings, persistentClass, dialect).Bind(joinMapping.Properties, join.Table,
																							inheritedMetas, p => { },
																							join.AddProperty);

			// CUSTOM SQL
			HandleCustomSQL(joinMapping, join);
		}
Esempio n. 16
0
 public virtual void AddJoin(Join join)
 {
     joins.Add(join);
     join.PersistentClass = this;
 }
Esempio n. 17
0
        private void HandleCustomSQL(XmlNode node, Join model)
        {
            XmlNode element = node.SelectSingleNode(HbmConstants.nsSqlInsert, namespaceManager);
            if (element != null)
            {
                bool callable = IsCallable(element);
                model.SetCustomSQLInsert(element.InnerText.Trim(), callable, GetResultCheckStyle(element, callable));
            }

            element = node.SelectSingleNode(HbmConstants.nsSqlDelete, namespaceManager);
            if (element != null)
            {
                bool callable = IsCallable(element);
                model.SetCustomSQLDelete(element.InnerText.Trim(), callable, GetResultCheckStyle(element, callable));
            }

            element = node.SelectSingleNode(HbmConstants.nsSqlUpdate, namespaceManager);
            if (element != null)
            {
                bool callable = IsCallable(element);
                model.SetCustomSQLUpdate(element.InnerText.Trim(), callable, GetResultCheckStyle(element, callable));
            }
        }
Esempio n. 18
0
 public virtual bool IsClassOrSuperclassJoin(Join join)
 {
     return(joins.Contains(join));
 }
Esempio n. 19
0
        protected void PropertiesFromXML(XmlNode node, PersistentClass model)
        {
            Table table = model.Table;

            foreach (XmlNode subnode in node.ChildNodes)
            {
                //I am only concerned with elements that are from the nhibernate namespace
                if (subnode.NamespaceURI != Configuration.MappingSchemaXMLNS)
                    continue;

                string name = subnode.LocalName; //.Name;
                string propertyName = GetPropertyName(subnode);

                IValue value = null;
                CollectionBinder collectionBinder = new CollectionBinder(this);
                if (collectionBinder.CanCreate(name))
                {
                    Mapping.Collection collection = collectionBinder.Create(name, subnode, model.EntityName,
                        propertyName, model, model.MappedClass);

                    mappings.AddCollection(collection);
                    value = collection;
                }
                else if ("many-to-one".Equals(name))
                {
                    value = new ManyToOne(table);
                    BindManyToOne(subnode, (ManyToOne) value, propertyName, true);
                }
                else if ("any".Equals(name))
                {
                    value = new Any(table);
                    BindAny(subnode, (Any) value, true);
                }
                else if ("one-to-one".Equals(name))
                {
                    value = new OneToOne(table, model);
                    BindOneToOne(subnode, (OneToOne) value);
                }
                else if ("property".Equals(name))
                {
                    value = new SimpleValue(table);
                    BindSimpleValue(subnode, (SimpleValue) value, true, propertyName);
                }
                else if ("component".Equals(name) || "dynamic-component".Equals(name))
                {
                    // NH: Modified from H2.1 to allow specifying the type explicitly using class attribute
                    System.Type reflectedClass = GetPropertyType(subnode, model.MappedClass, propertyName);
                    value = new Component(model);
                    BindComponent(subnode, (Component) value, reflectedClass, model.EntityName, propertyName, true);
                }
                else if ("join".Equals(name))
                {
                    Join join = new Join();
                    join.PersistentClass = model;
                    BindJoin(subnode, join);
                    model.AddJoin(join);
                }
                else if ("subclass".Equals(name))
                    new SubclassBinder(this).HandleSubclass(model, subnode);

                else if ("joined-subclass".Equals(name))
                    new JoinedSubclassBinder(this).HandleJoinedSubclass(model, subnode);

                else if ("union-subclass".Equals(name))
                    new UnionSubclassBinder(this).HandleUnionSubclass(model, subnode);

                else if ("filter".Equals(name))
                    ParseFilter(subnode, model);

                if (value != null)
                    model.AddProperty(CreateProperty(value, propertyName, model.MappedClass, subnode));
            }
        }
		private void BindJoin(HbmJoin joinMapping, Join join, IDictionary<string, MetaAttribute> inheritedMetas)
		{
			PersistentClass persistentClass = join.PersistentClass;

			// TABLENAME
			string schema = joinMapping.schema ?? mappings.SchemaName;
			string catalog = joinMapping.catalog ?? mappings.CatalogName;

			string action = "all"; // joinMapping.schemaaction ?? "all";

			string tableName = joinMapping.table;
			Table table = mappings.AddTable(schema, catalog, GetClassTableName(persistentClass, tableName), joinMapping.Subselect, false, action);
			join.Table = table;

			join.IsSequentialSelect = joinMapping.fetch == HbmJoinFetch.Select;
			join.IsInverse = joinMapping.inverse;
			join.IsOptional = joinMapping.optional;

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

			// KEY
			SimpleValue key = new DependantValue(table, persistentClass.Identifier);
			key.ForeignKeyName = joinMapping.key.foreignkey;
			join.Key = key;
			key.IsCascadeDeleteEnabled = joinMapping.key.ondelete == HbmOndelete.Cascade;
			new ValuePropertyBinder(key, Mappings).BindSimpleValue(joinMapping.key, persistentClass.EntityName, false);

			join.CreatePrimaryKey(dialect);
			join.CreateForeignKey();

			// PROPERTIES
			new PropertiesBinder(Mappings, persistentClass, dialect).Bind(joinMapping.Properties, join.Table,
			                                                                                inheritedMetas, p => { },
			                                                                                join.AddProperty);

			// CUSTOM SQL
			HandleCustomSQL(joinMapping, join);
		}
Esempio n. 21
0
        private void BindJoin(XmlNode node, Join join)
        {
            PersistentClass persistentClass = join.PersistentClass;
            String path = persistentClass.EntityName;

            // TABLENAME

            XmlAttribute schemaNode = node.Attributes["schema"];
            string schema = schemaNode == null ? mappings.SchemaName : schemaNode.Value;
            XmlAttribute catalogNode = node.Attributes["catalog"];
            string catalog = catalogNode == null ? mappings.CatalogName : catalogNode.Value;

            Table table = mappings.AddTable(schema, catalog, GetClassTableName(persistentClass, node), null, false);
            join.Table = table;

            XmlAttribute fetchNode = node.Attributes["fetch"];
            if (fetchNode != null)
                join.IsSequentialSelect = "select".Equals(fetchNode.Value);

            XmlAttribute invNode = node.Attributes["inverse"];
            if (invNode != null)
                join.IsInverse = "true".Equals(invNode.Value);

            XmlAttribute nullNode = node.Attributes["optional"];
            if (nullNode != null)
                join.IsOptional = "true".Equals(nullNode.Value);

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

            // KEY
            XmlNode keyNode = node.SelectSingleNode(HbmConstants.nsKey, namespaceManager);
            SimpleValue key = new DependantValue(table, persistentClass.Identifier);
            join.Key = key;
            if (keyNode.Attributes["on-delete"] != null)
                key.IsCascadeDeleteEnabled = "cascade".Equals(keyNode.Attributes["on-delete"].Value);
            BindSimpleValue(keyNode, key, false, persistentClass.EntityName);

            join.CreatePrimaryKey(dialect);
            join.CreateForeignKey();

            // PROPERTIES
            //PropertiesFromXML(node, persistentClass, mappings);
            foreach (XmlNode subnode in node.ChildNodes)
            {
                string name = subnode.Name;
                XmlAttribute nameAttribute = subnode.Attributes["name"];
                string propertyName = nameAttribute == null ? null : nameAttribute.Value;

                IValue value = null;
                switch (name)
                {
                    case "many-to-one":
                        value = new ManyToOne(table);
                        BindManyToOne(subnode, (ManyToOne) value, propertyName, true);
                        break;
                    case "any":
                        value = new Any(table);
                        BindAny(subnode, (Any) value, true);
                        break;
                    case "property":
                        value = new SimpleValue(table);
                        BindSimpleValue(subnode, (SimpleValue) value, true, propertyName);
                        break;
                    case "component":
                    case "dynamic-component":
                        string subpath = StringHelper.Qualify(path, propertyName);
                        value = new Component(join);
                        BindComponent(
                            subnode,
                            (Component) value,
                            join.PersistentClass.MappedClass,
                            propertyName,
                            subpath,
                            true);
                        break;
                }

                if (value != null)
                {
                    Mapping.Property prop = CreateProperty(value, propertyName, persistentClass.MappedClass, subnode);
                    prop.IsOptional = join.IsOptional;
                    join.AddProperty(prop);
                }
            }

            // CUSTOM SQL
            HandleCustomSQL(node, join);
        }
Esempio n. 22
0
 public virtual bool IsClassOrSuperclassJoin(Join join)
 {
     return joins.Contains(join);
 }
Esempio n. 23
0
		public override void AddSubclassJoin(Join join)
		{
			base.AddSubclassJoin(join);
			Superclass.AddSubclassJoin(join);
		}
Esempio n. 24
0
 public virtual void AddSubclassJoin(Join join)
 {
     subclassJoins.Add(join);
 }
Esempio n. 25
0
		private void BindJoin(XmlNode node, Join join, IDictionary<string, MetaAttribute> inheritedMetas)
		{
			PersistentClass persistentClass = join.PersistentClass;
			String path = persistentClass.EntityName;

			// TABLENAME

			XmlAttribute schemaNode = node.Attributes["schema"];
			string schema = schemaNode == null ? mappings.SchemaName : schemaNode.Value;
			XmlAttribute catalogNode = node.Attributes["catalog"];
			string catalog = catalogNode == null ? mappings.CatalogName : catalogNode.Value;

			XmlAttribute actionNode = node.Attributes["schema-action"];
			string action = actionNode == null ? "all" : actionNode.Value;

			Table table = mappings.AddTable(schema, catalog, GetClassTableName(persistentClass, node), null, false, action);
			join.Table = table;

			XmlAttribute fetchNode = node.Attributes["fetch"];
			if (fetchNode != null)
				join.IsSequentialSelect = "select".Equals(fetchNode.Value);

			XmlAttribute invNode = node.Attributes["inverse"];
			if (invNode != null)
				join.IsInverse = "true".Equals(invNode.Value);

			XmlAttribute nullNode = node.Attributes["optional"];
			if (nullNode != null)
				join.IsOptional = "true".Equals(nullNode.Value);

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

			// KEY
			XmlNode keyNode = node.SelectSingleNode(HbmConstants.nsKey, namespaceManager);
			SimpleValue key = new DependantValue(table, persistentClass.Identifier);
			join.Key = key;
			if (keyNode.Attributes["on-delete"] != null)
				key.IsCascadeDeleteEnabled = "cascade".Equals(keyNode.Attributes["on-delete"].Value);
			BindSimpleValue(keyNode, key, false, persistentClass.EntityName);

			join.CreatePrimaryKey(dialect);
			join.CreateForeignKey();

			// PROPERTIES
			//PropertiesFromXML(node, persistentClass, mappings);
			foreach (XmlNode subnode in node.ChildNodes)
			{
				//I am only concerned with elements that are from the nhibernate namespace
				if (subnode.NamespaceURI != Configuration.MappingSchemaXMLNS)
					continue;

				string name = subnode.Name;
				XmlAttribute nameAttribute = subnode.Attributes["name"];
				string propertyName = nameAttribute == null ? null : nameAttribute.Value;
				IValue value = null;
				var collectionBinder = new CollectionBinder(this);
				if (collectionBinder.CanCreate(name))
				{
					Mapping.Collection collection = collectionBinder.Create(name, subnode, persistentClass.EntityName, propertyName,
					                                                        persistentClass, persistentClass.MappedClass,
					                                                        inheritedMetas);

					mappings.AddCollection(collection);
					value = collection;
				}
				else
				{
					switch (name)
					{
						case "many-to-one":
							value = new ManyToOne(table);
							BindManyToOne(subnode, (ManyToOne) value, propertyName, true);
							break;
						case "any":
							value = new Any(table);
							BindAny(subnode, (Any) value, true);
							break;
						case "property":
							value = new SimpleValue(table);
							BindSimpleValue(subnode, (SimpleValue) value, true, propertyName);
							break;
						case "component":
						case "dynamic-component":
							string subpath = StringHelper.Qualify(path, propertyName);
							value = new Component(join);
							BindComponent(subnode, (Component) value, join.PersistentClass.MappedClass, join.PersistentClass.ClassName,
							              propertyName, subpath, true, inheritedMetas);
							break;
					}
				}
				if (value != null)
				{
					var prop = CreateProperty(value, propertyName, persistentClass.MappedClass.AssemblyQualifiedName, subnode,
					                          inheritedMetas);
					prop.IsOptional = join.IsOptional;
					join.AddProperty(prop);
				}
			}

			// CUSTOM SQL
			HandleCustomSQL(node, join);
		}