Exemplo n.º 1
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));
            }
        }
Exemplo n.º 2
0
		/// <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;
		}