From: <ric...@us...> - 2010-07-12 21:48:52
|
Revision: 5004 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5004&view=rev Author: ricbrown Date: 2010-07-12 21:48:46 +0000 (Mon, 12 Jul 2010) Log Message: ----------- Added custom extension methods usable inside QueryOver expressions. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs Added Paths: ----------- trunk/nhibernate/src/NHibernate/Criterion/RestrictionsExtensions.cs Added: trunk/nhibernate/src/NHibernate/Criterion/RestrictionsExtensions.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/RestrictionsExtensions.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Criterion/RestrictionsExtensions.cs 2010-07-12 21:48:46 UTC (rev 5004) @@ -0,0 +1,152 @@ +using System; +using System.Collections; +using System.Linq.Expressions; +using NHibernate.Impl; + +namespace NHibernate.Criterion +{ + public static class RestrictionExtensions + { + /// <summary> + /// Apply a "like" restriction in a QueryOver expression + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static bool IsLike(this string projection, string comparison) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + /// <summary> + /// Apply a "like" restriction in a QueryOver expression + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static bool IsLike(this string projection, string comparison, MatchMode matchMode) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + /// <summary> + /// Apply a "like" restriction in a QueryOver expression + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static bool IsLike(this string projection, string comparison, MatchMode matchMode, char? escapeChar) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + /// <summary> + /// Apply a "like" restriction in a QueryOver expression + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static bool IsInsensitiveLike(this string projection, string comparison) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + /// <summary> + /// Apply a "like" restriction in a QueryOver expression + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static bool IsInsensitiveLike(this string projection, string comparison, MatchMode matchMode) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + /// <summary> + /// Apply an "in" constraint to the named property + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static bool IsIn(this object projection, object[] values) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + /// <summary> + /// Apply an "in" constraint to the named property + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static bool IsIn(this object projection, ICollection values) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + /// <summary> + /// Apply a "between" constraint to the named property + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static RestrictionBetweenBuilder IsBetween(this object projection, object lo) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + public class RestrictionBetweenBuilder + { + public bool And(object hi) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + } + + public static ICriterion ProcessIsLike(MethodCallExpression methodCallExpression) + { + string property = ExpressionProcessor.FindMemberExpression(methodCallExpression.Arguments[0]); + object value = ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + return Restrictions.Like(property, value); + } + + public static ICriterion ProcessIsLikeMatchMode(MethodCallExpression methodCallExpression) + { + string property = ExpressionProcessor.FindMemberExpression(methodCallExpression.Arguments[0]); + string value = (string)ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + MatchMode matchMode = (MatchMode)ExpressionProcessor.FindValue(methodCallExpression.Arguments[2]); + return Restrictions.Like(property, value, matchMode); + } + + public static ICriterion ProcessIsLikeMatchModeEscapeChar(MethodCallExpression methodCallExpression) + { + string property = ExpressionProcessor.FindMemberExpression(methodCallExpression.Arguments[0]); + string value = (string)ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + MatchMode matchMode = (MatchMode)ExpressionProcessor.FindValue(methodCallExpression.Arguments[2]); + char? escapeChar = (char?)ExpressionProcessor.FindValue(methodCallExpression.Arguments[3]); + return Restrictions.Like(property, value, matchMode, escapeChar); + } + + public static ICriterion ProcessIsInsensitiveLike(MethodCallExpression methodCallExpression) + { + string property = ExpressionProcessor.FindMemberExpression(methodCallExpression.Arguments[0]); + object value = ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + return Restrictions.InsensitiveLike(property, value); + } + + public static ICriterion ProcessIsInsensitiveLikeMatchMode(MethodCallExpression methodCallExpression) + { + string property = ExpressionProcessor.FindMemberExpression(methodCallExpression.Arguments[0]); + string value = (string)ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + MatchMode matchMode = (MatchMode)ExpressionProcessor.FindValue(methodCallExpression.Arguments[2]); + return Restrictions.InsensitiveLike(property, value, matchMode); + } + + public static ICriterion ProcessIsInArray(MethodCallExpression methodCallExpression) + { + string property = ExpressionProcessor.FindMemberExpression(methodCallExpression.Arguments[0]); + object[] values = (object[])ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + return Restrictions.In(property, values); + } + + public static ICriterion ProcessIsInCollection(MethodCallExpression methodCallExpression) + { + string property = ExpressionProcessor.FindMemberExpression(methodCallExpression.Arguments[0]); + ICollection values = (ICollection)ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + return Restrictions.In(property, values); + } + + public static ICriterion ProcessIsBetween(MethodCallExpression methodCallExpression) + { + MethodCallExpression betweenFunction = (MethodCallExpression)methodCallExpression.Object; + string property = ExpressionProcessor.FindMemberExpression(betweenFunction.Arguments[0]); + object lo = ExpressionProcessor.FindValue(betweenFunction.Arguments[1]); + object hi = ExpressionProcessor.FindValue(methodCallExpression.Arguments[0]); + return Restrictions.Between(property, lo, hi); + } + } +} Modified: trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2010-07-08 22:13:54 UTC (rev 5003) +++ trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2010-07-12 21:48:46 UTC (rev 5004) @@ -34,6 +34,7 @@ private readonly static IDictionary<ExpressionType, Func<string, object, ICriterion>> _simpleExpressionCreators = null; private readonly static IDictionary<ExpressionType, Func<string, string, ICriterion>> _propertyExpressionCreators = null; private readonly static IDictionary<LambdaSubqueryType, IDictionary<ExpressionType, Func<string, DetachedCriteria, AbstractCriterion>>> _subqueryExpressionCreatorTypes = null; + private readonly static IDictionary<string, Func<MethodCallExpression, ICriterion>> _customMethodCallProcessors = null; static ExpressionProcessor() { @@ -75,6 +76,16 @@ _subqueryExpressionCreatorTypes[LambdaSubqueryType.Some][ExpressionType.GreaterThanOrEqual] = Subqueries.PropertyGeSome; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Some][ExpressionType.LessThan] = Subqueries.PropertyLtSome; _subqueryExpressionCreatorTypes[LambdaSubqueryType.Some][ExpressionType.LessThanOrEqual] = Subqueries.PropertyLeSome; + + _customMethodCallProcessors = new Dictionary<string, Func<MethodCallExpression, ICriterion>>(); + RegisterCustomMethodCall(() => RestrictionExtensions.IsLike("", ""), RestrictionExtensions.ProcessIsLike); + RegisterCustomMethodCall(() => RestrictionExtensions.IsLike("", "", null), RestrictionExtensions.ProcessIsLikeMatchMode); + RegisterCustomMethodCall(() => RestrictionExtensions.IsLike("", "", null, null), RestrictionExtensions.ProcessIsLikeMatchModeEscapeChar); + RegisterCustomMethodCall(() => RestrictionExtensions.IsInsensitiveLike("", ""), RestrictionExtensions.ProcessIsInsensitiveLike); + RegisterCustomMethodCall(() => RestrictionExtensions.IsInsensitiveLike("", "", null), RestrictionExtensions.ProcessIsInsensitiveLikeMatchMode); + RegisterCustomMethodCall(() => RestrictionExtensions.IsIn(null, new object[0]), RestrictionExtensions.ProcessIsInArray); + RegisterCustomMethodCall(() => RestrictionExtensions.IsIn(null, new List<object>()), RestrictionExtensions.ProcessIsInCollection); + RegisterCustomMethodCall(() => RestrictionExtensions.IsBetween(null, null).And(null), RestrictionExtensions.ProcessIsBetween); } private static ICriterion Eq(string propertyName, object value) @@ -110,6 +121,16 @@ } /// <summary> + /// Invoke the expression to extract its runtime value + /// </summary> + public static object FindValue(Expression expression) + { + var valueExpression = Expression.Lambda(expression).Compile(); + object value = valueExpression.DynamicInvoke(); + return value; + } + + /// <summary> /// Retrieves the name of the property from a member expression /// </summary> /// <param name="expression">An expression tree that can contain either a member, or a conversion from a member. @@ -299,8 +320,7 @@ string property = FindMemberExpression(be.Left); System.Type propertyType = FindMemberType(be.Left); - var valueExpression = Expression.Lambda(be.Right).Compile(); - object value = valueExpression.DynamicInvoke(); + object value = FindValue(be.Right); value = ConvertType(value, propertyType); if (value == null) @@ -395,12 +415,39 @@ if (unaryExpression.NodeType != ExpressionType.Not) throw new Exception("Cannot interpret member from " + expression.ToString()); - return Restrictions.Eq(FindMemberExpression(unaryExpression.Operand), false); + if (IsMemberExpression(unaryExpression.Operand)) + return Restrictions.Eq(FindMemberExpression(unaryExpression.Operand), false); + else + return Restrictions.Not(ProcessExpression(unaryExpression.Operand)); } + if (expression is MethodCallExpression) + { + MethodCallExpression methodCallExpression = (MethodCallExpression)expression; + return ProcessCustomMethodCall(methodCallExpression); + } + throw new Exception("Could not determine member type from " + expression.ToString()); } + private static string Signature(MethodInfo methodInfo) + { + return methodInfo.DeclaringType.FullName + + ":" + methodInfo.ToString(); + } + + private static ICriterion ProcessCustomMethodCall(MethodCallExpression methodCallExpression) + { + string signature = Signature(methodCallExpression.Method); + + if (!_customMethodCallProcessors.ContainsKey(signature)) + throw new Exception("Unrecognised method call: " + signature); + + Func<MethodCallExpression, ICriterion> customMethodCallProcessor = _customMethodCallProcessors[signature]; + ICriterion criterion = customMethodCallProcessor(methodCallExpression); + return criterion; + } + private static ICriterion ProcessExpression(Expression expression) { if (expression is BinaryExpression) @@ -524,6 +571,18 @@ return criterion; } + /// <summary> + /// Register a custom method for use in a QueryOver expression + /// </summary> + /// <param name="function">Lambda expression demonstrating call of custom method</param> + /// <param name="functionProcessor">function to convert MethodCallExpression to ICriterion</param> + public static void RegisterCustomMethodCall(Expression<Func<bool>> function, Func<MethodCallExpression, ICriterion> functionProcessor) + { + MethodCallExpression functionExpression = (MethodCallExpression)function.Body; + string signature = Signature(functionExpression.Method); + _customMethodCallProcessors.Add(signature, functionProcessor); + } + } } Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-07-08 22:13:54 UTC (rev 5003) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-07-12 21:48:46 UTC (rev 5004) @@ -580,6 +580,7 @@ <Compile Include="Criterion\NullSubqueryExpression.cs" /> <Compile Include="Criterion\QueryOverBuilderExtensions.cs" /> <Compile Include="Criterion\ProjectionsExtensions.cs" /> + <Compile Include="Criterion\RestrictionsExtensions.cs" /> <Compile Include="Dialect\MsSql2008Dialect.cs" /> <Compile Include="Dialect\InformixDialect0940.cs" /> <Compile Include="Dialect\InformixDialect1000.cs" /> Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs 2010-07-08 22:13:54 UTC (rev 5003) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs 2010-07-12 21:48:46 UTC (rev 5004) @@ -147,6 +147,14 @@ Assert.AreEqual(before.ToString(), after.ToString()); } + [Test] + public void TestEvaluateRestrictionExtension() + { + ICriterion before = Restrictions.Like("Name", "%test%"); + ICriterion after = ExpressionProcessor.ProcessExpression<Person>(p => p.Name.IsLike("%test%")); + Assert.AreEqual(before.ToString(), after.ToString()); + } + } } Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2010-07-08 22:13:54 UTC (rev 5003) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2010-07-12 21:48:46 UTC (rev 5004) @@ -101,6 +101,23 @@ } [Test] + public void CustomMethodExpression() + { + ICriteria expected = + CreateTestCriteria(typeof(Person), "personAlias") + .Add(Restrictions.Or( + Restrictions.Not(Restrictions.Eq("Name", "test name")), + Restrictions.Not(Restrictions.Like("personAlias.Name", "%test%")))); + + Person personAlias = null; + IQueryOver<Person> actual = + CreateTestQueryOver<Person>(() => personAlias) + .Where(p => !(p.Name == "test name") || !personAlias.Name.IsLike("%test%")); + + AssertCriteriaAreEqual(expected, actual); + } + + [Test] public void Negation() { ICriteria expected = Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs 2010-07-08 22:13:54 UTC (rev 5003) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs 2010-07-12 21:48:46 UTC (rev 5004) @@ -221,6 +221,34 @@ AssertCriteriaAreEqual(expected, actual); } + [Test] + public void RestrictionsExtensions() + { + ICriteria expected = + CreateTestCriteria(typeof(Person)) + .Add(Restrictions.Like("Name", "%test%")) + .Add(Restrictions.Like("Name", "test", MatchMode.End)) + .Add(Restrictions.Like("Name", "test", MatchMode.Start, '?')) + .Add(Restrictions.InsensitiveLike("Name", "%test%")) + .Add(Restrictions.InsensitiveLike("Name", "test", MatchMode.Anywhere)) + .Add(Restrictions.In("Name", new string[] { "name1", "name2" })) + .Add(Restrictions.In("Name", new ArrayList() { "name3", "name4" })) + .Add(Restrictions.Between("Age", 10, 20)); + + IQueryOver<Person> actual = + CreateTestQueryOver<Person>() + .Where(p => p.Name.IsLike("%test%")) + .And(p => p.Name.IsLike("test", MatchMode.End)) + .And(p => p.Name.IsLike("test", MatchMode.Start, '?')) + .And(p => p.Name.IsInsensitiveLike("%test%")) + .And(p => p.Name.IsInsensitiveLike("test", MatchMode.Anywhere)) + .And(p => p.Name.IsIn(new string[] { "name1", "name2" })) + .And(p => p.Name.IsIn(new ArrayList() { "name3", "name4" })) + .And(p => p.Age.IsBetween(10).And(20)); + + AssertCriteriaAreEqual(expected, actual); + } + } } \ 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...> - 2010-07-15 10:01:48
|
Revision: 5005 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5005&view=rev Author: julian-maughan Date: 2010-07-15 10:01:40 +0000 (Thu, 15 Jul 2010) Log Message: ----------- Bugfix: When touching the identifier of a proxy object a call to the database is executed (ref. NH-2069) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Util/ReflectHelper.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj trunk/nhibernate/src/NHibernate.Test/UtilityTest/ReflectHelperFixture.cs Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITest.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITest2.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITestBase.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Test.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Test2.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/TestBase.cs Modified: trunk/nhibernate/src/NHibernate/Util/ReflectHelper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Util/ReflectHelper.cs 2010-07-12 21:48:46 UTC (rev 5004) +++ trunk/nhibernate/src/NHibernate/Util/ReflectHelper.cs 2010-07-15 10:01:40 UTC (rev 5005) @@ -476,42 +476,6 @@ return SafeGetMethod(type, method, tps); } - /// <summary> - /// Try to find a method in a serie of given types. - /// </summary> - /// <param name="types">The serie of types where find.</param> - /// <param name="method">The method info.</param> - /// <returns>The found method or null.</returns> - /// <remarks> - /// The <paramref name="method"/>, in general, become from another <see cref="Type"/>. - /// </remarks> - public static MethodInfo TryGetMethod(IEnumerable<System.Type> types, MethodInfo method) - { - // This method will be used when we support multiple proxy interfaces. - if (types == null) - { - throw new ArgumentNullException("types"); - } - if (method == null) - { - return null; - } - - System.Type[] tps = GetMethodSignature(method); - MethodInfo result = null; - - foreach (var type in types) - { - result = SafeGetMethod(type, method, tps); - if (result != null) - { - return result; - } - } - - return result; - } - private static System.Type[] GetMethodSignature(MethodInfo method) { var pi = method.GetParameters(); @@ -527,14 +491,39 @@ { const BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; + List<System.Type> typesToSearch = new List<System.Type>(); + MethodInfo foundMethod = null; + try - { - return type.GetMethod(method.Name, bindingFlags, null, tps, null); + { + typesToSearch.Add(type); + + if (type.IsInterface) + { + // Methods on parent interfaces are not actually inherited + // by child interfaces, so we have to use GetInterfaces to + // identify any parent interfaces that may contain the + // method implementation + System.Type[] inheritedInterfaces = type.GetInterfaces(); + typesToSearch.AddRange(inheritedInterfaces); + } + + foreach (System.Type typeToSearch in typesToSearch) + { + MethodInfo result = typeToSearch.GetMethod(method.Name, bindingFlags, null, tps, null); + if (result != null) + { + foundMethod = result; + break; + } + } } catch (Exception) { - return null; + throw; } + + return foundMethod; } internal static object GetConstantValue(string qualifiedName) Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069 ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Fixture.cs 2010-07-15 10:01:40 UTC (rev 5005) @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Transactions; +using NHibernate; +using NHibernate.Impl; +using NHibernate.Proxy; +using NHibernate.Criterion; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2069 +{ + [TestFixture] + public class Fixture : BugTestCase + { + protected override void OnSetUp() + { + using (var s = OpenSession()) + using (s.BeginTransaction()) + { + var test2 = new Test2(); + test2.Cid = 5; + test2.Description = "Test 2: CID = 5"; + + var test = new Test(); + test.Cid = 1; + test.Description = "Test: CID = 1"; + test.Category = test2; + + s.Save(test2); + s.Save(test); + + s.Transaction.Commit(); + } + } + + protected override void OnTearDown() + { + using (var s = OpenSession()) + using (s.BeginTransaction()) + { + s.Delete("from Test"); + s.Delete("from Test2"); + s.Transaction.Commit(); + } + } + + [Test] + public void ProxyRemainsUninitializedWhenReferencingIdProperty() + { + using (ISession session = base.OpenSession()) + { + ITest b = session.CreateQuery("from Test").UniqueResult<Test>(); + + Assert.IsNotNull(b); + + INHibernateProxy proxy = b.Category as INHibernateProxy; + + Assert.That(proxy, Is.Not.Null); + + Assert.That(proxy.HibernateLazyInitializer.IsUninitialized, "Proxy should be uninitialized."); + + long cid = b.Category.Cid; + + Assert.That(proxy.HibernateLazyInitializer.IsUninitialized, "Proxy should still be uninitialized."); + } + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITest.cs 2010-07-15 10:01:40 UTC (rev 5005) @@ -0,0 +1,10 @@ +using System; + +namespace NHibernate.Test.NHSpecificTest.NH2069 +{ + public interface ITest : ITestBase + { + string Description { get; set;} + ITest2 Category { get; set; } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITest2.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITest2.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITest2.cs 2010-07-15 10:01:40 UTC (rev 5005) @@ -0,0 +1,9 @@ +using System; + +namespace NHibernate.Test.NHSpecificTest.NH2069 +{ + public interface ITest2 : ITestBase + { + string Description { get; set; } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITestBase.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITestBase.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITestBase.cs 2010-07-15 10:01:40 UTC (rev 5005) @@ -0,0 +1,9 @@ +using System; + +namespace NHibernate.Test.NHSpecificTest.NH2069 +{ + public interface ITestBase + { + Int64 Cid { get; set; } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Mappings.hbm.xml 2010-07-15 10:01:40 UTC (rev 5005) @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping + xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2069" + default-lazy="true"> + + <class name="Test" table="Test" proxy="ITest"> + <id column="cid" name="Cid" type="Int64" > + <generator class="native" /> + </id> + <many-to-one name="Category" class="Test2" column="Test2_Cid" not-null="true"/> + <property name="Description" column="Description" type="String" length="255"/> + </class> + + <class name="Test2" table="Test2" proxy="ITest2"> + <id column="cid" name="Cid" type="Int64"> + <generator class="native" /> + </id> + <property name="Description" column="Description" type="String" length="255"/> + </class> + +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Test.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Test.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Test.cs 2010-07-15 10:01:40 UTC (rev 5005) @@ -0,0 +1,13 @@ +using System; + +namespace NHibernate.Test.NHSpecificTest.NH2069 +{ + public class Test : TestBase, ITest + { + public Test() { } + + public string Description { get; set; } + + public ITest2 Category { get; set; } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Test2.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Test2.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Test2.cs 2010-07-15 10:01:40 UTC (rev 5005) @@ -0,0 +1,13 @@ +using System; + +namespace NHibernate.Test.NHSpecificTest.NH2069 +{ + public class Test2 : ITest2 + { + public Test2() { } + + public Int64 Cid { get; set; } //When using this property it works fine. + + public string Description { get; set; } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/TestBase.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/TestBase.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/TestBase.cs 2010-07-15 10:01:40 UTC (rev 5005) @@ -0,0 +1,9 @@ +using System; + +namespace NHibernate.Test.NHSpecificTest.NH2069 +{ + public class TestBase : ITestBase + { + public Int64 Cid { get; set; } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-12 21:48:46 UTC (rev 5004) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-15 10:01:40 UTC (rev 5005) @@ -443,6 +443,13 @@ <Compile Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Employee.cs" /> <Compile Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Fixture.cs" /> <Compile Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Money.cs" /> + <Compile Include="NHSpecificTest\NH2069\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2069\ITest.cs" /> + <Compile Include="NHSpecificTest\NH2069\ITest2.cs" /> + <Compile Include="NHSpecificTest\NH2069\ITestBase.cs" /> + <Compile Include="NHSpecificTest\NH2069\Test.cs" /> + <Compile Include="NHSpecificTest\NH2069\Test2.cs" /> + <Compile Include="NHSpecificTest\NH2069\TestBase.cs" /> <Compile Include="NHSpecificTest\NH2189\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2189\Model.cs" /> <Compile Include="NHSpecificTest\ElementsEnums\AbstractIntEnumsBagFixture.cs" /> @@ -2155,6 +2162,7 @@ <EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" /> <EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH2069\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2230\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2189\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2201\Mappings.hbm.xml" /> Modified: trunk/nhibernate/src/NHibernate.Test/UtilityTest/ReflectHelperFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/UtilityTest/ReflectHelperFixture.cs 2010-07-12 21:48:46 UTC (rev 5004) +++ trunk/nhibernate/src/NHibernate.Test/UtilityTest/ReflectHelperFixture.cs 2010-07-15 10:01:40 UTC (rev 5005) @@ -114,32 +114,8 @@ Assert.That(ReflectHelper.TryGetMethod(typeof(IMyBaseInterface), mng), Is.Not.Null); Assert.That(ReflectHelper.TryGetMethod(typeof(IMyBaseInterface), mns), Is.Not.Null); - mig = typeof(MyImplementation).GetMethod("get_Id", bf); - mis = typeof(MyImplementation).GetMethod("set_Id", bf); - mng = typeof(MyImplementation).GetMethod("get_Name", bf); - mns = typeof(MyImplementation).GetMethod("set_Name", bf); - MethodInfo mdg = typeof(MyImplementation).GetMethod("get_Description", bf); - MethodInfo mds = typeof(MyImplementation).GetMethod("set_Description", bf); - Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mig), Is.Not.Null); - Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mis), Is.Null); - Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mng), Is.Not.Null); - Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mns), Is.Not.Null); - Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mdg), Is.Not.Null); - Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mds), Is.Null); - - MethodInfo mdig = typeof(MyDerivedImplementation).GetMethod("get_Id", bf); - MethodInfo mdis = typeof(MyDerivedImplementation).GetMethod("set_Id", bf); - MethodInfo mdng = typeof(MyDerivedImplementation).GetMethod("get_Name", bf); - MethodInfo mdns = typeof(MyDerivedImplementation).GetMethod("set_Name", bf); - MethodInfo mddg = typeof(MyDerivedImplementation).GetMethod("get_Description", bf); - MethodInfo mdds = typeof(MyDerivedImplementation).GetMethod("set_Description", bf); - - Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mdig), Is.Not.Null); - Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mdis), Is.Null); - Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mdng), Is.Not.Null); - Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mdns), Is.Not.Null); - Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mddg), Is.Not.Null); - Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mdds), Is.Null); + mig = typeof(IMyBaseInterface).GetMethod("get_Id", bf); + Assert.That(ReflectHelper.TryGetMethod(typeof(IMyInterface), mig), Is.Not.Null); } [Test] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jul...@us...> - 2010-07-15 16:20:58
|
Revision: 5007 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5007&view=rev Author: julian-maughan Date: 2010-07-15 16:20:51 +0000 (Thu, 15 Jul 2010) Log Message: ----------- Performance enhancement, reported as "MsSql2005Dialect does not use parameters for paging parameters" (ref. NH-2215). Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/MsSql2005Dialect.cs trunk/nhibernate/src/NHibernate.Test/DialectTest/MsSql2005DialectFixture.cs trunk/nhibernate/src/NHibernate.Test/Pagination/CustomMsSqlDriver.cs Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2005Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/MsSql2005Dialect.cs 2010-07-15 15:16:31 UTC (rev 5006) +++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2005Dialect.cs 2010-07-15 16:20:51 UTC (rev 5007) @@ -45,7 +45,7 @@ public override SqlString GetLimitString(SqlString querySqlString, int offset, int last) { //dont do this paging code if there is no offset, use the - //sql 2000 dialect since it wont just uses a top statement + //sql 2000 dialect since it just uses a top statement if (offset == 0) { return base.GetLimitString(querySqlString, offset, last); @@ -76,11 +76,17 @@ sortExpressions = new[] {new SqlString("CURRENT_TIMESTAMP"),}; } + Parameter limitParameter = Parameter.Placeholder; + limitParameter.ParameterPosition = 0; + + Parameter offsetParameter = Parameter.Placeholder; + offsetParameter.ParameterPosition = 1; + SqlStringBuilder result = new SqlStringBuilder() - .Add("SELECT TOP ") - .Add(last.ToString()) - .Add(" ") + .Add("SELECT TOP (") + .Add(limitParameter) + .Add(") ") .Add(StringHelper.Join(", ", columnsOrAliases)) .Add(" FROM (") .Add(select) @@ -88,10 +94,12 @@ AppendSortExpressions(aliasToColumn, sortExpressions, result); - result.Add(") as __hibernate_sort_row ") - .Add(from) - .Add(") as query WHERE query.__hibernate_sort_row > ") - .Add(offset.ToString()).Add(" ORDER BY query.__hibernate_sort_row"); + result + .Add(") as __hibernate_sort_row ") + .Add(from) + .Add(") as query WHERE query.__hibernate_sort_row > ") + .Add(offsetParameter) + .Add(" ORDER BY query.__hibernate_sort_row"); return result.ToSqlString(); } @@ -106,8 +114,7 @@ return trimmedExpression.Trim(); } - private static void AppendSortExpressions(Dictionary<SqlString, SqlString> aliasToColumn, SqlString[] sortExpressions, - SqlStringBuilder result) + private static void AppendSortExpressions(Dictionary<SqlString, SqlString> aliasToColumn, SqlString[] sortExpressions, SqlStringBuilder result) { for (int i = 0; i < sortExpressions.Length; i++) { @@ -256,6 +263,21 @@ { get { return true; } } + + public override bool BindLimitParametersInReverseOrder + { + get { return true; } + } + + public override bool SupportsVariableLimit + { + get { return true; } + } + + public override bool BindLimitParametersFirst + { + get { return true; } + } protected override string GetSelectExistingObject(string name, Table table) { @@ -436,4 +458,3 @@ } } } - Modified: trunk/nhibernate/src/NHibernate.Test/DialectTest/MsSql2005DialectFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/DialectTest/MsSql2005DialectFixture.cs 2010-07-15 15:16:31 UTC (rev 5006) +++ trunk/nhibernate/src/NHibernate.Test/DialectTest/MsSql2005DialectFixture.cs 2010-07-15 16:20:51 UTC (rev 5007) @@ -19,37 +19,37 @@ SqlString str = d.GetLimitString(new SqlString("select distinct c.Contact_Id as Contact1_19_0_, c._Rating as Rating2_19_0_ from dbo.Contact c where COALESCE(c.Rating, 0) > 0 order by c.Rating desc , c.Last_Name , c.First_Name"), 1, 10); System.Console.WriteLine(str); Assert.AreEqual( - "SELECT TOP 10 Contact1_19_0_, Rating2_19_0_ FROM (select distinct c.Contact_Id as Contact1_19_0_, c._Rating as Rating2_19_0_, ROW_NUMBER() OVER(ORDER BY c.Rating DESC, c.Last_Name, c.First_Name) as __hibernate_sort_row from dbo.Contact c where COALESCE(c.Rating, 0) > 0) as query WHERE query.__hibernate_sort_row > 1 ORDER BY query.__hibernate_sort_row", + "SELECT TOP (?) Contact1_19_0_, Rating2_19_0_ FROM (select distinct c.Contact_Id as Contact1_19_0_, c._Rating as Rating2_19_0_, ROW_NUMBER() OVER(ORDER BY c.Rating DESC, c.Last_Name, c.First_Name) as __hibernate_sort_row from dbo.Contact c where COALESCE(c.Rating, 0) > 0) as query WHERE query.__hibernate_sort_row > ? ORDER BY query.__hibernate_sort_row", str.ToString()); str = d.GetLimitString(new SqlString("SELECT fish.id FROM fish"), 1, 10); System.Console.WriteLine(str); Assert.AreEqual( - "SELECT TOP 10 id FROM (SELECT fish.id, ROW_NUMBER() OVER(ORDER BY CURRENT_TIMESTAMP) as __hibernate_sort_row FROM fish) as query WHERE query.__hibernate_sort_row > 1 ORDER BY query.__hibernate_sort_row", + "SELECT TOP (?) id FROM (SELECT fish.id, ROW_NUMBER() OVER(ORDER BY CURRENT_TIMESTAMP) as __hibernate_sort_row FROM fish) as query WHERE query.__hibernate_sort_row > ? ORDER BY query.__hibernate_sort_row", str.ToString()); str = d.GetLimitString(new SqlString("SELECT DISTINCT fish_.id FROM fish fish_"), 1, 10); System.Console.WriteLine(str); Assert.AreEqual( - "SELECT TOP 10 id FROM (SELECT DISTINCT fish_.id, ROW_NUMBER() OVER(ORDER BY CURRENT_TIMESTAMP) as __hibernate_sort_row FROM fish fish_) as query WHERE query.__hibernate_sort_row > 1 ORDER BY query.__hibernate_sort_row", + "SELECT TOP (?) id FROM (SELECT DISTINCT fish_.id, ROW_NUMBER() OVER(ORDER BY CURRENT_TIMESTAMP) as __hibernate_sort_row FROM fish fish_) as query WHERE query.__hibernate_sort_row > ? ORDER BY query.__hibernate_sort_row", str.ToString()); str = d.GetLimitString(new SqlString("SELECT DISTINCT fish_.id as ixx9_ FROM fish fish_"), 1, 10); System.Console.WriteLine(str); Assert.AreEqual( - "SELECT TOP 10 ixx9_ FROM (SELECT DISTINCT fish_.id as ixx9_, ROW_NUMBER() OVER(ORDER BY CURRENT_TIMESTAMP) as __hibernate_sort_row FROM fish fish_) as query WHERE query.__hibernate_sort_row > 1 ORDER BY query.__hibernate_sort_row", + "SELECT TOP (?) ixx9_ FROM (SELECT DISTINCT fish_.id as ixx9_, ROW_NUMBER() OVER(ORDER BY CURRENT_TIMESTAMP) as __hibernate_sort_row FROM fish fish_) as query WHERE query.__hibernate_sort_row > ? ORDER BY query.__hibernate_sort_row", str.ToString()); str = d.GetLimitString(new SqlString("SELECT * FROM fish ORDER BY name"), 5, 15); System.Console.WriteLine(str); Assert.AreEqual( - "SELECT TOP 15 * FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY name) as __hibernate_sort_row FROM fish) as query WHERE query.__hibernate_sort_row > 5 ORDER BY query.__hibernate_sort_row", + "SELECT TOP (?) * FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY name) as __hibernate_sort_row FROM fish) as query WHERE query.__hibernate_sort_row > ? ORDER BY query.__hibernate_sort_row", str.ToString()); str = d.GetLimitString(new SqlString("SELECT fish.id, fish.name FROM fish ORDER BY name DESC"), 7, 28); System.Console.WriteLine(str); Assert.AreEqual( - "SELECT TOP 28 id, name FROM (SELECT fish.id, fish.name, ROW_NUMBER() OVER(ORDER BY fish.name DESC) as __hibernate_sort_row FROM fish) as query WHERE query.__hibernate_sort_row > 7 ORDER BY query.__hibernate_sort_row", + "SELECT TOP (?) id, name FROM (SELECT fish.id, fish.name, ROW_NUMBER() OVER(ORDER BY fish.name DESC) as __hibernate_sort_row FROM fish) as query WHERE query.__hibernate_sort_row > ? ORDER BY query.__hibernate_sort_row", str.ToString()); str = @@ -57,25 +57,25 @@ new SqlString("SELECT * FROM fish LEFT JOIN (SELECT * FROM meat ORDER BY weight) AS t ORDER BY name DESC"), 10, 20); System.Console.WriteLine(str); Assert.AreEqual( - "SELECT TOP 20 * FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY name DESC) as __hibernate_sort_row FROM fish LEFT JOIN (SELECT * FROM meat ORDER BY weight) AS t) as query WHERE query.__hibernate_sort_row > 10 ORDER BY query.__hibernate_sort_row", + "SELECT TOP (?) * FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY name DESC) as __hibernate_sort_row FROM fish LEFT JOIN (SELECT * FROM meat ORDER BY weight) AS t) as query WHERE query.__hibernate_sort_row > ? ORDER BY query.__hibernate_sort_row", str.ToString()); str = d.GetLimitString(new SqlString("SELECT *, (SELECT COUNT(1) FROM fowl WHERE fish_id = fish.id) AS some_count FROM fish"), 1, 10); System.Console.WriteLine(str); Assert.AreEqual( - "SELECT TOP 10 *, some_count FROM (SELECT *, (SELECT COUNT(1) FROM fowl WHERE fish_id = fish.id) AS some_count, ROW_NUMBER() OVER(ORDER BY CURRENT_TIMESTAMP) as __hibernate_sort_row FROM fish) as query WHERE query.__hibernate_sort_row > 1 ORDER BY query.__hibernate_sort_row", + "SELECT TOP (?) *, some_count FROM (SELECT *, (SELECT COUNT(1) FROM fowl WHERE fish_id = fish.id) AS some_count, ROW_NUMBER() OVER(ORDER BY CURRENT_TIMESTAMP) as __hibernate_sort_row FROM fish) as query WHERE query.__hibernate_sort_row > ? ORDER BY query.__hibernate_sort_row", str.ToString()); str = d.GetLimitString(new SqlString("SELECT * FROM fish WHERE scales = ", Parameter.Placeholder), 1, 10); System.Console.WriteLine(str); Assert.AreEqual( - "SELECT TOP 10 * FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY CURRENT_TIMESTAMP) as __hibernate_sort_row FROM fish WHERE scales = ?) as query WHERE query.__hibernate_sort_row > 1 ORDER BY query.__hibernate_sort_row", + "SELECT TOP (?) * FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY CURRENT_TIMESTAMP) as __hibernate_sort_row FROM fish WHERE scales = ?) as query WHERE query.__hibernate_sort_row > ? ORDER BY query.__hibernate_sort_row", str.ToString()); str = d.GetLimitString(new SqlString("SELECT f.Type, COUNT(DISTINCT f.Name) AS Name FROM Fish f GROUP BY f.Type ORDER BY COUNT(DISTINCT f.Name)"), 1, 10); System.Console.WriteLine(str); Assert.AreEqual( - "SELECT TOP 10 Type, Name FROM (SELECT f.Type, COUNT(DISTINCT f.Name) AS Name, ROW_NUMBER() OVER(ORDER BY COUNT(DISTINCT f.Name)) as __hibernate_sort_row FROM Fish f GROUP BY f.Type) as query WHERE query.__hibernate_sort_row > 1 ORDER BY query.__hibernate_sort_row", + "SELECT TOP (?) Type, Name FROM (SELECT f.Type, COUNT(DISTINCT f.Name) AS Name, ROW_NUMBER() OVER(ORDER BY COUNT(DISTINCT f.Name)) as __hibernate_sort_row FROM Fish f GROUP BY f.Type) as query WHERE query.__hibernate_sort_row > ? ORDER BY query.__hibernate_sort_row", str.ToString()); } @@ -97,14 +97,14 @@ SqlString result = d.GetLimitString(new SqlString("select concat(a.Description,', ', a.Description) as desc from Animal a"), 1, 10); System.Console.WriteLine(result); - Assert.AreEqual("SELECT TOP 10 desc FROM (select concat(a.Description,', ', a.Description) as desc, ROW_NUMBER() OVER(ORDER BY CURRENT_TIMESTAMP) as __hibernate_sort_row from Animal a) as query WHERE query.__hibernate_sort_row > 1 ORDER BY query.__hibernate_sort_row", result.ToString()); + Assert.AreEqual("SELECT TOP (?) desc FROM (select concat(a.Description,', ', a.Description) as desc, ROW_NUMBER() OVER(ORDER BY CURRENT_TIMESTAMP) as __hibernate_sort_row from Animal a) as query WHERE query.__hibernate_sort_row > ? ORDER BY query.__hibernate_sort_row", result.ToString()); // The test use the function "cast" because cast need the keyWork "as" too SqlString str = d.GetLimitString(new SqlString("SELECT fish.id, cast('astring, with,comma' as string) as bar FROM fish"), 1, 10); System.Console.WriteLine(str); Assert.AreEqual( - "SELECT TOP 10 id, bar FROM (SELECT fish.id, cast('astring, with,comma' as string) as bar, ROW_NUMBER() OVER(ORDER BY CURRENT_TIMESTAMP) as __hibernate_sort_row FROM fish) as query WHERE query.__hibernate_sort_row > 1 ORDER BY query.__hibernate_sort_row", + "SELECT TOP (?) id, bar FROM (SELECT fish.id, cast('astring, with,comma' as string) as bar, ROW_NUMBER() OVER(ORDER BY CURRENT_TIMESTAMP) as __hibernate_sort_row FROM fish) as query WHERE query.__hibernate_sort_row > ? ORDER BY query.__hibernate_sort_row", str.ToString()); } [Test] Modified: trunk/nhibernate/src/NHibernate.Test/Pagination/CustomMsSqlDriver.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Pagination/CustomMsSqlDriver.cs 2010-07-15 15:16:31 UTC (rev 5006) +++ trunk/nhibernate/src/NHibernate.Test/Pagination/CustomMsSqlDriver.cs 2010-07-15 16:20:51 UTC (rev 5007) @@ -22,11 +22,11 @@ int offset = (int)((IDataParameter)command.Parameters[0]).Value; int limit = (int)((IDataParameter)command.Parameters[1]).Value; - Assert.That(command.CommandText.ToLower().Contains("top " + limit), - "Expected string containing 'top " + limit + "', but got " + command.CommandText); + Assert.That(command.CommandText.ToLower().Contains("top (@p0)"), + "Expected string containing 'top (@p0)', but got " + command.CommandText); - Assert.That(command.CommandText.ToLower().Contains("hibernate_sort_row > " + offset), - "Expected string containing 'hibernate_sort_row > " + offset + "', but got " + command.CommandText); + Assert.That(command.CommandText.ToLower().Contains("hibernate_sort_row > @p1"), + "Expected string containing 'hibernate_sort_row > @p1', but got " + command.CommandText); } base.OnBeforePrepare(command); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jul...@us...> - 2010-07-19 14:59:35
|
Revision: 5013 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5013&view=rev Author: julian-maughan Date: 2010-07-19 14:59:28 +0000 (Mon, 19 Jul 2010) Log Message: ----------- Updated SQLiteDialect to explicitly declare that it does not support limit parameters (SupportsVariableLimit = false). This makes it consistent with the implementation of GetLimitString which does not use parameters when paging, and fixes the problem of non-limit parameter types getting mixed up (ref. NH-2195, NH-2129) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/DomainClass.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/SQLiteMultiCriteriaTest.cs Modified: trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs 2010-07-19 14:46:08 UTC (rev 5012) +++ trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs 2010-07-19 14:59:28 UTC (rev 5013) @@ -1,9 +1,9 @@ using System.Data; +using System.Data.Common; using System.Text; using NHibernate.Dialect.Function; using NHibernate.SqlCommand; using NHibernate.Util; -using System.Data.Common; namespace NHibernate.Dialect { @@ -114,6 +114,11 @@ get { return false; } } + public override bool SupportsVariableLimit + { + get { return false; } + } + public override bool SupportsIdentityColumns { get { return true; } @@ -138,19 +143,19 @@ public override string Qualify(string catalog, string schema, string table) { StringBuilder qualifiedName = new StringBuilder(); - bool quoted = false; + bool quoted = false; - if (!string.IsNullOrEmpty(catalog)) + if (!string.IsNullOrEmpty(catalog)) { - if (catalog.StartsWith(OpenQuote.ToString())) - { - catalog = catalog.Substring(1, catalog.Length - 1); - quoted = true; - } - if (catalog.EndsWith(CloseQuote.ToString())) + if (catalog.StartsWith(OpenQuote.ToString())) { - catalog = catalog.Substring(0, catalog.Length - 1); - quoted = true; + catalog = catalog.Substring(1, catalog.Length - 1); + quoted = true; + } + if (catalog.EndsWith(CloseQuote.ToString())) + { + catalog = catalog.Substring(0, catalog.Length - 1); + quoted = true; } qualifiedName.Append(catalog).Append(StringHelper.Underscore); } @@ -158,32 +163,32 @@ { if (schema.StartsWith(OpenQuote.ToString())) { - schema = schema.Substring(1, schema.Length - 1); - quoted = true; + schema = schema.Substring(1, schema.Length - 1); + quoted = true; } - if (schema.EndsWith(CloseQuote.ToString())) - { - schema = schema.Substring(0, schema.Length - 1); - quoted = true; - } - qualifiedName.Append(schema).Append(StringHelper.Underscore); + if (schema.EndsWith(CloseQuote.ToString())) + { + schema = schema.Substring(0, schema.Length - 1); + quoted = true; + } + qualifiedName.Append(schema).Append(StringHelper.Underscore); } if (table.StartsWith(OpenQuote.ToString())) { - table = table.Substring(1, table.Length - 1); - quoted = true; + table = table.Substring(1, table.Length - 1); + quoted = true; } - if (table.EndsWith(CloseQuote.ToString())) - { - table = table.Substring(0, table.Length - 1); - quoted = true; - } + if (table.EndsWith(CloseQuote.ToString())) + { + table = table.Substring(0, table.Length - 1); + quoted = true; + } - string name = qualifiedName.Append(table).ToString(); - if (quoted) - return OpenQuote + name + CloseQuote; - return name; + string name = qualifiedName.Append(table).ToString(); + if (quoted) + return OpenQuote + name + CloseQuote; + return name; } @@ -215,4 +220,4 @@ return pagingBuilder.ToSqlString(); } } -} +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/DomainClass.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/DomainClass.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/DomainClass.cs 2010-07-19 14:59:28 UTC (rev 5013) @@ -0,0 +1,29 @@ +using System; + +namespace NHibernate.Test.NHSpecificTest.NH2195 +{ + public class DomainClass + { + private string stringData; + private int intData; + private int id; + + public int Id + { + get { return id; } + set { id = value; } + } + + public string StringData + { + get { return stringData; } + set { stringData = value; } + } + + public int IntData + { + get { return intData; } + set { intData = value; } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/Mappings.hbm.xml 2010-07-19 14:59:28 UTC (rev 5013) @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping + xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2195" + default-access="field.camelcase" + default-lazy="false"> + + <class name="DomainClass"> + <id name="Id"> + <generator class="assigned" /> + </id> + <property name="StringData" /> + <property name="IntData" /> + </class> + +</hibernate-mapping> \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/SQLiteMultiCriteriaTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/SQLiteMultiCriteriaTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/SQLiteMultiCriteriaTest.cs 2010-07-19 14:59:28 UTC (rev 5013) @@ -0,0 +1,145 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using NHibernate.Criterion; +using NHibernate.Dialect; +using NHibernate.Tool.hbm2ddl; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2195 +{ + [TestFixture] + public class SQLiteMultiCriteriaTest : BugTestCase + { + protected override void OnSetUp() + { + base.OnSetUp(); + using (ISession session = this.OpenSession()) + { + DomainClass entity = new DomainClass(); + entity.Id = 1; + entity.StringData = "John Doe"; + entity.IntData = 1; + session.Save(entity); + + entity = new DomainClass(); + entity.Id = 2; + entity.StringData = "Jane Doe"; + entity.IntData = 2; + session.Save(entity); + session.Flush(); + } + } + + private object SchemaExport(NHibernate.Cfg.Configuration cfg) + { + throw new NotImplementedException(); + } + + protected override void OnTearDown() + { + base.OnTearDown(); + using (ISession session = this.OpenSession()) + { + string hql = "from System.Object"; + session.Delete(hql); + session.Flush(); + } + } + + protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect) + { + return dialect as SQLiteDialect != null; + } + + [Test] + public void SingleCriteriaQueriesWithIntsShouldExecuteCorrectly() + { + // Test querying IntData + using (ISession session = this.OpenSession()) + { + ICriteria criteriaWithPagination = session.CreateCriteria<DomainClass>(); + criteriaWithPagination.Add(Expression.Le("IntData",2)); + ICriteria criteriaWithRowCount = CriteriaTransformer.Clone(criteriaWithPagination); + criteriaWithPagination.SetFirstResult(0).SetMaxResults(1); + criteriaWithRowCount.SetProjection(Projections.RowCountInt64()); + + IList<DomainClass> list = criteriaWithPagination.List<DomainClass>(); + + Assert.AreEqual(2, criteriaWithRowCount.UniqueResult<long>()); + Assert.AreEqual(1, list.Count); + } + } + + [Test] + public void SingleCriteriaQueriesWithStringsShouldExecuteCorrectly() + { + // Test querying StringData + using (ISession session = this.OpenSession()) + { + ICriteria criteriaWithPagination = session.CreateCriteria<DomainClass>(); + criteriaWithPagination.Add(Expression.Like("StringData", "%Doe%")); + ICriteria criteriaWithRowCount = CriteriaTransformer.Clone(criteriaWithPagination); + criteriaWithPagination.SetFirstResult(0).SetMaxResults(1); + criteriaWithRowCount.SetProjection(Projections.RowCountInt64()); + + IList<DomainClass> list = criteriaWithPagination.List<DomainClass>(); + + Assert.AreEqual(2, criteriaWithRowCount.UniqueResult<long>()); + Assert.AreEqual(1, list.Count); + } + } + + [Test] + public void MultiCriteriaQueriesWithIntsShouldExecuteCorrectly() + { + // Test querying IntData + using (ISession session = this.OpenSession()) + { + ICriteria criteriaWithPagination = session.CreateCriteria<DomainClass>(); + criteriaWithPagination.Add(Expression.Le("IntData", 2)); + ICriteria criteriaWithRowCount = CriteriaTransformer.Clone(criteriaWithPagination); + criteriaWithPagination.SetFirstResult(0).SetMaxResults(1); + criteriaWithRowCount.SetProjection(Projections.RowCountInt64()); + + IMultiCriteria multiCriteria = session.CreateMultiCriteria(); + multiCriteria.Add(criteriaWithPagination); + multiCriteria.Add(criteriaWithRowCount); + + IList results = multiCriteria.List(); + long numResults = (long)((IList)results[1])[0]; + IList list = (IList)results[0]; + + Assert.AreEqual(2, criteriaWithRowCount.UniqueResult<long>()); + Assert.AreEqual(1, list.Count); + } + } + + [Test] + public void MultiCriteriaQueriesWithStringsShouldExecuteCorrectly() + { + // Test querying StringData + using (ISession session = this.OpenSession()) + { + ICriteria criteriaWithPagination = session.CreateCriteria<DomainClass>(); + criteriaWithPagination.Add(Expression.Like("StringData", "%Doe%")); + ICriteria criteriaWithRowCount = CriteriaTransformer.Clone(criteriaWithPagination); + criteriaWithPagination.SetFirstResult(0).SetMaxResults(1); + criteriaWithRowCount.SetProjection(Projections.RowCountInt64()); + + IMultiCriteria multiCriteria = session.CreateMultiCriteria(); + multiCriteria.Add(criteriaWithPagination); + multiCriteria.Add(criteriaWithRowCount); + + IList results = multiCriteria.List(); + + long numResults = (long)((IList)results[1])[0]; + IList list = (IList)results[0]; + + Assert.AreEqual(2, criteriaWithRowCount.UniqueResult<long>()); + Assert.AreEqual(1, list.Count); + } + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-19 14:46:08 UTC (rev 5012) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-19 14:59:28 UTC (rev 5013) @@ -738,6 +738,8 @@ <Compile Include="NHSpecificTest\NH2113\Model.cs" /> <Compile Include="NHSpecificTest\NH2192\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2192\Model.cs" /> + <Compile Include="NHSpecificTest\NH2195\DomainClass.cs" /> + <Compile Include="NHSpecificTest\NH2195\SQLiteMultiCriteriaTest.cs" /> <Compile Include="NHSpecificTest\NH2201\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2201\Model.cs" /> <Compile Include="NHSpecificTest\NH2230\Domain.cs" /> @@ -1602,6 +1604,7 @@ <Compile Include="VersionTest\VersionFixture.cs" /> <None Include="Component\Basic\User.hbm.xml" /> <None Include="NHSpecificTest\NH2061\Mappings.hbm.xml" /> + <EmbeddedResource Include="NHSpecificTest\NH2195\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="CompositeCollection\BaseClassA.hbm.xml" /> @@ -1684,6 +1687,7 @@ <Folder Include="Component" /> <Folder Include="Component\Basic" /> <Folder Include="NHSpecificTest\NH2061" /> + <Folder Include="NHSpecificTest\NH2195" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="NHSpecificTest\NH386\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jul...@us...> - 2010-07-20 00:54:46
|
Revision: 5017 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5017&view=rev Author: julian-maughan Date: 2010-07-20 00:54:39 +0000 (Tue, 20 Jul 2010) Log Message: ----------- Added support for many-to-one mappings that include a formula (ref. NH-2117) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToOne.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ColumnsBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ValuePropertyBinder.cs trunk/nhibernate/src/NHibernate/SqlCommand/ANSIJoinFragment.cs trunk/nhibernate/src/NHibernate/SqlCommand/SelectFragment.cs trunk/nhibernate/src/NHibernate/nhibernate-mapping.xsd trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/ trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/Address.cs trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/AddressId.cs trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/Customer.cs trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/Customer.hbm.xml trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/TypedManyToOneTest.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToOne.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToOne.cs 2010-07-20 00:34:18 UTC (rev 5016) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToOne.cs 2010-07-20 00:54:39 UTC (rev 5017) @@ -109,6 +109,14 @@ #endregion + /// <summary> + /// Columns and Formulas, in declared order + /// </summary> + public IEnumerable<object> ColumnsAndFormulas + { + get { return Columns.Cast<object>().Concat(Formulas.Cast<object>()); } + } + public HbmLaziness? Lazy { get { return lazySpecified ? lazy : (HbmLaziness?) null;} Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs 2010-07-20 00:34:18 UTC (rev 5016) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs 2010-07-20 00:54:39 UTC (rev 5017) @@ -18,6 +18,8 @@ } compositeId = new Component(rootClass); + compositeId.IsKey = true; + rootClass.Identifier = compositeId; if (idSchema.name == null) Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ColumnsBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ColumnsBinder.cs 2010-07-20 00:34:18 UTC (rev 5016) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ColumnsBinder.cs 2010-07-20 00:54:39 UTC (rev 5017) @@ -15,25 +15,29 @@ { this.value = value; } - + + public void Bind(HbmColumn column, bool isNullable) + { + this.BindColumn(column, value.Table, isNullable); + } + public void Bind(IEnumerable<HbmColumn> columns, bool isNullable, Func<HbmColumn> defaultColumnDelegate) { var table = value.Table; - int colIndex = 0; foreach (var hbmColumn in columns) { - BindColumn(hbmColumn, table, colIndex++, isNullable); + BindColumn(hbmColumn, table, isNullable); } if (value.ColumnSpan == 0 && defaultColumnDelegate != null) { - BindColumn(defaultColumnDelegate(), table, colIndex, isNullable); + BindColumn(defaultColumnDelegate(), table, isNullable); } } - private void BindColumn(HbmColumn hbmColumn, Table table, int colIndex, bool isNullable) + private void BindColumn(HbmColumn hbmColumn, Table table, bool isNullable) { - var col = new Column {Value = value, TypeIndex = colIndex}; + var col = new Column {Value = value}; BindColumn(hbmColumn, col, isNullable); if (table != null) Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ValuePropertyBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ValuePropertyBinder.cs 2010-07-20 00:34:18 UTC (rev 5016) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ValuePropertyBinder.cs 2010-07-20 00:54:39 UTC (rev 5017) @@ -28,7 +28,7 @@ var formulas = propertyMapping.Formulas.ToArray(); if (formulas.Length > 0) { - BindFormula(formulas); + BindFormulas(formulas); } else { @@ -56,7 +56,7 @@ var formulas = element.Formulas.ToArray(); if (formulas.Length > 0) { - BindFormula(formulas); + BindFormulas(formulas); } else { @@ -76,14 +76,6 @@ } } - private void BindFormula(IEnumerable<HbmFormula> formulas) - { - foreach (var hbmFormula in formulas) - { - value.AddFormula(new Formula { FormulaString = hbmFormula.Text.LinesToString() }); - } - } - public void BindSimpleValue(HbmKey propertyMapping, string propertyPath, bool isNullable) { new ColumnsBinder(value, Mappings).Bind(propertyMapping.Columns, isNullable, @@ -103,7 +95,7 @@ var formulas = manyToManyMapping.Formulas.ToArray(); if (formulas.Length > 0) { - BindFormula(formulas); + BindFormulas(formulas); } else { @@ -159,7 +151,7 @@ var formulas = mapKeyMapping.Formulas.ToArray(); if (formulas.Length > 0) { - BindFormula(formulas); + BindFormulas(formulas); } else { @@ -173,27 +165,28 @@ } } - public void BindSimpleValue(HbmManyToOne manyToManyMapping, string propertyPath, bool isNullable) + public void BindSimpleValue(HbmManyToOne manyToOneMapping, string propertyPath, bool isNullable) { - var formulas = manyToManyMapping.Formulas.ToArray(); - if (formulas.Length > 0) + ColumnsBinder binder = new ColumnsBinder(value, Mappings); + object[] columnsAndFormulas = manyToOneMapping.ColumnsAndFormulas.ToArray(); + + if (columnsAndFormulas.Length > 0) { - BindFormula(formulas); + this.AddColumnsAndOrFormulas(binder, columnsAndFormulas, isNullable); } else { - new ColumnsBinder(value, Mappings).Bind(manyToManyMapping.Columns, isNullable, - () => - new HbmColumn - { - name = mappings.NamingStrategy.PropertyToColumnName(propertyPath), - notnull = manyToManyMapping.notnull, - notnullSpecified = manyToManyMapping.notnullSpecified, - unique = manyToManyMapping.unique, - uniqueSpecified = true, - uniquekey = manyToManyMapping.uniquekey, - index = manyToManyMapping.index - }); + // No formulas or columns, so add default column + binder.Bind(new HbmColumn() + { + name = mappings.NamingStrategy.PropertyToColumnName(propertyPath), + notnull = manyToOneMapping.notnull, + notnullSpecified = manyToOneMapping.notnullSpecified, + unique = manyToOneMapping.unique, + uniqueSpecified = true, + uniquekey = manyToOneMapping.uniquekey, + index = manyToOneMapping.index + }, isNullable); } } @@ -212,7 +205,7 @@ var formulas = mapKeyManyToManyMapping.Formulas.ToArray(); if (formulas.Length > 0) { - BindFormula(formulas); + BindFormulas(formulas); } else { @@ -245,5 +238,34 @@ new HbmColumn {name = mappings.NamingStrategy.PropertyToColumnName(propertyPath),}); } + + /// <summary> + /// Bind columns and formulas in the order in which they were mapped. + /// </summary> + /// <param name="binder"></param> + /// <param name="columnsAndFormulas"></param> + /// <param name="isNullable"></param> + private void AddColumnsAndOrFormulas(ColumnsBinder binder, object[] columnsAndFormulas, bool isNullable) + { + foreach (object item in columnsAndFormulas) + { + if (item.GetType() == typeof(HbmFormula)) + this.BindFormula((HbmFormula)item); + + if (item.GetType() == typeof(HbmColumn)) + binder.Bind((HbmColumn)item, isNullable); + } + } + + private void BindFormula(HbmFormula formula) + { + value.AddFormula(new Formula { FormulaString = formula.Text.LinesToString() }); + } + + private void BindFormulas(IEnumerable<HbmFormula> formulas) + { + foreach (var hbmFormula in formulas) + this.BindFormula(hbmFormula); + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/SqlCommand/ANSIJoinFragment.cs =================================================================== --- trunk/nhibernate/src/NHibernate/SqlCommand/ANSIJoinFragment.cs 2010-07-20 00:34:18 UTC (rev 5016) +++ trunk/nhibernate/src/NHibernate/SqlCommand/ANSIJoinFragment.cs 2010-07-20 00:54:39 UTC (rev 5017) @@ -42,10 +42,6 @@ for (int j = 0; j < fkColumns.Length; j++) { - if (fkColumns[j].IndexOf('.') < 1) - { - throw new AssertionFailure("missing alias"); - } buffer.Add(fkColumns[j] + "=" + alias + StringHelper.Dot + pkColumns[j]); if (j < fkColumns.Length - 1) { Modified: trunk/nhibernate/src/NHibernate/SqlCommand/SelectFragment.cs =================================================================== --- trunk/nhibernate/src/NHibernate/SqlCommand/SelectFragment.cs 2010-07-20 00:34:18 UTC (rev 5016) +++ trunk/nhibernate/src/NHibernate/SqlCommand/SelectFragment.cs 2010-07-20 00:54:39 UTC (rev 5017) @@ -75,7 +75,8 @@ { for (int i = 0; i < columnNames.Length; i++) { - AddColumn(tableAlias, columnNames[i]); + if (columnNames[i] != null) + AddColumn(tableAlias, columnNames[i]); } return this; } @@ -84,7 +85,8 @@ { for (int i = 0; i < columnNames.Length; i++) { - AddColumn(tableAlias, columnNames[i], columnAliases[i]); + if (columnNames[i] != null) + AddColumn(tableAlias, columnNames[i], columnAliases[i]); } return this; } @@ -93,7 +95,8 @@ { for (int i = 0; i < formulas.Length; i++) { - AddFormula(tableAlias, formulas[i], formulaAliases[i]); + if (formulas[i] != null) + AddFormula(tableAlias, formulas[i], formulaAliases[i]); } return this; Modified: trunk/nhibernate/src/NHibernate/nhibernate-mapping.xsd =================================================================== --- trunk/nhibernate/src/NHibernate/nhibernate-mapping.xsd 2010-07-20 00:34:18 UTC (rev 5016) +++ trunk/nhibernate/src/NHibernate/nhibernate-mapping.xsd 2010-07-20 00:54:39 UTC (rev 5017) @@ -865,10 +865,8 @@ <xs:complexType> <xs:sequence> <xs:element ref="meta" minOccurs="0" maxOccurs="unbounded" /> - <xs:choice minOccurs="0" maxOccurs="unbounded"> - <xs:element ref="column" /> - <xs:element ref="formula" /> - </xs:choice> + <xs:element ref="column" minOccurs="0" maxOccurs="unbounded" /> + <xs:element ref="formula" minOccurs="0" maxOccurs="unbounded" /> </xs:sequence> <xs:attribute name="name" use="required" type="xs:string" /> <xs:attribute name="access" type="xs:string" /> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-20 00:34:18 UTC (rev 5016) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-20 00:54:39 UTC (rev 5017) @@ -1487,6 +1487,10 @@ <Compile Include="TransactionTest\TransactionNotificationFixture.cs" /> <Compile Include="TransformTests\AliasToBeanResultTransformerFixture.cs" /> <Compile Include="TransformTests\Simple.cs" /> + <Compile Include="TypedManyToOne\Address.cs" /> + <Compile Include="TypedManyToOne\AddressId.cs" /> + <Compile Include="TypedManyToOne\Customer.cs" /> + <Compile Include="TypedManyToOne\TypedManyToOneTest.cs" /> <Compile Include="TypeParameters\DefaultValueIntegerType.cs" /> <Compile Include="TypeParameters\DefinedTypeForIdFixture.cs" /> <Compile Include="TypeParameters\EntityCustomId.cs" /> @@ -1605,6 +1609,7 @@ <EmbeddedResource Include="Component\Basic\User.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2061\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2195\Mappings.hbm.xml" /> + <EmbeddedResource Include="TypedManyToOne\Customer.hbm.xml" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="CompositeCollection\BaseClassA.hbm.xml" /> @@ -1688,6 +1693,7 @@ <Folder Include="Component\Basic" /> <Folder Include="NHSpecificTest\NH2061" /> <Folder Include="NHSpecificTest\NH2195" /> + <Folder Include="TypedManyToOne" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="NHSpecificTest\NH386\Mappings.hbm.xml" /> Property changes on: trunk/nhibernate/src/NHibernate.Test/TypedManyToOne ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Added: trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/Address.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/Address.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/Address.cs 2010-07-20 00:54:39 UTC (rev 5017) @@ -0,0 +1,15 @@ +using System; + +namespace NHibernate.Test.TypedManyToOne +{ + [Serializable] + public class Address + { + public virtual AddressId AddressId {get; set;} + public virtual string Street { get; set; } + public virtual string City { get; set; } + public virtual string State { get; set; } + public virtual string Zip { get; set; } + public virtual Customer Customer { get; set; } + } +} Added: trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/AddressId.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/AddressId.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/AddressId.cs 2010-07-20 00:54:39 UTC (rev 5017) @@ -0,0 +1,55 @@ +using System; + +namespace NHibernate.Test.TypedManyToOne +{ + [Serializable] + public class AddressId + { + public virtual String Type { get; set; } + public virtual String Id { get; set; } + private int? requestedHash; + + public AddressId(String type, String id) + { + Id = id; + Type = type; + } + + public AddressId() { } + + public override bool Equals(object obj) + { + return Equals(obj as AddressId); + } + + public virtual bool Equals(AddressId other) + { + if (ReferenceEquals(null, other)) + { + return false; + } + if (ReferenceEquals(this, other)) + { + return true; + } + return other.Id == Id && Equals(other.Type, Type); + } + + public override int GetHashCode() + { + if (!requestedHash.HasValue) + { + unchecked + { + requestedHash = (Id.GetHashCode() * 397) ^ Type.GetHashCode(); + } + } + return requestedHash.Value; + } + + public override string ToString() + { + return Type + '#' + Id; + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/Customer.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/Customer.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/Customer.cs 2010-07-20 00:54:39 UTC (rev 5017) @@ -0,0 +1,13 @@ +using System; + +namespace NHibernate.Test.TypedManyToOne +{ + [Serializable] + public class Customer + { + public virtual string CustomerId { get; set; } + public virtual string Name {get; set;} + public virtual Address BillingAddress {get; set;} + public virtual Address ShippingAddress {get; set;} + } +} Added: trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/Customer.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/Customer.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/Customer.hbm.xml 2010-07-20 00:54:39 UTC (rev 5017) @@ -0,0 +1,79 @@ +<?xml version="1.0" encoding="utf-8"?> + +<!-- + + Shows how to map a one-to-many relationship in the relational + schema to "typed" one-to-one associations in the object model. + We map the Address class twice, with different entity names, + specifying a filtering condition in each mapping. The typed + associations then reference the named entities. + +--> + +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.TypedManyToOne" + assembly="NHibernate.Test"> + + <class name="Customer" + select-before-update="true" + dynamic-update="true"> + + <id name="CustomerId"> + <generator class="assigned"/> + </id> + + <property name="Name" not-null="true"/> + + <many-to-one name="BillingAddress" entity-name="BillingAddress" cascade="persist,save-update,delete" fetch="join"> + <column name="BillingAddressId" /> + <formula>(case when Name='blah' then 'SHIPPING' else 'BILLING' end)</formula> + </many-to-one> + + <many-to-one name="ShippingAddress" entity-name="ShippingAddress" cascade="persist,save-update,delete" fetch="join"> + <column name="ShippingAddressId"/> + <formula>'SHIPPING'</formula> + </many-to-one> + + </class> + + <class name="Address" + table="Address" + entity-name="BillingAddress" + where="add_type='BILLING'" + check="add_type in ('BILLING', 'SHIPPING')" + select-before-update="true" + dynamic-update="true"> + + <composite-id name="AddressId" class="AddressId"> + <key-property name="Id"/> + <key-property name="Type" column="add_type" /> + </composite-id> + + <property name="Street" not-null="true"/> + <property name="City" not-null="true"/> + <property name="State" not-null="true"/> + <property name="Zip" not-null="true"/> + + </class> + + <class name="Address" + table="Address" + entity-name="ShippingAddress" + where="add_type='SHIPPING'" + check="add_type in ('BILLING', 'SHIPPING')" + select-before-update="true" + dynamic-update="true"> + + <composite-id name="AddressId" class="AddressId"> + <key-property name="Id"/> + <key-property name="Type" column="add_type" /> + </composite-id> + + <property name="Street" not-null="true"/> + <property name="City" not-null="true"/> + <property name="State" not-null="true"/> + <property name="Zip" not-null="true"/> + + </class> + +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/TypedManyToOneTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/TypedManyToOneTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/TypedManyToOne/TypedManyToOneTest.cs 2010-07-20 00:54:39 UTC (rev 5017) @@ -0,0 +1,131 @@ +using System.Collections; +using NUnit.Framework; + +namespace NHibernate.Test.TypedManyToOne +{ + [TestFixture] + public class TypedManyToOneTest : TestCase + { + protected override string MappingsAssembly + { + get { return "NHibernate.Test"; } + } + + protected override IList Mappings + { + get { return new[] { "TypedManyToOne.Customer.hbm.xml" }; } + } + + [Test] + public void TestCreateQuery() + { + var cust = new Customer(); + cust.CustomerId = "abc123"; + cust.Name = "Matt"; + + var ship = new Address(); + ship.Street = "peachtree rd"; + ship.State = "GA"; + ship.City = "ATL"; + ship.Zip = "30326"; + ship.AddressId = new AddressId("SHIPPING", "xyz123"); + ship.Customer = cust; + + var bill = new Address(); + bill.Street = "peachtree rd"; + bill.State = "GA"; + bill.City = "ATL"; + bill.Zip = "30326"; + bill.AddressId = new AddressId("BILLING", "xyz123"); + bill.Customer = cust; + + cust.BillingAddress = bill; + cust.ShippingAddress = ship; + + using(ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + s.Persist(cust); + t.Commit(); + } + + using(ISession s = sessions.OpenSession()) + using(ITransaction t = s.BeginTransaction()) + { + try + { + IList results = s.CreateQuery("from Customer cust left join fetch cust.BillingAddress where cust.CustomerId='abc123'").List(); + //IList results = s.CreateQuery("from Customer cust left join fetch cust.BillingAddress left join fetch cust.ShippingAddress").List(); + cust = (Customer)results[0]; + Assert.That(NHibernateUtil.IsInitialized(cust.ShippingAddress), Is.False); + Assert.That(NHibernateUtil.IsInitialized(cust.BillingAddress), Is.True); + Assert.That(cust.BillingAddress.Zip, Is.EqualTo("30326")); + Assert.That(cust.ShippingAddress.Zip, Is.EqualTo("30326")); + Assert.That(cust.BillingAddress.AddressId.Type, Is.EqualTo("BILLING")); + Assert.That(cust.ShippingAddress.AddressId.Type, Is.EqualTo("SHIPPING")); + t.Commit(); + } + catch + { + throw; + } + } + + using(ISession s = sessions.OpenSession()) + using(ITransaction t = s.BeginTransaction()) + { + try + { + s.SaveOrUpdate(cust); + ship = cust.ShippingAddress; + cust.ShippingAddress = null; + s.Delete("ShippingAddress", ship); + s.Flush(); + + Assert.That(s.Get("ShippingAddress", ship.AddressId), Is.Null); + s.Delete(cust); + + t.Commit(); + } + catch + { + throw; + } + } + } + + [Test] + public void TestCreateQueryNull() + { + var cust = new Customer(); + cust.CustomerId = "xyz123"; + cust.Name = "Matt"; + + using(ISession s = sessions.OpenSession()) + using(ITransaction t = s.BeginTransaction()) + { + s.Persist(cust); + t.Commit(); + } + + using(ISession s = sessions.OpenSession()) + using(ITransaction t = s.BeginTransaction()) + { + try + { + IList results = s.CreateQuery("from Customer cust left join fetch cust.BillingAddress where cust.CustomerId='xyz123'").List(); + //IList results = s.CreateQuery("from Customer cust left join fetch cust.BillingAddress left join fetch cust.ShippingAddress").List(); + cust = (Customer)results[0]; + Assert.That(cust.ShippingAddress, Is.Null); + Assert.That(cust.BillingAddress, Is.Null); + s.Delete(cust); + t.Commit(); + } + catch + { + throw; + } + } + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-07-20 16:43:15
|
Revision: 5019 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5019&view=rev Author: fabiomaulo Date: 2010-07-20 16:43:09 +0000 (Tue, 20 Jul 2010) Log Message: ----------- Fix NH-2102 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/Property.cs trunk/nhibernate/src/NHibernate/Tuple/Entity/EntityMetamodel.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2102/Fixture.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/Property.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/Property.cs 2010-07-20 13:54:08 UTC (rev 5018) +++ trunk/nhibernate/src/NHibernate/Mapping/Property.cs 2010-07-20 16:43:09 UTC (rev 5019) @@ -294,5 +294,10 @@ // true here for the case of many-to-one and one-to-one // with lazy="no-proxy" public bool UnwrapProxy { get; set; } + + public bool IsEntityRelation + { + get { return (Value as ToOne) != null; } + } } } Modified: trunk/nhibernate/src/NHibernate/Tuple/Entity/EntityMetamodel.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Tuple/Entity/EntityMetamodel.cs 2010-07-20 13:54:08 UTC (rev 5018) +++ trunk/nhibernate/src/NHibernate/Tuple/Entity/EntityMetamodel.cs 2010-07-20 16:43:09 UTC (rev 5019) @@ -128,14 +128,17 @@ foreach (Mapping.Property prop in persistentClass.PropertyClosureIterator) { + // NH: A lazy property is a simple property marked with lazy=true or a relation (in this case many-to-one or one-to-one marked as "no-proxy") + bool lazyProperty = prop.IsLazy && lazyAvailable && (!prop.IsEntityRelation || prop.UnwrapProxy); + if (prop == persistentClass.Version) { tempVersionProperty = i; - properties[i] = PropertyFactory.BuildVersionProperty(prop, lazyAvailable); + properties[i] = PropertyFactory.BuildVersionProperty(prop, lazyProperty); } else { - properties[i] = PropertyFactory.BuildStandardProperty(prop, lazyAvailable); + properties[i] = PropertyFactory.BuildStandardProperty(prop, lazyProperty); } if (prop.IsNaturalIdentifier) @@ -148,7 +151,6 @@ foundNonIdentifierPropertyNamedId = true; } - bool lazyProperty = prop.IsLazy && lazyAvailable; if (lazyProperty) { hasLazy = true; Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2102/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2102/Fixture.cs 2010-07-20 13:54:08 UTC (rev 5018) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2102/Fixture.cs 2010-07-20 16:43:09 UTC (rev 5019) @@ -1,17 +1,16 @@ -using NHibernate.ByteCode.Castle; using NHibernate.Cfg; using NUnit.Framework; using SharpTestsEx; namespace NHibernate.Test.NHSpecificTest.NH2102 { - [TestFixture, Ignore("Not fixed yet.")] + [TestFixture] public class Fixture : BugTestCase { protected override void Configure(Configuration configuration) { configuration.SetProperty(Environment.ProxyFactoryFactoryClass, - typeof(ProxyFactoryFactory).AssemblyQualifiedName); + typeof(ByteCode.Castle.ProxyFactoryFactory).AssemblyQualifiedName); } [Test] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-07-20 17:45:14
|
Revision: 5020 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5020&view=rev Author: fabiomaulo Date: 2010-07-20 17:45:07 +0000 (Tue, 20 Jul 2010) Log Message: ----------- Fix NH-2093 (thanks to Johannes Gustafsson for the TEST) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Event/Default/AbstractSaveEventListener.cs trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs trunk/nhibernate/src/NHibernate/Intercept/DefaultFieldInterceptor.cs trunk/nhibernate/src/NHibernate/Intercept/FieldInterceptionHelper.cs trunk/nhibernate/src/NHibernate/Intercept/IFieldInterceptor.cs trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs trunk/nhibernate/src/NHibernate/Proxy/NHibernateProxyHelper.cs trunk/nhibernate/src/NHibernate/Tuple/Entity/PocoEntityTuplizer.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Model.cs Modified: trunk/nhibernate/src/NHibernate/Event/Default/AbstractSaveEventListener.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Event/Default/AbstractSaveEventListener.cs 2010-07-20 16:43:09 UTC (rev 5019) +++ trunk/nhibernate/src/NHibernate/Event/Default/AbstractSaveEventListener.cs 2010-07-20 17:45:07 UTC (rev 5020) @@ -292,7 +292,7 @@ { if (FieldInterceptionHelper.IsInstrumented(entity)) { - IFieldInterceptor interceptor = FieldInterceptionHelper.InjectFieldInterceptor(entity, persister.EntityName, null, null, source); + IFieldInterceptor interceptor = FieldInterceptionHelper.InjectFieldInterceptor(entity, persister.EntityName, persister.GetMappedClass(source.EntityMode), null, null, source); interceptor.MarkDirty(); } } Modified: trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs 2010-07-20 16:43:09 UTC (rev 5019) +++ trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs 2010-07-20 17:45:07 UTC (rev 5020) @@ -16,17 +16,19 @@ private readonly ISet<string> unwrapProxyFieldNames; private readonly ISet<string> loadedUnwrapProxyFieldNames = new HashedSet<string>(); private readonly string entityName; + private readonly System.Type mappedClass; [NonSerialized] private bool initializing; private bool isDirty; - protected internal AbstractFieldInterceptor(ISessionImplementor session, ISet<string> uninitializedFields, ISet<string> unwrapProxyFieldNames, string entityName) + protected internal AbstractFieldInterceptor(ISessionImplementor session, ISet<string> uninitializedFields, ISet<string> unwrapProxyFieldNames, string entityName, System.Type mappedClass) { this.session = session; this.uninitializedFields = uninitializedFields; this.unwrapProxyFieldNames = unwrapProxyFieldNames; this.entityName = entityName; + this.mappedClass = mappedClass; } #region IFieldInterceptor Members @@ -65,6 +67,16 @@ isDirty = false; } + public string EntityName + { + get { return entityName; } + } + + public System.Type MappedClass + { + get { return mappedClass; } + } + #endregion public ISet<string> UninitializedFields @@ -72,11 +84,6 @@ get { return uninitializedFields; } } - public string EntityName - { - get { return entityName; } - } - public bool Initializing { get { return initializing; } Modified: trunk/nhibernate/src/NHibernate/Intercept/DefaultFieldInterceptor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Intercept/DefaultFieldInterceptor.cs 2010-07-20 16:43:09 UTC (rev 5019) +++ trunk/nhibernate/src/NHibernate/Intercept/DefaultFieldInterceptor.cs 2010-07-20 17:45:07 UTC (rev 5020) @@ -5,8 +5,8 @@ { public class DefaultFieldInterceptor : AbstractFieldInterceptor { - public DefaultFieldInterceptor(ISessionImplementor session, ISet<string> uninitializedFields, ISet<string> unwrapProxyFieldNames, string entityName) - : base(session, uninitializedFields, unwrapProxyFieldNames, entityName) + public DefaultFieldInterceptor(ISessionImplementor session, ISet<string> uninitializedFields, ISet<string> unwrapProxyFieldNames, string entityName, System.Type mappedClass) + : base(session, uninitializedFields, unwrapProxyFieldNames, entityName, mappedClass) { } } Modified: trunk/nhibernate/src/NHibernate/Intercept/FieldInterceptionHelper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Intercept/FieldInterceptionHelper.cs 2010-07-20 16:43:09 UTC (rev 5019) +++ trunk/nhibernate/src/NHibernate/Intercept/FieldInterceptionHelper.cs 2010-07-20 17:45:07 UTC (rev 5020) @@ -33,6 +33,7 @@ } public static IFieldInterceptor InjectFieldInterceptor(object entity, string entityName, + System.Type mappedClass, ISet<string> uninitializedFieldNames, ISet<string> unwrapProxyFieldNames, ISessionImplementor session) @@ -40,7 +41,7 @@ var fieldInterceptorAccessor = entity as IFieldInterceptorAccessor; if (fieldInterceptorAccessor != null) { - var fieldInterceptorImpl = new DefaultFieldInterceptor(session, uninitializedFieldNames, unwrapProxyFieldNames, entityName); + var fieldInterceptorImpl = new DefaultFieldInterceptor(session, uninitializedFieldNames, unwrapProxyFieldNames, entityName, mappedClass); fieldInterceptorAccessor.FieldInterceptor = fieldInterceptorImpl; return fieldInterceptorImpl; } Modified: trunk/nhibernate/src/NHibernate/Intercept/IFieldInterceptor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Intercept/IFieldInterceptor.cs 2010-07-20 16:43:09 UTC (rev 5019) +++ trunk/nhibernate/src/NHibernate/Intercept/IFieldInterceptor.cs 2010-07-20 17:45:07 UTC (rev 5020) @@ -29,5 +29,11 @@ /// <summary> Intercept field set/get </summary> object Intercept(object target, string fieldName, object value); + + /// <summary> Get the entity-name of the field DeclaringType.</summary> + string EntityName { get; } + + /// <summary> Get the MappedClass (field container).</summary> + System.Type MappedClass { get; } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2010-07-20 16:43:09 UTC (rev 5019) +++ trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2010-07-20 17:45:07 UTC (rev 5020) @@ -3615,7 +3615,7 @@ } else { - IFieldInterceptor fieldInterceptor = FieldInterceptionHelper.InjectFieldInterceptor(entity, EntityName, null, null, session); + IFieldInterceptor fieldInterceptor = FieldInterceptionHelper.InjectFieldInterceptor(entity, EntityName, GetMappedClass(session.EntityMode), null, null, session); fieldInterceptor.MarkDirty(); } } Modified: trunk/nhibernate/src/NHibernate/Proxy/NHibernateProxyHelper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Proxy/NHibernateProxyHelper.cs 2010-07-20 16:43:09 UTC (rev 5019) +++ trunk/nhibernate/src/NHibernate/Proxy/NHibernateProxyHelper.cs 2010-07-20 17:45:07 UTC (rev 5020) @@ -1,3 +1,4 @@ +using NHibernate.Intercept; using NHibernate.Persister.Entity; namespace NHibernate.Proxy @@ -44,7 +45,7 @@ /// </remarks> public static System.Type GuessClass(object entity) { - INHibernateProxy proxy = entity as INHibernateProxy; + var proxy = entity as INHibernateProxy; if (proxy != null) { ILazyInitializer li = proxy.HibernateLazyInitializer; @@ -52,15 +53,15 @@ { return li.PersistentClass; } - else - { - return li.GetImplementation().GetType(); - } + return li.GetImplementation().GetType(); } - else + var fieldInterceptorAccessor = entity as IFieldInterceptorAccessor; + if (fieldInterceptorAccessor != null) { - return entity.GetType(); + var fieldInterceptor = fieldInterceptorAccessor.FieldInterceptor; + return fieldInterceptor.MappedClass; } + return entity.GetType(); } } } Modified: trunk/nhibernate/src/NHibernate/Tuple/Entity/PocoEntityTuplizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Tuple/Entity/PocoEntityTuplizer.cs 2010-07-20 16:43:09 UTC (rev 5019) +++ trunk/nhibernate/src/NHibernate/Tuple/Entity/PocoEntityTuplizer.cs 2010-07-20 17:45:07 UTC (rev 5020) @@ -229,7 +229,7 @@ HashedSet<string> lazyProps = lazyPropertiesAreUnfetched && EntityMetamodel.HasLazyProperties ? lazyPropertyNames : null; //TODO: if we support multiple fetch groups, we would need // to clone the set of lazy properties! - FieldInterceptionHelper.InjectFieldInterceptor(entity, EntityName, lazyProps, unwrapProxyPropertyNames, session); + FieldInterceptionHelper.InjectFieldInterceptor(entity, EntityName, this.MappedClass ,lazyProps, unwrapProxyPropertyNames, session); } } Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Fixture.cs 2010-07-20 17:45:07 UTC (rev 5020) @@ -0,0 +1,103 @@ +using System.Linq; +using NHibernate.ByteCode.Castle; +using NHibernate.Cfg; +using NHibernate.Proxy; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2093 + { + [TestFixture] + public class Fixture : BugTestCase + { + protected override void Configure(Configuration configuration) + { + configuration.SetProperty(Environment.ProxyFactoryFactoryClass, + typeof(ProxyFactoryFactory).AssemblyQualifiedName); + } + + [Test] + public void NHibernateProxyHelperReturnsCorrectType() + { + try + { + using (var s = OpenSession()) + { + var person = new Person { Id = 1, Name = "Person1" }; + var employee = new Employee { Id = 1, Name = "Emp1", Person = person }; + + s.Save(person); + s.Save(employee); + + s.Flush(); + } + + using (var s = OpenSession()) + { + var person = s.Load<Person>(1); + + var type = NHibernateProxyHelper.GuessClass(person); + + Assert.AreEqual(type, typeof(Person)); + } + + using (var s = OpenSession()) + { + var person = s.Get<Person>(1); + + var type = NHibernateProxyHelper.GuessClass(person); + + Assert.AreEqual(type, typeof(Person)); + } + } + finally + { + using (var s = OpenSession()) + { + s.Delete("from Employee"); + s.Delete("from Person"); + + s.Flush(); + } + } + } + + [Test] + public void CanUseFieldInterceptingProxyAsHQLArgument() + { + try + { + using (var s = OpenSession()) + { + var person = new Person { Id = 1, Name = "Person1" }; + var employee = new Employee { Id = 1, Name = "Emp1", Person = person }; + + s.Save(person); + s.Save(employee); + + s.Flush(); + } + + using (var s = OpenSession()) + { + var person = s.Get<Person>(1); + + var list = s.CreateQuery("from Employee where Person = :p") + .SetEntity("p", person) + .List<Employee>(); + + Assert.AreEqual(list.Count, 1); + } + } + finally + { + using (var s = OpenSession()) + { + s.Delete("from Employee"); + s.Delete("from Person"); + + s.Flush(); + } + } + } + } + } Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Mappings.hbm.xml 2010-07-20 17:45:07 UTC (rev 5020) @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2093"> + + <class name="Person"> + <id name="Id"/> + <property name="Name"></property> + <property name="LazyField" lazy="true"></property> + </class> + + <class name="Employee"> + <id name="Id"/> + <property name="Name"></property> + + <one-to-one name="Person" constrained="true" lazy="proxy"/> + </class> + +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Model.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Model.cs 2010-07-20 17:45:07 UTC (rev 5020) @@ -0,0 +1,20 @@ + using System.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.NH2093 + { + public class Person + { + public virtual int Id { get; set; } + public virtual string Name { get; set; } + + public virtual string LazyField { get; set; } + } + + public class Employee + { + public virtual int Id { get; set; } + public virtual string Name { get; set; } + + public virtual Person Person { get; set; } + } + } Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-20 16:43:09 UTC (rev 5019) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-20 17:45:07 UTC (rev 5020) @@ -457,6 +457,8 @@ <Compile Include="NHSpecificTest\NH2069\Test.cs" /> <Compile Include="NHSpecificTest\NH2069\Test2.cs" /> <Compile Include="NHSpecificTest\NH2069\TestBase.cs" /> + <Compile Include="NHSpecificTest\NH2093\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2093\Model.cs" /> <Compile Include="NHSpecificTest\NH2102\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2102\Model.cs" /> <Compile Include="NHSpecificTest\NH2189\Fixture.cs" /> @@ -1689,11 +1691,6 @@ <Project>{5909BFE7-93CF-4E5F-BE22-6293368AF01D}</Project> <Name>NHibernate</Name> </ProjectReference> - <Folder Include="Component" /> - <Folder Include="Component\Basic" /> - <Folder Include="NHSpecificTest\NH2061" /> - <Folder Include="NHSpecificTest\NH2195" /> - <Folder Include="TypedManyToOne" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="NHSpecificTest\NH386\Mappings.hbm.xml" /> @@ -2186,6 +2183,7 @@ <EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" /> <EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH2093\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2102\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2069\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2230\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-07-20 18:37:41
|
Revision: 5022 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5022&view=rev Author: fabiomaulo Date: 2010-07-20 18:37:34 +0000 (Tue, 20 Jul 2010) Log Message: ----------- Fix NH-2094 (thanks to Johannes Gustafsson for the TEST) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Model.cs Modified: trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs 2010-07-20 17:52:31 UTC (rev 5021) +++ trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs 2010-07-20 18:37:34 UTC (rev 5022) @@ -96,6 +96,11 @@ if (initializing) return InvokeImplementation; + if (!IsUninitializedProperty(fieldName)) + { + return value; + } + if (session == null) { throw new LazyInitializationException("entity with lazy properties is not associated with a session"); @@ -105,17 +110,23 @@ throw new LazyInitializationException("session is not connected"); } - if (uninitializedFields != null && uninitializedFields.Contains(fieldName)) + if (IsUninitializedProperty(fieldName)) { return InitializeField(fieldName, target); } - if (value is INHibernateProxy && unwrapProxyFieldNames != null && unwrapProxyFieldNames.Contains(fieldName)) + var nhproxy = value as INHibernateProxy; + if (nhproxy != null && unwrapProxyFieldNames != null && unwrapProxyFieldNames.Contains(fieldName)) { - return InitializeOrGetAssociation((INHibernateProxy)value, fieldName); + return InitializeOrGetAssociation(nhproxy, fieldName); } return InvokeImplementation; } + private bool IsUninitializedProperty(string fieldName) + { + return uninitializedFields != null && uninitializedFields.Contains(fieldName); + } + private object InitializeOrGetAssociation(INHibernateProxy value, string fieldName) { if(value.HibernateLazyInitializer.IsUninitialized) Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Fixture.cs 2010-07-20 18:37:34 UTC (rev 5022) @@ -0,0 +1,54 @@ +using NHibernate.ByteCode.Castle; +using NHibernate.Cfg; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2094 +{ + [TestFixture] + public class Fixture : BugTestCase + { + protected override void Configure(Configuration configuration) + { + configuration.SetProperty(Environment.ProxyFactoryFactoryClass, + typeof(ProxyFactoryFactory).AssemblyQualifiedName); + } + + [Test] + public void CanAccessInitializedPropertiesOutsideOfSession() + { + try + { + using (var s = OpenSession()) + { + var p = new Person { Id = 1, Name = "Person1", LazyField = "Long field"}; + + s.Save(p); + + s.Flush(); + } + + Person person; + + using (var s = OpenSession()) + { + person = s.Get<Person>(1); + + Assert.AreEqual("Person1", person.Name); + Assert.AreEqual("Long field", person.LazyField); + } + + Assert.AreEqual("Person1", person.Name); + Assert.AreEqual("Long field", person.LazyField); + } + finally + { + using (var s = OpenSession()) + { + s.Delete("from Person"); + + s.Flush(); + } + } + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Mappings.hbm.xml 2010-07-20 18:37:34 UTC (rev 5022) @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2094"> + + <class name="Person"> + <id name="Id"/> + <property name="Name"></property> + + <property name="LazyField" lazy="true"></property> + </class> + +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Model.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Model.cs 2010-07-20 18:37:34 UTC (rev 5022) @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.NH2094 +{ + public class Person + { + public virtual int Id { get; set; } + public virtual string Name { get; set; } + + public virtual string LazyField { get; set; } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-20 17:52:31 UTC (rev 5021) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-20 18:37:34 UTC (rev 5022) @@ -461,6 +461,8 @@ <Compile Include="NHSpecificTest\NH2092\Model.cs" /> <Compile Include="NHSpecificTest\NH2093\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2093\Model.cs" /> + <Compile Include="NHSpecificTest\NH2094\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2094\Model.cs" /> <Compile Include="NHSpecificTest\NH2102\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2102\Model.cs" /> <Compile Include="NHSpecificTest\NH2189\Fixture.cs" /> @@ -2185,6 +2187,7 @@ <EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" /> <EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH2094\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2092\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2093\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2102\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-07-20 19:01:14
|
Revision: 5023 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5023&view=rev Author: fabiomaulo Date: 2010-07-20 19:01:08 +0000 (Tue, 20 Jul 2010) Log Message: ----------- Additional tests with better exception message for NH-2094 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Fixture.cs Modified: trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs 2010-07-20 18:37:34 UTC (rev 5022) +++ trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs 2010-07-20 19:01:08 UTC (rev 5023) @@ -103,11 +103,11 @@ if (session == null) { - throw new LazyInitializationException("entity with lazy properties is not associated with a session"); + throw new LazyInitializationException(EntityName, null, string.Format("entity with lazy properties is not associated with a session. entity-name:'{0}' property:'{1}'", EntityName, fieldName)); } if (!session.IsOpen || !session.IsConnected) { - throw new LazyInitializationException("session is not connected"); + throw new LazyInitializationException(EntityName, null, string.Format("session is not connected. entity-name:'{0}' property:'{1}'", EntityName, fieldName)); } if (IsUninitializedProperty(fieldName)) Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Fixture.cs 2010-07-20 18:37:34 UTC (rev 5022) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2094/Fixture.cs 2010-07-20 19:01:08 UTC (rev 5023) @@ -1,7 +1,8 @@ using NHibernate.ByteCode.Castle; using NHibernate.Cfg; using NUnit.Framework; - +using SharpTestsEx; + namespace NHibernate.Test.NHSpecificTest.NH2094 { [TestFixture] @@ -50,5 +51,75 @@ } } } + + [Test] + public void WhenAccessNoLazyPropertiesOutsideOfSessionThenNotThrows() + { + try + { + using (var s = OpenSession()) + { + var p = new Person { Id = 1, Name = "Person1", LazyField = "Long field" }; + + s.Save(p); + + s.Flush(); + } + + Person person; + + using (var s = OpenSession()) + { + person = s.Get<Person>(1); + } + string personName; + Executing.This(()=> personName = person.Name).Should().NotThrow(); + } + finally + { + using (var s = OpenSession()) + { + s.Delete("from Person"); + + s.Flush(); + } + } + } + + [Test] + public void WhenAccessLazyPropertiesOutsideOfSessionThenThrows() + { + try + { + using (var s = OpenSession()) + { + var p = new Person { Id = 1, Name = "Person1", LazyField = "Long field" }; + + s.Save(p); + + s.Flush(); + } + + Person person; + + using (var s = OpenSession()) + { + person = s.Get<Person>(1); + } + string lazyField; + var lazyException = Executing.This(() => lazyField = person.LazyField).Should().Throw<LazyInitializationException>().Exception; + lazyException.EntityName.Should().Not.Be.Null(); + lazyException.Message.Should().Contain("LazyField"); + } + finally + { + using (var s = OpenSession()) + { + s.Delete("from Person"); + + s.Flush(); + } + } + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-07-21 06:11:23
|
Revision: 5027 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5027&view=rev Author: fabiomaulo Date: 2010-07-21 06:11:15 +0000 (Wed, 21 Jul 2010) Log Message: ----------- Fix NH-2242 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/SqlCommand/Template.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2242/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2242/EscapedFormulaDomainClass.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2242/FormulaTest.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2242/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2242/UnescapedFormulaDomainClass.cs Modified: trunk/nhibernate/src/NHibernate/SqlCommand/Template.cs =================================================================== --- trunk/nhibernate/src/NHibernate/SqlCommand/Template.cs 2010-07-20 21:23:32 UTC (rev 5026) +++ trunk/nhibernate/src/NHibernate/SqlCommand/Template.cs 2010-07-21 06:11:15 UTC (rev 5027) @@ -139,7 +139,7 @@ isOpenQuote = false; } - if (isOpenQuote) + if (isOpenQuote && !inFromClause) { result.Append(placeholder).Append('.'); } Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2242/EscapedFormulaDomainClass.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2242/EscapedFormulaDomainClass.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2242/EscapedFormulaDomainClass.cs 2010-07-21 06:11:15 UTC (rev 5027) @@ -0,0 +1,21 @@ +namespace NHibernate.Test.NHSpecificTest.NH2242 +{ + public class EscapedFormulaDomainClass + { + private int id; + + private int formula; + + public int Id + { + get { return id; } + set { id = value; } + } + + public int Formula + { + get { return formula; } + set { formula = value; } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2242/FormulaTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2242/FormulaTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2242/FormulaTest.cs 2010-07-21 06:11:15 UTC (rev 5027) @@ -0,0 +1,69 @@ +using NHibernate.Dialect; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2242 +{ + [TestFixture] + public class FormulaTest : BugTestCase + { + protected override bool AppliesTo(Dialect.Dialect dialect) + { + return dialect as MsSql2005Dialect != null; + } + + [Test] + public void FormulaOfEscapedDomainClassShouldBeRetrievedCorrectly() + { + using (ISession session = OpenSession()) + { + using (ITransaction transaction = session.BeginTransaction()) + { + var entity = new EscapedFormulaDomainClass(); + entity.Id = 1; + session.Save(entity); + + transaction.Commit(); + } + + session.Clear(); + + using (ITransaction transaction = session.BeginTransaction()) + { + var entity = session.Get<EscapedFormulaDomainClass>(1); + + Assert.AreEqual(1, entity.Formula); + session.Delete(entity); + + transaction.Commit(); + } + } + } + + [Test] + public void FormulaOfUnescapedDomainClassShouldBeRetrievedCorrectly() + { + using (ISession session = OpenSession()) + { + using (ITransaction transaction = session.BeginTransaction()) + { + var entity = new UnescapedFormulaDomainClass(); + entity.Id = 1; + session.Save(entity); + + transaction.Commit(); + } + + session.Clear(); + + using (ITransaction transaction = session.BeginTransaction()) + { + var entity = session.Get<UnescapedFormulaDomainClass>(1); + + Assert.AreEqual(1, entity.Formula); + session.Delete(entity); + transaction.Commit(); + } + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2242/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2242/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2242/Mappings.hbm.xml 2010-07-21 06:11:15 UTC (rev 5027) @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2242" default-access="field.camelcase" + default-lazy="false"> + <class name="EscapedFormulaDomainClass"> + <id name="Id"> + <generator class="assigned" /> + </id> + <property name="Formula" formula="(SELECT COUNT(*) FROM [EscapedFormulaDomainClass])" /> + </class> + <class name="UnescapedFormulaDomainClass"> + <id name="Id"> + <generator class="assigned" /> + </id> + <property name="Formula" formula="(SELECT COUNT(*) FROM UnescapedFormulaDomainClass)" /> + </class> +</hibernate-mapping> \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2242/UnescapedFormulaDomainClass.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2242/UnescapedFormulaDomainClass.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2242/UnescapedFormulaDomainClass.cs 2010-07-21 06:11:15 UTC (rev 5027) @@ -0,0 +1,21 @@ +namespace NHibernate.Test.NHSpecificTest.NH2242 +{ + public class UnescapedFormulaDomainClass + { + private int id; + + private int formula; + + public int Id + { + get { return id; } + set { id = value; } + } + + public int Formula + { + get { return formula; } + set { formula = value; } + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-20 21:23:32 UTC (rev 5026) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-21 06:11:15 UTC (rev 5027) @@ -752,6 +752,9 @@ <Compile Include="NHSpecificTest\NH2230\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2234\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2234\MyType.cs" /> + <Compile Include="NHSpecificTest\NH2242\EscapedFormulaDomainClass.cs" /> + <Compile Include="NHSpecificTest\NH2242\FormulaTest.cs" /> + <Compile Include="NHSpecificTest\NH2242\UnescapedFormulaDomainClass.cs" /> <Compile Include="NHSpecificTest\NH473\Child.cs" /> <Compile Include="NHSpecificTest\NH473\Fixture.cs" /> <Compile Include="NHSpecificTest\NH473\Parent.cs" /> @@ -2189,6 +2192,7 @@ <EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" /> <EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH2242\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2234\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2094\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2092\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-07-21 06:37:41
|
Revision: 5028 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5028&view=rev Author: fabiomaulo Date: 2010-07-21 06:37:34 +0000 (Wed, 21 Jul 2010) Log Message: ----------- Fix NH-1891 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/SqlCommand/Template.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/A.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/B.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/FormulaEscaping.hbm.xml Modified: trunk/nhibernate/src/NHibernate/SqlCommand/Template.cs =================================================================== --- trunk/nhibernate/src/NHibernate/SqlCommand/Template.cs 2010-07-21 06:11:15 UTC (rev 5027) +++ trunk/nhibernate/src/NHibernate/SqlCommand/Template.cs 2010-07-21 06:37:34 UTC (rev 5028) @@ -95,6 +95,7 @@ IEnumerator<string> tokensEnum = tokens.GetEnumerator(); bool hasMore = tokensEnum.MoveNext(); string nextToken = hasMore ? tokensEnum.Current : null; + string lastToken = string.Empty; while (hasMore) { string token = nextToken; @@ -139,7 +140,7 @@ isOpenQuote = false; } - if (isOpenQuote && !inFromClause) + if (isOpenQuote && !inFromClause && !lastToken.EndsWith(".")) { result.Append(placeholder).Append('.'); } @@ -201,6 +202,7 @@ { inFromClause = false; } + lastToken = token; } return result.ToString(); } Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/A.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/A.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/A.cs 2010-07-21 06:37:34 UTC (rev 5028) @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NHibernate.Test.NHSpecificTest.NH1891 +{ + public class A + { + public virtual Guid Id { get; set; } + public virtual int FormulaCount { get; set; } + public virtual string FormulaConstraint { get; set; } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/B.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/B.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/B.cs 2010-07-21 06:37:34 UTC (rev 5028) @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NHibernate.Test.NHSpecificTest.NH1891 +{ + public class B + { + public virtual Guid Id { get; set; } + public virtual string Name { get; set; } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/Fixture.cs 2010-07-21 06:37:34 UTC (rev 5028) @@ -0,0 +1,56 @@ +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH1891 +{ + [TestFixture] + public class Fixture : TestCase + { + protected override System.Collections.IList Mappings + { + get { return new string[] { "NHSpecificTest.NH1891.FormulaEscaping.hbm.xml" }; } + } + + protected override string MappingsAssembly + { + get { return "NHibernate.Test"; } + } + + protected override void OnTearDown() + { + using (ISession s = OpenSession()) + { + s.Delete("from B"); + s.Flush(); + s.Delete("from A"); + s.Flush(); + } + } + + [Test] + public void FormulaEscaping() + { + string name = "Test"; + + B b = new B(); + b.Name = name; + + A a = new A(); + a.FormulaConstraint = name; + + ISession s = OpenSession(); + + s.Save(b); + s.Save(a); + s.Flush(); + s.Close(); + + s = OpenSession(); + + a = s.Get<A>(a.Id); + + Assert.AreEqual(1, a.FormulaCount); + + s.Close(); + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/FormulaEscaping.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/FormulaEscaping.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/FormulaEscaping.hbm.xml 2010-07-21 06:37:34 UTC (rev 5028) @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.NH1891"> + <class name="A" table="a" lazy="false"> + <id name="Id" column="id"> + <generator class="guid.comb" /> + </id> + <property name="FormulaCount" formula="(select count(*) from b where b.`Name` = FormulaConstraint)" type="Int32" /> + <property name="FormulaConstraint" /> + </class> + + <class name="B" table="b"> + <id name="Id" column="id"> + <generator class="guid.comb" /> + </id> + <property name="Name" /> + </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 2010-07-21 06:11:15 UTC (rev 5027) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-21 06:37:34 UTC (rev 5028) @@ -448,6 +448,9 @@ <Compile Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Employee.cs" /> <Compile Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Fixture.cs" /> <Compile Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Money.cs" /> + <Compile Include="NHSpecificTest\NH1891\A.cs" /> + <Compile Include="NHSpecificTest\NH1891\B.cs" /> + <Compile Include="NHSpecificTest\NH1891\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2061\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2061\Model.cs" /> <Compile Include="NHSpecificTest\NH2069\Fixture.cs" /> @@ -2192,6 +2195,7 @@ <EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" /> <EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1891\FormulaEscaping.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2242\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2234\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2094\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-07-21 14:33:52
|
Revision: 5030 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5030&view=rev Author: fabiomaulo Date: 2010-07-21 14:33:45 +0000 (Wed, 21 Jul 2010) Log Message: ----------- Revert of mapping-schema breaking change introduced in r5017 (not needed to fix NH-2117) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/Hbm.generated.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToOne.cs trunk/nhibernate/src/NHibernate/nhibernate-mapping.xsd Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/Hbm.generated.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/Hbm.generated.cs 2010-07-21 13:06:48 UTC (rev 5029) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/Hbm.generated.cs 2010-07-21 14:33:45 UTC (rev 5030) @@ -649,14 +649,11 @@ public HbmMeta[] meta; /// <remarks/> - [System.Xml.Serialization.XmlElementAttribute("column")] - public HbmColumn[] column; + [System.Xml.Serialization.XmlElementAttribute("column", typeof(HbmColumn))] + [System.Xml.Serialization.XmlElementAttribute("formula", typeof(HbmFormula))] + public object[] Items; /// <remarks/> - [System.Xml.Serialization.XmlElementAttribute("formula")] - public HbmFormula[] formula; - - /// <remarks/> [System.Xml.Serialization.XmlAttributeAttribute()] public string name; @@ -673,8 +670,8 @@ public string entityname; /// <remarks/> - [System.Xml.Serialization.XmlAttributeAttribute("column")] - public string column1; + [System.Xml.Serialization.XmlAttributeAttribute()] + public string column; /// <remarks/> [System.Xml.Serialization.XmlAttributeAttribute("not-null")] @@ -741,8 +738,8 @@ public string propertyref; /// <remarks/> - [System.Xml.Serialization.XmlAttributeAttribute("formula")] - public string formula1; + [System.Xml.Serialization.XmlAttributeAttribute()] + public string formula; /// <remarks/> [System.Xml.Serialization.XmlAttributeAttribute()] Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToOne.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToOne.cs 2010-07-21 13:06:48 UTC (rev 5029) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToOne.cs 2010-07-21 14:33:45 UTC (rev 5030) @@ -43,14 +43,14 @@ public IEnumerable<HbmColumn> Columns { - get { return column != null ? column.OfType<HbmColumn>() : AsColumns(); } + get { return Items != null ? Items.OfType<HbmColumn>() : AsColumns(); } } #endregion private IEnumerable<HbmColumn> AsColumns() { - if (string.IsNullOrEmpty(column1)) + if (string.IsNullOrEmpty(column)) { yield break; } @@ -58,7 +58,7 @@ { yield return new HbmColumn { - name = column1, + name = column, notnull = notnull, notnullSpecified = notnullSpecified, unique = unique, @@ -73,18 +73,18 @@ public IEnumerable<HbmFormula> Formulas { - get { return formula != null ? formula.OfType<HbmFormula>() : AsFormulas(); } + get { return Items != null ? Items.OfType<HbmFormula>() : AsFormulas(); } } private IEnumerable<HbmFormula> AsFormulas() { - if (string.IsNullOrEmpty(formula1)) + if (string.IsNullOrEmpty(formula)) { yield break; } else { - yield return new HbmFormula { Text = new[] { formula1 } }; + yield return new HbmFormula { Text = new[] { formula } }; } } @@ -114,7 +114,11 @@ /// </summary> public IEnumerable<object> ColumnsAndFormulas { - get { return Columns.Cast<object>().Concat(Formulas.Cast<object>()); } + // when Items is empty the column attribute AND formula attribute will be used + // and it may cause an issue (breaking change) + // On the other hand it work properly when a mixing between <formula> and <column> tags are used + // respecting the order used in the mapping to map multi-columns id. + get { return Items ?? Columns.Cast<object>().Concat(Formulas.Cast<object>()); } } public HbmLaziness? Lazy Modified: trunk/nhibernate/src/NHibernate/nhibernate-mapping.xsd =================================================================== --- trunk/nhibernate/src/NHibernate/nhibernate-mapping.xsd 2010-07-21 13:06:48 UTC (rev 5029) +++ trunk/nhibernate/src/NHibernate/nhibernate-mapping.xsd 2010-07-21 14:33:45 UTC (rev 5030) @@ -865,9 +865,11 @@ <xs:complexType> <xs:sequence> <xs:element ref="meta" minOccurs="0" maxOccurs="unbounded" /> - <xs:element ref="column" minOccurs="0" maxOccurs="unbounded" /> - <xs:element ref="formula" minOccurs="0" maxOccurs="unbounded" /> - </xs:sequence> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element ref="column" /> + <xs:element ref="formula" /> + </xs:choice> + </xs:sequence> <xs:attribute name="name" use="required" type="xs:string" /> <xs:attribute name="access" type="xs:string" /> <xs:attribute name="class" type="xs:string" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-07-21 17:19:57
|
Revision: 5031 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5031&view=rev Author: fabiomaulo Date: 2010-07-21 17:19:49 +0000 (Wed, 21 Jul 2010) Log Message: ----------- Fix NH-2243 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2243/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2243/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2243/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2243/Person.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2010-07-21 14:33:45 UTC (rev 5030) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2010-07-21 17:19:49 UTC (rev 5031) @@ -200,6 +200,7 @@ // KEY SimpleValue key = new DependantValue(table, persistentClass.Identifier); + key.ForeignKeyName = joinMapping.key.foreignkey; join.Key = key; key.IsCascadeDeleteEnabled = joinMapping.key.ondelete == HbmOndelete.Cascade; new ValuePropertyBinder(key, Mappings).BindSimpleValue(joinMapping.key, persistentClass.EntityName, false); Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2243/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2243/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2243/Fixture.cs 2010-07-21 17:19:49 UTC (rev 5031) @@ -0,0 +1,27 @@ +using System.IO; +using System.Reflection; +using System.Text; +using NHibernate.Cfg; +using NHibernate.Tool.hbm2ddl; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.NHSpecificTest.NH2243 +{ + public class Fixture + { + [Test] + public void ShouldCreateSchemaWithDefaultClause() + { + var script = new StringBuilder(); + const string mapping = "NHibernate.Test.NHSpecificTest.NH2243.Mappings.hbm.xml"; + + Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration(); + using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(mapping)) + cfg.AddInputStream(stream); + new SchemaExport(cfg).Execute(s => script.AppendLine(s), false, false); + + script.ToString().Should().Contain("MyNameForFK"); + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2243/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2243/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2243/Mappings.hbm.xml 2010-07-21 17:19:49 UTC (rev 5031) @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2243"> + + <class name="Person" table="Person1"> + <id name="Id"> + <generator class="assigned" /> + </id> + <property name="Name"/> + <join table="Person2"> + <key column="PersonId" foreign-key="MyNameForFK" /> + <property name="Address"/> + </join> + </class> +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2243/Person.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2243/Person.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2243/Person.cs 2010-07-21 17:19:49 UTC (rev 5031) @@ -0,0 +1,9 @@ +namespace NHibernate.Test.NHSpecificTest.NH2243 +{ + public class Person + { + public virtual int Id { get; set; } + public virtual string Name { get; set; } + public virtual string Address { 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 2010-07-21 14:33:45 UTC (rev 5030) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-21 17:19:49 UTC (rev 5031) @@ -758,6 +758,8 @@ <Compile Include="NHSpecificTest\NH2242\EscapedFormulaDomainClass.cs" /> <Compile Include="NHSpecificTest\NH2242\FormulaTest.cs" /> <Compile Include="NHSpecificTest\NH2242\UnescapedFormulaDomainClass.cs" /> + <Compile Include="NHSpecificTest\NH2243\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2243\Person.cs" /> <Compile Include="NHSpecificTest\NH473\Child.cs" /> <Compile Include="NHSpecificTest\NH473\Fixture.cs" /> <Compile Include="NHSpecificTest\NH473\Parent.cs" /> @@ -2195,6 +2197,7 @@ <EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" /> <EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH2243\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1891\FormulaEscaping.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2242\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2234\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-07-21 17:51:21
|
Revision: 5032 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5032&view=rev Author: fabiomaulo Date: 2010-07-21 17:51:11 +0000 (Wed, 21 Jul 2010) Log Message: ----------- Fix NH-2227 (fixed also for others IPropertyAccessor, ISetter, IGetter) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Properties/BackrefPropertyAccessor.cs trunk/nhibernate/src/NHibernate/Properties/EmbeddedPropertyAccessor.cs trunk/nhibernate/src/NHibernate/Properties/IndexPropertyAccessor.cs trunk/nhibernate/src/NHibernate/Properties/MapAccessor.cs trunk/nhibernate/src/NHibernate/Properties/NoSetterAccessor.cs trunk/nhibernate/src/NHibernate/Properties/NoopAccessor.cs trunk/nhibernate/src/NHibernate/Properties/ReadonlyAccessor.cs trunk/nhibernate/src/NHibernate/Properties/XmlAccessor.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/CfgTest/AccessorsSerializableTest.cs Modified: trunk/nhibernate/src/NHibernate/Properties/BackrefPropertyAccessor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Properties/BackrefPropertyAccessor.cs 2010-07-21 17:19:49 UTC (rev 5031) +++ trunk/nhibernate/src/NHibernate/Properties/BackrefPropertyAccessor.cs 2010-07-21 17:51:11 UTC (rev 5032) @@ -6,6 +6,7 @@ namespace NHibernate.Properties { /// <summary> Represents a "back-reference" to the id of a collection owner. </summary> + [Serializable] public class BackrefPropertyAccessor : IPropertyAccessor { public static readonly object Unknown = new object(); Modified: trunk/nhibernate/src/NHibernate/Properties/EmbeddedPropertyAccessor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Properties/EmbeddedPropertyAccessor.cs 2010-07-21 17:19:49 UTC (rev 5031) +++ trunk/nhibernate/src/NHibernate/Properties/EmbeddedPropertyAccessor.cs 2010-07-21 17:51:11 UTC (rev 5032) @@ -5,6 +5,7 @@ namespace NHibernate.Properties { + [Serializable] public class EmbeddedPropertyAccessor : IPropertyAccessor { #region IPropertyAccessor Members Modified: trunk/nhibernate/src/NHibernate/Properties/IndexPropertyAccessor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Properties/IndexPropertyAccessor.cs 2010-07-21 17:19:49 UTC (rev 5031) +++ trunk/nhibernate/src/NHibernate/Properties/IndexPropertyAccessor.cs 2010-07-21 17:51:11 UTC (rev 5032) @@ -6,6 +6,7 @@ namespace NHibernate.Properties { /// <summary> Represents a "back-reference" to the index of a collection. </summary> + [Serializable] public class IndexPropertyAccessor : IPropertyAccessor { private readonly string propertyName; @@ -40,6 +41,7 @@ #endregion /// <summary> The Setter implementation for index backrefs.</summary> + [Serializable] public sealed class IndexSetter : ISetter { #region ISetter Members @@ -62,6 +64,7 @@ } /// <summary> The Getter implementation for index backrefs.</summary> + [Serializable] public class IndexGetter : IGetter { private readonly IndexPropertyAccessor encloser; Modified: trunk/nhibernate/src/NHibernate/Properties/MapAccessor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Properties/MapAccessor.cs 2010-07-21 17:19:49 UTC (rev 5031) +++ trunk/nhibernate/src/NHibernate/Properties/MapAccessor.cs 2010-07-21 17:51:11 UTC (rev 5032) @@ -4,6 +4,7 @@ using System; namespace NHibernate.Properties { + [Serializable] public class MapAccessor : IPropertyAccessor { #region IPropertyAccessor Members Modified: trunk/nhibernate/src/NHibernate/Properties/NoSetterAccessor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Properties/NoSetterAccessor.cs 2010-07-21 17:19:49 UTC (rev 5031) +++ trunk/nhibernate/src/NHibernate/Properties/NoSetterAccessor.cs 2010-07-21 17:51:11 UTC (rev 5032) @@ -1,3 +1,5 @@ +using System; + namespace NHibernate.Properties { /// <summary> @@ -9,6 +11,7 @@ /// that is the <c><id></c> but tell NHibernate there is no setter for the Property /// so the value should be written directly to the field. /// </remarks> + [Serializable] public class NoSetterAccessor : IPropertyAccessor { private readonly IFieldNamingStrategy namingStrategy; Modified: trunk/nhibernate/src/NHibernate/Properties/NoopAccessor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Properties/NoopAccessor.cs 2010-07-21 17:19:49 UTC (rev 5031) +++ trunk/nhibernate/src/NHibernate/Properties/NoopAccessor.cs 2010-07-21 17:51:11 UTC (rev 5032) @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Reflection; using NHibernate.Engine; @@ -5,6 +6,7 @@ namespace NHibernate.Properties { /// <summary> Used to declare properties not represented at the pojo level </summary> + [Serializable] public class NoopAccessor : IPropertyAccessor { #region IPropertyAccessor Members @@ -27,6 +29,7 @@ #endregion /// <summary> A Getter which will always return null. It should not be called anyway.</summary> + [Serializable] private class NoopGetter : IGetter { #region IGetter Members @@ -60,6 +63,7 @@ } /// <summary> A Setter which will just do nothing.</summary> + [Serializable] private class NoopSetter : ISetter { #region ISetter Members Modified: trunk/nhibernate/src/NHibernate/Properties/ReadonlyAccessor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Properties/ReadonlyAccessor.cs 2010-07-21 17:19:49 UTC (rev 5031) +++ trunk/nhibernate/src/NHibernate/Properties/ReadonlyAccessor.cs 2010-07-21 17:51:11 UTC (rev 5032) @@ -1,3 +1,4 @@ +using System; using System.Reflection; namespace NHibernate.Properties @@ -10,6 +11,7 @@ /// This is useful to allow calculated properties in the domain that will never /// be recovered from the DB but can be used for querying. /// </remarks> + [Serializable] public class ReadOnlyAccessor : IPropertyAccessor { /// <summary> @@ -64,6 +66,7 @@ #endregion + [Serializable] private class NoopSetter : ISetter { public void Set(object target, object value) {} Modified: trunk/nhibernate/src/NHibernate/Properties/XmlAccessor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Properties/XmlAccessor.cs 2010-07-21 17:19:49 UTC (rev 5031) +++ trunk/nhibernate/src/NHibernate/Properties/XmlAccessor.cs 2010-07-21 17:51:11 UTC (rev 5032) @@ -11,6 +11,7 @@ /// Responsible for accessing property values represented as a XmlElement /// or XmlAttribute. /// </summary> + [Serializable] public class XmlAccessor : IPropertyAccessor { private readonly ISessionFactoryImplementor factory; Added: trunk/nhibernate/src/NHibernate.Test/CfgTest/AccessorsSerializableTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/CfgTest/AccessorsSerializableTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/CfgTest/AccessorsSerializableTest.cs 2010-07-21 17:51:11 UTC (rev 5032) @@ -0,0 +1,35 @@ +using System; +using System.Linq; +using NHibernate.Properties; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.CfgTest +{ + public class AccessorsSerializableTest + { + private static System.Type[] accessors = typeof (IPropertyAccessor).Assembly.GetTypes().Where(t => t.Namespace == typeof (IPropertyAccessor).Namespace && t.GetInterfaces().Contains(typeof (IPropertyAccessor))).ToArray(); + + [Test, TestCaseSource("accessors")] + public void AllAccessorsAreMarkedAsSerializable(System.Type concreteAccessor) + { + concreteAccessor.Should().Have.Attribute<SerializableAttribute>(); + } + + private static System.Type[] setters = typeof(ISetter).Assembly.GetTypes().Where(t => t.Namespace == typeof(ISetter).Namespace && t.GetInterfaces().Contains(typeof(ISetter))).ToArray(); + + [Test, TestCaseSource("setters")] + public void AllSettersAreMarkedAsSerializable(System.Type concreteAccessor) + { + concreteAccessor.Should().Have.Attribute<SerializableAttribute>(); + } + + private static System.Type[] getters = typeof(IGetter).Assembly.GetTypes().Where(t => t.Namespace == typeof(IGetter).Namespace && t.GetInterfaces().Contains(typeof(IGetter))).ToArray(); + + [Test, TestCaseSource("getters")] + public void AllGettersAreMarkedAsSerializable(System.Type concreteAccessor) + { + concreteAccessor.Should().Have.Attribute<SerializableAttribute>(); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-21 17:19:49 UTC (rev 5031) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-21 17:51:11 UTC (rev 5032) @@ -108,6 +108,7 @@ <Compile Include="Cascade\Job.cs" /> <Compile Include="Cascade\JobBatch.cs" /> <Compile Include="Cascade\RefreshFixture.cs" /> + <Compile Include="CfgTest\AccessorsSerializableTest.cs" /> <Compile Include="CfgTest\ConfigurationFixture.cs" /> <Compile Include="CfgTest\ConfigurationSchemaFixture.cs" /> <Compile Include="CfgTest\ConfigurationSerializationTests.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-07-22 03:55:28
|
Revision: 5036 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5036&view=rev Author: fabiomaulo Date: 2010-07-22 03:55:22 +0000 (Thu, 22 Jul 2010) Log Message: ----------- Fix NH-2249 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Type/DateType.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/TypesTest/DateClass.cs trunk/nhibernate/src/NHibernate.Test/TypesTest/DateClass.hbm.xml trunk/nhibernate/src/NHibernate.Test/TypesTest/DateTypeTest.cs Modified: trunk/nhibernate/src/NHibernate/Type/DateType.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/DateType.cs 2010-07-21 20:58:52 UTC (rev 5035) +++ trunk/nhibernate/src/NHibernate/Type/DateType.cs 2010-07-22 03:55:22 UTC (rev 5036) @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using System.Data; using NHibernate.SqlTypes; +using NHibernate.UserTypes; namespace NHibernate.Type { @@ -9,12 +11,14 @@ /// <see cref="DbType.Date"/> column /// </summary> [Serializable] - public class DateType : PrimitiveType, IIdentifierType, ILiteralType + public class DateType : PrimitiveType, IIdentifierType, ILiteralType, IParameterizedType { - private static readonly DateTime BaseDateValue = new DateTime(1753, 01, 01); + public const string BaseValueParameterName = "BaseValue"; + public static readonly DateTime BaseDateValue = new DateTime(1753, 01, 01); + private DateTime customBaseDate = BaseDateValue; /// <summary></summary> - internal DateType() : base(SqlTypeFactory.Date) + public DateType() : base(SqlTypeFactory.Date) { } @@ -29,7 +33,7 @@ try { DateTime dbValue = Convert.ToDateTime(rs[index]); - return new DateTime(dbValue.Year, dbValue.Month, dbValue.Day); + return dbValue.Date; } catch (Exception ex) { @@ -51,7 +55,7 @@ { var parm = st.Parameters[index] as IDataParameter; var dateTime = (DateTime)value; - if (dateTime < BaseDateValue) + if (dateTime < customBaseDate) { parm.Value = DBNull.Value; } @@ -118,12 +122,25 @@ public override object DefaultValue { - get { return BaseDateValue; } + get { return customBaseDate; } } public override string ObjectToSQLString(object value, Dialect.Dialect dialect) { return '\'' + ((DateTime)value).ToShortDateString() + '\''; } + + public void SetParameterValues(IDictionary<string, string> parameters) + { + if(parameters == null) + { + return; + } + string value; + if (parameters.TryGetValue(BaseValueParameterName, out value)) + { + customBaseDate = DateTime.Parse(value); + } + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-21 20:58:52 UTC (rev 5035) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-22 03:55:22 UTC (rev 5036) @@ -1525,6 +1525,8 @@ <Compile Include="TypesTest\ByteTypeFixture.cs" /> <Compile Include="TypesTest\CurrencyClass.cs" /> <Compile Include="TypesTest\CurrencyTypeFixture.cs" /> + <Compile Include="TypesTest\DateClass.cs" /> + <Compile Include="TypesTest\DateTypeTest.cs" /> <Compile Include="TypesTest\TimeAsTimeSpanClass.cs" /> <Compile Include="TypesTest\TimeAsTimeSpanTypeFixture.cs" /> <Compile Include="TypesTest\TimeSpanClass.cs" /> @@ -2200,6 +2202,7 @@ <EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" /> <EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="TypesTest\DateClass.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2207\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2243\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1891\FormulaEscaping.hbm.xml" /> Added: trunk/nhibernate/src/NHibernate.Test/TypesTest/DateClass.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/TypesTest/DateClass.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/TypesTest/DateClass.cs 2010-07-22 03:55:22 UTC (rev 5036) @@ -0,0 +1,9 @@ +using System; + +namespace NHibernate.Test.TypesTest +{ + public class DateClass + { + public DateTime? DateValue { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/TypesTest/DateClass.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/TypesTest/DateClass.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/TypesTest/DateClass.hbm.xml 2010-07-22 03:55:22 UTC (rev 5036) @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.TypesTest" + default-lazy="false"> + + <class name="DateClass"> + <id type="int"> + <generator class="native" /> + </id> + <property name="DateValue"> + <type name="NHibernate.Type.DateType, NHibernate"> + <param name="BaseValue">1900/01/01</param> + </type> + </property> + </class> +</hibernate-mapping> \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/TypesTest/DateTypeTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/TypesTest/DateTypeTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/TypesTest/DateTypeTest.cs 2010-07-22 03:55:22 UTC (rev 5036) @@ -0,0 +1,93 @@ +using System.Collections.Generic; +using NHibernate.Dialect; +using NHibernate.Type; +using NUnit.Framework; +using SharpTestsEx; +using System; + +namespace NHibernate.Test.TypesTest +{ + public class DateTypeTest + { + [Test] + public void WhenNoParameterThenDefaultValueIsBaseDateValue() + { + var dateType = new DateType(); + dateType.DefaultValue.Should().Be(DateType.BaseDateValue); + } + + [Test] + public void WhenSetParameterThenDefaultValueIsParameterValue() + { + var dateType = new DateType(); + dateType.SetParameterValues(new Dictionary<string, string>{{DateType.BaseValueParameterName, "0001/01/01"}}); + dateType.DefaultValue.Should().Be(DateTime.MinValue); + } + + [Test] + public void WhenSetParameterNullThenNotThrow() + { + var dateType = new DateType(); + dateType.Executing(dt=> dt.SetParameterValues(null)).NotThrows(); + } + } + + public class DateTypeFixture : TypeFixtureBase + { + protected override string TypeName + { + get { return "Date"; } + } + + [Test] + public void ShouldBeDateType() + { + if (!(Dialect is MsSql2008Dialect)) + { + Assert.Ignore("This test does not apply to " + Dialect); + } + var sqlType = Dialect.GetTypeName(NHibernateUtil.Date.SqlType); + sqlType.ToLowerInvariant().Should().Be("date"); + } + + [Test] + public void ReadWriteNormal() + { + var expected = DateTime.Today.Date; + + var basic = new DateClass { DateValue = expected.AddHours(1) }; + object savedId; + using (ISession s = OpenSession()) + { + savedId = s.Save(basic); + s.Flush(); + } + using (ISession s = OpenSession()) + { + basic = s.Get<DateClass>(savedId); + basic.DateValue.Should().Be(expected); + s.Delete(basic); + s.Flush(); + } + } + + [Test] + public void ReadWriteBaseValue() + { + var basic = new DateClass { DateValue = new DateTime(1899,1,1) }; + object savedId; + using (ISession s = OpenSession()) + { + savedId = s.Save(basic); + s.Flush(); + } + using (ISession s = OpenSession()) + { + basic = s.Get<DateClass>(savedId); + basic.DateValue.HasValue.Should().Be.False(); + s.Delete(basic); + s.Flush(); + } + } + } +} \ 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...> - 2010-07-22 04:57:13
|
Revision: 5037 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5037&view=rev Author: fabiomaulo Date: 2010-07-22 04:57:07 +0000 (Thu, 22 Jul 2010) Log Message: ----------- Fix NH-2216 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Type/PersistentEnumType.cs trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs trunk/nhibernate/src/NHibernate.Test/GenericTest/EnumGeneric/EnumGenericFixture.cs trunk/nhibernate/src/NHibernate.Test/TypesTest/PersistentEnumClass.hbm.xml trunk/nhibernate/src/NHibernate.Test/TypesTest/PersistentEnumTypeFixture.cs trunk/nhibernate/src/NHibernate.Test/TypesTest/TypeFactoryFixture.cs Modified: trunk/nhibernate/src/NHibernate/Type/PersistentEnumType.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/PersistentEnumType.cs 2010-07-22 03:55:22 UTC (rev 5036) +++ trunk/nhibernate/src/NHibernate/Type/PersistentEnumType.cs 2010-07-22 04:57:07 UTC (rev 5037) @@ -279,6 +279,22 @@ { return ReturnedClass.GetHashCode(); } + } + [Serializable] + public class EnumType<T> : PersistentEnumType + { + private readonly string typeName; + + public EnumType() : base(typeof (T)) + { + System.Type type = GetType(); + typeName = type.FullName + ", " + type.Assembly.GetName().Name; + } + + public override string Name + { + get { return typeName; } + } } } Modified: trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2010-07-22 03:55:22 UTC (rev 5036) +++ trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2010-07-22 04:57:07 UTC (rev 5037) @@ -498,11 +498,11 @@ } else if (typeClass.IsEnum) { - type = NHibernateUtil.Enum(typeClass); + type = (IType) Activator.CreateInstance(typeof (EnumType<>).MakeGenericType(typeClass)); } else if (IsNullableEnum(typeClass)) { - type = NHibernateUtil.Enum(typeClass.GetGenericArguments()[0]); + type = (IType)Activator.CreateInstance(typeof(EnumType<>).MakeGenericType(typeClass.GetGenericArguments()[0])); } else if (typeClass.IsSerializable) { Modified: trunk/nhibernate/src/NHibernate.Test/GenericTest/EnumGeneric/EnumGenericFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/GenericTest/EnumGeneric/EnumGenericFixture.cs 2010-07-22 03:55:22 UTC (rev 5036) +++ trunk/nhibernate/src/NHibernate.Test/GenericTest/EnumGeneric/EnumGenericFixture.cs 2010-07-22 04:57:07 UTC (rev 5037) @@ -4,6 +4,7 @@ using NHibernate.Persister.Entity; using NHibernate.Type; using NUnit.Framework; +using SharpTestsEx; namespace NHibernate.Test.GenericTest.EnumGeneric { @@ -44,7 +45,7 @@ if (index == -1) Assert.Fail("Property NullableValue not found."); - Assert.AreEqual(typeof (PersistentEnumType), persister.PropertyTypes[index].GetType()); + persister.PropertyTypes[index].Should().Be.AssignableTo<PersistentEnumType>(); } } Modified: trunk/nhibernate/src/NHibernate.Test/TypesTest/PersistentEnumClass.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/TypesTest/PersistentEnumClass.hbm.xml 2010-07-22 03:55:22 UTC (rev 5036) +++ trunk/nhibernate/src/NHibernate.Test/TypesTest/PersistentEnumClass.hbm.xml 2010-07-22 04:57:07 UTC (rev 5037) @@ -12,6 +12,6 @@ </id> <property name="A" /> - <property name="B" /> + <property name="B" type="NHibernate.Type.EnumType`1[[NHibernate.Test.TypesTest.B, NHibernate.Test]], NHibernate" /> </class> </hibernate-mapping> \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/TypesTest/PersistentEnumTypeFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/TypesTest/PersistentEnumTypeFixture.cs 2010-07-22 03:55:22 UTC (rev 5036) +++ trunk/nhibernate/src/NHibernate.Test/TypesTest/PersistentEnumTypeFixture.cs 2010-07-22 04:57:07 UTC (rev 5037) @@ -1,6 +1,7 @@ using System; using NHibernate.Type; using NUnit.Framework; +using SharpTestsEx; namespace NHibernate.Test.TypesTest { @@ -114,5 +115,35 @@ s2.Close(); } } + + [Test] + public void CanWriteAndReadUsingBothHeuristicAndExplicitGenericDeclaration() + { + var persistentEnumClass = new PersistentEnumClass {Id = 1, A = A.Two, B = B.One}; + using (ISession s = OpenSession()) + { + s.Save(persistentEnumClass); + s.Flush(); + } + + using (ISession s = sessions.OpenSession()) + { + var saved = s.Get<PersistentEnumClass>(1); + saved.A.Should().Be(A.Two); + saved.B.Should().Be(B.One); + s.Delete(saved); + s.Flush(); + } + } } + + public class GenericEnumTypeTest + { + [Test] + public void TheNameShouldBeFullNameAndAssembly() + { + var enumType = new EnumType<B>(); + enumType.Name.Should().Be(typeof(EnumType<B>).FullName + ", NHibernate"); + } + } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/TypesTest/TypeFactoryFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/TypesTest/TypeFactoryFixture.cs 2010-07-22 03:55:22 UTC (rev 5036) +++ trunk/nhibernate/src/NHibernate.Test/TypesTest/TypeFactoryFixture.cs 2010-07-22 04:57:07 UTC (rev 5037) @@ -3,6 +3,7 @@ using log4net.Repository.Hierarchy; using NHibernate.Type; using NUnit.Framework; +using SharpTestsEx; namespace NHibernate.Test.TypesTest { @@ -138,5 +139,24 @@ Assert.That(singleType, Is.SameAs(TypeFactory.Basic("Single(10,5)"))); Assert.That(singleType, Is.Not.SameAs(TypeFactory.Basic("Single(11,5)"))); } + + public enum MyEnum + { + One + } + + [Test] + public void WhenUseEnumThenReturnGenericEnumType() + { + var iType = TypeFactory.HeuristicType(typeof (MyEnum).AssemblyQualifiedName); + iType.Should().Be.OfType<EnumType<MyEnum>>(); + } + + [Test] + public void WhenUseNullableEnumThenReturnGenericEnumType() + { + var iType = TypeFactory.HeuristicType(typeof(MyEnum?).AssemblyQualifiedName); + iType.Should().Be.OfType<EnumType<MyEnum>>(); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-07-22 14:19:56
|
Revision: 5042 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5042&view=rev Author: fabiomaulo Date: 2010-07-22 14:19:50 +0000 (Thu, 22 Jul 2010) Log Message: ----------- Fix NH-2221 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/MappingExtensions.cs Added: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/MappingExtensions.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/MappingExtensions.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/MappingExtensions.cs 2010-07-22 14:19:50 UTC (rev 5042) @@ -0,0 +1,22 @@ +using System; + +namespace NHibernate.Cfg.MappingSchema +{ + public static class MappingExtensions + { + public static EntityMode ToEntityMode(this HbmTuplizerEntitymode source) + { + switch (source) + { + case HbmTuplizerEntitymode.Poco: + return EntityMode.Poco; + case HbmTuplizerEntitymode.Xml: + return EntityMode.Xml; + case HbmTuplizerEntitymode.DynamicMap: + return EntityMode.Map; + default: + throw new ArgumentOutOfRangeException("source"); + } + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs 2010-07-22 13:34:19 UTC (rev 5041) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs 2010-07-22 14:19:50 UTC (rev 5042) @@ -4,6 +4,7 @@ using NHibernate.Mapping; using System; using NHibernate.Util; +using Array = System.Array; namespace NHibernate.Cfg.XmlHbmBinding { @@ -333,6 +334,16 @@ { model.Owner.Table.CreateUniqueKey(model.ColumnIterator.OfType<Column>().ToList()); } + HbmTuplizer[] tuplizers = componentMapping.tuplizer; + if (tuplizers != null) + { + Array.ForEach(tuplizers.Select(tuplizer => new + { + TuplizerClassName = FullQualifiedClassName(tuplizer.@class, mappings), + Mode = tuplizer.entitymode.ToEntityMode() + }).ToArray(), + x => model.AddTuplizer(x.Mode, x.TuplizerClassName)); + } } private void BindManyToOneProperty(HbmManyToOne manyToOneMapping, Property property) Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-07-22 13:34:19 UTC (rev 5041) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-07-22 14:19:50 UTC (rev 5042) @@ -547,6 +547,7 @@ <Compile Include="Cfg\MappingSchema\IReferencePropertyMapping.cs" /> <Compile Include="Cfg\MappingSchema\IRelationship.cs" /> <Compile Include="Cfg\MappingSchema\ITypeMapping.cs" /> + <Compile Include="Cfg\MappingSchema\MappingExtensions.cs" /> <Compile Include="Cfg\SchemaAutoAction.cs" /> <Compile Include="Cfg\SessionFactoryConfigurationBase.cs" /> <Compile Include="Cfg\ISessionFactoryConfiguration.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-07-22 15:39:57
|
Revision: 5044 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5044&view=rev Author: fabiomaulo Date: 2010-07-22 15:39:51 +0000 (Thu, 22 Jul 2010) Log Message: ----------- Fix NH-2219 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/SqlCommand/SqlUpdateBuilder.cs trunk/nhibernate/src/NHibernate.Test/HQL/Ast/BulkManipulation.cs Modified: trunk/nhibernate/src/NHibernate/SqlCommand/SqlUpdateBuilder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/SqlCommand/SqlUpdateBuilder.cs 2010-07-22 14:21:58 UTC (rev 5043) +++ trunk/nhibernate/src/NHibernate/SqlCommand/SqlUpdateBuilder.cs 2010-07-22 15:39:51 UTC (rev 5044) @@ -123,14 +123,8 @@ public SqlUpdateBuilder AppendAssignmentFragment(SqlString fragment) { - if (assignments == null) - { - assignments = fragment; - } - else - { - assignments.Append(", ").Append(fragment); - } + // SqlString is immutable + assignments = assignments == null ? fragment : assignments.Append(", ").Append(fragment); return this; } Modified: trunk/nhibernate/src/NHibernate.Test/HQL/Ast/BulkManipulation.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/HQL/Ast/BulkManipulation.cs 2010-07-22 14:21:58 UTC (rev 5043) +++ trunk/nhibernate/src/NHibernate.Test/HQL/Ast/BulkManipulation.cs 2010-07-22 15:39:51 UTC (rev 5044) @@ -6,6 +6,7 @@ using NHibernate.Id; using NHibernate.Persister.Entity; using NUnit.Framework; +using SharpTestsEx; namespace NHibernate.Test.HQL.Ast { @@ -609,6 +610,37 @@ } [Test] + public void UpdateMultiplePropertyOnAnimal() + { + var data = new TestData(this); + data.Prepare(); + + using (ISession s = OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + int count = + s.CreateQuery("update Animal set description = :newDesc, bodyWeight = :w1 where description = :desc") + .SetString("desc", data.Polliwog.Description) + .SetString("newDesc", "Tadpole") + .SetDouble("w1", 3) + .ExecuteUpdate(); + + count.Should().Be(1); + t.Commit(); + } + + using (ISession s = OpenSession()) + using (s.BeginTransaction()) + { + var tadpole = s.Get<Animal>(data.Polliwog.Id); + tadpole.Description.Should().Be("Tadpole"); + tadpole.BodyWeight.Should().Be(3); + } + + data.Cleanup(); + } + + [Test] public void UpdateOnMammal() { var data = new TestData(this); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-07-22 16:50:56
|
Revision: 5048 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5048&view=rev Author: fabiomaulo Date: 2010-07-22 16:50:49 +0000 (Thu, 22 Jul 2010) Log Message: ----------- Fix NH-2031 (thanks to Andrea Balducci) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2031/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2031/HqlModFuctionForMsSqlTest.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2031/Mappings.hbm.xml Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2010-07-22 16:10:05 UTC (rev 5047) +++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2010-07-22 16:50:49 UTC (rev 5048) @@ -94,7 +94,7 @@ RegisterFunction("ln", new StandardSQLFunction("ln", NHibernateUtil.Double)); RegisterFunction("log", new StandardSQLFunction("log", NHibernateUtil.Double)); RegisterFunction("log10", new StandardSQLFunction("log10", NHibernateUtil.Double)); - RegisterFunction("mod", new SQLFunctionTemplate(NHibernateUtil.Int32, "(?1 % ?2)")); + RegisterFunction("mod", new SQLFunctionTemplate(NHibernateUtil.Int32, "((?1) % (?2))")); RegisterFunction("radians", new StandardSQLFunction("radians", NHibernateUtil.Double)); RegisterFunction("rand", new NoArgSQLFunction("rand", NHibernateUtil.Double)); RegisterFunction("sin", new StandardSQLFunction("sin", NHibernateUtil.Double)); Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2031/HqlModFuctionForMsSqlTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2031/HqlModFuctionForMsSqlTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2031/HqlModFuctionForMsSqlTest.cs 2010-07-22 16:50:49 UTC (rev 5048) @@ -0,0 +1,35 @@ +using NHibernate.Dialect; +using NHibernate.Hql.Ast.ANTLR; +using NHibernate.Util; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.NHSpecificTest.NH2031 +{ + public class MyClass + { + + } + public class HqlModFuctionForMsSqlTest : BugTestCase + { + protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect) + { + return dialect is MsSql2000Dialect; + } + + [Test] + public void TheModuleOperationShouldAddParenthesisToAvoidWrongSentence() + { + // The expected value should be "(5+1)%(1+1)" instead "5+ 1%1 +1" + var sqlQuery = GetSql("select mod(5+1,1+1) from MyClass"); + sqlQuery.Should().Contain("(5+1)").And.Contain("(1+1)"); + } + + public string GetSql(string query) + { + var qt = new QueryTranslatorImpl(null, new HqlParseEngine(query, false, sessions).Parse(), new CollectionHelper.EmptyMapClass<string, IFilter>(), sessions); + qt.Compile(null, false); + return qt.SQLString; + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2031/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2031/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2031/Mappings.hbm.xml 2010-07-22 16:50:49 UTC (rev 5048) @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.NH2031" + assembly="NHibernate.Test"> + + <class name="MyClass"> + <id type="int"> + <generator class="hilo" /> + </id> + </class> +</hibernate-mapping> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-22 16:10:05 UTC (rev 5047) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-22 16:50:49 UTC (rev 5048) @@ -452,6 +452,7 @@ <Compile Include="NHSpecificTest\NH1891\A.cs" /> <Compile Include="NHSpecificTest\NH1891\B.cs" /> <Compile Include="NHSpecificTest\NH1891\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2031\HqlModFuctionForMsSqlTest.cs" /> <Compile Include="NHSpecificTest\NH2061\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2061\Model.cs" /> <Compile Include="NHSpecificTest\NH2069\Fixture.cs" /> @@ -2202,6 +2203,7 @@ <EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" /> <EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH2031\Mappings.hbm.xml" /> <EmbeddedResource Include="TypesTest\DateClass.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2207\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2243\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2010-07-22 20:59:48
|
Revision: 5050 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5050&view=rev Author: ricbrown Date: 2010-07-22 20:59:41 +0000 (Thu, 22 Jul 2010) Log Message: ----------- Added missing .Not to stand alone lambda restriction. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/Lambda/LambdaRestrictionBuilder.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/Lambda/LambdaRestrictionBuilder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/Lambda/LambdaRestrictionBuilder.cs 2010-07-22 16:54:35 UTC (rev 5049) +++ trunk/nhibernate/src/NHibernate/Criterion/Lambda/LambdaRestrictionBuilder.cs 2010-07-22 20:59:41 UTC (rev 5050) @@ -16,21 +16,35 @@ { private string propertyName; private object lo; + private bool isNot; - public LambdaBetweenBuilder(string propertyName, object lo) + public LambdaBetweenBuilder(string propertyName, object lo, bool isNot) { this.propertyName = propertyName; this.lo = lo; + this.isNot = isNot; } public AbstractCriterion And(object hi) { + if (isNot) + return Restrictions.Not(Restrictions.Between(propertyName, lo, hi)); + return Restrictions.Between(propertyName, lo, hi); } } private string propertyName; + private bool isNot; + private ICriterion Process(ICriterion criterion) + { + if (isNot) + return Restrictions.Not(criterion); + + return criterion; + } + /// <summary> /// Constructed with property name /// </summary> @@ -44,103 +58,112 @@ /// </summary> public LambdaBetweenBuilder IsBetween(object lo) { - return new LambdaBetweenBuilder(propertyName, lo); + return new LambdaBetweenBuilder(propertyName, lo, isNot); } + public LambdaRestrictionBuilder Not + { + get + { + isNot = !isNot; + return this; + } + } + /// <summary> /// Apply an "in" constraint to the named property /// </summary> - public AbstractCriterion IsIn(ICollection values) + public ICriterion IsIn(ICollection values) { - return Restrictions.In(propertyName, values); + return Process(Restrictions.In(propertyName, values)); } /// <summary> /// Apply an "in" constraint to the named property /// </summary> - public AbstractCriterion IsIn(object[] values) + public ICriterion IsIn(object[] values) { - return Restrictions.In(propertyName, values); + return Process(Restrictions.In(propertyName, values)); } /// <summary> /// Apply an "in" constraint to the named property /// </summary> - public AbstractCriterion IsInG<T>(ICollection<T> values) + public ICriterion IsInG<T>(ICollection<T> values) { - return Restrictions.InG(propertyName, values); + return Process(Restrictions.InG(propertyName, values)); } /// <summary> /// A case-insensitive "like", similar to Postgres "ilike" operator /// </summary> - public AbstractCriterion IsInsensitiveLike(object value) + public ICriterion IsInsensitiveLike(object value) { - return Restrictions.InsensitiveLike(propertyName, value); + return Process(Restrictions.InsensitiveLike(propertyName, value)); } /// <summary> /// A case-insensitive "like", similar to Postgres "ilike" operator /// </summary> - public AbstractCriterion IsInsensitiveLike(string value, MatchMode matchMode) + public ICriterion IsInsensitiveLike(string value, MatchMode matchMode) { - return Restrictions.InsensitiveLike(propertyName, value, matchMode); + return Process(Restrictions.InsensitiveLike(propertyName, value, matchMode)); } /// <summary> /// Apply an "is empty" constraint to the named property /// </summary> - public AbstractEmptinessExpression IsEmpty + public ICriterion IsEmpty { - get { return Restrictions.IsEmpty(propertyName); } + get { return Process(Restrictions.IsEmpty(propertyName)); } } /// <summary> /// Apply a "not is empty" constraint to the named property /// </summary> - public AbstractEmptinessExpression IsNotEmpty + public ICriterion IsNotEmpty { - get { return Restrictions.IsNotEmpty(propertyName); } + get { return Process(Restrictions.IsNotEmpty(propertyName)); } } /// <summary> /// Apply an "is null" constraint to the named property /// </summary> - public AbstractCriterion IsNull + public ICriterion IsNull { - get { return Restrictions.IsNull(propertyName); } + get { return Process(Restrictions.IsNull(propertyName)); } } /// <summary> /// Apply an "not is null" constraint to the named property /// </summary> - public AbstractCriterion IsNotNull + public ICriterion IsNotNull { - get { return Restrictions.IsNotNull(propertyName); } + get { return Process(Restrictions.IsNotNull(propertyName)); } } /// <summary> /// Apply a "like" constraint to the named property /// </summary> - public SimpleExpression IsLike(object value) + public ICriterion IsLike(object value) { - return Restrictions.Like(propertyName, value); + return Process(Restrictions.Like(propertyName, value)); } /// <summary> /// Apply a "like" constraint to the named property /// </summary> - public SimpleExpression IsLike(string value, MatchMode matchMode) + public ICriterion IsLike(string value, MatchMode matchMode) { - return Restrictions.Like(propertyName, value, matchMode); + return Process(Restrictions.Like(propertyName, value, matchMode)); } /// <summary> /// Apply a "like" constraint to the named property /// </summary> - public AbstractCriterion IsLike(string value, MatchMode matchMode, char? escapeChar) + public ICriterion IsLike(string value, MatchMode matchMode, char? escapeChar) { - return Restrictions.Like(propertyName, value, matchMode, escapeChar); + return Process(Restrictions.Like(propertyName, value, matchMode, escapeChar)); } } Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs 2010-07-22 16:54:35 UTC (rev 5049) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs 2010-07-22 20:59:41 UTC (rev 5050) @@ -40,12 +40,14 @@ CreateTestCriteria(typeof(Person), "personAlias") .Add(Restrictions.Between("Age", 18, 65)) .Add(Restrictions.Between("personAlias.Age", 18, 65)) + .Add(Restrictions.Not(Restrictions.Between("personAlias.Age", 10, 20))) .Add(Restrictions.In("Name", new string[] { "name1", "name2", "name3" })) .Add(Restrictions.In("Name", new ArrayList() { "name1", "name2", "name3" })) .Add(Restrictions.InG<int>("Age", new int[] { 1, 2, 3 })) .Add(Restrictions.InsensitiveLike("Name", "test")) .Add(Restrictions.InsensitiveLike("Name", "tEsT", MatchMode.Anywhere)) .Add(Restrictions.IsEmpty("Children")) + .Add(Restrictions.Not(Restrictions.IsEmpty("Children"))) .Add(Restrictions.IsNotEmpty("Children")) .Add(Restrictions.IsNotNull("Name")) .Add(Restrictions.IsNull("Name")) @@ -61,12 +63,14 @@ CreateTestQueryOver<Person>(() => personAlias) .Where(Restrictions.On<Person>(p => p.Age).IsBetween(18).And(65)) .And(Restrictions.On(() => personAlias.Age).IsBetween(18).And(65)) + .And(Restrictions.On(() => personAlias.Age).Not.IsBetween(10).And(20)) .And(Restrictions.On<Person>(p => p.Name).IsIn(new string[] { "name1", "name2", "name3" })) .And(Restrictions.On<Person>(p => p.Name).IsIn(new ArrayList() { "name1", "name2", "name3" })) .And(Restrictions.On<Person>(p => p.Age).IsInG<int>(new int[] { 1, 2, 3 })) .And(Restrictions.On<Person>(p => p.Name).IsInsensitiveLike("test")) .And(Restrictions.On<Person>(p => p.Name).IsInsensitiveLike("tEsT", MatchMode.Anywhere)) .And(Restrictions.On<Person>(p => p.Children).IsEmpty) + .And(Restrictions.On<Person>(p => p.Children).Not.IsEmpty) .And(Restrictions.On<Person>(p => p.Children).IsNotEmpty) .And(Restrictions.On<Person>(p => p.Name).IsNotNull) .And(Restrictions.On<Person>(p => p.Name).IsNull) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-07-23 03:51:31
|
Revision: 5051 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5051&view=rev Author: fabiomaulo Date: 2010-07-23 03:51:24 +0000 (Fri, 23 Jul 2010) Log Message: ----------- Fix NH-2166 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Exceptions/ADOExceptionHelper.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj trunk/nhibernate/src/NHibernate.Test/ProjectionFixtures/Fixture.cs Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2166/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2166/Fixture.cs Modified: trunk/nhibernate/src/NHibernate/Exceptions/ADOExceptionHelper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Exceptions/ADOExceptionHelper.cs 2010-07-22 20:59:41 UTC (rev 5050) +++ trunk/nhibernate/src/NHibernate/Exceptions/ADOExceptionHelper.cs 2010-07-23 03:51:24 UTC (rev 5051) @@ -55,13 +55,13 @@ return Convert(converter, new AdoExceptionContextInfo {SqlException = sqlException, Message = message, Sql = sql}); } - public static ADOException Convert(ISQLExceptionConverter converter, Exception sqle, string message, SqlString sql, + public static Exception Convert(ISQLExceptionConverter converter, Exception sqle, string message, SqlString sql, object[] parameterValues, IDictionary<string, TypedValue> namedParameters) { sql = TryGetActualSqlQuery(sqle, sql); string extendMessage = ExtendMessage(message, sql != null ? sql.ToString() : null, parameterValues, namedParameters); ADOExceptionReporter.LogExceptions(sqle, extendMessage); - return new ADOException(extendMessage, sqle, sql != null ? sql.ToString() : SQLNotAvailable); + return Convert(converter, sqle, extendMessage, sql); } /// <summary> For the given <see cref="Exception"/>, locates the <see cref="System.Data.Common.DbException"/>. </summary> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2166/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2166/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2166/Fixture.cs 2010-07-23 03:51:24 UTC (rev 5051) @@ -0,0 +1,25 @@ +using System; +using System.Collections; +using NHibernate.Exceptions; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.NHSpecificTest.NH2166 +{ + public class Fixture: TestCase + { + protected override IList Mappings + { + get { return new string[0]; } + } + + [Test] + public void WhenUniqueResultShouldCallConverter() + { + using (var s = OpenSession()) + { + Executing.This(()=> s.CreateSQLQuery("select make from ItFunky").UniqueResult<int>()).Should().Throw<GenericADOException>(); + } + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-22 20:59:41 UTC (rev 5050) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-23 03:51:24 UTC (rev 5051) @@ -470,6 +470,7 @@ <Compile Include="NHSpecificTest\NH2094\Model.cs" /> <Compile Include="NHSpecificTest\NH2102\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2102\Model.cs" /> + <Compile Include="NHSpecificTest\NH2166\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2189\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2189\Model.cs" /> <Compile Include="NHSpecificTest\ElementsEnums\AbstractIntEnumsBagFixture.cs" /> Modified: trunk/nhibernate/src/NHibernate.Test/ProjectionFixtures/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/ProjectionFixtures/Fixture.cs 2010-07-22 20:59:41 UTC (rev 5050) +++ trunk/nhibernate/src/NHibernate.Test/ProjectionFixtures/Fixture.cs 2010-07-23 03:51:24 UTC (rev 5051) @@ -1,3 +1,4 @@ +using System; using NHibernate.Criterion; using NHibernate.Driver; using NUnit.Framework; @@ -93,7 +94,7 @@ } Assert.Fail(); } - catch (ADOException e) + catch (Exception e) { if(e.Message != expectedMessage) throw; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-07-23 04:39:06
|
Revision: 5052 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5052&view=rev Author: fabiomaulo Date: 2010-07-23 04:38:56 +0000 (Fri, 23 Jul 2010) Log Message: ----------- Fix NH-2041 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs trunk/nhibernate/src/NHibernate/Mapping/Component.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2041/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2041/Domain.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2041/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2041/Mappings.hbm.xml Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs 2010-07-23 03:51:24 UTC (rev 5051) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs 2010-07-23 04:38:56 UTC (rev 5052) @@ -114,7 +114,7 @@ else if ((componentMapping = entityPropertyMapping as HbmComponent) != null) { string subpath = propertyName == null ? null : StringHelper.Qualify(propertyBasePath, propertyName); - var value = CreateNewComponent(); + var value = CreateNewComponent(table); // NH: Modified from H2.1 to allow specifying the type explicitly using class attribute System.Type reflectedClass = mappedClass == null ? null : GetPropertyType(componentMapping.Class, mappedClass, propertyName, componentMapping.Access); BindComponent(componentMapping, value, reflectedClass, entityName, subpath, componetDefaultNullable, inheritedMetas); @@ -131,7 +131,7 @@ else if ((dynamicComponentMapping = entityPropertyMapping as HbmDynamicComponent) != null) { string subpath = propertyName == null ? null : StringHelper.Qualify(propertyBasePath, propertyName); - var value = CreateNewComponent(); + var value = CreateNewComponent(table); // NH: Modified from H2.1 to allow specifying the type explicitly using class attribute System.Type reflectedClass = mappedClass == null ? null : GetPropertyType(dynamicComponentMapping.Class, mappedClass, propertyName, dynamicComponentMapping.Access); BindComponent(dynamicComponentMapping, value, reflectedClass, entityName, subpath, componetDefaultNullable, inheritedMetas); @@ -152,7 +152,7 @@ throw new AssertionFailure("Nested Composite Element without a owner component."); } string subpath = propertyName == null ? null : StringHelper.Qualify(propertyBasePath, propertyName); - var value = CreateNewComponent(); + var value = CreateNewComponent(table); // NH: Modified from H2.1 to allow specifying the type explicitly using class attribute System.Type reflectedClass = mappedClass == null ? null : GetPropertyType(nestedCompositeElementMapping.Class, mappedClass, propertyName, nestedCompositeElementMapping.access); BindComponent(nestedCompositeElementMapping, value, reflectedClass, entityName, subpath, componetDefaultNullable, inheritedMetas); @@ -180,10 +180,10 @@ } } - private Component CreateNewComponent() + private Component CreateNewComponent(Table table) { // Manage nested components - return component != null ? new Component(component) : new Component(persistentClass); + return component != null ? new Component(component) : new Component(table, persistentClass); } private System.Type GetPropertyType(string classMapping, System.Type containingType, string propertyName, string propertyAccess) Modified: trunk/nhibernate/src/NHibernate/Mapping/Component.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/Component.cs 2010-07-23 03:51:24 UTC (rev 5051) +++ trunk/nhibernate/src/NHibernate/Mapping/Component.cs 2010-07-23 04:38:56 UTC (rev 5052) @@ -92,18 +92,18 @@ this.owner = owner; } + public Component(Table table, PersistentClass owner) + : base(table) + { + this.owner = owner; + } + public Component(Collection collection) : base(collection.CollectionTable) { owner = collection.Owner; } - public Component(Join join) - : base(join.Table) - { - owner = join.PersistentClass; - } - public Component(Component component) : base(component.Table) { Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2041/Domain.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2041/Domain.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2041/Domain.cs 2010-07-23 04:38:56 UTC (rev 5052) @@ -0,0 +1,13 @@ +namespace NHibernate.Test.NHSpecificTest.NH2041 +{ + public class MyClass + { + public Coordinates Location { get; set; } + } + + public class Coordinates + { + public decimal Latitude { get; set; } + public decimal Longitude { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2041/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2041/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2041/Fixture.cs 2010-07-23 04:38:56 UTC (rev 5052) @@ -0,0 +1,21 @@ +using System.Linq; +using NUnit.Framework; +using NHibernate.Cfg; +using SharpTestsEx; + +namespace NHibernate.Test.NHSpecificTest.NH2041 +{ + public class Fixture + { + [Test] + public void WhenJoinTableContainComponentsThenColumnsShouldBeInJoinedTable() + { + Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration(); + cfg.AddResource("NHibernate.Test.NHSpecificTest.NH2041.Mappings.hbm.xml", GetType().Assembly); + var mappings = cfg.CreateMappings(Dialect.Dialect.GetDialect(cfg.Properties)); + var table = mappings.GetTable(null, null, "Locations"); + table.Should().Not.Be.Null(); + table.ColumnIterator.Select(c => c.Name).Should().Have.SameValuesAs("myclassId", "latitudecol", "longitudecol"); + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2041/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2041/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2041/Mappings.hbm.xml 2010-07-23 04:38:56 UTC (rev 5052) @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.NH2041" + assembly="NHibernate.Test"> + + <class name="MyClass"> + <id type="int"> + <generator class="hilo" /> + </id> + <join table="Locations"> + <key column="myclassId"/> + <component name="Location"> + <property name="Latitude" column="latitudecol"/> + <property name="Longitude" column="longitudecol"/> + </component> + </join> + </class> +</hibernate-mapping> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-23 03:51:24 UTC (rev 5051) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-23 04:38:56 UTC (rev 5052) @@ -453,6 +453,8 @@ <Compile Include="NHSpecificTest\NH1891\B.cs" /> <Compile Include="NHSpecificTest\NH1891\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2031\HqlModFuctionForMsSqlTest.cs" /> + <Compile Include="NHSpecificTest\NH2041\Domain.cs" /> + <Compile Include="NHSpecificTest\NH2041\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2061\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2061\Model.cs" /> <Compile Include="NHSpecificTest\NH2069\Fixture.cs" /> @@ -2204,6 +2206,7 @@ <EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" /> <EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH2041\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2031\Mappings.hbm.xml" /> <EmbeddedResource Include="TypesTest\DateClass.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2207\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-07-23 14:37:09
|
Revision: 5055 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5055&view=rev Author: fabiomaulo Date: 2010-07-23 14:37:02 +0000 (Fri, 23 Jul 2010) Log Message: ----------- Fix NH-2194 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Util/PropertiesHelper.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/UtilityTest/PropertiesHelperTest.cs Modified: trunk/nhibernate/src/NHibernate/Util/PropertiesHelper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Util/PropertiesHelper.cs 2010-07-23 05:37:14 UTC (rev 5054) +++ trunk/nhibernate/src/NHibernate/Util/PropertiesHelper.cs 2010-07-23 14:37:02 UTC (rev 5055) @@ -12,29 +12,29 @@ { string toParse; properties.TryGetValue(property, out toParse); - - return toParse == null ? defaultValue : bool.Parse(toParse); + bool result; + return bool.TryParse(toParse, out result) ? result : defaultValue; } public static bool GetBoolean(string property, IDictionary<string, string> properties) { - string toParse; - properties.TryGetValue(property, out toParse); - return toParse == null ? false : bool.Parse(properties[property]); + return GetBoolean(property, properties, false); } public static int GetInt32(string property, IDictionary<string, string> properties, int defaultValue) { string toParse; properties.TryGetValue(property, out toParse); - return toParse == null ? defaultValue : int.Parse(toParse); + int result; + return int.TryParse(toParse, out result) ? result : defaultValue; } public static long GetInt64(string property, IDictionary<string, string> properties, long defaultValue) { string toParse; properties.TryGetValue(property, out toParse); - return toParse == null ? defaultValue : long.Parse(toParse); + long result; + return long.TryParse(toParse, out result) ? result : defaultValue; } public static string GetString(string property, IDictionary<string, string> properties, string defaultValue) Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-23 05:37:14 UTC (rev 5054) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-23 14:37:02 UTC (rev 5055) @@ -1610,6 +1610,7 @@ <Compile Include="UtilityTest\JoinedEnumerableGenericFixture.cs" /> <Compile Include="UtilityTest\LinkedHashMapFixture.cs" /> <Compile Include="UtilityTest\LRUMapFixture.cs" /> + <Compile Include="UtilityTest\PropertiesHelperTest.cs" /> <Compile Include="UtilityTest\ReflectHelperFixture.cs" /> <Compile Include="UtilityTest\SafetyEnumerableFixture.cs" /> <Compile Include="UtilityTest\SequencedHashMapFixture.cs" /> Added: trunk/nhibernate/src/NHibernate.Test/UtilityTest/PropertiesHelperTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/UtilityTest/PropertiesHelperTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/UtilityTest/PropertiesHelperTest.cs 2010-07-23 14:37:02 UTC (rev 5055) @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using NHibernate.Util; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.UtilityTest +{ + public class PropertiesHelperTest + { + [Test] + public void WhenInvalidBoolValueThenUseDefault() + { + PropertiesHelper.GetBoolean("myProp", new Dictionary<string, string> {{"myProp", "pizza"}}, false).Should().Be.False(); + } + + [Test] + public void WhenInvalidInt32ValueThenUseDefault() + { + PropertiesHelper.GetInt32("myProp", new Dictionary<string, string> { { "myProp", "pizza" } }, 5).Should().Be(5); + } + + [Test] + public void WhenInvalidInt64ValueThenUseDefault() + { + PropertiesHelper.GetInt64("myProp", new Dictionary<string, string> { { "myProp", "pizza" } }, 5).Should().Be(5); + } + + [Test] + public void WhenValidBoolValueThenValue() + { + PropertiesHelper.GetBoolean("myProp", new Dictionary<string, string> { { "myProp", "true" } }, false).Should().Be.True(); + } + + [Test] + public void WhenValidInt32ValueThenValue() + { + PropertiesHelper.GetInt32("myProp", new Dictionary<string, string> { { "myProp", int.MaxValue.ToString() } }, 5).Should().Be(int.MaxValue); + } + + [Test] + public void WhenValidInt64ValueThenValue() + { + PropertiesHelper.GetInt64("myProp", new Dictionary<string, string> { { "myProp", long.MaxValue.ToString() } }, 5).Should().Be(long.MaxValue); + } + } +} \ 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...> - 2010-07-27 17:52:10
|
Revision: 5062 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5062&view=rev Author: fabiomaulo Date: 2010-07-27 17:52:03 +0000 (Tue, 27 Jul 2010) Log Message: ----------- SchemaExport supporting auto-quote configuration Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/Tools/hbm2ddl/SchemaExportTests/AutoQuoteFixture.cs Modified: trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs 2010-07-27 17:08:22 UTC (rev 5061) +++ trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs 2010-07-27 17:52:03 UTC (rev 5062) @@ -55,6 +55,13 @@ { return; } + string autoKeyWordsImport = PropertiesHelper.GetString(Environment.Hbm2ddlKeyWords, configProperties, "not-defined"); + autoKeyWordsImport = autoKeyWordsImport.ToLowerInvariant(); + if (autoKeyWordsImport == Hbm2DDLKeyWords.AutoQuote) + { + SchemaMetadataUpdater.QuoteTableAndColumns(cfg); + } + dialect = Dialect.Dialect.GetDialect(configProperties); dropSQL = cfg.GenerateDropSchemaScript(dialect); createSQL = cfg.GenerateSchemaCreationScript(dialect); Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-27 17:08:22 UTC (rev 5061) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-27 17:52:03 UTC (rev 5062) @@ -1434,6 +1434,7 @@ <Compile Include="SqlTest\SqlTypeFactoryFixture.cs" /> <Compile Include="Stateless\Naturalness.cs" /> <Compile Include="Stateless\StatelessWithRelationsFixture.cs" /> + <Compile Include="Tools\hbm2ddl\SchemaExportTests\AutoQuoteFixture.cs" /> <Compile Include="Tools\hbm2ddl\SchemaExportTests\WithColumnTag.cs" /> <Compile Include="Tools\hbm2ddl\SchemaExportTests\WithColumnTagFixture.cs" /> <Compile Include="Tools\hbm2ddl\SchemaMetadataUpdaterTest\HeavyEntity.cs" /> Added: trunk/nhibernate/src/NHibernate.Test/Tools/hbm2ddl/SchemaExportTests/AutoQuoteFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Tools/hbm2ddl/SchemaExportTests/AutoQuoteFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Tools/hbm2ddl/SchemaExportTests/AutoQuoteFixture.cs 2010-07-27 17:52:03 UTC (rev 5062) @@ -0,0 +1,31 @@ +using System.Text; +using NHibernate.Cfg; +using NHibernate.Dialect; +using NHibernate.Tool.hbm2ddl; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.Tools.hbm2ddl.SchemaExportTests +{ + public class AutoQuoteFixture + { + [Test] + public void WhenCalledExplicitlyThenTakeInAccountHbm2DdlKeyWordsSetting() + { + var configuration = TestConfigurationHelper.GetDefaultConfiguration(); + var dialect = NHibernate.Dialect.Dialect.GetDialect(configuration.Properties); + if(!(dialect is MsSql2000Dialect)) + { + Assert.Ignore(GetType() + " does not apply to " + dialect); + } + + configuration.SetProperty(Environment.Hbm2ddlKeyWords, "auto-quote"); + configuration.AddResource("NHibernate.Test.Tools.hbm2ddl.SchemaMetadataUpdaterTest.HeavyEntity.hbm.xml", + GetType().Assembly); + + var script = new StringBuilder(); + new SchemaExport(configuration).Execute(s=> script.AppendLine(s), false, false); + script.ToString().Should().Contain("[Order]").And.Contain("[Select]").And.Contain("[From]").And.Contain("[And]"); + } + } +} \ 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...> - 2010-07-27 18:36:15
|
Revision: 5063 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5063&view=rev Author: fabiomaulo Date: 2010-07-27 18:36:09 +0000 (Tue, 27 Jul 2010) Log Message: ----------- SchemaUpdate supporting auto-quote configuration (end Fix NH-2253) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaUpdate.cs trunk/nhibernate/src/NHibernate.Test/Tools/hbm2ddl/SchemaExportTests/AutoQuoteFixture.cs Modified: trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaUpdate.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaUpdate.cs 2010-07-27 17:52:03 UTC (rev 5062) +++ trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaUpdate.cs 2010-07-27 18:36:09 UTC (rev 5063) @@ -139,6 +139,13 @@ { log.Info("Running hbm2ddl schema update"); + string autoKeyWordsImport = PropertiesHelper.GetString(Environment.Hbm2ddlKeyWords, configuration.Properties, "not-defined"); + autoKeyWordsImport = autoKeyWordsImport.ToLowerInvariant(); + if (autoKeyWordsImport == Hbm2DDLKeyWords.AutoQuote) + { + SchemaMetadataUpdater.QuoteTableAndColumns(configuration); + } + DbConnection connection; IDbCommand stmt = null; Modified: trunk/nhibernate/src/NHibernate.Test/Tools/hbm2ddl/SchemaExportTests/AutoQuoteFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Tools/hbm2ddl/SchemaExportTests/AutoQuoteFixture.cs 2010-07-27 17:52:03 UTC (rev 5062) +++ trunk/nhibernate/src/NHibernate.Test/Tools/hbm2ddl/SchemaExportTests/AutoQuoteFixture.cs 2010-07-27 18:36:09 UTC (rev 5063) @@ -1,6 +1,10 @@ +using System.Collections.Generic; +using System.Linq; using System.Text; using NHibernate.Cfg; using NHibernate.Dialect; +using NHibernate.Mapping; +using NHibernate.Test.Tools.hbm2ddl.SchemaMetadataUpdaterTest; using NHibernate.Tool.hbm2ddl; using NUnit.Framework; using SharpTestsEx; @@ -27,5 +31,32 @@ new SchemaExport(configuration).Execute(s=> script.AppendLine(s), false, false); script.ToString().Should().Contain("[Order]").And.Contain("[Select]").And.Contain("[From]").And.Contain("[And]"); } + + [Test] + public void WhenUpdateCalledExplicitlyThenTakeInAccountHbm2DdlKeyWordsSetting() + { + var configuration = TestConfigurationHelper.GetDefaultConfiguration(); + var dialect = NHibernate.Dialect.Dialect.GetDialect(configuration.Properties); + if (!(dialect is MsSql2000Dialect)) + { + Assert.Ignore(GetType() + " does not apply to " + dialect); + } + + configuration.SetProperty(Environment.Hbm2ddlKeyWords, "auto-quote"); + configuration.AddResource("NHibernate.Test.Tools.hbm2ddl.SchemaMetadataUpdaterTest.HeavyEntity.hbm.xml", + GetType().Assembly); + + var script = new StringBuilder(); + new Tool.hbm2ddl.SchemaUpdate(configuration).Execute(s => script.AppendLine(s), false); + + // With SchemaUpdate the auto-quote method should be called and the conf. should hold quoted stuff + var cm = configuration.GetClassMapping(typeof(Order)); + var culs = cm.Table.ColumnIterator.ToList(); + cm.Table.Satisfy(t=> t.IsQuoted); + culs.First(c => "From".Equals(c.Name)).Satisfy(c=> c.IsQuoted); + culs.First(c => "And".Equals(c.Name)).Satisfy(c => c.IsQuoted); + culs.First(c => "Select".Equals(c.Name)).Satisfy(c => c.IsQuoted); + culs.First(c => "Column".Equals(c.Name)).Satisfy(c => c.IsQuoted); + } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |