|
From: <fab...@us...> - 2009-08-03 22:45:45
|
Revision: 4678
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4678&view=rev
Author: fabiomaulo
Date: 2009-08-03 22:45:29 +0000 (Mon, 03 Aug 2009)
Log Message:
-----------
Merge r4677 (Refactoring filter-def check first step)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs
trunk/nhibernate/src/NHibernate/Cfg/Mappings.cs
trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/FilterTest/defs.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Cfg/FilterSecondPassArgs.cs
trunk/nhibernate/src/NHibernate.Test/FilterTest/ConfigFixture.cs
trunk/nhibernate/src/NHibernate.Test/FilterTest/FilterSecondPassArgsFixture.cs
trunk/nhibernate/src/NHibernate.Test/FilterTest/SimpleFiltered.hbm.xml
trunk/nhibernate/src/NHibernate.Test/FilterTest/SimpleFilteredFiltersDefsOk.hbm.xml
trunk/nhibernate/src/NHibernate.Test/FilterTest/WrongFilterDefInClass.hbm.xml
Modified: trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2009-08-03 22:25:32 UTC (rev 4677)
+++ trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2009-08-03 22:45:29 UTC (rev 4678)
@@ -5,6 +5,7 @@
using System.Diagnostics;
using System.IO;
using System.Reflection;
+using System.Text;
using System.Xml;
using System.Xml.Schema;
using Iesi.Collections;
@@ -61,6 +62,7 @@
protected IDictionary<string, NHibernate.Mapping.Collection> collections;
protected IDictionary<string, Table> tables;
protected IList<SecondPassCommand> secondPasses;
+ protected Queue<FilterSecondPassArgs> filtersSecondPasses;
protected IList<Mappings.PropertyReference> propertyReferences;
private IInterceptor interceptor;
private IDictionary<string, string> properties;
@@ -113,6 +115,7 @@
tableNameBinding = GetSerialedObject<IDictionary<string, Mappings.TableDescription>>(info, "tableNameBinding");
tables = GetSerialedObject<IDictionary<string, Table>>(info, "tables");
typeDefs = GetSerialedObject<IDictionary<string, TypeDef>>(info, "typeDefs");
+ filtersSecondPasses = GetSerialedObject<Queue<FilterSecondPassArgs>>(info, "filtersSecondPasses");
}
private T GetSerialedObject<T>(SerializationInfo info, string name)
@@ -151,6 +154,7 @@
info.AddValue("tableNameBinding", tableNameBinding);
info.AddValue("tables", tables);
info.AddValue("typeDefs", typeDefs);
+ info.AddValue("filtersSecondPasses", filtersSecondPasses);
}
#endregion
@@ -179,7 +183,7 @@
extendsQueue = new HashedSet<ExtendsQueueEntry>();
tableNameBinding = new Dictionary<string, Mappings.TableDescription>();
columnNameBindingPerTable = new Dictionary<Table, Mappings.ColumnNames>();
-
+ filtersSecondPasses = new Queue<FilterSecondPassArgs>();
}
[Serializable]
private class Mapping : IMapping
@@ -520,7 +524,7 @@
{
ProcessPreMappingBuildProperties();
return new Mappings(classes, collections, tables, NamedQueries, NamedSQLQueries, SqlResultSetMappings, Imports,
- secondPasses, propertyReferences, namingStrategy, typeDefs, FilterDefinitions, extendsQueue,
+ secondPasses, filtersSecondPasses, propertyReferences, namingStrategy, typeDefs, FilterDefinitions, extendsQueue,
auxiliaryDatabaseObjects, tableNameBinding, columnNameBindingPerTable, defaultAssembly,
defaultNamespace, dialect);
}
@@ -904,6 +908,69 @@
private void Validate()
{
+ ValidateEntities();
+
+ ValidateCollections();
+
+ ValidateFilterDefs();
+ }
+
+ private void ValidateFilterDefs()
+ {
+ var filterNames = new HashedSet<string>();
+ foreach (var filterDefinition in FilterDefinitions)
+ {
+ if(filterDefinition.Value == null)
+ {
+ // a class/collection has a filter but the filter-def was not added.
+ filterNames.Add(filterDefinition.Key);
+ }
+ }
+ if(filterNames.Count > 0)
+ {
+ var message = new StringBuilder();
+ message.Append("filter-def for filter named ");
+ foreach (var filterName in filterNames)
+ {
+ message.AppendLine(filterName);
+ }
+ message.AppendLine("was not found.");
+ throw new MappingException(message.ToString());
+ }
+
+ // check filter-def without reference
+ if (FilterDefinitions.Count > 0)
+ {
+ filterNames.Clear();
+ var filterables = new JoinedEnumerable(ClassMappings, CollectionMappings);
+ foreach (IFilterable filterable in filterables)
+ {
+ filterNames.AddAll(filterable.FilterMap.Keys);
+ }
+ foreach (var filterName in FilterDefinitions.Keys)
+ {
+ if (!filterNames.Contains(filterName))
+ {
+ // if you are going to remove this exception at least add a log.Error
+ // because the usage of filter-def, outside its scope, may cause unexpected behaviour
+ // during queries.
+ throw new MappingException("filter-def for filter named '" + filterName
+ + "' was never used to filter classes nor collections.");
+ }
+ }
+ }
+ }
+
+ private void ValidateCollections()
+ {
+ foreach (var col in collections.Values)
+ {
+ col.Validate(mapping);
+ }
+ }
+
+ private void ValidateEntities()
+ {
bool validateProxy = PropertiesHelper.GetBoolean(Environment.UseProxyValidator, properties, true);
HashedSet<string> allProxyErrors = null;
IProxyValidator pvalidator = Environment.BytecodeProvider.ProxyFactoryFactory.ProxyValidator;
@@ -933,11 +1000,6 @@
{
throw new InvalidProxyTypeException(allProxyErrors);
}
-
- foreach (var col in collections.Values)
- {
- col.Validate(mapping);
- }
}
private static ICollection<string> ValidateProxyInterface(PersistentClass persistentClass, IProxyValidator validator)
@@ -1007,6 +1069,23 @@
{
SecondPassCompileForeignKeys(table, done);
}
+
+ log.Info("processing filters (second pass)");
+ foreach (var filterSecondPassArgs in filtersSecondPasses)
+ {
+ FilterDefinition filterDef;
+ var filterName = filterSecondPassArgs.FilterName;
+ FilterDefinitions.TryGetValue(filterName, out filterDef);
+ if(filterDef == null)
+ {
+ throw new MappingException("filter-def for filter named " + filterName + " was not found.");
+ }
+ if(string.IsNullOrEmpty(filterDef.DefaultFilterCondition))
+ {
+ throw new MappingException("no filter condition found for filter: " + filterName);
+ }
+ filterSecondPassArgs.Filterable.FilterMap[filterName] = filterDef.DefaultFilterCondition;
+ }
}
private void SecondPassCompileForeignKeys(Table table, ISet done)
@@ -2189,4 +2268,4 @@
}
-}
\ No newline at end of file
+}
Added: trunk/nhibernate/src/NHibernate/Cfg/FilterSecondPassArgs.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/FilterSecondPassArgs.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Cfg/FilterSecondPassArgs.cs 2009-08-03 22:45:29 UTC (rev 4678)
@@ -0,0 +1,28 @@
+using System;
+using NHibernate.Mapping;
+
+namespace NHibernate.Cfg
+{
+ [Serializable]
+ public class FilterSecondPassArgs
+ {
+ // this class is NH specific to solve problems generated by 'order of mapping-doc'
+ // to assign the condition of a filter.
+ public FilterSecondPassArgs(IFilterable filterable, string filterName)
+ {
+ if (filterable == null)
+ {
+ throw new ArgumentNullException("filterable");
+ }
+ if (string.IsNullOrEmpty(filterName))
+ {
+ throw new ArgumentNullException("filterName");
+ }
+ Filterable = filterable;
+ FilterName = filterName;
+ }
+
+ public IFilterable Filterable{ get; private set;}
+ public string FilterName { get; private set; }
+ }
+}
Modified: trunk/nhibernate/src/NHibernate/Cfg/Mappings.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Mappings.cs 2009-08-03 22:25:32 UTC (rev 4677)
+++ trunk/nhibernate/src/NHibernate/Cfg/Mappings.cs 2009-08-03 22:45:29 UTC (rev 4678)
@@ -69,6 +69,7 @@
private readonly IList<PropertyReference> propertyReferences;
private readonly IDictionary<string, FilterDefinition> filterDefinitions;
private readonly IList<IAuxiliaryDatabaseObject> auxiliaryDatabaseObjects;
+ private readonly Queue<FilterSecondPassArgs> filtersSecondPasses;
private readonly INamingStrategy namingStrategy;
@@ -98,6 +99,7 @@
IDictionary<string, ResultSetMappingDefinition> resultSetMappings,
IDictionary<string, string> imports,
IList<SecondPassCommand> secondPasses,
+ Queue<FilterSecondPassArgs> filtersSecondPasses,
IList<PropertyReference> propertyReferences,
INamingStrategy namingStrategy,
IDictionary<string, TypeDef> typeDefs,
@@ -108,7 +110,7 @@
IDictionary<Table, ColumnNames> columnNameBindingPerTable,
string defaultAssembly,
string defaultNamespace,
- Dialect.Dialect dialect)
+ Dialect.Dialect dialect)
{
this.classes = classes;
this.collections = collections;
@@ -129,6 +131,7 @@
this.defaultAssembly = defaultAssembly;
this.defaultNamespace = defaultNamespace;
this.dialect = dialect;
+ this.filtersSecondPasses = filtersSecondPasses;
}
/// <summary>
@@ -454,12 +457,22 @@
public void AddFilterDefinition(FilterDefinition definition)
{
- filterDefinitions.Add(definition.FilterName, definition);
+ FilterDefinition fd;
+ if (filterDefinitions.TryGetValue(definition.FilterName, out fd))
+ {
+ if(fd!=null)
+ {
+ throw new MappingException("Duplicated filter-def named: " + definition.FilterName);
+ }
+ }
+ filterDefinitions[definition.FilterName] = definition;
}
public FilterDefinition GetFilterDefinition(string name)
{
- return filterDefinitions[name];
+ FilterDefinition result;
+ filterDefinitions.TryGetValue(name, out result);
+ return result;
}
public void AddAuxiliaryDatabaseObject(IAuxiliaryDatabaseObject auxiliaryDatabaseObject)
@@ -638,6 +651,34 @@
return persistentClass;
}
+ public void ExpectedFilterDefinition(IFilterable filterable, string filterName, string condition)
+ {
+ var fdef = GetFilterDefinition(filterName);
+ if (string.IsNullOrEmpty(condition))
+ {
+ if (fdef != null)
+ {
+ // where immediately available, apply the condition
+ condition = fdef.DefaultFilterCondition;
+ }
+ }
+ if (string.IsNullOrEmpty(condition) && fdef == null)
+ {
+ log.Debug(string.Format("Adding filter second pass [{0}]", filterName));
+ filtersSecondPasses.Enqueue(new FilterSecondPassArgs(filterable, filterName));
+ }
+ else if (string.IsNullOrEmpty(condition) && fdef != null)
+ {
+ // Both sides does not have condition
+ throw new MappingException("no filter condition found for filter: " + filterName);
+ }
+
+ if (fdef == null)
+ {
+ // if not available add an expected filter definition
+ FilterDefinitions[filterName] = null;
+ }
+ }
}
public delegate void SecondPassCommand(IDictionary<string, PersistentClass> persistentClasses);
Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-08-03 22:25:32 UTC (rev 4677)
+++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-08-03 22:45:29 UTC (rev 4678)
@@ -1017,17 +1017,19 @@
condition = (propertyNameNode == null) ? null : propertyNameNode.Value;
}
- //TODO: bad implementation, cos it depends upon ordering of mapping doc
- // fixing this requires that Collection/PersistentClass gain access
- // to the Mappings reference from Configuration (or the filterDefinitions
- // map directly) sometime during Configuration.buildSessionFactory
- // (after all the types/filter-defs are known and before building
- // persisters).
if (StringHelper.IsEmpty(condition))
- condition = mappings.GetFilterDefinition(name).DefaultFilterCondition;
- if (condition == null)
- throw new MappingException("no filter condition found for filter: " + name);
- log.Debug("Applying filter [" + name + "] as [" + condition + "]");
+ {
+ var fdef = mappings.GetFilterDefinition(name);
+ if (fdef != null)
+ {
+ // where immediately available, apply the condition
+ condition = fdef.DefaultFilterCondition;
+ }
+ }
+
+ mappings.ExpectedFilterDefinition(filterable, name, condition);
+
+ log.Debug(string.Format("Applying filter [{0}] as [{1}]", name, condition));
filterable.AddFilter(name, condition);
}
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-08-03 22:25:32 UTC (rev 4677)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-08-03 22:45:29 UTC (rev 4678)
@@ -460,6 +460,7 @@
<Compile Include="Bytecode\UnableToLoadProxyFactoryFactoryException.cs" />
<Compile Include="Cache\FakeCache.cs" />
<Compile Include="Cfg\EntityCacheUsage.cs" />
+ <Compile Include="Cfg\FilterSecondPassArgs.cs" />
<Compile Include="Cfg\Hbm2ddlKeyWords.cs" />
<Compile Include="Cfg\Loquacious\CacheConfiguration.cs" />
<Compile Include="Cfg\Loquacious\ConfigurationExtensions.cs" />
Added: trunk/nhibernate/src/NHibernate.Test/FilterTest/ConfigFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/FilterTest/ConfigFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/FilterTest/ConfigFixture.cs 2009-08-03 22:45:29 UTC (rev 4678)
@@ -0,0 +1,244 @@
+using System.Collections.Generic;
+using NHibernate.Cfg;
+using NUnit.Framework;
+
+namespace NHibernate.Test.FilterTest
+{
+ [TestFixture]
+ public class ConfigFixture
+ {
+ private class ConfigurationStub: Configuration
+ {
+ public Queue<FilterSecondPassArgs> FiltersSecondPasses { get { return filtersSecondPasses; } }
+ }
+
+ private static ConfigurationStub GetConfiguration()
+ {
+ var result = new ConfigurationStub();
+ if (TestConfigurationHelper.hibernateConfigFile != null)
+ result.Configure(TestConfigurationHelper.hibernateConfigFile);
+ return result;
+ }
+
+ [Test]
+ [Description("Add a class with filters without condition should not Throw exceptions and add secondpass tasks.")]
+ public void AddClassWithFilters()
+ {
+ var cfg = GetConfiguration();
+ Assert.DoesNotThrow(() => cfg.AddResource("NHibernate.Test.FilterTest.SimpleFiltered.hbm.xml", GetType().Assembly));
+ Assert.That(cfg.FiltersSecondPasses.Count, Is.EqualTo(2));
+ }
+
+ [Test]
+ [Description("Add filters-def should change conditions of class filters")]
+ public void AddFilterDefToClassWithFilters()
+ {
+ var cfg = GetConfiguration();
+ cfg.AddResource("NHibernate.Test.FilterTest.SimpleFiltered.hbm.xml", GetType().Assembly);
+ cfg.AddResource("NHibernate.Test.FilterTest.SimpleFilteredFiltersDefsOk.hbm.xml", GetType().Assembly);
+ Assert.That(cfg.FilterDefinitions, Is.Not.Empty);
+ cfg.BuildMappings();
+ var pc = cfg.GetClassMapping(typeof (TestClass));
+ foreach (var filterMap in pc.FilterMap)
+ {
+ Assert.That(filterMap.Value, Is.Not.Null & Is.Not.Empty, "filtername:" + filterMap.Key);
+ }
+ }
+
+ [Test]
+ [Description("Filter def without condition in both sides should throw exception")]
+ public void WrongFilterDefInClass()
+ {
+ var cfg = GetConfiguration();
+ var e = Assert.Throws<MappingException>(() => cfg.AddResource("NHibernate.Test.FilterTest.WrongFilterDefInClass.hbm.xml", GetType().Assembly));
+ Assert.That(e.InnerException, Is.Not.Null);
+ Assert.That(e.InnerException.Message, Text.StartsWith("no filter condition").IgnoreCase);
+ }
+
+ [Test]
+ [Description("Filter def without condition in both sides should throw exception even in secondpass")]
+ public void WrongFilterDefInClassSeconPass()
+ {
+ const string wrongClassMap = @"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'
+ default-lazy='false'
+ assembly='NHibernate.Test'
+ namespace='NHibernate.Test.FilterTest' >
+
+ <class name='TestClass'>
+ <id name='Id' column='id'>
+ <generator class='assigned' />
+ </id>
+ <property name='Name'/>
+
+ <property name='Live'/>
+ <filter name='LiveFilter'/>
+ </class>
+
+</hibernate-mapping>";
+
+ const string wrongFilterDef = @"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2' >
+
+ <filter-def name='LiveFilter'>
+ <filter-param name='LiveParam' type='boolean'/>
+ </filter-def>
+
+</hibernate-mapping>";
+
+ var cfg = GetConfiguration();
+ cfg.AddXmlString(wrongClassMap);
+ cfg.AddXmlString(wrongFilterDef);
+ var e = Assert.Throws<MappingException>(cfg.BuildMappings);
+ Assert.That(e.Message, Text.StartsWith("no filter condition").IgnoreCase);
+ }
+
+ [Test]
+ [Description("Add a class with filters without condition should Throw exceptions at secondpass.")]
+ public void AddClassWithFiltersWithoutFilterDef()
+ {
+ var cfg = GetConfiguration();
+ cfg.AddResource("NHibernate.Test.FilterTest.SimpleFiltered.hbm.xml", GetType().Assembly);
+ var e = Assert.Throws<MappingException>(cfg.BuildMappings);
+ Assert.That(e.Message, Text.StartsWith("filter-def for filter named"));
+ Assert.That(e.Message, Text.Contains("was not found"));
+ }
+
+ [Test]
+ [Description("Class filter with condition does not add secondpass and add an invalid filter-def")]
+ public void ClassNoSecondPass()
+ {
+ const string classMap = @"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'
+ default-lazy='false'
+ assembly='NHibernate.Test'
+ namespace='NHibernate.Test.FilterTest' >
+
+ <class name='TestClass'>
+ <id name='Id' column='id'>
+ <generator class='assigned' />
+ </id>
+ <property name='Name'/>
+
+ <property name='Live'/>
+ <filter name='LiveFilter' condition=':LiveParam = Live'/>
+ </class>
+
+</hibernate-mapping>";
+
+ var cfg = GetConfiguration();
+ cfg.AddXmlString(classMap);
+ Assert.That(cfg.FiltersSecondPasses.Count, Is.EqualTo(0));
+ Assert.That(cfg.FilterDefinitions.Keys, Has.Member("LiveFilter"));
+ Assert.That(cfg.FilterDefinitions["LiveFilter"], Is.Null);
+ }
+
+ [Test]
+ [Description("Writing the condition in both sides should not change the condition defined in the class.")]
+ public void ClassConditionInBothSides()
+ {
+ const string classMap = @"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'
+ default-lazy='false'
+ assembly='NHibernate.Test'
+ namespace='NHibernate.Test.FilterTest' >
+
+ <class name='TestClass'>
+ <id name='Id' column='id'>
+ <generator class='assigned' />
+ </id>
+ <property name='Name'/>
+
+ <property name='Live'/>
+ <filter name='LiveFilter' condition='Live = 1'/>
+ </class>
+
+</hibernate-mapping>";
+
+ const string filterDef = @"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2' >
+
+ <filter-def name='LiveFilter' condition=':LiveParam = Live'>
+ <filter-param name='LiveParam' type='boolean'/>
+ </filter-def>
+
+</hibernate-mapping>";
+
+ var cfg = GetConfiguration();
+ cfg.AddXmlString(classMap);
+ cfg.AddXmlString(filterDef);
+ Assert.That(cfg.FiltersSecondPasses.Count, Is.EqualTo(0));
+ Assert.That(cfg.FilterDefinitions.Keys, Has.Member("LiveFilter"));
+ Assert.That(cfg.FilterDefinitions["LiveFilter"], Is.Not.Null);
+
+ cfg.BuildMappings();
+ Assert.That(cfg.FilterDefinitions.Count, Is.EqualTo(1));
+
+ var pc = cfg.GetClassMapping(typeof(TestClass));
+ Assert.That(pc.FilterMap["LiveFilter"], Is.EqualTo("Live = 1"));
+ }
+
+ [Test]
+ [Description("Filter-def duplication should Throw exception")]
+ public void DuplicatedFilterDef()
+ {
+ const string filterDef = @"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2' >
+
+ <filter-def name='LiveFilter'>
+ <filter-param name='LiveParam' type='boolean'/>
+ </filter-def>
+
+ <filter-def name='LiveFilter'>
+ <filter-param name='LiveParam' type='boolean'/>
+ </filter-def>
+
+</hibernate-mapping>";
+
+ var cfg = GetConfiguration();
+ var e = Assert.Throws<MappingException>(() => cfg.AddXmlString(filterDef));
+ Assert.That(e.InnerException, Is.Not.Null);
+ Assert.That(e.InnerException.Message, Text.Contains("Duplicated filter-def"));
+ }
+
+ [Test]
+ [Description("Add a filtered class with condition but without a filter-def should Throw exception")]
+ public void MissedFilterDef()
+ {
+ const string classMap = @"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'
+ default-lazy='false'
+ assembly='NHibernate.Test'
+ namespace='NHibernate.Test.FilterTest' >
+
+ <class name='TestClass'>
+ <id name='Id' column='id'>
+ <generator class='assigned' />
+ </id>
+ <property name='Name'/>
+
+ <property name='Live'/>
+ <filter name='LiveFilter' condition='Live = 1'/>
+ </class>
+
+</hibernate-mapping>";
+ var cfg = GetConfiguration();
+ cfg.AddXmlString(classMap);
+ var e = Assert.Throws<MappingException>(()=>cfg.BuildSessionFactory());
+ Assert.That(e.Message, Text.StartsWith("filter-def for filter named"));
+ Assert.That(e.Message, Text.Contains("was not found"));
+ }
+
+ [Test]
+ [Description("Filter-def without reference to it should Throw exception")]
+ public void FilterDefWithoutReference()
+ {
+ const string filterDef = @"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2' >
+
+ <filter-def name='LiveFilter'>
+ <filter-param name='LiveParam' type='boolean'/>
+ </filter-def>
+
+</hibernate-mapping>";
+
+ var cfg = GetConfiguration();
+ cfg.AddXmlString(filterDef);
+ var e = Assert.Throws<MappingException>(() => cfg.BuildSessionFactory());
+ Assert.That(e.Message, Text.StartsWith("filter-def for filter named"));
+ Assert.That(e.Message, Text.Contains("was never used to filter classes nor collections."));
+ }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/FilterTest/FilterSecondPassArgsFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/FilterTest/FilterSecondPassArgsFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/FilterTest/FilterSecondPassArgsFixture.cs 2009-08-03 22:45:29 UTC (rev 4678)
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using NHibernate.Mapping;
+using NUnit.Framework;
+using NHibernate.Cfg;
+
+namespace NHibernate.Test.FilterTest
+{
+ [TestFixture]
+ public class FilterSecondPassArgsFixture
+ {
+ public class FakeFilterable: IFilterable
+ {
+ public void AddFilter(string name, string condition)
+ {
+ throw new NotImplementedException();
+ }
+
+ public IDictionary<string, string> FilterMap
+ {
+ get { throw new NotImplementedException(); }
+ }
+ }
+ [Test]
+ public void CtorProtection()
+ {
+ Assert.Throws<ArgumentNullException>(() => new FilterSecondPassArgs(null, ""));
+ Assert.Throws<ArgumentNullException>(() => new FilterSecondPassArgs(null, "a>1"));
+ Assert.Throws<ArgumentNullException>(() => new FilterSecondPassArgs(new FakeFilterable(), null));
+ Assert.Throws<ArgumentNullException>(() => new FilterSecondPassArgs(new FakeFilterable(), ""));
+ Assert.DoesNotThrow(() => new FilterSecondPassArgs(new FakeFilterable(), "a>1"));
+ }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/FilterTest/SimpleFiltered.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/FilterTest/SimpleFiltered.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/FilterTest/SimpleFiltered.hbm.xml 2009-08-03 22:45:29 UTC (rev 4678)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ default-lazy="false"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.FilterTest" >
+
+ <class name="TestClass">
+ <id name="Id" column="id">
+ <generator class="assigned" />
+ </id>
+ <property name="Name"/>
+ <property name="Live" type="Boolean" />
+ <filter name="LiveFilter" />
+ <filter name="LiveFilter2" />
+ </class>
+
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/FilterTest/SimpleFilteredFiltersDefsOk.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/FilterTest/SimpleFilteredFiltersDefsOk.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/FilterTest/SimpleFilteredFiltersDefsOk.hbm.xml 2009-08-03 22:45:29 UTC (rev 4678)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
+
+ <filter-def name="LiveFilter" condition=":LiveParam = Live">
+ <filter-param name="LiveParam" type="boolean"/>
+ </filter-def>
+
+ <filter-def name="LiveFilter2">
+ <![CDATA[Name = :LiveParam2]]>
+ <filter-param name="LiveParam2" type="string"/>
+ </filter-def>
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/FilterTest/WrongFilterDefInClass.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/FilterTest/WrongFilterDefInClass.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/FilterTest/WrongFilterDefInClass.hbm.xml 2009-08-03 22:45:29 UTC (rev 4678)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ default-lazy="false"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.FilterTest" >
+
+ <class name="TestClass">
+ <id name="Id" column="id">
+ <generator class="assigned" />
+ </id>
+ <property name="Name" type="StringClob" length="100000" />
+
+ <property name="Live" type="Boolean" />
+ <filter name="LiveFilter"/>
+ </class>
+
+ <filter-def name="LiveFilter">
+ <filter-param name="LiveParam" type="boolean"/>
+ </filter-def>
+
+</hibernate-mapping>
Modified: trunk/nhibernate/src/NHibernate.Test/FilterTest/defs.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/FilterTest/defs.hbm.xml 2009-08-03 22:25:32 UTC (rev 4677)
+++ trunk/nhibernate/src/NHibernate.Test/FilterTest/defs.hbm.xml 2009-08-03 22:45:29 UTC (rev 4678)
@@ -19,8 +19,4 @@
<filter-def name="seniorSalespersons">
<filter-param name="asOfDate" type="DateTime"/>
</filter-def>
-
- <filter-def name="cat">
- <filter-param name="catId" type="long"/>
- </filter-def>
</hibernate-mapping>
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-08-03 22:25:32 UTC (rev 4677)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-08-03 22:45:29 UTC (rev 4678)
@@ -271,10 +271,12 @@
<Compile Include="Extralazy\User.cs" />
<Compile Include="FilterTest\BinaryFiltered.cs" />
<Compile Include="FilterTest\Category.cs" />
+ <Compile Include="FilterTest\ConfigFixture.cs" />
<Compile Include="FilterTest\Department.cs" />
<Compile Include="FilterTest\DynamicFilterTest.cs" />
<Compile Include="FilterTest\FilterBinaryParameterTest.cs" />
<Compile Include="FilterTest\FilterConfig.cs" />
+ <Compile Include="FilterTest\FilterSecondPassArgsFixture.cs" />
<Compile Include="FilterTest\LineItem.cs" />
<Compile Include="FilterTest\Order.cs" />
<Compile Include="FilterTest\Product.cs" />
@@ -1969,6 +1971,9 @@
<EmbeddedResource Include="Criteria\Lambda\Mappings.hbm.xml" />
<EmbeddedResource Include="CfgTest\Loquacious\EntityToCache.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="FilterTest\SimpleFiltered.hbm.xml" />
+ <EmbeddedResource Include="FilterTest\SimpleFilteredFiltersDefsOk.hbm.xml" />
+ <EmbeddedResource Include="FilterTest\WrongFilterDefInClass.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1898\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1907\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1899\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|