From: <fab...@us...> - 2011-03-22 18:53:50
|
Revision: 5504 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5504&view=rev Author: fabiomaulo Date: 2011-03-22 18:53:44 +0000 (Tue, 22 Mar 2011) Log Message: ----------- Fix NH-2550 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs trunk/nhibernate/src/NHibernate/Intercept/IFieldInterceptor.cs trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs Modified: trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs 2011-03-22 18:46:20 UTC (rev 5503) +++ trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs 2011-03-22 18:53:44 UTC (rev 5504) @@ -38,9 +38,10 @@ get { return isDirty; } } - public void SetSession(ISessionImplementor session) + public ISessionImplementor Session { - this.session = session; + get { return session; } + set { session = value; } } public bool IsInitialized Modified: trunk/nhibernate/src/NHibernate/Intercept/IFieldInterceptor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Intercept/IFieldInterceptor.cs 2011-03-22 18:46:20 UTC (rev 5503) +++ trunk/nhibernate/src/NHibernate/Intercept/IFieldInterceptor.cs 2011-03-22 18:53:44 UTC (rev 5504) @@ -10,8 +10,7 @@ bool IsDirty { get;} /// <summary> Use to associate the entity to which we are bound to the given session. </summary> - /// <param name="session">The session to which we are now associated. </param> - void SetSession(ISessionImplementor session); + ISessionImplementor Session { get; set; } /// <summary> Is the entity to which we are bound completely initialized? </summary> bool IsInitialized { get;} Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2011-03-22 18:46:20 UTC (rev 5503) +++ trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2011-03-22 18:53:44 UTC (rev 5504) @@ -3648,7 +3648,7 @@ IFieldInterceptor interceptor = FieldInterceptionHelper.ExtractFieldInterceptor(entity); if (interceptor != null) { - interceptor.SetSession(session); + interceptor.Session = session; } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-03-22 20:33:22
|
Revision: 5505 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5505&view=rev Author: fabiomaulo Date: 2011-03-22 20:33:16 +0000 (Tue, 22 Mar 2011) Log Message: ----------- Fix NH-2491 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2491/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2491/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2491/Mappings.hbm.xml Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2011-03-22 18:53:44 UTC (rev 5504) +++ trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2011-03-22 20:33:16 UTC (rev 5505) @@ -1821,9 +1821,11 @@ { int propertyIndex = Array.IndexOf(SubclassColumnClosure, column); - if (propertyIndex < 0) + // The check for KeyColumnNames was added to fix NH-2491 + if (propertyIndex < 0 || Array.IndexOf(KeyColumnNames, column) >= 0) + { return rootAlias; - + } return GenerateTableAlias(rootAlias, SubclassColumnTableNumberClosure[propertyIndex]); } Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2491/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2491/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2491/Fixture.cs 2011-03-22 20:33:16 UTC (rev 5505) @@ -0,0 +1,64 @@ +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.NHSpecificTest.NH2491 +{ + public class BaseClass + { + public virtual int Id { get; set; } + + public virtual BaseClass Another { get; set; } + } + + public class SubClass : BaseClass + { + } + + public class ReferencingClass + { + public virtual int Id { get; set; } + + public virtual SubClass SubClass { get; set; } + } + + + public class Fixture : BugTestCase + { + [Test] + public void InheritanceSameColumnName() + { + using (var session = OpenSession()) + using (session.BeginTransaction()) + { + var subClass = new SubClass(); + var referencing = new ReferencingClass() { SubClass = subClass }; + session.Save(subClass); + session.Save(referencing); + + session.Transaction.Commit(); + } + using (var session = OpenSession()) + using (session.BeginTransaction()) + { + var referencing = session.CreateQuery("from ReferencingClass") + .UniqueResult<ReferencingClass>(); + + // accessing a property of the base class to activate lazy loading + // this line crashes because it tries to find the base class by + // the wrong column name. + BaseClass another; + Executing.This(() => another = referencing.SubClass.Another).Should().NotThrow(); + + session.Transaction.Commit(); + } + using (var session = OpenSession()) + using (session.BeginTransaction()) + { + session.CreateQuery("delete from ReferencingClass").ExecuteUpdate(); + session.CreateQuery("delete from BaseClass").ExecuteUpdate(); + session.Transaction.Commit(); + } + + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2491/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2491/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2491/Mappings.hbm.xml 2011-03-22 20:33:16 UTC (rev 5505) @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.NH2491" + assembly="NHibernate.Test"> + + <class name="BaseClass" > + <id name="Id"> + <generator class="hilo" /> + </id> + + <many-to-one name="Another" column="BaseClass_FK" /> + + <joined-subclass name="SubClass" > + <!-- use a column name already used in the base class--> + <key column="BaseClass_FK"/> + </joined-subclass> + </class> + + <class name="ReferencingClass" > + <id name="Id"> + <generator class="hilo" /> + </id> + <many-to-one name="SubClass" column="SubClass_FK" /> + </class> + +</hibernate-mapping> \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-03-22 18:53:44 UTC (rev 5504) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-03-22 20:33:16 UTC (rev 5505) @@ -648,6 +648,7 @@ <Compile Include="NHSpecificTest\NH2470\DTO.cs" /> <Compile Include="NHSpecificTest\NH2484\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2484\Model.cs" /> + <Compile Include="NHSpecificTest\NH2491\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2507\Animal.cs" /> <Compile Include="NHSpecificTest\NH2507\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2530\Domain.cs" /> @@ -2476,6 +2477,7 @@ <EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="NHSpecificTest\NH2491\Mappings.hbm.xml" /> <EmbeddedResource Include="Insertordering\Mapping.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2530\Mappings.hbm.xml" /> <EmbeddedResource Include="DynamicProxyTests\InterfaceProxySerializationTests\ProxyImpl.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2011-03-23 18:41:34
|
Revision: 5513 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5513&view=rev Author: patearl Date: 2011-03-23 18:41:28 +0000 (Wed, 23 Mar 2011) Log Message: ----------- Support ToString in Linq expressions (NH-2563). Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs trunk/nhibernate/src/NHibernate.Test/Linq/FunctionTests.cs Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs 2011-03-23 18:29:04 UTC (rev 5512) +++ trunk/nhibernate/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs 2011-03-23 18:41:28 UTC (rev 5513) @@ -18,6 +18,7 @@ RegisterGenerator(new DictionaryContainsKeyRuntimeHqlGenerator()); RegisterGenerator(new GenericDictionaryItemRuntimeHqlGenerator()); RegisterGenerator(new GenericDictionaryContainsKeyRuntimeHqlGenerator()); + RegisterGenerator(new ToStringRuntimeMethodHqlGenerator()); this.Merge(new StartsWithGenerator()); this.Merge(new EndsWithGenerator()); Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs 2011-03-23 18:29:04 UTC (rev 5512) +++ trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs 2011-03-23 18:41:28 UTC (rev 5513) @@ -1,3 +1,5 @@ +using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq.Expressions; using System.Reflection; @@ -193,4 +195,31 @@ } } + public class ToStringRuntimeMethodHqlGenerator : IRuntimeMethodHqlGenerator + { + private readonly ToStringHqlGeneratorForMethod generator = new ToStringHqlGeneratorForMethod(); + + public bool SupportsMethod(MethodInfo method) + { + return method != null && method.Name == "ToString" && method.GetBaseDefinition().DeclaringType == typeof(object); + } + + public IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method) + { + return generator; + } + } + + public class ToStringHqlGeneratorForMethod : IHqlGeneratorForMethod + { + public IEnumerable<MethodInfo> SupportedMethods + { + get { throw new NotSupportedException(); } + } + + public HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) + { + return treeBuilder.MethodCall("str", visitor.Visit(targetObject).AsExpression()); + } + } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/Linq/FunctionTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Linq/FunctionTests.cs 2011-03-23 18:29:04 UTC (rev 5512) +++ trunk/nhibernate/src/NHibernate.Test/Linq/FunctionTests.cs 2011-03-23 18:41:28 UTC (rev 5513) @@ -90,5 +90,25 @@ ObjectDumper.Write(query); } - } + + [Test] + public void ToStringFunction() + { + var query = from ol in db.OrderLines + where ol.Quantity.ToString() == "4" + select ol; + + Assert.AreEqual(55, query.Count()); + } + + [Test] + public void ToStringWithContains() + { + var query = from ol in db.OrderLines + where ol.Quantity.ToString().Contains("5") + select ol; + + Assert.AreEqual(498, query.Count()); + } + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-03-23 21:48:57
|
Revision: 5514 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5514&view=rev Author: fabiomaulo Date: 2011-03-23 21:48:51 +0000 (Wed, 23 Mar 2011) Log Message: ----------- Fix NH-2580 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Event/Default/DefaultLoadEventListener.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2580/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2580/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2580/Mappings.hbm.xml Modified: trunk/nhibernate/src/NHibernate/Event/Default/DefaultLoadEventListener.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Event/Default/DefaultLoadEventListener.cs 2011-03-23 18:41:28 UTC (rev 5513) +++ trunk/nhibernate/src/NHibernate/Event/Default/DefaultLoadEventListener.cs 2011-03-23 21:48:51 UTC (rev 5514) @@ -41,7 +41,13 @@ if (persister == null) { - throw new HibernateException("Unable to locate persister: " + @event.EntityClassName); + + var message = new StringBuilder(512); + message.AppendLine(string.Format("Unable to locate persister for the entity named '{0}'.", @event.EntityClassName)); + message.AppendLine("The persister define the persistence strategy for an entity."); + message.AppendLine("Possible causes:"); + message.AppendLine(string.Format(" - The mapping for '{0}' was not added to the NHibernate configuration.", @event.EntityClassName)); + throw new HibernateException(message.ToString()); } if (persister.IdentifierType.IsComponentType) Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2580/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2580/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2580/Fixture.cs 2011-03-23 21:48:51 UTC (rev 5514) @@ -0,0 +1,23 @@ +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.NHSpecificTest.NH2580 +{ + public class Fixture: BugTestCase + { + private class MyClass + { + + } + + [Test] + public void WhenPersisterNotFoundShouldThrowAMoreExplicitException() + { + using (var s = OpenSession()) + { + var exeption = s.Executing(x=> x.Get<MyClass>(1)).Throws<HibernateException>().Exception; + exeption.Message.ToLowerInvariant().Should().Contain("possible cause"); + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2580/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2580/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2580/Mappings.hbm.xml 2011-03-23 21:48:51 UTC (rev 5514) @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> + +</hibernate-mapping> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-03-23 18:41:28 UTC (rev 5513) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-03-23 21:48:51 UTC (rev 5514) @@ -657,6 +657,7 @@ <Compile Include="NHSpecificTest\NH2530\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2565\Domain.cs" /> <Compile Include="NHSpecificTest\NH2565\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2580\Fixture.cs" /> <Compile Include="NHSpecificTest\Properties\CompositePropertyRefTest.cs" /> <Compile Include="NHSpecificTest\Properties\DynamicEntityTest.cs" /> <Compile Include="NHSpecificTest\Properties\Model.cs" /> @@ -2479,6 +2480,7 @@ <EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="NHSpecificTest\NH2580\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2390\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2491\Mappings.hbm.xml" /> <EmbeddedResource Include="Insertordering\Mapping.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jul...@us...> - 2011-03-24 17:19:50
|
Revision: 5518 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5518&view=rev Author: julian-maughan Date: 2011-03-24 17:19:43 +0000 (Thu, 24 Mar 2011) Log Message: ----------- Added data-type keywords to SQL Server dialects (NH-2554). Also updated the class-level XML comment block to reflect some recent changes to default properties. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs trunk/nhibernate/src/NHibernate/Dialect/MsSql2005Dialect.cs trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2554/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2554/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2554/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2554/Model.cs Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2011-03-24 02:51:16 UTC (rev 5517) +++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2011-03-24 17:19:43 UTC (rev 5518) @@ -21,22 +21,22 @@ /// <remarks> /// The MsSql2000Dialect defaults the following configuration properties: /// <list type="table"> - /// <listheader> - /// <term>Property</term> - /// <description>Default Value</description> - /// </listheader> - /// <item> - /// <term>use_outer_join</term> - /// <description><see langword="true" /></description> - /// </item> - /// <item> - /// <term>connection.driver_class</term> - /// <description><see cref="NHibernate.Driver.SqlClientDriver" /></description> - /// </item> - /// <item> - /// <term>prepare_sql</term> - /// <description><see langword="false" /></description> - /// </item> + /// <listheader> + /// <term>Property</term> + /// <description>Default Value</description> + /// </listheader> + /// <item> + /// <term>connection.driver_class</term> + /// <description><see cref="NHibernate.Driver.SqlClientDriver" /></description> + /// </item> + /// <item> + /// <term>adonet.batch_size</term> + /// <description>10</description> + /// </item> + /// <item> + /// <term>query.substitutions</term> + /// <description>true 1, false 0, yes 'Y', no 'N'</description> + /// </item> /// </list> /// </remarks> public class MsSql2000Dialect : Dialect @@ -66,9 +66,34 @@ protected virtual void RegisterKeywords() { RegisterKeyword("top"); - RegisterKeyword("integer"); RegisterKeyword("int"); + RegisterKeyword("integer"); // a commonly-used alias for 'int' + RegisterKeyword("tinyint"); + RegisterKeyword("smallint"); + RegisterKeyword("bigint"); + RegisterKeyword("numeric"); + RegisterKeyword("decimal"); + RegisterKeyword("bit"); + RegisterKeyword("money"); + RegisterKeyword("smallmoney"); + RegisterKeyword("float"); + RegisterKeyword("real"); RegisterKeyword("datetime"); + RegisterKeyword("smalldatetime"); + RegisterKeyword("char"); + RegisterKeyword("varchar"); + RegisterKeyword("text"); + RegisterKeyword("nchar"); + RegisterKeyword("nvarchar"); + RegisterKeyword("ntext"); + RegisterKeyword("binary"); + RegisterKeyword("varbinary"); + RegisterKeyword("image"); + RegisterKeyword("cursor"); + RegisterKeyword("timestamp"); + RegisterKeyword("uniqueidentifier"); + RegisterKeyword("sql_variant"); + RegisterKeyword("table"); } protected virtual void RegisterFunctions() @@ -110,7 +135,6 @@ RegisterFunction("right", new SQLFunctionTemplate(NHibernateUtil.String, "right(?1, ?2)")); RegisterFunction("locate", new StandardSQLFunction("charindex", NHibernateUtil.Int32)); - RegisterFunction("current_timestamp", new NoArgSQLFunction("getdate", NHibernateUtil.DateTime, true)); RegisterFunction("second", new SQLFunctionTemplate(NHibernateUtil.Int32, "datepart(second, ?1)")); RegisterFunction("minute", new SQLFunctionTemplate(NHibernateUtil.Int32, "datepart(minute, ?1)")); @@ -149,6 +173,8 @@ protected virtual void RegisterDateTimeTypeMappings() { RegisterColumnType(DbType.Time, "DATETIME"); + RegisterColumnType(DbType.Date, "DATETIME"); + RegisterColumnType(DbType.DateTime, "DATETIME"); } protected virtual void RegisterNumericTypeMappings() @@ -156,15 +182,13 @@ RegisterColumnType(DbType.Boolean, "BIT"); RegisterColumnType(DbType.Byte, "TINYINT"); RegisterColumnType(DbType.Currency, "MONEY"); - RegisterColumnType(DbType.Date, "DATETIME"); - RegisterColumnType(DbType.DateTime, "DATETIME"); RegisterColumnType(DbType.Decimal, "DECIMAL(19,5)"); RegisterColumnType(DbType.Decimal, 19, "DECIMAL($p, $s)"); RegisterColumnType(DbType.Double, "DOUBLE PRECISION"); //synonym for FLOAT(53) RegisterColumnType(DbType.Int16, "SMALLINT"); RegisterColumnType(DbType.Int32, "INT"); RegisterColumnType(DbType.Int64, "BIGINT"); - RegisterColumnType(DbType.Single, "REAL"); //synonym for FLOAT(24) + RegisterColumnType(DbType.Single, "REAL"); //synonym for FLOAT(24) } protected virtual void RegisterCharacterTypeMappings() @@ -181,13 +205,11 @@ RegisterColumnType(DbType.String, SqlClientDriver.MaxSizeForClob, "NTEXT"); } - /// <summary></summary> public override string AddColumnString { get { return "add"; } } - /// <summary></summary> public override string NullColumnString { get { return " null"; } @@ -213,7 +235,6 @@ get { return true; } } - /// <summary></summary> public override bool QualifyIndexName { get { return false; } @@ -253,7 +274,6 @@ get { return true; } } - /// <summary></summary> public override bool SupportsIdentityColumns { get { return true; } @@ -264,25 +284,21 @@ get { return "select SCOPE_IDENTITY()"; } } - /// <summary></summary> public override string IdentityColumnString { get { return "IDENTITY NOT NULL"; } } - /// <summary></summary> public override string NoColumnsInsertString { get { return "DEFAULT VALUES"; } } - /// <summary></summary> public override char CloseQuote { get { return ']'; } } - /// <summary></summary> public override char OpenQuote { get { return '['; } @@ -359,9 +375,7 @@ return true; } - /// <summary> - /// - /// </summary> + /// <summary /> /// <param name="name"></param> /// <returns></returns> /// <remarks> @@ -373,11 +387,6 @@ return OpenQuote + name.Replace(CloseQuote.ToString(), new string(CloseQuote, 2)) + CloseQuote; } - /// <summary> - /// - /// </summary> - /// <param name="quoted"></param> - /// <returns></returns> public override string UnQuote(string quoted) { if (IsQuoted(quoted)) @@ -505,13 +514,11 @@ string selectExistingObject = GetSelectExistingObject(name, table); return string.Format(@"if not exists ({0})", selectExistingObject); } + [Serializable] protected class CountBigQueryFunction : ClassicAggregateFunction { - public CountBigQueryFunction() - : base("count_big", true) - { - } + public CountBigQueryFunction() : base("count_big", true) { } public override IType ReturnType(IType columnType, IMapping mapping) { @@ -542,15 +549,12 @@ public override bool SupportsSqlBatches { - get - { - return true; - } + get { return true; } } public override bool IsKnownToken(string currentToken, string nextToken) { - return currentToken == "n" && nextToken == "'"; // unicode character + return currentToken == "n" && nextToken == "'"; // unicode character } } } Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2005Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/MsSql2005Dialect.cs 2011-03-24 02:51:16 UTC (rev 5517) +++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2005Dialect.cs 2011-03-24 17:19:43 UTC (rev 5518) @@ -22,6 +22,12 @@ RegisterColumnType(DbType.AnsiString, SqlClientDriver.MaxSizeForAnsiClob, "VARCHAR(MAX)"); RegisterColumnType(DbType.Binary, SqlClientDriver.MaxSizeForBlob, "VARBINARY(MAX)"); } + + protected override void RegisterKeywords() + { + base.RegisterKeywords(); + RegisterKeyword("xml"); + } /// <summary> /// Add a <c>LIMIT</c> clause to the given SQL <c>SELECT</c> @@ -63,7 +69,7 @@ SqlString fromAndWhere; SqlString[] sortExpressions; - //don't use the order index if it is contained within a larger statement(assuming + //don't use the order index if it is contained within a larger statement(assuming //a statement with non matching parenthesis is part of a larger block) if (orderIndex > 0 && HasMatchingParens(querySqlString.Substring(orderIndex).ToString())) { @@ -76,7 +82,7 @@ fromAndWhere = querySqlString.Substring(fromIndex).Trim(); // Use dummy sort to avoid errors sortExpressions = new[] {new SqlString("CURRENT_TIMESTAMP"),}; - } + } result .Add("SELECT TOP (") @@ -156,7 +162,7 @@ return 6; } throw new NotSupportedException("The query should start with 'SELECT' or 'SELECT DISTINCT'"); - } + } /// <summary> /// Indicates whether the string fragment contains matching parenthesis @@ -206,17 +212,17 @@ get { return true; } } - public override bool BindLimitParametersInReverseOrder + public override bool BindLimitParametersInReverseOrder { get { return true; } } - public override bool SupportsVariableLimit - { - get { return true; } + public override bool SupportsVariableLimit + { + get { return true; } } - public override bool BindLimitParametersFirst + public override bool BindLimitParametersFirst { get { return true; } } Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs 2011-03-24 02:51:16 UTC (rev 5517) +++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs 2011-03-24 17:19:43 UTC (rev 5518) @@ -24,8 +24,11 @@ protected override void RegisterKeywords() { base.RegisterKeywords(); + RegisterKeyword("date"); + RegisterKeyword("datetimeoffset"); RegisterKeyword("datetime2"); - RegisterKeyword("datetimeoffset"); + RegisterKeyword("time"); + RegisterKeyword("hierarchyid"); } } } \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2554/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2554/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2554/Fixture.cs 2011-03-24 17:19:43 UTC (rev 5518) @@ -0,0 +1,92 @@ +using System; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2554 +{ + [TestFixture] + public class Fixture: BugTestCase + { + protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect) + { + return (dialect is NHibernate.Dialect.MsSql2005Dialect) || (dialect is NHibernate.Dialect.MsSql2008Dialect); + } + + protected override void Configure(NHibernate.Cfg.Configuration configuration) + { + configuration.SetProperty(NHibernate.Cfg.Environment.Hbm2ddlKeyWords, "keywords"); + base.Configure(configuration); + } + + protected override void OnSetUp() + { + base.OnSetUp(); + + using (ISession session = Sfi.OpenSession()) + using (ITransaction transaction = session.BeginTransaction()) + { + session.Persist(new Student() { FullName = "Julian Maughan" }); + transaction.Commit(); + } + } + + protected override void OnTearDown() + { + using (ISession session = Sfi.OpenSession()) + using (ITransaction transaction = session.BeginTransaction()) + { + session.CreateQuery("delete from Student").ExecuteUpdate(); + transaction.Commit(); + } + + base.OnTearDown(); + } + + [Test] + public void TestMappedFormulasContainingSqlServerDataTypeKeywords() + { + using (ISession session = Sfi.OpenSession()) + using (ITransaction transaction = session.BeginTransaction()) + { + var students = session.CreateQuery("from Student").List<Student>(); + Assert.That(students.Count, Is.EqualTo(1)); + Assert.That(students[0].FullName, Is.StringMatching("Julian Maughan")); + Assert.That(students[0].FullNameAsVarBinary.Length, Is.EqualTo(28)); + Assert.That(students[0].FullNameAsVarBinary512.Length, Is.EqualTo(28)); + // Assert.That(students[0].FullNameAsBinary.Length, Is.EqualTo(28)); 30??? + Assert.That(students[0].FullNameAsBinary256.Length, Is.EqualTo(256)); + Assert.That(students[0].FullNameAsVarChar.Length, Is.EqualTo(14)); + Assert.That(students[0].FullNameAsVarChar125.Length, Is.EqualTo(14)); + + transaction.Commit(); + } + } + + [Test] + public void TestHqlStatementsContainingSqlServerDataTypeKeywords() + { + using (ISession session = Sfi.OpenSession()) + using (ITransaction transaction = session.BeginTransaction()) + { + var students = session + .CreateQuery("from Student where length(convert(varbinary, FullName)) = 28") + .List<Student>(); + + Assert.That(students.Count, Is.EqualTo(1)); + + students = session + .CreateQuery("from Student where length(convert(varbinary(256), FullName)) = 28") + .List<Student>(); + + Assert.That(students.Count, Is.EqualTo(1)); + + students = session + .CreateQuery("from Student where convert(int, 1) = 1") + .List<Student>(); + + Assert.That(students.Count, Is.EqualTo(1)); + + transaction.Commit(); + } + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2554/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2554/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2554/Mappings.hbm.xml 2011-03-24 17:19:43 UTC (rev 5518) @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping + xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2554"> + + <class name="Student"> + + <id name="Id"> + <generator class="guid" /> + </id> + + <property name="FullName"> + <column name="full_name" sql-type="nvarchar(255)" not-null="true" /> + </property> + + <property name="FullNameAsVarBinary" formula="CONVERT(varbinary, full_name)" /> + + <property name="FullNameAsVarBinary512" formula="CONVERT(varbinary(512), full_name)" /> + + <property name="FullNameAsBinary" formula="CONVERT(binary, full_name)" /> + + <property name="FullNameAsBinary256" formula="CONVERT(binary(256), full_name)" /> + + <property name="FullNameAsVarChar" formula="CONVERT(varchar, full_name)" /> + + <property name="FullNameAsVarChar125" formula="CONVERT(varchar(125), 'Julian Maughan')" /> + + </class> + +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2554/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2554/Model.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2554/Model.cs 2011-03-24 17:19:43 UTC (rev 5518) @@ -0,0 +1,16 @@ +using System; + +namespace NHibernate.Test.NHSpecificTest.NH2554 +{ + public class Student + { + public virtual Guid Id { get; set; } + public virtual string FullName { get; set; } + public virtual byte[] FullNameAsVarBinary { get; set; } + public virtual byte[] FullNameAsVarBinary512 { get; set; } + public virtual byte[] FullNameAsBinary { get; set; } + public virtual byte[] FullNameAsBinary256 { get; set; } + public virtual string FullNameAsVarChar { get; set; } + public virtual string FullNameAsVarChar125 { get; set; } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-03-24 02:51:16 UTC (rev 5517) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-03-24 17:19:43 UTC (rev 5518) @@ -655,6 +655,8 @@ <Compile Include="NHSpecificTest\NH2507\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2530\Domain.cs" /> <Compile Include="NHSpecificTest\NH2530\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2554\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2554\Model.cs" /> <Compile Include="NHSpecificTest\NH2565\Domain.cs" /> <Compile Include="NHSpecificTest\NH2565\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2580\Fixture.cs" /> @@ -2000,6 +2002,7 @@ <EmbeddedResource Include="ReadOnly\Enrolment.hbm.xml" /> <EmbeddedResource Include="ReadOnly\TextHolder.hbm.xml" /> <EmbeddedResource Include="ReadOnly\VersionedNode.hbm.xml" /> + <EmbeddedResource Include="NHSpecificTest\NH2554\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\NHibernate.DomainModel\NHibernate.DomainModel.csproj"> @@ -2875,6 +2878,7 @@ <EmbeddedResource Include="DynamicEntity\Tuplizer\Customer.hbm.xml" /> </ItemGroup> <ItemGroup> + <Folder Include="NHSpecificTest\NH2554" /> <Folder Include="Properties\" /> </ItemGroup> <ItemGroup> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-03-24 18:06:13
|
Revision: 5520 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5520&view=rev Author: fabiomaulo Date: 2011-03-24 18:06:06 +0000 (Thu, 24 Mar 2011) Log Message: ----------- Fix NH-2495 (thanks to Gerke Geurts) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1508/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/QueryTest/MultipleMixedQueriesFixture.cs Modified: trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs 2011-03-24 17:28:29 UTC (rev 5519) +++ trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs 2011-03-24 18:06:06 UTC (rev 5520) @@ -8,7 +8,10 @@ using NHibernate.Cache; using NHibernate.Driver; using NHibernate.Engine; +using NHibernate.Engine.Query.Sql; using NHibernate.Hql; +using NHibernate.Loader.Custom; +using NHibernate.Loader.Custom.Sql; using NHibernate.SqlCommand; using NHibernate.SqlTypes; using NHibernate.Transform; @@ -21,9 +24,9 @@ private static readonly IInternalLogger log = LoggerProvider.LoggerFor(typeof(MultiQueryImpl)); private readonly List<IQuery> queries = new List<IQuery>(); - private readonly List<IQueryTranslator> translators = new List<IQueryTranslator>(); - private readonly IList<System.Type> resultCollectionGenericType = new List<System.Type>(); - private readonly List<QueryParameters> parameters = new List<QueryParameters>(); + private readonly List<ITranslator> translators = new List<ITranslator>(); + private readonly IList<System.Type> resultCollectionGenericType = new List<System.Type>(); + private readonly List<QueryParameters> parameters = new List<QueryParameters>(); private IList queryResults; private readonly Dictionary<string, int> queryResultPositions = new Dictionary<string, int>(); private string cacheRegion; @@ -51,6 +54,8 @@ this.session = session; } + #region Parameters setting + public IMultiQuery SetResultTransformer(IResultTransformer transformer) { resultTransformer = transformer; @@ -267,6 +272,9 @@ return this; } + + #endregion + public IMultiQuery AddNamedQuery<T>(string key, string namedQuery) { ThrowIfKeyAlreadyExists(key); @@ -439,8 +447,8 @@ { // TODO : we need a test to check the behavior when the query has a 'new' istead a trasformer // we should take the HolderInstantiator directly from QueryTranslator... taking care with Parameters. - return Parameters[queryPosition].ResultTransformer != null ? - new HolderInstantiator(Parameters[queryPosition].ResultTransformer, translators[queryPosition].ReturnAliases) + return Parameters[queryPosition].ResultTransformer != null ? + new HolderInstantiator(Parameters[queryPosition].ResultTransformer, translators[queryPosition].ReturnAliases) : HolderInstantiator.NoopInstantiator; } @@ -480,10 +488,12 @@ try { if (log.IsDebugEnabled) + { log.DebugFormat("Executing {0} queries", translators.Count); + } for (int i = 0; i < translators.Count; i++) { - IQueryTranslator translator = Translators[i]; + ITranslator translator = Translators[i]; QueryParameters parameter = Parameters[i]; IList tempResults; if (resultCollectionGenericType[i] == typeof(object)) @@ -529,13 +539,13 @@ object result = translator.Loader.GetRowFromResultSet(reader, - session, - parameter, - lockModeArray, - optionalObjectKey, - hydratedObjects[i], - keys, - true); + session, + parameter, + lockModeArray, + optionalObjectKey, + hydratedObjects[i], + keys, + true); tempResults.Add(result); @@ -572,7 +582,7 @@ } for (int i = 0; i < translators.Count; i++) { - IQueryTranslator translator = translators[i]; + ITranslator translator = translators[i]; QueryParameters parameter = parameters[i]; translator.Loader.InitializeEntitiesAndCollections(hydratedObjects[i], reader, session, false); @@ -614,9 +624,7 @@ QueryParameters queryParameters = query.GetQueryParameters(); queryParameters.ValidateParameters(); query.VerifyParameters(); - IQueryTranslator[] queryTranslators = - session.GetQueries(query.ExpandParameterLists(queryParameters.NamedParameters), false); - foreach (IQueryTranslator translator in queryTranslators) + foreach (var translator in GetTranslators(query, queryParameters)) { translators.Add(translator); parameters.Add(queryParameters); @@ -628,12 +636,30 @@ } } - private static QueryParameters GetFilteredQueryParameters(QueryParameters queryParameters, IQueryTranslator translator) + private IEnumerable<ITranslator> GetTranslators(AbstractQueryImpl query, QueryParameters queryParameters) { + // NOTE: updates queryParameters.NamedParameters as (desired) side effect + var queryString = query.ExpandParameterLists(queryParameters.NamedParameters); + + var sqlQuery = query as ISQLQuery; + if (sqlQuery != null) + { + yield return new SqlTranslator(sqlQuery, session.Factory); + yield break; + } + + foreach (var queryTranslator in session.GetQueries(queryString, false)) + { + yield return new HqlTranslatorWrapper(queryTranslator); + } + } + + private static QueryParameters GetFilteredQueryParameters(QueryParameters queryParameters, ITranslator translator) + { QueryParameters filteredQueryParameters = queryParameters; Dictionary<string, TypedValue> namedParameters = new Dictionary<string, TypedValue>(queryParameters.NamedParameters); filteredQueryParameters.NamedParameters.Clear(); - foreach (string paramName in translator.GetParameterTranslations().GetNamedParameterNames()) + foreach (string paramName in translator.GetNamedParameterNames()) { TypedValue v; if (namedParameters.TryGetValue(paramName, out v)) @@ -723,9 +749,9 @@ List<IType[]> resultTypesList = new List<IType[]>(Translators.Count); for (int i = 0; i < Translators.Count; i++) { - IQueryTranslator queryTranslator = Translators[i]; + ITranslator queryTranslator = Translators[i]; querySpaces.AddAll(queryTranslator.QuerySpaces); - resultTypesList.Add(queryTranslator.ActualReturnTypes); + resultTypesList.Add(queryTranslator.ReturnTypes); } int[] firstRows = new int[Parameters.Count]; int[] maxRows = new int[Parameters.Count]; @@ -755,12 +781,14 @@ return GetResultList(result); } - private IList<IQueryTranslator> Translators + private IList<ITranslator> Translators { get { if (sqlString == null) + { AggregateQueriesInformation(); + } return translators; } } @@ -808,18 +836,94 @@ private int AddQueryForLaterExecutionAndReturnIndexOfQuery(System.Type resultGenericListType, IQuery query) { - ThrowNotSupportedIfSqlQuery(query); ((AbstractQueryImpl)query).SetIgnoreUknownNamedParameters(true); queries.Add(query); resultCollectionGenericType.Add(resultGenericListType); return queries.Count - 1; } - protected void ThrowNotSupportedIfSqlQuery(IQuery query) + + #endregion + + private interface ITranslator { - if (query is ISQLQuery) - throw new NotSupportedException("Sql queries in MultiQuery are currently not supported."); + Loader.Loader Loader { get; } + IType[] ReturnTypes { get; } + string[] ReturnAliases { get; } + ICollection<string> QuerySpaces { get; } + IEnumerable<string> GetNamedParameterNames(); } - #endregion + private class HqlTranslatorWrapper : ITranslator + { + private readonly IQueryTranslator innerTranslator; + + public HqlTranslatorWrapper(IQueryTranslator translator) + { + innerTranslator = translator; + } + + public Loader.Loader Loader + { + get { return innerTranslator.Loader; } + } + + public IType[] ReturnTypes + { + get { return innerTranslator.ActualReturnTypes; } + } + + public ICollection<string> QuerySpaces + { + get { return innerTranslator.QuerySpaces; } + } + + public string[] ReturnAliases + { + get { return innerTranslator.ReturnAliases; } + } + + public IEnumerable<string> GetNamedParameterNames() + { + return innerTranslator.GetParameterTranslations().GetNamedParameterNames(); + } + } + + private class SqlTranslator : ITranslator + { + private readonly CustomLoader loader; + + public SqlTranslator(ISQLQuery sqlQuery, ISessionFactoryImplementor sessionFactory) + { + var sqlQueryImpl = (SqlQueryImpl) sqlQuery; + NativeSQLQuerySpecification sqlQuerySpec = sqlQueryImpl.GenerateQuerySpecification(sqlQueryImpl.NamedParams); + var sqlCustomQuery = new SQLCustomQuery(sqlQuerySpec.SqlQueryReturns, sqlQuerySpec.QueryString, sqlQuerySpec.QuerySpaces, sessionFactory); + loader = new CustomLoader(sqlCustomQuery, sessionFactory); + } + + public IType[] ReturnTypes + { + get { return loader.ResultTypes; } + } + + public Loader.Loader Loader + { + get { return loader; } + } + + public ICollection<string> QuerySpaces + { + get { return loader.QuerySpaces; } + } + + public string[] ReturnAliases + { + get { return loader.ReturnAliases; } + } + + public IEnumerable<string> GetNamedParameterNames() + { + return loader.NamedParameters; + } + } } } Modified: trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs 2011-03-24 17:28:29 UTC (rev 5519) +++ trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs 2011-03-24 18:06:06 UTC (rev 5520) @@ -402,6 +402,21 @@ } } + public IType[] ResultTypes + { + get { return resultTypes; } + } + + public string[] ReturnAliases + { + get { return transformerAliases; } + } + + public IEnumerable<string> NamedParameters + { + get { return namedParameterBindPoints.Keys; } + } + public interface IResultColumnProcessor { object Extract(object[] data, IDataReader resultSet, ISessionImplementor session); Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1508/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1508/Fixture.cs 2011-03-24 17:28:29 UTC (rev 5519) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1508/Fixture.cs 2011-03-24 18:06:06 UTC (rev 5520) @@ -1,6 +1,7 @@ using System; using NHibernate.Driver; using NUnit.Framework; +using SharpTestsEx; namespace NHibernate.Test.NHSpecificTest.NH1508 { @@ -66,28 +67,27 @@ } [Test] - public void ThrowsExceptionWhenSqlQueryIsGiven() + public void DoesntThrowsExceptionWhenSqlQueryIsGiven() { using (ISession session = OpenSession()) using (ITransaction tx = session.BeginTransaction()) { ISQLQuery sqlQuery = session.CreateSQLQuery("select * from Document"); - Assert.Throws<NotSupportedException>(() => session.CreateMultiQuery().Add(sqlQuery)); + var multiquery = session.CreateMultiQuery(); + multiquery.Executing(x => x.Add(sqlQuery)).NotThrows(); } } [Test] - public void ThrowsExceptionWhenNamedSqlQueryIsGiven() + public void DoesntThrowsExceptionWhenNamedSqlQueryIsGiven() { using (ISession session = OpenSession()) using (ITransaction tx = session.BeginTransaction()) { - Assert.Throws<NotSupportedException>(() =>session - .CreateMultiQuery() - .AddNamedQuery("SampleSqlQuery")); + var multiquery = session.CreateMultiQuery(); + multiquery.Executing(x => x.AddNamedQuery("SampleSqlQuery")).NotThrows(); } } - } } Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-03-24 17:28:29 UTC (rev 5519) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-03-24 18:06:06 UTC (rev 5520) @@ -667,6 +667,7 @@ <Compile Include="PolymorphicGetAndLoad\PolymorphicGetAndLoadTest.cs" /> <Compile Include="PropertyTest\FieldCamelCaseMUnderscoreFixture.cs" /> <Compile Include="PropertyTest\NoSetterCamelCaseMUnderscoreFixture.cs" /> + <Compile Include="QueryTest\MultipleMixedQueriesFixture.cs" /> <Compile Include="ReadOnly\AbstractReadOnlyTest.cs" /> <Compile Include="ReadOnly\Container.cs" /> <Compile Include="ReadOnly\Course.cs" /> Added: trunk/nhibernate/src/NHibernate.Test/QueryTest/MultipleMixedQueriesFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/QueryTest/MultipleMixedQueriesFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/QueryTest/MultipleMixedQueriesFixture.cs 2011-03-24 18:06:06 UTC (rev 5520) @@ -0,0 +1,517 @@ +using System.Collections; +using System.Collections.Generic; +using System.Reflection; +using NHibernate.Cache; +using NHibernate.Driver; +using NHibernate.Engine; +using NHibernate.Test.SecondLevelCacheTests; +using NHibernate.Transform; +using NUnit.Framework; +using System; + +namespace NHibernate.Test.QueryTest +{ + public class MultipleMixedQueriesFixture : TestCase + { + protected override string MappingsAssembly + { + get { return "NHibernate.Test"; } + } + + protected override IList Mappings + { + get { return new string[] { "SecondLevelCacheTest.Item.hbm.xml" }; } + } + + [TestFixtureSetUp] + public void CheckMultiQuerySupport() + { + base.TestFixtureSetUp(); + IDriver driver = sessions.ConnectionProvider.Driver; + if (!driver.SupportsMultipleQueries) + { + Assert.Ignore("Driver {0} does not support multi-queries", driver.GetType().FullName); + } + } + + [Test] + public void NH_1085_WillIgnoreParametersIfDoesNotAppearInQuery() + { + using (ISession s = sessions.OpenSession()) + { + IMultiQuery multiQuery = s.CreateMultiQuery() + .Add(s.CreateSQLQuery("select * from ITEM where Id in (:ids)").AddEntity(typeof (Item))) + .Add(s.CreateSQLQuery("select * from ITEM where Id in (:ids2)").AddEntity(typeof (Item))) + .SetParameterList("ids", new int[] {50}) + .SetParameterList("ids2", new int[] {50}); + multiQuery.List(); + } + } + + [Test] + public void NH_1085_WillGiveReasonableErrorIfBadParameterName() + { + using (ISession s = sessions.OpenSession()) + { + IMultiQuery multiQuery = s.CreateMultiQuery() + .Add(s.CreateSQLQuery("select * from ITEM where Id in (:ids)").AddEntity(typeof(Item))) + .Add(s.CreateSQLQuery("select * from ITEM where Id in (:ids2)").AddEntity(typeof(Item))); + var e = Assert.Throws<QueryException>(() => multiQuery.List()); + Assert.That(e.Message, Is.EqualTo("Not all named parameters have been set: ['ids'] [select * from ITEM where Id in (:ids)]")); + } + } + + [Test] + public void CanGetMultiQueryFromSecondLevelCache() + { + CreateItems(); + //set the query in the cache + DoMutiQueryAndAssert(); + + Hashtable cacheHashtable = GetHashTableUsedAsQueryCache(); + IList cachedListEntry = (IList)new ArrayList(cacheHashtable.Values)[0]; + IList cachedQuery = (IList)cachedListEntry[1]; + + IList firstQueryResults = (IList)cachedQuery[0]; + firstQueryResults.Clear(); + firstQueryResults.Add(3); + firstQueryResults.Add(4); + + IList secondQueryResults = (IList)cachedQuery[1]; + secondQueryResults[0] = 2L; + + using (ISession s = sessions.OpenSession()) + { + IMultiQuery multiQuery = s.CreateMultiQuery() + .Add(s.CreateSQLQuery("select * from ITEM where Id > ?").AddEntity(typeof(Item)) + .SetInt32(0, 50) + .SetFirstResult(10)) + .Add(s.CreateQuery("select count(*) from Item i where i.Id > ?") + .SetInt32(0, 50)); + multiQuery.SetCacheable(true); + IList results = multiQuery.List(); + IList items = (IList)results[0]; + Assert.AreEqual(2, items.Count); + long count = (long)((IList)results[1])[0]; + Assert.AreEqual(2L, count); + } + + RemoveAllItems(); + } + + [Test] + public void CanSpecifyParameterOnMultiQueryWhenItIsNotUsedInAllQueries() + { + using (ISession s = OpenSession()) + { + s.CreateMultiQuery() + .Add("from Item") + .Add(s.CreateSQLQuery("select * from ITEM where Id > :id").AddEntity(typeof(Item))) + .SetParameter("id", 5) + .List(); + } + } + + [Test] + public void CanSpecifyParameterOnMultiQueryWhenItIsNotUsedInAllQueries_MoreThanOneParameter() + { + using (ISession s = OpenSession()) + { + s.CreateMultiQuery() + .Add("from Item") + .Add(s.CreateSQLQuery("select * from ITEM where Id = :id or Id = :id2").AddEntity(typeof(Item))) + .Add("from Item i where i.Id = :id2") + .SetParameter("id", 5) + .SetInt32("id2", 5) + .List(); + } + } + + [Test] + public void TwoMultiQueriesWithDifferentPagingGetDifferentResultsWhenUsingCachedQueries() + { + CreateItems(); + using (ISession s = OpenSession()) + { + IMultiQuery multiQuery = s.CreateMultiQuery() + .Add(s.CreateQuery("from Item i where i.Id > ?") + .SetInt32(0, 50) + .SetFirstResult(10)) + .Add(s.CreateSQLQuery("select count(*) as count from ITEM where Id > ?").AddScalar("count", NHibernateUtil.Int64) + .SetInt32(0, 50)); + + multiQuery.SetCacheable(true); + IList results = multiQuery.List(); + IList items = (IList)results[0]; + Assert.AreEqual(89, items.Count); + long count = (long)((IList)results[1])[0]; + Assert.AreEqual(99L, count); + } + + using (ISession s = OpenSession()) + { + IMultiQuery multiQuery = s.CreateMultiQuery() + .Add(s.CreateSQLQuery("select * from ITEM where Id > ?").AddEntity(typeof(Item)) + .SetInt32(0, 50) + .SetFirstResult(20)) + .Add(s.CreateQuery("select count(*) from Item i where i.Id > ?") + .SetInt32(0, 50)); + multiQuery.SetCacheable(true); + IList results = multiQuery.List(); + IList items = (IList)results[0]; + Assert.AreEqual(79, items.Count, + "Should have gotten different result here, because the paging is different"); + long count = (long)((IList)results[1])[0]; + Assert.AreEqual(99L, count); + } + + RemoveAllItems(); + } + + [Test] + public void CanUseSecondLevelCacheWithPositionalParameters() + { + Hashtable cacheHashtable = GetHashTableUsedAsQueryCache(); + cacheHashtable.Clear(); + + CreateItems(); + + DoMutiQueryAndAssert(); + + Assert.AreEqual(1, cacheHashtable.Count); + + RemoveAllItems(); + } + + private void DoMutiQueryAndAssert() + { + using (ISession s = OpenSession()) + { + IMultiQuery multiQuery = s.CreateMultiQuery() + .Add(s.CreateSQLQuery("select * from ITEM where Id > ?").AddEntity(typeof(Item)) + .SetInt32(0, 50) + .SetFirstResult(10)) + .Add(s.CreateQuery("select count(*) from Item i where i.Id > ?") + .SetInt32(0, 50)); + multiQuery.SetCacheable(true); + IList results = multiQuery.List(); + IList items = (IList)results[0]; + Assert.AreEqual(89, items.Count); + long count = (long)((IList)results[1])[0]; + Assert.AreEqual(99L, count); + } + } + + private void CreateItems() + { + using (ISession s = OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + for (int i = 0; i < 150; i++) + { + Item item = new Item(); + item.Id = i; + s.Save(item); + } + t.Commit(); + } + } + + private Hashtable GetHashTableUsedAsQueryCache() + { + ISessionFactoryImplementor factory = (ISessionFactoryImplementor)sessions; + //need the inner hashtable in the cache + HashtableCache cache = (HashtableCache) + typeof(StandardQueryCache) + .GetField("queryCache", BindingFlags.Instance | BindingFlags.NonPublic) + .GetValue(factory.GetQueryCache(null)); + + return (Hashtable)typeof(HashtableCache) + .GetField("hashtable", BindingFlags.Instance | BindingFlags.NonPublic) + .GetValue(cache); + } + + [Test] + public void CanUseWithParameterizedQueriesAndLimit() + { + using (ISession s = OpenSession()) + { + for (int i = 0; i < 150; i++) + { + Item item = new Item(); + item.Id = i; + s.Save(item); + } + s.Flush(); + } + + using (ISession s = OpenSession()) + { + IQuery getItems = s.CreateSQLQuery("select * from ITEM where Id > :id").AddEntity(typeof(Item)).SetFirstResult(10); + IQuery countItems = s.CreateQuery("select count(*) from Item i where i.Id > :id"); + + IList results = s.CreateMultiQuery() + .Add(getItems) + .Add(countItems) + .SetInt32("id", 50) + .List(); + IList items = (IList)results[0]; + Assert.AreEqual(89, items.Count); + long count = (long)((IList)results[1])[0]; + Assert.AreEqual(99L, count); + } + + RemoveAllItems(); + } + + private void RemoveAllItems() + { + using (ISession s = OpenSession()) + { + s.Delete("from Item"); + s.Flush(); + } + } + + [Test] + public void CanUseSetParameterList() + { + using (ISession s = OpenSession()) + { + Item item = new Item(); + item.Id = 1; + s.Save(item); + s.Flush(); + } + + using (ISession s = OpenSession()) + { + IList results = s.CreateMultiQuery() + .Add(s.CreateSQLQuery("select * from ITEM where Id in (:items)").AddEntity(typeof(Item))) + .Add("select count(*) from Item i where i.id in (:items)") + .SetParameterList("items", new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }) + .List(); + + IList items = (IList)results[0]; + Item fromDb = (Item)items[0]; + Assert.AreEqual(1, fromDb.Id); + + IList counts = (IList)results[1]; + long count = (long)counts[0]; + Assert.AreEqual(1L, count); + } + + using (ISession s = OpenSession()) + { + s.Delete("from Item"); + s.Flush(); + } + } + + [Test] + public void CanExecuteMultiplyQueriesInSingleRoundTrip() + { + using (ISession s = OpenSession()) + { + Item item = new Item(); + item.Id = 1; + s.Save(item); + s.Flush(); + } + + using (ISession s = OpenSession()) + { + IQuery getItems = s.CreateSQLQuery("select * from ITEM").AddEntity(typeof(Item)); + IQuery countItems = s.CreateQuery("select count(*) from Item"); + + IList results = s.CreateMultiQuery() + .Add(getItems) + .Add(countItems) + .List(); + IList items = (IList)results[0]; + Item fromDb = (Item)items[0]; + Assert.AreEqual(1, fromDb.Id); + + IList counts = (IList)results[1]; + long count = (long)counts[0]; + Assert.AreEqual(1L, count); + } + + using (ISession s = OpenSession()) + { + s.Delete("from Item"); + s.Flush(); + } + } + + [Test] + public void CanAddIQueryWithKeyAndRetrieveResultsWithKey() + { + CreateItems(); + + using (ISession session = OpenSession()) + { + IMultiQuery multiQuery = session.CreateMultiQuery(); + + IQuery firstQuery = session.CreateSQLQuery("select * from ITEM where Id < :id").AddEntity(typeof(Item)) + .SetInt32("id", 50); + + IQuery secondQuery = session.CreateQuery("from Item"); + + multiQuery.Add("first", firstQuery).Add("second", secondQuery); + + IList secondResult = (IList)multiQuery.GetResult("second"); + IList firstResult = (IList)multiQuery.GetResult("first"); + + Assert.Greater(secondResult.Count, firstResult.Count); + } + + RemoveAllItems(); + } + + [Test] + public void CanNotAddQueryWithKeyThatAlreadyExists() + { + using (ISession session = OpenSession()) + { + IMultiQuery multiQuery = session.CreateMultiQuery(); + + IQuery firstQuery = session.CreateSQLQuery("select * from ITEM where Id < :id").AddEntity(typeof(Item)) + .SetInt32("id", 50); + + try + { + IQuery secondQuery = session.CreateSQLQuery("select * from ITEM").AddEntity(typeof(Item)); + multiQuery.Add("first", firstQuery).Add("second", secondQuery); + } + catch (InvalidOperationException) + { + } + catch (Exception) + { + Assert.Fail("This should've thrown an InvalidOperationException"); + } + } + } + + [Test] + public void CanNotRetrieveQueryResultWithUnknownKey() + { + using (ISession session = OpenSession()) + { + IMultiQuery multiQuery = session.CreateMultiQuery(); + + multiQuery.Add("firstQuery", session.CreateSQLQuery("select * from ITEM").AddEntity(typeof(Item))); + + try + { + IList firstResult = (IList)multiQuery.GetResult("unknownKey"); + Assert.Fail("This should've thrown an InvalidOperationException"); + } + catch (InvalidOperationException) + { + } + catch (Exception) + { + Assert.Fail("This should've thrown an InvalidOperationException"); + } + + } + } + + [Test] + public void ExecutingQueryThroughMultiQueryTransformsResults() + { + CreateItems(); + + using (ISession session = OpenSession()) + { + ResultTransformerStub transformer = new ResultTransformerStub(); + IQuery query = session.CreateSQLQuery("select * from ITEM").AddEntity(typeof(Item)) + .SetResultTransformer(transformer); + session.CreateMultiQuery() + .Add(query) + .List(); + + Assert.IsTrue(transformer.WasTransformTupleCalled, "Transform Tuple was not called"); + Assert.IsTrue(transformer.WasTransformListCalled, "Transform List was not called"); + } + + RemoveAllItems(); + } + + [Test] + public void ExecutingQueryThroughMultiQueryTransformsResults_When_setting_on_multi_query_directly() + { + CreateItems(); + + using (ISession session = OpenSession()) + { + ResultTransformerStub transformer = new ResultTransformerStub(); + IQuery query = session.CreateSQLQuery("select * from ITEM").AddEntity(typeof(Item)); + session.CreateMultiQuery() + .Add(query) + .SetResultTransformer(transformer) + .List(); + + Assert.IsTrue(transformer.WasTransformTupleCalled, "Transform Tuple was not called"); + Assert.IsTrue(transformer.WasTransformListCalled, "Transform List was not called"); + } + + RemoveAllItems(); + } + + + [Test] + public void CanGetResultsInAGenericList() + { + using (ISession s = OpenSession()) + { + IQuery getItems = s.CreateQuery("from Item"); + IQuery countItems = s.CreateSQLQuery("select count(*) as count from ITEM").AddScalar("count", NHibernateUtil.Int64); + + IList results = s.CreateMultiQuery() + .Add(getItems) + .Add<long>(countItems) + .List(); + + Assert.That(results[0], Is.InstanceOf<ArrayList>()); + Assert.That(results[1], Is.InstanceOf<List<long>>()); + } + } + + public class ResultTransformerStub : IResultTransformer + { + private bool _wasTransformTupleCalled; + private bool _wasTransformListCalled; + + public bool WasTransformTupleCalled + { + get { return _wasTransformTupleCalled; } + } + + public bool WasTransformListCalled + { + get { return _wasTransformListCalled; } + } + + public ResultTransformerStub() + { + _wasTransformTupleCalled = false; + _wasTransformListCalled = false; + } + + public object TransformTuple(object[] tuple, string[] aliases) + { + _wasTransformTupleCalled = true; + return tuple; + } + + public IList TransformList(IList collection) + { + _wasTransformListCalled = true; + return collection; + } + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-03-24 21:46:47
|
Revision: 5525 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5525&view=rev Author: fabiomaulo Date: 2011-03-24 21:46:41 +0000 (Thu, 24 Mar 2011) Log Message: ----------- Minor (passing test) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/Table.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1399/Fixture.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/Table.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/Table.cs 2011-03-24 21:07:55 UTC (rev 5524) +++ trunk/nhibernate/src/NHibernate/Mapping/Table.cs 2011-03-24 21:46:41 UTC (rev 5525) @@ -804,7 +804,7 @@ public string UniqueColumnString(IEnumerable iterator, string referencedEntityName) { - // NH Different implementation (NH-1339) + // NH Different implementation (NH-1399) int result = 37; if (referencedEntityName != null) { Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1399/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1399/Fixture.cs 2011-03-24 21:07:55 UTC (rev 5524) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1399/Fixture.cs 2011-03-24 21:46:41 UTC (rev 5525) @@ -1,5 +1,6 @@ using NHibernate.Mapping; using NUnit.Framework; +using SharpTestsEx; namespace NHibernate.Test.NHSpecificTest.NH1399 { @@ -17,5 +18,29 @@ string t2Fk = table1.UniqueColumnString(new object[] { table1ITestManyB }, "BluewireTechnologies.Core.Framework.DynamicTypes2.Albatross.ITestManyB"); Assert.AreNotEqual(t1Fk, t2Fk, "Different columns in differents tables create the same FK name."); } + + [Test] + public void UsingTwoInstancesWithSameValuesTheFkNameIsTheSame() + { + // This test is to be sure that an eventual SchemaUpdate will find the FK with the same name + // The FK name should not use values depending on instence, istead should use values depending on table/columns names. + Table table1 = new Table("ATABLE"); + + Column table1ITestManyA = new Column("itestmanyaid"); + Column table1ITestManyB = new Column("itestmanybid"); + string t1Fk = table1.UniqueColumnString(new object[] { table1ITestManyA }, "BluewireTechnologies.Core.Framework.DynamicTypes2.Albatross.ITestManyA"); + string t2Fk = table1.UniqueColumnString(new object[] { table1ITestManyB }, "BluewireTechnologies.Core.Framework.DynamicTypes2.Albatross.ITestManyB"); + + + Table table1_ = new Table("ATABLE"); + + Column table1ITestManyA_ = new Column("itestmanyaid"); + Column table1ITestManyB_ = new Column("itestmanybid"); + string t1Fk_ = table1_.UniqueColumnString(new object[] { table1ITestManyA_ }, "BluewireTechnologies.Core.Framework.DynamicTypes2.Albatross.ITestManyA"); + string t2Fk_ = table1_.UniqueColumnString(new object[] { table1ITestManyB_ }, "BluewireTechnologies.Core.Framework.DynamicTypes2.Albatross.ITestManyB"); + + t1Fk_.Should().Be.EqualTo(t1Fk); + t2Fk_.Should().Be.EqualTo(t2Fk); + } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-03-25 17:42:22
|
Revision: 5529 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5529&view=rev Author: fabiomaulo Date: 2011-03-25 17:42:16 +0000 (Fri, 25 Mar 2011) Log Message: ----------- Applied (modified) fix of NH-2490 (thanks to Matthew Gabeler-Lee) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/Join.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2490/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2490/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2490/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2490/Model.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/Join.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/Join.cs 2011-03-25 12:01:05 UTC (rev 5528) +++ trunk/nhibernate/src/NHibernate/Mapping/Join.cs 2011-03-25 17:42:16 UTC (rev 5529) @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; +using System.Linq; using NHibernate.Engine; using NHibernate.SqlCommand; -using NHibernate.Util; namespace NHibernate.Mapping { @@ -90,7 +90,7 @@ pk.Name = PK_ALIAS.ToAliasString(table.Name, dialect); table.PrimaryKey = pk; - pk.AddColumns(new SafetyEnumerable<Column>(Key.ColumnIterator)); + pk.AddColumns(Key.ColumnIterator.OfType<Column>()); } public int PropertySpan @@ -149,13 +149,8 @@ { if (!isLazy.HasValue) { - IEnumerator<Property> iter = PropertyIterator.GetEnumerator(); - while (iter.MoveNext() && !isLazy.HasValue) - { - if (!iter.Current.IsLazy) - isLazy = false; - } - isLazy = true; + var hasAllLazyProperties = !PropertyIterator.Any(property=> property.IsLazy == false); + isLazy = hasAllLazyProperties; } return isLazy.Value; } Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2490/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2490/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2490/Fixture.cs 2011-03-25 17:42:16 UTC (rev 5529) @@ -0,0 +1,50 @@ +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.NHSpecificTest.NH2490 +{ + [TestFixture] + public class Fixture : BugTestCase + { + [Test] + public void BadSqlFromJoinLogicError() + { + try + { + using (ISession s = OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + Derived item1 = new Derived() + { + ShortContent = "Short", + ShortContent2 = "Short2", + LongContent = "LongLongLongLongLong", + LongContent2 = "LongLongLongLongLong2", + }; + s.Save(item1); + t.Commit(); + } + + // this is the real meat of the test + // for most edifying results, run this with show_sql enabled + + using (ISession s = OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + var q = s.CreateQuery("from Base"); + q.Executing(query => query.List()).NotThrows(); + } + } + finally + { + using (ISession s = OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + s.Delete("from Derived"); + t.Commit(); + } + } + } + + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2490/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2490/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2490/Mappings.hbm.xml 2011-03-25 17:42:16 UTC (rev 5529) @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.NH2490" + assembly="NHibernate.Test" +> + <class name="Base" abstract="true"> + <id name="Id"> + <generator class="increment"/> + </id> + <discriminator column="Discriminator" type="String" /> + <property name="ShortContent" not-null="true"/> + <property name="LongContent" lazy="true" not-null="true"/> + </class> + <subclass name="Derived" extends="Base" discriminator-value="Derived"> + <join table="Derived" fetch="join"> + <key column="Id" /> + <property name="ShortContent2" not-null="true"/> + <property name="LongContent2" lazy="true" not-null="true" /> + </join> + </subclass> +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2490/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2490/Model.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2490/Model.cs 2011-03-25 17:42:16 UTC (rev 5529) @@ -0,0 +1,39 @@ + +namespace NHibernate.Test.NHSpecificTest.NH2490 +{ + public class Base + { + public virtual int Id + { + get; + set; + } + + public virtual string ShortContent + { + get; + set; + } + + public virtual string LongContent + { + get; + set; + } + } + + public class Derived : Base + { + public virtual string ShortContent2 + { + get; + set; + } + + public virtual string LongContent2 + { + get; + set; + } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-03-25 12:01:05 UTC (rev 5528) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-03-25 17:42:16 UTC (rev 5529) @@ -654,6 +654,8 @@ <Compile Include="NHSpecificTest\NH2470\DTO.cs" /> <Compile Include="NHSpecificTest\NH2484\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2484\Model.cs" /> + <Compile Include="NHSpecificTest\NH2490\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2490\Model.cs" /> <Compile Include="NHSpecificTest\NH2491\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2507\Animal.cs" /> <Compile Include="NHSpecificTest\NH2507\Fixture.cs" /> @@ -2490,6 +2492,7 @@ <EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="NHSpecificTest\NH2490\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1925\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2527\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1323\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-03-25 20:29:40
|
Revision: 5534 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5534&view=rev Author: fabiomaulo Date: 2011-03-25 20:29:34 +0000 (Fri, 25 Mar 2011) Log Message: ----------- Partial fix NH-2488 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Persister/Entity/SingleTableEntityPersister.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Model.cs Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/SingleTableEntityPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Entity/SingleTableEntityPersister.cs 2011-03-25 20:28:08 UTC (rev 5533) +++ trunk/nhibernate/src/NHibernate/Persister/Entity/SingleTableEntityPersister.cs 2011-03-25 20:29:34 UTC (rev 5534) @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Text; -using Iesi.Collections.Generic; +using System.Linq; using NHibernate.Cache; using NHibernate.Engine; using NHibernate.Mapping; @@ -638,15 +638,16 @@ //note that this method could easily be moved up to BasicEntityPersister, //if we ever needed to reuse it from other subclasses - //figure out which tables need to be fetched + //figure out which tables need to be fetched (only those that contains at least a no-lazy-property) AbstractEntityPersister subclassPersister = (AbstractEntityPersister)persister; - HashedSet<int> tableNumbers = new HashedSet<int>(); + var tableNumbers = new HashSet<int>(); string[] props = subclassPersister.PropertyNames; string[] classes = subclassPersister.PropertySubclassNames; + bool[] propertyLazies = subclassPersister.PropertyLaziness; for (int i = 0; i < props.Length; i++) { int propTableNumber = GetSubclassPropertyTableNumber(props[i], classes[i]); - if (IsSubclassTableSequentialSelect(propTableNumber) && !IsSubclassTableLazy(propTableNumber)) + if (IsSubclassTableSequentialSelect(propTableNumber) && !IsSubclassTableLazy(propTableNumber) && propertyLazies[i] == false) { tableNumbers.Add(propTableNumber); } @@ -654,26 +655,32 @@ if ((tableNumbers.Count == 0)) return null; - //figure out which columns are needed + //figure out which columns are needed (excludes lazy-properties) List<int> columnNumbers = new List<int>(); int[] columnTableNumbers = SubclassColumnTableNumberClosure; + bool[] subclassColumnLaziness = SubclassColumnLaziness; for (int i = 0; i < SubclassColumnClosure.Length; i++) { - if (tableNumbers.Contains(columnTableNumbers[i])) + if (tableNumbers.Contains(columnTableNumbers[i]) && !subclassColumnLaziness[i]) + { columnNumbers.Add(i); + } } - //figure out which formulas are needed + //figure out which formulas are needed (excludes lazy-properties) List<int> formulaNumbers = new List<int>(); int[] formulaTableNumbers = SubclassColumnTableNumberClosure; + bool[] subclassFormulaLaziness = SubclassFormulaLaziness; for (int i = 0; i < SubclassFormulaTemplateClosure.Length; i++) { - if (tableNumbers.Contains(formulaTableNumbers[i])) + if (tableNumbers.Contains(formulaTableNumbers[i]) && !subclassFormulaLaziness[i]) + { formulaNumbers.Add(i); + } } //render the SQL - return RenderSelect(ArrayHelper.ToIntArray(tableNumbers), columnNumbers.ToArray(), formulaNumbers.ToArray()); + return RenderSelect(tableNumbers.ToArray(), columnNumbers.ToArray(), formulaNumbers.ToArray()); } protected override string[] GetSubclassTableKeyColumns(int j) Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Fixture.cs 2011-03-25 20:29:34 UTC (rev 5534) @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.NHSpecificTest.NH2488 +{ + public class Fixture : BugTestCase + { + #region Scenarios + + private class FetchSelectScenario: IDisposable + { + private readonly ISessionFactory factory; + + public FetchSelectScenario(ISessionFactory factory) + { + this.factory = factory; + using (ISession s = factory.OpenSession()) + { + using (ITransaction t = s.BeginTransaction()) + { + var entity = new Derived1 + { + ShortContent = "Short", + LongContent = "LongLongLongLongLong", + }; + s.Save(entity); + t.Commit(); + } + } + } + + public void Dispose() + { + using (ISession s = factory.OpenSession()) + { + using (ITransaction t = s.BeginTransaction()) + { + s.Delete("from Derived1"); + t.Commit(); + } + } + } + } + private class FetchJoinScenario : IDisposable + { + private readonly ISessionFactory factory; + + public FetchJoinScenario(ISessionFactory factory) + { + this.factory = factory; + using (ISession s = factory.OpenSession()) + { + using (ITransaction t = s.BeginTransaction()) + { + var entity = new Derived2 + { + ShortContent = "Short", + LongContent = "LongLongLongLongLong", + }; + s.Save(entity); + t.Commit(); + } + } + } + + public void Dispose() + { + using (ISession s = factory.OpenSession()) + { + using (ITransaction t = s.BeginTransaction()) + { + s.Delete("from Derived2"); + t.Commit(); + } + } + } + } + + #endregion + + [Test, Ignore("Not fixed yet")] + public void ShouldNotQueryLazyProperties_FetchJoin() + { + using (new FetchJoinScenario(Sfi)) + { + using (ISession s = OpenSession()) + { + using (ITransaction t = s.BeginTransaction()) + { + IList<Base2> items; + using (var ls = new SqlLogSpy()) + { + items = s.CreateQuery("from Base2").List<Base2>(); + ls.GetWholeLog().Should().Not.Contain("LongContent"); + } + var item = (Derived2) items[0]; + NHibernateUtil.IsPropertyInitialized(item, "LongContent").Should().Be.False(); + string lc = item.LongContent; + lc.Should().Not.Be.NullOrEmpty(); + NHibernateUtil.IsPropertyInitialized(item, "LongContent").Should().Be.True(); + } + } + } + } + + [Test] + public void ShouldNotQueryLazyProperties_FetchSelect() + { + // this is the real meat of the test + // for most edifying results, run this with show_sql enabled + + using (new FetchSelectScenario(Sfi)) + { + using (ISession s = OpenSession()) + { + using (ITransaction t = s.BeginTransaction()) + { + IList<Base1> items; + using(var ls = new SqlLogSpy()) + { + items = s.CreateQuery("from Base1").List<Base1>(); + ls.GetWholeLog().Should().Not.Contain("LongContent"); + } + var item = (Derived1) items[0]; + NHibernateUtil.IsPropertyInitialized(item, "LongContent").Should().Be.False(); + string lc = item.LongContent; + lc.Should().Not.Be.NullOrEmpty(); + NHibernateUtil.IsPropertyInitialized(item, "LongContent").Should().Be.True(); + } + } + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Mappings.hbm.xml 2011-03-25 20:29:34 UTC (rev 5534) @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.NH2488" + assembly="NHibernate.Test" +> + <class name="Base1" abstract="true"> + <id name="Id"> + <generator class="increment"/> + </id> + <discriminator column="Discriminator" type="String" /> + <property name="ShortContent"/> + </class> + <subclass name="Derived1" extends="Base1" discriminator-value="Derived1"> + <join table="Derived1" fetch="select"> + <key column="Id" /> + <property name="LongContent" lazy="true" not-null="true" /> + </join> + </subclass> + <class name="Base2" abstract="true"> + <id name="Id"> + <generator class="increment"/> + </id> + <discriminator column="Discriminator" type="String" /> + <property name="ShortContent"/> + </class> + <subclass name="Derived2" extends="Base2" discriminator-value="Derived2"> + <join table="Derived2" fetch="join"> + <key column="Id" /> + <property name="LongContent" lazy="true" not-null="true" /> + </join> + </subclass> +</hibernate-mapping> \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Model.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Model.cs 2011-03-25 20:29:34 UTC (rev 5534) @@ -0,0 +1,26 @@ +namespace NHibernate.Test.NHSpecificTest.NH2488 +{ + public class Base1 + { + public virtual int Id { get; set; } + + public virtual string ShortContent { get; set; } + } + + public class Base2 + { + public virtual int Id { get; set; } + + public virtual string ShortContent { get; set; } + } + + public class Derived1 : Base1 + { + public virtual string LongContent { get; set; } + } + + public class Derived2 : Base2 + { + public virtual string LongContent { get; set; } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-03-25 20:28:08 UTC (rev 5533) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-03-25 20:29:34 UTC (rev 5534) @@ -654,6 +654,8 @@ <Compile Include="NHSpecificTest\NH2470\DTO.cs" /> <Compile Include="NHSpecificTest\NH2484\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2484\Model.cs" /> + <Compile Include="NHSpecificTest\NH2488\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2488\Model.cs" /> <Compile Include="NHSpecificTest\NH2490\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2490\Model.cs" /> <Compile Include="NHSpecificTest\NH2491\Fixture.cs" /> @@ -2492,6 +2494,7 @@ <EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="NHSpecificTest\NH2488\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2490\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1925\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2527\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-03-25 21:44:34
|
Revision: 5535 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5535&view=rev Author: fabiomaulo Date: 2011-03-25 21:44:28 +0000 (Fri, 25 Mar 2011) Log Message: ----------- Reverted previous partial fix and fixed NH-2488 completely (added joined-subclass case) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Persister/Entity/SingleTableEntityPersister.cs trunk/nhibernate/src/NHibernate/Tuple/Entity/PocoEntityTuplizer.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Model.cs Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/SingleTableEntityPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Entity/SingleTableEntityPersister.cs 2011-03-25 20:29:34 UTC (rev 5534) +++ trunk/nhibernate/src/NHibernate/Persister/Entity/SingleTableEntityPersister.cs 2011-03-25 21:44:28 UTC (rev 5535) @@ -138,13 +138,8 @@ ?? ExecuteUpdateResultCheckStyle.DetermineDefault(customSQLDelete[j], deleteCallable[j]); - IEnumerable<Column> enumerableKeyCol = new SafetyEnumerable<Column>(join.Key.ColumnIterator); - List<string> kcName = new List<string>(join.Key.ColumnSpan); - foreach (Column col in enumerableKeyCol) - kcName.Add(col.GetQuotedName(factory.Dialect)); + keyColumnNames[j] = join.Key.ColumnIterator.OfType<Column>().Select(col => col.GetQuotedName(factory.Dialect)).ToArray(); - keyColumnNames[j] = kcName.ToArray(); - j++; } @@ -156,7 +151,7 @@ constraintOrderedKeyColumnNames[position] = keyColumnNames[i]; } - spaces = ArrayHelper.Join(qualifiedTableNames, ArrayHelper.ToStringArray(persistentClass.SynchronizedTables)); + spaces = qualifiedTableNames.Concat(persistentClass.SynchronizedTables).ToArray(); bool lazyAvailable = IsInstrumented(EntityMode.Poco); @@ -185,12 +180,9 @@ if (join.IsSequentialSelect && !persistentClass.IsClassOrSuperclassJoin(join)) hasDeferred = true; subclassTables.Add(join.Table.GetQualifiedName(factory.Dialect, factory.Settings.DefaultCatalogName, factory.Settings.DefaultSchemaName)); - IEnumerable<Column> enumerableKeyCol = new SafetyEnumerable<Column>(join.Key.ColumnIterator); - List<string> keyCols = new List<string>(join.Key.ColumnSpan); - foreach (Column col in enumerableKeyCol) - keyCols.Add(col.GetQuotedName(factory.Dialect)); - joinKeyColumns.Add(keyCols.ToArray()); + var keyCols = join.Key.ColumnIterator.OfType<Column>().Select(col => col.GetQuotedName(factory.Dialect)).ToArray(); + joinKeyColumns.Add(keyCols); } subclassTableSequentialSelect = isDeferreds.ToArray(); @@ -297,7 +289,6 @@ int join = persistentClass.GetJoinNumber(prop); propertyJoinNumbers.Add(join); - //propertyTableNumbersByName.put( prop.getName(), join ); propertyTableNumbersByNameAndSubclass[prop.PersistentClass.EntityName + '.' + prop.Name] = join; foreach (ISelectable thing in prop.ColumnIterator) { @@ -643,11 +634,10 @@ var tableNumbers = new HashSet<int>(); string[] props = subclassPersister.PropertyNames; string[] classes = subclassPersister.PropertySubclassNames; - bool[] propertyLazies = subclassPersister.PropertyLaziness; for (int i = 0; i < props.Length; i++) { int propTableNumber = GetSubclassPropertyTableNumber(props[i], classes[i]); - if (IsSubclassTableSequentialSelect(propTableNumber) && !IsSubclassTableLazy(propTableNumber) && propertyLazies[i] == false) + if (IsSubclassTableSequentialSelect(propTableNumber) && !IsSubclassTableLazy(propTableNumber)) { tableNumbers.Add(propTableNumber); } @@ -658,10 +648,9 @@ //figure out which columns are needed (excludes lazy-properties) List<int> columnNumbers = new List<int>(); int[] columnTableNumbers = SubclassColumnTableNumberClosure; - bool[] subclassColumnLaziness = SubclassColumnLaziness; for (int i = 0; i < SubclassColumnClosure.Length; i++) { - if (tableNumbers.Contains(columnTableNumbers[i]) && !subclassColumnLaziness[i]) + if (tableNumbers.Contains(columnTableNumbers[i])) { columnNumbers.Add(i); } @@ -670,10 +659,9 @@ //figure out which formulas are needed (excludes lazy-properties) List<int> formulaNumbers = new List<int>(); int[] formulaTableNumbers = SubclassColumnTableNumberClosure; - bool[] subclassFormulaLaziness = SubclassFormulaLaziness; for (int i = 0; i < SubclassFormulaTemplateClosure.Length; i++) { - if (tableNumbers.Contains(formulaTableNumbers[i]) && !subclassFormulaLaziness[i]) + if (tableNumbers.Contains(formulaTableNumbers[i])) { formulaNumbers.Add(i); } Modified: trunk/nhibernate/src/NHibernate/Tuple/Entity/PocoEntityTuplizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Tuple/Entity/PocoEntityTuplizer.cs 2011-03-25 20:29:34 UTC (rev 5534) +++ trunk/nhibernate/src/NHibernate/Tuple/Entity/PocoEntityTuplizer.cs 2011-03-25 21:44:28 UTC (rev 5535) @@ -78,9 +78,11 @@ public override bool IsInstrumented { get - { - return (EntityMetamodel.HasLazyProperties || EntityMetamodel.HasUnwrapProxyForProperties) - && FieldInterceptionHelper.IsInstrumented(MappedClass); + { + // NH: we can't really check for EntityMetamodel.HasLazyProperties and/or EntityMetamodel.HasUnwrapProxyForProperties here + // because this property is used even where subclasses has lazy-properties. + // Checking it here, where the root-entity has no lazy properties we will eager-load/double-load those properties. + return FieldInterceptionHelper.IsInstrumented(MappedClass); } } @@ -224,7 +226,7 @@ public override void AfterInitialize(object entity, bool lazyPropertiesAreUnfetched, ISessionImplementor session) { - if (IsInstrumented) + if (IsInstrumented && (EntityMetamodel.HasLazyProperties || EntityMetamodel.HasUnwrapProxyForProperties)) { HashedSet<string> lazyProps = lazyPropertiesAreUnfetched && EntityMetamodel.HasLazyProperties ? lazyPropertyNames : null; //TODO: if we support multiple fetch groups, we would need Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Fixture.cs 2011-03-25 20:29:34 UTC (rev 5534) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Fixture.cs 2011-03-25 21:44:28 UTC (rev 5535) @@ -77,10 +77,44 @@ } } } + private class JoinedSubclassScenario : IDisposable + { + private readonly ISessionFactory factory; + public JoinedSubclassScenario(ISessionFactory factory) + { + this.factory = factory; + using (ISession s = factory.OpenSession()) + { + using (ITransaction t = s.BeginTransaction()) + { + var entity = new Derived3 + { + ShortContent = "Short", + LongContent = "LongLongLongLongLong", + }; + s.Save(entity); + t.Commit(); + } + } + } + + public void Dispose() + { + using (ISession s = factory.OpenSession()) + { + using (ITransaction t = s.BeginTransaction()) + { + s.Delete("from Derived3"); + t.Commit(); + } + } + } + } + #endregion - [Test, Ignore("Not fixed yet")] + [Test] public void ShouldNotQueryLazyProperties_FetchJoin() { using (new FetchJoinScenario(Sfi)) @@ -108,9 +142,6 @@ [Test] public void ShouldNotQueryLazyProperties_FetchSelect() { - // this is the real meat of the test - // for most edifying results, run this with show_sql enabled - using (new FetchSelectScenario(Sfi)) { using (ISession s = OpenSession()) @@ -132,5 +163,30 @@ } } } + + [Test] + public void ShouldNotQueryLazyProperties_Joinedsubclass() + { + using (new JoinedSubclassScenario(Sfi)) + { + using (ISession s = OpenSession()) + { + using (ITransaction t = s.BeginTransaction()) + { + IList<Base3> items; + using (var ls = new SqlLogSpy()) + { + items = s.CreateQuery("from Base3").List<Base3>(); + ls.GetWholeLog().Should().Not.Contain("LongContent"); + } + var item = (Derived3)items[0]; + NHibernateUtil.IsPropertyInitialized(item, "LongContent").Should().Be.False(); + string lc = item.LongContent; + lc.Should().Not.Be.NullOrEmpty(); + NHibernateUtil.IsPropertyInitialized(item, "LongContent").Should().Be.True(); + } + } + } + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Mappings.hbm.xml 2011-03-25 20:29:34 UTC (rev 5534) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Mappings.hbm.xml 2011-03-25 21:44:28 UTC (rev 5535) @@ -29,4 +29,16 @@ <property name="LongContent" lazy="true" not-null="true" /> </join> </subclass> + + <class name="Base3" abstract="true"> + <id name="Id"> + <generator class="increment"/> + </id> + <property name="ShortContent"/> + </class> + <joined-subclass name="Derived3" extends="Base3"> + <key column="Id" /> + <property name="LongContent" lazy="true" not-null="true" /> + </joined-subclass> + </hibernate-mapping> \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Model.cs 2011-03-25 20:29:34 UTC (rev 5534) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2488/Model.cs 2011-03-25 21:44:28 UTC (rev 5535) @@ -23,4 +23,15 @@ { public virtual string LongContent { get; set; } } + + public class Base3 + { + public virtual int Id { get; set; } + + public virtual string ShortContent { get; set; } + } + public class Derived3 : Base3 + { + public virtual string LongContent { get; set; } + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2011-03-26 00:43:40
|
Revision: 5536 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5536&view=rev Author: patearl Date: 2011-03-26 00:43:34 +0000 (Sat, 26 Mar 2011) Log Message: ----------- Added and partially utilized Dialect.SupportsForeignKeyConstraintInAlterTable property. Need to fill in the "CREATE TABLE" part of the implementation still. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2011-03-25 21:44:28 UTC (rev 5535) +++ trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2011-03-26 00:43:34 UTC (rev 5536) @@ -912,7 +912,7 @@ script.Add(index.SqlCreateString(dialect, mapping, defaultCatalog, defaultSchema)); } - if (dialect.HasAlterTable) + if (dialect.SupportsForeignKeyConstraintInAlterTable) { foreach (var fk in table.ForeignKeyIterator) { @@ -2320,7 +2320,7 @@ ITableMetadata tableInfo = databaseMetadata.GetTableMetadata(table.Name, table.Schema, table.Catalog, table.IsQuoted); - if (dialect.HasAlterTable) + if (dialect.SupportsForeignKeyConstraintInAlterTable) { foreach (var fk in table.ForeignKeyIterator) { Modified: trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs 2011-03-25 21:44:28 UTC (rev 5535) +++ trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs 2011-03-26 00:43:34 UTC (rev 5536) @@ -621,6 +621,14 @@ get { return true; } } + /// <summary> + /// Does this dialect support adding foreign key constraints via alter table? If not, it's assumed they can only be added through create table. + /// </summary> + public virtual bool SupportsForeignKeyConstraintInAlterTable + { + get { return HasAlterTable; } + } + /// <summary> /// The syntax used to add a foreign key constraint to a table. /// </summary> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-03-26 12:12:50
|
Revision: 5537 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5537&view=rev Author: fabiomaulo Date: 2011-03-26 12:12:43 +0000 (Sat, 26 Mar 2011) Log Message: ----------- Fix NH-2382 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/IMultiQuery.cs trunk/nhibernate/src/NHibernate/IQuery.cs trunk/nhibernate/src/NHibernate/Impl/AbstractQueryImpl.cs trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs Modified: trunk/nhibernate/src/NHibernate/IMultiQuery.cs =================================================================== --- trunk/nhibernate/src/NHibernate/IMultiQuery.cs 2011-03-26 00:43:34 UTC (rev 5536) +++ trunk/nhibernate/src/NHibernate/IMultiQuery.cs 2011-03-26 12:12:43 UTC (rev 5537) @@ -243,6 +243,11 @@ /// <returns>The instance for method chain.</returns> IMultiQuery SetDateTime(string name, DateTime val); + IMultiQuery SetDateTime2(string name, DateTime val); + IMultiQuery SetTimeSpan(string name, TimeSpan val); + IMultiQuery SetTimeAsTimeSpan(string name, TimeSpan val); + IMultiQuery SetDateTimeOffset(string name, DateTimeOffset val); + /// <summary> /// Bind an instance of a <see cref="Decimal" /> to a named parameter /// using an NHibernate <see cref="DecimalType"/>. Modified: trunk/nhibernate/src/NHibernate/IQuery.cs =================================================================== --- trunk/nhibernate/src/NHibernate/IQuery.cs 2011-03-26 00:43:34 UTC (rev 5536) +++ trunk/nhibernate/src/NHibernate/IQuery.cs 2011-03-26 12:12:43 UTC (rev 5537) @@ -412,6 +412,15 @@ /// <param name="name">The name of the parameter</param> IQuery SetDateTime(string name, DateTime val); + IQuery SetDateTime2(int position, DateTime val); + IQuery SetDateTime2(string name, DateTime val); + IQuery SetTimeSpan(int position, TimeSpan val); + IQuery SetTimeSpan(string name, TimeSpan val); + IQuery SetTimeAsTimeSpan(int position, TimeSpan val); + IQuery SetTimeAsTimeSpan(string name, TimeSpan val); + IQuery SetDateTimeOffset(int position, DateTimeOffset val); + IQuery SetDateTimeOffset(string name, DateTimeOffset val); + /// <summary> /// Bind an instance of a <see cref="Decimal" /> to an indexed parameter /// using an NHibernate <see cref="DecimalType"/>. Modified: trunk/nhibernate/src/NHibernate/Impl/AbstractQueryImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/AbstractQueryImpl.cs 2011-03-26 00:43:34 UTC (rev 5536) +++ trunk/nhibernate/src/NHibernate/Impl/AbstractQueryImpl.cs 2011-03-26 12:12:43 UTC (rev 5537) @@ -437,6 +437,12 @@ return this; } + public IQuery SetDateTimeOffset(string name, DateTimeOffset val) + { + SetParameter(name, val, NHibernateUtil.DateTimeOffset); + return this; + } + public IQuery SetDecimal(int position, decimal val) { SetParameter(position, val, NHibernateUtil.Decimal); @@ -551,6 +557,48 @@ return this; } + public IQuery SetDateTime2(int position, DateTime val) + { + SetParameter(position, val, NHibernateUtil.DateTime2); + return this; + } + + public IQuery SetDateTime2(string name, DateTime val) + { + SetParameter(name, val, NHibernateUtil.DateTime2); + return this; + } + + public IQuery SetTimeSpan(int position, TimeSpan val) + { + SetParameter(position, val, NHibernateUtil.TimeSpan); + return this; + } + + public IQuery SetTimeSpan(string name, TimeSpan val) + { + SetParameter(name, val, NHibernateUtil.TimeSpan); + return this; + } + + public IQuery SetTimeAsTimeSpan(int position, TimeSpan val) + { + SetParameter(position, val, NHibernateUtil.TimeAsTimeSpan); + return this; + } + + public IQuery SetTimeAsTimeSpan(string name, TimeSpan val) + { + SetParameter(name, val, NHibernateUtil.TimeAsTimeSpan); + return this; + } + + public IQuery SetDateTimeOffset(int position, DateTimeOffset val) + { + SetParameter(position, val, NHibernateUtil.DateTimeOffset); + return this; + } + public IQuery SetTime(string name, DateTime val) { SetParameter(name, val, NHibernateUtil.Time); Modified: trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs 2011-03-26 00:43:34 UTC (rev 5536) +++ trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs 2011-03-26 12:12:43 UTC (rev 5537) @@ -164,6 +164,42 @@ return this; } + public IMultiQuery SetDateTime2(string name, DateTime val) + { + foreach (IQuery query in queries) + { + query.SetParameter(name, val, NHibernateUtil.DateTime2); + } + return this; + } + + public IMultiQuery SetTimeSpan(string name, TimeSpan val) + { + foreach (IQuery query in queries) + { + query.SetParameter(name, val, NHibernateUtil.TimeSpan); + } + return this; + } + + public IMultiQuery SetTimeAsTimeSpan(string name, TimeSpan val) + { + foreach (IQuery query in queries) + { + query.SetParameter(name, val, NHibernateUtil.TimeAsTimeSpan); + } + return this; + } + + public IMultiQuery SetDateTimeOffset(string name, DateTimeOffset val) + { + foreach (IQuery query in queries) + { + query.SetParameter(name, val, NHibernateUtil.DateTimeOffset); + } + return this; + } + public IMultiQuery SetDecimal(string name, decimal val) { foreach (IQuery query in queries) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2011-03-26 18:27:37
|
Revision: 5543 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5543&view=rev Author: patearl Date: 2011-03-26 18:27:30 +0000 (Sat, 26 Mar 2011) Log Message: ----------- Support foreign keys on SQLite. Breaking change for databases that don't support alter table and have DDL-time foreign key correctness checks. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs trunk/nhibernate/src/NHibernate/Dialect/Schema/SQLiteMetaData.cs trunk/nhibernate/src/NHibernate/Driver/SQLite20Driver.cs trunk/nhibernate/src/NHibernate/Mapping/Table.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2011-03-26 16:35:24 UTC (rev 5542) +++ trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2011-03-26 18:27:30 UTC (rev 5543) @@ -813,7 +813,10 @@ var script = new List<string>(); - // drop them in reverse order in case db needs it done that way... + if (!string.IsNullOrEmpty(dialect.BeforeDropSchemaCommand)) + script.Add(dialect.BeforeDropSchemaCommand); + + // drop them in reverse order in case db needs it done that way...);); for (int i = auxiliaryDatabaseObjects.Count - 1; i >= 0; i--) { IAuxiliaryDatabaseObject auxDbObj = auxiliaryDatabaseObjects[i]; @@ -861,6 +864,9 @@ } } + if (!string.IsNullOrEmpty(dialect.AfterDropSchemaCommand)) + script.Add(dialect.AfterDropSchemaCommand); + return script.ToArray(); } Modified: trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs 2011-03-26 16:35:24 UTC (rev 5542) +++ trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs 2011-03-26 18:27:30 UTC (rev 5543) @@ -645,7 +645,10 @@ { var res = new StringBuilder(200); - res.Append(" add constraint ") + if (SupportsForeignKeyConstraintInAlterTable) + res.Append(" add"); + + res.Append(" constraint ") .Append(constraintName) .Append(" foreign key (") .Append(StringHelper.Join(StringHelper.CommaSpace, foreignKey)) @@ -2413,5 +2416,15 @@ { return false; } - } + + public virtual string BeforeDropSchemaCommand + { + get { return null; } + } + + public virtual string AfterDropSchemaCommand + { + get { return null; } + } + } } Modified: trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs 2011-03-26 16:35:24 UTC (rev 5542) +++ trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs 2011-03-26 18:27:30 UTC (rev 5543) @@ -261,6 +261,23 @@ get { return "select randomblob(16)"; } } + /// <summary> + /// SQLite does not currently support dropping foreign key constraints by alter statements. + /// This means that tables cannot be dropped if there are any rows that depend on those. + /// If there are cycles between tables, it would even be excessively difficult to delete + /// the data in the right order first. Because of this, we just turn off the foreign + /// constraints before we drop the schema and hope that we're not going to break anything. :( + /// </summary> + public override string BeforeDropSchemaCommand + { + get { return "PRAGMA foreign_keys = OFF"; } + } + + public override string AfterDropSchemaCommand + { + get { return "PRAGMA foreign_keys = ON"; } + } + [Serializable] protected class SQLiteCastFunction : CastFunction { Modified: trunk/nhibernate/src/NHibernate/Dialect/Schema/SQLiteMetaData.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/Schema/SQLiteMetaData.cs 2011-03-26 16:35:24 UTC (rev 5542) +++ trunk/nhibernate/src/NHibernate/Dialect/Schema/SQLiteMetaData.cs 2011-03-26 18:27:30 UTC (rev 5543) @@ -30,8 +30,8 @@ protected override string GetConstraintName(DataRow rs) { - throw new NotImplementedException(); - } + return Convert.ToString(rs["CONSTRAINT_NAME"]); + } protected override IForeignKeyMetadata GetForeignKeyMetadata(DataRow rs) { Modified: trunk/nhibernate/src/NHibernate/Driver/SQLite20Driver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Driver/SQLite20Driver.cs 2011-03-26 16:35:24 UTC (rev 5542) +++ trunk/nhibernate/src/NHibernate/Driver/SQLite20Driver.cs 2011-03-26 18:27:30 UTC (rev 5543) @@ -1,4 +1,6 @@ using System; +using System.Data; +using System.Data.Common; namespace NHibernate.Driver { @@ -33,6 +35,28 @@ { } + public override IDbConnection CreateConnection() + { + DbConnection connection = (DbConnection)base.CreateConnection(); + connection.StateChange += Connection_StateChange; + return connection; + } + + private static void Connection_StateChange(object sender, StateChangeEventArgs e) + { + if ((e.OriginalState == ConnectionState.Broken || e.OriginalState == ConnectionState.Closed || e.OriginalState == ConnectionState.Connecting) && + e.CurrentState == ConnectionState.Open) + { + DbConnection connection = (DbConnection)sender; + using (DbCommand command = connection.CreateCommand()) + { + // Activated foreign keys if supported by SQLite. Unknown pragmas are ignored. + command.CommandText = "PRAGMA foreign_keys = ON"; + command.ExecuteNonQuery(); + } + } + } + public override bool UseNamedPrefixInSql { get { return true; } Modified: trunk/nhibernate/src/NHibernate/Mapping/Table.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/Table.cs 2011-03-26 16:35:24 UTC (rev 5542) +++ trunk/nhibernate/src/NHibernate/Mapping/Table.cs 2011-03-26 18:27:30 UTC (rev 5543) @@ -427,6 +427,17 @@ } } + if (!dialect.SupportsForeignKeyConstraintInAlterTable) + { + foreach (ForeignKey foreignKey in ForeignKeyIterator) + { + if (foreignKey.HasPhysicalConstraint) + { + buf.Append(",").Append(foreignKey.SqlConstraintString(dialect, foreignKey.Name, defaultCatalog, defaultSchema)); + } + } + } + buf.Append(StringHelper.ClosedParen); if (string.IsNullOrEmpty(comment) == false) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-03-26 18:52:00
|
Revision: 5544 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5544&view=rev Author: ricbrown Date: 2011-03-26 18:51:53 +0000 (Sat, 26 Mar 2011) Log Message: ----------- NH-2592 (Add ICriteria functionality missing in QueryOver) - added overloads for on-clause in left joins Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/DetachedCriteria.cs trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverJoinBuilder.cs trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs trunk/nhibernate/src/NHibernate/IQueryOver.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/DetachedCriteria.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/DetachedCriteria.cs 2011-03-26 18:27:30 UTC (rev 5543) +++ trunk/nhibernate/src/NHibernate/Criterion/DetachedCriteria.cs 2011-03-26 18:51:53 UTC (rev 5544) @@ -155,6 +155,11 @@ return new DetachedCriteria(impl, criteria.CreateCriteria(associationPath, alias, joinType)); } + public DetachedCriteria CreateCriteria(string associationPath, string alias, JoinType joinType, ICriterion withClause) + { + return new DetachedCriteria(impl, criteria.CreateCriteria(associationPath, alias, joinType, withClause)); + } + public string Alias { get { return criteria.Alias; } Modified: trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverJoinBuilder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverJoinBuilder.cs 2011-03-26 18:27:30 UTC (rev 5543) +++ trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverJoinBuilder.cs 2011-03-26 18:51:53 UTC (rev 5544) @@ -28,11 +28,41 @@ return root.JoinQueryOver<U>(path, alias, joinType); } + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, U>> path, Expression<Func<U>> alias, Expression<Func<U,bool>> withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, U>> path, Expression<Func<U>> alias, Expression<Func<bool>> withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, U>> path, Expression<Func<U>> alias, ICriterion withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, withClause); + } + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<U>> path, Expression<Func<U>> alias) { return root.JoinQueryOver<U>(path, alias, joinType); } + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<U>> path, Expression<Func<U>> alias, Expression<Func<U,bool>> withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<U>> path, Expression<Func<U>> alias, Expression<Func<bool>> withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<U>> path, Expression<Func<U>> alias, ICriterion withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, withClause); + } + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path) { return root.JoinQueryOver<U>(path, joinType); @@ -48,11 +78,41 @@ return root.JoinQueryOver<U>(path, alias, joinType); } + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias, Expression<Func<U,bool>> withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias, Expression<Func<bool>> withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias, ICriterion withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, withClause); + } + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias) { return root.JoinQueryOver<U>(path, alias, joinType); } + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, Expression<Func<U,bool>> withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, Expression<Func<bool>> withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, ICriterion withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, withClause); + } + } public class IQueryOverJoinBuilder<TRoot,TSubType> : QueryOverJoinBuilderBase<IQueryOver<TRoot,TSubType>, TRoot, TSubType> @@ -74,11 +134,41 @@ return root.JoinQueryOver<U>(path, alias, joinType); } + public IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, U>> path, Expression<Func<U>> alias, Expression<Func<U,bool>> withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, U>> path, Expression<Func<U>> alias, Expression<Func<bool>> withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, U>> path, Expression<Func<U>> alias, ICriterion withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, withClause); + } + public IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<U>> path, Expression<Func<U>> alias) { return root.JoinQueryOver<U>(path, alias, joinType); } + public IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<U>> path, Expression<Func<U>> alias, Expression<Func<U,bool>> withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<U>> path, Expression<Func<U>> alias, Expression<Func<bool>> withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<U>> path, Expression<Func<U>> alias, ICriterion withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, withClause); + } + public IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path) { return root.JoinQueryOver<U>(path, joinType); @@ -94,11 +184,41 @@ return root.JoinQueryOver<U>(path, alias, joinType); } + public IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias, Expression<Func<U,bool>> withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias, Expression<Func<bool>> withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias, ICriterion withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, withClause); + } + public IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias) { return root.JoinQueryOver<U>(path, alias, joinType); } + public IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, Expression<Func<U,bool>> withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, Expression<Func<bool>> withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, ICriterion withClause) + { + return root.JoinQueryOver<U>(path, alias, joinType, withClause); + } + } public class QueryOverJoinBuilderBase<TReturn, TRoot, TSubType> where TReturn : IQueryOver<TRoot,TSubType> @@ -118,11 +238,71 @@ return (TReturn)root.JoinAlias(path, alias, joinType); } + public TReturn JoinAlias<U>(Expression<Func<TSubType, U>> path, Expression<Func<U>> alias, Expression<Func<U,bool>> withClause) + { + return (TReturn)root.JoinAlias(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public TReturn JoinAlias<U>(Expression<Func<TSubType, U>> path, Expression<Func<U>> alias, Expression<Func<bool>> withClause) + { + return (TReturn)root.JoinAlias(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public TReturn JoinAlias<U>(Expression<Func<TSubType, U>> path, Expression<Func<U>> alias, ICriterion withClause) + { + return (TReturn)root.JoinAlias(path, alias, joinType, withClause); + } + + public TReturn JoinAlias<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias, Expression<Func<U,bool>> withClause) + { + return (TReturn)root.JoinAlias(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public TReturn JoinAlias<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias, Expression<Func<bool>> withClause) + { + return (TReturn)root.JoinAlias(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public TReturn JoinAlias<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias, ICriterion withClause) + { + return (TReturn)root.JoinAlias(path, alias, joinType, withClause); + } + public TReturn JoinAlias(Expression<Func<object>> path, Expression<Func<object>> alias) { return (TReturn)root.JoinAlias(path, alias, joinType); } + public TReturn JoinAlias<U>(Expression<Func<U>> path, Expression<Func<U>> alias, Expression<Func<U,bool>> withClause) + { + return (TReturn)root.JoinAlias(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public TReturn JoinAlias<U>(Expression<Func<U>> path, Expression<Func<U>> alias, Expression<Func<bool>> withClause) + { + return (TReturn)root.JoinAlias(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public TReturn JoinAlias<U>(Expression<Func<U>> path, Expression<Func<U>> alias, ICriterion withClause) + { + return (TReturn)root.JoinAlias(path, alias, joinType, withClause); + } + + public TReturn JoinAlias<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, Expression<Func<U,bool>> withClause) + { + return (TReturn)root.JoinAlias(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public TReturn JoinAlias<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, Expression<Func<bool>> withClause) + { + return (TReturn)root.JoinAlias(path, alias, joinType, ExpressionProcessor.ProcessExpression(withClause)); + } + + public TReturn JoinAlias<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, ICriterion withClause) + { + return (TReturn)root.JoinAlias(path, alias, joinType, withClause); + } + } } Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2011-03-26 18:27:30 UTC (rev 5543) +++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2011-03-26 18:51:53 UTC (rev 5544) @@ -182,6 +182,12 @@ return this; } + private QueryOver<TRoot> ReadOnly() + { + criteria.SetReadOnly(true); + return this; + } + /// <summary> /// Method to allow comparison of detached query in Lambda expression /// e.g., p => p.Name == myQuery.As<string> @@ -251,6 +257,9 @@ IQueryOver<TRoot> IQueryOver<TRoot>.CacheRegion(string cacheRegion) { return CacheRegion(cacheRegion); } + IQueryOver<TRoot> IQueryOver<TRoot>.ReadOnly() + { return ReadOnly(); } + } /// <summary> @@ -499,6 +508,16 @@ joinType)); } + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, U>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause) + { + return new QueryOver<TRoot,U>(impl, + criteria.CreateCriteria( + ExpressionProcessor.FindMemberExpression(path.Body), + ExpressionProcessor.FindMemberExpression(alias.Body), + joinType, + withClause)); + } + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<U>> path, Expression<Func<U>> alias, JoinType joinType) { return new QueryOver<TRoot,U>(impl, @@ -508,6 +527,16 @@ joinType)); } + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<U>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause) + { + return new QueryOver<TRoot,U>(impl, + criteria.CreateCriteria( + ExpressionProcessor.FindMemberExpression(path.Body), + ExpressionProcessor.FindMemberExpression(alias.Body), + joinType, + withClause)); + } + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias) { return new QueryOver<TRoot,U>(impl, @@ -547,6 +576,16 @@ joinType)); } + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause) + { + return new QueryOver<TRoot,U>(impl, + criteria.CreateCriteria( + ExpressionProcessor.FindMemberExpression(path.Body), + ExpressionProcessor.FindMemberExpression(alias.Body), + joinType, + withClause)); + } + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType) { return new QueryOver<TRoot,U>(impl, @@ -556,6 +595,16 @@ joinType)); } + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause) + { + return new QueryOver<TRoot,U>(impl, + criteria.CreateCriteria( + ExpressionProcessor.FindMemberExpression(path.Body), + ExpressionProcessor.FindMemberExpression(alias.Body), + joinType, + withClause)); + } + public QueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path, JoinType joinType) { return new QueryOver<TRoot,U>(impl, @@ -596,6 +645,24 @@ joinType); } + public QueryOver<TRoot,TSubType> JoinAlias<U>(Expression<Func<TSubType, U>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause) + { + return AddAlias( + ExpressionProcessor.FindMemberExpression(path.Body), + ExpressionProcessor.FindMemberExpression(alias.Body), + joinType, + withClause); + } + + public QueryOver<TRoot,TSubType> JoinAlias<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause) + { + return AddAlias( + ExpressionProcessor.FindMemberExpression(path.Body), + ExpressionProcessor.FindMemberExpression(alias.Body), + joinType, + withClause); + } + public QueryOver<TRoot,TSubType> JoinAlias(Expression<Func<object>> path, Expression<Func<object>> alias, JoinType joinType) { return AddAlias( @@ -604,6 +671,24 @@ joinType); } + public QueryOver<TRoot,TSubType> JoinAlias<U>(Expression<Func<U>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause) + { + return AddAlias( + ExpressionProcessor.FindMemberExpression(path.Body), + ExpressionProcessor.FindMemberExpression(alias.Body), + joinType, + withClause); + } + + public QueryOver<TRoot,TSubType> JoinAlias<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause) + { + return AddAlias( + ExpressionProcessor.FindMemberExpression(path.Body), + ExpressionProcessor.FindMemberExpression(alias.Body), + joinType, + withClause); + } + public QueryOverJoinBuilder<TRoot,TSubType> Inner { get { return new QueryOverJoinBuilder<TRoot,TSubType>(this, JoinType.InnerJoin); } @@ -630,6 +715,12 @@ return this; } + private QueryOver<TRoot,TSubType> AddAlias(string path, string alias, JoinType joinType, ICriterion withClause) + { + criteria.CreateAlias(path, alias, joinType, withClause); + return this; + } + private QueryOver<TRoot,TSubType> Add(Expression<Func<TSubType, bool>> expression) { criteria.Add(ExpressionProcessor.ProcessExpression<TSubType>(expression)); @@ -772,9 +863,15 @@ IQueryOver<TRoot,U> IQueryOver<TRoot,TSubType>.JoinQueryOver<U>(Expression<Func<TSubType, U>> path, Expression<Func<U>> alias, JoinType joinType) { return JoinQueryOver(path, alias, joinType); } + IQueryOver<TRoot,U> IQueryOver<TRoot,TSubType>.JoinQueryOver<U>(Expression<Func<TSubType, U>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause) + { return JoinQueryOver(path, alias, joinType, withClause); } + IQueryOver<TRoot,U> IQueryOver<TRoot,TSubType>.JoinQueryOver<U>(Expression<Func<U>> path, Expression<Func<U>> alias, JoinType joinType) { return JoinQueryOver(path, alias, joinType); } + IQueryOver<TRoot,U> IQueryOver<TRoot,TSubType>.JoinQueryOver<U>(Expression<Func<U>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause) + { return JoinQueryOver(path, alias, joinType, withClause); } + IQueryOver<TRoot,U> IQueryOver<TRoot,TSubType>.JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path) { return JoinQueryOver(path); } @@ -796,9 +893,15 @@ IQueryOver<TRoot,U> IQueryOver<TRoot,TSubType>.JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType) { return JoinQueryOver(path, alias, joinType); } + IQueryOver<TRoot,U> IQueryOver<TRoot,TSubType>.JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause) + { return JoinQueryOver(path, alias, joinType, withClause); } + IQueryOver<TRoot,U> IQueryOver<TRoot,TSubType>.JoinQueryOver<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType) { return JoinQueryOver(path, alias, joinType); } + IQueryOver<TRoot,U> IQueryOver<TRoot,TSubType>.JoinQueryOver<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause) + { return JoinQueryOver(path, alias, joinType, withClause); } + IQueryOver<TRoot,TSubType> IQueryOver<TRoot,TSubType>.JoinAlias(Expression<Func<TSubType, object>> path, Expression<Func<object>> alias) { return JoinAlias(path, alias); } @@ -808,9 +911,21 @@ IQueryOver<TRoot,TSubType> IQueryOver<TRoot,TSubType>.JoinAlias(Expression<Func<TSubType, object>> path, Expression<Func<object>> alias, JoinType joinType) { return JoinAlias(path, alias, joinType); } + IQueryOver<TRoot,TSubType> IQueryOver<TRoot,TSubType>.JoinAlias<U>(Expression<Func<TSubType, U>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause) + { return JoinAlias(path, alias, joinType, withClause); } + + IQueryOver<TRoot,TSubType> IQueryOver<TRoot,TSubType>.JoinAlias<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause) + { return JoinAlias(path, alias, joinType, withClause); } + IQueryOver<TRoot,TSubType> IQueryOver<TRoot,TSubType>.JoinAlias(Expression<Func<object>> path, Expression<Func<object>> alias, JoinType joinType) { return JoinAlias(path, alias, joinType); } + IQueryOver<TRoot,TSubType> IQueryOver<TRoot,TSubType>.JoinAlias<U>(Expression<Func<U>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause) + { return JoinAlias(path, alias, joinType, withClause); } + + IQueryOver<TRoot,TSubType> IQueryOver<TRoot,TSubType>.JoinAlias<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause) + { return JoinAlias(path, alias, joinType, withClause); } + IQueryOverJoinBuilder<TRoot,TSubType> IQueryOver<TRoot,TSubType>.Inner { get { return new IQueryOverJoinBuilder<TRoot,TSubType>(this, JoinType.InnerJoin); } } Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2011-03-26 18:27:30 UTC (rev 5543) +++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2011-03-26 18:51:53 UTC (rev 5544) @@ -154,6 +154,12 @@ /// for the default query cache</param> IQueryOver<TRoot> CacheRegion(string cacheRegion); + /// <summary> + /// Set the read-only mode for entities (and proxies) loaded by this QueryOver. + /// (see <see cref="ICriteria.SetReadOnly" />). + /// </summary> + IQueryOver<TRoot> ReadOnly(); + } /// <summary> @@ -431,11 +437,33 @@ /// <param name="path">Lambda expression returning association path</param> /// <param name="alias">Lambda expression returning alias reference</param> /// <param name="joinType">Type of join</param> + /// <param name="withClause">Additional criterion for the SQL on clause</param> /// <returns>The created "sub criteria"</returns> + IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, U>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause); + + /// <summary> + /// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity + /// </summary> + /// <typeparam name="U">Type of sub-criteria</typeparam> + /// <param name="path">Lambda expression returning association path</param> + /// <param name="alias">Lambda expression returning alias reference</param> + /// <param name="joinType">Type of join</param> + /// <returns>The created "sub criteria"</returns> IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<U>> path, Expression<Func<U>> alias, JoinType joinType); /// <summary> /// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity + /// </summary> + /// <typeparam name="U">Type of sub-criteria</typeparam> + /// <param name="path">Lambda expression returning association path</param> + /// <param name="alias">Lambda expression returning alias reference</param> + /// <param name="joinType">Type of join</param> + /// <param name="withClause">Additional criterion for the SQL on clause</param> + /// <returns>The created "sub criteria"</returns> + IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<U>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause); + + /// <summary> + /// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity /// specifying a collection for the join. /// </summary> /// <typeparam name="U">Type of sub-criteria (type of the collection)</typeparam> @@ -511,10 +539,34 @@ /// <param name="path">Lambda expression returning association path</param> /// <param name="alias">Lambda expression returning alias reference</param> /// <param name="joinType">Type of join</param> + /// <param name="withClause">Additional criterion for the SQL on clause</param> /// <returns>The created "sub criteria"</returns> + IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause); + + /// <summary> + /// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity + /// specifying a collection for the join. + /// </summary> + /// <typeparam name="U">Type of sub-criteria (type of the collection)</typeparam> + /// <param name="path">Lambda expression returning association path</param> + /// <param name="alias">Lambda expression returning alias reference</param> + /// <param name="joinType">Type of join</param> + /// <returns>The created "sub criteria"</returns> IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType); /// <summary> + /// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity + /// specifying a collection for the join. + /// </summary> + /// <typeparam name="U">Type of sub-criteria (type of the collection)</typeparam> + /// <param name="path">Lambda expression returning association path</param> + /// <param name="alias">Lambda expression returning alias reference</param> + /// <param name="joinType">Type of join</param> + /// <param name="withClause">Additional criterion for the SQL on clause</param> + /// <returns>The created "sub criteria"</returns> + IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause); + + /// <summary> /// Join an association, assigning an alias to the joined entity /// </summary> /// <param name="path">Lambda expression returning association path</param> @@ -545,9 +597,51 @@ /// <param name="path">Lambda expression returning association path</param> /// <param name="alias">Lambda expression returning alias reference</param> /// <param name="joinType">Type of join</param> + /// <param name="withClause">Additional criterion for the SQL on clause</param> /// <returns>criteria instance</returns> + IQueryOver<TRoot,TSubType> JoinAlias<U>(Expression<Func<TSubType, U>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause); + + /// <summary> + /// Join an association, assigning an alias to the joined entity + /// </summary> + /// <typeparam name="U">Type of sub-criteria (type of the collection)</typeparam> + /// <param name="path">Lambda expression returning association path</param> + /// <param name="alias">Lambda expression returning alias reference</param> + /// <param name="joinType">Type of join</param> + /// <param name="withClause">Additional criterion for the SQL on clause</param> + /// <returns>criteria instance</returns> + IQueryOver<TRoot,TSubType> JoinAlias<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause); + + /// <summary> + /// Join an association, assigning an alias to the joined entity + /// </summary> + /// <param name="path">Lambda expression returning association path</param> + /// <param name="alias">Lambda expression returning alias reference</param> + /// <param name="joinType">Type of join</param> + /// <returns>criteria instance</returns> IQueryOver<TRoot,TSubType> JoinAlias(Expression<Func<object>> path, Expression<Func<object>> alias, JoinType joinType); + /// <summary> + /// Join an association, assigning an alias to the joined entity + /// </summary> + /// <param name="path">Lambda expression returning association path</param> + /// <param name="alias">Lambda expression returning alias reference</param> + /// <param name="joinType">Type of join</param> + /// <param name="withClause">Additional criterion for the SQL on clause</param> + /// <returns>criteria instance</returns> + IQueryOver<TRoot,TSubType> JoinAlias<U>(Expression<Func<U>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause); + + /// <summary> + /// Join an association, assigning an alias to the joined entity + /// </summary> + /// <typeparam name="U">Type of sub-criteria (type of the collection)</typeparam> + /// <param name="path">Lambda expression returning association path</param> + /// <param name="alias">Lambda expression returning alias reference</param> + /// <param name="joinType">Type of join</param> + /// <param name="withClause">Additional criterion for the SQL on clause</param> + /// <returns>criteria instance</returns> + IQueryOver<TRoot,TSubType> JoinAlias<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType, ICriterion withClause); + IQueryOverJoinBuilder<TRoot,TSubType> Inner { get; } IQueryOverJoinBuilder<TRoot,TSubType> Left { get; } IQueryOverJoinBuilder<TRoot,TSubType> Right { get; } Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2011-03-26 18:27:30 UTC (rev 5543) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2011-03-26 18:51:53 UTC (rev 5544) @@ -4,6 +4,7 @@ using System.Linq; using NUnit.Framework; +using SharpTestsEx; using NHibernate.Criterion; using NHibernate.Transform; @@ -181,6 +182,79 @@ } [Test] + public void OnClause() + { + using (ISession s = OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + s.Save(new Person() { Name = "John" } + .AddChild(new Child() { Nickname = "John"}) + .AddChild(new Child() { Nickname = "Judy"})); + + s.Save(new Person() { Name = "Jean" }); + s.Save(new Child() { Nickname = "James" }); + + t.Commit(); + } + + using (ISession s = OpenSession()) + { + Child childAlias = null; + Person parentAlias = null; + var children = + s.QueryOver(() => childAlias) + .Left.JoinQueryOver(c => c.Parent, () => parentAlias, p => p.Name == childAlias.Nickname) + .WhereRestrictionOn(p => p.Name).IsNotNull + .List(); + + children.Should().Have.Count.EqualTo(1); + } + + using (ISession s = OpenSession()) + { + Child childAlias = null; + Person parentAlias = null; + var parentNames = + s.QueryOver<Child>(() => childAlias) + .Left.JoinAlias(c => c.Parent, () => parentAlias, p => p.Name == childAlias.Nickname) + .Select(c => parentAlias.Name) + .List<string>(); + + parentNames + .Where(n => !string.IsNullOrEmpty(n)) + .Should().Have.Count.EqualTo(1); + } + + using (ISession s = OpenSession()) + { + Person personAlias = null; + Child childAlias = null; + var people = + s.QueryOver<Person>(() => personAlias) + .Left.JoinQueryOver(p => p.Children, () => childAlias, c => c.Nickname == personAlias.Name) + .WhereRestrictionOn(c => c.Nickname).IsNotNull + .List(); + + people.Should().Have.Count.EqualTo(1); + } + + using (ISession s = OpenSession()) + { + Person personAlias = null; + Child childAlias = null; + var childNames = + s.QueryOver<Person>(() => personAlias) + .Left.JoinAlias(p => p.Children, () => childAlias, c => c.Nickname == personAlias.Name) + .Select(p => childAlias.Nickname) + .List<string>(); + + childNames + .Where(n => !string.IsNullOrEmpty(n)) + .Should().Have.Count.EqualTo(1); + } + } + + [Test] public void UniqueResult() { using (ISession s = OpenSession()) Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2011-03-26 18:27:30 UTC (rev 5543) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2011-03-26 18:51:53 UTC (rev 5544) @@ -412,6 +412,198 @@ } [Test] + public void OnClause_SubCriteria() + { + ICriteria expected = + CreateTestCriteria(typeof(Person)) + .CreateCriteria("PersonList", "alias1", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "many func t,bool")) + .CreateCriteria("PersonList", "alias2", JoinType.LeftOuterJoin, Restrictions.Eq("alias1.Name", "many func bool")) + .CreateCriteria("PersonList", "alias3", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "many private")) + .CreateCriteria("Father", "alias4", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "one func t,bool")) + .CreateCriteria("Father", "alias5", JoinType.LeftOuterJoin, Restrictions.Eq("alias4.Name", "one func bool")) + .CreateCriteria("Father", "alias6", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "one private")) + .CreateCriteria("alias1.PersonList", "alias7", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "a many func t,bool")) + .CreateCriteria("alias2.PersonList", "alias8", JoinType.LeftOuterJoin, Restrictions.Eq("alias1.Name", "a many func bool")) + .CreateCriteria("alias3.PersonList", "alias9", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "a many private")) + .CreateCriteria("alias4.Father", "alias10", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "a one func t,bool")) + .CreateCriteria("alias5.Father", "alias11", JoinType.LeftOuterJoin, Restrictions.Eq("alias4.Name", "a one func bool")) + .CreateCriteria("alias6.Father", "alias12", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "a one private")); + + Person alias1 = null; + Person alias2 = null; + Person alias3 = null; + Person alias4 = null; + Person alias5 = null; + Person alias6 = null; + Person alias7 = null; + Person alias8 = null; + Person alias9 = null; + Person alias10 = null; + Person alias11 = null; + Person alias12 = null; + IQueryOver<Person> actual = + CreateTestQueryOver<Person>() + .Left.JoinQueryOver(p => p.PersonList, () => alias1, p => p.Name == "many func t,bool") + .Left.JoinQueryOver(p => p.PersonList, () => alias2, () => alias1.Name == "many func bool") + .Left.JoinQueryOver(p => p.PersonList, () => alias3, Restrictions.Eq("Name", "many private")) + .Left.JoinQueryOver(p => p.Father, () => alias4, p => p.Name == "one func t,bool") + .Left.JoinQueryOver(p => p.Father, () => alias5, () => alias4.Name == "one func bool") + .Left.JoinQueryOver(p => p.Father, () => alias6, p => p.Name == "one private") + .Left.JoinQueryOver(() => alias1.PersonList, () => alias7, p => p.Name == "a many func t,bool") + .Left.JoinQueryOver(() => alias2.PersonList, () => alias8, () => alias1.Name == "a many func bool") + .Left.JoinQueryOver(() => alias3.PersonList, () => alias9, Restrictions.Eq("Name", "a many private")) + .Left.JoinQueryOver(() => alias4.Father, () => alias10, p => p.Name == "a one func t,bool") + .Left.JoinQueryOver(() => alias5.Father, () => alias11, () => alias4.Name == "a one func bool") + .Left.JoinQueryOver(() => alias6.Father, () => alias12, p => p.Name == "a one private"); + + AssertCriteriaAreEqual(expected, actual); + } + + [Test] + public void OnClauseDetached_SubCriteria() + { + DetachedCriteria expected = + DetachedCriteria.For<Person>() + .CreateCriteria("PersonList", "alias1", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "many func t,bool")) + .CreateCriteria("PersonList", "alias2", JoinType.LeftOuterJoin, Restrictions.Eq("alias1.Name", "many func bool")) + .CreateCriteria("PersonList", "alias3", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "many private")) + .CreateCriteria("Father", "alias4", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "one func t,bool")) + .CreateCriteria("Father", "alias5", JoinType.LeftOuterJoin, Restrictions.Eq("alias4.Name", "one func bool")) + .CreateCriteria("Father", "alias6", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "one private")) + .CreateCriteria("alias1.PersonList", "alias7", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "a many func t,bool")) + .CreateCriteria("alias2.PersonList", "alias8", JoinType.LeftOuterJoin, Restrictions.Eq("alias1.Name", "a many func bool")) + .CreateCriteria("alias3.PersonList", "alias9", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "a many private")) + .CreateCriteria("alias4.Father", "alias10", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "a one func t,bool")) + .CreateCriteria("alias5.Father", "alias11", JoinType.LeftOuterJoin, Restrictions.Eq("alias4.Name", "a one func bool")) + .CreateCriteria("alias6.Father", "alias12", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "a one private")); + + Person alias1 = null; + Person alias2 = null; + Person alias3 = null; + Person alias4 = null; + Person alias5 = null; + Person alias6 = null; + Person alias7 = null; + Person alias8 = null; + Person alias9 = null; + Person alias10 = null; + Person alias11 = null; + Person alias12 = null; + QueryOver<Person> actual = + QueryOver.Of<Person>() + .Left.JoinQueryOver(p => p.PersonList, () => alias1, p => p.Name == "many func t,bool") + .Left.JoinQueryOver(p => p.PersonList, () => alias2, () => alias1.Name == "many func bool") + .Left.JoinQueryOver(p => p.PersonList, () => alias3, Restrictions.Eq("Name", "many private")) + .Left.JoinQueryOver(p => p.Father, () => alias4, p => p.Name == "one func t,bool") + .Left.JoinQueryOver(p => p.Father, () => alias5, () => alias4.Name == "one func bool") + .Left.JoinQueryOver(p => p.Father, () => alias6, p => p.Name == "one private") + .Left.JoinQueryOver(() => alias1.PersonList, () => alias7, p => p.Name == "a many func t,bool") + .Left.JoinQueryOver(() => alias2.PersonList, () => alias8, () => alias1.Name == "a many func bool") + .Left.JoinQueryOver(() => alias3.PersonList, () => alias9, Restrictions.Eq("Name", "a many private")) + .Left.JoinQueryOver(() => alias4.Father, () => alias10, p => p.Name == "a one func t,bool") + .Left.JoinQueryOver(() => alias5.Father, () => alias11, () => alias4.Name == "a one func bool") + .Left.JoinQueryOver(() => alias6.Father, () => alias12, p => p.Name == "a one private"); + + AssertCriteriaAreEqual(expected, actual); + } + + [Test] + public void OnClause_Alias() + { + ICriteria expected = + CreateTestCriteria(typeof(Person)) + .CreateAlias("PersonList", "alias1", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "many func t,bool")) + .CreateAlias("PersonList", "alias2", JoinType.LeftOuterJoin, Restrictions.Eq("alias1.Name", "many func bool")) + .CreateAlias("PersonList", "alias3", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "many private")) + .CreateAlias("Father", "alias4", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "one func t,bool")) + .CreateAlias("Father", "alias5", JoinType.LeftOuterJoin, Restrictions.Eq("alias4.Name", "one func bool")) + .CreateAlias("Father", "alias6", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "one private")) + .CreateAlias("alias1.PersonList", "alias7", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "a many func t,bool")) + .CreateAlias("alias2.PersonList", "alias8", JoinType.LeftOuterJoin, Restrictions.Eq("alias1.Name", "a many func bool")) + .CreateAlias("alias3.PersonList", "alias9", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "a many private")) + .CreateAlias("alias4.Father", "alias10", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "a one func t,bool")) + .CreateAlias("alias5.Father", "alias11", JoinType.LeftOuterJoin, Restrictions.Eq("alias4.Name", "a one func bool")) + .CreateAlias("alias6.Father", "alias12", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "a one private")); + + Person alias1 = null; + Person alias2 = null; + Person alias3 = null; + Person alias4 = null; + Person alias5 = null; + Person alias6 = null; + Person alias7 = null; + Person alias8 = null; + Person alias9 = null; + Person alias10 = null; + Person alias11 = null; + Person alias12 = null; + IQueryOver<Person> actual = + CreateTestQueryOver<Person>() + .Left.JoinAlias(p => p.PersonList, () => alias1, p => p.Name == "many func t,bool") + .Left.JoinAlias(p => p.PersonList, () => alias2, () => alias1.Name == "many func bool") + .Left.JoinAlias(p => p.PersonList, () => alias3, Restrictions.Eq("Name", "many private")) + .Left.JoinAlias(p => p.Father, () => alias4, p => p.Name == "one func t,bool") + .Left.JoinAlias(p => p.Father, () => alias5, () => alias4.Name == "one func bool") + .Left.JoinAlias(p => p.Father, () => alias6, p => p.Name == "one private") + .Left.JoinAlias(() => alias1.PersonList, () => alias7, p => p.Name == "a many func t,bool") + .Left.JoinAlias(() => alias2.PersonList, () => alias8, () => alias1.Name == "a many func bool") + .Left.JoinAlias(() => alias3.PersonList, () => alias9, Restrictions.Eq("Name", "a many private")) + .Left.JoinAlias(() => alias4.Father, () => alias10, p => p.Name == "a one func t,bool") + .Left.JoinAlias(() => alias5.Father, () => alias11, () => alias4.Name == "a one func bool") + .Left.JoinAlias(() => alias6.Father, () => alias12, p => p.Name == "a one private"); + + AssertCriteriaAreEqual(expected, actual); + } + + [Test] + public void OnClauseDetached_Alias() + { + DetachedCriteria expected = + DetachedCriteria.For<Person>() + .CreateAlias("PersonList", "alias1", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "many func t,bool")) + .CreateAlias("PersonList", "alias2", JoinType.LeftOuterJoin, Restrictions.Eq("alias1.Name", "many func bool")) + .CreateAlias("PersonList", "alias3", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "many private")) + .CreateAlias("Father", "alias4", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "one func t,bool")) + .CreateAlias("Father", "alias5", JoinType.LeftOuterJoin, Restrictions.Eq("alias4.Name", "one func bool")) + .CreateAlias("Father", "alias6", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "one private")) + .CreateAlias("alias1.PersonList", "alias7", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "a many func t,bool")) + .CreateAlias("alias2.PersonList", "alias8", JoinType.LeftOuterJoin, Restrictions.Eq("alias1.Name", "a many func bool")) + .CreateAlias("alias3.PersonList", "alias9", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "a many private")) + .CreateAlias("alias4.Father", "alias10", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "a one func t,bool")) + .CreateAlias("alias5.Father", "alias11", JoinType.LeftOuterJoin, Restrictions.Eq("alias4.Name", "a one func bool")) + .CreateAlias("alias6.Father", "alias12", JoinType.LeftOuterJoin, Restrictions.Eq("Name", "a one private")); + + Person alias1 = null; + Person alias2 = null; + Person alias3 = null; + Person alias4 = null; + Person alias5 = null; + Person alias6 = null; + Person alias7 = null; + Person alias8 = null; + Person alias9 = null; + Person alias10 = null; + Person alias11 = null; + Person alias12 = null; + QueryOver<Person> actual = + QueryOver.Of<Person>() + .Left.JoinAlias(p => p.PersonList, () => alias1, p => p.Name == "many func t,bool") + .Left.JoinAlias(p => p.PersonList, () => alias2, () => alias1.Name == "many func bool") + .Left.JoinAlias(p => p.PersonList, () => alias3, Restrictions.Eq("Name", "many private")) + .Left.JoinAlias(p => p.Father, () => alias4, p => p.Name == "one func t,bool") + .Left.JoinAlias(p => p.Father, () => alias5, () => alias4.Name == "one func bool") + .Left.JoinAlias(p => p.Father, () => alias6, p => p.Name == "one private") + .Left.JoinAlias(() => alias1.PersonList, () => alias7, p => p.Name == "a many func t,bool") + .Left.JoinAlias(() => alias2.PersonList, () => alias8, () => alias1.Name == "a many func bool") + .Left.JoinAlias(() => alias3.PersonList, () => alias9, Restrictions.Eq("Name", "a many private")) + .Left.JoinAlias(() => alias4.Father, () => alias10, p => p.Name == "a one func t,bool") + .Left.JoinAlias(() => alias5.Father, () => alias11, () => alias4.Name == "a one func bool") + .Left.JoinAlias(() => alias6.Father, () => alias12, p => p.Name == "a one private"); + + AssertCriteriaAreEqual(expected, actual); + } + + [Test] public void OrderBy() { ICriteria expected = @@ -571,6 +763,20 @@ } [Test] + public void Readonly() + { + ICriteria expected = + CreateTestCriteria(typeof(Person)) + .SetReadOnly(true); + + IQueryOver<Person> actual = + CreateTestQueryOver<Person>() + .ReadOnly(); + + AssertCriteriaAreEqual(expected, actual); + } + + [Test] public void DetachedQueryOver() { DetachedCriteria expected = This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2011-03-27 05:11:06
|
Revision: 5548 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5548&view=rev Author: patearl Date: 2011-03-27 05:10:59 +0000 (Sun, 27 Mar 2011) Log Message: ----------- SQLite: Support non-repeating identity sequences. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs trunk/nhibernate/src/NHibernate/Mapping/Table.cs Modified: trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs 2011-03-27 02:18:06 UTC (rev 5547) +++ trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs 2011-03-27 05:10:59 UTC (rev 5548) @@ -1187,6 +1187,16 @@ { get { throw new MappingException("Dialect does not support identity key generation"); } } + + /// <summary> + /// Set this to false if no table-level primary key constraint should be generated when an identity column has been specified for the table. + /// This is used as a work-around for SQLite so it doesn't tell us we have "more than one primary key". + /// </summary> + public virtual bool GenerateTablePrimaryKeyConstraintForIdentityColumn + { + get { return true; } + } + #endregion #region SEQUENCE support Modified: trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs 2011-03-27 02:18:06 UTC (rev 5547) +++ trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs 2011-03-27 05:10:59 UTC (rev 5548) @@ -154,13 +154,20 @@ { get { - // identity columns in sqlite are marked as being integer primary key - // the primary key part will be put in at the end of the create table, - // so just the integer part is needed here - return "integer"; + // Adding the "autoincrement" keyword ensures that the same id will + // not be generated twice. When just utilizing "integer primary key", + // SQLite just takes the max value currently in the table and adds one. + // This causes problems with caches that use primary keys of deleted + // entities. + return "integer primary key autoincrement"; } } + public override bool GenerateTablePrimaryKeyConstraintForIdentityColumn + { + get { return false; } + } + public override string Qualify(string catalog, string schema, string table) { StringBuilder qualifiedName = new StringBuilder(); Modified: trunk/nhibernate/src/NHibernate/Mapping/Table.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/Table.cs 2011-03-27 02:18:06 UTC (rev 5547) +++ trunk/nhibernate/src/NHibernate/Mapping/Table.cs 2011-03-27 05:10:59 UTC (rev 5548) @@ -409,7 +409,7 @@ buf.Append(dialect.GetColumnComment(col.Comment)); } } - if (HasPrimaryKey) + if (HasPrimaryKey && (dialect.GenerateTablePrimaryKeyConstraintForIdentityColumn || !identityColumn)) { buf.Append(StringHelper.CommaSpace).Append(PrimaryKey.SqlConstraintString(dialect, defaultSchema)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2011-03-27 16:59:13
|
Revision: 5552 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5552&view=rev Author: patearl Date: 2011-03-27 16:59:07 +0000 (Sun, 27 Mar 2011) Log Message: ----------- Dialect: Removed meaningless HasAlterTable property. Improved the names and functionality of some other recently added properties. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2011-03-27 05:31:22 UTC (rev 5551) +++ trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2011-03-27 16:59:07 UTC (rev 5552) @@ -813,8 +813,8 @@ var script = new List<string>(); - if (!string.IsNullOrEmpty(dialect.BeforeDropSchemaCommand)) - script.Add(dialect.BeforeDropSchemaCommand); + if (!dialect.SupportsForeignKeyConstraintInAlterTable && !string.IsNullOrEmpty(dialect.DisableForeignKeyConstraintsString)) + script.Add(dialect.DisableForeignKeyConstraintsString); // drop them in reverse order in case db needs it done that way...);); for (int i = auxiliaryDatabaseObjects.Count - 1; i >= 0; i--) @@ -864,8 +864,8 @@ } } - if (!string.IsNullOrEmpty(dialect.AfterDropSchemaCommand)) - script.Add(dialect.AfterDropSchemaCommand); + if (!dialect.SupportsForeignKeyConstraintInAlterTable && !string.IsNullOrEmpty(dialect.EnableForeignKeyConstraintsString)) + script.Add(dialect.EnableForeignKeyConstraintsString); return script.ToArray(); } Modified: trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs 2011-03-27 05:31:22 UTC (rev 5551) +++ trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs 2011-03-27 16:59:07 UTC (rev 5552) @@ -584,14 +584,6 @@ #region DDL support /// <summary> - /// Does this dialect support the <c>ALTER TABLE</c> syntax? - /// </summary> - public virtual bool HasAlterTable - { - get { return true; } - } - - /// <summary> /// Do we need to drop constraints before dropping tables in the dialect? /// </summary> public virtual bool DropConstraints @@ -626,11 +618,11 @@ /// </summary> public virtual bool SupportsForeignKeyConstraintInAlterTable { - get { return HasAlterTable; } + get { return true; } } /// <summary> - /// The syntax used to add a foreign key constraint to a table. + /// The syntax used to add a foreign key constraint to a table. If SupportsForeignKeyConstraintInAlterTable is false, the returned string will be added to the create table statement instead. In this case, extra strings, like "add", that apply when using alter table should be omitted. /// </summary> /// <param name="constraintName">The FK constraint name. </param> /// <param name="foreignKey">The names of the columns comprising the FK </param> @@ -2427,12 +2419,18 @@ return false; } - public virtual string BeforeDropSchemaCommand + /// <summary> + /// Only needed if the Dialect does not have SupportsForeignKeyConstraintInAlterTable. + /// </summary> + public virtual string DisableForeignKeyConstraintsString { get { return null; } } - public virtual string AfterDropSchemaCommand + /// <summary> + /// Only needed if the Dialect does not have SupportsForeignKeyConstraintInAlterTable. + /// </summary> + public virtual string EnableForeignKeyConstraintsString { get { return null; } } Modified: trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs 2011-03-27 05:31:22 UTC (rev 5551) +++ trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs 2011-03-27 16:59:07 UTC (rev 5552) @@ -124,11 +124,6 @@ get { return true; } } - public override bool HasAlterTable - { - get { return false; } - } - public override bool DropConstraints { get { return false; } @@ -293,17 +288,23 @@ /// If there are cycles between tables, it would even be excessively difficult to delete /// the data in the right order first. Because of this, we just turn off the foreign /// constraints before we drop the schema and hope that we're not going to break anything. :( + /// We could theoretically check for data consistency afterwards, but we don't currently. /// </summary> - public override string BeforeDropSchemaCommand + public override string DisableForeignKeyConstraintsString { get { return "PRAGMA foreign_keys = OFF"; } } - public override string AfterDropSchemaCommand + public override string EnableForeignKeyConstraintsString { get { return "PRAGMA foreign_keys = ON"; } } + public override bool SupportsForeignKeyConstraintInAlterTable + { + get { return false; } + } + [Serializable] protected class SQLiteCastFunction : CastFunction { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2011-03-27 17:34:32
|
Revision: 5553 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5553&view=rev Author: patearl Date: 2011-03-27 17:34:26 +0000 (Sun, 27 Mar 2011) Log Message: ----------- PostgreSQL: Added support for database GUID generation. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/PostgreSQLDialect.cs trunk/nhibernate/src/NHibernate.TestDatabaseSetup/TestDatabaseSetup.cs Modified: trunk/nhibernate/src/NHibernate/Dialect/PostgreSQLDialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/PostgreSQLDialect.cs 2011-03-27 16:59:07 UTC (rev 5552) +++ trunk/nhibernate/src/NHibernate/Dialect/PostgreSQLDialect.cs 2011-03-27 17:34:26 UTC (rev 5553) @@ -211,5 +211,10 @@ { return value ? "TRUE" : "FALSE"; } + + public override string SelectGUIDString + { + get { return "select uuid_generate_v4()"; } + } } } Modified: trunk/nhibernate/src/NHibernate.TestDatabaseSetup/TestDatabaseSetup.cs =================================================================== --- trunk/nhibernate/src/NHibernate.TestDatabaseSetup/TestDatabaseSetup.cs 2011-03-27 16:59:07 UTC (rev 5552) +++ trunk/nhibernate/src/NHibernate.TestDatabaseSetup/TestDatabaseSetup.cs 2011-03-27 17:34:26 UTC (rev 5553) @@ -103,6 +103,23 @@ cmd.ExecuteNonQuery(); } } + + // Install the GUID generator function that uses the most common "random" algorithm. + using (var conn = new NpgsqlConnection(connStr)) + { + conn.Open(); + + using (var cmd = conn.CreateCommand()) + { + cmd.CommandText = + @"CREATE OR REPLACE FUNCTION uuid_generate_v4() + RETURNS uuid + AS '$libdir/uuid-ossp', 'uuid_generate_v4' + VOLATILE STRICT LANGUAGE C;"; + + cmd.ExecuteNonQuery(); + } + } } private static void SetupSQLite(Cfg.Configuration cfg) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-03-27 19:31:29
|
Revision: 5554 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5554&view=rev Author: fabiomaulo Date: 2011-03-27 19:31:22 +0000 (Sun, 27 Mar 2011) Log Message: ----------- Partial fix of NH-1747 and commented the full fix Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs trunk/nhibernate/src/NHibernate/Loader/Collection/OneToManyJoinWalker.cs trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs trunk/nhibernate/src/NHibernate/Persister/Collection/OneToManyPersister.cs trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1747/Fixture.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs 2011-03-27 17:34:26 UTC (rev 5553) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs 2011-03-27 19:31:22 UTC (rev 5554) @@ -712,6 +712,18 @@ throw new MappingException("Association references unmapped class: " + associatedEntityName); oneToMany.AssociatedClass = persistentClass; model.CollectionTable = persistentClass.Table; + if (model.IsInverse && persistentClass.JoinClosureSpan > 0) + { + // NH: bidirectional one-to-many with a class splitted in more tables; have to find in which table is the inverse side + foreach (var joined in persistentClass.JoinClosureIterator) + { + if (collectionMapping.Key.Columns.Select(x=> x.name).All(x => joined.Table.ColumnIterator.Select(jc=> jc.Name).Contains(x))) + { + model.CollectionTable = joined.Table; + break; + } + } + } if (log.IsInfoEnabled) log.Info("mapping collection: " + model.Role + " -> " + model.CollectionTable.Name); Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/OneToManyJoinWalker.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/OneToManyJoinWalker.cs 2011-03-27 17:34:26 UTC (rev 5553) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/OneToManyJoinWalker.cs 2011-03-27 19:31:22 UTC (rev 5554) @@ -13,6 +13,7 @@ /// <seealso cref="OneToManyLoader" /> public class OneToManyJoinWalker : CollectionJoinWalker { + private readonly IOuterJoinLoadable elementPersister; private readonly IQueryableCollection oneToManyPersister; protected override bool IsDuplicateAssociation(string foreignKeyTable, string[] foreignKeyColumns) @@ -28,7 +29,7 @@ : base(factory, enabledFilters) { this.oneToManyPersister = oneToManyPersister; - IOuterJoinLoadable elementPersister = (IOuterJoinLoadable) oneToManyPersister.ElementPersister; + elementPersister = (IOuterJoinLoadable)oneToManyPersister.ElementPersister; string alias = GenerateRootAlias(oneToManyPersister.Role); WalkEntityTree(elementPersister, alias); @@ -42,6 +43,12 @@ InitStatementString(elementPersister, alias, batchSize, subquery); } + // NH-1747 FIX + //protected override string GenerateAliasForColumn(string rootAlias, string column) + //{ + // return elementPersister.GenerateTableAliasForColumn(rootAlias, column); + //} + private void InitStatementString(IOuterJoinLoadable elementPersister, string alias, int batchSize, SqlString subquery) { int joins = CountEntityPersisters(associations); Modified: trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs 2011-03-27 17:34:26 UTC (rev 5553) +++ trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs 2011-03-27 19:31:22 UTC (rev 5554) @@ -1752,6 +1752,11 @@ get { return keyColumnNames; } } + protected string[] KeyColumnAliases + { + get { return keyColumnAliases; } + } + public bool IsLazy { get { return isLazy; } Modified: trunk/nhibernate/src/NHibernate/Persister/Collection/OneToManyPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Collection/OneToManyPersister.cs 2011-03-27 17:34:26 UTC (rev 5553) +++ trunk/nhibernate/src/NHibernate/Persister/Collection/OneToManyPersister.cs 2011-03-27 19:31:22 UTC (rev 5554) @@ -321,6 +321,22 @@ .ToString(); } + // NH-1747 FIX + //protected override SelectFragment GenerateSelectFragment(string alias, string columnSuffix) + //{ + // var ojl = (IOuterJoinLoadable)ElementPersister; + // var selectFragment = new SelectFragment(Dialect).SetSuffix(columnSuffix); + // var columnNames = KeyColumnNames; + // var columnAliases = KeyColumnAliases; + // for (int i = 0; i < columnNames.Length; i++) + // { + // var column = columnNames[i]; + // var tableAlias = ojl.GenerateTableAliasForColumn(alias, column); + // selectFragment.AddColumn(tableAlias, column, columnAliases[i]); + // } + // return selectFragment; + //} + /// <summary> /// Create the <see cref="OneToManyLoader" /> /// </summary> Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2011-03-27 17:34:26 UTC (rev 5553) +++ trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2011-03-27 19:31:22 UTC (rev 5554) @@ -1817,7 +1817,7 @@ } } - public string GenerateTableAliasForColumn(string rootAlias, string column) + public virtual string GenerateTableAliasForColumn(string rootAlias, string column) { int propertyIndex = Array.IndexOf(SubclassColumnClosure, column); Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1747/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1747/Fixture.cs 2011-03-27 17:34:26 UTC (rev 5553) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1747/Fixture.cs 2011-03-27 19:31:22 UTC (rev 5554) @@ -2,7 +2,7 @@ namespace NHibernate.Test.NHSpecificTest.NH1747 { - [TestFixture,Ignore] + [TestFixture] public class JoinTraversalTest : BugTestCase { [Test] @@ -43,14 +43,13 @@ } } - [Test] + [Test, Ignore("The fix was commented in the code. Look for NH-1747")] public void TraversingBagToJoinChildElementShouldWork() { using (ISession session = OpenSession()) { var paymentBatch = session.Get<PaymentBatch>(3); Assert.AreEqual(1, paymentBatch.Payments.Count); - } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-03-27 20:44:44
|
Revision: 5555 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5555&view=rev Author: fabiomaulo Date: 2011-03-27 20:44:38 +0000 (Sun, 27 Mar 2011) Log Message: ----------- Fix NH-2603 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2603/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2603/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2603/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2603/Model.cs Modified: trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs 2011-03-27 19:31:22 UTC (rev 5554) +++ trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs 2011-03-27 20:44:38 UTC (rev 5555) @@ -844,11 +844,9 @@ private SqlString GenerateSelectSizeString(ISessionImplementor sessionImplementor) { - string selectValue = isCollectionIntegerIndex - ? "max(" + IndexColumnNames[0] + ") + 1" - : "count(" + ElementColumnNames[0] + ")"; //sets, maps, bags + string selectValue = GetCountSqlSelectClause(); - return new SqlSimpleSelectBuilder(dialect, factory) + return new SqlSimpleSelectBuilder(dialect, factory) .SetTableName(TableName) .AddWhereFragment(KeyColumnNames, KeyType, "=") .AddColumn(selectValue) @@ -856,6 +854,20 @@ .Append(FilterFragment(TableName, sessionImplementor.EnabledFilters)); } + protected virtual string GetCountSqlSelectClause() + { + // NH: too many "if" when each collection can have its persister + return isCollectionIntegerIndex + ? (string.Format("max({0}) + 1", IndexColumnNames[0])) + : (HasIndex ? string.Format("count({0})", GetIndexCountExpression()) : string.Format("count({0})", ElementColumnNames[0])); + } + + private string GetIndexCountExpression() + { + // when the index has at least one column then use that column to perform the count, otherwise it will use the formula. + return IndexColumnNames[0] ?? IndexFormulas[0]; + } + private SqlString GenerateDetectRowByIndexString() { if (!hasIndex) Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2603/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2603/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2603/Fixture.cs 2011-03-27 20:44:38 UTC (rev 5555) @@ -0,0 +1,138 @@ +using System; +using System.Collections.Generic; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.NHSpecificTest.NH2603 +{ + public class Fixture : BugTestCase + { + #region Scenarios + + private class ListScenario : IDisposable + { + private readonly ISessionFactory factory; + + public ListScenario(ISessionFactory factory) + { + this.factory = factory; + using (ISession s = factory.OpenSession()) + { + using (ITransaction t = s.BeginTransaction()) + { + var entity = new Parent(); + var child = new Child(); + entity.ListChildren = new List<Child> {null, child, null}; + s.Save(entity); + t.Commit(); + } + } + } + + public void Dispose() + { + using (ISession s = factory.OpenSession()) + { + using (ITransaction t = s.BeginTransaction()) + { + s.Delete("from Parent"); + s.Delete("from Child"); + t.Commit(); + } + } + } + } + + private class MapScenario : IDisposable + { + private readonly ISessionFactory factory; + + public MapScenario(ISessionFactory factory) + { + this.factory = factory; + using (ISession s = factory.OpenSession()) + { + using (ITransaction t = s.BeginTransaction()) + { + var entity = new Parent(); + entity.MapChildren = new Dictionary<int, Child> + { + {0, null}, + {1, new Child()}, + {2, null}, + }; + s.Save(entity); + t.Commit(); + } + } + } + + public void Dispose() + { + using (ISession s = factory.OpenSession()) + { + using (ITransaction t = s.BeginTransaction()) + { + s.Delete("from Parent"); + s.Delete("from Child"); + t.Commit(); + } + } + } + } + + #endregion + + [Test] + public void List() + { + using (new ListScenario(Sfi)) + { + // by design NH will clean null elements at the end of the List since 'null' and 'no element' mean the same. + // the effective ammount store will be 1(one) because ther is only one valid element but whem we initialize the collection + // it will have 2 elements (the first with null) + using (ISession s = OpenSession()) + { + using (ITransaction t = s.BeginTransaction()) + { + var entity = s.CreateQuery("from Parent").UniqueResult<Parent>(); + IList<object[]> members = s.GetNamedQuery("ListMemberSpy") + .SetParameter("parentid", entity.Id) + .List<object[]>(); + int lazyCount = entity.ListChildren.Count; + NHibernateUtil.IsInitialized(entity.ListChildren).Should().Be.False(); + NHibernateUtil.Initialize(entity.ListChildren); + int initCount = entity.ListChildren.Count; + initCount.Should().Be.EqualTo(lazyCount); + members.Count.Should("because only the valid element should be persisted.").Be(1); + } + } + } + } + + [Test] + public void Map() + { + using (new MapScenario(Sfi)) + { + using (ISession s = OpenSession()) + { + // for the case of <map> what really matter is the key, then NH should count the KEY and not the elements. + using (ITransaction t = s.BeginTransaction()) + { + var entity = s.CreateQuery("from Parent").UniqueResult<Parent>(); + IList<object[]> members = s.GetNamedQuery("MapMemberSpy") + .SetParameter("parentid", entity.Id) + .List<object[]>(); + int lazyCount = entity.MapChildren.Count; + NHibernateUtil.IsInitialized(entity.MapChildren).Should().Be.False(); + NHibernateUtil.Initialize(entity.MapChildren); + int initCount = entity.MapChildren.Count; + initCount.Should().Be.EqualTo(lazyCount); + members.Count.Should("because all elements with a valid key should be persisted.").Be(3); + } + } + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2603/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2603/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2603/Mappings.hbm.xml 2011-03-27 20:44:38 UTC (rev 5555) @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.NH2603" + assembly="NHibernate.Test" +> + <class name="Parent" > + <id name="Id"> + <generator class="increment"/> + </id> + <list name="ListChildren" lazy="extra" cascade="all" table="ListChildren"> + <key column="listparentid"/> + <!-- sqlite doesn't like a column named index --> + <index column="childindex"/> + <many-to-many class="Child" column="childid"/> + </list> + <map name="MapChildren" lazy="extra" cascade="all" table="MapChildren"> + <key column="mapparentid" /> + <map-key column="childindex" type="int" /> + <many-to-many class="Child"> + <column name="childid" not-null="false" /> + </many-to-many> + </map> + </class> + + <class name="Child"> + <id name="Id"> + <generator class="increment"/> + </id> + </class> + + <sql-query name="ListMemberSpy"> + select listparentid, childindex, childid + from ListChildren + where listparentid = :parentid + </sql-query> + + <sql-query name="MapMemberSpy"> + select mapparentid, childindex, childid + from MapChildren + where mapparentid = :parentid + </sql-query> + +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2603/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2603/Model.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2603/Model.cs 2011-03-27 20:44:38 UTC (rev 5555) @@ -0,0 +1,34 @@ +using System.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.NH2603 +{ + public class Parent + { + public virtual int Id + { + get; + set; + } + + public virtual IList<Child> ListChildren + { + get; + set; + } + + public virtual IDictionary<int, Child> MapChildren + { + get; + set; + } + } + + public class Child + { + public virtual int Id + { + get; + set; + } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-03-27 19:31:22 UTC (rev 5554) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-03-27 20:44:38 UTC (rev 5555) @@ -670,6 +670,8 @@ <Compile Include="NHSpecificTest\NH2565\Domain.cs" /> <Compile Include="NHSpecificTest\NH2565\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2580\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2603\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2603\Model.cs" /> <Compile Include="NHSpecificTest\Properties\CompositePropertyRefTest.cs" /> <Compile Include="NHSpecificTest\Properties\DynamicEntityTest.cs" /> <Compile Include="NHSpecificTest\Properties\Model.cs" /> @@ -2496,6 +2498,7 @@ <EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="NHSpecificTest\NH2603\Mappings.hbm.xml" /> <EmbeddedResource Include="Subselect\Beings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2488\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2490\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2011-03-28 01:28:47
|
Revision: 5556 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5556&view=rev Author: patearl Date: 2011-03-28 01:28:41 +0000 (Mon, 28 Mar 2011) Log Message: ----------- Dialect support for specifying technique to retrieve identifiers generated by insert statements. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs trunk/nhibernate/src/NHibernate/Dialect/PostgreSQLDialect.cs trunk/nhibernate/src/NHibernate/Id/Insert/OutputParamReturningDelegate.cs Modified: trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs 2011-03-27 20:44:38 UTC (rev 5555) +++ trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs 2011-03-28 01:28:41 UTC (rev 5556) @@ -2375,6 +2375,11 @@ return insertString; } + public virtual InsertGeneratedIdentifierRetrievalMethod InsertGeneratedIdentifierRetrievalMethod + { + get { return InsertGeneratedIdentifierRetrievalMethod.ReturnValueParameter; } + } + /// <summary> /// The class (which implements <see cref="NHibernate.Id.IIdentifierGenerator"/>) /// which acts as this dialects identity-style generation strategy. @@ -2435,4 +2440,22 @@ get { return null; } } } + + public enum InsertGeneratedIdentifierRetrievalMethod + { + /// <summary> + /// Use a parameter with ParameterDirection.Output + /// </summary> + OutputParameter, + + /// <summary> + /// Use a parameter with ParameterDirection.ReturnValue + /// </summary> + ReturnValueParameter, + + // <summary> + // Get the result from the statment as if it were a query, using ExecuteScalar() or ExecuteDataReader(). + // </summary> + // QueryResult + } } Modified: trunk/nhibernate/src/NHibernate/Dialect/PostgreSQLDialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/PostgreSQLDialect.cs 2011-03-27 20:44:38 UTC (rev 5555) +++ trunk/nhibernate/src/NHibernate/Dialect/PostgreSQLDialect.cs 2011-03-28 01:28:41 UTC (rev 5556) @@ -111,6 +111,11 @@ return insertString.Append(" returning " + identifierColumnName); } + public override InsertGeneratedIdentifierRetrievalMethod InsertGeneratedIdentifierRetrievalMethod + { + get { return InsertGeneratedIdentifierRetrievalMethod.OutputParameter; } + } + public override bool SupportsSequences { get { return true; } Modified: trunk/nhibernate/src/NHibernate/Id/Insert/OutputParamReturningDelegate.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Id/Insert/OutputParamReturningDelegate.cs 2011-03-27 20:44:38 UTC (rev 5555) +++ trunk/nhibernate/src/NHibernate/Id/Insert/OutputParamReturningDelegate.cs 2011-03-28 01:28:41 UTC (rev 5556) @@ -1,4 +1,5 @@ using System.Data; +using NHibernate.Dialect; using NHibernate.Engine; using NHibernate.SqlCommand; using NHibernate.SqlTypes; @@ -45,8 +46,14 @@ IDbDataParameter idParameter = factory.ConnectionProvider.Driver.GenerateParameter(command, ReturnParameterName, paramType); driveGeneratedParamName = idParameter.ParameterName; - idParameter.Direction = ParameterDirection.ReturnValue; + if (factory.Dialect.InsertGeneratedIdentifierRetrievalMethod == InsertGeneratedIdentifierRetrievalMethod.OutputParameter) + idParameter.Direction = ParameterDirection.Output; + else if (factory.Dialect.InsertGeneratedIdentifierRetrievalMethod == InsertGeneratedIdentifierRetrievalMethod.ReturnValueParameter) + idParameter.Direction = ParameterDirection.ReturnValue; + else + throw new System.NotImplementedException("Unsupported InsertGeneratedIdentifierRetrievalMethod: " + factory.Dialect.InsertGeneratedIdentifierRetrievalMethod); + command.Parameters.Add(idParameter); return command; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2011-03-28 02:39:55
|
Revision: 5558 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5558&view=rev Author: patearl Date: 2011-03-28 02:39:49 +0000 (Mon, 28 Mar 2011) Log Message: ----------- Provide a convenience method for getting dialect-derived properties of configuration. Use derived properties for Linq tests. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs trunk/nhibernate/src/NHibernate/Cfg/SettingsFactory.cs trunk/nhibernate/src/NHibernate.Test/Linq/LinqReadonlyTestsContext.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2011-03-28 02:32:55 UTC (rev 5557) +++ trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2011-03-28 02:39:49 UTC (rev 5558) @@ -1276,6 +1276,27 @@ set { properties = value; } } + /// <summary> + /// Returns the set of properties computed from the default properties in the dialect combined with the other properties in the configuration. + /// </summary> + /// <returns></returns> + public IDictionary<string, string> GetDerivedProperties() + { + IDictionary<string, string> derivedProperties = new Dictionary<string, string>(); + + if (Properties.ContainsKey(Environment.Dialect)) + { + Dialect.Dialect dialect = Dialect.Dialect.GetDialect(Properties); + foreach (KeyValuePair<string, string> pair in dialect.DefaultProperties) + derivedProperties[pair.Key] = pair.Value; + } + + foreach (KeyValuePair<string, string> pair in Properties) + derivedProperties[pair.Key] = pair.Value; + + return derivedProperties; + } + /// <summary> /// Set the default assembly to use for the mappings added to the configuration /// afterwards. @@ -1692,7 +1713,7 @@ //protected Settings BuildSettings() private Settings BuildSettings() { - var result = settingsFactory.BuildSettings(properties); + var result = settingsFactory.BuildSettings(GetDerivedProperties()); // NH : Set configuration for IdGenerator SQL logging PersistentIdGeneratorParmsNames.SqlStatementLogger.FormatSql = result.SqlStatementLogger.FormatSql; PersistentIdGeneratorParmsNames.SqlStatementLogger.LogToStdout = result.SqlStatementLogger.LogToStdout; Modified: trunk/nhibernate/src/NHibernate/Cfg/SettingsFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/SettingsFactory.cs 2011-03-28 02:32:55 UTC (rev 5557) +++ trunk/nhibernate/src/NHibernate/Cfg/SettingsFactory.cs 2011-03-28 02:39:49 UTC (rev 5558) @@ -29,28 +29,15 @@ { Settings settings = new Settings(); - Dialect.Dialect dialect; try { - dialect = Dialect.Dialect.GetDialect(properties); - Dictionary<string, string> temp = new Dictionary<string, string>(); - - foreach (KeyValuePair<string, string> de in dialect.DefaultProperties) - { - temp[de.Key] = de.Value; - } - foreach (KeyValuePair<string, string> de in properties) - { - temp[de.Key] = de.Value; - } - properties = temp; + settings.Dialect = Dialect.Dialect.GetDialect(properties); } catch (HibernateException he) { log.Warn("No dialect set - using GenericDialect: " + he.Message); - dialect = new GenericDialect(); + settings.Dialect = new GenericDialect(); } - settings.Dialect = dialect; settings.LinqToHqlGeneratorsRegistry = LinqToHqlGeneratorsRegistryFactory.CreateGeneratorsRegistry(properties); Modified: trunk/nhibernate/src/NHibernate.Test/Linq/LinqReadonlyTestsContext.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Linq/LinqReadonlyTestsContext.cs 2011-03-28 02:32:55 UTC (rev 5557) +++ trunk/nhibernate/src/NHibernate.Test/Linq/LinqReadonlyTestsContext.cs 2011-03-28 02:39:49 UTC (rev 5558) @@ -70,7 +70,7 @@ { var file = new FileInfo(scripFileName); string script = file.OpenText().ReadToEnd().Replace("GO", ""); - var connectionProvider = ConnectionProviderFactory.NewConnectionProvider(configuration.Properties); + var connectionProvider = ConnectionProviderFactory.NewConnectionProvider(configuration.GetDerivedProperties()); using (var conn = connectionProvider.GetConnection()) { if (conn.State == ConnectionState.Closed) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-03-28 18:27:17
|
Revision: 5566 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5566&view=rev Author: fabiomaulo Date: 2011-03-28 18:27:11 +0000 (Mon, 28 Mar 2011) Log Message: ----------- Fix NH-2418 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs trunk/nhibernate/src/NHibernate.Test/DialectTest/DialectFixture.cs Modified: trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs 2011-03-28 16:03:06 UTC (rev 5565) +++ trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs 2011-03-28 18:27:11 UTC (rev 5566) @@ -1764,6 +1764,10 @@ /// </remarks> public virtual bool IsQuoted(string name) { + if (string.IsNullOrEmpty(name)) + { + return false; + } return (name[0] == OpenQuote && name[name.Length - 1] == CloseQuote); } Modified: trunk/nhibernate/src/NHibernate.Test/DialectTest/DialectFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/DialectTest/DialectFixture.cs 2011-03-28 16:03:06 UTC (rev 5565) +++ trunk/nhibernate/src/NHibernate.Test/DialectTest/DialectFixture.cs 2011-03-28 18:27:11 UTC (rev 5566) @@ -7,6 +7,7 @@ using NHibernate.SqlCommand; using NHibernate.SqlTypes; using NUnit.Framework; +using SharpTestsEx; using Environment=NHibernate.Cfg.Environment; namespace NHibernate.Test.DialectTest @@ -62,6 +63,13 @@ } [Test] + public void WhenNullOrEmptyIsQuotedFalse() + { + d.IsQuoted(null).Should().Be.False(); + d.IsQuoted("").Should().Be.False(); + } + + [Test] public void QuoteTableNameNeeded() { Assert.AreEqual( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-03-28 19:43:31
|
Revision: 5567 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5567&view=rev Author: fabiomaulo Date: 2011-03-28 19:43:25 +0000 (Mon, 28 Mar 2011) Log Message: ----------- Fix NH-2015 (thanks to John Davidson) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/Order.cs trunk/nhibernate/src/NHibernate.Test/Criteria/CriteriaQueryTest.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/Order.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/Order.cs 2011-03-28 18:27:11 UTC (rev 5566) +++ trunk/nhibernate/src/NHibernate/Criterion/Order.cs 2011-03-28 19:43:25 UTC (rev 5567) @@ -20,7 +20,8 @@ protected bool ascending; protected string propertyName; protected IProjection projection; - + private bool ignoreCase; + public Order(IProjection projection, bool ascending) { this.projection = projection; @@ -38,7 +39,7 @@ /// </summary> public virtual SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery) { - if (projection!=null) + if (projection != null) { SqlString sb = new SqlString(); SqlString produced = this.projection.ToSqlString(criteria, 0, criteriaQuery, new Dictionary<string, IFilter>()); @@ -49,14 +50,14 @@ } string[] columns = criteriaQuery.GetColumnAliasesUsingProjection(criteria, propertyName); + Type.IType type = criteriaQuery.GetTypeUsingProjection(criteria, propertyName); StringBuilder fragment = new StringBuilder(); - ISessionFactoryImplementor factory = criteriaQuery.Factory; for (int i = 0; i < columns.Length; i++) { - // TODO H3: bool lower = _ignoreCase && type.SqlTypes( factory )[ i ] == Types.VARCHAR - bool lower = false; + bool lower = ignoreCase && IsStringType(type.SqlTypes(factory)[i]); + if (lower) { fragment.Append(factory.Dialect.LowercaseFunction) @@ -82,7 +83,7 @@ public override string ToString() { - return (projection!=null?projection.ToString():propertyName) + (ascending ? " asc" : " desc"); + return (projection != null ? projection.ToString() : propertyName) + (ascending ? " asc" : " desc"); } /// <summary> @@ -124,13 +125,36 @@ { return new Order(propertyName, false); } - + public TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) { if (projection != null) return projection.GetTypedValues(criteria, criteriaQuery); - + return new TypedValue[0]; // not using parameters for ORDER BY columns } + + public Order IgnoreCase() + { + ignoreCase = true; + return this; + } + + private bool IsStringType(SqlTypes.SqlType propertyType) + { + switch (propertyType.DbType) + { + case System.Data.DbType.AnsiString: + return true; + case System.Data.DbType.AnsiStringFixedLength: + return true; + case System.Data.DbType.String: + return true; + case System.Data.DbType.StringFixedLength: + return true; + default: + return false; + } + } } } Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/CriteriaQueryTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/CriteriaQueryTest.cs 2011-03-28 18:27:11 UTC (rev 5566) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/CriteriaQueryTest.cs 2011-03-28 19:43:25 UTC (rev 5567) @@ -2901,5 +2901,60 @@ } } } + + [Test] + public void IgnoreCase() + { + //SqlServer collation set to Latin1_General_BIN + //when database created to validate this test + Course c1 = new Course(); + c1.CourseCode = "course-1"; + c1.Description = "Advanced NHibernate"; + Course c2 = new Course(); + c2.CourseCode = "course-2"; + c2.Description = "advanced csharp"; + Course c3 = new Course(); + c3.CourseCode = "course-3"; + c3.Description = "advanced UnitTesting"; + + using (ISession session = OpenSession()) + using (ITransaction t = session.BeginTransaction()) + { + session.Save(c1); + session.Save(c2); + session.Save(c3); + t.Commit(); + } + + // this particular selection is commented out if collation is not Latin1_General_BIN + //using (ISession session = OpenSession()) + //{ + // // order the courses in binary order - assumes collation Latin1_General_BIN + // IList result = + // session.CreateCriteria(typeof(Course)).AddOrder(Order.Asc("Description")).List(); + // Assert.AreEqual(3, result.Count); + // Course firstResult = (Course)result[0]; + // Assert.IsTrue(firstResult.Description.Contains("Advanced NHibernate"), "Description should have 'Advanced NHibernate', but has " + firstResult.Description); + //} + + using (ISession session = OpenSession()) + { + // order the courses after all descriptions have been converted to lower case + IList result = + session.CreateCriteria(typeof (Course)).AddOrder(Order.Asc("Description").IgnoreCase()).List(); + Assert.AreEqual(3, result.Count); + Course firstResult = (Course) result[0]; + Assert.IsTrue(firstResult.Description.Contains("advanced csharp"), "Description should have 'advanced csharp', but has " + firstResult.Description); + } + + using (ISession session = OpenSession()) + using (ITransaction t = session.BeginTransaction()) + { + session.Delete(c1); + session.Delete(c2); + session.Delete(c3); + t.Commit(); + } + } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jul...@us...> - 2011-03-30 01:50:38
|
Revision: 5569 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5569&view=rev Author: julian-maughan Date: 2011-03-30 01:50:31 +0000 (Wed, 30 Mar 2011) Log Message: ----------- Added PostgreSQL metadata provider (NH-2426) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/PostgreSQLDialect.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Dialect/Schema/PostgreSQLMetadata.cs Modified: trunk/nhibernate/src/NHibernate/Dialect/PostgreSQLDialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/PostgreSQLDialect.cs 2011-03-29 14:23:44 UTC (rev 5568) +++ trunk/nhibernate/src/NHibernate/Dialect/PostgreSQLDialect.cs 2011-03-30 01:50:31 UTC (rev 5569) @@ -1,6 +1,8 @@ using System.Data; +using System.Data.Common; using NHibernate.Cfg; using NHibernate.Dialect.Function; +using NHibernate.Dialect.Schema; using NHibernate.SqlCommand; using NHibernate.SqlTypes; @@ -12,21 +14,22 @@ /// <remarks> /// The PostgreSQLDialect defaults the following configuration properties: /// <list type="table"> - /// <listheader> - /// <term>Property</term> - /// <description>Default Value</description> - /// </listheader> - /// <item> - /// <term>connection.driver_class</term> - /// <description><see cref="NHibernate.Driver.NpgsqlDriver" /></description> - /// </item> + /// <listheader> + /// <term>Property</term> + /// <description>Default Value</description> + /// </listheader> + /// <item> + /// <term>connection.driver_class</term> + /// <description><see cref="NHibernate.Driver.NpgsqlDriver" /></description> + /// </item> /// </list> /// </remarks> public class PostgreSQLDialect : Dialect { - /// <summary></summary> public PostgreSQLDialect() { + DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.NpgsqlDriver"; + RegisterColumnType(DbType.AnsiStringFixedLength, "char(255)"); RegisterColumnType(DbType.AnsiStringFixedLength, 8000, "char($l)"); RegisterColumnType(DbType.AnsiString, "varchar(255)"); @@ -51,7 +54,7 @@ RegisterColumnType(DbType.StringFixedLength, 4000, "char($l)"); RegisterColumnType(DbType.String, "varchar(255)"); RegisterColumnType(DbType.String, 4000, "varchar($l)"); - RegisterColumnType(DbType.String, 1073741823, "text"); // + RegisterColumnType(DbType.String, 1073741823, "text"); RegisterColumnType(DbType.Time, "time"); // Override standard HQL function @@ -59,23 +62,17 @@ RegisterFunction("str", new SQLFunctionTemplate(NHibernateUtil.String, "cast(?1 as varchar)")); RegisterFunction("locate", new PositionSubstringFunction()); RegisterFunction("iif", new SQLFunctionTemplate(null, "case when ?1 then ?2 else ?3 end")); - RegisterFunction("substring", new AnsiSubstringFunction()); RegisterFunction("replace", new StandardSQLFunction("replace", NHibernateUtil.String)); RegisterFunction("left", new SQLFunctionTemplate(NHibernateUtil.String, "substr(?1,1,?2)")); - RegisterFunction("mod", new SQLFunctionTemplate(NHibernateUtil.Int32, "((?1) % (?2))")); - - DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.NpgsqlDriver"; } - /// <summary></summary> public override string AddColumnString { get { return "add column"; } } - /// <summary></summary> public override bool DropConstraints { get { return false; } @@ -111,10 +108,10 @@ return insertString.Append(" returning " + identifierColumnName); } - public override InsertGeneratedIdentifierRetrievalMethod InsertGeneratedIdentifierRetrievalMethod - { - get { return InsertGeneratedIdentifierRetrievalMethod.OutputParameter; } - } + public override InsertGeneratedIdentifierRetrievalMethod InsertGeneratedIdentifierRetrievalMethod + { + get { return InsertGeneratedIdentifierRetrievalMethod.OutputParameter; } + } public override bool SupportsSequences { @@ -192,13 +189,6 @@ get { return true; } } - /*public override bool DropTemporaryTableAfterUse() - { - //we have to, because postgres sets current tx - //to rollback only after a failed create table - return true; - }*/ - public override string CreateTemporaryTableString { get { return "create temporary table"; } @@ -206,10 +196,7 @@ public override string CreateTemporaryTablePostfix { - get - { - return "on commit drop"; - } + get { return "on commit drop"; } } public override string ToBooleanValueString(bool value) @@ -217,9 +204,14 @@ return value ? "TRUE" : "FALSE"; } - public override string SelectGUIDString - { - get { return "select uuid_generate_v4()"; } - } + public override string SelectGUIDString + { + get { return "select uuid_generate_v4()"; } + } + + public override IDataBaseSchema GetDataBaseSchema(DbConnection connection) + { + return new PostgreSQLDataBaseMetadata(connection); + } } } Added: trunk/nhibernate/src/NHibernate/Dialect/Schema/PostgreSQLMetadata.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/Schema/PostgreSQLMetadata.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Dialect/Schema/PostgreSQLMetadata.cs 2011-03-30 01:50:31 UTC (rev 5569) @@ -0,0 +1,110 @@ +using System; +using System.Data; +using System.Data.Common; +using Iesi.Collections.Generic; + +namespace NHibernate.Dialect.Schema +{ + public class PostgreSQLDataBaseMetadata : AbstractDataBaseSchema + { + public PostgreSQLDataBaseMetadata(DbConnection connection) : base(connection) {} + + public override ITableMetadata GetTableMetadata(DataRow rs, bool extras) + { + return new PostgreSQLTableMetadata(rs, this, extras); + } + + public override ISet<string> GetReservedWords() + { + // NpgsqlDriver does not currently (2011/03/30) support this feature, so the + // base class implementation has to be overriden + return new HashedSet<string>(); + } + } + + public class PostgreSQLTableMetadata : AbstractTableMetadata + { + public PostgreSQLTableMetadata(DataRow rs, IDataBaseSchema meta, bool extras) : base(rs, meta, extras) {} + + protected override IColumnMetadata GetColumnMetadata(DataRow rs) + { + return new PostgreSQLColumnMetadata(rs); + } + + protected override string GetColumnName(DataRow rs) + { + return Convert.ToString(rs["COLUMN_NAME"]); + } + + protected override string GetConstraintName(DataRow rs) + { + throw new NotImplementedException(); + } + + protected override IForeignKeyMetadata GetForeignKeyMetadata(DataRow rs) + { + return new PostgreSQLForeignKeyMetadata(rs); + } + + protected override IIndexMetadata GetIndexMetadata(DataRow rs) + { + return new PostgreSQLIndexMetadata(rs); + } + + protected override string GetIndexName(DataRow rs) + { + return Convert.ToString(rs["INDEX_NAME"]); + } + + protected override void ParseTableInfo(DataRow rs) + { + Catalog = Convert.ToString(rs["TABLE_CATALOG"]); + Schema = Convert.ToString(rs["TABLE_SCHEMA"]); + if (string.IsNullOrEmpty(Catalog)) + { + Catalog = null; + } + if (string.IsNullOrEmpty(Schema)) + { + Schema = null; + } + Name = Convert.ToString(rs["TABLE_NAME"]); + } + } + + public class PostgreSQLColumnMetadata : AbstractColumnMetaData + { + public PostgreSQLColumnMetadata(DataRow rs) : base(rs) + { + Name = Convert.ToString(rs["COLUMN_NAME"]); + object objValue = rs["CHARACTER_MAXIMUM_LENGTH"]; + if (objValue != DBNull.Value) + { + ColumnSize = Convert.ToInt32(objValue); + } + objValue = rs["NUMERIC_PRECISION"]; + if (objValue != DBNull.Value) + { + NumericalPrecision = Convert.ToInt32(objValue); + } + Nullable = Convert.ToString(rs["IS_NULLABLE"]); + TypeName = Convert.ToString(rs["DATA_TYPE"]); + } + } + + public class PostgreSQLIndexMetadata : AbstractIndexMetadata + { + public PostgreSQLIndexMetadata(DataRow rs) : base(rs) + { + Name = Convert.ToString(rs["INDEX_NAME"]); + } + } + + public class PostgreSQLForeignKeyMetadata : AbstractForeignKeyMetadata + { + public PostgreSQLForeignKeyMetadata(DataRow rs) : base(rs) + { + Name = Convert.ToString(rs["CONSTRAINT_NAME"]); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-03-29 14:23:44 UTC (rev 5568) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-03-30 01:50:31 UTC (rev 5569) @@ -138,6 +138,7 @@ <Compile Include="Dialect\MsSql7Dialect.cs" /> <Compile Include="Dialect\MySQLDialect.cs" /> <Compile Include="Dialect\PostgreSQLDialect.cs" /> + <Compile Include="Dialect\Schema\PostgreSQLMetadata.cs" /> <Compile Include="Dialect\SQLiteDialect.cs" /> <Compile Include="Dialect\SybaseSQLAnywhere10Dialect.cs" /> <Compile Include="Dialect\SybaseSQLAnywhere11Dialect.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-03-30 22:25:32
|
Revision: 5570 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5570&view=rev Author: fabiomaulo Date: 2011-03-30 22:25:25 +0000 (Wed, 30 Mar 2011) Log Message: ----------- Fix NH-2610 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Impl/MultiCriteriaImpl.cs trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/SqlConverterAndMultiQuery/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/SqlConverterAndMultiQuery/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/SqlConverterAndMultiQuery/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/SqlConverterAndMultiQuery/Model.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/SqlConverterAndMultiQuery/SqlConverter.cs Modified: trunk/nhibernate/src/NHibernate/Impl/MultiCriteriaImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/MultiCriteriaImpl.cs 2011-03-30 01:50:31 UTC (rev 5569) +++ trunk/nhibernate/src/NHibernate/Impl/MultiCriteriaImpl.cs 2011-03-30 22:25:25 UTC (rev 5570) @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Data.Common; using System.Diagnostics; using Iesi.Collections; using Iesi.Collections.Generic; @@ -8,6 +9,7 @@ using NHibernate.Criterion; using NHibernate.Driver; using NHibernate.Engine; +using NHibernate.Exceptions; using NHibernate.Loader.Criteria; using NHibernate.SqlCommand; using NHibernate.Transform; @@ -189,13 +191,13 @@ } int rowCount = 0; - using (var reader = resultSetsCommand.GetReader(parameters.ToArray(), null)) + try { - ArrayList[] hydratedObjects = new ArrayList[loaders.Count]; - List<EntityKey[]>[] subselectResultKeys = new List<EntityKey[]>[loaders.Count]; - bool[] createSubselects = new bool[loaders.Count]; - try + using (var reader = resultSetsCommand.GetReader(parameters.ToArray(), null)) { + ArrayList[] hydratedObjects = new ArrayList[loaders.Count]; + List<EntityKey[]>[] subselectResultKeys = new List<EntityKey[]>[loaders.Count]; + bool[] createSubselects = new bool[loaders.Count]; for (int i = 0; i < loaders.Count; i++) { CriteriaLoader loader = loaders[i]; @@ -217,7 +219,7 @@ createSubselects[i] = loader.IsSubselectLoadingEnabled; subselectResultKeys[i] = createSubselects[i] ? new List<EntityKey[]>() : null; int maxRows = Loader.Loader.HasMaxRows(selection) ? selection.MaxRows : int.MaxValue; - if (!dialect.SupportsLimitOffset || !NHibernate.Loader.Loader.UseLimit(selection, dialect)) + if (!dialect.SupportsLimitOffset || !Loader.Loader.UseLimit(selection, dialect)) { Loader.Loader.Advance(reader, selection); } @@ -228,7 +230,7 @@ object o = loader.GetRowFromResultSet(reader, session, queryParameters, loader.GetLockModes(queryParameters.LockModes), - null, hydratedObjects[i], keys, true); + null, hydratedObjects[i], keys, true); if (createSubselects[i]) { subselectResultKeys[i].Add(keys); @@ -239,24 +241,25 @@ results.Add(tmpResults); reader.NextResult(); } - } - catch (Exception e) - { - var message = string.Format("Failed to execute multi criteria: [{0}]", resultSetsCommand.Sql); - log.Error(message, e); - throw new HibernateException(message, e); - } - for (int i = 0; i < loaders.Count; i++) - { - CriteriaLoader loader = loaders[i]; - loader.InitializeEntitiesAndCollections(hydratedObjects[i], reader, session, false); - if (createSubselects[i]) + for (int i = 0; i < loaders.Count; i++) { - loader.CreateSubselects(subselectResultKeys[i], parameters[i], session); + CriteriaLoader loader = loaders[i]; + loader.InitializeEntitiesAndCollections(hydratedObjects[i], reader, session, false); + + if (createSubselects[i]) + { + loader.CreateSubselects(subselectResultKeys[i], parameters[i], session); + } } } } + catch (Exception sqle) + { + var message = string.Format("Failed to execute multi criteria: [{0}]", resultSetsCommand.Sql); + log.Error(message, sqle); + throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle, "Failed to execute multi criteria", resultSetsCommand.Sql); + } if (statsEnabled) { stopWatch.Stop(); Modified: trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs 2011-03-30 01:50:31 UTC (rev 5569) +++ trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs 2011-03-30 22:25:25 UTC (rev 5570) @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Data.Common; using System.Diagnostics; using System.Linq; using Iesi.Collections; @@ -9,6 +10,7 @@ using NHibernate.Driver; using NHibernate.Engine; using NHibernate.Engine.Query.Sql; +using NHibernate.Exceptions; using NHibernate.Hql; using NHibernate.Loader.Custom; using NHibernate.Loader.Custom.Sql; @@ -508,9 +510,9 @@ List<EntityKey[]>[] subselectResultKeys = new List<EntityKey[]>[Translators.Count]; bool[] createSubselects = new bool[Translators.Count]; - using (var reader = resultSetsCommand.GetReader(Parameters.ToArray(), commandTimeout != RowSelection.NoValue ? commandTimeout : (int?)null)) + try { - try + using (var reader = resultSetsCommand.GetReader(Parameters.ToArray(), commandTimeout != RowSelection.NoValue ? commandTimeout : (int?)null)) { if (log.IsDebugEnabled) { @@ -521,13 +523,13 @@ ITranslator translator = Translators[i]; QueryParameters parameter = Parameters[i]; IList tempResults; - if (resultCollectionGenericType[i] == typeof (object)) + if (resultCollectionGenericType[i] == typeof(object)) { tempResults = new ArrayList(); } else { - tempResults = (IList) Activator.CreateInstance(typeof (List<>).MakeGenericType(resultCollectionGenericType[i])); + tempResults = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(resultCollectionGenericType[i])); } int entitySpan = translator.Loader.EntityPersisters.Length; hydratedObjects[i] = entitySpan > 0 ? new ArrayList() : null; @@ -564,13 +566,13 @@ object result = translator.Loader.GetRowFromResultSet(reader, - session, - parameter, - lockModeArray, - optionalObjectKey, - hydratedObjects[i], - keys, - true); + session, + parameter, + lockModeArray, + optionalObjectKey, + hydratedObjects[i], + keys, + true); tempResults.Add(result); @@ -595,27 +597,27 @@ reader.NextResult(); } - } - catch (Exception ex) - { - var message = string.Format("Failed to execute multi query: [{0}]", resultSetsCommand.Sql); - log.Error(message, ex); - throw new HibernateException(message, ex); - } - for (int i = 0; i < translators.Count; i++) - { - ITranslator translator = translators[i]; - QueryParameters parameter = parameters[i]; + for (int i = 0; i < translators.Count; i++) + { + ITranslator translator = translators[i]; + QueryParameters parameter = parameters[i]; - translator.Loader.InitializeEntitiesAndCollections(hydratedObjects[i], reader, session, false); + translator.Loader.InitializeEntitiesAndCollections(hydratedObjects[i], reader, session, false); - if (createSubselects[i]) - { - translator.Loader.CreateSubselects(subselectResultKeys[i], parameter, session); + if (createSubselects[i]) + { + translator.Loader.CreateSubselects(subselectResultKeys[i], parameter, session); + } } } } + catch (Exception sqle) + { + var message = string.Format("Failed to execute multi query: [{0}]", resultSetsCommand.Sql); + log.Error(message, sqle); + throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle, "Failed to execute multi query", resultSetsCommand.Sql); + } if (statsEnabled) { Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/SqlConverterAndMultiQuery/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/SqlConverterAndMultiQuery/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/SqlConverterAndMultiQuery/Fixture.cs 2011-03-30 22:25:25 UTC (rev 5570) @@ -0,0 +1,77 @@ +using NHibernate.Cfg; +using NHibernate.Cfg.Loquacious; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.SqlConverterAndMultiQuery +{ + [TestFixture] + public class Fixture : BugTestCase + { + private const string hqlQuery = "select a.Id from ClassA a"; + + protected override void Configure(Configuration configuration) + { + configuration.DataBaseIntegration(x => x.ExceptionConverter<SqlConverter>()); + } + + [Test] + public void NormalHqlShouldThrowUserException() + { + using(var s = OpenSession()) + { + using(s.BeginTransaction()) + { + s.Connection.Close(); + Assert.Throws<UnitTestException>(() => + s.CreateQuery(hqlQuery).List()); + } + } + } + + [Test] + public void MultiHqlShouldThrowUserException() + { + using (var s = OpenSession()) + { + using (s.BeginTransaction()) + { + var multi = s.CreateMultiQuery(); + multi.Add(hqlQuery); + s.Connection.Close(); + Assert.Throws<UnitTestException>(() => + multi.List()); + } + } + } + + [Test] + public void NormalCriteriaShouldThrowUserException() + { + using (var s = OpenSession()) + { + using (s.BeginTransaction()) + { + s.Connection.Close(); + Assert.Throws<UnitTestException>(() => + s.CreateCriteria(typeof(ClassA)).List()); + } + } + } + + [Test] + public void MultiCriteriaShouldThrowUserException() + { + using (var s = OpenSession()) + { + using (s.BeginTransaction()) + { + var multi = s.CreateMultiCriteria(); + multi.Add(s.CreateCriteria(typeof (ClassA))); + s.Connection.Close(); + Assert.Throws<UnitTestException>(() => + multi.List()); + } + } + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/SqlConverterAndMultiQuery/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/SqlConverterAndMultiQuery/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/SqlConverterAndMultiQuery/Mappings.hbm.xml 2011-03-30 22:25:25 UTC (rev 5570) @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.SqlConverterAndMultiQuery" + assembly="NHibernate.Test"> + + <class name="ClassA"> + <id name="Id"> + <generator class="native"/> + </id> + </class> +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/SqlConverterAndMultiQuery/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/SqlConverterAndMultiQuery/Model.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/SqlConverterAndMultiQuery/Model.cs 2011-03-30 22:25:25 UTC (rev 5570) @@ -0,0 +1,7 @@ +namespace NHibernate.Test.NHSpecificTest.SqlConverterAndMultiQuery +{ + public class ClassA + { + public virtual int Id { get; set; } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/SqlConverterAndMultiQuery/SqlConverter.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/SqlConverterAndMultiQuery/SqlConverter.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/SqlConverterAndMultiQuery/SqlConverter.cs 2011-03-30 22:25:25 UTC (rev 5570) @@ -0,0 +1,15 @@ +using System; +using NHibernate.Exceptions; + +namespace NHibernate.Test.NHSpecificTest.SqlConverterAndMultiQuery +{ + public class SqlConverter : ISQLExceptionConverter + { + public Exception Convert(AdoExceptionContextInfo adoExceptionContextInfo) + { + return new UnitTestException(); + } + } + + public class UnitTestException : Exception{} +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-03-30 01:50:31 UTC (rev 5569) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-03-30 22:25:25 UTC (rev 5570) @@ -677,6 +677,9 @@ <Compile Include="NHSpecificTest\Properties\CompositePropertyRefTest.cs" /> <Compile Include="NHSpecificTest\Properties\DynamicEntityTest.cs" /> <Compile Include="NHSpecificTest\Properties\Model.cs" /> + <Compile Include="NHSpecificTest\SqlConverterAndMultiQuery\Fixture.cs" /> + <Compile Include="NHSpecificTest\SqlConverterAndMultiQuery\Model.cs" /> + <Compile Include="NHSpecificTest\SqlConverterAndMultiQuery\SqlConverter.cs" /> <Compile Include="PolymorphicGetAndLoad\Domain.cs" /> <Compile Include="PolymorphicGetAndLoad\PolymorphicGetAndLoadTest.cs" /> <Compile Include="PropertyTest\FieldCamelCaseMUnderscoreFixture.cs" /> @@ -2500,6 +2503,7 @@ <EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="NHSpecificTest\SqlConverterAndMultiQuery\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2489\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2603\Mappings.hbm.xml" /> <EmbeddedResource Include="Subselect\Beings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |