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/27 18:57:08 UTC
svn commit: r788996 - in
/ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper: ./
MappedStatements/ Model/Events/
Author: rgrabowski
Date: Sat Jun 27 16:57:07 2009
New Revision: 788996
URL: http://svn.apache.org/viewvc?rev=788996&view=rev
Log:
Removed classes that extended PostStatementEventArgs but didn't add any functionality.
Added missing call to PreparedCommand.Create in MappedStatement.Execute (Sqlite test case works now...SqlServer should too).
Consolidated RunQueryForList overloads in MappedStatement.QueryForList.
Removed:
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Model/Events/PostInsertEventArgs.cs
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Model/Events/PostSelectEventArgs.cs
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Model/Events/PostUpdateOrDeleteEventArgs.cs
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Model/Events/PreInsertEventArgs.cs
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Model/Events/PreSelectEventArgs.cs
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Model/Events/PreUpdateOrDeleteEventArgs.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/IMappedStatementEvents.cs
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
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.cs
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatementEventSupport.cs
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Model/Events/PostStatementEventArgs.cs
ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Model/Events/PreStatementEventArgs.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=788996&r1=788995&r2=788996&view=diff
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Apache.Ibatis.DataMapper.csproj (original)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Apache.Ibatis.DataMapper.csproj Sat Jun 27 16:57:07 2009
@@ -207,12 +207,6 @@
<Compile Include="Model\Events\PrePropertyEventArgs.cs" />
<Compile Include="Model\Events\PreStatementEventArgs.cs" />
<Compile Include="Model\Events\BaseStatementEventArgs.cs" />
- <Compile Include="Model\Events\PostInsertEventArgs.cs" />
- <Compile Include="Model\Events\PostSelectEventArgs.cs" />
- <Compile Include="Model\Events\PostUpdateOrDeleteEventArgs.cs" />
- <Compile Include="Model\Events\PreInsertEventArgs.cs" />
- <Compile Include="Model\Events\PreSelectEventArgs.cs" />
- <Compile Include="Model\Events\PreUpdateOrDeleteEventArgs.cs" />
<Compile Include="Model\ParameterMapping\InlineParemeterMapBuilder.cs" />
<Compile Include="Model\ResultMapping\ArgumentPropertyCollection.cs" />
<Compile Include="Model\ResultMapping\IResultMapEvents.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=788996&r1=788995&r2=788996&view=diff
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/CachingStatement.cs (original)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/CachingStatement.cs Sat Jun 27 16:57:07 2009
@@ -108,6 +108,7 @@
/// <returns>The object</returns>
public DataTable ExecuteQueryForDataTable(ISession session, object parameterObject)
{
+ // TODO: add cache support
return mappedStatement.ExecuteQueryForDataTable(session, parameterObject);
}
@@ -256,7 +257,7 @@
{
IList list = null;
- object param = RaisePreEvent<PreSelectEventArgs>(PreSelectEvent, parameterObject);
+ object param = RaisePreEvent(PreSelectEvent, parameterObject);
RequestScope request = Statement.Sql.GetRequestScope(this, param, session);
@@ -268,11 +269,11 @@
list = Statement.CacheModel[cacheKey] as IList;
if (list == null)
{
- list = mappedStatement.RunQueryForList(request, session, param);
+ list = mappedStatement.RunQueryForList(request, session, param, null, null);
Statement.CacheModel[cacheKey] = list;
}
- return RaisePostEvent<IList, PostSelectEventArgs>(PostSelectEvent, param, list);
+ return RaisePostEvent(PostSelectEvent, param, list);
}
#endregion
@@ -299,7 +300,7 @@
{
IList<T> list = null;
- object param = RaisePreEvent<PreSelectEventArgs>(PreSelectEvent, parameterObject);
+ object param = RaisePreEvent(PreSelectEvent, parameterObject);
RequestScope request = Statement.Sql.GetRequestScope(this, param, session);
@@ -311,10 +312,10 @@
list = Statement.CacheModel[cacheKey] as IList<T>;
if (list == null)
{
- list = mappedStatement.RunQueryForList<T>(request, session, param);
+ list = mappedStatement.RunQueryForList<T>(request, session, param, null, null);
Statement.CacheModel[cacheKey] = list;
}
- return RaisePostEvent<IList<T>, PostSelectEventArgs>(PostSelectEvent, param, list);
+ return RaisePostEvent(PostSelectEvent, param, list);
}
#endregion
@@ -332,7 +333,7 @@
{
object obj = null;
- object param = RaisePreEvent<PreSelectEventArgs>(PreSelectEvent, parameterObject);
+ object param = RaisePreEvent(PreSelectEvent, parameterObject);
RequestScope request = Statement.Sql.GetRequestScope(this, param, session);
@@ -354,7 +355,7 @@
Statement.CacheModel[cacheKey] = obj;
}
- return RaisePostEvent<object, PostSelectEventArgs>(PostSelectEvent, param, obj);
+ return RaisePostEvent(PostSelectEvent, param, obj);
}
#endregion
@@ -373,7 +374,7 @@
{
T obj = default(T);
- object param = RaisePreEvent<PreSelectEventArgs>(PreSelectEvent, parameterObject);
+ object param = RaisePreEvent(PreSelectEvent, parameterObject);
RequestScope request = Statement.Sql.GetRequestScope(this, param, session);
@@ -399,7 +400,7 @@
Statement.CacheModel[cacheKey] = obj;
}
- return RaisePostEvent<T, PostSelectEventArgs>(PostSelectEvent, param, obj);
+ return RaisePostEvent(PostSelectEvent, param, obj);
}
#endregion
Modified: ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/IMappedStatementEvents.cs
URL: http://svn.apache.org/viewvc/ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/IMappedStatementEvents.cs?rev=788996&r1=788995&r2=788996&view=diff
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/IMappedStatementEvents.cs (original)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/IMappedStatementEvents.cs Sat Jun 27 16:57:07 2009
@@ -33,11 +33,11 @@
/// </summary>
public interface IMappedStatementEvents
{
- event EventHandler<PreInsertEventArgs> PreInsert;
- event EventHandler<PreSelectEventArgs> PreSelect;
- event EventHandler<PreUpdateOrDeleteEventArgs> PreUpdateOrDelete;
- event EventHandler<PostInsertEventArgs> PostInsert;
- event EventHandler<PostSelectEventArgs> PostSelect;
- event EventHandler<PostUpdateOrDeleteEventArgs> PostUpdateOrDelete;
+ event EventHandler<PreStatementEventArgs> PreInsert;
+ event EventHandler<PreStatementEventArgs> PreSelect;
+ event EventHandler<PreStatementEventArgs> PreUpdateOrDelete;
+ event EventHandler<PostStatementEventArgs> PostInsert;
+ event EventHandler<PostStatementEventArgs> PostSelect;
+ event EventHandler<PostStatementEventArgs> PostUpdateOrDelete;
}
}
Modified: 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=788996&r1=788995&r2=788996&view=diff
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteInsert.cs (original)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteInsert.cs Sat Jun 27 16:57:07 2009
@@ -25,7 +25,6 @@
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;
@@ -43,11 +42,7 @@
/// <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,
+ return Execute(PreInsertEvent,PostInsertEvent,session,parameterObject,
(r, p) =>
{
#region RunInsert
Modified: 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=788996&r1=788995&r2=788996&view=diff
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForDataTable.cs (original)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForDataTable.cs Sat Jun 27 16:57:07 2009
@@ -24,7 +24,6 @@
#endregion
using System.Data;
-using Apache.Ibatis.DataMapper.Model.Events;
using Apache.Ibatis.DataMapper.Scope;
using Apache.Ibatis.DataMapper.Session;
@@ -41,11 +40,7 @@
/// <returns>The object</returns>
public virtual DataTable ExecuteQueryForDataTable(ISession session, object parameterObject)
{
- return Execute<DataTable, PreSelectEventArgs, PostSelectEventArgs>(
- PreSelectEvent,
- PostSelectEvent,
- session,
- parameterObject,
+ return Execute(PreSelectEvent, PostSelectEvent, session, parameterObject,
(r, p) => RunQueryForForDataTable(r, session, parameterObject));
// return RaisePostEvent<DataTable, PostSelectEventArgs>(PostSelectEvent, param, dataTable);
Modified: 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=788996&r1=788995&r2=788996&view=diff
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForList.cs (original)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForList.cs Sat Jun 27 16:57:07 2009
@@ -28,7 +28,6 @@
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;
@@ -45,11 +44,25 @@
/// <param name="rowDelegate"></param>
public virtual IList ExecuteQueryForRowDelegate(ISession session, object parameterObject, RowDelegate rowDelegate)
{
- return Execute<IList, PreSelectEventArgs, PostSelectEventArgs>(
- PreSelectEvent,
- PostSelectEvent,
- session,
- parameterObject,
+ return Execute(PreSelectEvent, PostSelectEvent, session, parameterObject,
+ (r, p) => RunQueryForList(r, session, p, null, 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 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(PreSelectEvent, PostSelectEvent, session, parameterObject,
(r, p) => RunQueryForList(r, session, p, null, rowDelegate));
}
@@ -61,12 +74,8 @@
/// <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));
+ return Execute(PreSelectEvent,PostSelectEvent,session,parameterObject,
+ (r, p) => RunQueryForList(r, session, p, null, null));
}
/// <summary>
@@ -77,85 +86,32 @@
/// <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,
+ Execute(PreSelectEvent,PostSelectEvent,session,parameterObject,
(r, p) => RunQueryForList(r, session, p, resultObject, null));
}
/// <summary>
- /// Runs the query for list.
+ /// Executes the SQL and retuns all rows selected.
/// </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)
+ public virtual IList<T> ExecuteQueryForList<T>(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 Execute(PreSelectEvent, PostSelectEvent, session, parameterObject,
+ (r, p) => RunQueryForList<T>(r, session, p, null, null));
+ }
- return list;
+ /// <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(PreSelectEvent, PostSelectEvent, session, parameterObject,
+ (r, p) => RunQueryForList(r, session, p, resultObject, null));
}
/// <summary>
@@ -249,112 +205,6 @@
}
/// <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>
Modified: 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=788996&r1=788995&r2=788996&view=diff
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForMap.cs (original)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForMap.cs Sat Jun 27 16:57:07 2009
@@ -28,7 +28,6 @@
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;
@@ -36,7 +35,6 @@
{
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
@@ -50,11 +48,7 @@
///<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,
+ return Execute(PreSelectEvent,PostSelectEvent,session,parameterObject,
(r, p) => RunQueryForMap(r, session, p, keyProperty, valueProperty, null));
}
@@ -63,6 +57,67 @@
/// 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(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(PreSelectEvent,PostSelectEvent,session,parameterObject,
+ (r, p) => RunQueryForDictionary(r, session, p, keyProperty, valueProperty, 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="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(PreSelectEvent,PostSelectEvent,session,parameterObject,
+ (r, p) => RunQueryForMap(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>
@@ -132,53 +187,6 @@
/// 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>
@@ -187,14 +195,14 @@
/// <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,
+ internal IDictionary<TKey, TValue> RunQueryForDictionary<TKey, TValue>(RequestScope request,
ISession session,
object parameterObject,
string keyProperty,
string valueProperty,
- DictionaryRowDelegate<K, V> rowDelegate)
+ DictionaryRowDelegate<TKey, TValue> rowDelegate)
{
- IDictionary<K, V> map = new Dictionary<K, V>();
+ IDictionary<TKey, TValue> map = new Dictionary<TKey, TValue>();
using (IDbCommand command = request.IDbCommand)
{
@@ -207,15 +215,15 @@
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);
+ TKey key = (TKey)ObjectProbe.GetMemberValue(obj, keyProperty, request.DataExchangeFactory.AccessorFactory);
+ TValue value = default(TValue);
if (valueProperty != null)
{
- value = (V)ObjectProbe.GetMemberValue(obj, valueProperty, request.DataExchangeFactory.AccessorFactory);
+ value = (TValue)ObjectProbe.GetMemberValue(obj, valueProperty, request.DataExchangeFactory.AccessorFactory);
}
else
{
- value = (V)obj;
+ value = (TValue)obj;
}
map.Add(key, value);
}
@@ -225,15 +233,15 @@
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);
+ TKey key = (TKey)ObjectProbe.GetMemberValue(obj, keyProperty, request.DataExchangeFactory.AccessorFactory);
+ TValue value = default(TValue);
if (valueProperty != null)
{
- value = (V)ObjectProbe.GetMemberValue(obj, valueProperty, request.DataExchangeFactory.AccessorFactory);
+ value = (TValue)ObjectProbe.GetMemberValue(obj, valueProperty, request.DataExchangeFactory.AccessorFactory);
}
else
{
- value = (V)obj;
+ value = (TValue)obj;
}
rowDelegate(key, value, parameterObject, map);
}
@@ -250,30 +258,5 @@
}
- /// <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));
- }
}
}
Modified: 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=788996&r1=788995&r2=788996&view=diff
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForObject.cs (original)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteQueryForObject.cs Sat Jun 27 16:57:07 2009
@@ -24,7 +24,6 @@
#endregion
using System.Data;
-using Apache.Ibatis.DataMapper.Model.Events;
using Apache.Ibatis.DataMapper.Scope;
using Apache.Ibatis.DataMapper.Session;
@@ -55,11 +54,7 @@
/// <returns>The object</returns>
public virtual T ExecuteQueryForObject<T>(ISession session, object parameterObject, T resultObject)
{
- return Execute<T, PreSelectEventArgs, PostSelectEventArgs>(
- PreSelectEvent,
- PostSelectEvent,
- session,
- parameterObject,
+ return Execute(PreSelectEvent,PostSelectEvent,session,parameterObject,
(r, p) => RunQueryForObject(r, session, p, resultObject));
}
Modified: 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=788996&r1=788995&r2=788996&view=diff
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteUpdate.cs (original)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.ExecuteUpdate.cs Sat Jun 27 16:57:07 2009
@@ -24,7 +24,6 @@
#endregion
using System.Data;
-using Apache.Ibatis.DataMapper.Model.Events;
using Apache.Ibatis.DataMapper.Session;
namespace Apache.Ibatis.DataMapper.MappedStatements
@@ -40,11 +39,7 @@
/// <returns>The number of row effected.</returns>
public virtual int ExecuteUpdate(ISession session, object parameterObject)
{
- return Execute<int, PreUpdateOrDeleteEventArgs, PostUpdateOrDeleteEventArgs>(
- PreUpdateOrDeleteEvent,
- PostUpdateOrDeleteEvent,
- session,
- parameterObject,
+ return Execute(PreUpdateOrDeleteEvent,PostUpdateOrDeleteEvent,session,parameterObject,
(r, p) =>
{
int rows; // the number of rows affected
Modified: ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.cs
URL: http://svn.apache.org/viewvc/ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.cs?rev=788996&r1=788995&r2=788996&view=diff
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.cs (original)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.cs Sat Jun 27 16:57:07 2009
@@ -216,19 +216,17 @@
Executed(this, e);
}
- public virtual T Execute<T, TPreStatementEventArgs, TPostStatementEventArgs>(object preEvent, object postEvent, ISession session, object parameterObject, Func<RequestScope, object, T> requestRunner)
- where TPreStatementEventArgs : PreStatementEventArgs, new()
- where TPostStatementEventArgs : PostStatementEventArgs, new()
+ public virtual T Execute<T>(object preEvent, object postEvent, ISession session, object parameterObject, Func<RequestScope, object, T> requestRunner)
{
- object paramPreEvent = RaisePreEvent<TPreStatementEventArgs>(preEvent, parameterObject);
+ object paramPreEvent = RaisePreEvent(preEvent, parameterObject);
RequestScope request = statement.Sql.GetRequestScope(this, paramPreEvent, session);
-
+ preparedCommand.Create(request, session, Statement, paramPreEvent);
T result = requestRunner(request, paramPreEvent);
RaiseExecuteEvent();
- return RaisePostEvent<T, TPostStatementEventArgs>(postEvent, paramPreEvent, result);
+ return RaisePostEvent(postEvent, paramPreEvent, result);
}
}
}
Modified: ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatementEventSupport.cs
URL: http://svn.apache.org/viewvc/ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatementEventSupport.cs?rev=788996&r1=788995&r2=788996&view=diff
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatementEventSupport.cs (original)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/MappedStatements/MappedStatementEventSupport.cs Sat Jun 27 16:57:07 2009
@@ -47,54 +47,54 @@
#region IMappedStatementEvents Members
/// <summary>
- /// Will handle an <see cref="PreInsertEventArgs"/>.
+ /// Will handle an <see cref="PreStatementEventArgs"/>.
/// </summary>
- public event EventHandler<PreInsertEventArgs> PreInsert
+ public event EventHandler<PreStatementEventArgs> PreInsert
{
add { events.AddHandler(PreInsertEvent, value); }
remove { events.RemoveHandler(PreInsertEvent, value); }
}
/// <summary>
- /// Will handle an <see cref="PreSelectEventArgs"/>.
+ /// Will handle an <see cref="PreStatementEventArgs"/>.
/// </summary>
- public event EventHandler<PreSelectEventArgs> PreSelect
+ public event EventHandler<PreStatementEventArgs> PreSelect
{
add { events.AddHandler(PreSelectEvent, value); }
remove { events.RemoveHandler(PreSelectEvent, value); }
}
/// <summary>
- /// Will handle an <see cref="PreUpdateOrDeleteEventArgs"/>.
+ /// Will handle an <see cref="PreStatementEventArgs"/>.
/// </summary>
- public event EventHandler<PreUpdateOrDeleteEventArgs> PreUpdateOrDelete
+ public event EventHandler<PreStatementEventArgs> PreUpdateOrDelete
{
add { events.AddHandler(PreUpdateOrDeleteEvent, value); }
remove { events.RemoveHandler(PreUpdateOrDeleteEvent, value); }
}
/// <summary>
- /// Will handle an <see cref="PostInsertEventArgs"/>.
+ /// Will handle an <see cref="PostStatementEventArgs"/>.
/// </summary>
- public event EventHandler<PostInsertEventArgs> PostInsert
+ public event EventHandler<PostStatementEventArgs> PostInsert
{
add { events.AddHandler(PostInsertEvent, value); }
remove { events.RemoveHandler(PostInsertEvent, value); }
}
/// <summary>
- /// Will handle an <see cref="PostSelectEventArgs"/>.
+ /// Will handle an <see cref="PostStatementEventArgs"/>.
/// </summary>
- public event EventHandler<PostSelectEventArgs> PostSelect
+ public event EventHandler<PostStatementEventArgs> PostSelect
{
add { events.AddHandler(PostSelectEvent, value); }
remove { events.RemoveHandler(PostSelectEvent, value); }
}
/// <summary>
- /// Will handle an <see cref="PostUpdateOrDeleteEventArgs"/>.
+ /// Will handle an <see cref="PostStatementEventArgs"/>.
/// </summary>
- public event EventHandler<PostUpdateOrDeleteEventArgs> PostUpdateOrDelete
+ public event EventHandler<PostStatementEventArgs> PostUpdateOrDelete
{
add { events.AddHandler(PostUpdateOrDeleteEvent, value); }
remove { events.RemoveHandler(PostUpdateOrDeleteEvent, value); }
@@ -108,14 +108,13 @@
/// <param name="key">The key.</param>
/// <param name="parameterObject">The parameter object.</param>
/// <returns>Returns is used as the parameter object</returns>
- protected object RaisePreEvent<TEvent>(object key, object parameterObject)
- where TEvent : PreStatementEventArgs, new()
+ protected object RaisePreEvent(object key, object parameterObject)
{
- EventHandler<TEvent> handlers = (EventHandler<TEvent>)events[key];
+ var handlers = (EventHandler<PreStatementEventArgs>)events[key];
if (handlers != null)
{
- TEvent eventArgs = new TEvent();
+ var eventArgs = new PreStatementEventArgs();
eventArgs.ParameterObject = parameterObject;
handlers(this, eventArgs);
return eventArgs.ParameterObject;
@@ -130,14 +129,13 @@
/// <param name="parameterObject">The parameter object.</param>
/// <param name="resultObject">The result object.</param>
/// <returns>Returns is used as the result object</returns>
- protected TType RaisePostEvent<TType, TEvent>(object key, object parameterObject, TType resultObject)
- where TEvent : PostStatementEventArgs, new()
+ protected TType RaisePostEvent<TType>(object key, object parameterObject, TType resultObject)
{
- EventHandler<TEvent> handlers = (EventHandler<TEvent>)events[key];
+ var handlers = (EventHandler<PostStatementEventArgs>)events[key];
if (handlers != null)
{
- TEvent eventArgs = new TEvent();
+ var eventArgs = new PostStatementEventArgs();
eventArgs.ParameterObject = parameterObject;
eventArgs.ResultObject = resultObject;
handlers(this, eventArgs);
Modified: ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Model/Events/PostStatementEventArgs.cs
URL: http://svn.apache.org/viewvc/ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Model/Events/PostStatementEventArgs.cs?rev=788996&r1=788995&r2=788996&view=diff
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Model/Events/PostStatementEventArgs.cs (original)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Model/Events/PostStatementEventArgs.cs Sat Jun 27 16:57:07 2009
@@ -28,7 +28,7 @@
/// <summary>
/// Base class for post <see cref="BaseStatementEventArgs"/>
/// </summary>
- public abstract class PostStatementEventArgs : BaseStatementEventArgs
+ public class PostStatementEventArgs : BaseStatementEventArgs
{
/// <summary>
/// Gets or sets the result object.
Modified: ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Model/Events/PreStatementEventArgs.cs
URL: http://svn.apache.org/viewvc/ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Model/Events/PreStatementEventArgs.cs?rev=788996&r1=788995&r2=788996&view=diff
==============================================================================
--- ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Model/Events/PreStatementEventArgs.cs (original)
+++ ibatis/branches/MappedStatementRefactor/Apache.Ibatis.DataMapper/Model/Events/PreStatementEventArgs.cs Sat Jun 27 16:57:07 2009
@@ -28,7 +28,7 @@
/// <summary>
/// Base class for pre <see cref="BaseStatementEventArgs"/>
/// </summary>
- public abstract class PreStatementEventArgs : BaseStatementEventArgs
+ public class PreStatementEventArgs : BaseStatementEventArgs
{
}