|
From: <fab...@us...> - 2010-07-28 20:40:46
|
Revision: 5071
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5071&view=rev
Author: fabiomaulo
Date: 2010-07-28 20:40:40 +0000 (Wed, 28 Jul 2010)
Log Message:
-----------
Added LinqToHqlGeneratorsRegistryFactory to create Generators Registry from configuration properties and through ObjectsFactory
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/Environment.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Linq/Functions/LinqToHqlGeneratorsRegistryFactory.cs
trunk/nhibernate/src/NHibernate.Test/Linq/LinqToHqlGeneratorsRegistryFactoryTest.cs
Modified: trunk/nhibernate/src/NHibernate/Cfg/Environment.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Environment.cs 2010-07-28 20:11:31 UTC (rev 5070)
+++ trunk/nhibernate/src/NHibernate/Cfg/Environment.cs 2010-07-28 20:40:40 UTC (rev 5071)
@@ -159,6 +159,8 @@
public const string DefaultBatchFetchSize = "default_batch_fetch_size";
public const string CollectionTypeFactoryClass = "collectiontype.factory_class";
+
+ public const string LinqToHqlGeneratorsRegistry = "linqtohql.generatorsregistry";
private static readonly Dictionary<string, string> GlobalProperties;
Added: trunk/nhibernate/src/NHibernate/Linq/Functions/LinqToHqlGeneratorsRegistryFactory.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/LinqToHqlGeneratorsRegistryFactory.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/LinqToHqlGeneratorsRegistryFactory.cs 2010-07-28 20:40:40 UTC (rev 5071)
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using log4net;
+using NHibernate.Util;
+using Environment = NHibernate.Cfg.Environment;
+
+namespace NHibernate.Linq.Functions
+{
+ public sealed class LinqToHqlGeneratorsRegistryFactory
+ {
+ private static readonly ILog log = LogManager.GetLogger(typeof (LinqToHqlGeneratorsRegistryFactory));
+
+ public static ILinqToHqlGeneratorsRegistry CreateGeneratorsRegistry(IDictionary<string, string> properties)
+ {
+ string registry;
+ if (properties.TryGetValue(Environment.LinqToHqlGeneratorsRegistry, out registry))
+ {
+ try
+ {
+ log.Info("Initializing LinqToHqlGeneratorsRegistry: " + registry);
+ return (ILinqToHqlGeneratorsRegistry) Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(registry));
+ }
+ catch (Exception e)
+ {
+ log.Fatal("Could not instantiate LinqToHqlGeneratorsRegistry", e);
+ throw new HibernateException("Could not instantiate LinqToHqlGeneratorsRegistry: " + registry, e);
+ }
+ }
+ return new FunctionRegistry();
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-07-28 20:11:31 UTC (rev 5070)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-07-28 20:40:40 UTC (rev 5071)
@@ -655,6 +655,7 @@
<Compile Include="Linq\Expressions\AggregateExpressionNode.cs" />
<Compile Include="Linq\EagerFetchingExtensionMethods.cs" />
<Compile Include="Linq\Functions\ILinqToHqlGeneratorsRegistry.cs" />
+ <Compile Include="Linq\Functions\LinqToHqlGeneratorsRegistryFactory.cs" />
<Compile Include="Linq\LinqExtensionMethodAttribute.cs" />
<Compile Include="Linq\TypeHelperExtensionMethods.cs" />
<Compile Include="Linq\Visitors\NameUnNamedParameters.cs" />
Added: trunk/nhibernate/src/NHibernate.Test/Linq/LinqToHqlGeneratorsRegistryFactoryTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Linq/LinqToHqlGeneratorsRegistryFactoryTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/Linq/LinqToHqlGeneratorsRegistryFactoryTest.cs 2010-07-28 20:40:40 UTC (rev 5071)
@@ -0,0 +1,53 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using NHibernate.Linq.Functions;
+using NUnit.Framework;
+using SharpTestsEx;
+using Environment = NHibernate.Cfg.Environment;
+
+namespace NHibernate.Test.Linq
+{
+ public class LinqToHqlGeneratorsRegistryFactoryTest
+ {
+ [Test]
+ public void WhenNotDefinedThenReturnDefaultRegistry()
+ {
+ var registry = LinqToHqlGeneratorsRegistryFactory.CreateGeneratorsRegistry(new Dictionary<string, string>());
+ registry.Should().Not.Be.Null();
+ registry.Should().Be.OfType<FunctionRegistry>();
+ }
+
+ [Test]
+ public void WhenDefinedThenReturnCustomtRegistry()
+ {
+ var properties = new Dictionary<string, string> { { Environment.LinqToHqlGeneratorsRegistry, typeof(MyLinqToHqlGeneratorsRegistry).AssemblyQualifiedName } };
+ var registry = LinqToHqlGeneratorsRegistryFactory.CreateGeneratorsRegistry(properties);
+ registry.Should().Not.Be.Null();
+ registry.Should().Be.OfType<MyLinqToHqlGeneratorsRegistry>();
+ }
+
+ private class MyLinqToHqlGeneratorsRegistry : ILinqToHqlGeneratorsRegistry
+ {
+ public bool TryGetGenerator(MethodInfo method, out IHqlGeneratorForMethod generator)
+ {
+ throw new NotImplementedException();
+ }
+
+ public bool TryGetGenerator(MemberInfo property, out IHqlGeneratorForProperty generator)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void RegisterGenerator(MethodInfo method, IHqlGeneratorForMethod generator)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void RegisterGenerator(MemberInfo property, IHqlGeneratorForProperty generator)
+ {
+ throw new NotImplementedException();
+ }
+ }
+ }
+}
\ 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-28 20:11:31 UTC (rev 5070)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-28 20:40:40 UTC (rev 5071)
@@ -425,6 +425,7 @@
<Compile Include="Linq\LinqQuerySamples.cs" />
<Compile Include="Linq\LinqReadonlyTestsContext.cs" />
<Compile Include="Linq\LinqTestCase.cs" />
+ <Compile Include="Linq\LinqToHqlGeneratorsRegistryFactoryTest.cs" />
<Compile Include="Linq\MethodCallTests.cs" />
<Compile Include="Linq\MiscellaneousTextFixture.cs" />
<Compile Include="Linq\NorthwindDbCreator.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|