You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by rg...@apache.org on 2005/07/13 04:58:30 UTC

svn commit: r216095 - in /ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration: DomSqlMapBuilder.cs Statements/SelectKey.cs

Author: rgrabowski
Date: Tue Jul 12 19:58:29 2005
New Revision: 216095

URL: http://svn.apache.org/viewcvs?rev=216095&view=rev
Log:
Fix for IBATISNET-92: Check selectKey's property attribute for writeability during mapper initialization

Modified:
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/SelectKey.cs

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs?rev=216095&r1=216094&r2=216095&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs Tue Jul 12 19:58:29 2005
@@ -1148,8 +1148,15 @@
 				// Set sql statement SelectKey 
 				if (insert.SelectKey != null)
 				{
+					insert.SelectKey.Id = insert.Id;
 					insert.SelectKey.Initialize( _configScope );
-					insert.SelectKey.Id = insert.Id + DOT + "SelectKey";
+					insert.SelectKey.Id += DOT + "SelectKey";
+
+					// Initialize can also use _configScope.ErrorContext.ObjectId to get the id
+					// of the parent <select> node
+					// insert.SelectKey.Initialize( _configScope );
+					// insert.SelectKey.Id = insert.Id + DOT + "SelectKey";
+					
 					string commandText = xmlNode.SelectSingleNode( ApplyMappingNamespacePrefix(XML_SELECTKEY), _configScope.XmlNamespaceManager).FirstChild.InnerText.Replace('\n', ' ').Replace('\r', ' ').Replace('\t', ' ').Trim();
 					commandText = Resources.ParsePropertyTokens(commandText, _configScope.Properties);
 					StaticSql sql = new StaticSql(insert.SelectKey);

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/SelectKey.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/SelectKey.cs?rev=216095&r1=216094&r2=216095&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/SelectKey.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/SelectKey.cs Tue Jul 12 19:58:29 2005
@@ -26,10 +26,15 @@
 
 #region Imports
 using System;
+using System.Reflection;
 using System.Xml.Serialization;
-
+using IBatisNet.Common.Exceptions;
+using IBatisNet.Common.Utilities.Objects;
 using IBatisNet.DataMapper.Configuration.Alias;
 using IBatisNet.DataMapper.Exceptions;
+using IBatisNet.DataMapper.MappedStatements;
+using IBatisNet.DataMapper.Scope;
+
 #endregion
 
 namespace IBatisNet.DataMapper.Configuration.Statements
@@ -100,6 +105,42 @@
 		[Obsolete("This public constructor with no parameter is not really obsolete, but is reserved for serialization.", false)]
 		public SelectKey():base()
 		{
+		}
+		#endregion
+
+		#region Methods
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="configurationScope">The scope of the configuration</param>
+		override internal void Initialize(ConfigurationScope configurationScope)
+		{
+			// the propertyName attribute on the selectKey node is optional
+			if (PropertyName.Length > 0)
+			{
+				// Id is equal to the parent <select> node's "id" attribute
+				MappedStatement insert = configurationScope.SqlMapper.GetMappedStatement(Id);
+
+				Type insertParameterClass = insert.Statement.ParameterClass;
+
+				// make sure the PropertyName is a valid settable property of the <insert> node's parameterClass
+				if (insertParameterClass != null && 
+					configurationScope.TypeHandlerFactory.IsSimpleType(insertParameterClass) == false)
+				{
+					configurationScope.ErrorContext.MoreInfo = String.Format("Looking for settable property named '{0}' on type '{1}' for selectKey node of statement id '{2}'.",
+						PropertyName, // 0
+						insert.Statement.ParameterClass.Name, // 1
+						Id); // 2
+
+					// we expect this to throw an exception if the property cannot be found; GetSetter is
+					// called instead of HasWriteableProperty becuase we want the same wording for 
+					// property not found exceptions; GetSetter and HasWritableProperty both use the 
+					// same internal cache for looking up the ProperyInfo object
+					ReflectionInfo.GetInstance(insert.Statement.ParameterClass).GetSetter(PropertyName);
+				}
+			}
+
+			base.Initialize(configurationScope);
 		}
 		#endregion