Skip to content

Commit 7509e26

Browse files
oskarbhazzik
authored andcommitted
Partially revert bf8056a "Fix NH-2673, NH-1090, NH-1344" plus some later changes that depend on it. Will port refactored result transformer handling from Hibernate instead.
1 parent ab86ab8 commit 7509e26

File tree

4 files changed

+10
-29
lines changed

4 files changed

+10
-29
lines changed

src/NHibernate/Cache/QueryKey.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ public QueryKey(ISessionFactoryImplementor factory, SqlString queryString, Query
6060
_hashCode = ComputeHashCode();
6161
}
6262

63-
public bool HasResultTransformer
64-
{
65-
get { return _customTransformer != null; }
66-
}
67-
6863
public QueryKey SetFirstRows(int[] firstRows)
6964
{
7065
_multiQueriesFirstRows = firstRows;

src/NHibernate/Cache/StandardQueryCache.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public bool Put(QueryKey key, ICacheAssembler[] returnTypes, IList result, bool
6868
IList cacheable = new List<object>(result.Count + 1) {ts};
6969
for (int i = 0; i < result.Count; i++)
7070
{
71-
if (returnTypes.Length == 1 && !key.HasResultTransformer)
71+
if (returnTypes.Length == 1)
7272
{
7373
cacheable.Add(returnTypes[0].Disassemble(result[i], session, null));
7474
}
@@ -109,7 +109,7 @@ public IList Get(QueryKey key, ICacheAssembler[] returnTypes, bool isNaturalKeyL
109109
Log.DebugFormat("returning cached query results for: {0}", key);
110110
for (int i = 1; i < cacheable.Count; i++)
111111
{
112-
if (returnTypes.Length == 1 && !key.HasResultTransformer)
112+
if (returnTypes.Length == 1)
113113
{
114114
returnTypes[0].BeforeAssemble(cacheable[i], session);
115115
}
@@ -124,7 +124,7 @@ public IList Get(QueryKey key, ICacheAssembler[] returnTypes, bool isNaturalKeyL
124124
{
125125
try
126126
{
127-
if (returnTypes.Length == 1 && !key.HasResultTransformer)
127+
if (returnTypes.Length == 1)
128128
{
129129
result.Add(returnTypes[0].Assemble(cacheable[i], session, null));
130130
}

src/NHibernate/Impl/CriteriaImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class CriteriaImpl : ICriteria
2626
private int timeout = RowSelection.NoValue;
2727
private int fetchSize = RowSelection.NoValue;
2828
private ISessionImplementor session;
29-
private IResultTransformer resultTransformer;
29+
private IResultTransformer resultTransformer = CriteriaSpecification.RootEntity;
3030
private bool cacheable;
3131
private string cacheRegion;
3232
private CacheMode? cacheMode;

src/NHibernate/Loader/Criteria/CriteriaLoader.cs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ protected override object GetResultColumnOrRow(object[] row, IResultTransformer
7979
ISessionImplementor session)
8080
{
8181
object[] result;
82+
string[] aliases;
8283

8384
if (translator.HasProjection)
8485
{
@@ -101,18 +102,14 @@ protected override object GetResultColumnOrRow(object[] row, IResultTransformer
101102
}
102103
position += numColumns;
103104
}
105+
aliases = translator.ProjectedAliases;
104106
}
105107
else
106108
{
107109
result = row;
110+
aliases = userAliases;
108111
}
109-
110-
if (customResultTransformer == null)
111-
{
112-
// apply the defaut transformer of criteria aka RootEntityResultTransformer
113-
return result[result.Length - 1];
114-
}
115-
return result;
112+
return translator.RootCriteria.ResultTransformer.TransformTuple(result, aliases);
116113
}
117114

118115
protected override SqlString ApplyLocks(SqlString sqlSelectString, IDictionary<string, LockMode> lockModes,
@@ -165,20 +162,9 @@ public override LockMode[] GetLockModes(IDictionary<string, LockMode> lockModes)
165162
return lockModesArray;
166163
}
167164

168-
public override IList GetResultList(IList results, IResultTransformer customResultTransformer)
165+
public override IList GetResultList(IList results, IResultTransformer resultTransformer)
169166
{
170-
if (customResultTransformer == null)
171-
{
172-
// apply the defaut transformer of criteria aka RootEntityResultTransformer
173-
return results;
174-
}
175-
for (int i = 0; i < results.Count; i++)
176-
{
177-
var row = results[i] as object[] ?? new object[] { results[i] };
178-
object result = customResultTransformer.TransformTuple(row, translator.HasProjection ? translator.ProjectedAliases : userAliases);
179-
results[i] = result;
180-
}
181-
return customResultTransformer.TransformList(results);
167+
return translator.RootCriteria.ResultTransformer.TransformList(results);
182168
}
183169

184170
protected override IEnumerable<IParameterSpecification> GetParameterSpecifications()

0 commit comments

Comments
 (0)