You can subscribe to this list here.
| 2004 |
Jan
|
Feb
|
Mar
|
Apr
(248) |
May
(82) |
Jun
(90) |
Jul
(177) |
Aug
(253) |
Sep
(157) |
Oct
(151) |
Nov
(143) |
Dec
(278) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2005 |
Jan
(152) |
Feb
(107) |
Mar
(177) |
Apr
(133) |
May
(259) |
Jun
(81) |
Jul
(119) |
Aug
(306) |
Sep
(416) |
Oct
(240) |
Nov
(329) |
Dec
(206) |
| 2006 |
Jan
(466) |
Feb
(382) |
Mar
(153) |
Apr
(162) |
May
(133) |
Jun
(21) |
Jul
(18) |
Aug
(37) |
Sep
(97) |
Oct
(114) |
Nov
(110) |
Dec
(28) |
| 2007 |
Jan
(74) |
Feb
(65) |
Mar
(49) |
Apr
(76) |
May
(43) |
Jun
(15) |
Jul
(68) |
Aug
(55) |
Sep
(63) |
Oct
(59) |
Nov
(70) |
Dec
(66) |
| 2008 |
Jan
(71) |
Feb
(60) |
Mar
(120) |
Apr
(31) |
May
(48) |
Jun
(81) |
Jul
(107) |
Aug
(51) |
Sep
(80) |
Oct
(83) |
Nov
(83) |
Dec
(79) |
| 2009 |
Jan
(83) |
Feb
(110) |
Mar
(97) |
Apr
(91) |
May
(291) |
Jun
(250) |
Jul
(197) |
Aug
(58) |
Sep
(54) |
Oct
(122) |
Nov
(68) |
Dec
(34) |
| 2010 |
Jan
(50) |
Feb
(17) |
Mar
(63) |
Apr
(61) |
May
(84) |
Jun
(81) |
Jul
(138) |
Aug
(144) |
Sep
(78) |
Oct
(26) |
Nov
(30) |
Dec
(61) |
| 2011 |
Jan
(33) |
Feb
(35) |
Mar
(166) |
Apr
(221) |
May
(109) |
Jun
(76) |
Jul
(27) |
Aug
(37) |
Sep
(1) |
Oct
(4) |
Nov
(2) |
Dec
(1) |
| 2012 |
Jan
|
Feb
|
Mar
(2) |
Apr
(2) |
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
(1) |
Dec
|
| 2013 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(1) |
Sep
(3) |
Oct
(2) |
Nov
|
Dec
(1) |
| 2014 |
Jan
(1) |
Feb
(1) |
Mar
(3) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <fab...@us...> - 2010-08-04 11:54:32
|
Revision: 5105
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5105&view=rev
Author: fabiomaulo
Date: 2010-08-04 11:54:24 +0000 (Wed, 04 Aug 2010)
Log Message:
-----------
Fix NH-2268
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Dialect/PostgreSQLDialect.cs
Modified: trunk/nhibernate/src/NHibernate/Dialect/PostgreSQLDialect.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Dialect/PostgreSQLDialect.cs 2010-08-03 13:04:37 UTC (rev 5104)
+++ trunk/nhibernate/src/NHibernate/Dialect/PostgreSQLDialect.cs 2010-08-04 11:54:24 UTC (rev 5105)
@@ -63,6 +63,10 @@
RegisterFunction("str", new SQLFunctionTemplate(NHibernateUtil.String, "cast(?1 as varchar)"));
RegisterFunction("locate", new PositionSubstringFunction());
RegisterFunction("iif", new SQLFunctionTemplate(null, "case when ?1 then ?2 else ?3 end"));
+
+ RegisterFunction("substring", new AnsiSubstringFunction());
+ RegisterFunction("replace", new StandardSQLFunction("replace", NHibernateUtil.String));
+
DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.NpgsqlDriver";
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <exa...@or...> - 2010-08-03 13:12:54
|
Take 2 a day for greater girth and permanent gains in length http://www.listocean.com/ |
|
From: <fab...@us...> - 2010-08-03 13:04:44
|
Revision: 5104
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5104&view=rev
Author: fabiomaulo
Date: 2010-08-03 13:04:37 +0000 (Tue, 03 Aug 2010)
Log Message:
-----------
Fix NH-2103
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Cfg/BindMappingEventArgs.cs
trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationAddMappingEvents.cs
Added: trunk/nhibernate/src/NHibernate/Cfg/BindMappingEventArgs.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/BindMappingEventArgs.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Cfg/BindMappingEventArgs.cs 2010-08-03 13:04:37 UTC (rev 5104)
@@ -0,0 +1,19 @@
+using System;
+using NHibernate.Cfg.MappingSchema;
+
+namespace NHibernate.Cfg
+{
+ public class BindMappingEventArgs: EventArgs
+ {
+ public BindMappingEventArgs(Dialect.Dialect dialect, HbmMapping mapping, string fileName)
+ {
+ Dialect = dialect;
+ Mapping = mapping;
+ FileName = fileName;
+ }
+
+ public Dialect.Dialect Dialect { get; private set; }
+ public HbmMapping Mapping { get; private set; }
+ public string FileName { get; private set; }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2010-08-03 11:41:25 UTC (rev 5103)
+++ trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2010-08-03 13:04:37 UTC (rev 5104)
@@ -496,6 +496,9 @@
AddDeserializedMapping(doc.Document, doc.Name);
}
+ public event EventHandler<BindMappingEventArgs> BeforeBindMapping;
+ public event EventHandler<BindMappingEventArgs> AfterBindMapping;
+
/// <summary>
/// Add mapping data using deserialized class.
/// </summary>
@@ -510,9 +513,11 @@
try
{
Dialect.Dialect dialect = Dialect.Dialect.GetDialect(properties);
+ OnBeforeBindMapping(new BindMappingEventArgs(dialect, mappingDocument, documentFileName));
Mappings mappings = CreateMappings(dialect);
new MappingRootBinder(mappings, dialect).Bind(mappingDocument);
+ OnAfterBindMapping(new BindMappingEventArgs(dialect, mappingDocument, documentFileName));
}
catch (Exception e)
{
@@ -523,6 +528,24 @@
}
}
+ private void OnAfterBindMapping(BindMappingEventArgs bindMappingEventArgs)
+ {
+ var handler = AfterBindMapping;
+ if (handler != null)
+ {
+ handler(this, bindMappingEventArgs);
+ }
+ }
+
+ private void OnBeforeBindMapping(BindMappingEventArgs bindMappingEventArgs)
+ {
+ var handler = BeforeBindMapping;
+ if(handler != null)
+ {
+ handler(this, bindMappingEventArgs);
+ }
+ }
+
/// <summary>
/// Create a new <see cref="Mappings" /> to add classes and collection
/// mappings to.
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-08-03 11:41:25 UTC (rev 5103)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-08-03 13:04:37 UTC (rev 5104)
@@ -467,6 +467,7 @@
<Compile Include="Bytecode\ProxyFactoryFactoryNotConfiguredException.cs" />
<Compile Include="Bytecode\UnableToLoadProxyFactoryFactoryException.cs" />
<Compile Include="Cache\FakeCache.cs" />
+ <Compile Include="Cfg\BindMappingEventArgs.cs" />
<Compile Include="Cfg\EntityCacheUsage.cs" />
<Compile Include="Cfg\FilterSecondPassArgs.cs" />
<Compile Include="Cfg\Hbm2ddlKeyWords.cs" />
Added: trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationAddMappingEvents.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationAddMappingEvents.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationAddMappingEvents.cs 2010-08-03 13:04:37 UTC (rev 5104)
@@ -0,0 +1,76 @@
+using System.Collections.Generic;
+using System.Linq;
+using NHibernate.Cfg;
+using NHibernate.Cfg.Loquacious;
+using NHibernate.Dialect;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.CfgTest
+{
+ public class ConfigurationAddMappingEvents
+ {
+ private const string ProductLineMapping =
+ @"<?xml version='1.0' encoding='utf-8' ?>
+<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'>
+ <class entity-name='ProductLine'>
+ <id name='Id' type='int'>
+ <generator class='hilo'/>
+ </id>
+ <property name='Description' not-null='true' length='200' type='string'/>
+ <bag name='Models' cascade='all' inverse='true'>
+ <key column='productId'/>
+ <one-to-many class='Model'/>
+ </bag>
+ </class>
+</hibernate-mapping>
+";
+ private const string ModelMapping =
+ @"<?xml version='1.0' encoding='utf-8' ?>
+<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'>
+ <class entity-name='Model'>
+ <id name='Id' type='int'>
+ <generator class='hilo'/>
+ </id>
+
+ <property name='Name' not-null='true' length='25' type='string'/>
+ <property name='Description' not-null='true' length='200' type='string'/>
+ <many-to-one name='ProductLine' column='productId' not-null='true' class='ProductLine'/>
+ </class>
+</hibernate-mapping>
+";
+ [Test]
+ public void WhenSubscribedToBeforeBindThenRaiseEventForEachMapping()
+ {
+ var listOfCalls = new List<BindMappingEventArgs>();
+ var configuration = new Configuration();
+ configuration.DataBaseIntegration(x => x.Dialect<MsSql2008Dialect>());
+ configuration.BeforeBindMapping += (sender, args) => { sender.Should().Be.SameInstanceAs(configuration); listOfCalls.Add(args); };
+
+ configuration.AddXmlString(ProductLineMapping);
+ configuration.AddXmlString(ModelMapping);
+
+ listOfCalls.Count.Should().Be(2);
+ listOfCalls.Select(x => x.FileName).All(x => x.Satisfy(filename => filename != null));
+ listOfCalls.Select(x => x.Mapping).All(x => x.Satisfy(mappingDoc => mappingDoc != null));
+ listOfCalls.Select(x => x.Dialect).All(x => x.Satisfy(dialect => dialect.GetType() == typeof(MsSql2008Dialect)));
+ }
+
+ [Test]
+ public void WhenSubscribedToAfterBindThenRaiseEventForEachMapping()
+ {
+ var listOfCalls = new List<BindMappingEventArgs>();
+ var configuration = new Configuration();
+ configuration.DataBaseIntegration(x => x.Dialect<MsSql2008Dialect>());
+ configuration.AfterBindMapping += (sender, args) => { sender.Should().Be.SameInstanceAs(configuration); listOfCalls.Add(args); };
+
+ configuration.AddXmlString(ProductLineMapping);
+ configuration.AddXmlString(ModelMapping);
+
+ listOfCalls.Count.Should().Be(2);
+ listOfCalls.Select(x => x.FileName).All(x => x.Satisfy(filename => filename != null));
+ listOfCalls.Select(x => x.Mapping).All(x => x.Satisfy(mappingDoc => mappingDoc != null));
+ listOfCalls.Select(x => x.Dialect).All(x => x.Satisfy(dialect => dialect.GetType() == typeof(MsSql2008Dialect)));
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-08-03 11:41:25 UTC (rev 5103)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-08-03 13:04:37 UTC (rev 5104)
@@ -109,6 +109,7 @@
<Compile Include="Cascade\JobBatch.cs" />
<Compile Include="Cascade\RefreshFixture.cs" />
<Compile Include="CfgTest\AccessorsSerializableTest.cs" />
+ <Compile Include="CfgTest\ConfigurationAddMappingEvents.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-08-03 11:41:31
|
Revision: 5103
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5103&view=rev
Author: fabiomaulo
Date: 2010-08-03 11:41:25 +0000 (Tue, 03 Aug 2010)
Log Message:
-----------
Fix NH-2148
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate.ByteCode.Castle/LazyFieldInterceptor.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2148/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2148/BugFixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2148/Domain.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2148/Mappings.hbm.xml
Modified: trunk/nhibernate/src/NHibernate.ByteCode.Castle/LazyFieldInterceptor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.ByteCode.Castle/LazyFieldInterceptor.cs 2010-08-03 10:47:31 UTC (rev 5102)
+++ trunk/nhibernate/src/NHibernate.ByteCode.Castle/LazyFieldInterceptor.cs 2010-08-03 11:41:25 UTC (rev 5103)
@@ -36,6 +36,10 @@
FieldInterceptor.Intercept(invocation.InvocationTarget, ReflectHelper.GetPropertyName(invocation.Method), null);
invocation.Proceed();
}
+ else
+ {
+ invocation.Proceed();
+ }
}
else
{
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2148/BugFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2148/BugFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2148/BugFixture.cs 2010-08-03 11:41:25 UTC (rev 5103)
@@ -0,0 +1,54 @@
+using NHibernate.ByteCode.Castle;
+using NHibernate.Cfg;
+using NUnit.Framework;
+namespace NHibernate.Test.NHSpecificTest.NH2148
+{
+ public class BugFixture : BugTestCase
+ {
+ protected override void Configure(NHibernate.Cfg.Configuration configuration)
+ {
+ configuration.SetProperty(Environment.ProxyFactoryFactoryClass,
+ typeof(ProxyFactoryFactory).AssemblyQualifiedName);
+ }
+
+ protected override void OnSetUp()
+ {
+ using (var s = OpenSession())
+ using (var tx = s.BeginTransaction())
+ {
+ s.Persist(new Book
+ {
+ Id = 1,
+ ALotOfText = "a lot of text ..."
+ });
+ tx.Commit();
+ }
+
+ }
+
+ protected override void OnTearDown()
+ {
+ using (var s = OpenSession())
+ using (var tx = s.BeginTransaction())
+ {
+ Assert.That(s.CreateSQLQuery("delete from Book").ExecuteUpdate(), Is.EqualTo(1));
+ tx.Commit();
+ }
+ }
+
+ [Test]
+ public void CanCallLazyPropertyEntityMethod()
+ {
+ using (ISession s = OpenSession())
+ {
+ var book = s.Get<Book>(1) as IBook;
+
+ Assert.IsNotNull(book);
+
+ string s1 = "testing1";
+ string s2 = book.SomeMethod(s1);
+ Assert.AreEqual(s1, s2);
+ }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2148/Domain.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2148/Domain.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2148/Domain.cs 2010-08-03 11:41:25 UTC (rev 5103)
@@ -0,0 +1,17 @@
+namespace NHibernate.Test.NHSpecificTest.NH2148
+{
+ public class Book: IBook
+ {
+ public virtual int Id { get; set; }
+ public virtual string ALotOfText { get; set; }
+ public virtual string SomeMethod(string arg)
+ {
+ return arg;
+ }
+ }
+
+ public interface IBook
+ {
+ string SomeMethod(string arg);
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2148/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2148/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2148/Mappings.hbm.xml 2010-08-03 11:41:25 UTC (rev 5103)
@@ -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.NH2148">
+
+ <class name="Book">
+ <id name="Id">
+ <generator class="assigned" />
+ </id>
+ <property name="ALotOfText" lazy="true" />
+ </class>
+
+</hibernate-mapping>
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-08-03 10:47:31 UTC (rev 5102)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-08-03 11:41:25 UTC (rev 5103)
@@ -443,6 +443,8 @@
<Compile Include="Linq\QueryCacheableTests.cs" />
<Compile Include="Linq\QueryReuseTests.cs" />
<Compile Include="Linq\ReadonlyTestCase.cs" />
+ <Compile Include="NHSpecificTest\NH2148\BugFixture.cs" />
+ <Compile Include="NHSpecificTest\NH2148\Domain.cs" />
<Compile Include="NHSpecificTest\NH2245\Fixture.cs" />
<Compile Include="NHSpecificTest\NH2245\Model.cs" />
<Compile Include="UtilityTest\ReflectionHelperIsMethodOfTests.cs" />
@@ -2226,6 +2228,7 @@
<EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" />
<EmbeddedResource Include="DriverTest\EntityForMs2008.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH2148\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2245\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2257\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2208\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-08-03 10:47:37
|
Revision: 5102
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5102&view=rev
Author: fabiomaulo
Date: 2010-08-03 10:47:31 +0000 (Tue, 03 Aug 2010)
Log Message:
-----------
Fix NH-2142 (tnx to Giovanni Bismondo)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Dialect/MySQLDialect.cs
Modified: trunk/nhibernate/src/NHibernate/Dialect/MySQLDialect.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Dialect/MySQLDialect.cs 2010-08-02 22:34:19 UTC (rev 5101)
+++ trunk/nhibernate/src/NHibernate/Dialect/MySQLDialect.cs 2010-08-03 10:47:31 UTC (rev 5102)
@@ -2,6 +2,7 @@
using System.Data;
using System.Data.Common;
using System.Text;
+using NHibernate.Dialect.Function;
using NHibernate.Dialect.Schema;
using NHibernate.SqlCommand;
using NHibernate.Util;
@@ -104,6 +105,9 @@
//special:
RegisterColumnType(DbType.Guid, "VARCHAR(40)");
+ //functions:
+ RegisterFunction("concat", new VarArgsSQLFunction(NHibernateUtil.String, "concat(", ",", ")"));
+
DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.MySqlDataDriver";
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2010-08-02 22:34:25
|
Revision: 5101
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5101&view=rev
Author: fabiomaulo
Date: 2010-08-02 22:34:19 +0000 (Mon, 02 Aug 2010)
Log Message:
-----------
Fix NH-2160 (for datetimeoffset too)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Driver/SqlClientDriver.cs
trunk/nhibernate/src/NHibernate.Test/DriverTest/MultiTypeEntity.hbm.xml
trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlClientDriverFixture.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/DriverTest/EntityForMs2008.hbm.xml
trunk/nhibernate/src/NHibernate.Test/DriverTest/Sql2008DateTime2Test.cs
Modified: trunk/nhibernate/src/NHibernate/Driver/SqlClientDriver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Driver/SqlClientDriver.cs 2010-08-02 21:44:15 UTC (rev 5100)
+++ trunk/nhibernate/src/NHibernate/Driver/SqlClientDriver.cs 2010-08-02 22:34:19 UTC (rev 5101)
@@ -95,6 +95,8 @@
private const int MaxStringClobSize = MaxBinaryBlobSize / 2;
private const byte MaxPrecision = 28;
private const byte MaxScale = 5;
+ private const byte MaxDateTime2 = 8;
+ private const byte MaxDateTimeOffset = 10;
private static void SetDefaultParameterSize(IDbDataParameter dbParam, SqlType sqlType)
{
@@ -130,6 +132,12 @@
dbParam.Size = MaxStringSize;
}
break;
+ case DbType.DateTime2:
+ dbParam.Size = MaxDateTime2;
+ break;
+ case DbType.DateTimeOffset:
+ dbParam.Size = MaxDateTimeOffset;
+ break;
}
}
Added: trunk/nhibernate/src/NHibernate.Test/DriverTest/EntityForMs2008.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/DriverTest/EntityForMs2008.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/DriverTest/EntityForMs2008.hbm.xml 2010-08-02 22:34:19 UTC (rev 5101)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Test.DriverTest"
+ assembly="NHibernate.Test">
+
+ <class name="EntityForMs2008">
+ <id name="Id">
+ <generator class="native" />
+ </id>
+ <property name="DateTimeProp" type="DateTime2"/>
+ <property name="TimeSpanProp" type="TimeSpan"/>
+ </class>
+</hibernate-mapping>
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/DriverTest/MultiTypeEntity.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/DriverTest/MultiTypeEntity.hbm.xml 2010-08-02 21:44:15 UTC (rev 5100)
+++ trunk/nhibernate/src/NHibernate.Test/DriverTest/MultiTypeEntity.hbm.xml 2010-08-02 22:34:19 UTC (rev 5101)
@@ -16,5 +16,6 @@
<property name="BinaryBlob" type="BinaryBlob"/>
<property name="Binary" type="Byte[]"/>
<property name="StringClob" type="StringClob"/>
- </class>
+ <property name="DateTimeProp" type="DateTime"/>
+ </class>
</hibernate-mapping>
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/DriverTest/Sql2008DateTime2Test.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/DriverTest/Sql2008DateTime2Test.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/DriverTest/Sql2008DateTime2Test.cs 2010-08-02 22:34:19 UTC (rev 5101)
@@ -0,0 +1,74 @@
+using System;
+using System.Collections;
+using NHibernate.Cfg;
+using NHibernate.Dialect;
+using NUnit.Framework;
+using SharpTestsEx;
+using Environment = NHibernate.Cfg.Environment;
+
+namespace NHibernate.Test.DriverTest
+{
+ public class EntityForMs2008
+ {
+ public virtual int Id { get; set; }
+ public virtual DateTime DateTimeProp { get; set; }
+ public virtual TimeSpan TimeSpanProp { get; set; }
+ }
+
+ public class Sql2008DateTime2Test : TestCase
+ {
+ protected override void Configure(Configuration configuration)
+ {
+ configuration.SetProperty(Environment.PrepareSql, "true");
+ }
+ protected override string MappingsAssembly
+ {
+ get { return "NHibernate.Test"; }
+ }
+
+ protected override IList Mappings
+ {
+ get { return new[] { "DriverTest.EntityForMs2008.hbm.xml" }; }
+ }
+
+ protected override bool AppliesTo(Dialect.Dialect dialect)
+ {
+ return dialect is MsSql2008Dialect;
+ }
+
+ [Test]
+ public void Crud()
+ {
+ var expectedMoment = new DateTime(1848, 6, 1, 12, 00, 00, 123);
+ var expectedLapse = new TimeSpan((DateTime.Now - expectedMoment).Ticks);
+ object savedId;
+ using (ISession s = OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ savedId = s.Save(new EntityForMs2008
+ {
+ DateTimeProp = expectedMoment,
+ TimeSpanProp = expectedLapse,
+ });
+ t.Commit();
+ }
+
+ using (ISession s = OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ var m = s.Get<EntityForMs2008>(savedId);
+ m.DateTimeProp.Should().Be(expectedMoment);
+ m.TimeSpanProp.Should().Be(expectedLapse);
+ t.Commit();
+ }
+
+ using (ISession s = OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ s.CreateQuery("delete from EntityForMs2008").ExecuteUpdate();
+ t.Commit();
+ }
+ }
+
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlClientDriverFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlClientDriverFixture.cs 2010-08-02 21:44:15 UTC (rev 5100)
+++ trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlClientDriverFixture.cs 2010-08-02 22:34:19 UTC (rev 5101)
@@ -1,3 +1,4 @@
+using System;
using System.Collections;
using NHibernate.Cfg;
using NHibernate.Dialect;
@@ -8,6 +9,10 @@
{
public class MultiTypeEntity
{
+ public MultiTypeEntity()
+ {
+ DateTimeProp = DateTime.Now;
+ }
public virtual int Id { get; set; }
public virtual string StringProp { get; set; }
public virtual string AnsiStringProp { get; set; }
@@ -18,6 +23,7 @@
public virtual byte[] BinaryBlob { get; set; }
public virtual byte[] Binary { get; set; }
public virtual string StringClob { get; set; }
+ public virtual DateTime DateTimeProp { get; set; }
}
[TestFixture]
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-08-02 21:44:15 UTC (rev 5100)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-08-02 22:34:19 UTC (rev 5101)
@@ -179,6 +179,7 @@
<Compile Include="Criteria\ProjectionsTest.cs" />
<Compile Include="Criteria\Reptile.cs" />
<Compile Include="DialectTest\MsSqlCe40DialectFixture.cs" />
+ <Compile Include="DriverTest\Sql2008DateTime2Test.cs" />
<Compile Include="DriverTest\SqlClientDriverFixture.cs" />
<Compile Include="DriverTest\SqlServerCeDriverFixture.cs" />
<Compile Include="EngineTest\CallableParserFixture.cs" />
@@ -2223,6 +2224,7 @@
<EmbeddedResource Include="CfgTest\Loquacious\EntityToCache.hbm.xml" />
<EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" />
<EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" />
+ <EmbeddedResource Include="DriverTest\EntityForMs2008.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
<EmbeddedResource Include="NHSpecificTest\NH2245\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2257\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-08-02 21:44:21
|
Revision: 5100
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5100&view=rev
Author: fabiomaulo
Date: 2010-08-02 21:44:15 +0000 (Mon, 02 Aug 2010)
Log Message:
-----------
Fix NH-2191
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs
Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2010-08-02 21:40:16 UTC (rev 5099)
+++ trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2010-08-02 21:44:15 UTC (rev 5100)
@@ -3154,7 +3154,7 @@
}
}
- public string FilterFragment(string alias, IDictionary<string, IFilter> enabledFilters)
+ public virtual string FilterFragment(string alias, IDictionary<string, IFilter> enabledFilters)
{
StringBuilder sessionFilterFragment = new StringBuilder();
filterHelper.Render(sessionFilterFragment, GenerateFilterConditionAlias(alias), enabledFilters);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2010-08-02 21:40:22
|
Revision: 5099
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5099&view=rev
Author: fabiomaulo
Date: 2010-08-02 21:40:16 +0000 (Mon, 02 Aug 2010)
Log Message:
-----------
Fix NH-2162
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs
trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs
Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2010-08-02 19:52:44 UTC (rev 5098)
+++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2010-08-02 21:40:16 UTC (rev 5099)
@@ -134,6 +134,7 @@
RegisterKeyword("top");
RegisterKeyword("integer");
RegisterKeyword("int");
+ RegisterKeyword("datetime");
DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.SqlClientDriver";
}
Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs 2010-08-02 19:52:44 UTC (rev 5098)
+++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs 2010-08-02 21:40:16 UTC (rev 5099)
@@ -3,17 +3,19 @@
namespace NHibernate.Dialect
{
- public class MsSql2008Dialect : MsSql2005Dialect
- {
- public MsSql2008Dialect()
- {
- RegisterColumnType(DbType.DateTime2, "DATETIME2");
- RegisterColumnType(DbType.DateTimeOffset, "DATETIMEOFFSET");
+ public class MsSql2008Dialect : MsSql2005Dialect
+ {
+ public MsSql2008Dialect()
+ {
+ RegisterColumnType(DbType.DateTime2, "DATETIME2");
+ RegisterColumnType(DbType.DateTimeOffset, "DATETIMEOFFSET");
RegisterColumnType(DbType.Date, "DATE");
RegisterColumnType(DbType.Time, "TIME");
RegisterFunction("current_timestamp", new NoArgSQLFunction("sysdatetime", NHibernateUtil.DateTime2, true));
RegisterFunction("current_timestamp_offset", new NoArgSQLFunction("sysdatetimeoffset", NHibernateUtil.DateTimeOffset, true));
- }
- }
+ RegisterKeyword("datetime2");
+ RegisterKeyword("datetimeoffset");
+ }
+ }
}
\ 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-08-02 19:52:51
|
Revision: 5098
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5098&view=rev
Author: fabiomaulo
Date: 2010-08-02 19:52:44 +0000 (Mon, 02 Aug 2010)
Log Message:
-----------
Actualized LinFu.DynamicProxy to 1.0.4
Modified Paths:
--------------
trunk/nhibernate/lib/net/3.5/LinFu.DynamicProxy.dll
trunk/nhibernate/lib/net/3.5/LinFu.License.txt
Modified: trunk/nhibernate/lib/net/3.5/LinFu.DynamicProxy.dll
===================================================================
(Binary files differ)
Modified: trunk/nhibernate/lib/net/3.5/LinFu.License.txt
===================================================================
--- trunk/nhibernate/lib/net/3.5/LinFu.License.txt 2010-08-02 19:14:47 UTC (rev 5097)
+++ trunk/nhibernate/lib/net/3.5/LinFu.License.txt 2010-08-02 19:52:44 UTC (rev 5098)
@@ -1,4 +1,4 @@
-The LinFu Library, (c) 2007 Philip Laureano, is subject to the terms of the following license:
+The LinFu Library, (c) 2007-2009 Philip Laureano, is subject to the terms of the following license:
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2010-08-02 19:14:57
|
Revision: 5097
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5097&view=rev
Author: fabiomaulo
Date: 2010-08-02 19:14:47 +0000 (Mon, 02 Aug 2010)
Log Message:
-----------
Removed unneeded breaking change (thanks to my personal advisor Fiamma)
Modified Paths:
--------------
trunk/nhibernate/releasenotes.txt
trunk/nhibernate/src/NHibernate/Driver/OracleClientDriver.cs
trunk/nhibernate/src/NHibernate.Test/App.config
Modified: trunk/nhibernate/releasenotes.txt
===================================================================
--- trunk/nhibernate/releasenotes.txt 2010-08-02 18:37:53 UTC (rev 5096)
+++ trunk/nhibernate/releasenotes.txt 2010-08-02 19:14:47 UTC (rev 5097)
@@ -3,8 +3,6 @@
** Known BREAKING CHANGES from NH2.1.1.GA to NH3.0.0.Alpha1
##### Run time #####
* (NH-2199) - null values in maps/dictionaries are no longer silenty ignored/deleted
- * (NH-2263) - removed the reference to System.Data.OracleClient, now you have to configure the assemblyBinding to resolve the partial name
- (example available in App.conf of out NHibernate.Test project)
Build 3.0.0.Alpha1 (rev5056)
=============================
Modified: trunk/nhibernate/src/NHibernate/Driver/OracleClientDriver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Driver/OracleClientDriver.cs 2010-08-02 18:37:53 UTC (rev 5096)
+++ trunk/nhibernate/src/NHibernate/Driver/OracleClientDriver.cs 2010-08-02 19:14:47 UTC (rev 5097)
@@ -12,7 +12,9 @@
private static readonly SqlType GuidSqlType = new SqlType(DbType.Binary, 16);
public OracleClientDriver() :
- base("System.Data.OracleClient", "System.Data.OracleClient.OracleConnection", "System.Data.OracleClient.OracleCommand") { }
+ base("System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
+ "System.Data.OracleClient.OracleConnection",
+ "System.Data.OracleClient.OracleCommand") { }
public override bool UseNamedPrefixInSql
{
Modified: trunk/nhibernate/src/NHibernate.Test/App.config
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/App.config 2010-08-02 18:37:53 UTC (rev 5096)
+++ trunk/nhibernate/src/NHibernate.Test/App.config 2010-08-02 19:14:47 UTC (rev 5097)
@@ -29,10 +29,6 @@
<qualifyAssembly partialName="FirebirdSql.Data.FirebirdClient" fullName="FirebirdSql.Data.FirebirdClient, Version=2.1.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c" />
</assemblyBinding>
<!-- -->
-
- <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
- <qualifyAssembly partialName="System.Data.OracleClient" fullName="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
- </assemblyBinding>
</runtime>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2010-08-02 18:37:59
|
Revision: 5096
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5096&view=rev
Author: fabiomaulo
Date: 2010-08-02 18:37:53 +0000 (Mon, 02 Aug 2010)
Log Message:
-----------
Fixed test problem and actualized releasenotes to documents the breaking-change
Modified Paths:
--------------
trunk/nhibernate/releasenotes.txt
trunk/nhibernate/src/NHibernate.Test/App.config
Modified: trunk/nhibernate/releasenotes.txt
===================================================================
--- trunk/nhibernate/releasenotes.txt 2010-08-02 17:56:21 UTC (rev 5095)
+++ trunk/nhibernate/releasenotes.txt 2010-08-02 18:37:53 UTC (rev 5096)
@@ -3,6 +3,8 @@
** Known BREAKING CHANGES from NH2.1.1.GA to NH3.0.0.Alpha1
##### Run time #####
* (NH-2199) - null values in maps/dictionaries are no longer silenty ignored/deleted
+ * (NH-2263) - removed the reference to System.Data.OracleClient, now you have to configure the assemblyBinding to resolve the partial name
+ (example available in App.conf of out NHibernate.Test project)
Build 3.0.0.Alpha1 (rev5056)
=============================
Modified: trunk/nhibernate/src/NHibernate.Test/App.config
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/App.config 2010-08-02 17:56:21 UTC (rev 5095)
+++ trunk/nhibernate/src/NHibernate.Test/App.config 2010-08-02 18:37:53 UTC (rev 5096)
@@ -29,8 +29,12 @@
<qualifyAssembly partialName="FirebirdSql.Data.FirebirdClient" fullName="FirebirdSql.Data.FirebirdClient, Version=2.1.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c" />
</assemblyBinding>
<!-- -->
+
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <qualifyAssembly partialName="System.Data.OracleClient" fullName="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ </assemblyBinding>
- </runtime>
+ </runtime>
<!--
hibernate-configuration section
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2010-08-02 17:56:27
|
Revision: 5095
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5095&view=rev
Author: fabiomaulo
Date: 2010-08-02 17:56:21 +0000 (Mon, 02 Aug 2010)
Log Message:
-----------
Partial fix of NH-2263 (thanks to Patrick Earl for the issue)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Driver/OracleClientDriver.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
Modified: trunk/nhibernate/src/NHibernate/Driver/OracleClientDriver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Driver/OracleClientDriver.cs 2010-08-02 17:30:36 UTC (rev 5094)
+++ trunk/nhibernate/src/NHibernate/Driver/OracleClientDriver.cs 2010-08-02 17:56:21 UTC (rev 5095)
@@ -1,5 +1,4 @@
using System.Data;
-using System.Data.OracleClient;
using NHibernate.Engine.Query;
using NHibernate.SqlTypes;
@@ -8,20 +7,13 @@
/// <summary>
/// A NHibernate Driver for using the Oracle DataProvider.
/// </summary>
- public class OracleClientDriver : DriverBase
+ public class OracleClientDriver : ReflectionBasedDriver
{
private static readonly SqlType GuidSqlType = new SqlType(DbType.Binary, 16);
- public override IDbConnection CreateConnection()
- {
- return new OracleConnection();
- }
+ public OracleClientDriver() :
+ base("System.Data.OracleClient", "System.Data.OracleClient.OracleConnection", "System.Data.OracleClient.OracleCommand") { }
- public override IDbCommand CreateCommand()
- {
- return new OracleCommand();
- }
-
public override bool UseNamedPrefixInSql
{
get { return true; }
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-08-02 17:30:36 UTC (rev 5094)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-08-02 17:56:21 UTC (rev 5095)
@@ -49,7 +49,6 @@
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
- <Reference Include="System.Data.OracleClient" />
<Reference Include="System.ServiceModel">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2010-08-02 17:30:42
|
Revision: 5094
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5094&view=rev
Author: fabiomaulo
Date: 2010-08-02 17:30:36 +0000 (Mon, 02 Aug 2010)
Log Message:
-----------
Fix NH-2226
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CfgXmlHelper.cs
trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/HibernateConfiguration.cs
trunk/nhibernate/src/NHibernate/Cfg/Environment.cs
trunk/nhibernate/src/NHibernate/Cfg/IHibernateConfiguration.cs
trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationSchemaFixture.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/CfgTest/CustomBytecodeProviderTest.cs
Modified: trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CfgXmlHelper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CfgXmlHelper.cs 2010-08-02 12:00:24 UTC (rev 5093)
+++ trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CfgXmlHelper.cs 2010-08-02 17:30:36 UTC (rev 5094)
@@ -64,34 +64,10 @@
/// <summary>XPath expression for session-factory.listener nodes</summary>
public static readonly XPathExpression SessionFactoryListenersExpression;
- /// <summary>
- /// Convert a string to <see cref="BytecodeProviderType"/>.
- /// </summary>
- /// <param name="byteCodeProvider">The string that represent <see cref="BytecodeProviderType"/>.</param>
- /// <returns>
- /// The <paramref name="byteCodeProvider"/> converted to <see cref="BytecodeProviderType"/>.
- /// <see cref="BytecodeProviderType.Null"/> for invalid values.
- /// </returns>
- /// <remarks>
- /// See <see cref="BytecodeProviderType"/> for allowed values.
- /// </remarks>
- public static BytecodeProviderType ByteCodeProviderConvertFrom(string byteCodeProvider)
+ internal static string ToConfigurationString(this BytecodeProviderType source)
{
- switch (byteCodeProvider)
+ switch (source)
{
- case "codedom":
- return BytecodeProviderType.Codedom;
- case "lcg":
- return BytecodeProviderType.Lcg;
- default:
- return BytecodeProviderType.Null;
- }
- }
-
- internal static string ByteCodeProviderToString(BytecodeProviderType byteCodeProvider)
- {
- switch (byteCodeProvider)
- {
case BytecodeProviderType.Codedom:
return "codedom";
case BytecodeProviderType.Lcg:
Modified: trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/HibernateConfiguration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/HibernateConfiguration.cs 2010-08-02 12:00:24 UTC (rev 5093)
+++ trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/HibernateConfiguration.cs 2010-08-02 17:30:36 UTC (rev 5094)
@@ -96,7 +96,7 @@
if (fromAppConfig)
{
xpn.MoveToFirstAttribute();
- byteCodeProviderType = CfgXmlHelper.ByteCodeProviderConvertFrom(xpn.Value);
+ byteCodeProviderType = xpn.Value;
}
else
{
@@ -128,12 +128,12 @@
}
}
- private BytecodeProviderType byteCodeProviderType = BytecodeProviderType.Lcg;
+ private string byteCodeProviderType = BytecodeProviderType.Lcg.ToConfigurationString();
/// <summary>
/// Value for bytecode-provider system property.
/// </summary>
/// <remarks>Default value <see cref="BytecodeProviderType.Lcg"/>.</remarks>
- public BytecodeProviderType ByteCodeProviderType
+ public string ByteCodeProviderType
{
get { return byteCodeProviderType; }
}
Modified: trunk/nhibernate/src/NHibernate/Cfg/Environment.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Environment.cs 2010-08-02 12:00:24 UTC (rev 5093)
+++ trunk/nhibernate/src/NHibernate/Cfg/Environment.cs 2010-08-02 17:30:36 UTC (rev 5094)
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using System.Configuration;
using System.Reflection;
@@ -3,5 +4,4 @@
using log4net;
using NHibernate.Bytecode;
-using NHibernate.Bytecode.CodeDom;
using NHibernate.Cfg.ConfigurationSchema;
using NHibernate.Util;
@@ -218,7 +218,7 @@
return;
}
- GlobalProperties[PropertyBytecodeProvider] = CfgXmlHelper.ByteCodeProviderToString(nhConfig.ByteCodeProviderType);
+ GlobalProperties[PropertyBytecodeProvider] = nhConfig.ByteCodeProviderType;
GlobalProperties[PropertyUseReflectionOptimizer] = nhConfig.UseReflectionOptimizer.ToString();
if (nhConfig.SessionFactory != null)
{
@@ -317,15 +317,43 @@
switch (providerName)
{
case "codedom":
- return new BytecodeProviderImpl();
+ return new Bytecode.CodeDom.BytecodeProviderImpl();
case "lcg":
return new Bytecode.Lightweight.BytecodeProviderImpl();
case "null":
return new NullBytecodeProvider();
default:
- log.Warn("unrecognized bytecode provider [" + providerName + "], using null by default");
- return new NullBytecodeProvider();
+ log.Info("custom bytecode provider [" + providerName + "]");
+ return CreateCustomBytecodeProvider(providerName);
}
}
+
+ private static IBytecodeProvider CreateCustomBytecodeProvider(string assemblyQualifiedName)
+ {
+ try
+ {
+ var type = ReflectHelper.ClassForName(assemblyQualifiedName);
+ try
+ {
+ return (IBytecodeProvider)Activator.CreateInstance(type);
+ }
+ catch (MissingMethodException ex)
+ {
+ throw new HibernateByteCodeException("Public constructor was not found for " + type, ex);
+ }
+ catch (InvalidCastException ex)
+ {
+ throw new HibernateByteCodeException(type + "Type does not implement " + typeof(IBytecodeProvider), ex);
+ }
+ catch (Exception ex)
+ {
+ throw new HibernateByteCodeException("Unable to instantiate: " + type, ex);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new HibernateByteCodeException("Unable to create the instance of Bytecode provider; check inner exception for detail", e);
+ }
+ }
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Cfg/IHibernateConfiguration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/IHibernateConfiguration.cs 2010-08-02 12:00:24 UTC (rev 5093)
+++ trunk/nhibernate/src/NHibernate/Cfg/IHibernateConfiguration.cs 2010-08-02 17:30:36 UTC (rev 5094)
@@ -1,10 +1,8 @@
-using NHibernate.Cfg.ConfigurationSchema;
-
-namespace NHibernate.Cfg
+namespace NHibernate.Cfg
{
public interface IHibernateConfiguration
{
- BytecodeProviderType ByteCodeProviderType { get; }
+ string ByteCodeProviderType { get; }
bool UseReflectionOptimizer { get; }
ISessionFactoryConfiguration SessionFactory { get; }
}
Modified: trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationSchemaFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationSchemaFixture.cs 2010-08-02 12:00:24 UTC (rev 5093)
+++ trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationSchemaFixture.cs 2010-08-02 17:30:36 UTC (rev 5094)
@@ -5,6 +5,7 @@
using NHibernate.Cfg;
using NHibernate.Cfg.ConfigurationSchema;
using System.Xml;
+using SharpTestsEx;
namespace NHibernate.Test.CfgTest
{
@@ -28,7 +29,7 @@
public void FromAppConfigTest()
{
IHibernateConfiguration hc = ConfigurationManager.GetSection("hibernate-configuration") as IHibernateConfiguration;
- Assert.AreEqual(BytecodeProviderType.Lcg, hc.ByteCodeProviderType);
+ hc.ByteCodeProviderType.Should().Be("lcg");
Assert.IsTrue(hc.UseReflectionOptimizer);
Assert.AreEqual("NHibernate.Test", hc.SessionFactory.Name);
}
Added: trunk/nhibernate/src/NHibernate.Test/CfgTest/CustomBytecodeProviderTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CfgTest/CustomBytecodeProviderTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CfgTest/CustomBytecodeProviderTest.cs 2010-08-02 17:30:36 UTC (rev 5094)
@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using NHibernate.Bytecode;
+using NHibernate.Properties;
+using NUnit.Framework;
+using SharpTestsEx;
+using Environment = NHibernate.Cfg.Environment;
+
+namespace NHibernate.Test.CfgTest
+{
+ public class CustomBytecodeProviderTest
+ {
+ private class MyByteCodeProvider : AbstractBytecodeProvider
+ {
+ public override IReflectionOptimizer GetReflectionOptimizer(System.Type clazz, IGetter[] getters, ISetter[] setters)
+ {
+ throw new NotImplementedException();
+ }
+ }
+ private class InvalidByteCodeProvider
+ {
+ }
+ private class InvalidNoCtorByteCodeProvider : AbstractBytecodeProvider
+ {
+ public InvalidNoCtorByteCodeProvider(string pizza) {}
+
+ public override IReflectionOptimizer GetReflectionOptimizer(System.Type clazz, IGetter[] getters, ISetter[] setters)
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+ [Test]
+ public void WhenNoShortCutUsedThenCanBuildBytecodeProvider()
+ {
+ var properties = new Dictionary<string, string> { { Environment.PropertyBytecodeProvider, typeof(MyByteCodeProvider).AssemblyQualifiedName } };
+ Executing.This(() => Environment.BuildBytecodeProvider(properties)).Should().NotThrow();
+ }
+
+ [Test]
+ public void WhenNoShortCutUsedThenCanBuildInstanceOfConfiguredBytecodeProvider()
+ {
+ var properties = new Dictionary<string, string> { { Environment.PropertyBytecodeProvider, typeof(MyByteCodeProvider).AssemblyQualifiedName } };
+ Environment.BuildBytecodeProvider(properties).Should().Be.InstanceOf<MyByteCodeProvider>();
+ }
+
+ [Test]
+ public void WhenInvalidThenThrow()
+ {
+ var properties = new Dictionary<string, string> { { Environment.PropertyBytecodeProvider, typeof(InvalidByteCodeProvider).AssemblyQualifiedName } };
+ Executing.This(() => Environment.BuildBytecodeProvider(properties)).Should().Throw<HibernateByteCodeException>();
+ }
+
+ [Test]
+ public void WhenNoDefaultCtorThenThrow()
+ {
+ var properties = new Dictionary<string, string> { { Environment.PropertyBytecodeProvider, typeof(InvalidNoCtorByteCodeProvider).AssemblyQualifiedName } };
+ Executing.This(() => Environment.BuildBytecodeProvider(properties)).Should().Throw<HibernateByteCodeException>()
+ .And.Exception.InnerException.Message.Should().Contain("constructor was not found");
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-08-02 12:00:24 UTC (rev 5093)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-08-02 17:30:36 UTC (rev 5094)
@@ -112,6 +112,7 @@
<Compile Include="CfgTest\ConfigurationFixture.cs" />
<Compile Include="CfgTest\ConfigurationSchemaFixture.cs" />
<Compile Include="CfgTest\ConfigurationSerializationTests.cs" />
+ <Compile Include="CfgTest\CustomBytecodeProviderTest.cs" />
<Compile Include="CfgTest\DefaultNsAssmFixture.cs" />
<Compile Include="CfgTest\EntityCacheUsageParserFixture.cs" />
<Compile Include="CfgTest\HbmOrderingFixture.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2010-08-02 12:00:30
|
Revision: 5093
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5093&view=rev
Author: fabiomaulo
Date: 2010-08-02 12:00:24 +0000 (Mon, 02 Aug 2010)
Log Message:
-----------
Preparing fix of NH-2226 (comment for XSD)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/nhibernate-configuration.xsd
Modified: trunk/nhibernate/src/NHibernate/nhibernate-configuration.xsd
===================================================================
--- trunk/nhibernate/src/NHibernate/nhibernate-configuration.xsd 2010-08-02 11:44:24 UTC (rev 5092)
+++ trunk/nhibernate/src/NHibernate/nhibernate-configuration.xsd 2010-08-02 12:00:24 UTC (rev 5093)
@@ -10,7 +10,18 @@
<xs:element name="hibernate-configuration">
<xs:complexType>
<xs:sequence>
- <xs:element ref="bytecode-provider" minOccurs="0" maxOccurs="1" />
+ <xs:element ref="bytecode-provider" minOccurs="0" maxOccurs="1" >
+ <xs:annotation>
+ <xs:documentation>
+ There are 3 default short-cut values
+ - lcg : default for .NET2.0 and higher.
+ - codedom : CodeDOM-based bytecode provider (mostly for .NET1.1).
+ - null : Disable the reflection optimization completely.
+ In addition you can specify the AssemblyQualifiedName of your custom bytecode-provider (implementation of IBytecodeProvider).
+ Note: the bytecode-provider will be tooks in account only when specified in the app.config or web.config.
+ </xs:documentation>
+ </xs:annotation>
+ </xs:element>
<xs:element ref="reflection-optimizer" maxOccurs="1" minOccurs="0" />
<xs:element ref="session-factory" minOccurs="0" maxOccurs="1" />
</xs:sequence>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2010-08-02 11:44:33
|
Revision: 5092
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5092&view=rev
Author: fabiomaulo
Date: 2010-08-02 11:44:24 +0000 (Mon, 02 Aug 2010)
Log Message:
-----------
Apply NH-2252 (thanks to Diego Mijelshon)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Dialect/MsSqlCe40Dialect.cs
trunk/nhibernate/src/NHibernate.Test/DialectTest/MsSqlCe40DialectFixture.cs
Added: trunk/nhibernate/src/NHibernate/Dialect/MsSqlCe40Dialect.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Dialect/MsSqlCe40Dialect.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Dialect/MsSqlCe40Dialect.cs 2010-08-02 11:44:24 UTC (rev 5092)
@@ -0,0 +1,30 @@
+using NHibernate.SqlCommand;
+
+namespace NHibernate.Dialect
+{
+ public class MsSqlCe40Dialect : MsSqlCeDialect
+ {
+ public override SqlString GetLimitString(SqlString querySqlString, int offset, int limit)
+ {
+ if (querySqlString.IndexOfCaseInsensitive(" ORDER BY ") < 0)
+ querySqlString = querySqlString.Append(" ORDER BY GETDATE()");
+ return querySqlString.Append(string.Format(" OFFSET {0} ROWS FETCH NEXT {1} ROWS ONLY", offset, limit));
+ }
+
+ public override bool SupportsLimit
+ {
+ get
+ {
+ return true;
+ }
+ }
+
+ public override bool SupportsLimitOffset
+ {
+ get
+ {
+ return true;
+ }
+ }
+ }
+}
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-08-02 11:35:07 UTC (rev 5091)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-08-02 11:44:24 UTC (rev 5092)
@@ -585,6 +585,7 @@
<Compile Include="Dialect\MsSql2008Dialect.cs" />
<Compile Include="Dialect\InformixDialect0940.cs" />
<Compile Include="Dialect\InformixDialect1000.cs" />
+ <Compile Include="Dialect\MsSqlCe40Dialect.cs" />
<Compile Include="Dialect\Oracle10gDialect.cs" />
<Compile Include="Dialect\Oracle8iDialect.cs" />
<Compile Include="Dialect\Oracle9iDialect.cs" />
Added: trunk/nhibernate/src/NHibernate.Test/DialectTest/MsSqlCe40DialectFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/DialectTest/MsSqlCe40DialectFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/DialectTest/MsSqlCe40DialectFixture.cs 2010-08-02 11:44:24 UTC (rev 5092)
@@ -0,0 +1,25 @@
+using NHibernate.Dialect;
+using NHibernate.SqlCommand;
+using NUnit.Framework;
+
+namespace NHibernate.Test.DialectTest
+{
+ public class MsSqlCe40DialectFixture
+ {
+ [Test]
+ public void GetLimitString()
+ {
+ var dialect = new MsSqlCe40Dialect();
+ var str = dialect.GetLimitString(new SqlString("SELECT id FROM user ORDER BY name"), 13, 17);
+ Assert.AreEqual("SELECT id FROM user ORDER BY name OFFSET 13 ROWS FETCH NEXT 17 ROWS ONLY", str.ToString());
+ }
+
+ [Test]
+ public void GetLimitStringWithDummyOrder()
+ {
+ var dialect = new MsSqlCe40Dialect();
+ var str = dialect.GetLimitString(new SqlString("SELECT id FROM user"), 13, 17);
+ Assert.AreEqual("SELECT id FROM user ORDER BY GETDATE() OFFSET 13 ROWS FETCH NEXT 17 ROWS ONLY", str.ToString());
+ }
+ }
+}
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-08-02 11:35:07 UTC (rev 5091)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-08-02 11:44:24 UTC (rev 5092)
@@ -177,6 +177,7 @@
<Compile Include="Criteria\MaterialResource.cs" />
<Compile Include="Criteria\ProjectionsTest.cs" />
<Compile Include="Criteria\Reptile.cs" />
+ <Compile Include="DialectTest\MsSqlCe40DialectFixture.cs" />
<Compile Include="DriverTest\SqlClientDriverFixture.cs" />
<Compile Include="DriverTest\SqlServerCeDriverFixture.cs" />
<Compile Include="EngineTest\CallableParserFixture.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2010-08-02 11:35:15
|
Revision: 5091
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5091&view=rev
Author: fabiomaulo
Date: 2010-08-02 11:35:07 +0000 (Mon, 02 Aug 2010)
Log Message:
-----------
Apply NH-2190 (thanks to Mihai Codrean)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Criterion/DetachedCriteria.cs
trunk/nhibernate/src/NHibernate/Dialect/Sybase11Dialect.cs
trunk/nhibernate/src/NHibernate/Engine/JoinSequence.cs
trunk/nhibernate/src/NHibernate/ICriteria.cs
trunk/nhibernate/src/NHibernate/Impl/CriteriaImpl.cs
trunk/nhibernate/src/NHibernate/Loader/AbstractEntityJoinWalker.cs
trunk/nhibernate/src/NHibernate/Loader/Collection/BasicCollectionJoinWalker.cs
trunk/nhibernate/src/NHibernate/Loader/Collection/OneToManyJoinWalker.cs
trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaJoinWalker.cs
trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs
trunk/nhibernate/src/NHibernate/Loader/JoinWalker.cs
trunk/nhibernate/src/NHibernate/Loader/OuterJoinableAssociation.cs
trunk/nhibernate/src/NHibernate/SqlCommand/ANSIJoinFragment.cs
trunk/nhibernate/src/NHibernate/SqlCommand/InformixJoinFragment.cs
trunk/nhibernate/src/NHibernate/SqlCommand/JoinFragment.cs
trunk/nhibernate/src/NHibernate/SqlCommand/OracleJoinFragment.cs
trunk/nhibernate/src/NHibernate/SqlCommand/QueryJoinFragment.cs
trunk/nhibernate/src/NHibernate/Util/StringHelper.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/CriteriaQueryTest.cs
Modified: trunk/nhibernate/src/NHibernate/Criterion/DetachedCriteria.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/DetachedCriteria.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate/Criterion/DetachedCriteria.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -129,6 +129,12 @@
return this;
}
+ public DetachedCriteria CreateAlias(string associationPath, string alias, JoinType joinType, ICriterion withClause)
+ {
+ criteria.CreateAlias(associationPath, alias, joinType, withClause);
+ return this;
+ }
+
public DetachedCriteria CreateCriteria(string associationPath, string alias)
{
return new DetachedCriteria(impl, criteria.CreateCriteria(associationPath, alias));
Modified: trunk/nhibernate/src/NHibernate/Dialect/Sybase11Dialect.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Dialect/Sybase11Dialect.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate/Dialect/Sybase11Dialect.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -69,7 +69,7 @@
}
public override void AddJoin(string tableName, string alias, string[] fkColumns, string[] pkColumns, JoinType joinType,
- string on)
+ SqlString on)
{
AddJoin(tableName, alias, fkColumns, pkColumns, joinType);
AddCondition(on);
Modified: trunk/nhibernate/src/NHibernate/Engine/JoinSequence.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Engine/JoinSequence.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate/Engine/JoinSequence.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -203,7 +203,7 @@
join.LHSColumns,
JoinHelper.GetRHSColumnNames(join.AssociationType, factory),
join.JoinType,
- condition
+ new SqlString(condition)
);
if (includeExtraJoins)
{
Modified: trunk/nhibernate/src/NHibernate/ICriteria.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/ICriteria.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate/ICriteria.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -130,6 +130,17 @@
ICriteria CreateAlias(string associationPath, string alias, JoinType joinType);
/// <summary>
+ /// Join an association using the specified join-type, assigning an alias to the joined
+ /// association
+ /// </summary>
+ /// <param name="associationPath"></param>
+ /// <param name="alias"></param>
+ /// <param name="joinType">The type of join to use.</param>
+ /// <param name="withClause"The criteria to be added to the join condition (ON clause)</param>
+ /// <returns>this (for method chaining)</returns>
+ ICriteria CreateAlias(string associationPath, string alias, JoinType joinType, ICriterion withClause);
+
+ /// <summary>
/// Create a new <see cref="ICriteria" />, "rooted" at the associated entity
/// </summary>
/// <param name="associationPath"></param>
@@ -165,6 +176,17 @@
ICriteria CreateCriteria(string associationPath, string alias, JoinType joinType);
/// <summary>
+ /// Create a new <see cref="ICriteria" />, "rooted" at the associated entity,
+ /// assigning the given alias and using the specified join type.
+ /// </summary>
+ /// <param name="associationPath">A dot-separated property path</param>
+ /// <param name="alias">The alias to assign to the joined association (for later reference).</param>
+ /// <param name="joinType">The type of join to use.</param>
+ /// <param name="withClause"The criteria to be added to the join condition (ON clause)</param>
+ /// <returns>The created "sub criteria"</returns>
+ ICriteria CreateCriteria(string associationPath, string alias, JoinType joinType, ICriterion withClause);
+
+ /// <summary>
/// Set a strategy for handling the query results. This determines the
/// "shape" of the query result set.
/// <seealso cref="CriteriaSpecification.RootEntity"/>
Modified: trunk/nhibernate/src/NHibernate/Impl/CriteriaImpl.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/CriteriaImpl.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate/Impl/CriteriaImpl.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -345,6 +345,12 @@
return this;
}
+ public ICriteria CreateAlias(string associationPath, string alias, JoinType joinType, ICriterion withClause)
+ {
+ new Subcriteria(this, this, associationPath, alias, joinType, withClause);
+ return this;
+ }
+
public ICriteria Add(ICriteria criteriaInst, ICriterion expression)
{
criteria.Add(new CriterionEntry(expression, criteriaInst));
@@ -371,6 +377,11 @@
return new Subcriteria(this, this, associationPath, alias, joinType);
}
+ public ICriteria CreateCriteria(string associationPath, string alias, JoinType joinType, ICriterion withClause)
+ {
+ return new Subcriteria(this, this, associationPath, alias, joinType, withClause);
+ }
+
public IFutureValue<T> FutureValue<T>()
{
if (!session.Factory.ConnectionProvider.Driver.SupportsMultipleQueries)
@@ -607,14 +618,16 @@
private readonly string path;
private LockMode lockMode;
private readonly JoinType joinType;
+ private ICriterion withClause;
- internal Subcriteria(CriteriaImpl root, ICriteria parent, string path, string alias, JoinType joinType)
+ internal Subcriteria(CriteriaImpl root, ICriteria parent, string path, string alias, JoinType joinType, ICriterion withClause)
{
this.root = root;
this.parent = parent;
this.alias = alias;
this.path = path;
this.joinType = joinType;
+ this.withClause = withClause;
root.subcriteriaList.Add(this);
@@ -625,9 +638,17 @@
}
}
+ internal Subcriteria(CriteriaImpl root, ICriteria parent, string path, string alias, JoinType joinType)
+ : this(root, parent, path, alias, joinType, null) {}
+
internal Subcriteria(CriteriaImpl root, ICriteria parent, string path, JoinType joinType)
- : this(root, parent, path, null, joinType) {}
+ : this(root, parent, path, null, joinType) { }
+ public ICriterion WithClause
+ {
+ get { return withClause; }
+ }
+
public string Path
{
get { return path; }
@@ -688,6 +709,12 @@
return this;
}
+ public ICriteria CreateAlias(string associationPath, string alias, JoinType joinType, ICriterion withClause)
+ {
+ new Subcriteria(root, this, associationPath, alias, joinType, withClause);
+ return this;
+ }
+
public ICriteria CreateCriteria(string associationPath)
{
return CreateCriteria(associationPath, JoinType.InnerJoin);
@@ -708,6 +735,11 @@
return new Subcriteria(root, this, associationPath, alias, joinType);
}
+ public ICriteria CreateCriteria(string associationPath, string alias, JoinType joinType, ICriterion withClause)
+ {
+ return new Subcriteria(root, this, associationPath, alias, joinType, withClause);
+ }
+
public ICriteria SetCacheable(bool cacheable)
{
root.SetCacheable(cacheable);
Modified: trunk/nhibernate/src/NHibernate/Loader/AbstractEntityJoinWalker.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Loader/AbstractEntityJoinWalker.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate/Loader/AbstractEntityJoinWalker.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -4,6 +4,7 @@
using NHibernate.SqlCommand;
using NHibernate.Type;
using NHibernate.Util;
+using NHibernate.Loader.Criteria;
namespace NHibernate.Loader
{
@@ -33,19 +34,27 @@
WalkEntityTree(persister, Alias);
IList<OuterJoinableAssociation> allAssociations = new List<OuterJoinableAssociation>(associations);
allAssociations.Add(
- new OuterJoinableAssociation(persister.EntityType, null, null, alias, JoinType.LeftOuterJoin, Factory,
+ new OuterJoinableAssociation(persister.EntityType, null, null, alias, JoinType.LeftOuterJoin, null, Factory,
new CollectionHelper.EmptyMapClass<string, IFilter>()));
InitPersisters(allAssociations, lockMode);
InitStatementString(whereString, orderByString, lockMode);
}
- protected void InitProjection(SqlString projectionString, SqlString whereString,
- SqlString orderByString, string groupByString, SqlString havingString, LockMode lockMode)
+ protected void InitProjection(CriteriaQueryTranslator translator,
+ IDictionary<string, IFilter> enabledFilters, LockMode lockMode)
{
+ // the order of the calls here is important, as the join clauses can contain parameter bindings
+ SqlString projectionString = translator.GetSelect(enabledFilters);
WalkEntityTree(persister, Alias);
+ SqlString whereString = translator.GetWhereCondition(enabledFilters);
+ SqlString orderByString = translator.GetOrderBy();
+ SqlString groupByString = translator.GetGroupBy();
+ SqlString havingString = translator.GetHavingCondition(enabledFilters);
+
Persisters = new ILoadable[0];
- InitStatementString(projectionString, whereString, orderByString, groupByString, havingString, lockMode);
+ InitStatementString(projectionString, whereString, orderByString, groupByString.ToString(),
+ havingString, lockMode);
}
private void InitStatementString(SqlString condition, SqlString orderBy, LockMode lockMode)
Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/BasicCollectionJoinWalker.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Loader/Collection/BasicCollectionJoinWalker.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate/Loader/Collection/BasicCollectionJoinWalker.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -29,7 +29,7 @@
// NH Different behavior : passing enabledFilters instead empty-filter
allAssociations.Add(
- new OuterJoinableAssociation(collectionPersister.CollectionType, null, null, alias, JoinType.LeftOuterJoin, Factory,
+ new OuterJoinableAssociation(collectionPersister.CollectionType, null, null, alias, JoinType.LeftOuterJoin, null, Factory,
enabledFilters));
InitPersisters(allAssociations, LockMode.None);
Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/OneToManyJoinWalker.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Loader/Collection/OneToManyJoinWalker.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate/Loader/Collection/OneToManyJoinWalker.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -35,7 +35,7 @@
IList<OuterJoinableAssociation> allAssociations = new List<OuterJoinableAssociation>(associations);
allAssociations.Add(
- new OuterJoinableAssociation(oneToManyPersister.CollectionType, null, null, alias, JoinType.LeftOuterJoin, Factory,
+ new OuterJoinableAssociation(oneToManyPersister.CollectionType, null, null, alias, JoinType.LeftOuterJoin, null, Factory,
new CollectionHelper.EmptyMapClass<string, IFilter>()));
InitPersisters(allAssociations, LockMode.None);
Modified: trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaJoinWalker.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaJoinWalker.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaJoinWalker.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -42,9 +42,7 @@
{
resultTypes = translator.ProjectedTypes;
- InitProjection(translator.GetSelect(enabledFilters), translator.GetWhereCondition(enabledFilters),
- translator.GetOrderBy(), translator.GetGroupBy().ToString(),
- translator.GetHavingCondition(enabledFilters), LockMode.None);
+ InitProjection(translator, enabledFilters, LockMode.None);
}
else
{
@@ -175,5 +173,10 @@
return CriteriaQueryTranslator.RootSqlAlias;
// NH: really not used (we are using a different ctor to support SubQueryCriteria)
}
+
+ protected override SqlString GetWithClause(string path)
+ {
+ return translator.GetWithClause(path, EnabledFilters);
+ }
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -39,6 +39,7 @@
private readonly IDictionary<string, ICriteria> aliasCriteriaMap = new Dictionary<string, ICriteria>();
private readonly IDictionary<string, ICriteria> associationPathCriteriaMap = new LinkedHashMap<string, ICriteria>();
private readonly IDictionary<string, JoinType> associationPathJoinTypesMap = new LinkedHashMap<string, JoinType>();
+ private readonly IDictionary<string, ICriterion> withClauseMap = new Dictionary<string, ICriterion>();
private readonly ISessionFactoryImplementor sessionFactory;
private int indexForAlias = 0;
@@ -300,6 +301,18 @@
{
throw new QueryException("duplicate association path: " + wholeAssociationPath, ae);
}
+
+ try
+ {
+ if (crit.WithClause != null)
+ {
+ withClauseMap.Add(wholeAssociationPath, crit.WithClause);
+ }
+ }
+ catch (ArgumentException ae)
+ {
+ throw new QueryException("duplicate association path: " + wholeAssociationPath, ae);
+ }
}
}
@@ -685,6 +698,16 @@
return propertyName;
}
+ public SqlString GetWithClause(string path, IDictionary<string, IFilter> enabledFilters)
+ {
+ if (withClauseMap.ContainsKey(path))
+ {
+ ICriterion crit = (ICriterion)withClauseMap[path];
+ return crit == null ? null : crit.ToSqlString(GetCriteria(path), this, enabledFilters);
+ }
+ return null;
+ }
+
#region NH specific
public int GetIndexForAlias()
Modified: trunk/nhibernate/src/NHibernate/Loader/JoinWalker.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Loader/JoinWalker.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate/Loader/JoinWalker.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -130,6 +130,11 @@
}
}
+ protected virtual SqlString GetWithClause(string path)
+ {
+ return SqlString.Empty;
+ }
+
/// <summary>
/// Add on association (one-to-one, many-to-one, or a collection) to a list
/// of associations to be fetched by outerjoin
@@ -142,7 +147,7 @@
string subalias = GenerateTableAlias(associations.Count + 1, path, joinable);
OuterJoinableAssociation assoc =
- new OuterJoinableAssociation(type, alias, aliasedLhsColumns, subalias, joinType, Factory, enabledFilters);
+ new OuterJoinableAssociation(type, alias, aliasedLhsColumns, subalias, joinType, GetWithClause(path), Factory, enabledFilters);
assoc.ValidateJoin(path);
associations.Add(assoc);
Modified: trunk/nhibernate/src/NHibernate/Loader/OuterJoinableAssociation.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Loader/OuterJoinableAssociation.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate/Loader/OuterJoinableAssociation.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -5,6 +5,7 @@
using NHibernate.Persister.Entity;
using NHibernate.SqlCommand;
using NHibernate.Type;
+using NHibernate.Util;
namespace NHibernate.Loader
{
@@ -17,11 +18,11 @@
private readonly string rhsAlias;
private readonly string[] rhsColumns;
private readonly JoinType joinType;
- private readonly string on;
+ private readonly SqlString on;
private readonly IDictionary<string, IFilter> enabledFilters;
public OuterJoinableAssociation(IAssociationType joinableType, String lhsAlias, String[] lhsColumns, String rhsAlias,
- JoinType joinType, ISessionFactoryImplementor factory,
+ JoinType joinType, SqlString withClause, ISessionFactoryImplementor factory,
IDictionary<string, IFilter> enabledFilters)
{
this.joinableType = joinableType;
@@ -31,7 +32,9 @@
this.joinType = joinType;
joinable = joinableType.GetAssociatedJoinable(factory);
rhsColumns = JoinHelper.GetRHSColumnNames(joinableType, factory);
- on = joinableType.GetOnCondition(rhsAlias, factory, enabledFilters);
+ on = new SqlString(joinableType.GetOnCondition(rhsAlias, factory, enabledFilters));
+ if (StringHelper.IsNotEmpty(withClause))
+ on = on.Append(" and ( ").Append(withClause).Append(" )");
this.enabledFilters = enabledFilters; // needed later for many-to-many/filter application
}
@@ -146,9 +149,10 @@
public void AddManyToManyJoin(JoinFragment outerjoin, IQueryableCollection collection)
{
string manyToManyFilter = collection.GetManyToManyFilterFragment(rhsAlias, enabledFilters);
- string condition = string.Empty.Equals(manyToManyFilter)
+ SqlString condition = string.Empty.Equals(manyToManyFilter)
? on
- : string.Empty.Equals(on) ? manyToManyFilter : on + " and " + manyToManyFilter;
+ : StringHelper.IsEmpty(on) ? new SqlString(manyToManyFilter) :
+ on.Append(" and ").Append(manyToManyFilter);
outerjoin.AddJoin(joinable.TableName, rhsAlias, lhsColumns, rhsColumns, joinType, condition);
outerjoin.AddJoins(joinable.FromJoinFragment(rhsAlias, false, true),
Modified: trunk/nhibernate/src/NHibernate/SqlCommand/ANSIJoinFragment.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/SqlCommand/ANSIJoinFragment.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate/SqlCommand/ANSIJoinFragment.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -17,7 +17,7 @@
}
public override void AddJoin(string tableName, string alias, string[] fkColumns, string[] pkColumns, JoinType joinType,
- string on)
+ SqlString on)
{
string joinString;
switch (joinType)
Modified: trunk/nhibernate/src/NHibernate/SqlCommand/InformixJoinFragment.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/SqlCommand/InformixJoinFragment.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate/SqlCommand/InformixJoinFragment.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -40,7 +40,7 @@
}
public override void AddJoin(string tableName, string alias, string[] fkColumns, string[] pkColumns, JoinType joinType,
- string on)
+ SqlString on)
{
//arbitrary on clause ignored!!
AddJoin(tableName, alias, fkColumns, pkColumns, joinType);
Modified: trunk/nhibernate/src/NHibernate/SqlCommand/JoinFragment.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/SqlCommand/JoinFragment.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate/SqlCommand/JoinFragment.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -20,7 +20,7 @@
public abstract void AddJoin(string tableName, string alias, string[] fkColumns, string[] pkColumns, JoinType joinType);
public abstract void AddJoin(string tableName, string alias, string[] fkColumns, string[] pkColumns, JoinType joinType,
- string on);
+ SqlString on);
public abstract void AddCrossJoin(string tableName, string alias);
Modified: trunk/nhibernate/src/NHibernate/SqlCommand/OracleJoinFragment.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/SqlCommand/OracleJoinFragment.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate/SqlCommand/OracleJoinFragment.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -36,7 +36,7 @@
}
public override void AddJoin(string tableName, string alias, string[] fkColumns, string[] pkColumns, JoinType joinType,
- string on)
+ SqlString on)
{
//arbitrary on clause ignored!!
AddJoin(tableName, alias, fkColumns, pkColumns, joinType);
@@ -62,9 +62,9 @@
/// was a normal join condition, but is natural
/// for a filter.
/// </summary>
- private void AddLeftOuterJoinCondition(string on)
+ private void AddLeftOuterJoinCondition(SqlString on)
{
- StringBuilder buf = new StringBuilder(on);
+ StringBuilder buf = new StringBuilder(on.ToString());
for (int i = 0; i < buf.Length; i++)
{
char character = buf[i];
@@ -76,7 +76,7 @@
i += 3;
}
}
- AddCondition(buf.ToString());
+ AddCondition(SqlString.Parse(buf.ToString()));
}
private static readonly ISet Operators = new HashedSet();
Modified: trunk/nhibernate/src/NHibernate/SqlCommand/QueryJoinFragment.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/SqlCommand/QueryJoinFragment.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate/SqlCommand/QueryJoinFragment.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -25,7 +25,7 @@
}
private void AddJoin(string tableName, string alias, string concreteAlias, string[] fkColumns, string[] pkColumns,
- JoinType joinType, string on)
+ JoinType joinType, SqlString on)
{
if (!useThetaStyleInnerJoins || joinType != JoinType.InnerJoin)
{
@@ -42,7 +42,7 @@
}
public override void AddJoin(string tableName, string alias, string[] fkColumns, string[] pkColumns, JoinType joinType,
- string on)
+ SqlString on)
{
AddJoin(tableName, alias, alias, fkColumns, pkColumns, joinType, on);
}
Modified: trunk/nhibernate/src/NHibernate/Util/StringHelper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Util/StringHelper.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate/Util/StringHelper.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -496,9 +496,14 @@
public static bool IsNotEmpty(SqlString str)
{
- return str != null && str.Count > 0;
+ return !IsEmpty(str);
}
+ public static bool IsEmpty(SqlString str)
+ {
+ return str == null || str.Count == 0;
+ }
+
/// <summary>
///
/// </summary>
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/CriteriaQueryTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/CriteriaQueryTest.cs 2010-08-01 19:49:12 UTC (rev 5090)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/CriteriaQueryTest.cs 2010-08-02 11:35:07 UTC (rev 5091)
@@ -1849,5 +1849,111 @@
criteria.List();
}
}
+
+
+ [Test]
+ public void AliasJoinCriterion()
+ {
+ using (ISession session = this.OpenSession())
+ {
+ using (ITransaction t = session.BeginTransaction())
+ {
+ Course courseA = new Course();
+ courseA.CourseCode = "HIB-A";
+ courseA.Description = "Hibernate Training A";
+ session.Persist(courseA);
+
+ Course courseB = new Course();
+ courseB.CourseCode = "HIB-B";
+ courseB.Description = "Hibernate Training B";
+ session.Persist(courseB);
+
+ Student gavin = new Student();
+ gavin.Name = "Gavin King";
+ gavin.StudentNumber = 232;
+ gavin.PreferredCourse = courseA;
+ session.Persist(gavin);
+
+ Student leonardo = new Student();
+ leonardo.Name = "Leonardo Quijano";
+ leonardo.StudentNumber = 233;
+ leonardo.PreferredCourse = courseB;
+ session.Persist(leonardo);
+
+ Student johnDoe = new Student();
+ johnDoe.Name = "John Doe";
+ johnDoe.StudentNumber = 235;
+ johnDoe.PreferredCourse = null;
+ session.Persist(johnDoe);
+
+ // test == on one value exists
+ IList<string> result = session.CreateCriteria<Student>()
+ .CreateAlias("PreferredCourse", "pc", JoinType.LeftOuterJoin,
+ Restrictions.Eq("pc.CourseCode", "HIB-A"))
+ .SetProjection(Property.ForName("pc.CourseCode"))
+ .AddOrder(Order.Asc("pc.CourseCode"))
+ .List<string>();
+
+ // can't be sure of NULL comparison ordering aside from they should
+ // either come first or last
+ if (result[0] == null)
+ {
+ Assert.IsNull(result[1]);
+ Assert.AreEqual("HIB-A", result[2]);
+ }
+ else
+ {
+ Assert.IsNull(result[2]);
+ Assert.IsNull(result[1]);
+ Assert.AreEqual("HIB-A", result[0]);
+ }
+
+ // test == on non existent value
+ result = session.CreateCriteria<Student>()
+ .CreateAlias("PreferredCourse", "pc", JoinType.LeftOuterJoin,
+ Restrictions.Eq("pc.CourseCode", "HIB-R"))
+ .SetProjection(Property.ForName("pc.CourseCode"))
+ .AddOrder(Order.Asc("pc.CourseCode"))
+ .List<string>();
+
+ Assert.AreEqual(3, result.Count);
+ Assert.IsNull(result[2]);
+ Assert.IsNull(result[1]);
+ Assert.IsNull(result[0]);
+
+ // test != on one existing value
+ result = session.CreateCriteria<Student>()
+ .CreateAlias("PreferredCourse", "pc", JoinType.LeftOuterJoin,
+ Restrictions.Not(Restrictions.Eq("pc.CourseCode", "HIB-A")))
+ .SetProjection(Property.ForName("pc.CourseCode"))
+ .AddOrder(Order.Asc("pc.CourseCode"))
+ .List<string>();
+
+ Assert.AreEqual(3, result.Count);
+
+ // can't be sure of NULL comparison ordering aside from they should
+ // either come first or last
+ if (result[0] == null)
+ {
+ Assert.IsNull(result[1]);
+ Assert.AreEqual("HIB-B", result[2]);
+ }
+ else
+ {
+ Assert.AreEqual("HIB-B", result[0]);
+ Assert.IsNull(result[1]);
+ Assert.IsNull(result[2]);
+ }
+
+ session.Delete(gavin);
+ session.Delete(leonardo);
+ session.Delete(johnDoe);
+ session.Delete(courseA);
+ session.Delete(courseB);
+
+ t.Commit();
+ }
+ }
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2010-08-01 19:49:18
|
Revision: 5090
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5090&view=rev
Author: fabiomaulo
Date: 2010-08-01 19:49:12 +0000 (Sun, 01 Aug 2010)
Log Message:
-----------
Removed obsolete classes (thanks to Patrick Earl)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/NHibernate.csproj
Removed Paths:
-------------
trunk/nhibernate/src/NHibernate/Impl/DbCommandSet.cs
trunk/nhibernate/src/NHibernate/Impl/IDbCommandSet.cs
trunk/nhibernate/src/NHibernate/Impl/OracleClientCommandSet.cs
trunk/nhibernate/src/NHibernate/Impl/SqlClientCommandSet.cs
Deleted: trunk/nhibernate/src/NHibernate/Impl/DbCommandSet.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/DbCommandSet.cs 2010-08-01 17:41:53 UTC (rev 5089)
+++ trunk/nhibernate/src/NHibernate/Impl/DbCommandSet.cs 2010-08-01 19:49:12 UTC (rev 5090)
@@ -1,133 +0,0 @@
-
-using System;
-using System.Data;
-
-namespace NHibernate.Impl
-{
- /// <summary>
- /// Expose the batch functionality in ADO.Net 2.0
- /// Microsoft in its wisdom decided to make my life hard and mark it internal.
- /// Through the use of Reflection and some delegates magic, I opened up the functionality.
- ///
- /// Observable performance benefits are 50%+ when used, so it is really worth it.
- /// </summary>
- public abstract class DbCommandSet<TConnection, TCommand> : IDbCommandSet
- where TConnection : class, IDbConnection
- where TCommand : class, IDbCommand
- {
- private readonly PropGetter<TCommand> commandGetter;
- private readonly AppendCommand doAppend;
- private readonly ExecuteNonQueryCommand doExecuteNonQuery;
- private readonly DisposeCommand doDispose;
- private int countOfCommands;
-
- protected DbCommandSet()
- {
- object internalCommandSet = CreateInternalCommandSet();
- commandGetter =
- (PropGetter<TCommand>)
- Delegate.CreateDelegate(typeof(PropGetter<TCommand>), internalCommandSet,
- "get_BatchCommand");
- doAppend = (AppendCommand)Delegate.CreateDelegate(typeof(AppendCommand), internalCommandSet, "Append");
- doExecuteNonQuery = (ExecuteNonQueryCommand)
- Delegate.CreateDelegate(typeof(ExecuteNonQueryCommand),
- internalCommandSet, "ExecuteNonQuery");
- doDispose = (DisposeCommand)Delegate.CreateDelegate(typeof(DisposeCommand), internalCommandSet, "Dispose");
- }
-
- protected abstract object CreateInternalCommandSet();
-
- /// <summary>
- /// Append a command to the batch
- /// </summary>
- /// <param name="command"></param>
- public void Append(IDbCommand command)
- {
- AssertHasParameters(command);
- TCommand sqlCommand = (TCommand)command;
- doAppend(sqlCommand);
- countOfCommands++;
- }
-
- /// <summary>
- /// This is required because SqlClient.SqlCommandSet will throw if
- /// the command has no parameters.
- /// </summary>
- /// <param name="command"></param>
- private static void AssertHasParameters(IDbCommand command)
- {
- if (command.Parameters.Count == 0)
- {
- throw new ArgumentException("A command in SqlCommandSet must have parameters. You can't pass hardcoded sql strings.");
- }
- }
-
-
- /// <summary>
- /// Return the batch command to be executed
- /// </summary>
- public IDbCommand BatchCommand
- {
- get { return commandGetter(); }
- }
-
- /// <summary>
- /// The number of commands batched in this instance
- /// </summary>
- public int CountOfCommands
- {
- get { return countOfCommands; }
- }
-
- /// <summary>
- /// Executes the batch
- /// </summary>
- /// <returns>
- /// This seems to be returning the total number of affected rows in all queries
- /// </returns>
- public int ExecuteNonQuery()
- {
- if (Connection == null)
- throw new ArgumentNullException("Connection",
- "Connection was not set! You must set the connection property before calling ExecuteNonQuery()");
- try
- {
- if (CountOfCommands == 0)
- return 0;
- return doExecuteNonQuery();
- }
- catch (Exception e)
- {
- throw new HibernateException("An exception occurred when executing batch queries", e);
- }
- }
-
- public TConnection Connection
- {
- get { return (TConnection) commandGetter().Connection; }
- set { commandGetter().Connection = value; }
- }
-
- ///<summary>
- ///Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- ///</summary>
- ///<filterpriority>2</filterpriority>
- public void Dispose()
- {
- doDispose();
- }
-
- #region Delegate Definitions
-
- private delegate T PropGetter<T>();
-
- private delegate void AppendCommand(TCommand command);
-
- private delegate int ExecuteNonQueryCommand();
-
- private delegate void DisposeCommand();
-
- #endregion
- }
-}
-
Deleted: trunk/nhibernate/src/NHibernate/Impl/IDbCommandSet.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/IDbCommandSet.cs 2010-08-01 17:41:53 UTC (rev 5089)
+++ trunk/nhibernate/src/NHibernate/Impl/IDbCommandSet.cs 2010-08-01 19:49:12 UTC (rev 5090)
@@ -1,32 +0,0 @@
-using System;
-using System.Data;
-
-namespace NHibernate.Impl
-{
- internal interface IDbCommandSet : IDisposable
- {
- /// <summary>
- /// Append a command to the batch
- /// </summary>
- /// <param name="command"></param>
- void Append(IDbCommand command);
-
- /// <summary>
- /// Return the batch command to be executed
- /// </summary>
- IDbCommand BatchCommand { get; }
-
- /// <summary>
- /// The number of commands batched in this instance
- /// </summary>
- int CountOfCommands { get; }
-
- /// <summary>
- /// Executes the batch
- /// </summary>
- /// <returns>
- /// This seems to be returning the total number of affected rows in all queries
- /// </returns>
- int ExecuteNonQuery();
- }
-}
Deleted: trunk/nhibernate/src/NHibernate/Impl/OracleClientCommandSet.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/OracleClientCommandSet.cs 2010-08-01 17:41:53 UTC (rev 5089)
+++ trunk/nhibernate/src/NHibernate/Impl/OracleClientCommandSet.cs 2010-08-01 19:49:12 UTC (rev 5090)
@@ -1,25 +0,0 @@
-using System;
-using System.Data.OracleClient;
-using System.Diagnostics;
-using System.Reflection;
-
-namespace NHibernate.Impl
-{
- internal class OracleClientCommandSet : DbCommandSet<OracleConnection, OracleCommand>
- {
- private static readonly System.Type oracleCmdSetType;
-
- static OracleClientCommandSet()
- {
- Assembly sysDataOracleClient =
- Assembly.Load("System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
- oracleCmdSetType = sysDataOracleClient.GetType("System.Data.OracleClient.OracleCommandSet");
- Debug.Assert(oracleCmdSetType != null, "Could not find OracleCommandSet!");
- }
-
- protected override object CreateInternalCommandSet()
- {
- return Activator.CreateInstance(oracleCmdSetType, true);
- }
- }
-}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate/Impl/SqlClientCommandSet.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/SqlClientCommandSet.cs 2010-08-01 17:41:53 UTC (rev 5089)
+++ trunk/nhibernate/src/NHibernate/Impl/SqlClientCommandSet.cs 2010-08-01 19:49:12 UTC (rev 5090)
@@ -1,33 +0,0 @@
-using System;
-using System.Data;
-using System.Data.SqlClient;
-using System.Reflection;
-
-namespace NHibernate.Impl
-{
- internal class SqlClientCommandSet : DbCommandSet<SqlConnection, System.Data.SqlClient.SqlCommand>
- {
- private static readonly System.Type sqlCmdSetType;
-
- static SqlClientCommandSet()
- {
- Assembly sysData = typeof (IDbConnection).Assembly;
- sqlCmdSetType = sysData.GetType("System.Data.SqlClient.SqlCommandSet");
- }
-
- protected override object CreateInternalCommandSet()
- {
- if (sqlCmdSetType == null)
- {
- throw new HibernateException("Could not find SqlCommandSet" + Environment.NewLine
- + "If you are running on Mono, batching support isn't implemented on Mono"
- + Environment.NewLine
- + "If you are running on Microsoft .NET, this probably means that internal details"
- + Environment.NewLine
- +
- "of the BCL that we rely on to allow this have changed, this is a bug. Please inform the developers");
- }
- return Activator.CreateInstance(sqlCmdSetType, true);
- }
- }
-}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-08-01 17:41:53 UTC (rev 5089)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-08-01 19:49:12 UTC (rev 5090)
@@ -1210,17 +1210,13 @@
<Compile Include="Impl\AbstractDetachedQuery.cs" />
<Compile Include="Hql\Classic\FunctionStack.cs" />
<Compile Include="Impl\AbstractSessionImpl.cs" />
- <Compile Include="Impl\DbCommandSet.cs" />
<Compile Include="Impl\DetachedNamedQuery.cs" />
<Compile Include="Impl\DetachedQuery.cs" />
<Compile Include="IDetachedQuery.cs" />
<Compile Include="IdentityEqualityComparer.cs" />
- <Compile Include="Impl\IDbCommandSet.cs" />
<Compile Include="Impl\IDetachedQueryImplementor.cs" />
<Compile Include="Impl\MultiCriteriaImpl.cs" />
<Compile Include="Impl\MultipleQueriesCacheAssembler.cs" />
- <Compile Include="Impl\OracleClientCommandSet.cs" />
- <Compile Include="Impl\SqlClientCommandSet.cs" />
<Compile Include="Impl\StatelessSessionImpl.cs" />
<Compile Include="IMultiCriteria.cs" />
<Compile Include="Intercept\AbstractFieldInterceptor.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2010-08-01 17:41:59
|
Revision: 5089
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5089&view=rev
Author: fabiomaulo
Date: 2010-08-01 17:41:53 +0000 (Sun, 01 Aug 2010)
Log Message:
-----------
Tests for NH-2206 (not fixed yet)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate.Test/Linq/WhereTests.cs
Modified: trunk/nhibernate/src/NHibernate.Test/Linq/WhereTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Linq/WhereTests.cs 2010-08-01 13:49:32 UTC (rev 5088)
+++ trunk/nhibernate/src/NHibernate.Test/Linq/WhereTests.cs 2010-08-01 17:41:53 UTC (rev 5089)
@@ -403,6 +403,24 @@
Assert.AreEqual(2, query.Count);
}
+ [Test(Description = "Reported as bug NH-2206"), Ignore("Not fixed yet")]
+ public void SearchOnObjectTypeUpCastWithExtensionMethod()
+ {
+ var query = (from o in session.Query<Dog>()
+ select o).Cast<Animal>().ToList();
+
+ Assert.AreEqual(2, query.Count);
+ }
+
+ [Test(Description = "Reported as bug NH-2206"), Ignore("Not fixed yet")]
+ public void SearchOnObjectTypeCast()
+ {
+ var query = (from Dog o in session.Query<Dog>()
+ select o).ToList();
+
+ Assert.AreEqual(2, query.Count);
+ }
+
[Test]
public void SearchOnObjectTypeWithIsKeyword()
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2010-08-01 13:49:38
|
Revision: 5088
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5088&view=rev
Author: fabiomaulo
Date: 2010-08-01 13:49:32 +0000 (Sun, 01 Aug 2010)
Log Message:
-----------
Removed unused method
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessOfType.cs
Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessOfType.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessOfType.cs 2010-08-01 12:50:01 UTC (rev 5087)
+++ trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessOfType.cs 2010-08-01 13:49:32 UTC (rev 5088)
@@ -1,36 +1,26 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
+using System.Linq.Expressions;
using NHibernate.Hql.Ast;
using Remotion.Data.Linq.Clauses.ResultOperators;
using Remotion.Data.Linq.Clauses.StreamedData;
namespace NHibernate.Linq.Visitors.ResultOperatorProcessors
{
- public class ProcessOfType : IResultOperatorProcessor<OfTypeResultOperator>
- {
- public void Process(OfTypeResultOperator resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
- {
- var source =
- queryModelVisitor.CurrentEvaluationType.As<StreamedSequenceInfo>().ItemExpression;
+ public class ProcessOfType : IResultOperatorProcessor<OfTypeResultOperator>
+ {
+ #region IResultOperatorProcessor<OfTypeResultOperator> Members
- var type = BuildDot(resultOperator.SearchedItemType.FullName.Split('.'), tree.TreeBuilder);
+ public void Process(OfTypeResultOperator resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
+ {
+ Expression source =
+ queryModelVisitor.CurrentEvaluationType.As<StreamedSequenceInfo>().ItemExpression;
- tree.AddWhereClause(tree.TreeBuilder.Equality(
- tree.TreeBuilder.Dot(
- HqlGeneratorExpressionTreeVisitor.Visit(source, queryModelVisitor.VisitorParameters).AsExpression(),
- tree.TreeBuilder.Class()),
- tree.TreeBuilder.Ident(resultOperator.SearchedItemType.FullName)));
- }
+ tree.AddWhereClause(tree.TreeBuilder.Equality(
+ tree.TreeBuilder.Dot(
+ HqlGeneratorExpressionTreeVisitor.Visit(source, queryModelVisitor.VisitorParameters).AsExpression(),
+ tree.TreeBuilder.Class()),
+ tree.TreeBuilder.Ident(resultOperator.SearchedItemType.FullName)));
+ }
- private static HqlExpression BuildDot(IEnumerable<string> split, HqlTreeBuilder builder)
- {
- if (split.Count() == 1)
- {
- return builder.Ident(split.First());
- }
-
- return builder.Dot(builder.Ident(split.First()), BuildDot(split.Skip(1), builder));
- }
- }
+ #endregion
+ }
}
\ 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-08-01 12:50:07
|
Revision: 5087
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5087&view=rev
Author: fabiomaulo
Date: 2010-08-01 12:50:01 +0000 (Sun, 01 Aug 2010)
Log Message:
-----------
Fix NH-2245 (thanks to Harold Howe)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2245/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2245/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2245/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2245/Model.cs
Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2010-07-31 14:15:53 UTC (rev 5086)
+++ trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2010-08-01 12:50:01 UTC (rev 5087)
@@ -2367,7 +2367,8 @@
.SetTableName(GetTableName(j))
.SetIdentityColumn(GetKeyColumns(j), IdentifierType);
- if (j == 0 && IsVersioned)
+ // NH: Only add version to where clause if optimistic lock mode is Version
+ if (j == 0 && IsVersioned && entityMetamodel.OptimisticLockMode == Versioning.OptimisticLock.Version)
{
deleteBuilder.SetVersionColumn(new[] { VersionColumnName }, VersionType);
}
@@ -2811,7 +2812,9 @@
return;
}
- bool useVersion = j == 0 && IsVersioned;
+ // NH : Only use version if lock mode is Version
+ bool useVersion = j == 0 && IsVersioned && Versioning.OptimisticLock.Version == entityMetamodel.OptimisticLockMode;
+
//bool callable = IsDeleteCallable(j);
IExpectation expectation = Expectations.AppropriateExpectation(deleteResultCheckStyles[j]);
bool useBatch = j == 0 && expectation.CanBeBatched && IsBatchable;
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2245/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2245/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2245/Fixture.cs 2010-08-01 12:50:01 UTC (rev 5087)
@@ -0,0 +1,62 @@
+using System;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.NHSpecificTest.NH2245
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+ [Test]
+ public void TestDelete_OptimisticLockNone()
+ {
+ Guid id;
+
+ // persist a foo instance
+ using (ISession session = OpenSession())
+ {
+ using (ITransaction tx = session.BeginTransaction())
+ {
+ var f = new Foo();
+ f.Name = "Henry";
+ f.Description = "description";
+ session.Save(f);
+ tx.Commit();
+ id = f.Id;
+ }
+ }
+
+ using (ISession session1 = OpenSession())
+ using (ISession session2 = OpenSession())
+ {
+ // Load the foo from two different sessions. Modify the foo in one session to bump the version in the database, and save.
+ // Then try to delete the foo from the other session. With optimistic lock set to none, this should succeed when the 2245
+ // patch is applied to AbstractEntityPersister.cs. Without the patch, NH adds the version to the where clause of the delete
+ // statement, and the delete fails.
+ var f1 = session1.Get<Foo>(id);
+ var f2 = session2.Get<Foo>(id);
+
+ // Bump version
+ using (ITransaction trans1 = session1.BeginTransaction())
+ {
+ f1.Description = "modified description";
+ session1.Update(f1);
+ trans1.Commit();
+ }
+
+ // Now delete from second session
+ using (ITransaction trans2 = session2.BeginTransaction())
+ {
+ session2.Executing(s=> s.Delete(f2)).NotThrows();
+ trans2.Commit();
+ }
+ }
+
+ // Assert that row is really gone
+ using (ISession assertSession = OpenSession())
+ {
+ Assert.IsNull(assertSession.Get<Foo>(id));
+ }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2245/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2245/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2245/Mappings.hbm.xml 2010-08-01 12:50:01 UTC (rev 5087)
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.NHSpecificTest.NH2245">
+
+ <class name="Foo" table="Foos" optimistic-lock="none">
+ <id name="Id">
+ <generator class="guid.comb"/>
+ </id>
+ <version name="Version" column="Version" />
+ <property name="Name" type="String" />
+ <property name="Description" type="String"/>
+ </class>
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2245/Model.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2245/Model.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2245/Model.cs 2010-08-01 12:50:01 UTC (rev 5087)
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+
+namespace NHibernate.Test.NHSpecificTest.NH2245
+{
+public class Foo
+{
+ public Foo() {}
+ public virtual Guid Id {get; private set;}
+ public virtual string Name {get; set;}
+ public virtual string Description {get; set;}
+ public virtual int Version{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-31 14:15:53 UTC (rev 5086)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-08-01 12:50:01 UTC (rev 5087)
@@ -440,6 +440,8 @@
<Compile Include="Linq\QueryCacheableTests.cs" />
<Compile Include="Linq\QueryReuseTests.cs" />
<Compile Include="Linq\ReadonlyTestCase.cs" />
+ <Compile Include="NHSpecificTest\NH2245\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH2245\Model.cs" />
<Compile Include="UtilityTest\ReflectionHelperIsMethodOfTests.cs" />
<Compile Include="UtilityTest\ReflectionHelperTest.cs" />
<Compile Include="Linq\RegresstionTests.cs" />
@@ -2220,6 +2222,7 @@
<EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" />
<EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH2245\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2257\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2208\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2251\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-31 14:16:00
|
Revision: 5086
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5086&view=rev
Author: fabiomaulo
Date: 2010-07-31 14:15:53 +0000 (Sat, 31 Jul 2010)
Log Message:
-----------
- relax of DateTimePropertiesHqlGenerator
- removed if in ToUpperLowerGenerator (separated in two classes)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Linq/Functions/DateTimePropertiesHqlGenerator.cs
trunk/nhibernate/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs
trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs
Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/DateTimePropertiesHqlGenerator.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/DateTimePropertiesHqlGenerator.cs 2010-07-31 13:59:59 UTC (rev 5085)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/DateTimePropertiesHqlGenerator.cs 2010-07-31 14:15:53 UTC (rev 5086)
@@ -33,7 +33,7 @@
}
}
- public HqlTreeNode BuildHql(MemberInfo member, Expression expression, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
+ public virtual HqlTreeNode BuildHql(MemberInfo member, Expression expression, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
{
return treeBuilder.MethodCall(member.Name.ToLowerInvariant(),
visitor.Visit(expression).AsExpression());
Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs 2010-07-31 13:59:59 UTC (rev 5085)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs 2010-07-31 14:15:53 UTC (rev 5086)
@@ -19,7 +19,8 @@
this.Merge(new EndsWithGenerator());
this.Merge(new ContainsGenerator());
this.Merge(new EqualsGenerator());
- this.Merge(new ToUpperLowerGenerator());
+ this.Merge(new ToUpperGenerator());
+ this.Merge(new ToLowerGenerator());
this.Merge(new SubStringGenerator());
this.Merge(new IndexOfGenerator());
this.Merge(new ReplaceGenerator());
Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs 2010-07-31 13:59:59 UTC (rev 5085)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs 2010-07-31 14:15:53 UTC (rev 5086)
@@ -86,14 +86,12 @@
}
}
- public class ToUpperLowerGenerator : BaseHqlGeneratorForMethod
+ public class ToLowerGenerator : BaseHqlGeneratorForMethod
{
- public ToUpperLowerGenerator()
+ public ToLowerGenerator()
{
SupportedMethods = new[]
{
- ReflectionHelper.GetMethodDefinition<string>(x => x.ToUpper()),
- ReflectionHelper.GetMethodDefinition<string>(x => x.ToUpperInvariant()),
ReflectionHelper.GetMethodDefinition<string>(x => x.ToLower()),
ReflectionHelper.GetMethodDefinition<string>(x => x.ToLowerInvariant())
};
@@ -101,18 +99,24 @@
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
{
- string methodName;
+ return treeBuilder.MethodCall("lower", visitor.Visit(targetObject).AsExpression());
+ }
+ }
- if (((method.Name == "ToUpper") || (method.Name == "ToUpperInvariant")))
- {
- methodName = "upper";
- }
- else
- {
- methodName = "lower";
- }
+ public class ToUpperGenerator : BaseHqlGeneratorForMethod
+ {
+ public ToUpperGenerator()
+ {
+ SupportedMethods = new[]
+ {
+ ReflectionHelper.GetMethodDefinition<string>(x => x.ToUpper()),
+ ReflectionHelper.GetMethodDefinition<string>(x => x.ToUpperInvariant()),
+ };
+ }
- return treeBuilder.MethodCall(methodName, visitor.Visit(targetObject).AsExpression());
+ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
+ {
+ return treeBuilder.MethodCall("upper", visitor.Visit(targetObject).AsExpression());
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2010-07-31 14:00:06
|
Revision: 5085
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5085&view=rev
Author: fabiomaulo
Date: 2010-07-31 13:59:59 +0000 (Sat, 31 Jul 2010)
Log Message:
-----------
Refactoring in order to allow/show a more grained of ILinqToHqlGeneratorsRegistry; In this way the user can choose what reuse, what replace and what override.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs
trunk/nhibernate/src/NHibernate/Linq/Functions/ILinqToHqlGeneratorsRegistry.cs
trunk/nhibernate/src/NHibernate/Linq/Functions/QueryableGenerator.cs
trunk/nhibernate/src/NHibernate/Linq/Functions/StandardLinqExtensionMethodGenerator.cs
trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/Linq/LinqToHqlGeneratorsRegistryFactoryTest.cs
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Linq/Functions/DateTimePropertiesHqlGenerator.cs
trunk/nhibernate/src/NHibernate/Linq/Functions/IRuntimeMethodHqlGenerator.cs
trunk/nhibernate/src/NHibernate/Linq/Functions/LinqToHqlGeneratorsRegistryExtensions.cs
Removed Paths:
-------------
trunk/nhibernate/src/NHibernate/Linq/Functions/BaseHqlGeneratorForType.cs
trunk/nhibernate/src/NHibernate/Linq/Functions/DateTimeGenerator.cs
trunk/nhibernate/src/NHibernate/Linq/Functions/IHqlGeneratorForType.cs
Deleted: trunk/nhibernate/src/NHibernate/Linq/Functions/BaseHqlGeneratorForType.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/BaseHqlGeneratorForType.cs 2010-07-31 11:38:05 UTC (rev 5084)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/BaseHqlGeneratorForType.cs 2010-07-31 13:59:59 UTC (rev 5085)
@@ -1,45 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-
-namespace NHibernate.Linq.Functions
-{
- public abstract class BaseHqlGeneratorForType : IHqlGeneratorForType
- {
- protected readonly List<IHqlGeneratorForMethod> MethodRegistry = new List<IHqlGeneratorForMethod>();
- protected readonly List<IHqlGeneratorForProperty> PropertyRegistry = new List<IHqlGeneratorForProperty>();
-
- #region IHqlGeneratorForType Members
-
- public void Register(ILinqToHqlGeneratorsRegistry functionRegistry)
- {
- foreach (IHqlGeneratorForMethod generator in MethodRegistry)
- {
- foreach (MethodInfo method in generator.SupportedMethods)
- {
- functionRegistry.RegisterGenerator(method, generator);
- }
- }
-
- foreach (IHqlGeneratorForProperty generator in PropertyRegistry)
- {
- foreach (MemberInfo property in generator.SupportedProperties)
- {
- functionRegistry.RegisterGenerator(property, generator);
- }
- }
- }
-
- public virtual bool SupportsMethod(MethodInfo method)
- {
- return false;
- }
-
- public virtual IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method)
- {
- throw new NotSupportedException();
- }
-
- #endregion
- }
-}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate/Linq/Functions/DateTimeGenerator.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/DateTimeGenerator.cs 2010-07-31 11:38:05 UTC (rev 5084)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/DateTimeGenerator.cs 2010-07-31 13:59:59 UTC (rev 5085)
@@ -1,39 +0,0 @@
-using System;
-using System.Linq.Expressions;
-using System.Reflection;
-using NHibernate.Hql.Ast;
-using NHibernate.Linq.Visitors;
-
-namespace NHibernate.Linq.Functions
-{
- public class DateTimeGenerator : BaseHqlGeneratorForType
- {
- public DateTimeGenerator()
- {
- PropertyRegistry.Add(new DatePartGenerator());
- }
-
- public class DatePartGenerator : BaseHqlGeneratorForProperty
- {
- public DatePartGenerator()
- {
- SupportedProperties = new[]
- {
- ReflectionHelper.GetProperty((DateTime x) => x.Year),
- ReflectionHelper.GetProperty((DateTime x) => x.Month),
- ReflectionHelper.GetProperty((DateTime x) => x.Day),
- ReflectionHelper.GetProperty((DateTime x) => x.Hour),
- ReflectionHelper.GetProperty((DateTime x) => x.Minute),
- ReflectionHelper.GetProperty((DateTime x) => x.Second),
- ReflectionHelper.GetProperty((DateTime x) => x.Date),
- };
- }
-
- public override HqlTreeNode BuildHql(MemberInfo member, Expression expression, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
- {
- return treeBuilder.MethodCall(member.Name.ToLowerInvariant(),
- visitor.Visit(expression).AsExpression());
- }
- }
- }
-}
\ No newline at end of file
Copied: trunk/nhibernate/src/NHibernate/Linq/Functions/DateTimePropertiesHqlGenerator.cs (from rev 5083, trunk/nhibernate/src/NHibernate/Linq/Functions/DateTimeGenerator.cs)
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/DateTimePropertiesHqlGenerator.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/DateTimePropertiesHqlGenerator.cs 2010-07-31 13:59:59 UTC (rev 5085)
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq.Expressions;
+using System.Reflection;
+using NHibernate.Hql.Ast;
+using NHibernate.Linq.Visitors;
+
+namespace NHibernate.Linq.Functions
+{
+ public class DateTimePropertiesHqlGenerator : IHqlGeneratorForProperty
+ {
+ private readonly MemberInfo[] supportedProperties;
+
+ public DateTimePropertiesHqlGenerator()
+ {
+ supportedProperties = new[]
+ {
+ ReflectionHelper.GetProperty((DateTime x) => x.Year),
+ ReflectionHelper.GetProperty((DateTime x) => x.Month),
+ ReflectionHelper.GetProperty((DateTime x) => x.Day),
+ ReflectionHelper.GetProperty((DateTime x) => x.Hour),
+ ReflectionHelper.GetProperty((DateTime x) => x.Minute),
+ ReflectionHelper.GetProperty((DateTime x) => x.Second),
+ ReflectionHelper.GetProperty((DateTime x) => x.Date),
+ };
+ }
+
+ public IEnumerable<MemberInfo> SupportedProperties
+ {
+ get
+ {
+ return supportedProperties;
+ }
+ }
+
+ public HqlTreeNode BuildHql(MemberInfo member, Expression expression, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
+ {
+ return treeBuilder.MethodCall(member.Name.ToLowerInvariant(),
+ visitor.Visit(expression).AsExpression());
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs 2010-07-31 11:38:05 UTC (rev 5084)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs 2010-07-31 13:59:59 UTC (rev 5085)
@@ -8,22 +8,37 @@
{
private readonly Dictionary<MethodInfo, IHqlGeneratorForMethod> registeredMethods = new Dictionary<MethodInfo, IHqlGeneratorForMethod>();
private readonly Dictionary<MemberInfo, IHqlGeneratorForProperty> registeredProperties = new Dictionary<MemberInfo, IHqlGeneratorForProperty>();
- private readonly List<IHqlGeneratorForType> typeGenerators = new List<IHqlGeneratorForType>();
+ private readonly List<IRuntimeMethodHqlGenerator> runtimeMethodHqlGenerators = new List<IRuntimeMethodHqlGenerator>();
public DefaultLinqToHqlGeneratorsRegistry()
{
- Register(new StandardLinqExtensionMethodGenerator());
- Register(new QueryableGenerator());
- Register(new StringGenerator());
- Register(new DateTimeGenerator());
- Register(new ICollectionGenerator());
+ RegisterGenerator(new StandardLinqExtensionMethodGenerator());
+ RegisterGenerator(new CollectionContainsRuntimeHqlGenerator());
+
+ this.Merge(new StartsWithGenerator());
+ this.Merge(new EndsWithGenerator());
+ this.Merge(new ContainsGenerator());
+ this.Merge(new EqualsGenerator());
+ this.Merge(new ToUpperLowerGenerator());
+ this.Merge(new SubStringGenerator());
+ this.Merge(new IndexOfGenerator());
+ this.Merge(new ReplaceGenerator());
+ this.Merge(new LengthGenerator());
+
+ this.Merge(new AnyHqlGenerator());
+ this.Merge(new AllHqlGenerator());
+ this.Merge(new MinHqlGenerator());
+ this.Merge(new MaxHqlGenerator());
+ this.Merge(new CollectionContainsGenerator());
+
+ this.Merge(new DateTimePropertiesHqlGenerator());
}
- protected bool GetMethodGeneratorForType(MethodInfo method, out IHqlGeneratorForMethod methodGenerator)
+ protected bool GetRuntimeMethodGenerator(MethodInfo method, out IHqlGeneratorForMethod methodGenerator)
{
methodGenerator = null;
- foreach (var typeGenerator in typeGenerators.Where(typeGenerator => typeGenerator.SupportsMethod(method)))
+ foreach (var typeGenerator in runtimeMethodHqlGenerators.Where(typeGenerator => typeGenerator.SupportsMethod(method)))
{
methodGenerator = typeGenerator.GetMethodGenerator(method);
return true;
@@ -41,7 +56,7 @@
if (registeredMethods.TryGetValue(method, out generator)) return true;
// Not that either. Let's query each type generator to see if it can handle it
- if (GetMethodGeneratorForType(method, out generator)) return true;
+ if (GetRuntimeMethodGenerator(method, out generator)) return true;
return false;
}
@@ -61,10 +76,9 @@
registeredProperties.Add(property, generator);
}
- protected void Register(IHqlGeneratorForType typeMethodGenerator)
+ public void RegisterGenerator(IRuntimeMethodHqlGenerator generator)
{
- typeGenerators.Add(typeMethodGenerator);
- typeMethodGenerator.Register(this);
+ runtimeMethodHqlGenerators.Add(generator);
}
}
}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate/Linq/Functions/IHqlGeneratorForType.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/IHqlGeneratorForType.cs 2010-07-31 11:38:05 UTC (rev 5084)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/IHqlGeneratorForType.cs 2010-07-31 13:59:59 UTC (rev 5085)
@@ -1,11 +0,0 @@
-using System.Reflection;
-
-namespace NHibernate.Linq.Functions
-{
- public interface IHqlGeneratorForType
- {
- void Register(ILinqToHqlGeneratorsRegistry functionRegistry);
- bool SupportsMethod(MethodInfo method);
- IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method);
- }
-}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/ILinqToHqlGeneratorsRegistry.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/ILinqToHqlGeneratorsRegistry.cs 2010-07-31 11:38:05 UTC (rev 5084)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/ILinqToHqlGeneratorsRegistry.cs 2010-07-31 13:59:59 UTC (rev 5085)
@@ -8,5 +8,6 @@
bool TryGetGenerator(MemberInfo property, out IHqlGeneratorForProperty generator);
void RegisterGenerator(MethodInfo method, IHqlGeneratorForMethod generator);
void RegisterGenerator(MemberInfo property, IHqlGeneratorForProperty generator);
+ void RegisterGenerator(IRuntimeMethodHqlGenerator generator);
}
}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate/Linq/Functions/IRuntimeMethodHqlGenerator.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/IRuntimeMethodHqlGenerator.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/IRuntimeMethodHqlGenerator.cs 2010-07-31 13:59:59 UTC (rev 5085)
@@ -0,0 +1,10 @@
+using System.Reflection;
+
+namespace NHibernate.Linq.Functions
+{
+ public interface IRuntimeMethodHqlGenerator
+ {
+ bool SupportsMethod(MethodInfo method);
+ IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method);
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate/Linq/Functions/LinqToHqlGeneratorsRegistryExtensions.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/LinqToHqlGeneratorsRegistryExtensions.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/LinqToHqlGeneratorsRegistryExtensions.cs 2010-07-31 13:59:59 UTC (rev 5085)
@@ -0,0 +1,34 @@
+using System;
+using System.Linq;
+
+namespace NHibernate.Linq.Functions
+{
+ public static class LinqToHqlGeneratorsRegistryExtensions
+ {
+ public static void Merge(this ILinqToHqlGeneratorsRegistry registry, IHqlGeneratorForMethod generator)
+ {
+ if (registry == null)
+ {
+ throw new ArgumentNullException("registry");
+ }
+ if (generator == null)
+ {
+ throw new ArgumentNullException("generator");
+ }
+ Array.ForEach(generator.SupportedMethods.ToArray(), method=> registry.RegisterGenerator(method, generator));
+ }
+
+ public static void Merge(this ILinqToHqlGeneratorsRegistry registry, IHqlGeneratorForProperty generator)
+ {
+ if (registry == null)
+ {
+ throw new ArgumentNullException("registry");
+ }
+ if (generator == null)
+ {
+ throw new ArgumentNullException("generator");
+ }
+ Array.ForEach(generator.SupportedProperties.ToArray(), property => registry.RegisterGenerator(property, generator));
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/QueryableGenerator.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/QueryableGenerator.cs 2010-07-31 11:38:05 UTC (rev 5084)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/QueryableGenerator.cs 2010-07-31 13:59:59 UTC (rev 5085)
@@ -1,5 +1,4 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Linq.Expressions;
@@ -9,193 +8,165 @@
namespace NHibernate.Linq.Functions
{
- public class QueryableGenerator : BaseHqlGeneratorForType
- {
- public QueryableGenerator()
- {
- // TODO - could use reflection
- MethodRegistry.Add(new AnyGenerator());
- MethodRegistry.Add(new AllGenerator());
- MethodRegistry.Add(new MinGenerator());
- MethodRegistry.Add(new MaxGenerator());
- }
+ public class AnyHqlGenerator : BaseHqlGeneratorForMethod
+ {
+ public AnyHqlGenerator()
+ {
+ SupportedMethods = new[]
+ {
+ ReflectionHelper.GetMethodDefinition(() => Queryable.Any<object>(null)),
+ ReflectionHelper.GetMethodDefinition(() => Queryable.Any<object>(null, null)),
+ ReflectionHelper.GetMethodDefinition(() => Enumerable.Any<object>(null)),
+ ReflectionHelper.GetMethodDefinition(() => Enumerable.Any<object>(null, null))
+ };
+ }
- class AnyGenerator : BaseHqlGeneratorForMethod
- {
- public AnyGenerator()
- {
- SupportedMethods = new[]
- {
- ReflectionHelper.GetMethodDefinition(() => Queryable.Any<object>(null)),
- ReflectionHelper.GetMethodDefinition(() => Queryable.Any<object>(null, null)),
- ReflectionHelper.GetMethodDefinition(() => Enumerable.Any<object>(null)),
- ReflectionHelper.GetMethodDefinition(() => Enumerable.Any<object>(null, null))
- };
- }
+ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
+ {
+ HqlAlias alias = null;
+ HqlWhere where = null;
- public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
- {
- HqlAlias alias = null;
- HqlWhere where = null;
+ if (arguments.Count > 1)
+ {
+ var expr = (LambdaExpression) arguments[1];
- if (arguments.Count > 1)
- {
- var expr = (LambdaExpression)arguments[1];
+ alias = treeBuilder.Alias(expr.Parameters[0].Name);
+ where = treeBuilder.Where(visitor.Visit(arguments[1]).AsExpression());
+ }
- alias = treeBuilder.Alias(expr.Parameters[0].Name);
- where = treeBuilder.Where(visitor.Visit(arguments[1]).AsExpression());
- }
+ return treeBuilder.Exists(
+ treeBuilder.Query(
+ treeBuilder.SelectFrom(
+ treeBuilder.From(
+ treeBuilder.Range(
+ visitor.Visit(arguments[0]),
+ alias)
+ )
+ ),
+ where));
+ }
+ }
- return treeBuilder.Exists(
- treeBuilder.Query(
- treeBuilder.SelectFrom(
- treeBuilder.From(
- treeBuilder.Range(
- visitor.Visit(arguments[0]),
- alias)
- )
- ),
- where));
- }
- }
+ public class AllHqlGenerator : BaseHqlGeneratorForMethod
+ {
+ public AllHqlGenerator()
+ {
+ SupportedMethods = new[]
+ {
+ ReflectionHelper.GetMethodDefinition(() => Queryable.All<object>(null, null)),
+ ReflectionHelper.GetMethodDefinition(() => Enumerable.All<object>(null, null))
+ };
+ }
- class AllGenerator : BaseHqlGeneratorForMethod
- {
- public AllGenerator()
- {
- SupportedMethods = new[]
- {
- ReflectionHelper.GetMethodDefinition(() => Queryable.All<object>(null, null)),
- ReflectionHelper.GetMethodDefinition(() => Enumerable.All<object>(null, null))
- };
- }
+ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
+ {
+ // All has two arguments. Arg 1 is the source and arg 2 is the predicate
+ var predicate = (LambdaExpression) arguments[1];
- public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
- {
- // All has two arguments. Arg 1 is the source and arg 2 is the predicate
- var predicate = (LambdaExpression)arguments[1];
+ return treeBuilder.BooleanNot(
+ treeBuilder.Exists(
+ treeBuilder.Query(
+ treeBuilder.SelectFrom(
+ treeBuilder.From(
+ treeBuilder.Range(
+ visitor.Visit(arguments[0]),
+ treeBuilder.Alias(predicate.Parameters[0].Name))
+ )
+ ),
+ treeBuilder.Where(
+ treeBuilder.BooleanNot(visitor.Visit(arguments[1]).AsBooleanExpression())
+ )
+ )
+ )
+ );
+ }
+ }
- return treeBuilder.BooleanNot(
- treeBuilder.Exists(
- treeBuilder.Query(
- treeBuilder.SelectFrom(
- treeBuilder.From(
- treeBuilder.Range(
- visitor.Visit(arguments[0]),
- treeBuilder.Alias(predicate.Parameters[0].Name))
- )
- ),
- treeBuilder.Where(
- treeBuilder.BooleanNot(visitor.Visit(arguments[1]).AsBooleanExpression())
- )
- )
- )
- );
- }
- }
+ public class MinHqlGenerator : BaseHqlGeneratorForMethod
+ {
+ public MinHqlGenerator()
+ {
+ SupportedMethods = new[]
+ {
+ ReflectionHelper.GetMethodDefinition(() => Queryable.Min<object>(null)),
+ ReflectionHelper.GetMethodDefinition(() => Enumerable.Min<object>(null))
+ };
+ }
- class MinGenerator : BaseHqlGeneratorForMethod
- {
- public MinGenerator()
- {
- SupportedMethods = new[]
- {
- ReflectionHelper.GetMethodDefinition(() => Queryable.Min<object>(null)),
- ReflectionHelper.GetMethodDefinition(() => Enumerable.Min<object>(null))
- };
- }
+ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
+ {
+ return treeBuilder.Min(visitor.Visit(arguments[1]).AsExpression());
+ }
+ }
- public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
- {
- return treeBuilder.Min(visitor.Visit(arguments[1]).AsExpression());
- }
- }
+ public class MaxHqlGenerator : BaseHqlGeneratorForMethod
+ {
+ public MaxHqlGenerator()
+ {
+ SupportedMethods = new[]
+ {
+ ReflectionHelper.GetMethodDefinition(() => Queryable.Max<object>(null)),
+ ReflectionHelper.GetMethodDefinition(() => Enumerable.Max<object>(null))
+ };
+ }
- class MaxGenerator : BaseHqlGeneratorForMethod
- {
- public MaxGenerator()
- {
- SupportedMethods = new[]
- {
- ReflectionHelper.GetMethodDefinition(() => Queryable.Max<object>(null)),
- ReflectionHelper.GetMethodDefinition(() => Enumerable.Max<object>(null))
- };
- }
+ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
+ {
+ return treeBuilder.Max(visitor.Visit(arguments[1]).AsExpression());
+ }
+ }
- public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
- {
- return treeBuilder.Max(visitor.Visit(arguments[1]).AsExpression());
- }
- }
- }
+ public class CollectionContainsRuntimeHqlGenerator : IRuntimeMethodHqlGenerator
+ {
+ private readonly IHqlGeneratorForMethod containsGenerator = new CollectionContainsGenerator();
- public class ICollectionGenerator : BaseHqlGeneratorForType
- {
- public ICollectionGenerator()
- {
- // TODO - could use reflection
- MethodRegistry.Add(new ContainsGenerator());
- }
+ #region IRuntimeMethodHqlGenerator Members
- public override bool SupportsMethod(MethodInfo method)
- {
- var declaringType = method.DeclaringType;
+ public bool SupportsMethod(MethodInfo method)
+ {
+ // the check about the name is to make things a little be fasters
+ return method != null && method.Name == "Contains" && method.IsMethodOf(typeof(ICollection<>));
+ }
- if (declaringType.IsGenericType)
- {
- if (declaringType.GetGenericTypeDefinition() == typeof(ICollection<>) ||
- declaringType.GetGenericTypeDefinition() == typeof(IEnumerable<>))
- {
- if (method.Name == "Contains")
- {
- return true;
- }
- }
- }
+ public IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method)
+ {
+ return containsGenerator;
+ }
- return false;
- }
+ #endregion
+ }
- public override IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method)
- {
- // TODO - ick
- if (method.Name == "Contains")
- {
- return new ContainsGenerator();
- }
+ public class CollectionContainsGenerator : BaseHqlGeneratorForMethod
+ {
+ public CollectionContainsGenerator()
+ {
+ SupportedMethods = new[]
+ {
+ ReflectionHelper.GetMethodDefinition(() => Queryable.Contains<object>(null, null)),
+ ReflectionHelper.GetMethodDefinition(() => Enumerable.Contains<object>(null, null))
+ };
+ }
- throw new NotSupportedException(method.Name);
- }
+ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
+ {
+ // TODO - alias generator
+ HqlAlias alias = treeBuilder.Alias("x");
- class ContainsGenerator : BaseHqlGeneratorForMethod
- {
- public ContainsGenerator()
- {
- SupportedMethods = new MethodInfo[0];
- }
+ ParameterExpression param = Expression.Parameter(targetObject.Type, "x");
+ HqlWhere where = treeBuilder.Where(visitor.Visit(Expression.Lambda(
+ Expression.Equal(param, arguments[0]), param))
+ .AsExpression());
- public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
- {
- // TODO - alias generator
- var alias = treeBuilder.Alias("x");
-
- var param = Expression.Parameter(targetObject.Type, "x");
- var where = treeBuilder.Where(visitor.Visit(Expression.Lambda(
- Expression.Equal(param, arguments[0]), param))
- .AsExpression());
-
- return treeBuilder.Exists(
- treeBuilder.Query(
- treeBuilder.SelectFrom(
- treeBuilder.From(
- treeBuilder.Range(
- visitor.Visit(targetObject),
- alias)
- )
- ),
- where));
- }
- }
-
- }
+ return treeBuilder.Exists(
+ treeBuilder.Query(
+ treeBuilder.SelectFrom(
+ treeBuilder.From(
+ treeBuilder.Range(
+ visitor.Visit(targetObject),
+ alias)
+ )
+ ),
+ where));
+ }
+ }
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/StandardLinqExtensionMethodGenerator.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/StandardLinqExtensionMethodGenerator.cs 2010-07-31 11:38:05 UTC (rev 5084)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/StandardLinqExtensionMethodGenerator.cs 2010-07-31 13:59:59 UTC (rev 5085)
@@ -8,15 +8,10 @@
namespace NHibernate.Linq.Functions
{
- public class StandardLinqExtensionMethodGenerator : IHqlGeneratorForType
+ public class StandardLinqExtensionMethodGenerator : IRuntimeMethodHqlGenerator
{
- #region IHqlGeneratorForType Members
+ #region IRuntimeMethodHqlGenerator Members
- public void Register(ILinqToHqlGeneratorsRegistry functionRegistry)
- {
- // nothing to do
- }
-
public bool SupportsMethod(MethodInfo method)
{
return method.GetCustomAttributes(typeof (LinqExtensionMethodAttribute), false).Any();
@@ -41,21 +36,21 @@
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
{
- var args = visitor.Visit(targetObject)
- .Union(arguments.Select(a => visitor.Visit(a)))
- .Cast<HqlExpression>();
+ IEnumerable<HqlExpression> args = visitor.Visit(targetObject)
+ .Union(arguments.Select(a => visitor.Visit(a)))
+ .Cast<HqlExpression>();
return treeBuilder.MethodCall(_name, args);
}
}
- static class UnionExtension
+ internal static class UnionExtension
{
public static IEnumerable<HqlTreeNode> Union(this HqlTreeNode first, IEnumerable<HqlTreeNode> rest)
{
yield return first;
- foreach (var x in rest)
+ foreach (HqlTreeNode x in rest)
{
yield return x;
}
Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs 2010-07-31 11:38:05 UTC (rev 5084)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs 2010-07-31 13:59:59 UTC (rev 5085)
@@ -6,204 +6,187 @@
namespace NHibernate.Linq.Functions
{
- public class StringGenerator : BaseHqlGeneratorForType
- {
- public StringGenerator()
- {
- // TODO - could use reflection
- MethodRegistry.Add(new StartsWithGenerator());
- MethodRegistry.Add(new EndsWithGenerator());
- MethodRegistry.Add(new ContainsGenerator());
- MethodRegistry.Add(new EqualsGenerator());
- MethodRegistry.Add(new ToUpperLowerGenerator());
- MethodRegistry.Add(new SubStringGenerator());
- MethodRegistry.Add(new IndexOfGenerator());
- MethodRegistry.Add(new ReplaceGenerator());
+ public class LengthGenerator : BaseHqlGeneratorForProperty
+ {
+ public LengthGenerator()
+ {
+ SupportedProperties = new[] { ReflectionHelper.GetProperty((string x) => x.Length) };
+ }
- PropertyRegistry.Add(new LengthGenerator());
- }
+ public override HqlTreeNode BuildHql(MemberInfo member, Expression expression, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
+ {
+ return treeBuilder.MethodCall("length", visitor.Visit(expression).AsExpression());
+ }
+ }
- public class LengthGenerator : BaseHqlGeneratorForProperty
- {
- public LengthGenerator()
- {
- SupportedProperties = new[] {ReflectionHelper.GetProperty((string x) => x.Length)};
- }
+ public class StartsWithGenerator : BaseHqlGeneratorForMethod
+ {
+ public StartsWithGenerator()
+ {
+ SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition<string>(x => x.StartsWith(null)) };
+ }
- public override HqlTreeNode BuildHql(MemberInfo member, Expression expression, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
- {
- return treeBuilder.MethodCall("length", visitor.Visit(expression).AsExpression());
- }
- }
+ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
+ {
+ return treeBuilder.Like(
+ visitor.Visit(targetObject).AsExpression(),
+ treeBuilder.Concat(
+ visitor.Visit(arguments[0]).AsExpression(),
+ treeBuilder.Constant("%")));
+ }
+ }
- class StartsWithGenerator : BaseHqlGeneratorForMethod
- {
- public StartsWithGenerator()
- {
- SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition<string>(x => x.StartsWith(null)) };
- }
+ public class EndsWithGenerator : BaseHqlGeneratorForMethod
+ {
+ public EndsWithGenerator()
+ {
+ SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition<string>(x => x.EndsWith(null)) };
+ }
- public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
- {
- return treeBuilder.Like(
- visitor.Visit(targetObject).AsExpression(),
- treeBuilder.Concat(
- visitor.Visit(arguments[0]).AsExpression(),
- treeBuilder.Constant("%")));
- }
- }
+ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
+ {
+ return treeBuilder.Like(
+ visitor.Visit(targetObject).AsExpression(),
+ treeBuilder.Concat(
+ treeBuilder.Constant("%"),
+ visitor.Visit(arguments[0]).AsExpression()));
+ }
+ }
- class EndsWithGenerator : BaseHqlGeneratorForMethod
- {
- public EndsWithGenerator()
- {
- SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition<string>(x => x.EndsWith(null)) };
- }
+ public class ContainsGenerator : BaseHqlGeneratorForMethod
+ {
+ public ContainsGenerator()
+ {
+ SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition<string>(x => x.Contains(null)) };
+ }
- public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
- {
- return treeBuilder.Like(
- visitor.Visit(targetObject).AsExpression(),
- treeBuilder.Concat(
- treeBuilder.Constant("%"),
- visitor.Visit(arguments[0]).AsExpression()));
- }
- }
+ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
+ {
+ return treeBuilder.Like(
+ visitor.Visit(targetObject).AsExpression(),
+ treeBuilder.Concat(
+ treeBuilder.Constant("%"),
+ visitor.Visit(arguments[0]).AsExpression(),
+ treeBuilder.Constant("%")));
+ }
+ }
- class ContainsGenerator : BaseHqlGeneratorForMethod
- {
- public ContainsGenerator()
- {
- SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition<string>(x => x.Contains(null)) };
- }
+ public class EqualsGenerator : BaseHqlGeneratorForMethod
+ {
+ public EqualsGenerator()
+ {
+ SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition<string>(x => x.Equals((string)null)) };
+ }
- public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
- {
- return treeBuilder.Like(
- visitor.Visit(targetObject).AsExpression(),
- treeBuilder.Concat(
- treeBuilder.Constant("%"),
- visitor.Visit(arguments[0]).AsExpression(),
- treeBuilder.Constant("%")));
- }
- }
+ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
+ {
+ return treeBuilder.Equality(
+ visitor.Visit(targetObject).AsExpression(),
+ visitor.Visit(arguments[0]).AsExpression());
+ }
+ }
- class EqualsGenerator : BaseHqlGeneratorForMethod
- {
- public EqualsGenerator()
- {
- SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition<string>(x => x.Equals((string)null)) };
- }
-
- public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
- {
- return treeBuilder.Equality(
- visitor.Visit(targetObject).AsExpression(),
- visitor.Visit(arguments[0]).AsExpression());
- }
- }
-
- class ToUpperLowerGenerator : BaseHqlGeneratorForMethod
- {
- public ToUpperLowerGenerator()
- {
- SupportedMethods = new[]
+ public class ToUpperLowerGenerator : BaseHqlGeneratorForMethod
+ {
+ public ToUpperLowerGenerator()
+ {
+ SupportedMethods = new[]
{
ReflectionHelper.GetMethodDefinition<string>(x => x.ToUpper()),
ReflectionHelper.GetMethodDefinition<string>(x => x.ToUpperInvariant()),
ReflectionHelper.GetMethodDefinition<string>(x => x.ToLower()),
ReflectionHelper.GetMethodDefinition<string>(x => x.ToLowerInvariant())
};
- }
+ }
- public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
- {
- string methodName;
+ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
+ {
+ string methodName;
- if (((method.Name == "ToUpper") || (method.Name == "ToUpperInvariant")))
- {
- methodName = "upper";
- }
- else
- {
- methodName = "lower";
- }
+ if (((method.Name == "ToUpper") || (method.Name == "ToUpperInvariant")))
+ {
+ methodName = "upper";
+ }
+ else
+ {
+ methodName = "lower";
+ }
- return treeBuilder.MethodCall(methodName, visitor.Visit(targetObject).AsExpression());
- }
- }
+ return treeBuilder.MethodCall(methodName, visitor.Visit(targetObject).AsExpression());
+ }
+ }
- class SubStringGenerator : BaseHqlGeneratorForMethod
- {
- public SubStringGenerator()
- {
- SupportedMethods = new[]
+ public class SubStringGenerator : BaseHqlGeneratorForMethod
+ {
+ public SubStringGenerator()
+ {
+ SupportedMethods = new[]
{
ReflectionHelper.GetMethodDefinition<string>(s => s.Substring(0)),
ReflectionHelper.GetMethodDefinition<string>(s => s.Substring(0, 0))
};
- }
- public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
- {
- if (arguments.Count == 1)
- {
- return treeBuilder.MethodCall("substring", visitor.Visit(targetObject).AsExpression(),
- treeBuilder.Constant(0),
- visitor.Visit(arguments[0]).AsExpression());
- }
-
- return treeBuilder.MethodCall("substring", visitor.Visit(targetObject).AsExpression(),
- visitor.Visit(arguments[0]).AsExpression(),
- visitor.Visit(arguments[1]).AsExpression());
- }
- }
+ }
+ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
+ {
+ if (arguments.Count == 1)
+ {
+ return treeBuilder.MethodCall("substring", visitor.Visit(targetObject).AsExpression(),
+ treeBuilder.Constant(0),
+ visitor.Visit(arguments[0]).AsExpression());
+ }
- class IndexOfGenerator : BaseHqlGeneratorForMethod
- {
- public IndexOfGenerator()
- {
- SupportedMethods = new[]
+ return treeBuilder.MethodCall("substring", visitor.Visit(targetObject).AsExpression(),
+ visitor.Visit(arguments[0]).AsExpression(),
+ visitor.Visit(arguments[1]).AsExpression());
+ }
+ }
+
+ public class IndexOfGenerator : BaseHqlGeneratorForMethod
+ {
+ public IndexOfGenerator()
+ {
+ SupportedMethods = new[]
{
ReflectionHelper.GetMethodDefinition<string>(s => s.IndexOf(' ')),
ReflectionHelper.GetMethodDefinition<string>(s => s.IndexOf(" ")),
ReflectionHelper.GetMethodDefinition<string>(s => s.IndexOf(' ', 0)),
ReflectionHelper.GetMethodDefinition<string>(s => s.IndexOf(" ", 0))
};
- }
- public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
- {
- if (arguments.Count == 1)
- {
- return treeBuilder.MethodCall("locate",
- visitor.Visit(arguments[0]).AsExpression(),
- visitor.Visit(targetObject).AsExpression(),
- treeBuilder.Constant(0));
- }
- return treeBuilder.MethodCall("locate",
- visitor.Visit(arguments[0]).AsExpression(),
- visitor.Visit(targetObject).AsExpression(),
- visitor.Visit(arguments[1]).AsExpression());
- }
- }
+ }
+ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
+ {
+ if (arguments.Count == 1)
+ {
+ return treeBuilder.MethodCall("locate",
+ visitor.Visit(arguments[0]).AsExpression(),
+ visitor.Visit(targetObject).AsExpression(),
+ treeBuilder.Constant(0));
+ }
+ return treeBuilder.MethodCall("locate",
+ visitor.Visit(arguments[0]).AsExpression(),
+ visitor.Visit(targetObject).AsExpression(),
+ visitor.Visit(arguments[1]).AsExpression());
+ }
+ }
- class ReplaceGenerator : BaseHqlGeneratorForMethod
- {
- public ReplaceGenerator()
- {
- SupportedMethods = new[]
+ public class ReplaceGenerator : BaseHqlGeneratorForMethod
+ {
+ public ReplaceGenerator()
+ {
+ SupportedMethods = new[]
{
ReflectionHelper.GetMethodDefinition<string>(s => s.Replace(' ', ' ')),
ReflectionHelper.GetMethodDefinition<string>(s => s.Replace("", ""))
};
- }
+ }
- public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
- {
- return treeBuilder.MethodCall("replace",
- visitor.Visit(targetObject).AsExpression(),
- visitor.Visit(arguments[0]).AsExpression(),
- visitor.Visit(arguments[1]).AsExpression());
- }
- }
- }
+ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
+ {
+ return treeBuilder.MethodCall("replace",
+ visitor.Visit(targetObject).AsExpression(),
+ visitor.Visit(arguments[0]).AsExpression(),
+ visitor.Visit(arguments[1]).AsExpression());
+ }
+ }
+
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-07-31 11:38:05 UTC (rev 5084)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-07-31 13:59:59 UTC (rev 5085)
@@ -655,6 +655,10 @@
<Compile Include="Linq\Expressions\AggregateExpressionNode.cs" />
<Compile Include="Linq\EagerFetchingExtensionMethods.cs" />
<Compile Include="Linq\Functions\ILinqToHqlGeneratorsRegistry.cs" />
+ <Compile Include="Linq\Functions\IRuntimeMethodHqlGenerator.cs">
+ <SubType>Code</SubType>
+ </Compile>
+ <Compile Include="Linq\Functions\LinqToHqlGeneratorsRegistryExtensions.cs" />
<Compile Include="Linq\Functions\LinqToHqlGeneratorsRegistryFactory.cs" />
<Compile Include="Linq\Functions\StandardLinqExtensionMethodGenerator.cs" />
<Compile Include="Linq\LinqExtensionMethodAttribute.cs" />
@@ -683,9 +687,7 @@
<Compile Include="Linq\Functions\IHqlGeneratorForMethod.cs" />
<Compile Include="Linq\Functions\IHqlGeneratorForProperty.cs" />
<Compile Include="Linq\Functions\BaseHqlGeneratorForMethod.cs" />
- <Compile Include="Linq\Functions\BaseHqlGeneratorForType.cs" />
- <Compile Include="Linq\Functions\IHqlGeneratorForType.cs" />
- <Compile Include="Linq\Functions\DateTimeGenerator.cs" />
+ <Compile Include="Linq\Functions\DateTimePropertiesHqlGenerator.cs" />
<Compile Include="Linq\Functions\StringGenerator.cs" />
<Compile Include="Linq\Functions\QueryableGenerator.cs" />
<Compile Include="Linq\ReWriters\RemoveUnnecessaryBodyOperators.cs" />
Modified: trunk/nhibernate/src/NHibernate.Test/Linq/LinqToHqlGeneratorsRegistryFactoryTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Linq/LinqToHqlGeneratorsRegistryFactoryTest.cs 2010-07-31 11:38:05 UTC (rev 5084)
+++ trunk/nhibernate/src/NHibernate.Test/Linq/LinqToHqlGeneratorsRegistryFactoryTest.cs 2010-07-31 13:59:59 UTC (rev 5085)
@@ -48,6 +48,11 @@
{
throw new NotImplementedException();
}
+
+ public void RegisterGenerator(IRuntimeMethodHqlGenerator generator)
+ {
+ throw new NotImplementedException();
+ }
}
}
}
\ 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-31 11:38:11
|
Revision: 5084
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5084&view=rev
Author: fabiomaulo
Date: 2010-07-31 11:38:05 +0000 (Sat, 31 Jul 2010)
Log Message:
-----------
Added extension to check if a method is declared by an interface.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Linq/EnumerableHelper.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/UtilityTest/ReflectionHelperIsMethodOfTests.cs
Modified: trunk/nhibernate/src/NHibernate/Linq/EnumerableHelper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/EnumerableHelper.cs 2010-07-31 08:30:17 UTC (rev 5083)
+++ trunk/nhibernate/src/NHibernate/Linq/EnumerableHelper.cs 2010-07-31 11:38:05 UTC (rev 5084)
@@ -55,6 +55,58 @@
}
return ((MemberExpression)property.Body).Member;
}
+
+ /// <summary>
+ /// Check if a method is declared in a given <see cref="System.Type"/>.
+ /// </summary>
+ /// <param name="source">The method to check.</param>
+ /// <param name="realDeclaringType">The where the method is really declared.</param>
+ /// <returns>True if the method is an implementation of the method declared in <paramref name="realDeclaringType"/>; false otherwise. </returns>
+ public static bool IsMethodOf(this MethodInfo source, System.Type realDeclaringType)
+ {
+ if (source == null)
+ {
+ throw new ArgumentNullException("source");
+ }
+ if (realDeclaringType == null)
+ {
+ throw new ArgumentNullException("realDeclaringType");
+ }
+ var methodDeclaringType = source.DeclaringType;
+ if(realDeclaringType.Equals(methodDeclaringType))
+ {
+ return true;
+ }
+ if (methodDeclaringType.IsGenericType && !methodDeclaringType.IsGenericTypeDefinition &&
+ realDeclaringType.Equals(methodDeclaringType.GetGenericTypeDefinition()))
+ {
+ return true;
+ }
+ if (realDeclaringType.IsInterface)
+ {
+ var declaringTypeInterfaces = methodDeclaringType.GetInterfaces();
+ if(declaringTypeInterfaces.Contains(realDeclaringType))
+ {
+ var methodsMap = methodDeclaringType.GetInterfaceMap(realDeclaringType);
+ if(methodsMap.TargetMethods.Contains(source))
+ {
+ return true;
+ }
+ }
+ if (realDeclaringType.IsGenericTypeDefinition)
+ {
+ bool implements = declaringTypeInterfaces
+ .Where(t => t.IsGenericType && t.GetGenericTypeDefinition().Equals(realDeclaringType))
+ .Select(implementedGenericInterface => methodDeclaringType.GetInterfaceMap(implementedGenericInterface))
+ .Any(methodsMap => methodsMap.TargetMethods.Contains(source));
+ if (implements)
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
}
// TODO rename / remove - reflection helper above is better
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-31 08:30:17 UTC (rev 5083)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-31 11:38:05 UTC (rev 5084)
@@ -440,6 +440,7 @@
<Compile Include="Linq\QueryCacheableTests.cs" />
<Compile Include="Linq\QueryReuseTests.cs" />
<Compile Include="Linq\ReadonlyTestCase.cs" />
+ <Compile Include="UtilityTest\ReflectionHelperIsMethodOfTests.cs" />
<Compile Include="UtilityTest\ReflectionHelperTest.cs" />
<Compile Include="Linq\RegresstionTests.cs" />
<Compile Include="Linq\SelectionTests.cs" />
Added: trunk/nhibernate/src/NHibernate.Test/UtilityTest/ReflectionHelperIsMethodOfTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/UtilityTest/ReflectionHelperIsMethodOfTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/UtilityTest/ReflectionHelperIsMethodOfTests.cs 2010-07-31 11:38:05 UTC (rev 5084)
@@ -0,0 +1,91 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using NHibernate.Linq;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.UtilityTest
+{
+ public class ReflectionHelperIsMethodOfTests
+ {
+ [Test]
+ public void WhenNullMethodInfoThenThrows()
+ {
+ ((MethodInfo) null).Executing(mi => mi.IsMethodOf(typeof (Object))).Throws<ArgumentNullException>();
+ }
+
+ [Test]
+ public void WhenNullTypeThenThrows()
+ {
+ ReflectionHelper.GetMethodDefinition<List<int>>(t => t.Contains(5)).Executing(mi => mi.IsMethodOf(null)).Throws<ArgumentNullException>();
+ }
+
+ [Test]
+ public void WhenDeclaringTypeMatchThenTrue()
+ {
+ ReflectionHelper.GetMethodDefinition<List<int>>(t => t.Contains(5)).IsMethodOf(typeof(List<int>)).Should().Be.True();
+ }
+
+ private class MyCollection: List<int>
+ {
+
+ }
+
+ [Test]
+ public void WhenCustomTypeMatchThenTrue()
+ {
+ ReflectionHelper.GetMethodDefinition<MyCollection>(t => t.Contains(5)).IsMethodOf(typeof(List<int>)).Should().Be.True();
+ }
+
+ [Test]
+ public void WhenTypeIsGenericDefinitionAndMatchThenTrue()
+ {
+ ReflectionHelper.GetMethodDefinition<List<int>>(t => t.Contains(5)).IsMethodOf(typeof(List<>)).Should().Be.True();
+ }
+
+ [Test]
+ public void WhenTypeIsGenericImplementedInterfaceAndMatchThenTrue()
+ {
+ var containsMethodDefinition = ReflectionHelper.GetMethodDefinition<List<int>>(t => t.Contains(5));
+ containsMethodDefinition.IsMethodOf(typeof(ICollection<int>)).Should().Be.True();
+ }
+
+ [Test]
+ public void WhenTypeIsGenericImplementedInterfaceAndMatchGenericInterfaceDefinitionThenTrue()
+ {
+ var containsMethodDefinition = ReflectionHelper.GetMethodDefinition<List<int>>(t => t.Contains(5));
+ containsMethodDefinition.IsMethodOf(typeof(ICollection<>)).Should().Be.True();
+ }
+
+ [Test]
+ public void WhenNoMatchThenFalse()
+ {
+ ReflectionHelper.GetMethodDefinition<List<int>>(t => t.Contains(5)).IsMethodOf(typeof(IEnumerable<>)).Should().Be.False();
+ }
+
+ private abstract class MyAbstractClass<T>
+ {
+ public abstract T MyMethod();
+ }
+
+ private class MyClass : MyAbstractClass<int>
+ {
+ public override int MyMethod() {return 0;}
+ }
+
+ [Test]
+ public void WhenTypeIsGenericImplementedAbstractAndMatchThenTrue()
+ {
+ var containsMethodDefinition = ReflectionHelper.GetMethodDefinition<MyClass>(t => t.MyMethod());
+ containsMethodDefinition.IsMethodOf(typeof(MyAbstractClass<int>)).Should().Be.True();
+ }
+
+ [Test]
+ public void WhenTypeIsGenericImplementedAbstractAndMatchGenericInterfaceDefinitionThenTrue()
+ {
+ var containsMethodDefinition = ReflectionHelper.GetMethodDefinition<MyClass>(t => t.MyMethod());
+ containsMethodDefinition.IsMethodOf(typeof(MyAbstractClass<>)).Should().Be.True();
+ }
+ }
+}
\ 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: <ric...@us...> - 2010-07-31 08:30:24
|
Revision: 5083
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5083&view=rev
Author: ricbrown
Date: 2010-07-31 08:30:17 +0000 (Sat, 31 Jul 2010)
Log Message:
-----------
Returned AbstractCriterion from LambdaRestrictionBuilder to allow operator overloading syntax.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Criterion/AbstractEmptinessExpression.cs
trunk/nhibernate/src/NHibernate/Criterion/Lambda/LambdaRestrictionBuilder.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Criterion/AbstractEmptinessExpression.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/AbstractEmptinessExpression.cs 2010-07-30 17:03:00 UTC (rev 5082)
+++ trunk/nhibernate/src/NHibernate/Criterion/AbstractEmptinessExpression.cs 2010-07-31 08:30:17 UTC (rev 5083)
@@ -10,7 +10,7 @@
namespace NHibernate.Criterion
{
[Serializable]
- public abstract class AbstractEmptinessExpression : ICriterion
+ public abstract class AbstractEmptinessExpression : AbstractCriterion
{
private readonly TypedValue[] NO_VALUES = new TypedValue[0];
private readonly string propertyName;
@@ -23,19 +23,17 @@
this.propertyName = propertyName;
}
- public TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery)
+ public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
return NO_VALUES;
}
- public abstract IProjection[] GetProjections();
-
public override sealed string ToString()
{
return propertyName + (ExcludeEmpty ? " is not empty" : " is empty");
}
- public SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
+ public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
{
string entityName = criteriaQuery.GetEntityName(criteria, propertyName);
string actualPropertyName = criteriaQuery.GetPropertyName(propertyName);
@@ -92,54 +90,5 @@
throw new QueryException("collection role not found: " + role, e);
}
}
-
- #region Operator Overloading
-
- public static AbstractCriterion operator &(AbstractEmptinessExpression lhs, AbstractEmptinessExpression rhs)
- {
- return new AndExpression(lhs, rhs);
- }
-
- public static AbstractCriterion operator |(AbstractEmptinessExpression lhs, AbstractEmptinessExpression rhs)
- {
- return new OrExpression(lhs, rhs);
- }
-
-
- public static AbstractCriterion operator &(AbstractEmptinessExpression lhs, AbstractCriterion rhs)
- {
- return new AndExpression(lhs, rhs);
- }
-
- public static AbstractCriterion operator |(AbstractEmptinessExpression lhs, AbstractCriterion rhs)
- {
- return new OrExpression(lhs, rhs);
- }
-
-
- public static AbstractCriterion operator !(AbstractEmptinessExpression crit)
- {
- return new NotExpression(crit);
- }
-
- /// <summary>
- /// See here for details:
- /// http://steve.emxsoftware.com/NET/Overloading+the++and++operators
- /// </summary>
- public static bool operator false(AbstractEmptinessExpression criteria)
- {
- return false;
- }
-
- /// <summary>
- /// See here for details:
- /// http://steve.emxsoftware.com/NET/Overloading+the++and++operators
- /// </summary>
- public static bool operator true(AbstractEmptinessExpression criteria)
- {
- return false;
- }
-
- #endregion
}
}
Modified: trunk/nhibernate/src/NHibernate/Criterion/Lambda/LambdaRestrictionBuilder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/Lambda/LambdaRestrictionBuilder.cs 2010-07-30 17:03:00 UTC (rev 5082)
+++ trunk/nhibernate/src/NHibernate/Criterion/Lambda/LambdaRestrictionBuilder.cs 2010-07-31 08:30:17 UTC (rev 5083)
@@ -37,7 +37,7 @@
private string propertyName;
private bool isNot;
- private ICriterion Process(ICriterion criterion)
+ private AbstractCriterion Process(AbstractCriterion criterion)
{
if (isNot)
return Restrictions.Not(criterion);
@@ -73,7 +73,7 @@
/// <summary>
/// Apply an "in" constraint to the named property
/// </summary>
- public ICriterion IsIn(ICollection values)
+ public AbstractCriterion IsIn(ICollection values)
{
return Process(Restrictions.In(propertyName, values));
}
@@ -81,7 +81,7 @@
/// <summary>
/// Apply an "in" constraint to the named property
/// </summary>
- public ICriterion IsIn(object[] values)
+ public AbstractCriterion IsIn(object[] values)
{
return Process(Restrictions.In(propertyName, values));
}
@@ -89,7 +89,7 @@
/// <summary>
/// Apply an "in" constraint to the named property
/// </summary>
- public ICriterion IsInG<T>(ICollection<T> values)
+ public AbstractCriterion IsInG<T>(ICollection<T> values)
{
return Process(Restrictions.InG(propertyName, values));
}
@@ -97,7 +97,7 @@
/// <summary>
/// A case-insensitive "like", similar to Postgres "ilike" operator
/// </summary>
- public ICriterion IsInsensitiveLike(object value)
+ public AbstractCriterion IsInsensitiveLike(object value)
{
return Process(Restrictions.InsensitiveLike(propertyName, value));
}
@@ -105,7 +105,7 @@
/// <summary>
/// A case-insensitive "like", similar to Postgres "ilike" operator
/// </summary>
- public ICriterion IsInsensitiveLike(string value, MatchMode matchMode)
+ public AbstractCriterion IsInsensitiveLike(string value, MatchMode matchMode)
{
return Process(Restrictions.InsensitiveLike(propertyName, value, matchMode));
}
@@ -113,7 +113,7 @@
/// <summary>
/// Apply an "is empty" constraint to the named property
/// </summary>
- public ICriterion IsEmpty
+ public AbstractCriterion IsEmpty
{
get { return Process(Restrictions.IsEmpty(propertyName)); }
}
@@ -121,7 +121,7 @@
/// <summary>
/// Apply a "not is empty" constraint to the named property
/// </summary>
- public ICriterion IsNotEmpty
+ public AbstractCriterion IsNotEmpty
{
get { return Process(Restrictions.IsNotEmpty(propertyName)); }
}
@@ -129,7 +129,7 @@
/// <summary>
/// Apply an "is null" constraint to the named property
/// </summary>
- public ICriterion IsNull
+ public AbstractCriterion IsNull
{
get { return Process(Restrictions.IsNull(propertyName)); }
}
@@ -137,7 +137,7 @@
/// <summary>
/// Apply an "not is null" constraint to the named property
/// </summary>
- public ICriterion IsNotNull
+ public AbstractCriterion IsNotNull
{
get { return Process(Restrictions.IsNotNull(propertyName)); }
}
@@ -145,7 +145,7 @@
/// <summary>
/// Apply a "like" constraint to the named property
/// </summary>
- public ICriterion IsLike(object value)
+ public AbstractCriterion IsLike(object value)
{
return Process(Restrictions.Like(propertyName, value));
}
@@ -153,7 +153,7 @@
/// <summary>
/// Apply a "like" constraint to the named property
/// </summary>
- public ICriterion IsLike(string value, MatchMode matchMode)
+ public AbstractCriterion IsLike(string value, MatchMode matchMode)
{
return Process(Restrictions.Like(propertyName, value, matchMode));
}
@@ -161,7 +161,7 @@
/// <summary>
/// Apply a "like" constraint to the named property
/// </summary>
- public ICriterion IsLike(string value, MatchMode matchMode, char? escapeChar)
+ public AbstractCriterion IsLike(string value, MatchMode matchMode, char? 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-30 17:03:00 UTC (rev 5082)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs 2010-07-31 08:30:17 UTC (rev 5083)
@@ -41,6 +41,7 @@
.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[] { "name4" }))
.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 }))
@@ -64,6 +65,7 @@
.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[] { "name4" }))
.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 }))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2010-07-30 17:03:06
|
Revision: 5082
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5082&view=rev
Author: fabiomaulo
Date: 2010-07-30 17:03:00 +0000 (Fri, 30 Jul 2010)
Log Message:
-----------
- ReflectionHelper tests
- Renamed methods (more representative because return generic definition)
- Added documentation for ReflectionHelper
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Linq/EnumerableHelper.cs
trunk/nhibernate/src/NHibernate/Linq/Functions/QueryableGenerator.cs
trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs
trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs
trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs
trunk/nhibernate/src/NHibernate/Linq/NhRelinqQueryParser.cs
trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessAggregate.cs
trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessFirst.cs
trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessSingle.cs
trunk/nhibernate/src/NHibernate.Test/Linq/CustomExtensionsExample.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/UtilityTest/ReflectionHelperTest.cs
Modified: trunk/nhibernate/src/NHibernate/Linq/EnumerableHelper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/EnumerableHelper.cs 2010-07-29 13:10:59 UTC (rev 5081)
+++ trunk/nhibernate/src/NHibernate/Linq/EnumerableHelper.cs 2010-07-30 17:03:00 UTC (rev 5082)
@@ -5,28 +5,58 @@
namespace NHibernate.Linq
{
- public static class ReflectionHelper
- {
- public delegate void Action();
+ public static class ReflectionHelper
+ {
+ /// <summary>
+ /// Extract the <see cref="MethodInfo"/> from a given expression.
+ /// </summary>
+ /// <typeparam name="TSource">The declaring-type of the method.</typeparam>
+ /// <param name="method">The method.</param>
+ /// <returns>The <see cref="MethodInfo"/> of the no-generic method or the generic-definition for a generic-method.</returns>
+ /// <seealso cref="MethodInfo.GetGenericMethodDefinition"/>
+ public static MethodInfo GetMethodDefinition<TSource>(Expression<Action<TSource>> method)
+ {
+ if (method == null)
+ {
+ throw new ArgumentNullException("method");
+ }
+ MethodInfo methodInfo = ((MethodCallExpression) method.Body).Method;
+ return methodInfo.IsGenericMethod ? methodInfo.GetGenericMethodDefinition() : methodInfo;
+ }
- public static MethodInfo GetMethod<TSource>(Expression<Action<TSource>> method)
- {
- var methodInfo = ((MethodCallExpression) method.Body).Method;
- return methodInfo.IsGenericMethod ? methodInfo.GetGenericMethodDefinition() : methodInfo;
- }
+ /// <summary>
+ /// Extract the <see cref="MethodInfo"/> from a given expression.
+ /// </summary>
+ /// <param name="method">The method.</param>
+ /// <returns>The <see cref="MethodInfo"/> of the no-generic method or the generic-definition for a generic-method.</returns>
+ /// <seealso cref="MethodInfo.GetGenericMethodDefinition"/>
+ public static MethodInfo GetMethodDefinition(Expression<System.Action> method)
+ {
+ if (method == null)
+ {
+ throw new ArgumentNullException("method");
+ }
+ var methodInfo = ((MethodCallExpression)method.Body).Method;
+ return methodInfo.IsGenericMethod ? methodInfo.GetGenericMethodDefinition() : methodInfo;
+ }
- public static MethodInfo GetMethod(Expression<Action> method)
- {
- var methodInfo = ((MethodCallExpression)method.Body).Method;
- return methodInfo.IsGenericMethod ? methodInfo.GetGenericMethodDefinition() : methodInfo;
- }
+ /// <summary>
+ /// Gets the field or property to be accessed.
+ /// </summary>
+ /// <typeparam name="TSource">The declaring-type of the property.</typeparam>
+ /// <typeparam name="TResult">The type of the property.</typeparam>
+ /// <param name="property">The expression representing the property getter.</param>
+ /// <returns>The <see cref="MemberInfo"/> of the property.</returns>
+ public static MemberInfo GetProperty<TSource, TResult>(Expression<Func<TSource, TResult>> property)
+ {
+ if (property == null)
+ {
+ throw new ArgumentNullException("property");
+ }
+ return ((MemberExpression)property.Body).Member;
+ }
+ }
- public static MemberInfo GetProperty<TSource, TResult>(Expression<Func<TSource, TResult>> property)
- {
- return ((MemberExpression) property.Body).Member;
- }
- }
-
// TODO rename / remove - reflection helper above is better
public static class EnumerableHelper
{
Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/QueryableGenerator.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/QueryableGenerator.cs 2010-07-29 13:10:59 UTC (rev 5081)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/QueryableGenerator.cs 2010-07-30 17:03:00 UTC (rev 5082)
@@ -26,10 +26,10 @@
{
SupportedMethods = new[]
{
- ReflectionHelper.GetMethod(() => Queryable.Any<object>(null)),
- ReflectionHelper.GetMethod(() => Queryable.Any<object>(null, null)),
- ReflectionHelper.GetMethod(() => Enumerable.Any<object>(null)),
- ReflectionHelper.GetMethod(() => Enumerable.Any<object>(null, null))
+ ReflectionHelper.GetMethodDefinition(() => Queryable.Any<object>(null)),
+ ReflectionHelper.GetMethodDefinition(() => Queryable.Any<object>(null, null)),
+ ReflectionHelper.GetMethodDefinition(() => Enumerable.Any<object>(null)),
+ ReflectionHelper.GetMethodDefinition(() => Enumerable.Any<object>(null, null))
};
}
@@ -65,8 +65,8 @@
{
SupportedMethods = new[]
{
- ReflectionHelper.GetMethod(() => Queryable.All<object>(null, null)),
- ReflectionHelper.GetMethod(() => Enumerable.All<object>(null, null))
+ ReflectionHelper.GetMethodDefinition(() => Queryable.All<object>(null, null)),
+ ReflectionHelper.GetMethodDefinition(() => Enumerable.All<object>(null, null))
};
}
@@ -100,8 +100,8 @@
{
SupportedMethods = new[]
{
- ReflectionHelper.GetMethod(() => Queryable.Min<object>(null)),
- ReflectionHelper.GetMethod(() => Enumerable.Min<object>(null))
+ ReflectionHelper.GetMethodDefinition(() => Queryable.Min<object>(null)),
+ ReflectionHelper.GetMethodDefinition(() => Enumerable.Min<object>(null))
};
}
@@ -117,8 +117,8 @@
{
SupportedMethods = new[]
{
- ReflectionHelper.GetMethod(() => Queryable.Max<object>(null)),
- ReflectionHelper.GetMethod(() => Enumerable.Max<object>(null))
+ ReflectionHelper.GetMethodDefinition(() => Queryable.Max<object>(null)),
+ ReflectionHelper.GetMethodDefinition(() => Enumerable.Max<object>(null))
};
}
Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs 2010-07-29 13:10:59 UTC (rev 5081)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs 2010-07-30 17:03:00 UTC (rev 5082)
@@ -1,4 +1,4 @@
-using System.Collections.ObjectModel;
+using System.Collections.ObjectModel;
using System.Linq.Expressions;
using System.Reflection;
using NHibernate.Hql.Ast;
@@ -40,7 +40,7 @@
{
public StartsWithGenerator()
{
- SupportedMethods = new[] { ReflectionHelper.GetMethod<string>(x => x.StartsWith(null)) };
+ SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition<string>(x => x.StartsWith(null)) };
}
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
@@ -57,7 +57,7 @@
{
public EndsWithGenerator()
{
- SupportedMethods = new[] { ReflectionHelper.GetMethod<string>(x => x.EndsWith(null)) };
+ SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition<string>(x => x.EndsWith(null)) };
}
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
@@ -74,7 +74,7 @@
{
public ContainsGenerator()
{
- SupportedMethods = new[] { ReflectionHelper.GetMethod<string>(x => x.Contains(null)) };
+ SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition<string>(x => x.Contains(null)) };
}
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
@@ -92,7 +92,7 @@
{
public EqualsGenerator()
{
- SupportedMethods = new[] { ReflectionHelper.GetMethod<string>(x => x.Equals((string)null)) };
+ SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition<string>(x => x.Equals((string)null)) };
}
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
@@ -109,10 +109,10 @@
{
SupportedMethods = new[]
{
- ReflectionHelper.GetMethod<string>(x => x.ToUpper()),
- ReflectionHelper.GetMethod<string>(x => x.ToUpperInvariant()),
- ReflectionHelper.GetMethod<string>(x => x.ToLower()),
- ReflectionHelper.GetMethod<string>(x => x.ToLowerInvariant())
+ ReflectionHelper.GetMethodDefinition<string>(x => x.ToUpper()),
+ ReflectionHelper.GetMethodDefinition<string>(x => x.ToUpperInvariant()),
+ ReflectionHelper.GetMethodDefinition<string>(x => x.ToLower()),
+ ReflectionHelper.GetMethodDefinition<string>(x => x.ToLowerInvariant())
};
}
@@ -139,8 +139,8 @@
{
SupportedMethods = new[]
{
- ReflectionHelper.GetMethod<string>(s => s.Substring(0)),
- ReflectionHelper.GetMethod<string>(s => s.Substring(0, 0))
+ ReflectionHelper.GetMethodDefinition<string>(s => s.Substring(0)),
+ ReflectionHelper.GetMethodDefinition<string>(s => s.Substring(0, 0))
};
}
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
@@ -164,10 +164,10 @@
{
SupportedMethods = new[]
{
- ReflectionHelper.GetMethod<string>(s => s.IndexOf(' ')),
- ReflectionHelper.GetMethod<string>(s => s.IndexOf(" ")),
- ReflectionHelper.GetMethod<string>(s => s.IndexOf(' ', 0)),
- ReflectionHelper.GetMethod<string>(s => s.IndexOf(" ", 0))
+ ReflectionHelper.GetMethodDefinition<string>(s => s.IndexOf(' ')),
+ ReflectionHelper.GetMethodDefinition<string>(s => s.IndexOf(" ")),
+ ReflectionHelper.GetMethodDefinition<string>(s => s.IndexOf(' ', 0)),
+ ReflectionHelper.GetMethodDefinition<string>(s => s.IndexOf(" ", 0))
};
}
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
@@ -192,8 +192,8 @@
{
SupportedMethods = new[]
{
- ReflectionHelper.GetMethod<string>(s => s.Replace(' ', ' ')),
- ReflectionHelper.GetMethod<string>(s => s.Replace("", ""))
+ ReflectionHelper.GetMethodDefinition<string>(s => s.Replace(' ', ' ')),
+ ReflectionHelper.GetMethodDefinition<string>(s => s.Replace("", ""))
};
}
Modified: trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs 2010-07-29 13:10:59 UTC (rev 5081)
+++ trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs 2010-07-30 17:03:00 UTC (rev 5082)
@@ -1,4 +1,4 @@
-using System.Linq;
+using System.Linq;
using System.Linq.Expressions;
namespace NHibernate.Linq
@@ -12,7 +12,7 @@
public static IQueryable<T> Cacheable<T>(this IQueryable<T> query)
{
- var method = ReflectionHelper.GetMethod(() => Cacheable<object>(null)).MakeGenericMethod(typeof(T));
+ var method = ReflectionHelper.GetMethodDefinition(() => Cacheable<object>(null)).MakeGenericMethod(typeof(T));
var callExpression = Expression.Call(method, query.Expression);
@@ -21,7 +21,7 @@
public static IQueryable<T> CacheMode<T>(this IQueryable<T> query, CacheMode cacheMode)
{
- var method = ReflectionHelper.GetMethod(() => CacheMode<object>(null, NHibernate.CacheMode.Normal)).MakeGenericMethod(typeof(T));
+ var method = ReflectionHelper.GetMethodDefinition(() => CacheMode<object>(null, NHibernate.CacheMode.Normal)).MakeGenericMethod(typeof(T));
var callExpression = Expression.Call(method, query.Expression, Expression.Constant(cacheMode));
@@ -30,7 +30,7 @@
public static IQueryable<T> CacheRegion<T>(this IQueryable<T> query, string region)
{
- var method = ReflectionHelper.GetMethod(() => CacheRegion<object>(null, null)).MakeGenericMethod(typeof(T));
+ var method = ReflectionHelper.GetMethodDefinition(() => CacheRegion<object>(null, null)).MakeGenericMethod(typeof(T));
var callExpression = Expression.Call(method, query.Expression, Expression.Constant(region));
Modified: trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs 2010-07-29 13:10:59 UTC (rev 5081)
+++ trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs 2010-07-30 17:03:00 UTC (rev 5082)
@@ -1,4 +1,4 @@
-using System.Collections;
+using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
@@ -57,7 +57,7 @@
public IQueryable CreateQuery(Expression expression)
{
- var m = ReflectionHelper.GetMethod((NhQueryProvider p) => p.CreateQuery<object>(null)).MakeGenericMethod(expression.Type.GetGenericArguments()[0]);
+ var m = ReflectionHelper.GetMethodDefinition((NhQueryProvider p) => p.CreateQuery<object>(null)).MakeGenericMethod(expression.Type.GetGenericArguments()[0]);
return (IQueryable) m.Invoke(this, new[] {expression});
}
Modified: trunk/nhibernate/src/NHibernate/Linq/NhRelinqQueryParser.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/NhRelinqQueryParser.cs 2010-07-29 13:10:59 UTC (rev 5081)
+++ trunk/nhibernate/src/NHibernate/Linq/NhRelinqQueryParser.cs 2010-07-30 17:03:00 UTC (rev 5082)
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
@@ -23,9 +23,9 @@
new[]
{
MethodCallExpressionNodeTypeRegistry.GetRegisterableMethodDefinition(
- ReflectionHelper.GetMethod(() => Queryable.Aggregate<object>(null, null))),
+ ReflectionHelper.GetMethodDefinition(() => Queryable.Aggregate<object>(null, null))),
MethodCallExpressionNodeTypeRegistry.GetRegisterableMethodDefinition(
- ReflectionHelper.GetMethod(() => Queryable.Aggregate<object, object>(null, null, null)))
+ ReflectionHelper.GetMethodDefinition(() => Queryable.Aggregate<object, object>(null, null, null)))
},
typeof (AggregateExpressionNode));
@@ -33,7 +33,7 @@
new[]
{
MethodCallExpressionNodeTypeRegistry.GetRegisterableMethodDefinition(
- ReflectionHelper.GetMethod((List<object> l) => l.Contains(null))),
+ ReflectionHelper.GetMethodDefinition((List<object> l) => l.Contains(null))),
},
typeof (ContainsExpressionNode));
Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessAggregate.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessAggregate.cs 2010-07-29 13:10:59 UTC (rev 5081)
+++ trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessAggregate.cs 2010-07-30 17:03:00 UTC (rev 5082)
@@ -1,4 +1,4 @@
-using System.Collections;
+using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
@@ -21,7 +21,7 @@
if (resultOperator.ParseInfo.ParsedExpression.Arguments.Count == 2)
{
- var aggregate = ReflectionHelper.GetMethod(() => Enumerable.Aggregate<object>(null, null));
+ var aggregate = ReflectionHelper.GetMethodDefinition(() => Enumerable.Aggregate<object>(null, null));
aggregate = aggregate.GetGenericMethodDefinition().MakeGenericMethod(inputType);
call = Expression.Call(
@@ -33,7 +33,7 @@
}
else if (resultOperator.ParseInfo.ParsedExpression.Arguments.Count == 3)
{
- var aggregate = ReflectionHelper.GetMethod(() => Enumerable.Aggregate<object, object>(null, null, null));
+ var aggregate = ReflectionHelper.GetMethodDefinition(() => Enumerable.Aggregate<object, object>(null, null, null));
aggregate = aggregate.GetGenericMethodDefinition().MakeGenericMethod(inputType, accumulatorType);
call = Expression.Call(
@@ -46,7 +46,7 @@
else
{
var selectorType = resultOperator.OptionalSelector.Type.GetGenericArguments()[2];
- var aggregate = ReflectionHelper.GetMethod(() => Enumerable.Aggregate<object, object, object>(null, null, null, null));
+ var aggregate = ReflectionHelper.GetMethodDefinition(() => Enumerable.Aggregate<object, object, object>(null, null, null, null));
aggregate = aggregate.GetGenericMethodDefinition().MakeGenericMethod(inputType, accumulatorType, selectorType);
call = Expression.Call(
Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessFirst.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessFirst.cs 2010-07-29 13:10:59 UTC (rev 5081)
+++ trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessFirst.cs 2010-07-30 17:03:00 UTC (rev 5082)
@@ -1,4 +1,4 @@
-using System.Linq;
+using System.Linq;
using Remotion.Data.Linq.Clauses.ResultOperators;
namespace NHibernate.Linq.Visitors.ResultOperatorProcessors
@@ -8,8 +8,8 @@
public void Process(FirstResultOperator resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
{
var firstMethod = resultOperator.ReturnDefaultWhenEmpty
- ? ReflectionHelper.GetMethod(() => Queryable.FirstOrDefault<object>(null))
- : ReflectionHelper.GetMethod(() => Queryable.First<object>(null));
+ ? ReflectionHelper.GetMethodDefinition(() => Queryable.FirstOrDefault<object>(null))
+ : ReflectionHelper.GetMethodDefinition(() => Queryable.First<object>(null));
AddClientSideEval(firstMethod, queryModelVisitor, tree);
Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessSingle.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessSingle.cs 2010-07-29 13:10:59 UTC (rev 5081)
+++ trunk/nhibernate/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessSingle.cs 2010-07-30 17:03:00 UTC (rev 5082)
@@ -1,4 +1,4 @@
-using System.Linq;
+using System.Linq;
using Remotion.Data.Linq.Clauses.ResultOperators;
namespace NHibernate.Linq.Visitors.ResultOperatorProcessors
@@ -8,8 +8,8 @@
public void Process(SingleResultOperator resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
{
var firstMethod = resultOperator.ReturnDefaultWhenEmpty
- ? ReflectionHelper.GetMethod(() => Queryable.SingleOrDefault<object>(null))
- : ReflectionHelper.GetMethod(() => Queryable.Single<object>(null));
+ ? ReflectionHelper.GetMethodDefinition(() => Queryable.SingleOrDefault<object>(null))
+ : ReflectionHelper.GetMethodDefinition(() => Queryable.Single<object>(null));
AddClientSideEval(firstMethod, queryModelVisitor, tree);
}
Modified: trunk/nhibernate/src/NHibernate.Test/Linq/CustomExtensionsExample.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Linq/CustomExtensionsExample.cs 2010-07-29 13:10:59 UTC (rev 5081)
+++ trunk/nhibernate/src/NHibernate.Test/Linq/CustomExtensionsExample.cs 2010-07-30 17:03:00 UTC (rev 5082)
@@ -29,7 +29,7 @@
{
public MyLinqToHqlGeneratorsRegistry():base()
{
- RegisterGenerator(ReflectionHelper.GetMethod(() => MyLinqExtensions.IsLike(null, null)),
+ RegisterGenerator(ReflectionHelper.GetMethodDefinition(() => MyLinqExtensions.IsLike(null, null)),
new IsLikeGenerator());
}
}
@@ -38,7 +38,7 @@
{
public IsLikeGenerator()
{
- SupportedMethods = new[] {ReflectionHelper.GetMethod(() => MyLinqExtensions.IsLike(null, null))};
+ SupportedMethods = new[] {ReflectionHelper.GetMethodDefinition(() => MyLinqExtensions.IsLike(null, null))};
}
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject,
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-29 13:10:59 UTC (rev 5081)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-30 17:03:00 UTC (rev 5082)
@@ -440,6 +440,7 @@
<Compile Include="Linq\QueryCacheableTests.cs" />
<Compile Include="Linq\QueryReuseTests.cs" />
<Compile Include="Linq\ReadonlyTestCase.cs" />
+ <Compile Include="UtilityTest\ReflectionHelperTest.cs" />
<Compile Include="Linq\RegresstionTests.cs" />
<Compile Include="Linq\SelectionTests.cs" />
<Compile Include="Linq\WhereSubqueryTests.cs" />
Added: trunk/nhibernate/src/NHibernate.Test/UtilityTest/ReflectionHelperTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/UtilityTest/ReflectionHelperTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/UtilityTest/ReflectionHelperTest.cs 2010-07-30 17:03:00 UTC (rev 5082)
@@ -0,0 +1,74 @@
+using System;
+using System.Linq;
+using System.Linq.Expressions;
+using NHibernate.Linq;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.UtilityTest
+{
+ public class ReflectionHelperTest
+ {
+ private class MyClass
+ {
+ public void NoGenericMethod() {}
+ public void GenericMethod<T>() { }
+ public string BaseProperty { get; set; }
+ public bool BaseBool { get; set; }
+ }
+
+ [Test]
+ public void WhenGetMethodForNullThenThrows()
+ {
+ Executing.This(() => ReflectionHelper.GetMethodDefinition((Expression<System.Action>) null)).Should().Throw<ArgumentNullException>();
+ }
+
+ [Test]
+ public void WhenGenericGetMethodForNullThenThrows()
+ {
+ Executing.This(() => ReflectionHelper.GetMethodDefinition<object>((Expression<System.Action<object>>)null)).Should().Throw<ArgumentNullException>();
+ }
+
+ [Test]
+ public void WhenGetPropertyForNullThenThrows()
+ {
+ Executing.This(() => ReflectionHelper.GetProperty<object, object>(null)).Should().Throw<ArgumentNullException>();
+ }
+
+ [Test]
+ public void WhenGenericMethodOfClassThenReturnGenericDefinition()
+ {
+ ReflectionHelper.GetMethodDefinition<MyClass>(mc => mc.GenericMethod<int>()).Should().Be(typeof (MyClass).GetMethod("GenericMethod").GetGenericMethodDefinition());
+ }
+
+ [Test]
+ public void WhenNoGenericMethodOfClassThenReturnDefinition()
+ {
+ ReflectionHelper.GetMethodDefinition<MyClass>(mc => mc.NoGenericMethod()).Should().Be(typeof(MyClass).GetMethod("NoGenericMethod"));
+ }
+
+ [Test]
+ public void WhenStaticGenericMethodThenReturnGenericDefinition()
+ {
+ ReflectionHelper.GetMethodDefinition(() => Enumerable.All<int>(null, null)).Should().Be(typeof(Enumerable).GetMethod("All").GetGenericMethodDefinition());
+ }
+
+ [Test]
+ public void WhenStaticNoGenericMethodThenReturnDefinition()
+ {
+ ReflectionHelper.GetMethodDefinition(() => string.Join(null, null)).Should().Be(typeof(string).GetMethod("Join", new []{typeof(string), typeof(string[])}));
+ }
+
+ [Test]
+ public void WhenGetPropertyThenReturnPropertyInfo()
+ {
+ ReflectionHelper.GetProperty<MyClass, string>(mc => mc.BaseProperty).Should().Be(typeof(MyClass).GetProperty("BaseProperty"));
+ }
+
+ [Test]
+ public void WhenGetPropertyForBoolThenReturnPropertyInfo()
+ {
+ ReflectionHelper.GetProperty<MyClass, bool>(mc => mc.BaseBool).Should().Be(typeof(MyClass).GetProperty("BaseBool"));
+ }
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|