Skip to content

Commit

Permalink
Avoiding sync overhead when it is not needed for WrapResultSet
Browse files Browse the repository at this point in the history
SVN: branches/2.1.x@4511
  • Loading branch information
ayende committed Jun 23, 2009
1 parent d8c10ed commit 8c199ce
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/NHibernate/Loader/Loader.cs
Expand Up @@ -1297,7 +1297,12 @@ protected virtual void AdjustNamedParameterLocationsForQueryParameters(QueryPara
log.Info(st.CommandText);
// TODO NH: Callable
rs = session.Batcher.ExecuteReader(st);
rs = WrapResultSetIfEnabled(rs, session);

//NH: this is checked outside the WrapResultSet because we
// want to avoid the syncronization overhead in the vast majority
// of cases where IsWrapResultSetsEnabled is set to false
if (session.Factory.Settings.IsWrapResultSetsEnabled)
rs = WrapResultSet(rs);

Dialect.Dialect dialect = session.Factory.Dialect;
if (!dialect.SupportsLimitOffset || !UseLimit(selection, dialect))
Expand Down Expand Up @@ -1325,25 +1330,18 @@ protected virtual void AutoDiscoverTypes(IDataReader rs)
}

[MethodImpl(MethodImplOptions.Synchronized)]
private IDataReader WrapResultSetIfEnabled(IDataReader rs, ISessionImplementor session)
private IDataReader WrapResultSet(IDataReader rs)
{
// synchronized to avoid multi-thread access issues; defined as method synch to avoid
// potential deadlock issues due to nature of code.
if (session.Factory.Settings.IsWrapResultSetsEnabled)
try
{
try
{
log.Debug("Wrapping result set [" + rs + "]");
return new ResultSetWrapper(rs, RetreiveColumnNameToIndexCache(rs));
}
catch (Exception e)
{
log.Info("Error wrapping result set", e);
return rs;
}
log.Debug("Wrapping result set [" + rs + "]");
return new ResultSetWrapper(rs, RetreiveColumnNameToIndexCache(rs));
}
else
catch (Exception e)
{
log.Info("Error wrapping result set", e);
return rs;
}
}
Expand Down

0 comments on commit 8c199ce

Please sign in to comment.