Author: gbayon
Date: Sat Sep 15 03:40:19 2007
New Revision: 575902

URL: http://svn.apache.org/viewvc?rev=575902&view=rev
Log:
Fix IBATISNET-239
+ corrected bug in NullableTimeSpanTypeHandler and EnumTypeHandler

Modified:
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Category.xml
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/MSSQL/ProcedureTest.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/category-procedureWithReturn.sql
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterMap.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterProperty.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/EnumTypeHandler.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/Nullables/NullableTimeSpanTypeHandler.cs

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Category.xml
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Category.xml?rev=575902&r1=575901&r2=575902&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Category.xml
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Category.xml
 Sat Sep 15 03:40:19 2007
@@ -167,7 +167,7 @@
                </parameterMap>
                        
                <parameterMap id="insert-params" class="Category">
-                       <parameter property="Name" column="Category_Name"/>
+                       <parameter property="Name" column="Category_Name" />
                        <parameter property="Id" column="Category_Id" 
dbType="Int" /><!-- Int for SqlClient, Obdc; Integer for Oledb -->
                        <parameter property="Guid" column="Category_Guid" 
dbType="UniqueIdentifier"/><!--Guid for Oledb, UniqueIdentifier for 
SqlClient,Odbc -->
                </parameterMap>

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/MSSQL/ProcedureTest.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/MSSQL/ProcedureTest.cs?rev=575902&r1=575901&r2=575902&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/MSSQL/ProcedureTest.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/MSSQL/ProcedureTest.cs
 Sat Sep 15 03:40:19 2007
@@ -2,6 +2,7 @@
 using System.Collections;
 using IBatisNet.DataMapper.Test.Domain;
 using NUnit.Framework;
+using NUnit.Framework.SyntaxHelpers;
 
 namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests.MSSQL
 {
@@ -53,13 +54,15 @@
             category.Name = "Mapping object relational";
 
             int categoryID = ( int ) sqlMap.Insert ( 
"InsertCategoryViaStoreProcedureWithReturn", category );
-            Assert.AreEqual ( 1, categoryID );
+            Assert.That(categoryID, Is.EqualTo(1));
+            Assert.That(category.Id, Is.EqualTo(1));
 
             Category category2 = new Category ( );
             category2.Name = "Nausicaa";
 
             int categoryID2 = ( int ) sqlMap.Insert ( 
"InsertCategoryViaStoreProcedureWithReturn", category2 );
-            Assert.AreEqual ( 2, categoryID2 );
+            Assert.That(categoryID2, Is.EqualTo(2));
+            Assert.That(category2.Id, Is.EqualTo(2));
 
             Category category3 = sqlMap.QueryForObject<Category> ( 
"GetCategory", categoryID2 ) ;
             Category category4 = sqlMap.QueryForObject<Category> ( 
"GetCategory", categoryID );

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/category-procedureWithReturn.sql
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/category-procedureWithReturn.sql?rev=575902&r1=575901&r2=575902&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/category-procedureWithReturn.sql
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/category-procedureWithReturn.sql
 Sat Sep 15 03:40:19 2007
@@ -7,5 +7,6 @@
                        (Category_Name, Category_Guid ) 
 values 
                        (@Category_Name, @Category_Guid)
-return SCOPE_IDENTITY()
+set @Category_Id = SCOPE_IDENTITY()
+return @Category_Id
 

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterMap.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterMap.cs?rev=575902&r1=575901&r2=575902&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterMap.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterMap.cs
 Sat Sep 15 03:40:19 2007
@@ -339,31 +339,23 @@
 
 
                /// <summary>
-               /// Build the properties
+        /// Get the parameter properties child for the xmlNode parameter.
                /// </summary>
-               /// <param name="scope"></param>
-               public void BuildProperties(ConfigurationScope scope)
+        /// <param name="configScope"></param>
+        public void BuildProperties(ConfigurationScope configScope)
                {
-                       GetProperties( scope );
-               }
+            ParameterProperty property = null;
 
-               /// <summary>
-               ///  Get the parameter properties child for the xmlNode 
parameter.
-               /// </summary>
-               /// <param name="configScope"></param>
-               private void GetProperties(ConfigurationScope configScope)
-               {
-                       ParameterProperty property = null;
+            foreach (XmlNode parameterNode in 
configScope.NodeContext.SelectNodes(DomSqlMapBuilder.ApplyMappingNamespacePrefix(XML_PARAMATER),
 configScope.XmlNamespaceManager))
+            {
+                property = 
ParameterPropertyDeSerializer.Deserialize(parameterNode, configScope);
 
-                       foreach ( XmlNode parameterNode in 
configScope.NodeContext.SelectNodes(DomSqlMapBuilder.ApplyMappingNamespacePrefix(XML_PARAMATER),
 configScope.XmlNamespaceManager) )
-                       {
-                               property = 
ParameterPropertyDeSerializer.Deserialize(parameterNode, configScope);
+                property.Initialize(configScope, _parameterClass);
 
-                               property.Initialize(configScope, 
_parameterClass);
-
-                               AddParameterProperty(property);
-                       }
+                AddParameterProperty(property);
+            }
                }
+
                #endregion
 
                #endregion

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterProperty.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterProperty.cs?rev=575902&r1=575901&r2=575902&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterProperty.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterProperty.cs
 Sat Sep 15 03:40:19 2007
@@ -318,10 +318,11 @@
                        {
                                if (this.CLRType.Length == 0 )  // Unknown
                                {
-                                       if 
(scope.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(parameterClass)) 
+                    if (_getAccessor!= null &&
+                        
scope.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(_getAccessor.MemberType))
 
                                        {
                                                // Primitive
-                                               _typeHandler = 
scope.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(parameterClass, 
_dbType);
+                        _typeHandler = 
scope.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(_getAccessor.MemberType,
 _dbType);
                                        }
                                        else
                                        {

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs?rev=575902&r1=575901&r2=575902&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs 
(original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs 
Sat Sep 15 03:40:19 2007
@@ -172,10 +172,33 @@
                             }
                         }
 
-                        object dataBaseValue = 
mapping.TypeHandler.GetDataBaseValue(((IDataParameter)command.Parameters[parameterName]).Value,
 result.GetType());
-                        request.IsRowDataFound = request.IsRowDataFound || 
(dataBaseValue != null);
+                        // Fix IBATISNET-239
+                        //"Normalize" System.DBNull parameters
+                        IDataParameter dataParameter = 
(IDataParameter)command.Parameters[parameterName];
+                        object dbValue = dataParameter.Value;
 
-                        request.ParameterMap.SetOutputParameter(ref result, 
mapping, dataBaseValue);
+                        object value = null;
+
+                        bool wasNull = (dbValue == DBNull.Value);
+                        if (wasNull)
+                        {
+                            if (mapping.HasNullValue)
+                            {
+                               value = 
mapping.TypeHandler.ValueOf(mapping.GetAccessor.MemberType, mapping.NullValue);
+                            }
+                            else
+                            {
+                                value = mapping.TypeHandler.NullValue;
+                            }
+                        }
+                        else
+                        {
+                            value = 
mapping.TypeHandler.GetDataBaseValue(dataParameter.Value, result.GetType());
+                        }
+
+                        request.IsRowDataFound = request.IsRowDataFound || 
(value != null);
+
+                        request.ParameterMap.SetOutputParameter(ref result, 
mapping, value);
                     }
                 }
             }

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs?rev=575902&r1=575901&r2=575902&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs Sat Sep 15 
03:40:19 2007
@@ -1313,10 +1313,6 @@
                                IMappedStatement statement = 
GetMappedStatement(statementName);
                                generatedKey = statement.ExecuteInsert(session, 
parameterObject);
                        } 
-                       catch
-                       {
-                               throw;
-                       }
                        finally
                        {
                                if ( isSessionLocal )

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/EnumTypeHandler.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/EnumTypeHandler.cs?rev=575902&r1=575901&r2=575902&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/EnumTypeHandler.cs 
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/EnumTypeHandler.cs 
Sat Sep 15 03:40:19 2007
@@ -48,7 +48,16 @@
                /// <param name="dbType">the dbType of the parameter</param>
                public override void SetParameter(IDataParameter dataParameter, 
object parameterValue, string dbType)
                {
-                       dataParameter.Value =  Convert.ChangeType( 
parameterValue, Enum.GetUnderlyingType( parameterValue.GetType() ) );
+            if (parameterValue != null)
+            {
+                           dataParameter.Value =  Convert.ChangeType( 
parameterValue, Enum.GetUnderlyingType( parameterValue.GetType() ) );
+            }
+            else
+            {
+                // When sending a null parameter value to the server,
+                // the user must specify DBNull, not null. 
+                dataParameter.Value = DBNull.Value;
+            }
                }
 
                /// <summary>

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/Nullables/NullableTimeSpanTypeHandler.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/Nullables/NullableTimeSpanTypeHandler.cs?rev=575902&r1=575901&r2=575902&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/Nullables/NullableTimeSpanTypeHandler.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/Nullables/NullableTimeSpanTypeHandler.cs
 Sat Sep 15 03:40:19 2007
@@ -50,7 +50,7 @@
 
             if (nullableValue.HasValue)
             {
-                dataParameter.Value = nullableValue.Value;
+                dataParameter.Value = nullableValue.Value.Ticks; 
//nullableValue.Value;
             }
             else
             {


Reply via email to