From: <fab...@us...> - 2009-08-03 22:25:40
|
Revision: 4677 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4677&view=rev Author: fabiomaulo Date: 2009-08-03 22:25:32 +0000 (Mon, 03 Aug 2009) Log Message: ----------- Refactoring filter-def check first step (removed a very old TODO and removed the problem of filter-def mappings inspection order) Modified Paths: -------------- branches/2.1.x/nhibernate/src/NHibernate/Cfg/Configuration.cs branches/2.1.x/nhibernate/src/NHibernate/Cfg/Mappings.cs branches/2.1.x/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs branches/2.1.x/nhibernate/src/NHibernate/NHibernate.csproj branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/defs.hbm.xml branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- branches/2.1.x/nhibernate/src/NHibernate/Cfg/FilterSecondPassArgs.cs branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/ConfigFixture.cs branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/FilterSecondPassArgsFixture.cs branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/SimpleFiltered.hbm.xml branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/SimpleFilteredFiltersDefsOk.hbm.xml branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/WrongFilterDefInClass.hbm.xml Modified: branches/2.1.x/nhibernate/src/NHibernate/Cfg/Configuration.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/Cfg/Configuration.cs 2009-08-02 22:35:41 UTC (rev 4676) +++ branches/2.1.x/nhibernate/src/NHibernate/Cfg/Configuration.cs 2009-08-03 22:25:32 UTC (rev 4677) @@ -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,12 +115,7 @@ this.tableNameBinding = GetSerialedObject<IDictionary<string, Mappings.TableDescription>>(info, "tableNameBinding"); this.tables = GetSerialedObject<IDictionary<string, Table>>(info, "tables"); this.typeDefs = GetSerialedObject<IDictionary<string, TypeDef>>(info, "typeDefs"); - - - - - - + filtersSecondPasses = GetSerialedObject<Queue<FilterSecondPassArgs>>(info, "filtersSecondPasses"); } private T GetSerialedObject<T>(SerializationInfo info, string name) { @@ -157,6 +154,7 @@ info.AddValue("tableNameBinding", this.tableNameBinding); info.AddValue("tables", this.tables); info.AddValue("typeDefs", this.typeDefs); + info.AddValue("filtersSecondPasses", filtersSecondPasses); } #endregion @@ -185,8 +183,9 @@ 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 { @@ -526,7 +525,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); } @@ -910,6 +909,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; @@ -917,7 +979,7 @@ foreach (var clazz in classes.Values) { clazz.Validate(mapping); - + if (validateProxy) { ICollection<string> errors = ValidateProxyInterface(clazz, pvalidator); @@ -939,11 +1001,6 @@ { throw new InvalidProxyTypeException(allProxyErrors); } - - foreach (var col in collections.Values) - { - col.Validate(mapping); - } } private static ICollection<string> ValidateProxyInterface(PersistentClass persistentClass, IProxyValidator validator) @@ -1013,6 +1070,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) Added: branches/2.1.x/nhibernate/src/NHibernate/Cfg/FilterSecondPassArgs.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/Cfg/FilterSecondPassArgs.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate/Cfg/FilterSecondPassArgs.cs 2009-08-03 22:25:32 UTC (rev 4677) @@ -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; } + } +} \ No newline at end of file Modified: branches/2.1.x/nhibernate/src/NHibernate/Cfg/Mappings.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/Cfg/Mappings.cs 2009-08-02 22:35:41 UTC (rev 4676) +++ branches/2.1.x/nhibernate/src/NHibernate/Cfg/Mappings.cs 2009-08-03 22:25:32 UTC (rev 4677) @@ -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: branches/2.1.x/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-08-02 22:35:41 UTC (rev 4676) +++ branches/2.1.x/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-08-03 22:25:32 UTC (rev 4677) @@ -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: branches/2.1.x/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/NHibernate.csproj 2009-08-02 22:35:41 UTC (rev 4676) +++ branches/2.1.x/nhibernate/src/NHibernate/NHibernate.csproj 2009-08-03 22:25:32 UTC (rev 4677) @@ -456,6 +456,7 @@ <Compile Include="Bytecode\ProxyFactoryFactoryNotConfiguredException.cs" /> <Compile Include="Bytecode\UnableToLoadProxyFactoryFactoryException.cs" /> <Compile Include="Cache\FakeCache.cs" /> + <Compile Include="Cfg\FilterSecondPassArgs.cs" /> <Compile Include="Cfg\MappingSchema\AbstractDecoratable.cs" /> <Compile Include="Cfg\MappingSchema\HbmTimestamp.cs" /> <Compile Include="Cfg\MappingSchema\HbmVersion.cs" /> Added: branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/ConfigFixture.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/ConfigFixture.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/ConfigFixture.cs 2009-08-03 22:25:32 UTC (rev 4677) @@ -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.")); + } + } +} \ No newline at end of file Added: branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/FilterSecondPassArgsFixture.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/FilterSecondPassArgsFixture.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/FilterSecondPassArgsFixture.cs 2009-08-03 22:25:32 UTC (rev 4677) @@ -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")); + } + } +} \ No newline at end of file Added: branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/SimpleFiltered.hbm.xml =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/SimpleFiltered.hbm.xml (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/SimpleFiltered.hbm.xml 2009-08-03 22:25:32 UTC (rev 4677) @@ -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> \ No newline at end of file Added: branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/SimpleFilteredFiltersDefsOk.hbm.xml =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/SimpleFilteredFiltersDefsOk.hbm.xml (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/SimpleFilteredFiltersDefsOk.hbm.xml 2009-08-03 22:25:32 UTC (rev 4677) @@ -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> \ No newline at end of file Added: branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/WrongFilterDefInClass.hbm.xml =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/WrongFilterDefInClass.hbm.xml (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/WrongFilterDefInClass.hbm.xml 2009-08-03 22:25:32 UTC (rev 4677) @@ -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> \ No newline at end of file Modified: branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/defs.hbm.xml =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/defs.hbm.xml 2009-08-02 22:35:41 UTC (rev 4676) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/FilterTest/defs.hbm.xml 2009-08-03 22:25:32 UTC (rev 4677) @@ -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: branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-08-02 22:35:41 UTC (rev 4676) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-08-03 22:25:32 UTC (rev 4677) @@ -105,6 +105,8 @@ <Compile Include="CfgTest\ConfigurationSchemaFixture.cs" /> <Compile Include="CfgTest\ConfigurationSerializationTests.cs" /> <Compile Include="CfgTest\DefaultNsAssmFixture.cs" /> + <Compile Include="FilterTest\ConfigFixture.cs" /> + <Compile Include="FilterTest\FilterSecondPassArgsFixture.cs" /> <Compile Include="CfgTest\HbmBinderFixture.cs" /> <Compile Include="CfgTest\HbmOrderingFixture.cs" /> <Compile Include="CfgTest\LocatedInTestAssembly.cs" /> @@ -1954,6 +1956,9 @@ <EmbeddedResource Include="Bytecode\Lightweight\ProductLine.hbm.xml" /> <EmbeddedResource Include="DriverTest\MultiTypeEntity.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="FilterTest\WrongFilterDefInClass.hbm.xml" /> + <EmbeddedResource Include="FilterTest\SimpleFiltered.hbm.xml" /> + <EmbeddedResource Include="FilterTest\SimpleFilteredFiltersDefsOk.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. |