|
From: <ric...@us...> - 2009-10-29 14:31:43
|
Revision: 4806
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4806&view=rev
Author: ricbrown
Date: 2009-10-29 14:31:35 +0000 (Thu, 29 Oct 2009)
Log Message:
-----------
Merge r4805 (Updated fix for NH-847 moving responsibility to the driver)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Driver/DriverBase.cs
trunk/nhibernate/src/NHibernate/Driver/IDriver.cs
trunk/nhibernate/src/NHibernate/Driver/OracleClientDriver.cs
trunk/nhibernate/src/NHibernate/Driver/OracleDataClientDriver.cs
trunk/nhibernate/src/NHibernate/Driver/SqlStringFormatter.cs
trunk/nhibernate/src/NHibernate/Engine/Query/CallableParser.cs
trunk/nhibernate/src/NHibernate/Engine/Query/ParamLocationRecognizer.cs
trunk/nhibernate/src/NHibernate/Engine/Query/ParameterMetadata.cs
trunk/nhibernate/src/NHibernate/Engine/Query/ParameterParser.cs
trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs
trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs
trunk/nhibernate/src/NHibernate/Impl/SqlQueryImpl.cs
trunk/nhibernate/src/NHibernate/Loader/Loader.cs
trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs
trunk/nhibernate/src/NHibernate/SqlCommand/SqlCommandInfo.cs
trunk/nhibernate/src/NHibernate.Test/EngineTest/CallableParserFixture.cs
trunk/nhibernate/src/NHibernate.Test/EngineTest/ParameterParserFixture.cs
trunk/nhibernate/src/NHibernate.Test/SqlTest/Custom/Oracle/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/SqlTest/Custom/Oracle/StoredProcedures.hbm.xml
Modified: trunk/nhibernate/src/NHibernate/Driver/DriverBase.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Driver/DriverBase.cs 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate/Driver/DriverBase.cs 2009-10-29 14:31:35 UTC (rev 4806)
@@ -136,11 +136,6 @@
return cmd;
}
- public virtual int RegisterResultSetOutParameter(IDbCommand command, int position, bool hasReturnValue)
- {
- throw new NotImplementedException(GetType().Name + " does not support resultsets via stored procedures");
- }
-
private void SetCommandTimeout(IDbCommand cmd, object envTimeout)
{
if (commandTimeout >= 0)
@@ -215,12 +210,23 @@
public void PrepareCommand(IDbCommand command)
{
+ OnBeforePrepare(command);
+
if (SupportsPreparingCommands && prepareSql)
{
command.Prepare();
}
}
+ /// <summary>
+ /// Override to make any adjustments to the IDbCommand object. (e.g., Oracle custom OUT parameter)
+ /// Parameters have been bound by this point, so their order can be adjusted too.
+ /// This is analagous to the RegisterResultSetOutParameter() function in Hibernate.
+ /// </summary>
+ protected virtual void OnBeforePrepare(IDbCommand command)
+ {
+ }
+
public IDbDataParameter GenerateOutputParameter(IDbCommand command)
{
IDbDataParameter param = GenerateParameter(command, "ReturnValue", SqlTypeFactory.Int32);
Modified: trunk/nhibernate/src/NHibernate/Driver/IDriver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Driver/IDriver.cs 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate/Driver/IDriver.cs 2009-10-29 14:31:35 UTC (rev 4806)
@@ -80,17 +80,6 @@
IDbCommand GenerateCommand(CommandType type, SqlString sqlString, SqlType[] parameterTypes);
/// <summary>
- /// Registers an OUT parameter which will be returing a
- /// <see cref="IDataReader"/>. How this is accomplished varies greatly
- /// from DB to DB, hence its inclusion here.
- /// </summary>
- /// <param name="command">The <see cref="IDbCommand"/> with CommandType.StoredProcedure.</param>
- /// <param name="position">The bind position at which to register the OUT param.</param>
- /// <param name="hasReturnValue">Whether the out parameter is a return value, or an out parameter.</param>
- /// <returns>The number of (contiguous) bind positions used.</returns>
- int RegisterResultSetOutParameter(IDbCommand command, int position, bool hasReturnValue);
-
- /// <summary>
/// Prepare the <paramref name="command" /> by calling <see cref="IDbCommand.Prepare()" />.
/// May be a no-op if the driver does not support preparing commands, or for any other reason.
/// </summary>
Modified: trunk/nhibernate/src/NHibernate/Driver/OracleClientDriver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Driver/OracleClientDriver.cs 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate/Driver/OracleClientDriver.cs 2009-10-29 14:31:35 UTC (rev 4806)
@@ -1,5 +1,6 @@
using System.Data;
using System.Data.OracleClient;
+using NHibernate.Engine.Query;
using NHibernate.SqlTypes;
namespace NHibernate.Driver
@@ -48,10 +49,17 @@
}
}
- public override int RegisterResultSetOutParameter(IDbCommand command, int position, bool hasReturnValue)
+ protected override void OnBeforePrepare(IDbCommand command)
{
+ base.OnBeforePrepare(command);
+
+ CallableParser.Detail detail = CallableParser.Parse(command.CommandText);
+
+ if (!detail.IsCallable)
+ return;
+
throw new System.NotImplementedException(GetType().Name +
- " does not support resultsets via stored procedures." +
+ " does not support CallableStatement syntax (stored procedures)." +
" Consider using OracleDataClientDriver instead.");
}
}
Modified: trunk/nhibernate/src/NHibernate/Driver/OracleDataClientDriver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Driver/OracleDataClientDriver.cs 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate/Driver/OracleDataClientDriver.cs 2009-10-29 14:31:35 UTC (rev 4806)
@@ -1,6 +1,7 @@
using System.Data;
using System.Reflection;
using NHibernate.AdoNet;
+using NHibernate.Engine.Query;
using NHibernate.SqlTypes;
using NHibernate.Util;
@@ -82,17 +83,24 @@
}
}
- public override int RegisterResultSetOutParameter(IDbCommand command, int position, bool hasReturnValue)
+ protected override void OnBeforePrepare(IDbCommand command)
{
+ base.OnBeforePrepare(command);
+
+ CallableParser.Detail detail = CallableParser.Parse(command.CommandText);
+
+ if (!detail.IsCallable)
+ return;
+
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = detail.FunctionName;
+
IDbDataParameter outCursor = command.CreateParameter();
- outCursor.ParameterName = "";
oracleDbType.SetValue(outCursor, oracleDbTypeRefCursor, null);
- outCursor.Direction = hasReturnValue ? ParameterDirection.ReturnValue : ParameterDirection.Output;
+ outCursor.Direction = detail.HasReturn ? ParameterDirection.ReturnValue : ParameterDirection.Output;
- command.Parameters.Insert(position, outCursor);
-
- return 1;
+ command.Parameters.Insert(0, outCursor);
}
#region IEmbeddedBatcherFactoryProvider Members
Modified: trunk/nhibernate/src/NHibernate/Driver/SqlStringFormatter.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Driver/SqlStringFormatter.cs 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate/Driver/SqlStringFormatter.cs 2009-10-29 14:31:35 UTC (rev 4806)
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Text;
using NHibernate.SqlCommand;
+using NHibernate.Engine.Query;
namespace NHibernate.Driver
{
@@ -15,6 +16,9 @@
private readonly Dictionary<int, int> queryIndexToNumberOfPreceedingParameters = new Dictionary<int, int>();
private readonly Dictionary<int, int> parameterIndexToQueryIndex = new Dictionary<int, int>();
+ private bool hasReturnParameter = false;
+ private bool foundReturnParameter = false;
+
public SqlStringFormatter(ISqlParameterFormatter formatter, string multipleQueriesSeparator)
{
this.formatter = formatter;
@@ -24,6 +28,7 @@
public void Format(SqlString text)
{
DetermineNumberOfPreceedingParametersForEachQuery(text);
+ foundReturnParameter = false;
text.Visit(this);
}
@@ -44,6 +49,13 @@
void ISqlStringVisitor.Parameter(Parameter parameter)
{
+ if (hasReturnParameter && !foundReturnParameter)
+ {
+ result.Append(parameter);
+ foundReturnParameter = true;
+ return;
+ }
+
string name;
if (queryIndexToNumberOfPreceedingParameters.Count == 0)
@@ -80,7 +92,14 @@
int currentParameterIndex = 0;
int currentQueryParameterCount = 0;
int currentQueryIndex = 0;
+ hasReturnParameter = false;
+ foundReturnParameter = false;
+ CallableParser.Detail callableDetail = CallableParser.Parse(text.ToString());
+
+ if (callableDetail.IsCallable && callableDetail.HasReturn)
+ hasReturnParameter = true;
+
foreach (object part in text.Parts)
{
if (part.ToString().Equals(multipleQueriesSeparator))
@@ -95,7 +114,14 @@
if (parameter != null)
{
- parameterIndexToQueryIndex[currentParameterIndex] = currentQueryIndex;
+ if (hasReturnParameter && !foundReturnParameter)
+ {
+ foundReturnParameter = true;
+ }
+ else
+ {
+ parameterIndexToQueryIndex[currentParameterIndex] = currentQueryIndex;
+ }
currentQueryParameterCount++;
currentParameterIndex++;
}
Modified: trunk/nhibernate/src/NHibernate/Engine/Query/CallableParser.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Engine/Query/CallableParser.cs 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate/Engine/Query/CallableParser.cs 2009-10-29 14:31:35 UTC (rev 4806)
@@ -8,26 +8,42 @@
{
public static class CallableParser
{
+
+ public class Detail
+ {
+ public bool IsCallable;
+ public bool HasReturn;
+ public string FunctionName;
+ }
+
private static readonly Regex functionNameFinder = new Regex(@"\{[\S\s]*call[\s]+([\w]+)[^\w]");
private static readonly int NewLineLength = Environment.NewLine.Length;
- public static SqlString Parse(string sqlString)
+ public static Detail Parse(string sqlString)
{
- bool isCallableSyntax = sqlString.IndexOf("{") == 0 &&
- sqlString.IndexOf("}") == (sqlString.Length - 1) &&
- sqlString.IndexOf("call") > 0;
+ Detail callableDetail = new Detail();
- if (!isCallableSyntax)
- throw new ParserException("Expected callable syntax {? = call procedure_name[(?, ?, ...)]} but got: " + sqlString);
+ callableDetail.IsCallable = sqlString.IndexOf("{") == 0 &&
+ sqlString.IndexOf("}") == (sqlString.Length - 1) &&
+ sqlString.IndexOf("call") > 0;
+ if (!callableDetail.IsCallable)
+ return callableDetail;
Match functionMatch = functionNameFinder.Match(sqlString);
if ((!functionMatch.Success) || (functionMatch.Groups.Count < 2))
throw new HibernateException("Could not determine function name for callable SQL: " + sqlString);
- string function = functionMatch.Groups[1].Value;
- return new SqlString(function);
+ callableDetail.FunctionName = functionMatch.Groups[1].Value;
+
+ callableDetail.HasReturn = sqlString.IndexOf("call") > 0 &&
+ sqlString.IndexOf("?") > 0 &&
+ sqlString.IndexOf("=") > 0 &&
+ sqlString.IndexOf("?") < sqlString.IndexOf("call") &&
+ sqlString.IndexOf("=") < sqlString.IndexOf("call");
+
+ return callableDetail;
}
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Engine/Query/ParamLocationRecognizer.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Engine/Query/ParamLocationRecognizer.cs 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate/Engine/Query/ParamLocationRecognizer.cs 2009-10-29 14:31:35 UTC (rev 4806)
@@ -13,8 +13,6 @@
private readonly List<int> ordinalParameterLocationList = new List<int>();
- private bool hasReturnValue = false;
-
/// <summary>
/// Convenience method for creating a param location recognizer and
/// initiating the parse.
@@ -49,16 +47,11 @@
get { return ordinalParameterLocationList; }
}
- public bool HasReturnValue
- {
- get { return hasReturnValue; }
- }
-
#region IRecognizer Members
public void OutParameter(int position)
{
- hasReturnValue = true;
+ // don't care...
}
public void OrdinalParameter(int position)
Modified: trunk/nhibernate/src/NHibernate/Engine/Query/ParameterMetadata.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Engine/Query/ParameterMetadata.cs 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate/Engine/Query/ParameterMetadata.cs 2009-10-29 14:31:35 UTC (rev 4806)
@@ -12,17 +12,8 @@
private static readonly OrdinalParameterDescriptor[] EmptyOrdinals = new OrdinalParameterDescriptor[0];
private readonly OrdinalParameterDescriptor[] ordinalDescriptors;
private readonly Dictionary<string, NamedParameterDescriptor> namedDescriptorMap;
- private readonly bool hasReturnValue = false;
public ParameterMetadata(OrdinalParameterDescriptor[] ordinalDescriptors,
- IDictionary<string, NamedParameterDescriptor> namedDescriptorMap,
- bool hasReturnValue)
- : this (ordinalDescriptors, namedDescriptorMap)
- {
- this.hasReturnValue = hasReturnValue;
- }
-
- public ParameterMetadata(OrdinalParameterDescriptor[] ordinalDescriptors,
IDictionary<string, NamedParameterDescriptor> namedDescriptorMap)
{
if (ordinalDescriptors == null)
@@ -52,11 +43,6 @@
get { return namedDescriptorMap.Keys; }
}
- public bool HasReturnValue
- {
- get { return hasReturnValue; }
- }
-
public OrdinalParameterDescriptor GetOrdinalParameterDescriptor(int position)
{
if (position < 1 || position > ordinalDescriptors.Length)
Modified: trunk/nhibernate/src/NHibernate/Engine/Query/ParameterParser.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Engine/Query/ParameterParser.cs 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate/Engine/Query/ParameterParser.cs 2009-10-29 14:31:35 UTC (rev 4806)
@@ -44,8 +44,10 @@
public static void Parse(string sqlString, IRecognizer recognizer)
{
bool hasMainOutputParameter = sqlString.IndexOf("call") > 0 &&
- sqlString.IndexOf("?") < sqlString.IndexOf("call") &&
- sqlString.IndexOf("=") < sqlString.IndexOf("call");
+ sqlString.IndexOf("?") > 0 &&
+ sqlString.IndexOf("=") > 0 &&
+ sqlString.IndexOf("?") < sqlString.IndexOf("call") &&
+ sqlString.IndexOf("=") < sqlString.IndexOf("call");
bool foundMainOutputParam = false;
int stringLength = sqlString.Length;
Modified: trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs 2009-10-29 14:31:35 UTC (rev 4806)
@@ -171,7 +171,7 @@
new NamedParameterDescriptor(name, null, description.BuildPositionsArray(), description.JpaStyle);
}
- return new ParameterMetadata(ordinalDescriptors, namedParamDescriptorMap, recognizer.HasReturnValue);
+ return new ParameterMetadata(ordinalDescriptors, namedParamDescriptorMap);
}
[Serializable]
Modified: trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2009-10-29 14:31:35 UTC (rev 4806)
@@ -279,8 +279,6 @@
public bool Callable { get; set; }
- public bool HasReturnValue { get; set; }
-
public bool ReadOnly
{
get { return _readOnly; }
Modified: trunk/nhibernate/src/NHibernate/Impl/SqlQueryImpl.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/SqlQueryImpl.cs 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate/Impl/SqlQueryImpl.cs 2009-10-29 14:31:35 UTC (rev 4806)
@@ -27,7 +27,6 @@
private readonly IList<INativeSQLQueryReturn> queryReturns;
private readonly ICollection<string> querySpaces;
private readonly bool callable;
- private readonly bool hasReturnValue;
private bool autoDiscoverTypes;
/// <summary> Constructs a SQLQueryImpl given a sql query defined in the mappings. </summary>
@@ -53,9 +52,16 @@
querySpaces = queryDef.QuerySpaces;
callable = queryDef.IsCallable;
- hasReturnValue = parameterMetadata.HasReturnValue;
}
+ internal SqlQueryImpl(string sql, IList<INativeSQLQueryReturn> queryReturns, ICollection<string> querySpaces, FlushMode flushMode, bool callable, ISessionImplementor session, ParameterMetadata parameterMetadata)
+ : base(sql, flushMode, session, parameterMetadata)
+ {
+ this.queryReturns = queryReturns;
+ this.querySpaces = querySpaces;
+ this.callable = callable;
+ }
+
internal SqlQueryImpl(string sql, string[] returnAliases, System.Type[] returnClasses, LockMode[] lockModes, ISessionImplementor session, ICollection<string> querySpaces, FlushMode flushMode, ParameterMetadata parameterMetadata)
: base(sql, flushMode, session, parameterMetadata)
{
@@ -174,7 +180,6 @@
{
QueryParameters qp = base.GetQueryParameters(namedParams);
qp.Callable = callable;
- qp.HasReturnValue = hasReturnValue;
qp.HasAutoDiscoverScalarTypes = autoDiscoverTypes;
return qp;
}
Modified: trunk/nhibernate/src/NHibernate/Loader/Loader.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2009-10-29 14:31:35 UTC (rev 4806)
@@ -11,7 +11,6 @@
using NHibernate.Cache;
using NHibernate.Collection;
using NHibernate.Engine;
-using NHibernate.Engine.Query;
using NHibernate.Event;
using NHibernate.Exceptions;
using NHibernate.Hql.Util;
@@ -1105,8 +1104,7 @@
bool useLimit = UseLimit(selection, dialect);
bool hasFirstRow = GetFirstRow(selection) > 0;
bool useOffset = hasFirstRow && useLimit && dialect.SupportsLimitOffset;
- bool isCallable = queryParameters.Callable;
- bool hasReturnValue = queryParameters.HasReturnValue;
+ // TODO NH bool callable = queryParameters.Callable;
if (useLimit)
{
@@ -1116,19 +1114,10 @@
sqlString = PreprocessSQL(sqlString, queryParameters, dialect);
- IDbCommand command = null;
- if (isCallable)
- {
- command =
- session.Batcher.PrepareQueryCommand(CommandType.StoredProcedure, CallableParser.Parse(sqlString.ToString()),
- GetParameterTypes(queryParameters, useLimit, useOffset));
- }
- else
- {
- command =
- session.Batcher.PrepareQueryCommand(CommandType.Text, sqlString,
- GetParameterTypes(queryParameters, useLimit, useOffset));
- }
+ // TODO NH: Callable for SP -> PrepareCallableQueryCommand
+ IDbCommand command =
+ session.Batcher.PrepareQueryCommand(CommandType.Text, sqlString,
+ GetParameterTypes(queryParameters, useLimit, useOffset));
try
{
@@ -1144,13 +1133,12 @@
{
colIndex += BindLimitParameters(command, colIndex, selection, session);
}
+ // TODO NH
+ //if (callable)
+ //{
+ // colIndex = dialect.RegisterResultSetOutParameter(command, col);
+ //}
- if (isCallable)
- {
- colIndex +=
- session.Factory.ConnectionProvider.Driver.RegisterResultSetOutParameter(command, colIndex, hasReturnValue);
- }
-
colIndex += BindParameterValues(command, queryParameters, colIndex, session);
if (useLimit && !dialect.BindLimitParametersFirst)
@@ -1275,7 +1263,7 @@
// NH Different behavior:
// The responsibility of parameter binding was entirely moved to QueryParameters
// to deal with positionslParameter+NamedParameter+ParameterOfFilters
- return queryParameters.BindParameters(statement, GetNamedParameterLocs, startIndex, session);
+ return queryParameters.BindParameters(statement, GetNamedParameterLocs, 0, session);
}
public virtual int[] GetNamedParameterLocs(string name)
Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2009-10-29 14:31:35 UTC (rev 4806)
@@ -3332,20 +3332,20 @@
SqlCommandInfo defaultDelete = GenerateDeleteString(j);
sqlInsertStrings[j] = customSQLInsert[j] != null
- ? new SqlCommandInfo(customSQLInsert[j], insertCallable[j], defaultInsert.ParameterTypes)
+ ? new SqlCommandInfo(customSQLInsert[j], defaultInsert.ParameterTypes)
: defaultInsert;
sqlUpdateStrings[j] = customSQLUpdate[j] != null
- ? new SqlCommandInfo(customSQLUpdate[j], updateCallable[j], defaultUpdate.ParameterTypes)
+ ? new SqlCommandInfo(customSQLUpdate[j], defaultUpdate.ParameterTypes)
: defaultUpdate;
// NH: in practice for lazy update de update sql is the same any way.
sqlLazyUpdateStrings[j] = customSQLUpdate[j] != null
- ? new SqlCommandInfo(customSQLUpdate[j], updateCallable[j], defaultUpdate.ParameterTypes)
+ ? new SqlCommandInfo(customSQLUpdate[j], defaultUpdate.ParameterTypes)
: GenerateUpdateString(NonLazyPropertyUpdateability, j, false);
sqlDeleteStrings[j] = customSQLDelete[j] != null
- ? new SqlCommandInfo(customSQLDelete[j], deleteCallable[j], defaultDelete.ParameterTypes)
+ ? new SqlCommandInfo(customSQLDelete[j], defaultDelete.ParameterTypes)
: defaultDelete;
}
Modified: trunk/nhibernate/src/NHibernate/SqlCommand/SqlCommandInfo.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/SqlCommand/SqlCommandInfo.cs 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate/SqlCommand/SqlCommandInfo.cs 2009-10-29 14:31:35 UTC (rev 4806)
@@ -1,12 +1,10 @@
using System.Data;
-using NHibernate.Engine.Query;
using NHibernate.SqlTypes;
namespace NHibernate.SqlCommand
{
public class SqlCommandInfo
{
- private readonly CommandType commandType;
private readonly SqlString text;
private readonly SqlType[] parameterTypes;
@@ -14,22 +12,12 @@
{
this.text = text;
this.parameterTypes = parameterTypes;
- this.commandType = CommandType.Text;
}
- public SqlCommandInfo(SqlString text, bool isStoredProcedure, SqlType[] parameterTypes)
- : this(text, parameterTypes)
- {
- if (isStoredProcedure)
- {
- this.commandType = CommandType.StoredProcedure;
- this.text = CallableParser.Parse(text.ToString());
- }
- }
-
public CommandType CommandType
{
- get { return commandType; }
+ // Always Text for now
+ get { return CommandType.Text; }
}
public SqlString Text
Modified: trunk/nhibernate/src/NHibernate.Test/EngineTest/CallableParserFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/EngineTest/CallableParserFixture.cs 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate.Test/EngineTest/CallableParserFixture.cs 2009-10-29 14:31:35 UTC (rev 4806)
@@ -9,12 +9,12 @@
public class CallableParserFixture
{
[Test]
- public void CanFindCallableFunctionName()
+ public void CanDetermineIsCallable()
{
string query = @"{ call myFunction(:name) }";
- SqlString sqlFunction = CallableParser.Parse(query);
- Assert.That(sqlFunction.ToString(), Is.EqualTo("myFunction"));
+ CallableParser.Detail detail = CallableParser.Parse(query);
+ Assert.That(detail.IsCallable, Is.True);
}
[Test]
@@ -22,19 +22,44 @@
{
string query = @"SELECT id FROM mytable";
- Assert.Throws<ParserException>(() =>
- {
- SqlString sqlFunction = CallableParser.Parse(query);
- });
+ CallableParser.Detail detail = CallableParser.Parse(query);
+ Assert.That(detail.IsCallable, Is.False);
}
[Test]
+ public void CanFindCallableFunctionName()
+ {
+ string query = @"{ call myFunction(:name) }";
+
+ CallableParser.Detail detail = CallableParser.Parse(query);
+ Assert.That(detail.FunctionName, Is.EqualTo("myFunction"));
+ }
+
+ [Test]
public void CanFindCallableFunctionNameWithoutParameters()
{
string query = @"{ call myFunction }";
- SqlString sqlFunction = CallableParser.Parse(query);
- Assert.That(sqlFunction.ToString(), Is.EqualTo("myFunction"));
+ CallableParser.Detail detail = CallableParser.Parse(query);
+ Assert.That(detail.FunctionName, Is.EqualTo("myFunction"));
}
+
+ [Test]
+ public void CanDetermineHasReturn()
+ {
+ string query = @"{ ? = call myFunction(:name) }";
+
+ CallableParser.Detail detail = CallableParser.Parse(query);
+ Assert.That(detail.HasReturn, Is.True);
+ }
+
+ [Test]
+ public void CanDetermineHasNoReturn()
+ {
+ string query = @"{ call myFunction(:name) }";
+
+ CallableParser.Detail detail = CallableParser.Parse(query);
+ Assert.That(detail.HasReturn, Is.False);
+ }
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/EngineTest/ParameterParserFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/EngineTest/ParameterParserFixture.cs 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate.Test/EngineTest/ParameterParserFixture.cs 2009-10-29 14:31:35 UTC (rev 4806)
@@ -59,22 +59,5 @@
Assert.DoesNotThrow(() => p = recognizer.NamedParameterDescriptionMap["pizza"]);
}
- [Test]
- public void CanRecogniseNoReturnValueParameter()
- {
- string query = "{ call myFunction(?) }";
- ParamLocationRecognizer recognizer = new ParamLocationRecognizer();
- ParameterParser.Parse(query, recognizer);
- Assert.That(recognizer.HasReturnValue, Is.False);
- }
-
- [Test]
- public void CanRecogniseReturnValueParameter()
- {
- string query = "{ ? = call myFunction(?) }";
- ParamLocationRecognizer recognizer = new ParamLocationRecognizer();
- ParameterParser.Parse(query, recognizer);
- Assert.That(recognizer.HasReturnValue, Is.True);
- }
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/SqlTest/Custom/Oracle/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/SqlTest/Custom/Oracle/Mappings.hbm.xml 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate.Test/SqlTest/Custom/Oracle/Mappings.hbm.xml 2009-10-29 14:31:35 UTC (rev 4806)
@@ -39,7 +39,7 @@
</id>
<property name="name" not-null="true"/>
<loader query-ref="person"/>
- <sql-insert callable="true" check="none">{ call createPerson(?, ?) }</sql-insert>
+ <sql-insert check="none">{ call createPerson(?, ?) }</sql-insert>
<sql-update>UPDATE PERSON SET NAME=UPPER(?) WHERE PERID=?</sql-update>
<sql-delete>DELETE FROM PERSON WHERE PERID=?</sql-delete>
</class>
@@ -204,7 +204,7 @@
<database-object>
<create>
- CREATE OR REPLACE PROCEDURE createPerson(p_name PERSON.NAME%TYPE, p_id PERSON.PERID%TYPE)
+ CREATE OR REPLACE PROCEDURE createPerson(unused OUT SYS_REFCURSOR, p_name PERSON.NAME%TYPE, p_id PERSON.PERID%TYPE)
AS
rowcount INTEGER;
BEGIN
Modified: trunk/nhibernate/src/NHibernate.Test/SqlTest/Custom/Oracle/StoredProcedures.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/SqlTest/Custom/Oracle/StoredProcedures.hbm.xml 2009-10-29 14:30:40 UTC (rev 4805)
+++ trunk/nhibernate/src/NHibernate.Test/SqlTest/Custom/Oracle/StoredProcedures.hbm.xml 2009-10-29 14:31:35 UTC (rev 4806)
@@ -8,25 +8,25 @@
namespace="NHibernate.Test.SqlTest"
default-access="field">
- <sql-query name="simpleScalar" callable="true">
+ <sql-query name="simpleScalar">
<return-scalar column="name" type="string"/>
<return-scalar column="value" type="long"/>
{ ? = call simpleScalar(:number) }
</sql-query>
- <sql-query name="paramhandling" callable="true">
+ <sql-query name="paramhandling">
<return-scalar column="value" type="long"/>
<return-scalar column="value2" type="long"/>
{ ? = call testParamHandling(?, ?) }
</sql-query>
- <sql-query name="paramhandling_mixed" callable="true">
+ <sql-query name="paramhandling_mixed">
<return-scalar column="value" type="long"/>
<return-scalar column="value2" type="long"/>
{ ? = call testParamHandling(?,:second) }
</sql-query>
- <sql-query name="selectAllEmployments" callable="true">
+ <sql-query name="selectAllEmployments">
<return alias="emp" class="Employment">
<return-property name="employee" column="EMPLOYEE"/>
<return-property name="employer" column="EMPLOYER"/>
@@ -42,7 +42,7 @@
{ ? = call allEmployments }
</sql-query>
- <sql-query name="selectEmploymentsForRegion" callable="true">
+ <sql-query name="selectEmploymentsForRegion">
<return alias="emp" class="Employment">
<return-property name="employee" column="EMPLOYEE"/>
<return-property name="employer" column="EMPLOYER"/>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|