You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by gb...@apache.org on 2006/06/27 21:03:37 UTC
svn commit: r417557 - in /ibatis/trunk/cs/mapper:
IBatisNet.Common/Utilities/ IBatisNet.DataMapper.Test/
IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/
IBatisNet.DataMapper.Test/NUnit/SqlMapTests/MSSQL/
IBatisNet.DataMapper.Test/Scripts/MSSQL/ IBatisN...
Author: gbayon
Date: Tue Jun 27 12:03:36 2006
New Revision: 417557
URL: http://svn.apache.org/viewvc?rev=417557&view=rev
Log:
- Fixed IBATISNET-165
- Added SByte type handler
Added:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/category-procedureWithReturn.sql
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/Nullables/NullableSByteTypeHandler.cs (with props)
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/SByteTypeHandler.cs (with props)
Modified:
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/TypeUtils.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj
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-init.sql
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/TypeHandlerFactory.cs
Modified: ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/TypeUtils.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/TypeUtils.cs?rev=417557&r1=417556&r2=417557&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/TypeUtils.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/TypeUtils.cs Tue Jun 27 12:03:36 2006
@@ -59,8 +59,6 @@
{
}
- // CLOVER:ON
-
#endregion
/// <summary>
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj?rev=417557&r1=417556&r2=417557&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj Tue Jun 27 12:03:36 2006
@@ -409,6 +409,7 @@
<Content Include="Scripts\MSSQL\account-procedure.sql" />
<Content Include="Scripts\MSSQL\category-init.sql" />
<Content Include="Scripts\MSSQL\category-procedure.sql" />
+ <Content Include="Scripts\MSSQL\category-procedureWithReturn.sql" />
<Content Include="Scripts\MSSQL\DataBase.sql" />
<Content Include="Scripts\MSSQL\DBCreation.sql" />
<Content Include="Scripts\MSSQL\documents-init.sql" />
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=417557&r1=417556&r2=417557&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 Tue Jun 27 12:03:36 2006
@@ -17,6 +17,10 @@
<statements>
+ <procedure id="InsertCategoryViaStoreProcedureWithReturn" parameterMap="insert-params" resultClass="int">
+ ps_InsertCategorieWithReturnValue
+ </procedure>
+
<select id="GetCategoryWithNullValueReplacementGuid" resultMap="Category-result" >
select
Category_ID,
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=417557&r1=417556&r2=417557&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 Tue Jun 27 12:03:36 2006
@@ -25,6 +25,7 @@
InitScript( sqlMap.DataSource, ScriptDirectory + "category-procedure.sql" );
InitScript( sqlMap.DataSource, ScriptDirectory + "account-init.sql" );
InitScript( sqlMap.DataSource, ScriptDirectory + "account-procedure.sql", false );
+ InitScript( sqlMap.DataSource, ScriptDirectory + "category-procedureWithReturn.sql", false);
InitScript( sqlMap.DataSource, ScriptDirectory + "ps_SelectAccount.sql", false );
InitScript( sqlMap.DataSource, ScriptDirectory + "swap-procedure.sql" );
}
@@ -39,6 +40,34 @@
#endregion
#region Specific statement store procedure tests for sql server
+
+ /// <summary>
+ /// Test an insert with via a store procedure and getting the generatedKey from a t-sql return statement
+ /// </summary>
+ [Test]
+ public void InsertTestIdentityViaProcedureWithReturn ( )
+ {
+ Category category = new Category ( );
+ category.Name = "Mapping object relational";
+
+ int categoryID = ( int ) sqlMap.Insert ( "InsertCategoryViaStoreProcedureWithReturn", category );
+ Assert.AreEqual ( 1, categoryID );
+
+ Category category2 = new Category ( );
+ category2.Name = "Nausicaa";
+
+ int categoryID2 = ( int ) sqlMap.Insert ( "InsertCategoryViaStoreProcedureWithReturn", category2 );
+ Assert.AreEqual ( 2, categoryID2 );
+
+ Category category3 = sqlMap.QueryForObject<Category> ( "GetCategory", categoryID2 ) ;
+ Category category4 = sqlMap.QueryForObject<Category> ( "GetCategory", categoryID );
+
+ Assert.AreEqual ( categoryID2, category3.Id );
+ Assert.AreEqual ( category2.Name, category3.Name );
+
+ Assert.AreEqual ( categoryID, category4.Id );
+ Assert.AreEqual ( category.Name, category4.Name );
+ }
/// <summary>
/// Test get an account via a store procedure.
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/category-init.sql
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/category-init.sql?rev=417557&r1=417556&r2=417557&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/category-init.sql (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/category-init.sql Tue Jun 27 12:03:36 2006
@@ -15,3 +15,6 @@
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ps_InsertCategorie]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[ps_InsertCategorie]
+
+if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ps_InsertCategorieWithReturnValue]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
+drop procedure [dbo].[ps_InsertCategorieWithReturnValue]
Added: 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=417557&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/category-procedureWithReturn.sql (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/category-procedureWithReturn.sql Tue Jun 27 12:03:36 2006
@@ -0,0 +1,11 @@
+CREATE PROCEDURE dbo.[ps_InsertCategorieWithReturnValue]
+@Category_Id [int] output,
+@Category_Name [varchar] (32),
+@Category_Guid [uniqueidentifier]
+AS
+insert into Categories
+ (Category_Name, Category_Guid )
+values
+ (@Category_Name, @Category_Guid)
+return SCOPE_IDENTITY()
+
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj?rev=417557&r1=417556&r2=417557&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj Tue Jun 27 12:03:36 2006
@@ -623,6 +623,7 @@
<Compile Include="TypeHandlers\Nullables\NullableInt16TypeHandler.cs" />
<Compile Include="TypeHandlers\Nullables\NullableInt32TypeHandler.cs" />
<Compile Include="TypeHandlers\Nullables\NullableInt64TypeHandler.cs" />
+ <Compile Include="TypeHandlers\Nullables\NullableSByteTypeHandler.cs" />
<Compile Include="TypeHandlers\Nullables\NullableSingleTypeHandler.cs" />
<Compile Include="TypeHandlers\Nullables\NullableUInt16TypeHandler.cs" />
<Compile Include="TypeHandlers\Nullables\NullableUInt32TypeHandler.cs" />
@@ -636,6 +637,7 @@
<Compile Include="TypeHandlers\ResultGetterImpl.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="TypeHandlers\SByteTypeHandler.cs" />
<Compile Include="TypeHandlers\SingleTypeHandler.cs">
<SubType>Code</SubType>
</Compile>
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=417557&r1=417556&r2=417557&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs Tue Jun 27 12:03:36 2006
@@ -766,7 +766,21 @@
{
command.ExecuteNonQuery();
}
- else
+ else if (_statement is Procedure && (_statement.ResultClass != null) &&
+ _sqlMap.TypeHandlerFactory.IsSimpleType(_statement.ResultClass) )
+ {
+ IDataParameter returnValueParameter = command.CreateParameter();
+ returnValueParameter.Direction = ParameterDirection.ReturnValue;
+ command.Parameters.Add(returnValueParameter);
+
+ command.ExecuteNonQuery ( );
+ generatedKey = returnValueParameter.Value;
+
+ ITypeHandler typeHandler = _sqlMap.TypeHandlerFactory.GetTypeHandler ( _statement.ResultClass );
+ generatedKey = typeHandler.GetDataBaseValue ( generatedKey, _statement.ResultClass );
+ }
+ else
+
{
generatedKey = command.ExecuteScalar();
if ( (_statement.ResultClass!=null) &&
Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/Nullables/NullableSByteTypeHandler.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/Nullables/NullableSByteTypeHandler.cs?rev=417557&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/Nullables/NullableSByteTypeHandler.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/Nullables/NullableSByteTypeHandler.cs Tue Jun 27 12:03:36 2006
@@ -0,0 +1,111 @@
+#region Apache Notice
+/*****************************************************************************
+ * $Revision: 378879 $
+ * $LastChangedDate$
+ * $LastChangedBy$
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2006/2005 - The Apache Software Foundation
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ********************************************************************************/
+#endregion
+
+#if dotnet2
+#region Using
+using System;
+using System.Data;
+
+using System.Collections.Generic;
+using IBatisNet.DataMapper.Configuration.ParameterMapping;
+using IBatisNet.DataMapper.Configuration.ResultMapping;
+#endregion
+
+namespace IBatisNet.DataMapper.TypeHandlers.Nullables
+{
+ class NullableSByteTypeHandler : BaseTypeHandler
+ {
+
+ public override void SetParameter(IDataParameter dataParameter, object parameterValue, string dbType)
+ {
+ byte? nullableValue = (byte?)parameterValue;
+
+ if (nullableValue.HasValue)
+ {
+ dataParameter.Value = nullableValue.Value;
+ }
+ else
+ {
+ dataParameter.Value = DBNull.Value;
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="mapping"></param>
+ /// <param name="dataReader"></param>
+ /// <returns></returns>
+ public override object GetValueByName(ResultProperty mapping, IDataReader dataReader)
+ {
+ int index = dataReader.GetOrdinal(mapping.ColumnName);
+
+ if (dataReader.IsDBNull(index) == true)
+ {
+ return DBNull.Value;
+ }
+ else
+ {
+ return new sbyte?(Convert.ToSByte(dataReader.GetValue(index)));
+ }
+ }
+
+ public override object GetValueByIndex(ResultProperty mapping, IDataReader dataReader)
+ {
+ if (dataReader.IsDBNull(mapping.ColumnIndex) == true)
+ {
+ return DBNull.Value;
+ }
+ else
+ {
+ return new sbyte?(Convert.ToSByte(dataReader.GetValue(mapping.ColumnIndex)));
+ }
+ }
+
+ public override object GetDataBaseValue(object outputValue, Type parameterType)
+ {
+ return new sbyte?(Convert.ToSByte(outputValue));
+ }
+
+ public override object ValueOf(Type type, string s)
+ {
+ return new sbyte?(Convert.ToSByte(s));
+ }
+
+
+ public override bool IsSimpleType
+ {
+ get { return true; }
+ }
+
+
+ public override object NullValue
+ {
+ get { return new sbyte?(); }
+ }
+ }
+}
+
+#endif
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/Nullables/NullableSByteTypeHandler.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/Nullables/NullableSByteTypeHandler.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/SByteTypeHandler.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/SByteTypeHandler.cs?rev=417557&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/SByteTypeHandler.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/SByteTypeHandler.cs Tue Jun 27 12:03:36 2006
@@ -0,0 +1,125 @@
+
+#region Apache Notice
+/*****************************************************************************
+ * $Revision: 408164 $
+ * $LastChangedDate$
+ * $LastChangedBy$
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2006/2005 - The Apache Software Foundation
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ********************************************************************************/
+#endregion
+
+#region Using
+
+using System;
+using System.Data;
+using System.Globalization;
+
+using IBatisNet.DataMapper.Configuration.ResultMapping;
+#endregion
+
+
+namespace IBatisNet.DataMapper.TypeHandlers
+{
+ /// <summary>
+ /// SByteTypeHandler.
+ /// </summary>
+ internal sealed class SByteTypeHandler : BaseTypeHandler
+ {
+ /// <summary>
+ /// Gets a column value by the name
+ /// </summary>
+ /// <param name="mapping"></param>
+ /// <param name="dataReader"></param>
+ /// <returns></returns>
+ public override object GetValueByName(ResultProperty mapping, IDataReader dataReader)
+ {
+ int index = dataReader.GetOrdinal(mapping.ColumnName);
+
+ if (dataReader.IsDBNull(index) == true)
+ {
+ return System.DBNull.Value;
+ }
+ else
+ {
+ return Convert.ToSByte(dataReader.GetValue(index));
+ }
+ }
+
+ /// <summary>
+ /// Gets a column value by the index
+ /// </summary>
+ /// <param name="mapping"></param>
+ /// <param name="dataReader"></param>
+ /// <returns></returns>
+ public override object GetValueByIndex(ResultProperty mapping, IDataReader dataReader)
+ {
+ if (dataReader.IsDBNull(mapping.ColumnIndex) == true)
+ {
+ return System.DBNull.Value;
+ }
+ else
+ {
+ return Convert.ToSByte(dataReader.GetValue(mapping.ColumnIndex));
+ }
+ }
+
+ /// <summary>
+ /// Converts the String to the type that this handler deals with
+ /// </summary>
+ /// <param name="type">the tyepe of the property (used only for enum conversion)</param>
+ /// <param name="s">the String value</param>
+ /// <returns>the converted value</returns>
+ public override object ValueOf(Type type, string s)
+ {
+ return Convert.ToSByte(s);
+ }
+
+ /// <summary>
+ /// Retrieve ouput database value of an output parameter
+ /// </summary>
+ /// <param name="outputValue">ouput database value</param>
+ /// <param name="parameterType">type used in EnumTypeHandler</param>
+ /// <returns></returns>
+ public override object GetDataBaseValue(object outputValue, Type parameterType)
+ {
+ return Convert.ToSByte(outputValue);
+ }
+
+
+ /// <summary>
+ /// Gets a value indicating whether this instance is simple type.
+ /// </summary>
+ /// <value>
+ /// <c>true</c> if this instance is simple type; otherwise, <c>false</c>.
+ /// </value>
+ public override bool IsSimpleType
+ {
+ get { return true; }
+ }
+
+ /// <summary>
+ /// The null value for this type
+ /// </summary>
+ /// <value></value>
+ public override object NullValue
+ {
+ get { throw new InvalidCastException("SByteTypeHandler, could not cast a null value in sbyte field."); }
+ }
+ }
+}
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/SByteTypeHandler.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/SByteTypeHandler.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/TypeHandlerFactory.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/TypeHandlerFactory.cs?rev=417557&r1=417556&r2=417557&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/TypeHandlerFactory.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/TypeHandlers/TypeHandlerFactory.cs Tue Jun 27 12:03:36 2006
@@ -125,6 +125,9 @@
handler = new UInt64TypeHandler();
this.Register(typeof(UInt64), handler);
+
+ handler = new SByteTypeHandler();
+ this.Register(typeof(SByte), handler);
#if dotnet2
handler = new NullableBooleanTypeHandler();
@@ -168,6 +171,9 @@
handler = new NullableUInt64TypeHandler();
this.Register(typeof(UInt64?), handler);
+
+ handler = new NullableSByteTypeHandler();
+ this.Register(typeof(SByte?), handler);
#endif
_unknownTypeHandler = new UnknownTypeHandler(this);