-
Notifications
You must be signed in to change notification settings - Fork 933
NH-3693 - AliasToBeanResultTransformer fails under Firebird #330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
42c5b85
af58562
3409f8f
51e454d
5a7529f
a55a9fe
9bd8d1a
0d628f3
7e61b14
b20526a
c62df4a
1d949eb
8dfccf4
5d8f2dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH1904 | ||
{ | ||
[TestFixture] | ||
public class StructFixture : BugTestCase | ||
{ | ||
protected override IList Mappings => | ||
new string[] | ||
{ | ||
"NHSpecificTest." + BugNumber + ".StructMappings.hbm.xml" | ||
}; | ||
|
||
[Test] | ||
public void ExecuteQuery() | ||
{ | ||
using (ISession session = OpenSession()) | ||
using (ITransaction transaction = session.BeginTransaction()) | ||
{ | ||
var invoice = new InvoiceWithAddress | ||
{ | ||
Issued = DateTime.Now, | ||
BillingAddress = new Address { Line = "84 rue du 22 septembre", City = "Courbevoie", ZipCode = "92400", Country = "France" } | ||
}; | ||
session.Save(invoice); | ||
transaction.Commit(); | ||
} | ||
|
||
using (ISession session = OpenSession()) | ||
{ | ||
var invoices = session.CreateCriteria<Invoice>().List<Invoice>(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
base.OnTearDown(); | ||
using (ISession session = OpenSession()) | ||
{ | ||
session.CreateQuery("delete from InvoiceWithAddress").ExecuteUpdate(); | ||
session.Flush(); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" | ||
assembly="NHibernate.Test" | ||
namespace="NHibernate.Test.NHSpecificTest.NH1904"> | ||
|
||
<class name="InvoiceWithAddress"> | ||
<id name="ID" type="Int32"> | ||
<generator class="hilo" /> | ||
</id> | ||
|
||
<property name="Issued" type="DateTime" /> | ||
|
||
<component name="BillingAddress"> | ||
<property name="Line"/> | ||
<property name="Line2"/> | ||
<property name="City"/> | ||
<property name="ZipCode"/> | ||
<property name="Country"/> | ||
</component> | ||
</class> | ||
|
||
</hibernate-mapping> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Reflection; | ||
using NHibernate.Properties; | ||
|
||
namespace NHibernate.Transform | ||
{ | ||
|
@@ -27,10 +26,9 @@ namespace NHibernate.Transform | |
[Serializable] | ||
public class AliasToBeanResultTransformer : AliasedTupleSubsetResultTransformer | ||
{ | ||
private readonly QueryAliasToObjectPropertySetter _propertySetter; | ||
private const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; | ||
private readonly System.Type resultClass; | ||
private ISetter[] setters; | ||
private readonly IPropertyAccessor propertyAccessor; | ||
private readonly ConstructorInfo constructor; | ||
|
||
public AliasToBeanResultTransformer(System.Type resultClass) | ||
|
@@ -48,22 +46,17 @@ public AliasToBeanResultTransformer(System.Type resultClass) | |
if (constructor == null && resultClass.IsClass) | ||
{ | ||
throw new ArgumentException("The target class of a AliasToBeanResultTransformer need a parameter-less constructor", | ||
"resultClass"); | ||
"resultClass"); | ||
} | ||
|
||
propertyAccessor = | ||
new ChainedPropertyAccessor(new[] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the only usage of the class (Of course, if we keep current changes, not reverting back to 42c5b85.) |
||
{ | ||
PropertyAccessorFactory.GetPropertyAccessor(null), | ||
PropertyAccessorFactory.GetPropertyAccessor("field") | ||
}); | ||
_propertySetter = QueryAliasToObjectPropertySetter.MakeFor(resultClass); | ||
} | ||
|
||
|
||
public override bool IsTransformedValueATupleElement(String[] aliases, int tupleLength) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
|
||
public override object TransformTuple(object[] tuple, String[] aliases) | ||
|
@@ -76,30 +69,13 @@ public override object TransformTuple(object[] tuple, String[] aliases) | |
|
||
try | ||
{ | ||
if (setters == null) | ||
{ | ||
setters = new ISetter[aliases.Length]; | ||
for (int i = 0; i < aliases.Length; i++) | ||
{ | ||
string alias = aliases[i]; | ||
if (alias != null) | ||
{ | ||
setters[i] = propertyAccessor.GetSetter(resultClass, alias); | ||
} | ||
} | ||
} | ||
|
||
// if resultClass is not a class but a value type, we need to use Activator.CreateInstance | ||
result = resultClass.IsClass | ||
? constructor.Invoke(null) | ||
: Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(resultClass, true); | ||
? constructor.Invoke(null) | ||
: Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(resultClass, true); | ||
|
||
for (int i = 0; i < aliases.Length; i++) | ||
{ | ||
if (setters[i] != null) | ||
{ | ||
setters[i].Set(result, tuple[i]); | ||
} | ||
_propertySetter.SetProperty(aliases[i], tuple[i], result); | ||
} | ||
} | ||
catch (InstantiationException e) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#330 (diff)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, good for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does fix NH-1904 for the struct case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but if we're going towards QueryAliasToObjectPropertySetter then I would suggest a separate PR for this then. I only did it here because it "was" used in AliasToBeanResultTransformer.