Author: gbayon
Date: Mon Jul 25 11:19:33 2005
New Revision: 225160
URL: http://svn.apache.org/viewcvs?rev=225160&view=rev
Log:
- Begin to fix IBATISNET-98, need unit test
Modified:
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/MappedStatements/IMappedStatement.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs?rev=225160&r1=225159&r2=225160&view=diff
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs
Mon Jul 25 11:19:33 2005
@@ -82,7 +82,6 @@
}
#endregion
- #region Methods
#region ExecuteQueryForMap
/// <summary>
@@ -151,36 +150,52 @@
#endregion
+ #region ExecuteForObject
+
/// <summary>
///
/// </summary>
/// <param name="session"></param>
/// <param name="parameterObject"></param>
- /// <param name="rowDelegate"></param>
/// <returns></returns>
- IList ExecuteQueryForRowDelegate( IDalSession session, object
parameterObject, SqlMapper.RowDelegate rowDelegate );
-
- #region ExecuteForObject
+ object ExecuteQueryForObject( IDalSession session, object
parameterObject );
/// <summary>
///
/// </summary>
/// <param name="session"></param>
/// <param name="parameterObject"></param>
+ /// <param name="resultObject"></param>
/// <returns></returns>
- object ExecuteQueryForObject( IDalSession session, object
parameterObject );
+ object ExecuteQueryForObject( IDalSession session, object
parameterObject, object resultObject );
+
+ #endregion
+
+ #region Delegate
/// <summary>
///
/// </summary>
/// <param name="session"></param>
/// <param name="parameterObject"></param>
- /// <param name="resultObject"></param>
+ /// <param name="rowDelegate"></param>
/// <returns></returns>
- object ExecuteQueryForObject( IDalSession session, object
parameterObject, object resultObject );
+ IList ExecuteQueryForRowDelegate( IDalSession session, object
parameterObject, SqlMapper.RowDelegate rowDelegate );
- #endregion
- #endregion
+ /// <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="IBatisNet.DataMapper.Exceptions.DataMapperException">If a transaction is
not in progress, or the database throws an exception.</exception>
+ IDictionary ExecuteQueryForMapWithRowDelegate( IDalSession
session, object parameterObject, string keyProperty, string valueProperty,
SqlMapper.DictionaryRowDelegate rowDelegate );
+ #endregion
+
}
}
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=225160&r1=225159&r2=225160&view=diff
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
Mon Jul 25 11:19:33 2005
@@ -450,7 +450,6 @@
{
object result = resultObject;
- //using ( IDbCommand command =
CreatePreparedCommand(request, session, parameterObject ))
using ( IDbCommand command = _preparedCommand.Create(
request, session, this.Statement, parameterObject ) )
{
using ( IDataReader reader =
command.ExecuteReader() )
@@ -497,6 +496,29 @@
return RunQueryForList(request, session,
parameterObject, NO_SKIPPED_RESULTS, NO_MAXIMUM_RESULTS, 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(
IDalSession session, object parameterObject, string keyProperty, string
valueProperty, SqlMapper.DictionaryRowDelegate rowDelegate )
+ {
+ RequestScope request =
_statement.Sql.GetRequestScope(parameterObject, session);;
+
+ if (rowDelegate == null)
+ {
+ throw new DataMapperException("A null
DictionaryRowDelegate was passed to QueryForMapWithRowDelegate.");
+ }
+
+ return RunQueryForMap(request, session,
parameterObject, keyProperty, valueProperty, rowDelegate);
+ }
+
/// <summary>
/// Executes the SQL and retuns all rows selected. This is
exactly the same as
@@ -578,7 +600,6 @@
{
IList list = null;
- //using ( IDbCommand command =
CreatePreparedCommand(request, session, parameterObject ))
using ( IDbCommand command = _preparedCommand.Create(
request, session, this.Statement, parameterObject ) )
{
if (_statement.ListClass == null)
@@ -769,22 +790,12 @@
/// 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>
+ /// <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>
+ ///<exception cref="DataMapperException">If a transaction is
not in progress, or the database throws an exception.</exception>
public virtual IDictionary ExecuteQueryForMap( IDalSession
session, object parameterObject, string keyProperty, string valueProperty )
{
IDictionary map = new Hashtable();
@@ -792,7 +803,7 @@
if (_statement.CacheModel == null)
{
- map = RunQueryForMap(request, session,
parameterObject, keyProperty, valueProperty );
+ map = RunQueryForMap(request, session,
parameterObject, keyProperty, valueProperty, null );
}
else
{
@@ -821,7 +832,7 @@
map = (IDictionary)_statement.CacheModel[key];
if (map == null)
{
- map = RunQueryForMap( request, session,
parameterObject, keyProperty, valueProperty );
+ map = RunQueryForMap( request, session,
parameterObject, keyProperty, valueProperty, null );
_statement.CacheModel[key] = map;
}
}
@@ -840,32 +851,55 @@
/// <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>
- private IDictionary RunQueryForMap( RequestScope request,
IDalSession session,
- object parameterObject, string keyProperty, string
valueProperty )
+ private IDictionary RunQueryForMap( RequestScope request,
+ IDalSession session,
+ object parameterObject,
+ string keyProperty,
+ string valueProperty,
+ SqlMapper.DictionaryRowDelegate rowDelegate )
{
IDictionary map = new Hashtable();
- IList list = ExecuteQueryForList(session,
parameterObject);
-
- for(int i =0; i<list.Count; i++)
+ using (IDbCommand command =
_preparedCommand.Create(request, session, this.Statement, parameterObject))
{
- object obj = list[i];
- if (obj != null)
+ using (IDataReader reader =
command.ExecuteReader())
{
- object key =
ObjectProbe.GetPropertyValue(obj, keyProperty);
-
- object value = obj;
- if (valueProperty != null)
+ if (rowDelegate == null)
{
- value =
ObjectProbe.GetPropertyValue(obj, valueProperty);
+ while (reader.Read() )
+ {
+ object obj =
ApplyResultMap(request, reader, null);
+ object key =
ObjectProbe.GetPropertyValue(obj, keyProperty);
+ object value = obj;
+ if (valueProperty !=
null)
+ {
+ value =
ObjectProbe.GetPropertyValue(obj, valueProperty);
+ }
+ map.Add(key, value);
+ }
}
- map.Add(key, value);
- }
- }
+ else
+ {
+ while (reader.Read())
+ {
+ object obj =
ApplyResultMap(request, reader, null);
+ object key =
ObjectProbe.GetPropertyValue(obj, keyProperty);
+ object value = obj;
+ if (valueProperty !=
null)
+ {
+ value =
ObjectProbe.GetPropertyValue(obj, valueProperty);
+ }
+ rowDelegate(key, value,
map);
+ }
+ }
+ }
+ }
return map;
+
}
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs?rev=225160&r1=225159&r2=225160&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs Mon Jul 25
11:19:33 2005
@@ -56,10 +56,16 @@
{
/// <summary>
- ///
+ /// A delegate called once per row in the QueryWithRowDelegate
method
/// </summary>
public delegate void RowDelegate(object obj, IList list);
+ /// <summary>
+ /// A delegate called once per row in the QueryWithRowDelegate
method
+ /// </summary>
+ public delegate void DictionaryRowDelegate(object key, object
value, IDictionary dictionary);
+
+
#region Fields
//(MappedStatement Name, MappedStatement)
private HybridDictionary _mappedStatements = new
HybridDictionary();
@@ -837,7 +843,7 @@
#region QueryWithRowDelegate
/// <summary>
- /// Runs a query with a custom object that gets a chance to
deal
+ /// 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
@@ -879,6 +885,55 @@
}
return list;
+ }
+
+
+ /// <summary>
+ /// Runs a query 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="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 IDictionary (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 IDictionary QueryForMapWithRowDelegate(string
statementName, object parameterObject, string keyProperty, string
valueProperty, DictionaryRowDelegate rowDelegate)
+ {
+ bool isSessionLocal = false;
+ IDalSession session = _sessionContainer.LocalSession;
+ IDictionary map = null;
+
+ if (session == null)
+ {
+ session = new SqlMapSession(this.DataSource);
+ session.OpenConnection();
+ isSessionLocal = true;
+ }
+
+ IMappedStatement statement =
GetMappedStatement(statementName);
+
+ try
+ {
+ map =
statement.ExecuteQueryForMapWithRowDelegate(session, parameterObject,
keyProperty, valueProperty, rowDelegate);
+ }
+ catch
+ {
+ throw;
+ }
+ finally
+ {
+ if ( isSessionLocal )
+ {
+ session.CloseConnection();
+ }
+ }
+
+ return map;
}