Author: gbayon
Date: Wed Feb 8 11:36:53 2006
New Revision: 376033
URL: http://svn.apache.org/viewcvs?rev=376033&view=rev
Log:
- Added more generic tests
- Fixed issue with generic support in .NET V2
Added:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics.StatementTest.cs
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj?rev=376033&r1=376032&r2=376033&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
Wed Feb 8 11:36:53 2006
@@ -212,6 +212,7 @@
<Compile Include="NUnit\SqlMapTests\DynamicTest.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="NUnit\SqlMapTests\Generics.StatementTest.cs" />
<Compile Include="NUnit\SqlMapTests\InheritanceTest.cs">
<SubType>Code</SubType>
</Compile>
Added:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics.StatementTest.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics.StatementTest.cs?rev=376033&view=auto
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics.StatementTest.cs
(added)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics.StatementTest.cs
Wed Feb 8 11:36:53 2006
@@ -0,0 +1,507 @@
+#region Apache Notice
+/*****************************************************************************
+ * $Revision: $
+ * $LastChangedDate: $
+ * $LastChangedBy: $
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2005, 2006 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
+
+using System;
+using System.Collections;
+using IBatisNet.Common;
+using IBatisNet.Common.Exceptions;
+using IBatisNet.Common.Utilities;
+using IBatisNet.DataMapper.MappedStatements;
+using IBatisNet.DataMapper.Test.Domain;
+using System.Collections.Generic;
+using NUnit.Framework;
+
+namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests
+{
+ [TestFixture]
+ public class GenericsStatementTest : BaseTest
+ {
+ #region SetUp & TearDown
+
+ /// <summary>
+ /// SetUp
+ /// </summary>
+ [SetUp]
+ public void Init()
+ {
+ InitScript(sqlMap.DataSource, ScriptDirectory +
"account-init.sql");
+ InitScript(sqlMap.DataSource, ScriptDirectory + "order-init.sql");
+ InitScript(sqlMap.DataSource, ScriptDirectory +
"line-item-init.sql");
+ InitScript(sqlMap.DataSource, ScriptDirectory +
"enumeration-init.sql");
+ InitScript(sqlMap.DataSource, ScriptDirectory + "other-init.sql");
+ }
+
+ /// <summary>
+ /// TearDown
+ /// </summary>
+ [TearDown]
+ public void Dispose()
+ { /* ... */
+ }
+
+ #endregion
+
+ #region Object Query tests
+
+ /// <summary>
+ /// Test Open connection with a connection string
+ /// </summary>
+ [Test]
+ public void TestOpenConnection()
+ {
+ sqlMap.OpenConnection(sqlMap.DataSource.ConnectionString);
+ Account account =
sqlMap.QueryForObject<Account>("SelectWithProperty", null);
+ sqlMap.CloseConnection();
+
+ AssertAccount1(account);
+ }
+
+ /// <summary>
+ /// Test use a statement with property subtitution
+ /// (JIRA 22)
+ /// </summary>
+ [Test]
+ public void TestSelectWithProperty()
+ {
+ Account account =
sqlMap.QueryForObject<Account>("SelectWithProperty", null);
+ AssertAccount1(account);
+ }
+
+ /// <summary>
+ /// Test ExecuteQueryForObject Via ColumnName
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectViaColumnName()
+ {
+ Account account =
sqlMap.QueryForObject<Account>("GetAccountViaColumnName", 1);
+ AssertAccount1(account);
+ }
+
+ /// <summary>
+ /// Test ExecuteQueryForObject Via ColumnIndex
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectViaColumnIndex()
+ {
+ Account account =
sqlMap.QueryForObject<Account>("GetAccountViaColumnIndex", 1);
+ AssertAccount1(account);
+ }
+
+ /// <summary>
+ /// Test ExecuteQueryForObject Via ResultClass
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectViaResultClass()
+ {
+ Account account =
sqlMap.QueryForObject<Account>("GetAccountViaResultClass", 1);
+ AssertAccount1(account);
+ }
+
+ /// <summary>
+ /// Test ExecuteQueryForObject With simple ResultClass : string
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectWithSimpleResultClass()
+ {
+ string email =
sqlMap.QueryForObject<string>("GetEmailAddressViaResultClass", 1);
+ Assert.AreEqual("[EMAIL PROTECTED]", email);
+ }
+
+ /// <summary>
+ /// Test ExecuteQueryForObject With simple ResultMap : string
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectWithSimpleResultMap()
+ {
+ string email =
sqlMap.QueryForObject<string>("GetEmailAddressViaResultMap", 1);
+ Assert.AreEqual("[EMAIL PROTECTED]", email);
+ }
+
+ /// <summary>
+ /// Test Primitive ReturnValue : System.DateTime
+ /// </summary>
+ [Test]
+ public void TestPrimitiveReturnValue()
+ {
+ DateTime CardExpiry =
sqlMap.QueryForObject<DateTime>("GetOrderCardExpiryViaResultClass", 1);
+ Assert.AreEqual(new DateTime(2003, 02, 15, 8, 15, 00), CardExpiry);
+ }
+
+ /// <summary>
+ /// Test ExecuteQueryForObject with result object : Account
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectWithResultObject()
+ {
+ Account account = new Account();
+ Account testAccount =
sqlMap.QueryForObject<Account>("GetAccountViaColumnName", 1, account);
+ AssertAccount1(account);
+ Assert.IsTrue(account == testAccount);
+ }
+
+ /// <summary>
+ /// Test ExecuteQueryForObject as Hashtable
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectAsHashtable()
+ {
+ Hashtable account =
sqlMap.QueryForObject<Hashtable>("GetAccountAsHashtable", 1);
+ AssertAccount1AsHashtable(account);
+ }
+
+ /// <summary>
+ /// Test ExecuteQueryForObject as Hashtable ResultClass
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectAsHashtableResultClass()
+ {
+ Hashtable account =
sqlMap.QueryForObject<Hashtable>("GetAccountAsHashtableResultClass", 1);
+ AssertAccount1AsHashtableForResultClass(account);
+ }
+
+ /// <summary>
+ /// Test ExecuteQueryForObject via Hashtable
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectViaHashtable()
+ {
+ Hashtable param = new Hashtable();
+ param.Add("LineItem_ID", 2);
+ param.Add("Order_ID", 9);
+
+ LineItem testItem =
sqlMap.QueryForObject<LineItem>("GetSpecificLineItem", param);
+
+ Assert.IsNotNull(testItem);
+ Assert.AreEqual("TSM-12", testItem.Code);
+ }
+
+ /// <summary>
+ /// Test Query Dynamic Sql Element
+ /// </summary>
+ [Test]
+ public void TestQueryDynamicSqlElement()
+ {
+ //IList list =
sqlMap.QueryForList("GetDynamicOrderedEmailAddressesViaResultMap",
"Account_ID");
+ IList<string> list =
sqlMap.QueryForList<string>("GetDynamicOrderedEmailAddressesViaResultMap",
"Account_ID");
+
+ Assert.AreEqual("[EMAIL PROTECTED]", list[0]);
+
+ //list =
sqlMap.QueryForList("GetDynamicOrderedEmailAddressesViaResultMap",
"Account_FirstName");
+ list =
sqlMap.QueryForList<string>("GetDynamicOrderedEmailAddressesViaResultMap",
"Account_FirstName");
+
+ Assert.AreEqual("[EMAIL PROTECTED]", list[0]);
+
+ }
+
+ /// <summary>
+ /// Test Execute QueryForList With ResultMap With Dynamic Element
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForListWithResultMapWithDynamicElement()
+ {
+ //IList list =
sqlMap.QueryForList("GetAllAccountsViaResultMapWithDynamicElement", "LIKE");
+ IList<Account> list =
sqlMap.QueryForList<Account>("GetAllAccountsViaResultMapWithDynamicElement",
"LIKE");
+
+ AssertAccount1(list[0]);
+ Assert.AreEqual(3, list.Count);
+ Assert.AreEqual(1, list[0].Id);
+ Assert.AreEqual(2, list[1].Id);
+ Assert.AreEqual(4, list[2].Id);
+
+ //list =
sqlMap.QueryForList("GetAllAccountsViaResultMapWithDynamicElement", "=");
+ list =
sqlMap.QueryForList<Account>("GetAllAccountsViaResultMapWithDynamicElement",
"=");
+
+ Assert.AreEqual(0, list.Count);
+ }
+
+ /// <summary>
+ /// Test Simple Dynamic Substitution
+ /// </summary>
+ [Test]
+ [Ignore("No longer supported.")]
+ public void TestSimpleDynamicSubstitution()
+ {
+ string statement = "select" + " Account_ID as Id," + "
Account_FirstName as FirstName," + " Account_LastName as LastName,"
+ " Account_Email as EmailAddress" + " from Accounts" + " WHERE
Account_ID = #id#";
+
+ Hashtable param = new Hashtable();
+ param.Add("id", 1);
+ param.Add("statement", statement);
+
+
+ IList list = sqlMap.QueryForList("SimpleDynamicSubstitution",
param);
+ AssertAccount1((Account)list[0]);
+ Assert.AreEqual(1, list.Count);
+ }
+
+ /// <summary>
+ /// Test Get Account Via Inline Parameters
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectViaInlineParameters()
+ {
+ Account account = new Account();
+ account.Id = 1;
+
+ Account testAccount =
sqlMap.QueryForObject<Account>("GetAccountViaInlineParameters", account);
+
+ AssertAccount1(testAccount);
+ }
+
+ /// <summary>
+ /// Test ExecuteQuery For Object With Enum property
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectWithEnum()
+ {
+ Enumeration enumClass =
sqlMap.QueryForObject<Enumeration>("GetEnumeration", 1);
+
+ Assert.AreEqual(enumClass.Day, Days.Sat);
+ Assert.AreEqual(enumClass.Color, Colors.Red);
+ Assert.AreEqual(enumClass.Month, Months.August);
+
+ enumClass = sqlMap.QueryForObject("GetEnumeration", 3) as
Enumeration;
+
+ Assert.AreEqual(enumClass.Day, Days.Mon);
+ Assert.AreEqual(enumClass.Color, Colors.Blue);
+ Assert.AreEqual(enumClass.Month, Months.September);
+ }
+
+ #endregion
+
+ #region List Query tests
+
+ /// <summary>
+ /// Test QueryForList with Hashtable ResultMap
+ /// </summary>
+ [Test]
+ public void TestQueryForListWithHashtableResultMap()
+ {
+ IList<Hashtable> list =
sqlMap.QueryForList<Hashtable>("GetAllAccountsAsHashMapViaResultMap", null);
+
+ AssertAccount1AsHashtable(list[0]);
+ Assert.AreEqual(5, list.Count);
+
+ Assert.AreEqual(1, list[0]["Id"]);
+ Assert.AreEqual(2, list[1]["Id"]);
+ Assert.AreEqual(3, list[2]["Id"]);
+ Assert.AreEqual(4, list[3]["Id"]);
+ Assert.AreEqual(5, list[4]["Id"]);
+ }
+
+ /// <summary>
+ /// Test QueryForList with Hashtable ResultClass
+ /// </summary>
+ [Test]
+ public void TestQueryForListWithHashtableResultClass()
+ {
+ IList<Hashtable> list =
sqlMap.QueryForList<Hashtable>("GetAllAccountsAsHashtableViaResultClass", null);
+
+ AssertAccount1AsHashtableForResultClass(list[0]);
+ Assert.AreEqual(5, list.Count);
+
+ Assert.AreEqual(1, list[0][BaseTest.ConvertKey("Id")]);
+ Assert.AreEqual(2, list[1][BaseTest.ConvertKey("Id")]);
+ Assert.AreEqual(3, list[2][BaseTest.ConvertKey("Id")]);
+ Assert.AreEqual(4, list[3][BaseTest.ConvertKey("Id")]);
+ Assert.AreEqual(5, list[4][BaseTest.ConvertKey("Id")]);
+ }
+
+ /// <summary>
+ /// Test QueryForList with IList ResultClass
+ /// </summary>
+ [Test]
+ public void TestQueryForListWithIListResultClass()
+ {
+ IList<IList> list =
sqlMap.QueryForList<IList>("GetAllAccountsAsArrayListViaResultClass", null);
+
+ IList listAccount = list[0];
+ Assert.AreEqual(1, listAccount[0]);
+ Assert.AreEqual("Joe", listAccount[1]);
+ Assert.AreEqual("Dalton", listAccount[2]);
+ Assert.AreEqual("[EMAIL PROTECTED]", listAccount[3]);
+
+ Assert.AreEqual(5, list.Count);
+
+ listAccount = (IList)list[0];
+ Assert.AreEqual(1, listAccount[0]);
+ listAccount = (IList)list[1];
+ Assert.AreEqual(2, listAccount[0]);
+ listAccount = (IList)list[2];
+ Assert.AreEqual(3, listAccount[0]);
+ listAccount = (IList)list[3];
+ Assert.AreEqual(4, listAccount[0]);
+ listAccount = (IList)list[4];
+ Assert.AreEqual(5, listAccount[0]);
+ }
+
+ /// <summary>
+ /// Test QueryForList With ResultMap, result collection as ArrayList
+ /// </summary>
+ [Test]
+ public void TestQueryForListWithResultMap()
+ {
+ IList<Account> list =
sqlMap.QueryForList<Account>("GetAllAccountsViaResultMap", null);
+
+ AssertAccount1(list[0]);
+ Assert.AreEqual(5, list.Count);
+ Assert.AreEqual(1, list[0].Id);
+ Assert.AreEqual(2, list[1].Id);
+ Assert.AreEqual(3, list[2].Id);
+ Assert.AreEqual(4, list[3].Id);
+ Assert.AreEqual(5, list[4].Id);
+ }
+
+ /// <summary>
+ /// Test QueryForList with ResultObject :
+ /// AccountCollection strongly typed collection
+ /// </summary>
+ [Test]
+ public void TestQueryForListWithResultObject()
+ {
+ IList<Account> accounts = new List<Account>();
+
+ sqlMap.QueryForList("GetAllAccountsViaResultMap", null, accounts);
+
+ AssertAccount1(accounts[0]);
+ Assert.AreEqual(5, accounts.Count);
+ Assert.AreEqual(1, accounts[0].Id);
+ Assert.AreEqual(2, accounts[1].Id);
+ Assert.AreEqual(3, accounts[2].Id);
+ Assert.AreEqual(4, accounts[3].Id);
+ Assert.AreEqual(5, accounts[4].Id);
+ }
+
+
+ /// <summary>
+ /// Test QueryForList with no result.
+ /// </summary>
+ [Test]
+ public void TestQueryForListWithNoResult()
+ {
+ IList<Account> list =
sqlMap.QueryForList<Account>("GetNoAccountsViaResultMap", null);
+
+ Assert.AreEqual(0, list.Count);
+ }
+
+ /// <summary>
+ /// Test QueryForList with ResultClass : Account.
+ /// </summary>
+ [Test]
+ public void TestQueryForListResultClass()
+ {
+ IList<Account> list =
sqlMap.QueryForList<Account>("GetAllAccountsViaResultClass", null);
+
+ AssertAccount1(list[0]);
+ Assert.AreEqual(5, list.Count);
+ Assert.AreEqual(1, list[0].Id);
+ Assert.AreEqual(2, list[1].Id);
+ Assert.AreEqual(3, list[2].Id);
+ Assert.AreEqual(4, list[3].Id);
+ Assert.AreEqual(5, list[4].Id);
+ }
+
+ /// <summary>
+ /// Test QueryForList with simple resultClass : string
+ /// </summary>
+ [Test]
+ public void TestQueryForListWithSimpleResultClass()
+ {
+ IList<string> list =
sqlMap.QueryForList<string>("GetAllEmailAddressesViaResultClass", null);
+
+ Assert.AreEqual("[EMAIL PROTECTED]", list[0]);
+ Assert.AreEqual("[EMAIL PROTECTED]", list[1]);
+ Assert.IsNull(list[2]);
+ Assert.AreEqual("[EMAIL PROTECTED]", list[3]);
+ Assert.IsNull(list[4]);
+ }
+
+ /// <summary>
+ /// Test QueryForList with simple ResultMap : string
+ /// </summary>
+ [Test]
+ public void TestQueryForListWithSimpleResultMap()
+ {
+ IList<string> list =
sqlMap.QueryForList<string>("GetAllEmailAddressesViaResultMap", null);
+
+ Assert.AreEqual("[EMAIL PROTECTED]", list[0]);
+ Assert.AreEqual("[EMAIL PROTECTED]", list[1]);
+ Assert.IsNull(list[2]);
+ Assert.AreEqual("[EMAIL PROTECTED]", list[3]);
+ Assert.IsNull(list[4]);
+ }
+
+ /// <summary>
+ /// Test QueryForListWithSkipAndMax
+ /// </summary>
+ [Test]
+ public void TestQueryForListWithSkipAndMax()
+ {
+ IList<Account> list =
sqlMap.QueryForList<Account>("GetAllAccountsViaResultMap", null, 2, 2);
+
+ Assert.AreEqual(2, list.Count);
+ Assert.AreEqual(3, list[0].Id);
+ Assert.AreEqual(4, list[1].Id);
+ }
+
+
+ [Test]
+ public void TestQueryWithRowDelegate()
+ {
+ SqlMapper.RowDelegate<Account> handler = new
SqlMapper.RowDelegate<Account>(this.RowHandler);
+
+ IList<Account> list =
sqlMap.QueryWithRowDelegate<Account>("GetAllAccountsViaResultMap", null,
handler);
+
+ Assert.AreEqual(5, _index);
+ Assert.AreEqual(5, list.Count);
+ AssertAccount1( list[0]);
+ Assert.AreEqual(1, list[0].Id);
+ Assert.AreEqual(2, list[1].Id);
+ Assert.AreEqual(3, list[2].Id);
+ Assert.AreEqual(4, list[3].Id);
+ Assert.AreEqual(5, list[4].Id);
+
+ }
+
+ #endregion
+
+ #region Row delegate
+
+ private int _index = 0;
+
+ public void RowHandler(object obj, object paramterObject,
IList<Account> list)
+ {
+ _index++;
+
+ Assert.AreEqual(_index, ((Account)obj).Id);
+ list.Add(((Account)obj));
+ }
+
+ #endregion
+ }
+}
+
+#endif
\ No newline at end of file
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs?rev=376033&r1=376032&r2=376033&view=diff
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
Wed Feb 8 11:36:53 2006
@@ -382,6 +382,18 @@
return
_mappedStatement.ExecuteQueryForRowDelegate(session, parameterObject,
rowDelegate);
}
+ /// <summary>
+ /// Runs a query with a custom object that gets a chance
+ /// to deal with each row as it is processed.
+ /// </summary>
+ /// <param name="session">The session used to execute the
statement.</param>
+ /// <param name="parameterObject">The object used to set the
parameters in the SQL.</param>
+ /// <param name="rowDelegate"></param>
+ public IList<T> ExecuteQueryForRowDelegate<T>(IDalSession session,
object parameterObject, SqlMapper.RowDelegate<T> rowDelegate)
+ {
+ return _mappedStatement.ExecuteQueryForRowDelegate<T>(session,
parameterObject, rowDelegate);
+ }
+
/// <summary>
/// Runs a query with a custom object that gets a chance
/// to deal with each row as it is processed.
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs?rev=376033&r1=376032&r2=376033&view=diff
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs
Wed Feb 8 11:36:53 2006
@@ -256,6 +256,16 @@
/// <returns></returns>
IList ExecuteQueryForRowDelegate( IDalSession session, object
parameterObject, SqlMapper.RowDelegate rowDelegate );
+ /// <summary>
+ /// Runs a query with a custom object that gets a chance
+ /// to deal with each row as it is processed.
+ /// </summary>
+ /// <param name="session">The session used to execute the
statement.</param>
+ /// <param name="parameterObject">The object used to set the
parameters in the SQL.</param>
+ /// <param name="rowDelegate"></param>param>
+ /// <returns></returns>
+ IList<T> ExecuteQueryForRowDelegate<T>(IDalSession session, object
parameterObject, SqlMapper.RowDelegate<T> rowDelegate);
+
/// <summary>
/// Runs a query with a custom object that gets a chance
/// to deal with each row as it is processed.
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs?rev=376033&r1=376032&r2=376033&view=diff
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
Wed Feb 8 11:36:53 2006
@@ -752,7 +752,7 @@
/// <param name="session">The session used to execute the
statement.</param>
/// <param name="parameterObject">The object used to set the
parameters in the SQL.</param>
/// <param name="rowDelegate"></param>
- public virtual IList<T> ExecuteQueryForRowDelegate<T>(IDalSession
session, object parameterObject, SqlMapper.RowDelegate rowDelegate)
+ public virtual IList<T> ExecuteQueryForRowDelegate<T>(IDalSession
session, object parameterObject, SqlMapper.RowDelegate<T> rowDelegate)
{
RequestScope request =
_statement.Sql.GetRequestScope(parameterObject, session); ;
@@ -811,7 +811,7 @@
/// <param name="maxResults">The maximum number of rows to
return.</param>
/// <param name="rowDelegate"></param>
/// <returns>A List of result objects.</returns>
- internal IList<T> RunQueryForList<T>(RequestScope request, IDalSession
session, object parameterObject, int skipResults, int maxResults,
SqlMapper.RowDelegate rowDelegate)
+ internal IList<T> RunQueryForList<T>(RequestScope request, IDalSession
session, object parameterObject, int skipResults, int maxResults,
SqlMapper.RowDelegate<T> rowDelegate)
{
IList<T> list = null;
@@ -859,7 +859,7 @@
{
T obj = (T)ApplyResultMap(request, reader, null);
- rowDelegate(obj, parameterObject, (IList)list);
+ rowDelegate(obj, parameterObject, list);
n++;
}
}
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs?rev=376033&r1=376032&r2=376033&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs Wed Feb 8
11:36:53 2006
@@ -62,6 +62,14 @@
/// <param name="list">The IList that will be returned to the
caller.</param>
public delegate void RowDelegate(object obj, object
parameterObject, IList list);
+ /// <summary>
+ /// A delegate called once per row in the QueryWithRowDelegate method
+ /// </summary>
+ /// <param name="obj">The object currently being processed.</param>
+ /// <param name="parameterObject">The optional parameter object passed
into the QueryWithRowDelegate method.</param>
+ /// <param name="list">The IList that will be returned to the
caller.</param>
+ public delegate void RowDelegate<T>(object obj, object
parameterObject, IList<T> list);
+
/// <summary>
/// A delegate called once per row in the
QueryForMapWithRowDelegate method
/// </summary>
@@ -1010,7 +1018,7 @@
try
{
IMappedStatement statement = GetMappedStatement(statementName);
- list = (IList<T>)statement.ExecuteQueryForList(session,
parameterObject);
+ list = statement.ExecuteQueryForList<T>(session,
parameterObject);
}
catch
{
@@ -1054,7 +1062,7 @@
try
{
IMappedStatement statement = GetMappedStatement(statementName);
- list = (IList<T>)statement.ExecuteQueryForList(session,
parameterObject, skipResults, maxResults);
+ list = statement.ExecuteQueryForList<T>(session,
parameterObject, skipResults, maxResults);
}
catch
{
@@ -1180,6 +1188,52 @@
return list;
}
+
+#if dotnet2
+ /// <summary>
+ /// Runs a query for list with a custom object that gets a chance to
deal
+ /// with each row as it is processed.
+ /// <p/>
+ /// The parameter object is generally used to supply the input
+ /// data for the WHERE clause parameter(s) of the SELECT statement.
+ /// </summary>
+ /// <param name="statementName">The name of the sql statement to
execute.</param>
+ /// <param name="parameterObject">The object used to set the
parameters in the SQL.</param>
+ /// <param name="rowDelegate"></param>
+ /// <returns>A List of result objects.</returns>
+ public IList<T> QueryWithRowDelegate<T>(string statementName, object
parameterObject, RowDelegate<T> rowDelegate)
+ {
+ bool isSessionLocal = false;
+ IDalSession session = _sessionHolder.LocalSession;
+ IList<T> list = null;
+
+ if (session == null)
+ {
+ session = new SqlMapSession(this.DataSource);
+ session.OpenConnection();
+ isSessionLocal = true;
+ }
+
+ try
+ {
+ IMappedStatement statement = GetMappedStatement(statementName);
+ list = statement.ExecuteQueryForRowDelegate<T>(session,
parameterObject, rowDelegate);
+ }
+ catch
+ {
+ throw;
+ }
+ finally
+ {
+ if (isSessionLocal)
+ {
+ session.CloseConnection();
+ }
+ }
+
+ return list;
+ }
+#endif
/// <summary>
/// Runs a query with a custom object that gets a chance to
deal