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 2009/06/25 07:41:43 UTC
svn commit: r788267 [1/2] - in
/ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper: ./
MappedStatements/ Model/Cache/
Author: rgrabowski
Date: Thu Jun 25 05:41:43 2009
New Revision: 788267
URL: http://svn.apache.org/viewvc?rev=788267&view=rev
Log:
Refactored large MappedStatement class into partial classes:
MappedStatement.ExecuteInsert.cs
MappedStatement.ExecuteQueryForDataTable.cs
MappedStatement.ExecuteQueryForList.cs
MappedStatement.ExecuteQueryForMap.cs
MappedStatement.ExecuteQueryForObject.cs
MappedStatement.ExecuteUpdate.cs
All Execute methods call through to a single generic Execute method in MappedStatement.cs that ensures the RequestScope is created and events are raised in a consistent manner.
Code compiles but test cases are broke.
Added:
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteInsert.cs
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForDataTable.cs
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForList.cs
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForMap.cs
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForObject.cs
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteUpdate.cs
Modified:
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Apache.Ibatis.DataMapper.csproj
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/CachingStatement.cs
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/IMappedStatement.cs
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.cs
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Model/Cache/CacheModel.cs
Modified: ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Apache.Ibatis.DataMapper.csproj
URL: http://svn.apache.org/viewvc/ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Apache.Ibatis.DataMapper.csproj?rev=788267&r1=788266&r2=788267&view=diff
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Apache.Ibatis.DataMapper.csproj (original)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Apache.Ibatis.DataMapper.csproj Thu Jun 25 05:41:43 2009
@@ -1,7 +1,7 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<ProjectType>Local</ProjectType>
- <ProductVersion>9.0.21022</ProductVersion>
+ <ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{F3E45F39-3224-4EAD-B138-EB5CC0E32824}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -27,7 +27,7 @@
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>2.0</OldToolsVersion>
- <TargetFrameworkVersion>v3.0</TargetFrameworkVersion>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>bin\Debug\</OutputPath>
@@ -86,6 +86,9 @@
<Name>System</Name>
</Reference>
<Reference Include="System.configuration" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
<Reference Include="System.Data">
<Name>System.Data</Name>
</Reference>
@@ -123,6 +126,12 @@
<Compile Include="Configuration\Module\ResultMapModuleBuilder.cs" />
<Compile Include="Configuration\Module\TypeAliasModuleBuilder.cs" />
<Compile Include="Configuration\Module\TypeHandlerModuleBuilder.cs" />
+ <Compile Include="MappedStatements\MappedStatement.ExecuteInsert.cs" />
+ <Compile Include="MappedStatements\MappedStatement.ExecuteQueryForDataTable.cs" />
+ <Compile Include="MappedStatements\MappedStatement.ExecuteQueryForList.cs" />
+ <Compile Include="MappedStatements\MappedStatement.ExecuteQueryForMap.cs" />
+ <Compile Include="MappedStatements\MappedStatement.ExecuteQueryForObject.cs" />
+ <Compile Include="MappedStatements\MappedStatement.ExecuteUpdate.cs" />
<Compile Include="MappedStatements\ResultStrategy\DataRowStrategy.cs" />
<Compile Include="Model\Cache\BaseCache.cs" />
<Compile Include="Model\Cache\Decorators\LoggingCache.cs" />
Modified: ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/CachingStatement.cs
URL: http://svn.apache.org/viewvc/ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/CachingStatement.cs?rev=788267&r1=788266&r2=788267&view=diff
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/CachingStatement.cs (original)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/CachingStatement.cs Thu Jun 25 05:41:43 2009
@@ -53,7 +53,7 @@
/// <summary>
/// Event launch on Execute query
/// </summary>
- public event EventHandler<ExecuteEventArgs> Execute = delegate { };
+ public event EventHandler<ExecuteEventArgs> Executed = delegate { };
/// <summary>
/// Constructor
Modified: ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/IMappedStatement.cs
URL: http://svn.apache.org/viewvc/ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/IMappedStatement.cs?rev=788267&r1=788266&r2=788267&view=diff
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/IMappedStatement.cs (original)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/IMappedStatement.cs Thu Jun 25 05:41:43 2009
@@ -50,7 +50,7 @@
/// <summary>
/// Event launch on exceute query
/// </summary>
- event EventHandler<ExecuteEventArgs> Execute;
+ event EventHandler<ExecuteEventArgs> Executed;
#endregion
Added: ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteInsert.cs
URL: http://svn.apache.org/viewvc/ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteInsert.cs?rev=788267&view=auto
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteInsert.cs (added)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteInsert.cs Thu Jun 25 05:41:43 2009
@@ -0,0 +1,126 @@
+#region Apache Notice
+/*****************************************************************************
+ * $Revision: 374175 $
+ * $LastChangedDate: 2008-10-11 12:07:44 -0400 (Sat, 11 Oct 2008) $
+ * $LastChangedBy: gbayon $
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2008/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
+
+using System.Data;
+using Apache.Ibatis.Common.Utilities.Objects;
+using Apache.Ibatis.DataMapper.Model.Events;
+using Apache.Ibatis.DataMapper.Model.Statements;
+using Apache.Ibatis.DataMapper.Session;
+using Apache.Ibatis.DataMapper.TypeHandlers;
+
+namespace Apache.Ibatis.DataMapper.MappedStatements
+{
+ public partial class MappedStatement
+ {
+ /// <summary>
+ /// Execute an insert statement. Fill the parameter object with
+ /// the ouput parameters if any, also could return the insert generated key
+ /// </summary>
+ /// <param name="session">The session</param>
+ /// <param name="parameterObject">The parameter object used to fill the statement.</param>
+ /// <returns>Can return the insert generated key.</returns>
+ public virtual object ExecuteInsert(ISession session, object parameterObject)
+ {
+ return Execute<object, PreInsertEventArgs, PostInsertEventArgs>(
+ PreInsertEvent,
+ PostInsertEvent,
+ session,
+ parameterObject,
+ (r, p) =>
+ {
+ #region RunInsert
+
+ object generatedKey = null;
+ SelectKey selectKeyStatement = null;
+
+ if (statement is Insert)
+ {
+ selectKeyStatement = ((Insert)statement).SelectKey;
+ }
+
+ if (selectKeyStatement != null && !selectKeyStatement.isAfter)
+ {
+ IMappedStatement mappedStatement = modelStore.GetMappedStatement(selectKeyStatement.Id);
+ generatedKey = mappedStatement.ExecuteQueryForObject(session, p, null);
+
+ ObjectProbe.SetMemberValue(p, selectKeyStatement.PropertyName, generatedKey,
+ r.DataExchangeFactory.ObjectFactory,
+ r.DataExchangeFactory.AccessorFactory);
+ }
+
+ preparedCommand.Create(r, session, Statement, p);
+
+ using (IDbCommand command = r.IDbCommand)
+ {
+ if (statement is Insert)
+ {
+ command.ExecuteNonQuery();
+ }
+ // Retrieve output parameter if the result class is specified
+ else if (statement is Procedure && (statement.ResultClass != null) &&
+ modelStore.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(statement.ResultClass))
+ {
+ IDataParameter returnValueParameter = command.CreateParameter();
+ returnValueParameter.Direction = ParameterDirection.ReturnValue;
+ command.Parameters.Add(returnValueParameter);
+
+ command.ExecuteNonQuery();
+ generatedKey = returnValueParameter.Value;
+
+ ITypeHandler typeHandler = modelStore.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(statement.ResultClass);
+ generatedKey = typeHandler.GetDataBaseValue(generatedKey, statement.ResultClass);
+ }
+ else
+ {
+ generatedKey = command.ExecuteScalar();
+ if ((statement.ResultClass != null) &&
+ modelStore.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(statement.ResultClass))
+ {
+ ITypeHandler typeHandler = modelStore.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(statement.ResultClass);
+ generatedKey = typeHandler.GetDataBaseValue(generatedKey, statement.ResultClass);
+ }
+ }
+
+ if (selectKeyStatement != null && selectKeyStatement.isAfter)
+ {
+ IMappedStatement mappedStatement = modelStore.GetMappedStatement(selectKeyStatement.Id);
+ generatedKey = mappedStatement.ExecuteQueryForObject(session, p, null);
+
+ ObjectProbe.SetMemberValue(p, selectKeyStatement.PropertyName, generatedKey,
+ r.DataExchangeFactory.ObjectFactory,
+ r.DataExchangeFactory.AccessorFactory);
+ }
+
+ RetrieveOutputParameters(r, session, command, p);
+ }
+
+ // ???
+ return generatedKey;
+
+ #endregion
+ });
+ }
+ }
+}
Added: ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForDataTable.cs
URL: http://svn.apache.org/viewvc/ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForDataTable.cs?rev=788267&view=auto
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForDataTable.cs (added)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForDataTable.cs Thu Jun 25 05:41:43 2009
@@ -0,0 +1,96 @@
+#region Apache Notice
+/*****************************************************************************
+ * $Revision: 374175 $
+ * $LastChangedDate: 2008-10-11 12:07:44 -0400 (Sat, 11 Oct 2008) $
+ * $LastChangedBy: gbayon $
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2008/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
+
+using System.Data;
+using Apache.Ibatis.DataMapper.Model.Events;
+using Apache.Ibatis.DataMapper.Scope;
+using Apache.Ibatis.DataMapper.Session;
+
+namespace Apache.Ibatis.DataMapper.MappedStatements
+{
+ public partial class MappedStatement
+ {
+ #region ExecuteQueryForDataTable
+ /// <summary>
+ /// Executes an SQL statement that returns DataTable.
+ /// </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>
+ /// <returns>The object</returns>
+ public virtual DataTable ExecuteQueryForDataTable(ISession session, object parameterObject)
+ {
+ return Execute<DataTable, PreSelectEventArgs, PostSelectEventArgs>(
+ PreSelectEvent,
+ PostSelectEvent,
+ session,
+ parameterObject,
+ (r, p) => RunQueryForForDataTable(r, session, parameterObject));
+
+ // return RaisePostEvent<DataTable, PostSelectEventArgs>(PostSelectEvent, param, dataTable);
+ }
+
+ /// <summary>
+ /// Runs the query for for data table.
+ /// </summary>
+ /// <param name="request">The request.</param>
+ /// <param name="session">The session.</param>
+ /// <param name="parameterObject">The parameter object.</param>
+ /// <returns></returns>
+ internal DataTable RunQueryForForDataTable(RequestScope request, ISession session, object parameterObject)
+ {
+ DataTable dataTable = new DataTable("DataTable");
+
+ using (IDbCommand command = request.IDbCommand)
+ {
+ IDataReader reader = command.ExecuteReader();
+
+ try
+ {
+ // Get Results
+ while (reader.Read())
+ {
+ DataRow dataRow = dataTable.NewRow();
+ dataTable.Rows.Add(dataRow);
+ resultStrategy.Process(request, ref reader, dataRow);
+ }
+ }
+ finally
+ {
+ reader.Close();
+ reader.Dispose();
+ }
+
+ // do we need ??
+ //ExecuteDelayedLoad(request);
+
+ // do we need ??
+ //RetrieveOutputParameters(request, session, command, parameterObject);
+ }
+
+ return dataTable;
+ }
+ #endregion
+ }
+}
Added: ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForList.cs
URL: http://svn.apache.org/viewvc/ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForList.cs?rev=788267&view=auto
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForList.cs (added)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForList.cs Thu Jun 25 05:41:43 2009
@@ -0,0 +1,424 @@
+#region Apache Notice
+/*****************************************************************************
+ * $Revision: 374175 $
+ * $LastChangedDate: 2008-10-11 12:07:44 -0400 (Sat, 11 Oct 2008) $
+ * $LastChangedBy: gbayon $
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2008/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
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Data;
+using Apache.Ibatis.DataMapper.Exceptions;
+using Apache.Ibatis.DataMapper.Model.Events;
+using Apache.Ibatis.DataMapper.Scope;
+using Apache.Ibatis.DataMapper.Session;
+
+namespace Apache.Ibatis.DataMapper.MappedStatements
+{
+ public partial class MappedStatement
+ {
+ /// <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 virtual IList ExecuteQueryForRowDelegate(ISession session, object parameterObject, RowDelegate rowDelegate)
+ {
+ return Execute<IList, PreSelectEventArgs, PostSelectEventArgs>(
+ PreSelectEvent,
+ PostSelectEvent,
+ session,
+ parameterObject,
+ (r, p) => RunQueryForList(r, session, p, null, rowDelegate));
+ }
+
+ /// <summary>
+ /// Executes the SQL and retuns all rows selected.
+ /// </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>
+ /// <returns>A List of result objects.</returns>
+ public virtual IList ExecuteQueryForList(ISession session, object parameterObject)
+ {
+ return Execute<IList, PreSelectEventArgs, PostSelectEventArgs>(
+ PreSelectEvent,
+ PostSelectEvent,
+ session,
+ parameterObject,
+ (r, p) => RunQueryForList(r, session, p));
+ }
+
+ /// <summary>
+ /// Executes the SQL and and fill a strongly typed collection.
+ /// </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="resultObject">A strongly typed collection of result objects.</param>
+ public virtual void ExecuteQueryForList(ISession session, object parameterObject, IList resultObject)
+ {
+ Execute<IList, PreSelectEventArgs, PostSelectEventArgs>(
+ PreSelectEvent,
+ PostSelectEvent,
+ session,
+ parameterObject,
+ (r, p) => RunQueryForList(r, session, p, resultObject, null));
+ }
+
+ /// <summary>
+ /// Runs the query for list.
+ /// </summary>
+ /// <param name="request">The request.</param>
+ /// <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>
+ /// <returns>A List of result objects.</returns>
+ internal IList RunQueryForList(RequestScope request, ISession session, object parameterObject)
+ {
+ IList list = null;
+
+ using (IDbCommand command = request.IDbCommand)
+ {
+ if (statement.ListClass == null)
+ {
+ list = new ArrayList();
+ }
+ else
+ {
+ list = statement.CreateInstanceOfListClass();
+ }
+
+ IDataReader reader = command.ExecuteReader();
+
+ try
+ {
+ do
+ {
+ IList currentList = null;
+ if (request.Statement.ResultsMap.Count == 1)
+ {
+ currentList = list;
+ }
+ else
+ {
+ if (request.CurrentResultMap != null)
+ {
+ Type genericListType = typeof(List<>).MakeGenericType(new Type[] { request.CurrentResultMap.Class });
+ currentList = (IList)Activator.CreateInstance(genericListType);
+ }
+ else
+ {
+ currentList = new ArrayList();
+ }
+ list.Add(currentList);
+
+ }
+ // Get Results
+ while (reader.Read())
+ {
+ object obj = resultStrategy.Process(request, ref reader, null);
+ if (obj != BaseStrategy.SKIP)
+ {
+ currentList.Add(obj);
+ }
+ }
+ }
+ while (reader.NextResult());
+ }
+ finally
+ {
+ reader.Close();
+ reader.Dispose();
+ }
+
+ ExecuteDelayedLoad(request);
+
+ RetrieveOutputParameters(request, session, command, parameterObject);
+ }
+
+ return list;
+ }
+
+ /// <summary>
+ /// Executes the SQL and retuns a List of result objects.
+ /// </summary>
+ /// <param name="request">The request scope.</param>
+ /// <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="resultObject">A strongly typed collection of result objects.</param>
+ /// <param name="rowDelegate"></param>
+ /// <returns>A List of result objects.</returns>
+ internal IList RunQueryForList(RequestScope request, ISession session, object parameterObject, IList resultObject, RowDelegate rowDelegate)
+ {
+ IList list = resultObject;
+
+ using (IDbCommand command = request.IDbCommand)
+ {
+ if (resultObject == null)
+ {
+ if (statement.ListClass == null)
+ {
+ list = new ArrayList();
+ }
+ else
+ {
+ list = statement.CreateInstanceOfListClass();
+ }
+ }
+
+ IDataReader reader = command.ExecuteReader();
+
+ try
+ {
+ do
+ {
+ if (rowDelegate == null)
+ {
+ //***
+ IList currentList = null;
+ if (request.Statement.ResultsMap.Count == 1)
+ {
+ currentList = list;
+ }
+ else
+ {
+ if (request.CurrentResultMap != null)
+ {
+ Type genericListType = typeof(List<>).MakeGenericType(new Type[] { request.CurrentResultMap.Class });
+ currentList = (IList)Activator.CreateInstance(genericListType);
+ }
+ else
+ {
+ currentList = new ArrayList();
+ }
+ list.Add(currentList);
+
+ }
+ //***
+ while (reader.Read())
+ {
+ object obj = resultStrategy.Process(request, ref reader, null);
+ if (obj != BaseStrategy.SKIP)
+ {
+ //list.Add(obj);
+ currentList.Add(obj);
+ }
+ }
+ }
+ else
+ {
+ while (reader.Read())
+ {
+ object obj = resultStrategy.Process(request, ref reader, null);
+ rowDelegate(obj, parameterObject, list);
+ }
+ }
+ }
+ while (reader.NextResult());
+ }
+ finally
+ {
+ reader.Close();
+ reader.Dispose();
+ }
+
+ ExecuteDelayedLoad(request);
+ RetrieveOutputParameters(request, session, command, parameterObject);
+ }
+
+ return list;
+ }
+
+ /// <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 virtual IList<T> ExecuteQueryForRowDelegate<T>(ISession session, object parameterObject, RowDelegate<T> rowDelegate)
+ {
+ if (rowDelegate == null)
+ {
+ throw new DataMapperException("A null RowDelegate was passed to QueryForRowDelegate.");
+ }
+
+ return Execute<IList<T>, PreSelectEventArgs, PostSelectEventArgs>(
+ PreSelectEvent,
+ PostSelectEvent,
+ session,
+ parameterObject,
+ (r, p) => RunQueryForList(r, session, p, null, rowDelegate));
+ }
+
+ /// <summary>
+ /// Executes the SQL and retuns all rows selected.
+ /// </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>
+ /// <returns>A List of result objects.</returns>
+ public virtual IList<T> ExecuteQueryForList<T>(ISession session, object parameterObject)
+ {
+ return Execute<IList<T>, PreSelectEventArgs, PostSelectEventArgs>(
+ PreSelectEvent,
+ PostSelectEvent,
+ session,
+ parameterObject,
+ (r, p) => RunQueryForList<T>(r, session, p, null, null));
+ }
+
+ /// <summary>
+ /// Executes the SQL and and fill a strongly typed collection.
+ /// </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="resultObject">A strongly typed collection of result objects.</param>
+ public virtual void ExecuteQueryForList<T>(ISession session, object parameterObject, IList<T> resultObject)
+ {
+ Execute<IList<T>, PreSelectEventArgs, PostSelectEventArgs>(
+ PreSelectEvent,
+ PostSelectEvent,
+ session,
+ parameterObject,
+ (r, p) => RunQueryForList(r, session, p, resultObject, null));
+ }
+
+ /// <summary>
+ /// Executes the SQL and retuns a List of result objects.
+ /// </summary>
+ /// <param name="request">The request scope.</param>
+ /// <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>
+ /// <returns>A List of result objects.</returns>
+ internal IList<T> RunQueryForList<T>(RequestScope request, ISession session, object parameterObject)
+ {
+ IList<T> list = null;
+
+ using (IDbCommand command = request.IDbCommand)
+ {
+ if (statement.ListClass == null)
+ {
+ list = new List<T>();
+ }
+ else
+ {
+ list = statement.CreateInstanceOfGenericListClass<T>();
+ }
+
+ IDataReader reader = command.ExecuteReader();
+ try
+ {
+ do
+ {
+ while (reader.Read())
+ {
+ object obj = resultStrategy.Process(request, ref reader, null);
+ if (obj != BaseStrategy.SKIP)
+ {
+ list.Add((T)obj);
+ }
+ }
+ }
+ while (reader.NextResult());
+ }
+ finally
+ {
+ reader.Close();
+ reader.Dispose();
+ }
+
+ ExecuteDelayedLoad(request);
+
+ RetrieveOutputParameters(request, session, command, parameterObject);
+ }
+
+ return list;
+ }
+
+ /// <summary>
+ /// Executes the SQL and retuns a List of result objects.
+ /// </summary>
+ /// <param name="request">The request scope.</param>
+ /// <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="resultObject">The result object</param>
+ /// <param name="rowDelegate"></param>
+ /// <returns>A List of result objects.</returns>
+ internal IList<T> RunQueryForList<T>(RequestScope request, ISession session, object parameterObject, IList<T> resultObject, RowDelegate<T> rowDelegate)
+ {
+ IList<T> list = resultObject;
+
+ using (IDbCommand command = request.IDbCommand)
+ {
+ if (resultObject == null)
+ {
+ if (statement.ListClass == null)
+ {
+ list = new List<T>();
+ }
+ else
+ {
+ list = statement.CreateInstanceOfGenericListClass<T>();
+ }
+ }
+
+ IDataReader reader = command.ExecuteReader();
+ try
+ {
+ do
+ {
+ if (rowDelegate == null)
+ {
+ while (reader.Read())
+ {
+ object obj = resultStrategy.Process(request, ref reader, null);
+ if (obj != BaseStrategy.SKIP)
+ {
+ list.Add((T)obj);
+ }
+ }
+ }
+ else
+ {
+ while (reader.Read())
+ {
+ T obj = (T)resultStrategy.Process(request, ref reader, null);
+ rowDelegate(obj, parameterObject, list);
+ }
+ }
+ }
+ while (reader.NextResult());
+ }
+ finally
+ {
+ reader.Close();
+ reader.Dispose();
+ }
+
+ ExecuteDelayedLoad(request);
+ RetrieveOutputParameters(request, session, command, parameterObject);
+ }
+
+ return list;
+ }
+ }
+}
Added: ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForMap.cs
URL: http://svn.apache.org/viewvc/ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForMap.cs?rev=788267&view=auto
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForMap.cs (added)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForMap.cs Thu Jun 25 05:41:43 2009
@@ -0,0 +1,279 @@
+#region Apache Notice
+/*****************************************************************************
+ * $Revision: 374175 $
+ * $LastChangedDate: 2008-10-11 12:07:44 -0400 (Sat, 11 Oct 2008) $
+ * $LastChangedBy: gbayon $
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2008/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
+
+using System.Collections;
+using System.Collections.Generic;
+using System.Data;
+using Apache.Ibatis.Common.Utilities.Objects;
+using Apache.Ibatis.DataMapper.Exceptions;
+using Apache.Ibatis.DataMapper.Model.Events;
+using Apache.Ibatis.DataMapper.Scope;
+using Apache.Ibatis.DataMapper.Session;
+
+namespace Apache.Ibatis.DataMapper.MappedStatements
+{
+ public partial class MappedStatement
+ {
+
+ /// <summary>
+ /// Executes the SQL and retuns all rows selected in a map that is keyed on the property named
+ /// in the keyProperty parameter. The value at each key will be the value of the property specified
+ /// in the valueProperty parameter. If valueProperty is null, the entire result object will be entered.
+ /// </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="keyProperty">The property of the result object to be used as the key. </param>
+ /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
+ /// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
+ ///<exception cref="DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
+ public virtual IDictionary ExecuteQueryForMap(ISession session, object parameterObject, string keyProperty, string valueProperty)
+ {
+ return Execute<IDictionary, PreSelectEventArgs, PostSelectEventArgs>(
+ PreSelectEvent,
+ PostSelectEvent,
+ session,
+ parameterObject,
+ (r, p) => RunQueryForMap(r, session, p, keyProperty, valueProperty, null));
+ }
+
+ /// <summary>
+ /// Executes the SQL and retuns all rows selected in a map that is keyed on the property named
+ /// in the keyProperty parameter. The value at each key will be the value of the property specified
+ /// in the valueProperty parameter. If valueProperty is null, the entire result object will be entered.
+ /// </summary>
+ /// <param name="request">The request scope.</param>
+ /// <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="keyProperty">The property of the result object to be used as the key.</param>
+ /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
+ /// <param name="rowDelegate">A delegate called once per row in the QueryForMapWithRowDelegate method</param>
+ /// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
+ ///<exception cref="DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
+ internal IDictionary RunQueryForMap(RequestScope request,
+ ISession session,
+ object parameterObject,
+ string keyProperty,
+ string valueProperty,
+ DictionaryRowDelegate rowDelegate)
+ {
+ IDictionary map = new Hashtable();
+
+ using (IDbCommand command = request.IDbCommand)
+ {
+ IDataReader reader = command.ExecuteReader();
+ try
+ {
+
+ if (rowDelegate == null)
+ {
+ while (reader.Read())
+ {
+ object obj = resultStrategy.Process(request, ref reader, null);
+ object key = ObjectProbe.GetMemberValue(obj, keyProperty, request.DataExchangeFactory.AccessorFactory);
+ object value = obj;
+ if (valueProperty != null)
+ {
+ value = ObjectProbe.GetMemberValue(obj, valueProperty, request.DataExchangeFactory.AccessorFactory);
+ }
+ map.Add(key, value);
+ }
+ }
+ else
+ {
+ while (reader.Read())
+ {
+ object obj = resultStrategy.Process(request, ref reader, null);
+ object key = ObjectProbe.GetMemberValue(obj, keyProperty, request.DataExchangeFactory.AccessorFactory);
+ object value = obj;
+ if (valueProperty != null)
+ {
+ value = ObjectProbe.GetMemberValue(obj, valueProperty, request.DataExchangeFactory.AccessorFactory);
+ }
+ rowDelegate(key, value, parameterObject, map);
+
+ }
+ }
+ }
+ finally
+ {
+ reader.Close();
+ reader.Dispose();
+ }
+ ExecuteDelayedLoad(request);
+ }
+ return map;
+
+ }
+
+ /// <summary>
+ /// Executes the SQL and retuns all rows selected in a map that is keyed on the property named
+ /// in the keyProperty parameter. The value at each key will be the value of the property specified
+ /// in the valueProperty parameter. If valueProperty is null, the entire result object will be entered.
+ /// </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="keyProperty">The property of the result object to be used as the key. </param>
+ /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
+ /// <returns>A IDictionary of object containing the rows keyed by keyProperty.</returns>
+ ///<exception cref="Apache.Ibatis.DataMapper.Exceptions.DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
+ public virtual IDictionary<K, V> ExecuteQueryForDictionary<K, V>(ISession session, object parameterObject, string keyProperty, string valueProperty)
+ {
+ return Execute<IDictionary<K, V>, PreSelectEventArgs, PostSelectEventArgs>(
+ PreSelectEvent,
+ PostSelectEvent,
+ session,
+ parameterObject,
+ (r, p) => RunQueryForDictionary<K, V>(r, session, p, keyProperty, valueProperty, null));
+ }
+
+ /// <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="keyProperty">The property of the result object to be used as the key. </param>
+ /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
+ /// <param name="rowDelegate">A delegate called once per row in the QueryForDictionary method</param>
+ /// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
+ ///<exception cref="DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
+ public virtual IDictionary<K, V> ExecuteQueryForDictionary<K, V>(ISession session, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate<K, V> rowDelegate)
+ {
+ if (rowDelegate == null)
+ {
+ throw new DataMapperException("A null DictionaryRowDelegate was passed to QueryForDictionary.");
+ }
+
+ return Execute<IDictionary<K, V>, PreSelectEventArgs, PostSelectEventArgs>(
+ PreSelectEvent,
+ PostSelectEvent,
+ session,
+ parameterObject,
+ (r, p) => RunQueryForDictionary(r, session, p, keyProperty, valueProperty, rowDelegate));
+ }
+
+ /// <summary>
+ /// Executes the SQL and retuns all rows selected in a map that is keyed on the property named
+ /// in the keyProperty parameter. The value at each key will be the value of the property specified
+ /// in the valueProperty parameter. If valueProperty is null, the entire result object will be entered.
+ /// </summary>
+ /// <param name="request">The request scope.</param>
+ /// <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="keyProperty">The property of the result object to be used as the key.</param>
+ /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
+ /// <param name="rowDelegate">A delegate called once per row in the QueryForMapWithRowDelegate method</param>
+ /// <returns>A IDictionary of object containing the rows keyed by keyProperty.</returns>
+ ///<exception cref="DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
+ internal IDictionary<K, V> RunQueryForDictionary<K, V>(RequestScope request,
+ ISession session,
+ object parameterObject,
+ string keyProperty,
+ string valueProperty,
+ DictionaryRowDelegate<K, V> rowDelegate)
+ {
+ IDictionary<K, V> map = new Dictionary<K, V>();
+
+ using (IDbCommand command = request.IDbCommand)
+ {
+ IDataReader reader = command.ExecuteReader();
+ try
+ {
+
+ if (rowDelegate == null)
+ {
+ while (reader.Read())
+ {
+ object obj = resultStrategy.Process(request, ref reader, null);
+ K key = (K)ObjectProbe.GetMemberValue(obj, keyProperty, request.DataExchangeFactory.AccessorFactory);
+ V value = default(V);
+ if (valueProperty != null)
+ {
+ value = (V)ObjectProbe.GetMemberValue(obj, valueProperty, request.DataExchangeFactory.AccessorFactory);
+ }
+ else
+ {
+ value = (V)obj;
+ }
+ map.Add(key, value);
+ }
+ }
+ else
+ {
+ while (reader.Read())
+ {
+ object obj = resultStrategy.Process(request, ref reader, null);
+ K key = (K)ObjectProbe.GetMemberValue(obj, keyProperty, request.DataExchangeFactory.AccessorFactory);
+ V value = default(V);
+ if (valueProperty != null)
+ {
+ value = (V)ObjectProbe.GetMemberValue(obj, valueProperty, request.DataExchangeFactory.AccessorFactory);
+ }
+ else
+ {
+ value = (V)obj;
+ }
+ rowDelegate(key, value, parameterObject, map);
+ }
+ }
+ }
+ finally
+ {
+ reader.Close();
+ reader.Dispose();
+ }
+ ExecuteDelayedLoad(request);
+ }
+ return map;
+
+ }
+
+ /// <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="keyProperty">The property of the result object to be used as the key. </param>
+ /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
+ /// <param name="rowDelegate"></param>
+ /// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
+ ///<exception cref="DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
+ public virtual IDictionary ExecuteQueryForMapWithRowDelegate(ISession session, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate rowDelegate)
+ {
+ if (rowDelegate == null)
+ {
+ throw new DataMapperException("A null DictionaryRowDelegate was passed to QueryForMapWithRowDelegate.");
+ }
+
+ return Execute<IDictionary, PreSelectEventArgs, PostSelectEventArgs>(
+ PreSelectEvent,
+ PostSelectEvent,
+ session,
+ parameterObject,
+ (r, p) => RunQueryForMap(r, session, p, keyProperty, valueProperty, rowDelegate));
+ }
+ }
+}
Added: ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForObject.cs
URL: http://svn.apache.org/viewvc/ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForObject.cs?rev=788267&view=auto
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForObject.cs (added)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForObject.cs Thu Jun 25 05:41:43 2009
@@ -0,0 +1,112 @@
+#region Apache Notice
+/*****************************************************************************
+ * $Revision: 374175 $
+ * $LastChangedDate: 2008-10-11 12:07:44 -0400 (Sat, 11 Oct 2008) $
+ * $LastChangedBy: gbayon $
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2008/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
+
+using System.Data;
+using Apache.Ibatis.DataMapper.Model.Events;
+using Apache.Ibatis.DataMapper.Scope;
+using Apache.Ibatis.DataMapper.Session;
+
+namespace Apache.Ibatis.DataMapper.MappedStatements
+{
+ public partial class MappedStatement
+ {
+ /// <summary>
+ /// Executes an SQL statement that returns a single row as an Object of the type of
+ /// the resultObject passed in as a parameter.
+ /// </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="resultObject">The result object.</param>
+ /// <returns>The object</returns>
+ public virtual object ExecuteQueryForObject(ISession session, object parameterObject, object resultObject)
+ {
+ return ExecuteQueryForObject<object>(session, parameterObject, resultObject);
+ }
+
+ /// <summary>
+ /// Executes an SQL statement that returns a single row as an Object of the type of
+ /// the resultObject passed in as a parameter.
+ /// </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="resultObject">The result object.</param>
+ /// <returns>The object</returns>
+ public virtual T ExecuteQueryForObject<T>(ISession session, object parameterObject, T resultObject)
+ {
+ return Execute<T, PreSelectEventArgs, PostSelectEventArgs>(
+ PreSelectEvent,
+ PostSelectEvent,
+ session,
+ parameterObject,
+ (r, p) => RunQueryForObject(r, session, p, resultObject));
+ }
+
+ /// <summary>
+ /// Executes an SQL statement that returns a single row as an Object of the type of
+ /// the resultObject passed in as a parameter.
+ /// </summary>
+ /// <param name="request">The request scope.</param>
+ /// <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="resultObject">The result object.</param>
+ /// <returns>The object</returns>
+ internal T RunQueryForObject<T>(RequestScope request, ISession session, object parameterObject, T resultObject)
+ {
+ T result = resultObject;
+
+ using (IDbCommand command = request.IDbCommand)
+ {
+ IDataReader reader = command.ExecuteReader();
+ try
+ {
+ while (reader.Read())
+ {
+ object obj = resultStrategy.Process(request, ref reader, resultObject);
+ if (obj != BaseStrategy.SKIP)
+ {
+ result = (T)obj;
+ }
+ }
+ }
+ finally
+ {
+ reader.Close();
+ reader.Dispose();
+ }
+
+ ExecuteDelayedLoad(request);
+
+ #region remark
+ // If you are using the OleDb data provider, you need to close the
+ // DataReader before output parameters are visible.
+ #endregion
+
+ RetrieveOutputParameters(request, session, command, parameterObject);
+ }
+
+ return result;
+ }
+ }
+}
Added: ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteUpdate.cs
URL: http://svn.apache.org/viewvc/ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteUpdate.cs?rev=788267&view=auto
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteUpdate.cs (added)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteUpdate.cs Thu Jun 25 05:41:43 2009
@@ -0,0 +1,63 @@
+#region Apache Notice
+/*****************************************************************************
+ * $Revision: 374175 $
+ * $LastChangedDate: 2008-10-11 12:07:44 -0400 (Sat, 11 Oct 2008) $
+ * $LastChangedBy: gbayon $
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2008/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
+
+using System.Data;
+using Apache.Ibatis.DataMapper.Model.Events;
+using Apache.Ibatis.DataMapper.Session;
+
+namespace Apache.Ibatis.DataMapper.MappedStatements
+{
+ public partial class MappedStatement
+ {
+ /// <summary>
+ /// Execute an update statement. Also used for delete statement.
+ /// Return the number of row effected.
+ /// </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>
+ /// <returns>The number of row effected.</returns>
+ public virtual int ExecuteUpdate(ISession session, object parameterObject)
+ {
+ return Execute<int, PreUpdateOrDeleteEventArgs, PostUpdateOrDeleteEventArgs>(
+ PreUpdateOrDeleteEvent,
+ PostUpdateOrDeleteEvent,
+ session,
+ parameterObject,
+ (r, p) =>
+ {
+ int rows; // the number of rows affected
+
+ using (IDbCommand command = r.IDbCommand)
+ {
+ rows = command.ExecuteNonQuery();
+
+ RetrieveOutputParameters(r, session, command, p);
+ }
+ return rows;
+ });
+ }
+
+ }
+}