|
From: <ste...@us...> - 2009-10-22 20:27:29
|
Revision: 4796
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4796&view=rev
Author: steverstrong
Date: 2009-10-22 20:27:17 +0000 (Thu, 22 Oct 2009)
Log Message:
-----------
Updated Linq parameter handling
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Engine/Query/HQLQueryPlan.cs
trunk/nhibernate/src/NHibernate/IQueryExpression.cs
trunk/nhibernate/src/NHibernate/ISession.cs
trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs
trunk/nhibernate/src/NHibernate/Impl/QueryImpl.cs
trunk/nhibernate/src/NHibernate/Linq/CommandData.cs
trunk/nhibernate/src/NHibernate/Linq/NhQueryable.cs
Modified: trunk/nhibernate/src/NHibernate/Engine/Query/HQLQueryPlan.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Engine/Query/HQLQueryPlan.cs 2009-10-22 14:59:17 UTC (rev 4795)
+++ trunk/nhibernate/src/NHibernate/Engine/Query/HQLQueryPlan.cs 2009-10-22 20:27:17 UTC (rev 4796)
@@ -135,7 +135,7 @@
var parameterTranslations = translator.GetParameterTranslations();
var namedParamDescriptorMap = new Dictionary<string, NamedParameterDescriptor>();
- foreach (NamedParameterDescriptor entry in queryExpression.Parameters)
+ foreach (NamedParameterDescriptor entry in queryExpression.ParameterDescriptors)
{
namedParamDescriptorMap[entry.Name] =
new NamedParameterDescriptor(entry.Name, parameterTranslations.GetNamedParameterExpectedType(entry.Name),
Modified: trunk/nhibernate/src/NHibernate/IQueryExpression.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/IQueryExpression.cs 2009-10-22 14:59:17 UTC (rev 4795)
+++ trunk/nhibernate/src/NHibernate/IQueryExpression.cs 2009-10-22 20:27:17 UTC (rev 4796)
@@ -10,7 +10,7 @@
IASTNode Translate(ISessionFactory sessionFactory);
string Key { get; }
System.Type Type { get; }
- IList<NamedParameterDescriptor> Parameters { get; }
- void SetQueryParametersPriorToExecute(QueryImpl impl);
+ IList<NamedParameterDescriptor> ParameterDescriptors { get; }
+ void SetQueryPropertiesPriorToExecute(IQuery impl);
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/ISession.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/ISession.cs 2009-10-22 14:59:17 UTC (rev 4795)
+++ trunk/nhibernate/src/NHibernate/ISession.cs 2009-10-22 20:27:17 UTC (rev 4796)
@@ -803,7 +803,7 @@
/// <param name="queryString">A hibernate query string</param>
/// <returns>The query</returns>
IQuery CreateQuery(string queryString);
-
+
/// <summary>
/// Create a new instance of <c>Query</c> for the given query expression
/// <param name="queryExpression"/>A hibernate query expression</param>
Modified: trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs 2009-10-22 14:59:17 UTC (rev 4795)
+++ trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs 2009-10-22 20:27:17 UTC (rev 4796)
@@ -259,8 +259,10 @@
{
CheckAndUpdateSessionStatus();
HQLQueryPlan queryPlan = GetHQLQueryPlan(queryExpression, false);
- QueryImpl query = new QueryImpl(queryPlan.QueryExpression, this,
- queryPlan.ParameterMetadata);
+ QueryImpl query = new QueryImpl(queryPlan.QueryExpression,
+ this,
+ queryPlan.ParameterMetadata
+ );
query.SetComment("[expression]");
return query;
}
Modified: trunk/nhibernate/src/NHibernate/Impl/QueryImpl.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/QueryImpl.cs 2009-10-22 14:59:17 UTC (rev 4795)
+++ trunk/nhibernate/src/NHibernate/Impl/QueryImpl.cs 2009-10-22 20:27:17 UTC (rev 4796)
@@ -13,7 +13,7 @@
public class QueryImpl : AbstractQueryImpl
{
private readonly Dictionary<string, LockMode> lockModes = new Dictionary<string, LockMode>(2);
- private readonly IQueryExpression _queryExpression;
+ private readonly IQueryExpression _queryExpression;
public QueryImpl(string queryString, FlushMode flushMode, ISessionImplementor session, ParameterMetadata parameterMetadata)
: base(queryString, flushMode, session, parameterMetadata)
@@ -63,11 +63,6 @@
public override IList List()
{
- if (_queryExpression != null)
- {
- _queryExpression.SetQueryParametersPriorToExecute(this);
- }
-
VerifyParameters();
IDictionary<string, TypedValue> namedParams = NamedParams;
Before();
@@ -79,7 +74,8 @@
}
else
{
- return Session.List(_queryExpression, GetQueryParameters(namedParams));
+ _queryExpression.SetQueryPropertiesPriorToExecute(this);
+ return Session.List(_queryExpression, GetQueryParameters(namedParams));
}
}
finally
Modified: trunk/nhibernate/src/NHibernate/Linq/CommandData.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/CommandData.cs 2009-10-22 14:59:17 UTC (rev 4795)
+++ trunk/nhibernate/src/NHibernate/Linq/CommandData.cs 2009-10-22 20:27:17 UTC (rev 4796)
@@ -23,14 +23,6 @@
public HqlQuery Statement { get; private set; }
- public void SetParameters(IQuery query, IDictionary<string, object> parameters)
- {
- foreach (var parameterName in query.NamedParameters)
- {
- query.SetParameter(parameterName, parameters[parameterName]);
- }
- }
-
public void AddAdditionalCriteria(IQuery query)
{
foreach (var criteria in _additionalCriteria)
Modified: trunk/nhibernate/src/NHibernate/Linq/NhQueryable.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/NhQueryable.cs 2009-10-22 14:59:17 UTC (rev 4795)
+++ trunk/nhibernate/src/NHibernate/Linq/NhQueryable.cs 2009-10-22 20:27:17 UTC (rev 4796)
@@ -43,14 +43,18 @@
{
var nhLinqExpression = new NhLinqExpression(expression);
- var query = _session.CreateQuery(nhLinqExpression).List();
+ var query = _session.CreateQuery(nhLinqExpression);
+ SetParameters(query, nhLinqExpression.ParameterValuesByName);
+
+ var results = query.List();
+
if (nhLinqExpression.ReturnType == NhLinqExpressionReturnType.Sequence)
{
- return query.AsQueryable();
+ return results.AsQueryable();
}
- return query[0];
+ return results[0];
}
public TResult Execute<TResult>(Expression expression)
@@ -67,6 +71,14 @@
{
return new NhQueryable<T>(this, expression);
}
+
+ void SetParameters(IQuery query, IDictionary<string, object> parameters)
+ {
+ foreach (var parameterName in query.NamedParameters)
+ {
+ query.SetParameter(parameterName, parameters[parameterName]);
+ }
+ }
}
public enum NhLinqExpressionReturnType
@@ -80,14 +92,13 @@
private readonly Expression _expression;
private CommandData _commandData;
private readonly IDictionary<ConstantExpression, NamedParameter> _queryParameters;
- private readonly IDictionary<string, object> _queryParameterValues;
- public NhLinqExpression(Expression expression)
+ public NhLinqExpression(Expression expression)
{
_expression = PartialEvaluatingExpressionTreeVisitor.EvaluateIndependentSubtrees(expression);
_queryParameters = ExpressionParameterVisitor.Visit(_expression);
- _queryParameterValues = _queryParameters.Values.ToDictionary(p => p.Name, p => p.Value);
+ ParameterValuesByName = _queryParameters.Values.ToDictionary(p => p.Name, p => p.Value);
Key = ExpressionKeyVisitor.Visit(_expression, _queryParameters);
Type = _expression.Type;
@@ -111,14 +122,14 @@
_commandData = QueryModelVisitor.GenerateHqlQuery(queryModel, _queryParameters, requiredHqlParameters);
- Parameters = requiredHqlParameters.AsReadOnly();
+ ParameterDescriptors = requiredHqlParameters.AsReadOnly();
return _commandData.Statement.AstNode;
}
public string Key { get; private set; }
- public IList<NamedParameterDescriptor> Parameters { get; private set; }
+ public IList<NamedParameterDescriptor> ParameterDescriptors { get; private set; }
public ICollection<NamedParameter> ParameterValues { get; private set; }
@@ -126,9 +137,10 @@
public System.Type Type { get; private set; }
- public void SetQueryParametersPriorToExecute(QueryImpl impl)
+ public IDictionary<string, object> ParameterValuesByName { get; private set; }
+
+ public void SetQueryPropertiesPriorToExecute(IQuery impl)
{
- _commandData.SetParameters(impl, _queryParameterValues);
_commandData.SetResultTransformer(impl);
_commandData.AddAdditionalCriteria(impl);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|