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: <aye...@us...> - 2010-01-06 22:12:03
|
Revision: 4912 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4912&view=rev Author: ayenderahien Date: 2010-01-06 22:11:57 +0000 (Wed, 06 Jan 2010) Log Message: ----------- Changing throwing indexer to TryGetValue Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs Modified: trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs 2010-01-06 21:41:19 UTC (rev 4911) +++ trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs 2010-01-06 22:11:57 UTC (rev 4912) @@ -465,14 +465,10 @@ public IEntityPersister GetEntityPersister(string entityName) { - try - { - return entityPersisters[entityName]; - } - catch (KeyNotFoundException) - { - throw new MappingException("No persister for: " + entityName); - } + IEntityPersister value; + if (entityPersisters.TryGetValue(entityName, out value) == false) + throw new MappingException("No persister for: " + entityName); + return value; } public IEntityPersister TryGetEntityPersister(string entityName) @@ -484,14 +480,10 @@ public ICollectionPersister GetCollectionPersister(string role) { - try - { - return collectionPersisters[role]; - } - catch (KeyNotFoundException) - { + ICollectionPersister value; + if(collectionPersisters.TryGetValue(role, out value) == false) throw new MappingException("Unknown collection role: " + role); - } + return value; } public ISet<string> GetCollectionRolesByEntityParticipant(string entityName) @@ -979,14 +971,10 @@ public FilterDefinition GetFilterDefinition(string filterName) { - try - { - return filters[filterName]; - } - catch (KeyNotFoundException) - { + FilterDefinition value; + if(filters.TryGetValue(filterName,out value)==false) throw new HibernateException("No such filter configured [" + filterName + "]"); - } + return value; } public ICollection<string> DefinedFilterNames This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aye...@us...> - 2010-01-06 21:41:25
|
Revision: 4911 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4911&view=rev Author: ayenderahien Date: 2010-01-06 21:41:19 +0000 (Wed, 06 Jan 2010) Log Message: ----------- Adding default ctors - per NH-2021 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/ADOException.cs trunk/nhibernate/src/NHibernate/Exceptions/GenericADOException.cs Modified: trunk/nhibernate/src/NHibernate/ADOException.cs =================================================================== --- trunk/nhibernate/src/NHibernate/ADOException.cs 2010-01-06 21:39:25 UTC (rev 4910) +++ trunk/nhibernate/src/NHibernate/ADOException.cs 2010-01-06 21:41:19 UTC (rev 4911) @@ -17,6 +17,10 @@ { private readonly string sql; + public ADOException() + { + + } /// <summary> /// Initializes a new instance of the <see cref="ADOException"/> class. /// </summary> Modified: trunk/nhibernate/src/NHibernate/Exceptions/GenericADOException.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Exceptions/GenericADOException.cs 2010-01-06 21:39:25 UTC (rev 4910) +++ trunk/nhibernate/src/NHibernate/Exceptions/GenericADOException.cs 2010-01-06 21:41:19 UTC (rev 4911) @@ -7,6 +7,10 @@ [Serializable] public class GenericADOException : ADOException { + public GenericADOException() + { + + } public GenericADOException(SerializationInfo info, StreamingContext context) : base(info, context) { } public GenericADOException(string message, Exception innerException, string sql) : base(message, innerException, sql) { } public GenericADOException(string message, Exception innerException) : base(message, innerException) { } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aye...@us...> - 2010-01-06 21:39:32
|
Revision: 4910 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4910&view=rev Author: ayenderahien Date: 2010-01-06 21:39:25 +0000 (Wed, 06 Jan 2010) Log Message: ----------- Fixing NH 2044 & NH 2045 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Type/AbstractCharType.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2044/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2044/DomainClass.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2044/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2044/SampleTest.cs Modified: trunk/nhibernate/src/NHibernate/Type/AbstractCharType.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/AbstractCharType.cs 2010-01-06 21:35:19 UTC (rev 4909) +++ trunk/nhibernate/src/NHibernate/Type/AbstractCharType.cs 2010-01-06 21:39:25 UTC (rev 4910) @@ -48,7 +48,7 @@ public override void Set(IDbCommand cmd, object value, int index) { - ((IDataParameter)cmd.Parameters[index]).Value = (char)value; + ((IDataParameter)cmd.Parameters[index]).Value = Convert.ToChar(value); } public override string ObjectToSQLString(object value, Dialect.Dialect dialect) Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2044 ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2044/DomainClass.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2044/DomainClass.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2044/DomainClass.cs 2010-01-06 21:39:25 UTC (rev 4910) @@ -0,0 +1,22 @@ + + +namespace NHibernate.Test.NHSpecificTest.NH2044 +{ + public class DomainClass + { + private char symbol; + private int id; + + public int Id + { + get { return id; } + set { id = value; } + } + + public char Symbol + { + get { return symbol; } + set { symbol = value; } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2044/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2044/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2044/Mappings.hbm.xml 2010-01-06 21:39:25 UTC (rev 4910) @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2044" default-access="field.camelcase" + default-lazy="false"> + <class name="DomainClass"> + <id name="Id"> + <generator class="assigned" /> + </id> + <property name="Symbol" type="Char"/> + </class> +</hibernate-mapping> \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2044/SampleTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2044/SampleTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2044/SampleTest.cs 2010-01-06 21:39:25 UTC (rev 4910) @@ -0,0 +1,52 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using NHibernate.Dialect; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2044 +{ + [TestFixture] + public class SampleTest : BugTestCase + { + protected override void OnSetUp() + { + base.OnSetUp(); + using (ISession session = this.OpenSession()) + { + DomainClass entity = new DomainClass(); + entity.Id = 1; + entity.Symbol = 'S'; + session.Save(entity); + session.Flush(); + } + } + + protected override void OnTearDown() + { + base.OnTearDown(); + using (ISession session = this.OpenSession()) + { + string hql = "from DomainClass"; + session.Delete(hql); + session.Flush(); + } + } + + + [Test] + public void IgnoreCaseShouldWorkWithCharCorrectly() + { + using (ISession session = this.OpenSession()) + { + ICriteria criteria = session.CreateCriteria(typeof(DomainClass), "domain"); + criteria.Add(NHibernate.Criterion.Expression.Eq("Symbol", 's').IgnoreCase()); + IList<DomainClass> list = criteria.List<DomainClass>(); + + Assert.AreEqual(1, list.Count); + + } + } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-01-06 21:35:19 UTC (rev 4909) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-01-06 21:39:25 UTC (rev 4910) @@ -658,6 +658,8 @@ <Compile Include="NHSpecificTest\NH1938\Model.cs" /> <Compile Include="NHSpecificTest\NH1939\AuxType.cs" /> <Compile Include="NHSpecificTest\NH1939\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2044\DomainClass.cs" /> + <Compile Include="NHSpecificTest\NH2044\SampleTest.cs" /> <Compile Include="NHSpecificTest\NH2055\AuxType.cs" /> <Compile Include="NHSpecificTest\NH2055\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2057\Fixture.cs" /> @@ -2098,6 +2100,7 @@ <EmbeddedResource Include="CfgTest\Loquacious\EntityToCache.hbm.xml" /> <EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH2044\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2030\Mappings.hbm.xml" /> <EmbeddedResource Include="Linq\Mappings\Patient.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2055\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aye...@us...> - 2010-01-06 21:35:27
|
Revision: 4909 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4909&view=rev Author: ayenderahien Date: 2010-01-06 21:35:19 +0000 (Wed, 06 Jan 2010) Log Message: ----------- Merging 4905-4908 revisions from 2.1 branch Modified Paths: -------------- trunk/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs trunk/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Exceptions/SqlParseException.cs trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/ScriptSplitter.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/AuxType.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Model.cs Removed Paths: ------------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/AuxType.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Model.cs Property Changed: ---------------- trunk/nhibernate/src/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Customer.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1904/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1904/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1904/Model.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1927/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1928/ trunk/nhibernate/src/NHibernate.Test/Tools/hbm2ddl/SchemaExportTests/ Property changes on: trunk/nhibernate/src ___________________________________________________________________ Modified: svn:mergeinfo - /branches/2.1.x/nhibernate/src:4659,4671,4681,4690-4691,4696-4697,4711,4715-4716 + /branches/2.1.x/nhibernate/src:4659,4671,4681,4690-4691,4696-4697,4711,4715-4716,4905-4908 Modified: trunk/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs =================================================================== --- trunk/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs 2010-01-06 21:05:51 UTC (rev 4908) +++ trunk/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs 2010-01-06 21:35:19 UTC (rev 4909) @@ -97,7 +97,6 @@ { try { - LogCommand(cmd); IDbConnection sessionConnection = connectionManager.GetConnection(); if (cmd.Connection != null) @@ -201,7 +200,8 @@ public int ExecuteNonQuery(IDbCommand cmd) { CheckReaders(); - Prepare(cmd); + LogCommand(cmd); + Prepare(cmd); Stopwatch duration = null; if(log.IsDebugEnabled) duration = Stopwatch.StartNew(); @@ -225,7 +225,8 @@ public IDataReader ExecuteReader(IDbCommand cmd) { CheckReaders(); - Prepare(cmd); + LogCommand(cmd); + Prepare(cmd); Stopwatch duration = null; if (log.IsDebugEnabled) duration = Stopwatch.StartNew(); Modified: trunk/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs =================================================================== --- trunk/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs 2010-01-06 21:05:51 UTC (rev 4908) +++ trunk/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs 2010-01-06 21:35:19 UTC (rev 4909) @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Data; using System.Reflection; +using System.Text; +using NHibernate.AdoNet.Util; namespace NHibernate.AdoNet { @@ -18,20 +20,40 @@ private IDbCommand currentBatch; private IDictionary<string, List<object>> parameterValueListHashTable; private IDictionary<string, bool> parameterIsAllNullsHashTable; + private StringBuilder currentBatchCommandsLog; public OracleDataClientBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor) : base(connectionManager, interceptor) { batchSize = Factory.Settings.AdoBatchSize; - } + //we always create this, because we need to deal with a scenario in which + //the user change the logging configuration at runtime. Trying to put this + //behind an if(log.IsDebugEnabled) will cause a null reference exception + //at that point. + currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:"); + } public override void AddToBatch(IExpectation expectation) { bool firstOnBatch = true; totalExpectedRowsAffected += expectation.ExpectedRowCount; - log.Info("Adding to batch"); - LogCommand(CurrentCommand); + string lineWithParameters = null; + var sqlStatementLogger = Factory.Settings.SqlStatementLogger; + if (sqlStatementLogger.IsDebugEnabled || log.IsDebugEnabled) + { + lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(CurrentCommand); + var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic); + lineWithParameters = formatStyle.Formatter.Format(lineWithParameters); + currentBatchCommandsLog.Append("command ") + .Append(countOfCommands) + .Append(":") + .AppendLine(lineWithParameters); + } + if (log.IsDebugEnabled) + { + log.Debug("Adding to batch:" + lineWithParameters); + } if (currentBatch == null) { @@ -87,6 +109,12 @@ CheckReaders(); Prepare(currentBatch); + if (Factory.Settings.SqlStatementLogger.IsDebugEnabled) + { + Factory.Settings.SqlStatementLogger.LogBatchCommand(currentBatchCommandsLog.ToString()); + currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:"); + } + foreach (IDataParameter currentParameter in currentBatch.Parameters) { List<object> parameterValueArray = parameterValueListHashTable[currentParameter.ParameterName]; Modified: trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs 2010-01-06 21:05:51 UTC (rev 4908) +++ trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs 2010-01-06 21:35:19 UTC (rev 4909) @@ -2105,5 +2105,17 @@ } } #endregion + + /// <summary> + /// Supports splitting batches using GO T-SQL command + /// </summary> + /// <remarks> + /// Batches http://msdn.microsoft.com/en-us/library/ms175502.aspx + /// </remarks> + public virtual bool SupportsSqlBatches + { + get { return false; } + } + } } Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2010-01-06 21:05:51 UTC (rev 4908) +++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2010-01-06 21:35:19 UTC (rev 4909) @@ -495,5 +495,13 @@ { get { return true; } } + + public override bool SupportsSqlBatches + { + get + { + return true; + } + } } } Copied: trunk/nhibernate/src/NHibernate/Exceptions/SqlParseException.cs (from rev 4908, branches/2.1.x/nhibernate/src/NHibernate/Exceptions/SqlParseException.cs) =================================================================== --- trunk/nhibernate/src/NHibernate/Exceptions/SqlParseException.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Exceptions/SqlParseException.cs 2010-01-06 21:35:19 UTC (rev 4909) @@ -0,0 +1,13 @@ +using System; + +namespace NHibernate.Exceptions +{ + public class SqlParseException : Exception + { + + public SqlParseException(string Message) : base(Message) + { + } + + } +} Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-01-06 21:05:51 UTC (rev 4908) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-01-06 21:35:19 UTC (rev 4909) @@ -607,6 +607,7 @@ <Compile Include="Event\IPreDatabaseOperationEventArgs.cs" /> <Compile Include="Exceptions\AdoExceptionContextInfo.cs" /> <Compile Include="Exceptions\ReflectionBasedSqlStateExtracter.cs" /> + <Compile Include="Exceptions\SqlParseException.cs" /> <Compile Include="Exceptions\SqlStateExtracter.cs" /> <Compile Include="Exceptions\TemplatedViolatedConstraintNameExtracter.cs" /> <Compile Include="Hql\Ast\ANTLR\AstPolymorphicProcessor.cs" /> @@ -800,6 +801,7 @@ <Compile Include="Proxy\AbstractProxyFactory.cs" /> <Compile Include="SqlCommand\InsertSelect.cs" /> <Compile Include="Tool\hbm2ddl\SchemaMetadataUpdater.cs" /> + <Compile Include="Tool\hbm2ddl\ScriptSplitter.cs" /> <Compile Include="Transaction\AdoNetWithDistrubtedTransactionFactory.cs" /> <Compile Include="Transform\ToListResultTransformer.cs" /> <Compile Include="Type\DbTimestampType.cs" /> Modified: trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs 2010-01-06 21:05:51 UTC (rev 4908) +++ trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs 2010-01-06 21:35:19 UTC (rev 4909) @@ -127,9 +127,7 @@ } if (export) { - statement.CommandText = sql; - statement.CommandType = CommandType.Text; - statement.ExecuteNonQuery(); + ExecuteSql(statement, sql); } } catch (Exception e) @@ -143,6 +141,29 @@ } } + private void ExecuteSql(IDbCommand cmd, string sql) + { + if (dialect.SupportsSqlBatches) + { + var objFactory = Environment.BytecodeProvider.ObjectsFactory; + ScriptSplitter splitter = (ScriptSplitter)objFactory.CreateInstance(typeof(ScriptSplitter), sql); + + foreach (string stmt in splitter) + { + log.DebugFormat("SQL Batch: {0}", stmt); + cmd.CommandText = stmt; + cmd.CommandType = CommandType.Text; + cmd.ExecuteNonQuery(); + } + } + else + { + cmd.CommandText = sql; + cmd.CommandType = CommandType.Text; + cmd.ExecuteNonQuery(); + } + } + /// <summary> /// Executes the Export of the Schema in the given connection /// </summary> Copied: trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/ScriptSplitter.cs (from rev 4908, branches/2.1.x/nhibernate/src/NHibernate/Tool/hbm2ddl/ScriptSplitter.cs) =================================================================== --- trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/ScriptSplitter.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Tool/hbm2ddl/ScriptSplitter.cs 2010-01-06 21:35:19 UTC (rev 4909) @@ -0,0 +1,405 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace NHibernate.Tool.hbm2ddl +{ + public class ScriptSplitter : IEnumerable<string> + { + private readonly TextReader _reader; + private StringBuilder _builder = new StringBuilder(); + private char _current; + private char _lastChar; + private ScriptReader _scriptReader; + + public ScriptSplitter(string script) + { + _reader = new StringReader(script); + _scriptReader = new SeparatorLineReader(this); + } + + internal bool HasNext + { + get { return _reader.Peek() != -1; } + } + + internal char Current + { + get { return _current; } + } + + internal char LastChar + { + get { return _lastChar; } + } + + #region IEnumerable<string> Members + + public IEnumerator<string> GetEnumerator() + { + while (Next()) + { + if (Split()) + { + string script = _builder.ToString().Trim(); + if (script.Length > 0) + { + yield return (script); + } + Reset(); + } + } + if (_builder.Length > 0) + { + string scriptRemains = _builder.ToString().Trim(); + if (scriptRemains.Length > 0) + { + yield return (scriptRemains); + } + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + #endregion + + internal bool Next() + { + if (!HasNext) + { + return false; + } + + _lastChar = _current; + _current = (char)_reader.Read(); + return true; + } + + internal int Peek() + { + return _reader.Peek(); + } + + private bool Split() + { + return _scriptReader.ReadNextSection(); + } + + internal void SetParser(ScriptReader newReader) + { + _scriptReader = newReader; + } + + internal void Append(string text) + { + _builder.Append(text); + } + + internal void Append(char c) + { + _builder.Append(c); + } + + void Reset() + { + _current = _lastChar = char.MinValue; + _builder = new StringBuilder(); + } + } + + abstract class ScriptReader + { + protected readonly ScriptSplitter Splitter; + + protected ScriptReader(ScriptSplitter splitter) + { + Splitter = splitter; + } + + /// <summary> + /// This acts as a template method. Specific Reader instances + /// override the component methods. + /// </summary> + public bool ReadNextSection() + { + if (IsQuote) + { + ReadQuotedString(); + return false; + } + + if (BeginDashDashComment) + { + return ReadDashDashComment(); + } + + if (BeginSlashStarComment) + { + ReadSlashStarComment(); + return false; + } + + return ReadNext(); + } + + protected virtual bool ReadDashDashComment() + { + Splitter.Append(Current); + while (Splitter.Next()) + { + Splitter.Append(Current); + if (EndOfLine) + { + break; + } + } + //We should be EndOfLine or EndOfScript here. + Splitter.SetParser(new SeparatorLineReader(Splitter)); + return false; + } + + protected virtual void ReadSlashStarComment() + { + if (ReadSlashStarCommentWithResult()) + { + Splitter.SetParser(new SeparatorLineReader(Splitter)); + return; + } + } + + private bool ReadSlashStarCommentWithResult() + { + Splitter.Append(Current); + while (Splitter.Next()) + { + if (BeginSlashStarComment) + { + ReadSlashStarCommentWithResult(); + continue; + } + Splitter.Append(Current); + + if (EndSlashStarComment) + { + return true; + } + } + return false; + } + + protected virtual void ReadQuotedString() + { + Splitter.Append(Current); + while (Splitter.Next()) + { + Splitter.Append(Current); + if (IsQuote) + { + return; + } + } + } + + protected abstract bool ReadNext(); + + #region Helper methods and properties + + protected bool HasNext + { + get { return Splitter.HasNext; } + } + + protected bool WhiteSpace + { + get { return char.IsWhiteSpace(Splitter.Current); } + } + + protected bool EndOfLine + { + get { return '\n' == Splitter.Current; } + } + + protected bool IsQuote + { + get { return '\'' == Splitter.Current; } + } + + protected char Current + { + get { return Splitter.Current; } + } + + protected char LastChar + { + get { return Splitter.LastChar; } + } + + bool BeginDashDashComment + { + get { return Current == '-' && Peek() == '-'; } + } + + bool BeginSlashStarComment + { + get { return Current == '/' && Peek() == '*'; } + } + + bool EndSlashStarComment + { + get { return LastChar == '*' && Current == '/'; } + } + + protected static bool CharEquals(char expected, char actual) + { + return Char.ToLowerInvariant(expected) == Char.ToLowerInvariant(actual); + } + + protected bool CharEquals(char compare) + { + return CharEquals(Current, compare); + } + + protected char Peek() + { + if (!HasNext) + { + return char.MinValue; + } + return (char)Splitter.Peek(); + } + + #endregion + } + + class SeparatorLineReader : ScriptReader + { + private StringBuilder _builder = new StringBuilder(); + private bool _foundGo; + private bool _gFound; + + public SeparatorLineReader(ScriptSplitter splitter) + : base(splitter) + { + } + + void Reset() + { + _foundGo = false; + _gFound = false; + _builder = new StringBuilder(); + } + + protected override bool ReadDashDashComment() + { + if (!_foundGo) + { + base.ReadDashDashComment(); + return false; + } + base.ReadDashDashComment(); + return true; + } + + protected override void ReadSlashStarComment() + { + if (_foundGo) + { + throw new NHibernate.Exceptions.SqlParseException(@"Incorrect syntax was encountered while parsing GO. Cannot have a slash star /* comment */ after a GO statement."); + } + base.ReadSlashStarComment(); + } + + protected override bool ReadNext() + { + if (EndOfLine) //End of line or script + { + if (!_foundGo) + { + _builder.Append(Current); + Splitter.Append(_builder.ToString()); + Splitter.SetParser(new SeparatorLineReader(Splitter)); + return false; + } + Reset(); + return true; + } + + if (WhiteSpace) + { + _builder.Append(Current); + return false; + } + + if (!CharEquals('g') && !CharEquals('o')) + { + FoundNonEmptyCharacter(Current); + return false; + } + + if (CharEquals('o')) + { + if (CharEquals('g', LastChar) && !_foundGo) + { + _foundGo = true; + } + else + { + FoundNonEmptyCharacter(Current); + } + } + + if (CharEquals('g', Current)) + { + if (_gFound || (!Char.IsWhiteSpace(LastChar) && LastChar != char.MinValue)) + { + FoundNonEmptyCharacter(Current); + return false; + } + + _gFound = true; + } + + if (!HasNext && _foundGo) + { + Reset(); + return true; + } + + _builder.Append(Current); + return false; + } + + void FoundNonEmptyCharacter(char c) + { + _builder.Append(c); + Splitter.Append(_builder.ToString()); + Splitter.SetParser(new SqlScriptReader(Splitter)); + } + } + + class SqlScriptReader : ScriptReader + { + public SqlScriptReader(ScriptSplitter splitter) + : base(splitter) + { + } + + protected override bool ReadNext() + { + if (EndOfLine) //end of line + { + Splitter.Append(Current); + Splitter.SetParser(new SeparatorLineReader(Splitter)); + return false; + } + + Splitter.Append(Current); + return false; + } + } +} Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Customer.cs ___________________________________________________________________ Modified: svn:mergeinfo - /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Customer.cs:4593-4594,4690-4691,4696-4697,4711,4715-4716 + /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Customer.cs:4593-4594,4690-4691,4696-4697,4711,4715-4716,4905-4908 Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Fixture.cs ___________________________________________________________________ Modified: svn:mergeinfo - /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Fixture.cs:4593-4594,4690-4691,4696-4697,4711,4715-4716 + /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Fixture.cs:4593-4594,4690-4691,4696-4697,4711,4715-4716,4905-4908 Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Mappings.hbm.xml ___________________________________________________________________ Modified: svn:mergeinfo - /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Mappings.hbm.xml:4593-4594,4690-4691,4696-4697,4711,4715-4716 + /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Mappings.hbm.xml:4593-4594,4690-4691,4696-4697,4711,4715-4716,4905-4908 Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1904/Fixture.cs ___________________________________________________________________ Modified: svn:mergeinfo - /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1904/Fixture.cs:4690-4691,4696-4697,4711,4715-4716 /trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/Fixture.cs:4657 + /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1904/Fixture.cs:4690-4691,4696-4697,4711,4715-4716,4905-4908 /trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/Fixture.cs:4657 Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1904/Mappings.hbm.xml ___________________________________________________________________ Modified: svn:mergeinfo - /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1904/Mappings.hbm.xml:4690-4691,4696-4697,4711,4715-4716 /trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/Mappings.hbm.xml:4657 + /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1904/Mappings.hbm.xml:4690-4691,4696-4697,4711,4715-4716,4905-4908 /trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/Mappings.hbm.xml:4657 Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1904/Model.cs ___________________________________________________________________ Modified: svn:mergeinfo - /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1904/Model.cs:4690-4691,4696-4697,4711,4715-4716 /trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/Model.cs:4657 + /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1904/Model.cs:4690-4691,4696-4697,4711,4715-4716,4905-4908 /trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/Model.cs:4657 Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1927 ___________________________________________________________________ Modified: svn:mergeinfo - /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1927:4691,4696-4697,4711,4715-4716 + /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1927:4691,4696-4697,4711,4715-4716,4905-4908 Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1928 ___________________________________________________________________ Modified: svn:mergeinfo - /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1928:4690-4691,4696-4697,4711,4715-4716 + /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1928:4690-4691,4696-4697,4711,4715-4716,4905-4908 Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055 ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Deleted: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/AuxType.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/AuxType.cs 2010-01-06 21:05:51 UTC (rev 4908) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/AuxType.cs 2010-01-06 21:35:19 UTC (rev 4909) @@ -1,22 +0,0 @@ -using System.Collections.Generic; -using NHibernate; -using NHibernate.Engine; -using NHibernate.Mapping; - -namespace NHibernate.Test.NHSpecificTest.NH2055 -{ - public class AuxType : AbstractAuxiliaryDatabaseObject - { - - override public string SqlCreateString(Dialect.Dialect dialect, IMapping p, string defaultCatalog, string defaultSchema) - { - return "select '" + Parameters["scriptParameter"] + "'"; - } - - override public string SqlDropString(Dialect.Dialect dialect, string defaultCatalog, string defaultSchema) - { - return "select 'drop script'"; - } - - } -} \ No newline at end of file Copied: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/AuxType.cs (from rev 4908, branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/AuxType.cs) =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/AuxType.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/AuxType.cs 2010-01-06 21:35:19 UTC (rev 4909) @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using NHibernate; +using NHibernate.Engine; +using NHibernate.Mapping; + +namespace NHibernate.Test.NHSpecificTest.NH2055 +{ + public class AuxType : AbstractAuxiliaryDatabaseObject + { + + override public string SqlCreateString(Dialect.Dialect dialect, IMapping p, string defaultCatalog, string defaultSchema) + { + return "select '" + Parameters["scriptParameter"] + "'"; + } + + override public string SqlDropString(Dialect.Dialect dialect, string defaultCatalog, string defaultSchema) + { + return "select 'drop script'"; + } + + } +} \ No newline at end of file Deleted: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Fixture.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Fixture.cs 2010-01-06 21:05:51 UTC (rev 4908) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Fixture.cs 2010-01-06 21:35:19 UTC (rev 4909) @@ -1,46 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using NUnit.Framework; -using NHibernate.Tool.hbm2ddl; -using System.Text; -using NHibernate.Cfg; - -namespace NHibernate.Test.NHSpecificTest.NH2055 -{ - [TestFixture] - public class Fixture : BugTestCase - { - protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect) - { - return (dialect is Dialect.MsSql2000Dialect); - } - - protected override void Configure(Configuration configuration) - { - base.Configure(configuration); - cfg = configuration; - } - - [Test] - public void CanCreateAndDropSchema() - { - using(var s = sessions.OpenSession()) - { - using(var cmd = s.Connection.CreateCommand()) - { - cmd.CommandType = CommandType.StoredProcedure; - - cmd.CommandText = "test_proc1"; - - Assert.AreEqual(1, cmd.ExecuteScalar()); - - cmd.CommandText = "test_proc2"; - - Assert.AreEqual(2, cmd.ExecuteScalar()); - } - } - } - - } -} Copied: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Fixture.cs (from rev 4908, branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Fixture.cs) =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Fixture.cs 2010-01-06 21:35:19 UTC (rev 4909) @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Data; +using NUnit.Framework; +using NHibernate.Tool.hbm2ddl; +using System.Text; +using NHibernate.Cfg; + +namespace NHibernate.Test.NHSpecificTest.NH2055 +{ + [TestFixture] + public class Fixture : BugTestCase + { + protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect) + { + return (dialect is Dialect.MsSql2000Dialect); + } + + protected override void Configure(Configuration configuration) + { + base.Configure(configuration); + cfg = configuration; + } + + [Test] + public void CanCreateAndDropSchema() + { + using(var s = sessions.OpenSession()) + { + using(var cmd = s.Connection.CreateCommand()) + { + cmd.CommandType = CommandType.StoredProcedure; + + cmd.CommandText = "test_proc1"; + + Assert.AreEqual(1, cmd.ExecuteScalar()); + + cmd.CommandText = "test_proc2"; + + Assert.AreEqual(2, cmd.ExecuteScalar()); + } + } + } + + } +} Deleted: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Mappings.hbm.xml =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Mappings.hbm.xml 2010-01-06 21:05:51 UTC (rev 4908) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Mappings.hbm.xml 2010-01-06 21:35:19 UTC (rev 4909) @@ -1,27 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" - assembly="NHibernate.Test" - namespace="NHibernate.Test.NHSpecificTest.NH2055"> - - <database-object> - <create> - CREATE PROC test_proc1 - AS - SELECT 1 - GO - CREATE PROC test_proc2 - AS - SELECT 2 - GO - </create> - <drop> - if (object_id('test_proc1') is not null ) - DROP PROC test_proc1 - GO - if (object_id('test_proc2') is not null ) - DROP PROC test_proc2 - GO - </drop> - </database-object> - -</hibernate-mapping> Copied: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Mappings.hbm.xml (from rev 4908, branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Mappings.hbm.xml) =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Mappings.hbm.xml 2010-01-06 21:35:19 UTC (rev 4909) @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2055"> + + <database-object> + <create> + CREATE PROC test_proc1 + AS + SELECT 1 + GO + CREATE PROC test_proc2 + AS + SELECT 2 + GO + </create> + <drop> + if (object_id('test_proc1') is not null ) + DROP PROC test_proc1 + GO + if (object_id('test_proc2') is not null ) + DROP PROC test_proc2 + GO + </drop> + </database-object> + +</hibernate-mapping> Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057 ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Deleted: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Fixture.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Fixture.cs 2010-01-06 21:05:51 UTC (rev 4908) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Fixture.cs 2010-01-06 21:35:19 UTC (rev 4909) @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Transactions; -using NHibernate.Impl; -using NUnit.Framework; -using NHibernate.Criterion; - -namespace NHibernate.Test.NHSpecificTest.NH2057 -{ - [TestFixture] - public class Fixture : BugTestCase - { - [Test] - public void WillCloseWhenUsingDTC() - { - SessionImpl s; - using (var tx = new TransactionScope()) - { - using (s = (SessionImpl)OpenSession()) - { - s.Get<Person>(1); - } - //not closed because the tx is opened yet - Assert.False(s.IsClosed); - tx.Complete(); - } - Assert.True(s.IsClosed); - } - - } -} Copied: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Fixture.cs (from rev 4908, branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Fixture.cs) =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Fixture.cs 2010-01-06 21:35:19 UTC (rev 4909) @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Transactions; +using NHibernate.Impl; +using NUnit.Framework; +using NHibernate.Criterion; + +namespace NHibernate.Test.NHSpecificTest.NH2057 +{ + [TestFixture] + public class Fixture : BugTestCase + { + [Test] + public void WillCloseWhenUsingDTC() + { + SessionImpl s; + using (var tx = new TransactionScope()) + { + using (s = (SessionImpl)OpenSession()) + { + s.Get<Person>(1); + } + //not closed because the tx is opened yet + Assert.False(s.IsClosed); + tx.Complete(); + } + Assert.True(s.IsClosed); + } + + } +} Deleted: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Mappings.hbm.xml =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Mappings.hbm.xml 2010-01-06 21:05:51 UTC (rev 4908) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Mappings.hbm.xml 2010-01-06 21:35:19 UTC (rev 4909) @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" - assembly="NHibernate.Test" - namespace="NHibernate.Test.NHSpecificTest.NH2057"> - - <class name="Person"> - <id name="Id"> - <generator class="native" /> - </id> - <property name="Name"/> - </class> - -</hibernate-mapping> Copied: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Mappings.hbm.xml (from rev 4908, branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Mappings.hbm.xml) =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Mappings.hbm.xml 2010-01-06 21:35:19 UTC (rev 4909) @@ -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.NH2057"> + + <class name="Person"> + <id name="Id"> + <generator class="native" /> + </id> + <property name="Name"/> + </class> + +</hibernate-mapping> Deleted: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Model.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Model.cs 2010-01-06 21:05:51 UTC (rev 4908) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Model.cs 2010-01-06 21:35:19 UTC (rev 4909) @@ -1,19 +0,0 @@ -using System; -using System.Xml.Serialization; -using System.Collections; -using System.Collections.Generic; -using System.Text; - -using NHibernate; -using NHibernate.Classic; - -namespace NHibernate.Test.NHSpecificTest.NH2057 -{ - - public class Person - { - public virtual int Id { get; set; } - public virtual string Name { get; set; } - } - -} Copied: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Model.cs (from rev 4908, branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Model.cs) =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Model.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Model.cs 2010-01-06 21:35:19 UTC (rev 4909) @@ -0,0 +1,19 @@ +using System; +using System.Xml.Serialization; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +using NHibernate; +using NHibernate.Classic; + +namespace NHibernate.Test.NHSpecificTest.NH2057 +{ + + public class Person + { + public virtual int Id { get; set; } + public virtual string Name { get; set; } + } + +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-01-06 21:05:51 UTC (rev 4908) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-01-06 21:35:19 UTC (rev 4909) @@ -658,6 +658,10 @@ <Compile Include="NHSpecificTest\NH1938\Model.cs" /> <Compile Include="NHSpecificTest\NH1939\AuxType.cs" /> <Compile Include="NHSpecificTest\NH1939\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2055\AuxType.cs" /> + <Compile Include="NHSpecificTest\NH2055\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2057\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2057\Model.cs" /> <Compile Include="NHSpecificTest\NH1941\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1941\Model.cs" /> <Compile Include="NHSpecificTest\NH1941\SexEnumStringType.cs" /> @@ -2096,6 +2100,8 @@ <Content Include="DynamicEntity\package.html" /> <EmbeddedResource Include="NHSpecificTest\NH2030\Mappings.hbm.xml" /> <EmbeddedResource Include="Linq\Mappings\Patient.hbm.xml" /> + <EmbeddedResource Include="NHSpecificTest\NH2055\Mappings.hbm.xml" /> + <EmbeddedResource Include="NHSpecificTest\NH2057\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2011\Mappings.hbm.xml" /> <EmbeddedResource Include="Linq\Mappings\Animal.hbm.xml" /> <EmbeddedResource Include="Linq\Mappings\AnotherEntity.hbm.xml" /> Property changes on: trunk/nhibernate/src/NHibernate.Test/Tools/hbm2ddl/SchemaExportTests ___________________________________________________________________ Modified: svn:mergeinfo - /branches/2.1.x/nhibernate/src/NHibernate.Test/Tools/hbm2ddl/SchemaExportTests:4507-4508,4510-4513,4537-4538,4593-4594,4690-4691,4696-4697,4711,4715-4716 + /branches/2.1.x/nhibernate/src/NHibernate.Test/Tools/hbm2ddl/SchemaExportTests:4507-4508,4510-4513,4537-4538,4593-4594,4690-4691,4696-4697,4711,4715-4716,4905-4908 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aye...@us...> - 2010-01-06 21:05:58
|
Revision: 4908 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4908&view=rev Author: ayenderahien Date: 2010-01-06 21:05:51 +0000 (Wed, 06 Jan 2010) Log Message: ----------- Completing NH2055 previous commit Modified Paths: -------------- branches/2.1.x/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/AuxType.cs branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Fixture.cs branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Mappings.hbm.xml Modified: branches/2.1.x/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2010-01-06 20:52:28 UTC (rev 4907) +++ branches/2.1.x/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2010-01-06 21:05:51 UTC (rev 4908) @@ -493,5 +493,13 @@ { get { return true; } } + + public override bool SupportsSqlBatches + { + get + { + return true; + } + } } } Property changes on: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055 ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/AuxType.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/AuxType.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/AuxType.cs 2010-01-06 21:05:51 UTC (rev 4908) @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using NHibernate; +using NHibernate.Engine; +using NHibernate.Mapping; + +namespace NHibernate.Test.NHSpecificTest.NH2055 +{ + public class AuxType : AbstractAuxiliaryDatabaseObject + { + + override public string SqlCreateString(Dialect.Dialect dialect, IMapping p, string defaultCatalog, string defaultSchema) + { + return "select '" + Parameters["scriptParameter"] + "'"; + } + + override public string SqlDropString(Dialect.Dialect dialect, string defaultCatalog, string defaultSchema) + { + return "select 'drop script'"; + } + + } +} \ No newline at end of file Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Fixture.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Fixture.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Fixture.cs 2010-01-06 21:05:51 UTC (rev 4908) @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Data; +using NUnit.Framework; +using NHibernate.Tool.hbm2ddl; +using System.Text; +using NHibernate.Cfg; + +namespace NHibernate.Test.NHSpecificTest.NH2055 +{ + [TestFixture] + public class Fixture : BugTestCase + { + protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect) + { + return (dialect is Dialect.MsSql2000Dialect); + } + + protected override void Configure(Configuration configuration) + { + base.Configure(configuration); + cfg = configuration; + } + + [Test] + public void CanCreateAndDropSchema() + { + using(var s = sessions.OpenSession()) + { + using(var cmd = s.Connection.CreateCommand()) + { + cmd.CommandType = CommandType.StoredProcedure; + + cmd.CommandText = "test_proc1"; + + Assert.AreEqual(1, cmd.ExecuteScalar()); + + cmd.CommandText = "test_proc2"; + + Assert.AreEqual(2, cmd.ExecuteScalar()); + } + } + } + + } +} Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Mappings.hbm.xml =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Mappings.hbm.xml (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2055/Mappings.hbm.xml 2010-01-06 21:05:51 UTC (rev 4908) @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2055"> + + <database-object> + <create> + CREATE PROC test_proc1 + AS + SELECT 1 + GO + CREATE PROC test_proc2 + AS + SELECT 2 + GO + </create> + <drop> + if (object_id('test_proc1') is not null ) + DROP PROC test_proc1 + GO + if (object_id('test_proc2') is not null ) + DROP PROC test_proc2 + GO + </drop> + </database-object> + +</hibernate-mapping> Modified: branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-01-06 20:52:28 UTC (rev 4907) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-01-06 21:05:51 UTC (rev 4908) @@ -591,6 +591,8 @@ <Compile Include="NHSpecificTest\NH1938\Model.cs" /> <Compile Include="NHSpecificTest\NH1939\AuxType.cs" /> <Compile Include="NHSpecificTest\NH1939\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2055\AuxType.cs" /> + <Compile Include="NHSpecificTest\NH2055\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2057\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2057\Model.cs" /> <Compile Include="NHSpecificTest\NH1941\Fixture.cs" /> @@ -2023,6 +2025,7 @@ <EmbeddedResource Include="DriverTest\MultiTypeEntity.hbm.xml" /> <EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH2055\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2057\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2011\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\ManyToOneFilters20Behaviour\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aye...@us...> - 2010-01-06 20:52:34
|
Revision: 4907 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4907&view=rev Author: ayenderahien Date: 2010-01-06 20:52:28 +0000 (Wed, 06 Jan 2010) Log Message: ----------- Applying patch for NH-2055 from Jason Dentler Modified Paths: -------------- branches/2.1.x/nhibernate/src/NHibernate/Dialect/Dialect.cs branches/2.1.x/nhibernate/src/NHibernate/NHibernate.csproj branches/2.1.x/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs Added Paths: ----------- branches/2.1.x/nhibernate/src/NHibernate/Exceptions/SqlParseException.cs branches/2.1.x/nhibernate/src/NHibernate/Tool/hbm2ddl/ScriptSplitter.cs Modified: branches/2.1.x/nhibernate/src/NHibernate/Dialect/Dialect.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/Dialect/Dialect.cs 2010-01-06 20:48:12 UTC (rev 4906) +++ branches/2.1.x/nhibernate/src/NHibernate/Dialect/Dialect.cs 2010-01-06 20:52:28 UTC (rev 4907) @@ -2105,5 +2105,17 @@ } } #endregion + + /// <summary> + /// Supports splitting batches using GO T-SQL command + /// </summary> + /// <remarks> + /// Batches http://msdn.microsoft.com/en-us/library/ms175502.aspx + /// </remarks> + public virtual bool SupportsSqlBatches + { + get { return false; } + } + } } Added: branches/2.1.x/nhibernate/src/NHibernate/Exceptions/SqlParseException.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/Exceptions/SqlParseException.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate/Exceptions/SqlParseException.cs 2010-01-06 20:52:28 UTC (rev 4907) @@ -0,0 +1,13 @@ +using System; + +namespace NHibernate.Exceptions +{ + public class SqlParseException : Exception + { + + public SqlParseException(string Message) : base(Message) + { + } + + } +} Modified: branches/2.1.x/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/NHibernate.csproj 2010-01-06 20:48:12 UTC (rev 4906) +++ branches/2.1.x/nhibernate/src/NHibernate/NHibernate.csproj 2010-01-06 20:52:28 UTC (rev 4907) @@ -489,6 +489,7 @@ <Compile Include="Event\IPreDatabaseOperationEventArgs.cs" /> <Compile Include="Exceptions\AdoExceptionContextInfo.cs" /> <Compile Include="Exceptions\ReflectionBasedSqlStateExtracter.cs" /> + <Compile Include="Exceptions\SqlParseException.cs" /> <Compile Include="Exceptions\SqlStateExtracter.cs" /> <Compile Include="Exceptions\TemplatedViolatedConstraintNameExtracter.cs" /> <Compile Include="Hql\Ast\ANTLR\ASTQueryTranslatorFactory.cs" /> @@ -614,6 +615,7 @@ <Compile Include="Proxy\AbstractProxyFactory.cs" /> <Compile Include="SqlCommand\InsertSelect.cs" /> <Compile Include="Tool\hbm2ddl\SchemaMetadataUpdater.cs" /> + <Compile Include="Tool\hbm2ddl\ScriptSplitter.cs" /> <Compile Include="Transaction\AdoNetWithDistrubtedTransactionFactory.cs" /> <Compile Include="Transform\ToListResultTransformer.cs" /> <Compile Include="Type\DbTimestampType.cs" /> Modified: branches/2.1.x/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs 2010-01-06 20:48:12 UTC (rev 4906) +++ branches/2.1.x/nhibernate/src/NHibernate/Tool/hbm2ddl/SchemaExport.cs 2010-01-06 20:52:28 UTC (rev 4907) @@ -127,9 +127,7 @@ } if (export) { - statement.CommandText = sql; - statement.CommandType = CommandType.Text; - statement.ExecuteNonQuery(); + ExecuteSql(statement, sql); } } catch (Exception e) @@ -143,6 +141,29 @@ } } + private void ExecuteSql(IDbCommand cmd, string sql) + { + if (dialect.SupportsSqlBatches) + { + var objFactory = Environment.BytecodeProvider.ObjectsFactory; + ScriptSplitter splitter = (ScriptSplitter)objFactory.CreateInstance(typeof(ScriptSplitter), sql); + + foreach (string stmt in splitter) + { + log.DebugFormat("SQL Batch: {0}", stmt); + cmd.CommandText = stmt; + cmd.CommandType = CommandType.Text; + cmd.ExecuteNonQuery(); + } + } + else + { + cmd.CommandText = sql; + cmd.CommandType = CommandType.Text; + cmd.ExecuteNonQuery(); + } + } + /// <summary> /// Executes the Export of the Schema in the given connection /// </summary> Added: branches/2.1.x/nhibernate/src/NHibernate/Tool/hbm2ddl/ScriptSplitter.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/Tool/hbm2ddl/ScriptSplitter.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate/Tool/hbm2ddl/ScriptSplitter.cs 2010-01-06 20:52:28 UTC (rev 4907) @@ -0,0 +1,405 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace NHibernate.Tool.hbm2ddl +{ + public class ScriptSplitter : IEnumerable<string> + { + private readonly TextReader _reader; + private StringBuilder _builder = new StringBuilder(); + private char _current; + private char _lastChar; + private ScriptReader _scriptReader; + + public ScriptSplitter(string script) + { + _reader = new StringReader(script); + _scriptReader = new SeparatorLineReader(this); + } + + internal bool HasNext + { + get { return _reader.Peek() != -1; } + } + + internal char Current + { + get { return _current; } + } + + internal char LastChar + { + get { return _lastChar; } + } + + #region IEnumerable<string> Members + + public IEnumerator<string> GetEnumerator() + { + while (Next()) + { + if (Split()) + { + string script = _builder.ToString().Trim(); + if (script.Length > 0) + { + yield return (script); + } + Reset(); + } + } + if (_builder.Length > 0) + { + string scriptRemains = _builder.ToString().Trim(); + if (scriptRemains.Length > 0) + { + yield return (scriptRemains); + } + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + #endregion + + internal bool Next() + { + if (!HasNext) + { + return false; + } + + _lastChar = _current; + _current = (char)_reader.Read(); + return true; + } + + internal int Peek() + { + return _reader.Peek(); + } + + private bool Split() + { + return _scriptReader.ReadNextSection(); + } + + internal void SetParser(ScriptReader newReader) + { + _scriptReader = newReader; + } + + internal void Append(string text) + { + _builder.Append(text); + } + + internal void Append(char c) + { + _builder.Append(c); + } + + void Reset() + { + _current = _lastChar = char.MinValue; + _builder = new StringBuilder(); + } + } + + abstract class ScriptReader + { + protected readonly ScriptSplitter Splitter; + + protected ScriptReader(ScriptSplitter splitter) + { + Splitter = splitter; + } + + /// <summary> + /// This acts as a template method. Specific Reader instances + /// override the component methods. + /// </summary> + public bool ReadNextSection() + { + if (IsQuote) + { + ReadQuotedString(); + return false; + } + + if (BeginDashDashComment) + { + return ReadDashDashComment(); + } + + if (BeginSlashStarComment) + { + ReadSlashStarComment(); + return false; + } + + return ReadNext(); + } + + protected virtual bool ReadDashDashComment() + { + Splitter.Append(Current); + while (Splitter.Next()) + { + Splitter.Append(Current); + if (EndOfLine) + { + break; + } + } + //We should be EndOfLine or EndOfScript here. + Splitter.SetParser(new SeparatorLineReader(Splitter)); + return false; + } + + protected virtual void ReadSlashStarComment() + { + if (ReadSlashStarCommentWithResult()) + { + Splitter.SetParser(new SeparatorLineReader(Splitter)); + return; + } + } + + private bool ReadSlashStarCommentWithResult() + { + Splitter.Append(Current); + while (Splitter.Next()) + { + if (BeginSlashStarComment) + { + ReadSlashStarCommentWithResult(); + continue; + } + Splitter.Append(Current); + + if (EndSlashStarComment) + { + return true; + } + } + return false; + } + + protected virtual void ReadQuotedString() + { + Splitter.Append(Current); + while (Splitter.Next()) + { + Splitter.Append(Current); + if (IsQuote) + { + return; + } + } + } + + protected abstract bool ReadNext(); + + #region Helper methods and properties + + protected bool HasNext + { + get { return Splitter.HasNext; } + } + + protected bool WhiteSpace + { + get { return char.IsWhiteSpace(Splitter.Current); } + } + + protected bool EndOfLine + { + get { return '\n' == Splitter.Current; } + } + + protected bool IsQuote + { + get { return '\'' == Splitter.Current; } + } + + protected char Current + { + get { return Splitter.Current; } + } + + protected char LastChar + { + get { return Splitter.LastChar; } + } + + bool BeginDashDashComment + { + get { return Current == '-' && Peek() == '-'; } + } + + bool BeginSlashStarComment + { + get { return Current == '/' && Peek() == '*'; } + } + + bool EndSlashStarComment + { + get { return LastChar == '*' && Current == '/'; } + } + + protected static bool CharEquals(char expected, char actual) + { + return Char.ToLowerInvariant(expected) == Char.ToLowerInvariant(actual); + } + + protected bool CharEquals(char compare) + { + return CharEquals(Current, compare); + } + + protected char Peek() + { + if (!HasNext) + { + return char.MinValue; + } + return (char)Splitter.Peek(); + } + + #endregion + } + + class SeparatorLineReader : ScriptReader + { + private StringBuilder _builder = new StringBuilder(); + private bool _foundGo; + private bool _gFound; + + public SeparatorLineReader(ScriptSplitter splitter) + : base(splitter) + { + } + + void Reset() + { + _foundGo = false; + _gFound = false; + _builder = new StringBuilder(); + } + + protected override bool ReadDashDashComment() + { + if (!_foundGo) + { + base.ReadDashDashComment(); + return false; + } + base.ReadDashDashComment(); + return true; + } + + protected override void ReadSlashStarComment() + { + if (_foundGo) + { + throw new NHibernate.Exceptions.SqlParseException(@"Incorrect syntax was encountered while parsing GO. Cannot have a slash star /* comment */ after a GO statement."); + } + base.ReadSlashStarComment(); + } + + protected override bool ReadNext() + { + if (EndOfLine) //End of line or script + { + if (!_foundGo) + { + _builder.Append(Current); + Splitter.Append(_builder.ToString()); + Splitter.SetParser(new SeparatorLineReader(Splitter)); + return false; + } + Reset(); + return true; + } + + if (WhiteSpace) + { + _builder.Append(Current); + return false; + } + + if (!CharEquals('g') && !CharEquals('o')) + { + FoundNonEmptyCharacter(Current); + return false; + } + + if (CharEquals('o')) + { + if (CharEquals('g', LastChar) && !_foundGo) + { + _foundGo = true; + } + else + { + FoundNonEmptyCharacter(Current); + } + } + + if (CharEquals('g', Current)) + { + if (_gFound || (!Char.IsWhiteSpace(LastChar) && LastChar != char.MinValue)) + { + FoundNonEmptyCharacter(Current); + return false; + } + + _gFound = true; + } + + if (!HasNext && _foundGo) + { + Reset(); + return true; + } + + _builder.Append(Current); + return false; + } + + void FoundNonEmptyCharacter(char c) + { + _builder.Append(c); + Splitter.Append(_builder.ToString()); + Splitter.SetParser(new SqlScriptReader(Splitter)); + } + } + + class SqlScriptReader : ScriptReader + { + public SqlScriptReader(ScriptSplitter splitter) + : base(splitter) + { + } + + protected override bool ReadNext() + { + if (EndOfLine) //end of line + { + Splitter.Append(Current); + Splitter.SetParser(new SeparatorLineReader(Splitter)); + return false; + } + + Splitter.Append(Current); + return false; + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aye...@us...> - 2010-01-06 20:48:19
|
Revision: 4906 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4906&view=rev Author: ayenderahien Date: 2010-01-06 20:48:12 +0000 (Wed, 06 Jan 2010) Log Message: ----------- Adding passing test for NH 2057 Modified Paths: -------------- branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Fixture.cs branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Mappings.hbm.xml branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Model.cs Property changes on: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057 ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Fixture.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Fixture.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Fixture.cs 2010-01-06 20:48:12 UTC (rev 4906) @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Transactions; +using NHibernate.Impl; +using NUnit.Framework; +using NHibernate.Criterion; + +namespace NHibernate.Test.NHSpecificTest.NH2057 +{ + [TestFixture] + public class Fixture : BugTestCase + { + [Test] + public void WillCloseWhenUsingDTC() + { + SessionImpl s; + using (var tx = new TransactionScope()) + { + using (s = (SessionImpl)OpenSession()) + { + s.Get<Person>(1); + } + //not closed because the tx is opened yet + Assert.False(s.IsClosed); + tx.Complete(); + } + Assert.True(s.IsClosed); + } + + } +} Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Mappings.hbm.xml =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Mappings.hbm.xml (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Mappings.hbm.xml 2010-01-06 20:48:12 UTC (rev 4906) @@ -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.NH2057"> + + <class name="Person"> + <id name="Id"> + <generator class="native" /> + </id> + <property name="Name"/> + </class> + +</hibernate-mapping> Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Model.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Model.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2057/Model.cs 2010-01-06 20:48:12 UTC (rev 4906) @@ -0,0 +1,19 @@ +using System; +using System.Xml.Serialization; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +using NHibernate; +using NHibernate.Classic; + +namespace NHibernate.Test.NHSpecificTest.NH2057 +{ + + public class Person + { + public virtual int Id { get; set; } + public virtual string Name { get; set; } + } + +} Modified: branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-01-06 20:12:26 UTC (rev 4905) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-01-06 20:48:12 UTC (rev 4906) @@ -591,6 +591,8 @@ <Compile Include="NHSpecificTest\NH1938\Model.cs" /> <Compile Include="NHSpecificTest\NH1939\AuxType.cs" /> <Compile Include="NHSpecificTest\NH1939\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2057\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2057\Model.cs" /> <Compile Include="NHSpecificTest\NH1941\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1941\Model.cs" /> <Compile Include="NHSpecificTest\NH1941\SexEnumStringType.cs" /> @@ -2021,6 +2023,7 @@ <EmbeddedResource Include="DriverTest\MultiTypeEntity.hbm.xml" /> <EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH2057\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2011\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\ManyToOneFilters20Behaviour\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2000\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aye...@us...> - 2010-01-06 20:12:33
|
Revision: 4905 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4905&view=rev Author: ayenderahien Date: 2010-01-06 20:12:26 +0000 (Wed, 06 Jan 2010) Log Message: ----------- Fixing NH-2047 - standardizing the format of Oracle Batcher to match SqlClient Batcher and ensure that we only output batch statements once Modified Paths: -------------- branches/2.1.x/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs branches/2.1.x/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs Modified: branches/2.1.x/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs 2010-01-06 05:08:17 UTC (rev 4904) +++ branches/2.1.x/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs 2010-01-06 20:12:26 UTC (rev 4905) @@ -97,7 +97,6 @@ { try { - LogCommand(cmd); IDbConnection sessionConnection = connectionManager.GetConnection(); if (cmd.Connection != null) @@ -201,7 +200,8 @@ public int ExecuteNonQuery(IDbCommand cmd) { CheckReaders(); - Prepare(cmd); + LogCommand(cmd); + Prepare(cmd); Stopwatch duration = null; if(log.IsDebugEnabled) duration = Stopwatch.StartNew(); @@ -225,7 +225,8 @@ public IDataReader ExecuteReader(IDbCommand cmd) { CheckReaders(); - Prepare(cmd); + LogCommand(cmd); + Prepare(cmd); Stopwatch duration = null; if (log.IsDebugEnabled) duration = Stopwatch.StartNew(); Modified: branches/2.1.x/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs 2010-01-06 05:08:17 UTC (rev 4904) +++ branches/2.1.x/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs 2010-01-06 20:12:26 UTC (rev 4905) @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Data; using System.Reflection; +using System.Text; +using NHibernate.AdoNet.Util; namespace NHibernate.AdoNet { @@ -18,20 +20,40 @@ private IDbCommand currentBatch; private IDictionary<string, List<object>> parameterValueListHashTable; private IDictionary<string, bool> parameterIsAllNullsHashTable; + private StringBuilder currentBatchCommandsLog; public OracleDataClientBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor) : base(connectionManager, interceptor) { batchSize = Factory.Settings.AdoBatchSize; - } + //we always create this, because we need to deal with a scenario in which + //the user change the logging configuration at runtime. Trying to put this + //behind an if(log.IsDebugEnabled) will cause a null reference exception + //at that point. + currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:"); + } public override void AddToBatch(IExpectation expectation) { bool firstOnBatch = true; totalExpectedRowsAffected += expectation.ExpectedRowCount; - log.Info("Adding to batch"); - LogCommand(CurrentCommand); + string lineWithParameters = null; + var sqlStatementLogger = Factory.Settings.SqlStatementLogger; + if (sqlStatementLogger.IsDebugEnabled || log.IsDebugEnabled) + { + lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(CurrentCommand); + var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic); + lineWithParameters = formatStyle.Formatter.Format(lineWithParameters); + currentBatchCommandsLog.Append("command ") + .Append(countOfCommands) + .Append(":") + .AppendLine(lineWithParameters); + } + if (log.IsDebugEnabled) + { + log.Debug("Adding to batch:" + lineWithParameters); + } if (currentBatch == null) { @@ -87,6 +109,12 @@ CheckReaders(); Prepare(currentBatch); + if (Factory.Settings.SqlStatementLogger.IsDebugEnabled) + { + Factory.Settings.SqlStatementLogger.LogBatchCommand(currentBatchCommandsLog.ToString()); + currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:"); + } + foreach (IDataParameter currentParameter in currentBatch.Parameters) { List<object> parameterValueArray = parameterValueListHashTable[currentParameter.ParameterName]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-01-06 05:08:29
|
Revision: 4904 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4904&view=rev Author: fabiomaulo Date: 2010-01-06 05:08:17 +0000 (Wed, 06 Jan 2010) Log Message: ----------- - Refactoring - removed unused code Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/ClassExtractor.cs trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs trunk/nhibernate/src/NHibernate/Cfg/NamedXmlDocument.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj Removed Paths: ------------- trunk/nhibernate/src/NHibernate/Util/XmlHelper.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/ClassExtractor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/ClassExtractor.cs 2010-01-06 04:00:10 UTC (rev 4903) +++ trunk/nhibernate/src/NHibernate/Cfg/ClassExtractor.cs 2010-01-06 05:08:17 UTC (rev 4904) @@ -1,8 +1,8 @@ using System.Xml; -using NHibernate.Cfg.XmlHbmBinding; +using System.Linq; using NHibernate.Util; using System.Collections.Generic; -using Iesi.Collections.Generic; +using NHibernate.Cfg.MappingSchema; namespace NHibernate.Cfg { @@ -59,8 +59,7 @@ public override bool Equals(object obj) { - ClassEntry that = obj as ClassEntry; - return Equals(that); + return Equals(obj as ClassEntry); } public bool Equals(ClassEntry obj) @@ -88,40 +87,19 @@ /// </summary> /// <param name="document">A validated <see cref="XmlDocument"/> representing /// a mapping file.</param> - public static ICollection<ClassEntry> GetClassEntries(XmlDocument document) + public static ICollection<ClassEntry> GetClassEntries(HbmMapping document) { - // TODO this should be extracted into a utility method since there's similar - // code in Configuration - XmlNamespaceManager nsmgr = new XmlNamespaceManager(document.NameTable); - nsmgr.AddNamespace(HbmConstants.nsPrefix, Binder.MappingSchemaXMLNS); - // Since the document is validated, no error checking is done in this method. - HashedSet<ClassEntry> classEntries = new HashedSet<ClassEntry>(); + var classEntries = new HashSet<ClassEntry>(); - XmlNode root = document.DocumentElement; + string assembly = document.assembly; + string @namespace = document.@namespace; - string assembly = XmlHelper.GetAttributeValue(root, "assembly"); - string @namespace = XmlHelper.GetAttributeValue(root, "namespace"); + classEntries.UnionWith(document.RootClasses.Select(c=> new ClassEntry(null, c.Name, c.EntityName, assembly, @namespace))); + classEntries.UnionWith(document.SubClasses.Select(c => new ClassEntry(c.extends, c.Name, c.EntityName, assembly, @namespace))); + classEntries.UnionWith(document.JoinedSubclasses.Select(c => new ClassEntry(c.extends, c.Name, c.EntityName, assembly, @namespace))); + classEntries.UnionWith(document.UnionSubclasses.Select(c => new ClassEntry(c.extends, c.Name, c.EntityName, assembly, @namespace))); - XmlNodeList classNodes = document.SelectNodes( - "//" + HbmConstants.nsClass + - "|//" + HbmConstants.nsSubclass + - "|//" + HbmConstants.nsJoinedSubclass + - "|//" + HbmConstants.nsUnionSubclass, - nsmgr - ); - - if (classNodes != null) - { - foreach (XmlNode classNode in classNodes) - { - string name = XmlHelper.GetAttributeValue(classNode, "name"); - string extends = XmlHelper.GetAttributeValue(classNode, "extends"); - string entityName = XmlHelper.GetAttributeValue(classNode, "entity-name"); - classEntries.Add(new ClassEntry(extends, name, entityName, assembly, @namespace)); - } - } - return classEntries; } } Modified: trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2010-01-06 04:00:10 UTC (rev 4903) +++ trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2010-01-06 05:08:17 UTC (rev 4904) @@ -8,7 +8,6 @@ using System.Text; using System.Xml; using System.Xml.Schema; -using System.Xml.Serialization; using Iesi.Collections; using Iesi.Collections.Generic; using log4net; @@ -494,22 +493,7 @@ /// <param name="doc">The NamedXmlDocument that contains the <b>validated</b> mapping XML file.</param> private void AddValidatedDocument(NamedXmlDocument doc) { - HbmMapping mappingMeta = null; - try - { - // TODO : The mappingMeta should be the property of NamedXmlDocument - // A validated document IS a deserialized doc and we don't need to deserialize it more than one time. - using (var reader = new StringReader(doc.Document.DocumentElement.OuterXml)) - { - mappingMeta = (HbmMapping) new XmlSerializer(typeof (HbmMapping)).Deserialize(reader); - } - } - catch (Exception e) - { - string nameFormatted = doc.Name ?? "(unknown)"; - LogAndThrow(new MappingException("Could not compile the mapping document: " + nameFormatted, e)); - } - AddDeserializedMapping(mappingMeta, doc.Name); + AddDeserializedMapping(doc.Document, doc.Name); } /// <summary> @@ -1762,11 +1746,21 @@ hbmDocument.Load(reader); return new NamedXmlDocument(name, hbmDocument); } + catch(MappingException) + { + throw; + } + catch (Exception e) + { + string nameFormatted = name ?? "(unknown)"; + LogAndThrow(new MappingException("Could not compile the mapping document: " + nameFormatted, e)); + } finally { currentDocumentName = null; } } + return null; } /// <summary> Modified: trunk/nhibernate/src/NHibernate/Cfg/NamedXmlDocument.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/NamedXmlDocument.cs 2010-01-06 04:00:10 UTC (rev 4903) +++ trunk/nhibernate/src/NHibernate/Cfg/NamedXmlDocument.cs 2010-01-06 05:08:17 UTC (rev 4904) @@ -1,16 +1,31 @@ +using System; +using System.IO; using System.Xml; +using System.Xml.Serialization; +using NHibernate.Cfg.MappingSchema; namespace NHibernate.Cfg { public class NamedXmlDocument { private readonly string name; - private readonly XmlDocument document; + private readonly HbmMapping document; public NamedXmlDocument(string name, XmlDocument document) { + if (document == null) + { + throw new ArgumentNullException("document"); + } this.name = name; - this.document = document; + if (document.DocumentElement == null) + { + throw new MappingException("Empty XML document:" + name); + } + using (var reader = new StringReader(document.DocumentElement.OuterXml)) + { + this.document = (HbmMapping)new XmlSerializer(typeof(HbmMapping)).Deserialize(reader); + } } public string Name @@ -18,7 +33,7 @@ get { return name; } } - public XmlDocument Document + public HbmMapping Document { get { return document; } } Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs 2010-01-06 04:00:10 UTC (rev 4903) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs 2010-01-06 05:08:17 UTC (rev 4904) @@ -10,9 +10,6 @@ { public abstract class Binder { - /// <summary>The XML Namespace for the nhibernate-mapping</summary> - public const string MappingSchemaXMLNS = "urn:nhibernate-mapping-2.2"; - protected static readonly ILog log = LogManager.GetLogger(typeof (Binder)); protected static readonly IDictionary<string, MetaAttribute> EmptyMeta = Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-01-06 04:00:10 UTC (rev 4903) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-01-06 05:08:17 UTC (rev 4904) @@ -1487,7 +1487,6 @@ <Compile Include="Util\WeakHashtable.cs"> <SubType>Code</SubType> </Compile> - <Compile Include="Util\XmlHelper.cs" /> <Compile Include="Properties\XmlAccessor.cs" /> <EmbeddedResource Include="nhibernate-configuration.xsd"> <SubType> Deleted: trunk/nhibernate/src/NHibernate/Util/XmlHelper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Util/XmlHelper.cs 2010-01-06 04:00:10 UTC (rev 4903) +++ trunk/nhibernate/src/NHibernate/Util/XmlHelper.cs 2010-01-06 05:08:17 UTC (rev 4904) @@ -1,29 +0,0 @@ -using System; -using System.Xml; - -namespace NHibernate.Util -{ - public class XmlHelper - { - public static string GetAttributeValue(XmlNode node, string attributeName) - { - XmlAttribute attribute = node.Attributes[attributeName]; - if (attribute == null) - { - return null; - } - return attribute.Value; - } - - public static string ElementTextTrim(XmlNode node, string elementName, XmlNamespaceManager nsmgr) - { - XmlNode subNode = node.SelectSingleNode(elementName, nsmgr); - if (subNode == null) - { - return null; - } - - return subNode.InnerText.Trim(); - } - } -} \ 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-01-06 04:00:16
|
Revision: 4903 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4903&view=rev Author: fabiomaulo Date: 2010-01-06 04:00:10 +0000 (Wed, 06 Jan 2010) Log Message: ----------- Minor refactoring Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/MappingsQueue.cs trunk/nhibernate/src/NHibernate/Cfg/MappingsQueueEntry.cs trunk/nhibernate/src/NHibernate/Cfg/NamedXmlDocument.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingsQueue.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingsQueue.cs 2010-01-06 00:09:14 UTC (rev 4902) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingsQueue.cs 2010-01-06 04:00:10 UTC (rev 4903) @@ -1,7 +1,8 @@ using System.Collections; +using System.Collections.Generic; +using System.Linq; using System.Text; using Iesi.Collections.Generic; -using System.Collections.Generic; namespace NHibernate.Cfg { @@ -10,17 +11,17 @@ /// </summary> public class MappingsQueue { - private readonly ISet<string> _processedClassNames = new HashedSet<string>(); + private readonly Queue availableEntries = new Queue(); + private readonly ISet<string> processedClassNames = new HashedSet<string>(); - private readonly List<MappingsQueueEntry> _unavailableEntries = new List<MappingsQueueEntry>(); - private readonly Queue _availableEntries = new Queue(); + private readonly List<MappingsQueueEntry> unavailableEntries = new List<MappingsQueueEntry>(); /// <summary> /// Adds the specified document to the queue. /// </summary> public void AddDocument(NamedXmlDocument document) { - MappingsQueueEntry re = new MappingsQueueEntry(document, ClassExtractor.GetClassEntries(document.Document)); + var re = new MappingsQueueEntry(document, ClassExtractor.GetClassEntries(document.Document)); AddEntry(re); } @@ -31,12 +32,12 @@ /// <returns></returns> public NamedXmlDocument GetNextAvailableResource() { - if (_availableEntries.Count == 0) + if (availableEntries.Count == 0) { return null; } - MappingsQueueEntry entry = (MappingsQueueEntry)_availableEntries.Dequeue(); + var entry = (MappingsQueueEntry) availableEntries.Dequeue(); AddProcessedClassNames(entry.ContainedClassNames); return entry.Document; } @@ -46,15 +47,15 @@ /// </summary> public void CheckNoUnavailableEntries() { - if (_unavailableEntries.Count > 0) + if (unavailableEntries.Count > 0) { - throw new MappingException(FormatExceptionMessage(_unavailableEntries)); + throw new MappingException(FormatExceptionMessage(unavailableEntries)); } } private void AddProcessedClassNames(ICollection<string> classNames) { - _processedClassNames.AddAll(classNames); + processedClassNames.AddAll(classNames); if (classNames.Count > 0) { ProcessUnavailableEntries(); @@ -65,11 +66,11 @@ { if (CanProcess(re)) { - _availableEntries.Enqueue(re); + availableEntries.Enqueue(re); } else { - _unavailableEntries.Add(re); + unavailableEntries.Add(re); } } @@ -79,44 +80,31 @@ while ((found = FindAvailableResourceEntry()) != null) { - _availableEntries.Enqueue(found); - _unavailableEntries.Remove(found); + availableEntries.Enqueue(found); + unavailableEntries.Remove(found); } } private MappingsQueueEntry FindAvailableResourceEntry() { - foreach (MappingsQueueEntry re in _unavailableEntries) - { - if (CanProcess(re)) - { - return re; - } - } - return null; + return unavailableEntries.FirstOrDefault(CanProcess); } private bool CanProcess(MappingsQueueEntry ce) { - foreach (var c in ce.RequiredClassNames) - { - if (!(_processedClassNames.Contains(c.FullClassName) || _processedClassNames.Contains(c.EntityName))) - return false; - } - return true; + return + ce.RequiredClassNames.All( + c => (processedClassNames.Contains(c.FullClassName) || processedClassNames.Contains(c.EntityName))); } - private static string FormatExceptionMessage(ICollection resourceEntries) + private static string FormatExceptionMessage(IEnumerable<MappingsQueueEntry> resourceEntries) { - StringBuilder message = new StringBuilder( - "These classes referenced by 'extends' were not found:"); - - foreach (MappingsQueueEntry resourceEntry in resourceEntries) + var message = new StringBuilder(500); + message.Append("These classes referenced by 'extends' were not found:"); + foreach (MappingsQueueEntry.RequiredEntityName className in + resourceEntries.SelectMany(resourceEntry => resourceEntry.RequiredClassNames)) { - foreach (var className in resourceEntry.RequiredClassNames) - { - message.Append('\n').Append(className); - } + message.Append('\n').Append(className); } return message.ToString(); Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingsQueueEntry.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingsQueueEntry.cs 2010-01-06 00:09:14 UTC (rev 4902) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingsQueueEntry.cs 2010-01-06 04:00:10 UTC (rev 4903) @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Iesi.Collections.Generic; namespace NHibernate.Cfg { @@ -8,9 +7,9 @@ /// </summary> public class MappingsQueueEntry { - private readonly HashedSet<string> containedClassNames; + private readonly HashSet<string> containedClassNames; private readonly NamedXmlDocument document; - private readonly HashedSet<RequiredEntityName> requiredClassNames; + private readonly HashSet<RequiredEntityName> requiredClassNames; public MappingsQueueEntry(NamedXmlDocument document, IEnumerable<ClassExtractor.ClassEntry> classEntries) { @@ -42,9 +41,9 @@ get { return containedClassNames; } } - private static HashedSet<string> GetClassNames(IEnumerable<ClassExtractor.ClassEntry> classEntries) + private static HashSet<string> GetClassNames(IEnumerable<ClassExtractor.ClassEntry> classEntries) { - var result = new HashedSet<string>(); + var result = new HashSet<string>(); foreach (var ce in classEntries) { @@ -61,10 +60,10 @@ return result; } - private static HashedSet<RequiredEntityName> GetRequiredClassNames(IEnumerable<ClassExtractor.ClassEntry> classEntries, + private static HashSet<RequiredEntityName> GetRequiredClassNames(IEnumerable<ClassExtractor.ClassEntry> classEntries, ICollection<string> containedNames) { - var result = new HashedSet<RequiredEntityName>(); + var result = new HashSet<RequiredEntityName>(); foreach (var ce in classEntries) { Modified: trunk/nhibernate/src/NHibernate/Cfg/NamedXmlDocument.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/NamedXmlDocument.cs 2010-01-06 00:09:14 UTC (rev 4902) +++ trunk/nhibernate/src/NHibernate/Cfg/NamedXmlDocument.cs 2010-01-06 04:00:10 UTC (rev 4903) @@ -1,4 +1,3 @@ -using System; using System.Xml; namespace NHibernate.Cfg This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-01-06 00:09:21
|
Revision: 4902 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4902&view=rev Author: fabiomaulo Date: 2010-01-06 00:09:14 +0000 (Wed, 06 Jan 2010) Log Message: ----------- Refactoring (DRY) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs 2010-01-05 22:56:37 UTC (rev 4901) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs 2010-01-06 00:09:14 UTC (rev 4902) @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using NHibernate.Cfg.MappingSchema; using NHibernate.Mapping; using System; @@ -173,16 +172,7 @@ if (property != null) { modifier(property); - if (log.IsDebugEnabled) - { - string msg = "Mapped property: " + property.Name; - string columns = string.Join(",", property.Value.ColumnIterator.Select(c => c.Text).ToArray()); - if (columns.Length > 0) - msg += " -> " + columns; - if (property.Type != null) - msg += ", type: " + property.Type.Name; - log.Debug(msg); - } + property.LogMapped(log); addToModelAction(property); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-01-05 22:56:46
|
Revision: 4901 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4901&view=rev Author: fabiomaulo Date: 2010-01-05 22:56:37 +0000 (Tue, 05 Jan 2010) Log Message: ----------- Refactoring Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmExtensions.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/NamedQueryBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/NamedSQLQueryBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj Removed Paths: ------------- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CacheModeConverter.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmExtensions.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmExtensions.cs 2010-01-05 22:16:33 UTC (rev 4900) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmExtensions.cs 2010-01-05 22:56:37 UTC (rev 4901) @@ -1,3 +1,4 @@ +using System; using NHibernate.Engine; namespace NHibernate.Cfg.MappingSchema @@ -20,5 +21,56 @@ return Versioning.OptimisticLock.Version; } } + + public static string ToNullValue(this HbmUnsavedValueType unsavedValueType) + { + switch (unsavedValueType) + { + case HbmUnsavedValueType.Undefined: + return "undefined"; + case HbmUnsavedValueType.Any: + return "any"; + case HbmUnsavedValueType.None: + return "none"; + default: + throw new ArgumentOutOfRangeException("unsavedValueType"); + } + } + + public static string ToCacheConcurrencyStrategy(this HbmCacheUsage cacheUsage) + { + switch (cacheUsage) + { + case HbmCacheUsage.ReadOnly: + return "read-only"; + case HbmCacheUsage.ReadWrite: + return "read-write"; + case HbmCacheUsage.NonstrictReadWrite: + return "nonstrict-read-write"; + case HbmCacheUsage.Transactional: + return "transactional"; + default: + throw new ArgumentOutOfRangeException("cacheUsage"); + } + } + + public static CacheMode? ToCacheMode(this HbmCacheMode cacheMode) + { + switch (cacheMode) + { + case HbmCacheMode.Get: + return CacheMode.Get; + case HbmCacheMode.Ignore: + return CacheMode.Ignore; + case HbmCacheMode.Normal: + return CacheMode.Normal; + case HbmCacheMode.Put: + return CacheMode.Put; + case HbmCacheMode.Refresh: + return CacheMode.Refresh; + default: + throw new ArgumentOutOfRangeException("cacheMode"); + } + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs 2010-01-05 22:16:33 UTC (rev 4900) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs 2010-01-05 22:56:37 UTC (rev 4901) @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.Reflection; -using System.Xml.Serialization; - using log4net; using NHibernate.Mapping; using NHibernate.Type; @@ -134,21 +131,6 @@ return ClassForNameChecked(unqualifiedName, mappings, "unknown class {0}").AssemblyQualifiedName; } - protected static string GetXmlEnumAttribute(Enum cascadeStyle) - { - MemberInfo[] memberInfo = cascadeStyle.GetType().GetMember(cascadeStyle.ToString()); - - if (memberInfo != null && memberInfo.Length == 1) - { - object[] customAttributes = memberInfo[0].GetCustomAttributes(typeof(XmlEnumAttribute), false); - - if (customAttributes.Length == 1) - return ((XmlEnumAttribute)customAttributes[0]).Name; - } - - return null; - } - public static IDictionary<string, MetaAttribute> GetMetas(IDecoratable decoratable, IDictionary<string, MetaAttribute> inheritedMeta) { return GetMetas(decoratable, inheritedMeta, false); Deleted: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CacheModeConverter.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CacheModeConverter.cs 2010-01-05 22:16:33 UTC (rev 4900) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CacheModeConverter.cs 2010-01-05 22:56:37 UTC (rev 4901) @@ -1,27 +0,0 @@ -using System; -using NHibernate.Cfg.MappingSchema; - -namespace NHibernate.Cfg.XmlHbmBinding -{ - internal static class CacheModeConverter - { - public static CacheMode? GetCacheMode(HbmCacheMode cacheMode) - { - switch (cacheMode) - { - case HbmCacheMode.Get: - return CacheMode.Get; - case HbmCacheMode.Ignore: - return CacheMode.Ignore; - case HbmCacheMode.Normal: - return CacheMode.Normal; - case HbmCacheMode.Put: - return CacheMode.Put; - case HbmCacheMode.Refresh: - return CacheMode.Refresh; - default: - throw new ArgumentOutOfRangeException("cacheMode"); - } - } - } -} Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs 2010-01-05 22:16:33 UTC (rev 4900) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs 2010-01-05 22:56:37 UTC (rev 4901) @@ -37,7 +37,7 @@ } compositeId.Table.SetIdentifierValue(compositeId); - compositeId.NullValue = GetXmlEnumAttribute(idSchema.unsavedvalue); + compositeId.NullValue = idSchema.unsavedvalue.ToNullValue(); System.Type compIdClass = compositeId.ComponentClass; if (!ReflectHelper.OverridesEquals(compIdClass)) Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs 2010-01-05 22:16:33 UTC (rev 4900) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs 2010-01-05 22:56:37 UTC (rev 4901) @@ -823,7 +823,7 @@ { if (cacheSchema != null) { - collection.CacheConcurrencyStrategy = GetXmlEnumAttribute(cacheSchema.usage); + collection.CacheConcurrencyStrategy = cacheSchema.usage.ToCacheConcurrencyStrategy(); collection.CacheRegionName = cacheSchema.region; } } Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/NamedQueryBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/NamedQueryBinder.cs 2010-01-05 22:16:33 UTC (rev 4900) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/NamedQueryBinder.cs 2010-01-05 22:56:37 UTC (rev 4901) @@ -28,7 +28,7 @@ FlushMode flushMode = FlushModeConverter.GetFlushMode(querySchema); CacheMode? cacheMode = (querySchema.cachemodeSpecified) - ? CacheModeConverter.GetCacheMode(querySchema.cachemode) + ? querySchema.cachemode.ToCacheMode() : null; IDictionary<string,string> parameterTypes = new LinkedHashMap<string,string>(); Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/NamedSQLQueryBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/NamedSQLQueryBinder.cs 2010-01-05 22:16:33 UTC (rev 4900) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/NamedSQLQueryBinder.cs 2010-01-05 22:56:37 UTC (rev 4901) @@ -29,7 +29,7 @@ FlushMode flushMode = FlushModeConverter.GetFlushMode(querySchema); CacheMode? cacheMode = (querySchema.cachemodeSpecified) - ? CacheModeConverter.GetCacheMode(querySchema.cachemode) + ? querySchema.cachemode.ToCacheMode() : null; IDictionary<string,string> parameterTypes = new LinkedHashMap<string,string>(); Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs 2010-01-05 22:16:33 UTC (rev 4900) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs 2010-01-05 22:56:37 UTC (rev 4901) @@ -259,7 +259,7 @@ { if (cacheSchema != null) { - rootClass.CacheConcurrencyStrategy = GetXmlEnumAttribute(cacheSchema.usage); + rootClass.CacheConcurrencyStrategy = cacheSchema.usage.ToCacheConcurrencyStrategy(); rootClass.CacheRegionName = cacheSchema.region; } } Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-01-05 22:16:33 UTC (rev 4900) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-01-05 22:56:37 UTC (rev 4901) @@ -881,7 +881,6 @@ <Compile Include="Cfg\MappingSchema\MappingDocumentParser.cs" /> <Compile Include="Cfg\XmlHbmBinding\AuxiliaryDatabaseObjectFactory.cs" /> <Compile Include="Cfg\MappingSchema\HbmFilterDef.cs" /> - <Compile Include="Cfg\XmlHbmBinding\CacheModeConverter.cs" /> <Compile Include="Cfg\XmlHbmBinding\ClassCompositeIdBinder.cs" /> <Compile Include="Cfg\XmlHbmBinding\ClassDiscriminatorBinder.cs" /> <Compile Include="Cfg\XmlHbmBinding\ClassIdBinder.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-01-05 22:16:39
|
Revision: 4900 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4900&view=rev Author: fabiomaulo Date: 2010-01-05 22:16:33 +0000 (Tue, 05 Jan 2010) Log Message: ----------- Removed unused code Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs 2010-01-05 22:09:23 UTC (rev 4899) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs 2010-01-05 22:16:33 UTC (rev 4900) @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.IO; using System.Reflection; -using System.Xml; using System.Xml.Serialization; using log4net; @@ -136,44 +134,6 @@ return ClassForNameChecked(unqualifiedName, mappings, "unknown class {0}").AssemblyQualifiedName; } - protected static T Deserialize<T>(XmlNode node) - { - using (StringReader reader = new StringReader(node.OuterXml)) - return (T) new XmlSerializer(typeof (T)).Deserialize(reader); - } - - protected static XmlNode Serialize<T>(T hbmElement) - { - // TODO : this method is only for TEMPORAL usage; should be removed after refactorize all binders - var xmlTypeMapping = typeof (T); - return Serialize(xmlTypeMapping, hbmElement); - } - - protected static XmlNode Serialize(System.Type xmlTypeMapping, object hbmElement) - { - // TODO : this method is only for TEMPORAL usage; should be removed after refactorize all binders - var serializer = new XmlSerializer(xmlTypeMapping); - using (var memStream = new MemoryStream(2000)) - using (var xmlWriter = XmlWriter.Create(memStream)) - { - serializer.Serialize(xmlWriter, hbmElement); - memStream.Position = 0; - using (XmlReader reader = XmlReader.Create(memStream)) - { - var hbmDocument = new XmlDocument(); - hbmDocument.Load(reader); - // note that the prefix has absolutely nothing to do with what the user - // selects as their prefix in the document. It is the prefix we use to - // build the XPath and the nsmgr takes care of translating our prefix into - // the user defined prefix... - var namespaceManager = new XmlNamespaceManager(hbmDocument.NameTable); - namespaceManager.AddNamespace(HbmConstants.nsPrefix, MappingSchemaXMLNS); - - return hbmDocument.DocumentElement; - } - } - } - protected static string GetXmlEnumAttribute(Enum cascadeStyle) { MemberInfo[] memberInfo = cascadeStyle.GetType().GetMember(cascadeStyle.ToString()); @@ -189,22 +149,6 @@ return null; } - protected static bool IsTrue(string xmlNodeValue) - { - return "true".Equals(xmlNodeValue) || "1".Equals(xmlNodeValue); - } - - protected static bool IsFalse(string xmlNodeValue) - { - return "false".Equals(xmlNodeValue) || "0".Equals(xmlNodeValue); - } - - protected static string GetAttributeValue(XmlNode node, string attributeName) - { - XmlAttribute att = node.Attributes[attributeName]; - return att != null ? att.Value : null; - } - public static IDictionary<string, MetaAttribute> GetMetas(IDecoratable decoratable, IDictionary<string, MetaAttribute> inheritedMeta) { return GetMetas(decoratable, inheritedMeta, false); @@ -247,57 +191,5 @@ } return map; } - - public static IDictionary<string, MetaAttribute> GetMetas(XmlNodeList nodes, IDictionary<string, MetaAttribute> inheritedMeta) - { - return GetMetas(nodes, inheritedMeta, false); - } - - public static IDictionary<string, MetaAttribute> GetMetas(XmlNodeList nodes, IDictionary<string, MetaAttribute> inheritedMeta, bool onlyInheritable) - { - var map = new Dictionary<string, MetaAttribute>(inheritedMeta); - foreach (XmlNode metaNode in nodes) - { - if(metaNode.Name != "meta") - { - continue; - } - var inheritableValue = GetAttributeValue(metaNode, "inherit"); - bool inheritable = inheritableValue != null ? IsTrue(inheritableValue) : true; - if (onlyInheritable & !inheritable) - { - continue; - } - string name = GetAttributeValue(metaNode, "attribute"); - - MetaAttribute meta; - MetaAttribute inheritedAttribute; - map.TryGetValue(name, out meta); - inheritedMeta.TryGetValue(name, out inheritedAttribute); - if (meta == null) - { - meta = new MetaAttribute(name); - map[name] = meta; - } - else if (meta == inheritedAttribute) - { - meta = new MetaAttribute(name); - map[name] = meta; - } - meta.AddValue(metaNode.InnerText); - } - return map; - } - - protected XmlNamespaceManager GetNamespaceManager(XmlNode parentNode) - { - // note that the prefix has absolutely nothing to do with what the user - // selects as their prefix in the document. It is the prefix we use to - // build the XPath and the nsmgr takes care of translating our prefix into - // the user defined prefix... - var namespaceManager = new XmlNamespaceManager(parentNode.OwnerDocument.NameTable); - namespaceManager.AddNamespace(HbmConstants.nsPrefix, MappingSchemaXMLNS); - return namespaceManager; - } } } \ 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-01-05 22:09:34
|
Revision: 4899 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4899&view=rev Author: fabiomaulo Date: 2010-01-05 22:09:23 +0000 (Tue, 05 Jan 2010) Log Message: ----------- Removed the usage of System.Xml from binders. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmAny.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmArray.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmBag.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmCollectionId.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmComponent.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmDynamicComponent.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmElement.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmIdbag.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmIndex.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmIndexManyToAny.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmIndexManyToMany.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmKey.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmKeyManyToOne.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmKeyProperty.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmList.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToAny.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToMany.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToOne.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmMap.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmMapKey.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmMapKeyManyToMany.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmOneToOne.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmPrimitiveArray.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmProperty.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmSet.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IEntityPropertyMapping.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/FiltersBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/JoinedSubclassBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/MappingRootBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/SubclassBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/UnionSubclassBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ValuePropertyBinder.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/FilterTest/defs.hbm.xml Added Paths: ----------- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmCompositeElement.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmCompositeIndex.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmCompositeMapKey.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmNestedCompositeElement.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmOneToMany.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IAnyMapping.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/ICollectionPropertiesMapping.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/ICollectionSqlsMapping.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IComponentMapping.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IIndexedCollectionMapping.cs trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IRelationship.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/IdGeneratorBinder.cs Removed Paths: ------------- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/ICollectionPropertyMapping.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -965,11 +965,15 @@ if (FilterDefinitions.Count > 0) { filterNames.Clear(); - var filterables = new JoinedEnumerable(ClassMappings, CollectionMappings); - foreach (IFilterable filterable in filterables) + foreach (var persistentClass in ClassMappings) { - filterNames.AddAll(filterable.FilterMap.Keys); + filterNames.AddAll(persistentClass.FilterMap.Keys); } + foreach (var collectionMapping in CollectionMappings) + { + filterNames.AddAll(collectionMapping.FilterMap.Keys); + filterNames.AddAll(collectionMapping.ManyToManyFilterMap.Keys); + } foreach (var filterName in FilterDefinitions.Keys) { if (!filterNames.Contains(filterName)) Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmAny.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmAny.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmAny.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -3,7 +3,7 @@ namespace NHibernate.Cfg.MappingSchema { - public partial class HbmAny : AbstractDecoratable, IEntityPropertyMapping, IColumnsMapping + public partial class HbmAny : AbstractDecoratable, IEntityPropertyMapping, IColumnsMapping, IAnyMapping { #region Implementation of IEntityPropertyMapping @@ -17,7 +17,7 @@ get { return access; } } - public bool OptimisticKock + public bool OptimisticLock { get { return optimisticlock; } } @@ -57,5 +57,22 @@ }; } } + + #region Implementation of IAnyMapping + + public string MetaType + { + get { return metatype; } + } + + public ICollection<HbmMetaValue> MetaValues + { + get + { + return metavalue ?? new HbmMetaValue[0]; + } + } + + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmArray.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmArray.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmArray.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -1,8 +1,8 @@ -using System; +using System.Collections.Generic; namespace NHibernate.Cfg.MappingSchema { - public partial class HbmArray : AbstractDecoratable, ICollectionPropertyMapping + public partial class HbmArray : AbstractDecoratable, ICollectionPropertiesMapping, IIndexedCollectionMapping { #region Implementation of IEntityPropertyMapping @@ -16,7 +16,7 @@ get { return access; } } - public bool OptimisticKock + public bool OptimisticLock { get { return optimisticlock; } } @@ -41,5 +41,151 @@ #endregion + #region Implementation of ICollectionSqlsMapping + + public HbmLoader SqlLoader + { + get { return loader; } + } + + public HbmCustomSQL SqlInsert + { + get { return sqlinsert; } + } + + public HbmCustomSQL SqlUpdate + { + get { return sqlupdate; } + } + + public HbmCustomSQL SqlDelete + { + get { return sqldelete; } + } + + public HbmCustomSQL SqlDeleteAll + { + get { return sqldeleteall; } + } + + #endregion + + #region Implementation of ICollectionPropertyMapping + + public bool Inverse + { + get { return inverse; } + } + + public bool Mutable + { + get { return mutable; } + } + + public string OrderBy + { + get { return null; } + } + + public string Where + { + get { return @where; } + } + + public int? BatchSize + { + get { return batchsizeSpecified ? batchsize : (int?)null; } + } + + public string PersisterQualifiedName + { + get { return persister; } + } + + public string CollectionType + { + get { return collectiontype; } + } + + public HbmCollectionFetchMode? FetchMode + { + get { return fetchSpecified ? (HbmCollectionFetchMode?) fetch : null; } + } + + public HbmOuterJoinStrategy? OuterJoin + { + get { return outerjoinSpecified ? (HbmOuterJoinStrategy?) outerjoin : null; } + } + + public HbmCollectionLazy? Lazy + { + get { return null; } + } + + public string Table + { + get { return table; } + } + + public string Schema + { + get { return schema; } + } + + public string Catalog + { + get { return catalog; } + } + + public string Check + { + get { return check; } + } + + public object ElementRelationship + { + get { return Item1; } + } + + public string Sort + { + get { return null; } + } + + public bool? Generic + { + get { return null; } + } + + public IEnumerable<HbmFilter> Filters + { + get { yield break; } + } + + public HbmKey Key + { + get { return key; } + } + + public HbmCache Cache + { + get { return cache; } + } + + #endregion + + #region Implementation of IIndexedCollection + + public HbmListIndex ListIndex + { + get { return Item as HbmListIndex; } + } + + public HbmIndex Index + { + get { return Item as HbmIndex; } + } + + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmBag.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmBag.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmBag.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -1,6 +1,9 @@ +using System; +using System.Collections.Generic; + namespace NHibernate.Cfg.MappingSchema { - public partial class HbmBag : AbstractDecoratable, ICollectionPropertyMapping + public partial class HbmBag : AbstractDecoratable, ICollectionPropertiesMapping { #region Implementation of IEntityPropertyMapping @@ -14,7 +17,7 @@ get { return access; } } - public bool OptimisticKock + public bool OptimisticLock { get { return optimisticlock; } } @@ -38,5 +41,138 @@ } #endregion + + #region Implementation of ICollectionSqlsMapping + + public HbmLoader SqlLoader + { + get { return loader; } + } + + public HbmCustomSQL SqlInsert + { + get { return sqlinsert; } + } + + public HbmCustomSQL SqlUpdate + { + get { return sqlupdate; } + } + + public HbmCustomSQL SqlDelete + { + get { return sqldelete; } + } + + public HbmCustomSQL SqlDeleteAll + { + get { return sqldeleteall; } + } + + #endregion + + #region Implementation of ICollectionPropertiesMapping + + public bool Inverse + { + get { return inverse; } + } + + public bool Mutable + { + get { return mutable; } + } + + public string OrderBy + { + get { return orderby; } + } + + public string Where + { + get { return where; } + } + + public int? BatchSize + { + get { return batchsizeSpecified ? batchsize: (int?) null; } + } + + public string PersisterQualifiedName + { + get { return persister; } + } + + public string CollectionType + { + get { return collectiontype; } + } + + public HbmCollectionFetchMode? FetchMode + { + get { return fetchSpecified ? fetch: (HbmCollectionFetchMode?) null; } + } + + public HbmOuterJoinStrategy? OuterJoin + { + get { return outerjoinSpecified ? outerjoin:(HbmOuterJoinStrategy?) null; } + } + + public HbmCollectionLazy? Lazy + { + get { return lazySpecified ? lazy : (HbmCollectionLazy?)null; } + } + + public string Table + { + get { return table; } + } + + public string Schema + { + get { return schema; } + } + + public string Catalog + { + get { return catalog; } + } + + public string Check + { + get { return check; } + } + + public object ElementRelationship + { + get { return Item; } + } + + public string Sort + { + get { return null; } + } + + public bool? Generic + { + get { return genericSpecified ? generic: (bool?) null; } + } + + public IEnumerable<HbmFilter> Filters + { + get { return filter ?? new HbmFilter[0]; } + } + + public HbmKey Key + { + get { return key; } + } + + public HbmCache Cache + { + get { return cache; } + } + + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmCollectionId.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmCollectionId.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmCollectionId.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -2,7 +2,7 @@ namespace NHibernate.Cfg.MappingSchema { - public partial class HbmCollectionId: IColumnsMapping + public partial class HbmCollectionId : IColumnsMapping, ITypeMapping { #region Implementation of IColumnsMapping @@ -28,5 +28,14 @@ }; } } + + #region Implementation of ITypeMapping + + public HbmType Type + { + get { return !string.IsNullOrEmpty(type) ? new HbmType { name = type } : null; } + } + + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmComponent.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmComponent.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmComponent.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -4,10 +4,25 @@ namespace NHibernate.Cfg.MappingSchema { - public partial class HbmComponent : AbstractDecoratable, IEntityPropertyMapping, IPropertiesContainerMapping + public partial class HbmComponent : AbstractDecoratable, IEntityPropertyMapping, IComponentMapping { #region Implementation of IEntityPropertyMapping + public string Class + { + get { return @class; } + } + + public HbmParent Parent + { + get { return parent; } + } + + public string EmbeddedNode + { + get { return node; } + } + public string Name { get { return name; } @@ -18,7 +33,7 @@ get { return access; } } - public bool OptimisticKock + public bool OptimisticLock { get { return optimisticlock; } } Added: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmCompositeElement.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmCompositeElement.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmCompositeElement.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace NHibernate.Cfg.MappingSchema +{ + public partial class HbmCompositeElement : AbstractDecoratable, IComponentMapping + { + #region Implementation of IComponentMapping + + public string Class + { + get { return @class; } + } + + public HbmParent Parent + { + get { return parent; } + } + + public string EmbeddedNode + { + get { return node;} + } + + public string Name + { + get { return null; } + } + + #endregion + + #region Overrides of AbstractDecoratable + + protected override HbmMeta[] Metadatas + { + get { return meta ?? new HbmMeta[0]; } + } + + #endregion + + #region Implementation of IPropertiesContainerMapping + + public IEnumerable<IEntityPropertyMapping> Properties + { + get { return Items != null ? Items.Cast<IEntityPropertyMapping>() : new IEntityPropertyMapping[0]; } + } + + #endregion + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmCompositeIndex.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmCompositeIndex.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmCompositeIndex.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace NHibernate.Cfg.MappingSchema +{ + public partial class HbmCompositeIndex: IComponentMapping + { + #region Implementation of IPropertiesContainerMapping + + public IEnumerable<IEntityPropertyMapping> Properties + { + get { return Items != null ? Items.Cast<IEntityPropertyMapping>() : new IEntityPropertyMapping[0]; } + } + + #endregion + + #region Implementation of IComponentMapping + + public string Class + { + get { return @class; } + } + + public HbmParent Parent + { + get { return null; } + } + + public string EmbeddedNode + { + get { return null; } + } + + public string Name + { + get { return null; } + } + + #endregion + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmCompositeMapKey.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmCompositeMapKey.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmCompositeMapKey.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace NHibernate.Cfg.MappingSchema +{ + public partial class HbmCompositeMapKey: IComponentMapping + { + #region Implementation of IPropertiesContainerMapping + + public IEnumerable<IEntityPropertyMapping> Properties + { + get { return Items != null ? Items.Cast<IEntityPropertyMapping>() : new IEntityPropertyMapping[0]; } + } + + #endregion + + #region Implementation of IComponentMapping + + public string Class + { + get { return @class; } + } + + public HbmParent Parent + { + get { return null; } + } + + public string EmbeddedNode + { + get { return null; } + } + + public string Name + { + get { return null; } + } + + #endregion + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmDynamicComponent.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmDynamicComponent.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmDynamicComponent.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; @@ -3,8 +4,23 @@ namespace NHibernate.Cfg.MappingSchema { - public partial class HbmDynamicComponent: AbstractDecoratable, IEntityPropertyMapping, IPropertiesContainerMapping + public partial class HbmDynamicComponent: AbstractDecoratable, IEntityPropertyMapping, IComponentMapping { #region Implementation of IEntityPropertyMapping + public string Class + { + get { return null; } + } + + public HbmParent Parent + { + get { return null; } + } + + public string EmbeddedNode + { + get { return node; } + } + public string Name { @@ -17,7 +33,7 @@ get { return access; } } - public bool OptimisticKock + public bool OptimisticLock { get { return optimisticlock; } } Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmElement.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmElement.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmElement.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -23,16 +23,18 @@ } else { - yield return new HbmColumn - { - name = column, - length = length, - scale = scale, - precision = precision, - notnull = notnull, - unique = unique, - uniqueSpecified = true, - }; + yield return + new HbmColumn + { + name = column, + length = length, + scale = scale, + precision = precision, + notnull = notnull, + notnullSpecified = true, + unique = unique, + uniqueSpecified = true, + }; } } Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmIdbag.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmIdbag.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmIdbag.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -1,6 +1,8 @@ +using System.Collections.Generic; + namespace NHibernate.Cfg.MappingSchema { - public partial class HbmIdbag : AbstractDecoratable, ICollectionPropertyMapping + public partial class HbmIdbag : AbstractDecoratable, ICollectionPropertiesMapping { #region Implementation of IEntityPropertyMapping @@ -14,7 +16,7 @@ get { return access; } } - public bool OptimisticKock + public bool OptimisticLock { get { return optimisticlock; } } @@ -38,5 +40,139 @@ } #endregion + + #region Implementation of ICollectionSqlsMapping + + public HbmLoader SqlLoader + { + get { return loader; } + } + + public HbmCustomSQL SqlInsert + { + get { return sqlinsert; } + } + + public HbmCustomSQL SqlUpdate + { + get { return sqlupdate; } + } + + public HbmCustomSQL SqlDelete + { + get { return sqldelete; } + } + + public HbmCustomSQL SqlDeleteAll + { + get { return sqldeleteall; } + } + + #endregion + + #region Implementation of ICollectionPropertiesMapping + + public bool Inverse + { + get { return inverse; } + } + + public bool Mutable + { + get { return mutable; } + } + + public string OrderBy + { + get { return orderby; } + } + + public string Where + { + get { return where; } + } + + public int? BatchSize + { + get { return batchsizeSpecified ? batchsize : (int?)null; } + } + + public string PersisterQualifiedName + { + get { return persister; } + } + + public string CollectionType + { + get { return collectiontype; } + } + + public HbmCollectionFetchMode? FetchMode + { + get { return fetchSpecified ? fetch : (HbmCollectionFetchMode?)null; } + } + + public HbmOuterJoinStrategy? OuterJoin + { + get { return outerjoinSpecified ? outerjoin : (HbmOuterJoinStrategy?)null; } + } + + public HbmCollectionLazy? Lazy + { + get { return lazySpecified ? lazy : (HbmCollectionLazy?)null; } + } + + public string Table + { + get { return table; } + } + + public string Schema + { + get { return schema; } + } + + public string Catalog + { + get { return catalog; } + } + + public string Check + { + get { return check; } + } + + public object ElementRelationship + { + get { return Item; } + } + + public string Sort + { + get { return null; } + } + + public bool? Generic + { + get { return genericSpecified ? generic : (bool?)null; } + } + + public IEnumerable<HbmFilter> Filters + { + get { return filter ?? new HbmFilter[0]; } + } + + public HbmKey Key + { + get { return key; } + } + + public HbmCache Cache + { + get { return cache; } + } + + #endregion + } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmIndex.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmIndex.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmIndex.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; namespace NHibernate.Cfg.MappingSchema @@ -2,3 +3,3 @@ { - public partial class HbmIndex: IColumnsMapping + public partial class HbmIndex: IColumnsMapping, ITypeMapping { @@ -28,5 +29,14 @@ }; } } + + #region Implementation of ITypeMapping + + public HbmType Type + { + get { return string.IsNullOrEmpty(type) ? null : new HbmType {name = type}; } + } + + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmIndexManyToAny.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmIndexManyToAny.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmIndexManyToAny.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; namespace NHibernate.Cfg.MappingSchema @@ -2,3 +3,3 @@ { - public partial class HbmIndexManyToAny: IColumnsMapping + public partial class HbmIndexManyToAny: IColumnsMapping, IAnyMapping { @@ -27,5 +28,19 @@ }; } } + + #region Implementation of IAnyMapping + + public string MetaType + { + get { return metatype; } + } + + public ICollection<HbmMetaValue> MetaValues + { + get { return new HbmMetaValue[0]; } + } + + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmIndexManyToMany.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmIndexManyToMany.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmIndexManyToMany.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -2,7 +2,7 @@ namespace NHibernate.Cfg.MappingSchema { - public partial class HbmIndexManyToMany: IColumnsMapping + public partial class HbmIndexManyToMany: IColumnsMapping, IRelationship { #region Implementation of IColumnsMapping @@ -27,5 +27,24 @@ }; } } + + #region Implementation of IRelationship + + public string EntityName + { + get { return entityname; } + } + + public string Class + { + get { return @class; } + } + + public HbmNotFoundMode NotFoundMode + { + get { return HbmNotFoundMode.Exception; } + } + + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmKey.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmKey.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmKey.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -31,5 +31,15 @@ }; } } + + public bool? IsNullable + { + get { return notnullSpecified ? !notnull : (bool?)null; } + } + + public bool? IsUpdatable + { + get { return updateSpecified ? update : (bool?)null; } + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmKeyManyToOne.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmKeyManyToOne.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmKeyManyToOne.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; namespace NHibernate.Cfg.MappingSchema @@ -2,3 +3,3 @@ { - public partial class HbmKeyManyToOne: IColumnsMapping + public partial class HbmKeyManyToOne : AbstractDecoratable, IColumnsMapping, IRelationship, IEntityPropertyMapping { @@ -28,5 +29,57 @@ }; } } + + #region Overrides of AbstractDecoratable + + protected override HbmMeta[] Metadatas + { + get { return meta ?? new HbmMeta[0]; } + } + + #endregion + + public HbmRestrictedLaziness? Lazy + { + get { return lazySpecified ? lazy : (HbmRestrictedLaziness?)null; } + } + + #region Implementation of IRelationship + + public string EntityName + { + get { return entityname; } + } + + public string Class + { + get { return @class; } + } + + public HbmNotFoundMode NotFoundMode + { + get { return notfound; } + } + + #endregion + + #region Implementation of IEntityPropertyMapping + + public string Name + { + get { return name; } + } + + public string Access + { + get { return access; } + } + + public bool OptimisticLock + { + get { return false; } + } + + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmKeyProperty.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmKeyProperty.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmKeyProperty.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; namespace NHibernate.Cfg.MappingSchema @@ -2,3 +3,3 @@ { - public partial class HbmKeyProperty: IColumnsMapping, ITypeMapping + public partial class HbmKeyProperty : AbstractDecoratable, IColumnsMapping, ITypeMapping, IEntityPropertyMapping { @@ -38,5 +39,33 @@ } #endregion + + #region Overrides of AbstractDecoratable + + protected override HbmMeta[] Metadatas + { + get { return meta ?? new HbmMeta[0]; } + } + + #endregion + + #region Implementation of IEntityPropertyMapping + + public string Name + { + get { return name; } + } + + public string Access + { + get { return access; } + } + + public bool OptimisticLock + { + get { return false; } + } + + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmList.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmList.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmList.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -1,6 +1,8 @@ +using System.Collections.Generic; + namespace NHibernate.Cfg.MappingSchema { - public partial class HbmList : AbstractDecoratable, ICollectionPropertyMapping + public partial class HbmList : AbstractDecoratable, ICollectionPropertiesMapping, IIndexedCollectionMapping { #region Implementation of IEntityPropertyMapping @@ -14,7 +16,7 @@ get { return access; } } - public bool OptimisticKock + public bool OptimisticLock { get { return optimisticlock; } } @@ -39,5 +41,151 @@ #endregion + #region Implementation of ICollectionSqlsMapping + + public HbmLoader SqlLoader + { + get { return loader; } + } + + public HbmCustomSQL SqlInsert + { + get { return sqlinsert; } + } + + public HbmCustomSQL SqlUpdate + { + get { return sqlupdate; } + } + + public HbmCustomSQL SqlDelete + { + get { return sqldelete; } + } + + public HbmCustomSQL SqlDeleteAll + { + get { return sqldeleteall; } + } + + #endregion + + #region Implementation of IIndexedCollection + + public HbmListIndex ListIndex + { + get { return Item as HbmListIndex; } + } + + public HbmIndex Index + { + get { return Item as HbmIndex; } + } + + #endregion + + #region Implementation of ICollectionPropertiesMapping + + public bool Inverse + { + get { return inverse; } + } + + public bool Mutable + { + get { return mutable; } + } + + public string OrderBy + { + get { return orderby; } + } + + public string Where + { + get { return where; } + } + + public int? BatchSize + { + get { return batchsizeSpecified ? batchsize : (int?)null; } + } + + public string PersisterQualifiedName + { + get { return persister; } + } + + public string CollectionType + { + get { return collectiontype; } + } + + public HbmCollectionFetchMode? FetchMode + { + get { return fetchSpecified ? fetch : (HbmCollectionFetchMode?)null; } + } + + public HbmOuterJoinStrategy? OuterJoin + { + get { return outerjoinSpecified ? outerjoin : (HbmOuterJoinStrategy?)null; } + } + + public HbmCollectionLazy? Lazy + { + get { return lazySpecified ? lazy : (HbmCollectionLazy?)null; } + } + + public string Table + { + get { return table; } + } + + public string Schema + { + get { return schema; } + } + + public string Catalog + { + get { return catalog; } + } + + public string Check + { + get { return check; } + } + + public object ElementRelationship + { + get { return Item1; } + } + + public string Sort + { + get { return null; } + } + + public bool? Generic + { + get { return genericSpecified ? generic : (bool?)null; } + } + + public IEnumerable<HbmFilter> Filters + { + get { return filter ?? new HbmFilter[0]; } + } + + public HbmKey Key + { + get { return key; } + } + + public HbmCache Cache + { + get { return cache; } + } + + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToAny.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToAny.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToAny.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; namespace NHibernate.Cfg.MappingSchema @@ -2,3 +3,3 @@ { - public partial class HbmManyToAny: IColumnsMapping + public partial class HbmManyToAny : IColumnsMapping, IAnyMapping { @@ -28,5 +29,22 @@ }; } } + + #region Implementation of IAnyMapping + + public string MetaType + { + get { return metatype; } + } + + public ICollection<HbmMetaValue> MetaValues + { + get + { + return metavalue ?? new HbmMetaValue[0]; + } + } + + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToMany.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToMany.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToMany.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; @@ -3,7 +4,6 @@ namespace NHibernate.Cfg.MappingSchema { - public partial class HbmManyToMany: IColumnsMapping + public partial class HbmManyToMany : IColumnsMapping, IFormulasMapping, IRelationship { - #region Implementation of IColumnsMapping @@ -26,8 +26,50 @@ yield return new HbmColumn { name = column, + unique = unique, + uniqueSpecified = true }; } } + + #region Implementation of IFormulasMapping + + public IEnumerable<HbmFormula> Formulas + { + get { return Items != null ? Items.OfType<HbmFormula>() : AsFormulas(); } + } + + private IEnumerable<HbmFormula> AsFormulas() + { + if (string.IsNullOrEmpty(formula)) + { + yield break; + } + else + { + yield return new HbmFormula { Text = new[] { formula } }; + } + } + + #endregion + + #region Implementation of IRelationship + + public string EntityName + { + get { return entityname; } + } + + public string Class + { + get { return @class; } + } + + public HbmNotFoundMode NotFoundMode + { + get { return notfound; } + } + + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToOne.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToOne.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmManyToOne.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -4,7 +4,7 @@ namespace NHibernate.Cfg.MappingSchema { - public partial class HbmManyToOne : AbstractDecoratable, IEntityPropertyMapping, IColumnsMapping, IFormulasMapping + public partial class HbmManyToOne : AbstractDecoratable, IEntityPropertyMapping, IColumnsMapping, IFormulasMapping, IRelationship { #region Implementation of IEntityPropertyMapping @@ -18,7 +18,7 @@ get { return access; } } - public bool OptimisticKock + public bool OptimisticLock { get { return optimisticlock; } } @@ -84,5 +84,29 @@ } #endregion + + #region Implementation of IRelationship + + public string EntityName + { + get { return entityname; } + } + + public string Class + { + get { return @class; } + } + + public HbmNotFoundMode NotFoundMode + { + get { return notfound; } + } + + #endregion + + public HbmLaziness? Lazy + { + get { return lazySpecified ? lazy : (HbmLaziness?) null;} + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmMap.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmMap.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmMap.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -1,6 +1,8 @@ +using System.Collections.Generic; + namespace NHibernate.Cfg.MappingSchema { - public partial class HbmMap : AbstractDecoratable, ICollectionPropertyMapping + public partial class HbmMap : AbstractDecoratable, ICollectionPropertiesMapping { #region Implementation of IEntityPropertyMapping @@ -14,7 +16,7 @@ get { return access; } } - public bool OptimisticKock + public bool OptimisticLock { get { return optimisticlock; } } @@ -39,5 +41,137 @@ #endregion + #region Implementation of ICollectionSqlsMapping + + public HbmLoader SqlLoader + { + get { return loader; } + } + + public HbmCustomSQL SqlInsert + { + get { return sqlinsert; } + } + + public HbmCustomSQL SqlUpdate + { + get { return sqlupdate; } + } + + public HbmCustomSQL SqlDelete + { + get { return sqldelete; } + } + + public HbmCustomSQL SqlDeleteAll + { + get { return sqldeleteall; } + } + + #endregion + + #region Implementation of ICollectionPropertiesMapping + + public bool Inverse + { + get { return inverse; } + } + + public bool Mutable + { + get { return mutable; } + } + + public string OrderBy + { + get { return orderby; } + } + + public string Where + { + get { return where; } + } + + public int? BatchSize + { + get { return batchsizeSpecified ? batchsize : (int?)null; } + } + + public string PersisterQualifiedName + { + get { return persister; } + } + + public string CollectionType + { + get { return collectiontype; } + } + + public HbmCollectionFetchMode? FetchMode + { + get { return fetchSpecified ? fetch : (HbmCollectionFetchMode?)null; } + } + + public HbmOuterJoinStrategy? OuterJoin + { + get { return outerjoinSpecified ? outerjoin : (HbmOuterJoinStrategy?)null; } + } + + public HbmCollectionLazy? Lazy + { + get { return lazySpecified ? lazy : (HbmCollectionLazy?)null; } + } + + public string Table + { + get { return table; } + } + + public string Schema + { + get { return schema; } + } + + public string Catalog + { + get { return catalog; } + } + + public string Check + { + get { return check; } + } + + public object ElementRelationship + { + get { return Item1; } + } + + public string Sort + { + get { return sort; } + } + + public bool? Generic + { + get { return genericSpecified ? generic : (bool?)null; } + } + + public IEnumerable<HbmFilter> Filters + { + get { return filter ?? new HbmFilter[0]; } + } + + public HbmKey Key + { + get { return key; } + } + + public HbmCache Cache + { + get { return cache; } + } + + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmMapKey.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmMapKey.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmMapKey.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; @@ -3,5 +4,5 @@ namespace NHibernate.Cfg.MappingSchema { - public partial class HbmMapKey: IColumnsMapping + public partial class HbmMapKey: IColumnsMapping, ITypeMapping { @@ -51,5 +52,14 @@ } #endregion + + #region Implementation of ITypeMapping + + public HbmType Type + { + get { return string.IsNullOrEmpty(type) ? null : new HbmType { name = type }; } + } + + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmMapKeyManyToMany.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmMapKeyManyToMany.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmMapKeyManyToMany.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; @@ -3,5 +4,5 @@ namespace NHibernate.Cfg.MappingSchema { - public partial class HbmMapKeyManyToMany: IColumnsMapping, IFormulasMapping + public partial class HbmMapKeyManyToMany: IColumnsMapping, IFormulasMapping, IRelationship { @@ -50,5 +51,24 @@ } #endregion + + #region Implementation of IRelationship + + public string EntityName + { + get { return entityname; } + } + + public string Class + { + get { return @class; } + } + + public HbmNotFoundMode NotFoundMode + { + get { return HbmNotFoundMode.Exception; } + } + + #endregion } } \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmNestedCompositeElement.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmNestedCompositeElement.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmNestedCompositeElement.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -0,0 +1,60 @@ +using System.Collections.Generic; +using System.Linq; + +namespace NHibernate.Cfg.MappingSchema +{ + public partial class HbmNestedCompositeElement : AbstractDecoratable, IEntityPropertyMapping, IComponentMapping + { + #region Implementation of IPropertiesContainerMapping + + public IEnumerable<IEntityPropertyMapping> Properties + { + get { return Items != null ? Items.Cast<IEntityPropertyMapping>() : new IEntityPropertyMapping[0]; } + } + + #endregion + + #region Implementation of IComponentMapping + + public string Class + { + get { return @class; } + } + + public HbmParent Parent + { + get { return parent; } + } + + public string EmbeddedNode + { + get { return node; } + } + + public string Name + { + get { return name; } + } + + public string Access + { + get { return access; } + } + + public bool OptimisticLock + { + get { return true; } + } + + #endregion + + #region Overrides of AbstractDecoratable + + protected override HbmMeta[] Metadatas + { + get { return new HbmMeta[0];} + } + + #endregion + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmOneToMany.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmOneToMany.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmOneToMany.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -0,0 +1,26 @@ +using System; + +namespace NHibernate.Cfg.MappingSchema +{ + public partial class HbmOneToMany: IRelationship + { + #region Implementation of IRelationship + + public string EntityName + { + get { return entityname; } + } + + public string Class + { + get { return @class; } + } + + public HbmNotFoundMode NotFoundMode + { + get { return notfound; } + } + + #endregion + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmOneToOne.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmOneToOne.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmOneToOne.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -2,7 +2,7 @@ namespace NHibernate.Cfg.MappingSchema { - public partial class HbmOneToOne : AbstractDecoratable, IEntityPropertyMapping, IFormulasMapping + public partial class HbmOneToOne : AbstractDecoratable, IEntityPropertyMapping, IFormulasMapping, IRelationship { #region Implementation of IEntityPropertyMapping @@ -16,7 +16,7 @@ get { return access; } } - public bool OptimisticKock + public bool OptimisticLock { get { return true; } } @@ -53,5 +53,28 @@ #endregion + #region Implementation of IRelationship + + public string EntityName + { + get { return entityname; } + } + + public string Class + { + get { return @class; } + } + + public HbmNotFoundMode NotFoundMode + { + get { return HbmNotFoundMode.Exception; } + } + + #endregion + + public HbmLaziness? Lazy + { + get { return lazySpecified ? lazy : (HbmLaziness?)null; } + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmPrimitiveArray.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmPrimitiveArray.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmPrimitiveArray.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -1,6 +1,8 @@ +using System.Collections.Generic; + namespace NHibernate.Cfg.MappingSchema { - public partial class HbmPrimitiveArray : AbstractDecoratable, ICollectionPropertyMapping + public partial class HbmPrimitiveArray : AbstractDecoratable, ICollectionPropertiesMapping, IIndexedCollectionMapping { #region Implementation of IEntityPropertyMapping @@ -14,7 +16,7 @@ get { return access; } } - public bool OptimisticKock + public bool OptimisticLock { get { return optimisticlock; } } @@ -39,5 +41,151 @@ #endregion + #region Implementation of ICollectionSqlsMapping + + public HbmLoader SqlLoader + { + get { return loader; } + } + + public HbmCustomSQL SqlInsert + { + get { return sqlinsert; } + } + + public HbmCustomSQL SqlUpdate + { + get { return sqlupdate; } + } + + public HbmCustomSQL SqlDelete + { + get { return sqldelete; } + } + + public HbmCustomSQL SqlDeleteAll + { + get { return sqldeleteall; } + } + + #endregion + + #region Implementation of ICollectionPropertyMapping + + public bool Inverse + { + get { return false; } + } + + public bool Mutable + { + get { return mutable; } + } + + public string OrderBy + { + get { return null; } + } + + public string Where + { + get { return @where; } + } + + public int? BatchSize + { + get { return null; } // TODO NH: change schema following the same schema of others collections + } + + public string PersisterQualifiedName + { + get { return persister; } + } + + public string CollectionType + { + get { return collectiontype; } + } + + public HbmCollectionFetchMode? FetchMode + { + get { return fetchSpecified ? (HbmCollectionFetchMode?)fetch : null; } + } + + public HbmOuterJoinStrategy? OuterJoin + { + get { return outerjoinSpecified ? (HbmOuterJoinStrategy?)outerjoin : null; } + } + + public HbmCollectionLazy? Lazy + { + get { return null; } + } + + public string Table + { + get { return table; } + } + + public string Schema + { + get { return schema; } + } + + public string Catalog + { + get { return catalog; } + } + + public string Check + { + get { return check; } + } + + public object ElementRelationship + { + get { return element; } + } + + public string Sort + { + get { return null; } + } + + public bool? Generic + { + get { return null; } + } + + public IEnumerable<HbmFilter> Filters + { + get { yield break; } + } + + public HbmKey Key + { + get { return key; } + } + + public HbmCache Cache + { + get { return cache; } + } + + #endregion + + #region Implementation of IIndexedCollection + + public HbmListIndex ListIndex + { + get { return Item as HbmListIndex; } + } + + public HbmIndex Index + { + get { return Item as HbmIndex; } + } + + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmProperty.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmProperty.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmProperty.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -18,7 +18,7 @@ get { return access; } } - public bool OptimisticKock + public bool OptimisticLock { get { return optimisticlock; } } Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmSet.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmSet.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmSet.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -1,6 +1,9 @@ +using System; +using System.Collections.Generic; + namespace NHibernate.Cfg.MappingSchema { - public partial class HbmSet : AbstractDecoratable, ICollectionPropertyMapping + public partial class HbmSet : AbstractDecoratable, ICollectionPropertiesMapping { #region Implementation of IEntityPropertyMapping @@ -14,7 +17,7 @@ get { return access; } } - public bool OptimisticKock + public bool OptimisticLock { get { return optimisticlock; } } @@ -39,5 +42,137 @@ #endregion + #region Implementation of ICollectionSqlsMapping + + public HbmLoader SqlLoader + { + get { return loader; } + } + + public HbmCustomSQL SqlInsert + { + get { return sqlinsert; } + } + + public HbmCustomSQL SqlUpdate + { + get { return sqlupdate; } + } + + public HbmCustomSQL SqlDelete + { + get { return sqldelete; } + } + + public HbmCustomSQL SqlDeleteAll + { + get { return sqldeleteall; } + } + + #endregion + + #region Implementation of ICollectionPropertiesMapping + + public bool Inverse + { + get { return inverse; } + } + + public bool Mutable + { + get { return mutable; } + } + + public string OrderBy + { + get { return orderby; } + } + + public string Where + { + get { return where; } + } + + public int? BatchSize + { + get { return batchsizeSpecified ? batchsize : (int?)null; } + } + + public string PersisterQualifiedName + { + get { return persister; } + } + + public string CollectionType + { + get { return collectiontype; } + } + + public HbmCollectionFetchMode? FetchMode + { + get { return fetchSpecified ? fetch : (HbmCollectionFetchMode?)null; } + } + + public HbmOuterJoinStrategy? OuterJoin + { + get { return outerjoinSpecified ? outerjoin : (HbmOuterJoinStrategy?)null; } + } + + public HbmCollectionLazy? Lazy + { + get { return lazySpecified ? lazy : (HbmCollectionLazy?)null; } + } + + public string Table + { + get { return table; } + } + + public string Schema + { + get { return schema; } + } + + public string Catalog + { + get { return catalog; } + } + + public string Check + { + get { return check; } + } + + public object ElementRelationship + { + get { return Item; } + } + + public string Sort + { + get { return sort; } + } + + public bool? Generic + { + get { return genericSpecified ? generic : (bool?)null; } + } + + public IEnumerable<HbmFilter> Filters + { + get { return filter ?? new HbmFilter[0]; } + } + + public HbmKey Key + { + get { return key; } + } + + public HbmCache Cache + { + get { return cache; } + } + + #endregion } } \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IAnyMapping.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IAnyMapping.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IAnyMapping.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace NHibernate.Cfg.MappingSchema +{ + public interface IAnyMapping + { + string MetaType { get; } + ICollection<HbmMetaValue> MetaValues { get; } + } +} \ No newline at end of file Copied: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/ICollectionPropertiesMapping.cs (from rev 4894, trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/ICollectionPropertyMapping.cs) =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/ICollectionPropertiesMapping.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/ICollectionPropertiesMapping.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -0,0 +1,36 @@ +using System.Collections.Generic; + +namespace NHibernate.Cfg.MappingSchema +{ + public interface ICollectionPropertiesMapping : IEntityPropertyMapping, IReferencePropertyMapping, ICollectionSqlsMapping + { + bool Inverse { get; } + bool Mutable { get; } + string OrderBy { get; } + string Where { get; } + int? BatchSize { get; } + string PersisterQualifiedName { get; } + string CollectionType { get; } + HbmCollectionFetchMode? FetchMode { get; } + HbmOuterJoinStrategy? OuterJoin { get; } + HbmCollectionLazy? Lazy { get; } + string Table { get; } + string Schema { get; } + string Catalog { get; } + string Check { get; } + + /// <summary> + /// The relation of the element of the collection. + /// </summary> + /// <remarks> + /// Can be one of: HbmCompositeElement, HbmElement, HbmManyToAny, HbmManyToMany, HbmOneToMany... + /// according to the type of the collection. + /// </remarks> + object ElementRelationship { get; } + string Sort { get; } + bool? Generic { get; } + IEnumerable<HbmFilter> Filters { get; } + HbmKey Key { get; } + HbmCache Cache { get; } + } +} \ No newline at end of file Deleted: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/ICollectionPropertyMapping.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/ICollectionPropertyMapping.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/ICollectionPropertyMapping.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -1,7 +0,0 @@ -namespace NHibernate.Cfg.MappingSchema -{ - public interface ICollectionPropertyMapping : IEntityPropertyMapping, IReferencePropertyMapping - { - - } -} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/ICollectionSqlsMapping.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/ICollectionSqlsMapping.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/ICollectionSqlsMapping.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -0,0 +1,11 @@ +namespace NHibernate.Cfg.MappingSchema +{ + public interface ICollectionSqlsMapping + { + HbmLoader SqlLoader { get; } + HbmCustomSQL SqlInsert { get; } + HbmCustomSQL SqlUpdate { get; } + HbmCustomSQL SqlDelete { get; } + HbmCustomSQL SqlDeleteAll { get; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IComponentMapping.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IComponentMapping.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IComponentMapping.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -0,0 +1,10 @@ +namespace NHibernate.Cfg.MappingSchema +{ + public interface IComponentMapping : IPropertiesContainerMapping + { + string Class { get; } + HbmParent Parent { get; } + string EmbeddedNode { get; } + string Name { get; } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IEntityPropertyMapping.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IEntityPropertyMapping.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IEntityPropertyMapping.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -4,6 +4,6 @@ { string Name { get; } string Access { get; } - bool OptimisticKock { get; } + bool OptimisticLock { get; } } } \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IIndexedCollectionMapping.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IIndexedCollectionMapping.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IIndexedCollectionMapping.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -0,0 +1,8 @@ +namespace NHibernate.Cfg.MappingSchema +{ + public interface IIndexedCollectionMapping + { + HbmListIndex ListIndex { get; } + HbmIndex Index { get; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IRelationship.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IRelationship.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/IRelationship.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -0,0 +1,9 @@ +namespace NHibernate.Cfg.MappingSchema +{ + public interface IRelationship + { + string EntityName { get; } + string Class { get; } + HbmNotFoundMode NotFoundMode { get; } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -289,5 +289,15 @@ return map; } + protected XmlNamespaceManager GetNamespaceManager(XmlNode parentNode) + { + // note that the prefix has absolutely nothing to do with what the user + // selects as their prefix in the document. It is the prefix we use to + // build the XPath and the nsmgr takes care of translating our prefix into + // the user defined prefix... + var namespaceManager = new XmlNamespaceManager(parentNode.OwnerDocument.NameTable); + namespaceManager.AddNamespace(HbmConstants.nsPrefix, MappingSchemaXMLNS); + return namespaceManager; + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2010-01-04 15:35:10 UTC (rev 4898) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2010-01-05 22:09:23 UTC (rev 4899) @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Xml; using NHibernate.Cfg.MappingSchema; using NHibernate.Engine; using NHibernate.Mapping; @@ -13,27 +12,19 @@ public abstract class ClassBinder : Binder { protected readonly Dialect.Dialect dialect; - private readonly XmlNamespaceManager namespaceManager; - protected ClassBinder(Mappings mappings, XmlNamespaceManager namespaceManager, Dialect.Dialect dialect) + protected ClassBinder(Mappings mappings, Dialect.Dialect dialect) : base(mappings) { this.dialect = dialect; - this.namespaceManager = namespaceManager; } protected ClassBinder(ClassBinder parent) : base(parent.Mappings) { dialect = parent.dialect; - namespaceManager = parent.NamespaceManager; } - public XmlNamespaceManager NamespaceManager - { - get { return namespaceManager; } - } - protected void BindClass(IEntityMapping classMapping, PersistentClass model, IDictionary<string, MetaAttribute> inheritedMetas) { // handle the lazy attribute @@ -211,13 +202,13 @@ SimpleValue key = new DependantValue(table, persistentClass.Identifier); join.Key = key; key.IsCascadeDeleteEnabled = joinMapping.key.ondelete == HbmOndelete.Cascade; - BindSimpleValue(Serialize(joinMapping.key), key, false, persistentClass.EntityName); + new ValuePropertyBinder(key, Mappings).BindSimpleValue(joinMapping.key, persistentClass.EntityName, false); join.CreatePrimaryKey(dialect); join.CreateForeignKey(); // PROPERTIES - new PropertiesBinder(Mappings, persistentClass, NamespaceManager, dialect).Bind(joinMapping.Properties, join.Table, + new PropertiesBinder(Mappings, persistentClass, dialect).Bind(joinMapping.Properties, join.Table, ... [truncated message content] |
From: <ric...@us...> - 2010-01-04 15:35:25
|
Revision: 4898 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4898&view=rev Author: ricbrown Date: 2010-01-04 15:35:10 +0000 (Mon, 04 Jan 2010) Log Message: ----------- Renamed QueryOver.Single() to SingleOrDefault() to closer mimic semantics of Linq extension methods of the same name. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs trunk/nhibernate/src/NHibernate/IQueryOver.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2010-01-04 15:20:56 UTC (rev 4897) +++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2010-01-04 15:35:10 UTC (rev 4898) @@ -56,12 +56,12 @@ return criteria.List<U>(); } - private TRoot Single() + private TRoot SingleOrDefault() { return criteria.UniqueResult<TRoot>(); } - private U Single<U>() + private U SingleOrDefault<U>() { return criteria.UniqueResult<U>(); } @@ -125,11 +125,11 @@ IList<U> IQueryOver<TRoot>.List<U>() { return List<U>(); } - TRoot IQueryOver<TRoot>.Single() - { return Single(); } + TRoot IQueryOver<TRoot>.SingleOrDefault() + { return SingleOrDefault(); } - U IQueryOver<TRoot>.Single<U>() - { return Single<U>(); } + U IQueryOver<TRoot>.SingleOrDefault<U>() + { return SingleOrDefault<U>(); } IEnumerable<TRoot> IQueryOver<TRoot>.Future() { return Future(); } Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2010-01-04 15:20:56 UTC (rev 4897) +++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2010-01-04 15:35:10 UTC (rev 4898) @@ -49,12 +49,12 @@ /// <exception cref="HibernateException"> /// If there is more than one matching result /// </exception> - TRoot Single(); + TRoot SingleOrDefault(); /// <summary> - /// Override type of <see cref="Single()" />. + /// Override type of <see cref="SingleOrDefault()" />. /// </summary> - U Single<U>(); + U SingleOrDefault<U>(); /// <summary> /// Get a enumerable that when enumerated will execute Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2010-01-04 15:20:56 UTC (rev 4897) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2010-01-04 15:35:10 UTC (rev 4898) @@ -159,7 +159,7 @@ { Person actual = s.QueryOver<Person>() - .Single(); + .SingleOrDefault(); Assert.That(actual.Name, Is.EqualTo("test person 1")); } @@ -169,7 +169,7 @@ string actual = s.QueryOver<Person>() .Select(p => p.Name) - .Single<string>(); + .SingleOrDefault<string>(); Assert.That(actual, Is.EqualTo("test person 1")); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2010-01-04 15:21:26
|
Revision: 4897 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4897&view=rev Author: ricbrown Date: 2010-01-04 15:20:56 +0000 (Mon, 04 Jan 2010) Log Message: ----------- Renamed QueryOver UniqueResult() to Single(). Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs trunk/nhibernate/src/NHibernate/IQueryOver.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-12-16 21:52:08 UTC (rev 4896) +++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2010-01-04 15:20:56 UTC (rev 4897) @@ -56,12 +56,12 @@ return criteria.List<U>(); } - private TRoot UniqueResult() + private TRoot Single() { return criteria.UniqueResult<TRoot>(); } - private U UniqueResult<U>() + private U Single<U>() { return criteria.UniqueResult<U>(); } @@ -125,11 +125,11 @@ IList<U> IQueryOver<TRoot>.List<U>() { return List<U>(); } - TRoot IQueryOver<TRoot>.UniqueResult() - { return UniqueResult(); } + TRoot IQueryOver<TRoot>.Single() + { return Single(); } - U IQueryOver<TRoot>.UniqueResult<U>() - { return UniqueResult<U>(); } + U IQueryOver<TRoot>.Single<U>() + { return Single<U>(); } IEnumerable<TRoot> IQueryOver<TRoot>.Future() { return Future(); } Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-12-16 21:52:08 UTC (rev 4896) +++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2010-01-04 15:20:56 UTC (rev 4897) @@ -49,12 +49,12 @@ /// <exception cref="HibernateException"> /// If there is more than one matching result /// </exception> - TRoot UniqueResult(); + TRoot Single(); /// <summary> - /// Override type of <see cref="UniqueResult()" />. + /// Override type of <see cref="Single()" />. /// </summary> - U UniqueResult<U>(); + U Single<U>(); /// <summary> /// Get a enumerable that when enumerated will execute Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2009-12-16 21:52:08 UTC (rev 4896) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2010-01-04 15:20:56 UTC (rev 4897) @@ -159,7 +159,7 @@ { Person actual = s.QueryOver<Person>() - .UniqueResult(); + .Single(); Assert.That(actual.Name, Is.EqualTo("test person 1")); } @@ -169,7 +169,7 @@ string actual = s.QueryOver<Person>() .Select(p => p.Name) - .UniqueResult<string>(); + .Single<string>(); Assert.That(actual, Is.EqualTo("test person 1")); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Messerli <pe...@zw...> - 2009-12-25 21:01:55
|
days I had seen little further than the old school of political economists into the possibilities of fundamental improvement in social arrangements. Private property, as now understood, and inheritance, appeared to me, as to them, the _dernier mot_ of legislation: and I looked no further than to mitigating the inequalities consequent on these institutions, by getting rid of primogeniture and entails. The notion that it was possible to go further than this in removing the injustice--for injustice it is, whether admitting of a complete remedy or not--involved in the fact that some are born to riches and the vast majority to poverty, I then reckoned chimerical, and only hoped that by universal education, leading to voluntary restraint on population, the portion of the poor might be made more tolerable. In short, I was a democrat, but not the least of a Socialist. We were now much less democrats than I had been, because so long as education continues to be so wretchedly imperfect, we dreaded the ignorance and especially the selfishness and brutality of the mass: but our ideal of ultimate improvement went far beyond Democracy, and would class us decidedly under the general designation of Socialists. While we repudiated with the greatest energy that tyranny of society over the individual which most Socialistic systems are supposed to involve, we yet looked forward to a time when society will no longer be divided into the idle and the industrious; when the rule that they who do not work shall not eat, will be applied not to paupers only, but impartially to all; when the division of the produce of labour, instead of depending, as in so great a degree it now does, on the |
From: Thersa K. <cer...@il...> - 2009-12-23 09:47:03
|
Shamed. He hurried away with lowered head and tail and didn't reappear until he had cleaned his coat. Even then he would not look at Hortense, try as she would to catch his eye. [Illustration] CHAPTER VII "_... there should be Little People up the mountain yonder...._" "If you will come to tea at four o'clock, Fergus will tell you a story of the Little People," said Mary to Hortense, adding as Hortense hesitated a moment, "Bring Andy with you." Hortense accepted gladly and ran to inform Andy of the invitation and that nut cake with chocolate icing had been especially made for the occasion. At four o'clock Andy and Hortense, in their best bib and tucker and with clean smiling faces, knocked at the door of the little cottage beyond the orchard where lived Fergus and Mary. The tea was all that could be asked for in variety and quantity, and it was quite evident when Hortense and Andy had finished with it that if they ate even a |
From: <ste...@us...> - 2009-12-16 21:52:16
|
Revision: 4896 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4896&view=rev Author: steverstrong Date: 2009-12-16 21:52:08 +0000 (Wed, 16 Dec 2009) Log Message: ----------- Two files that should have been deleted on the last commit. Added Paths: ----------- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/output/ Removed Paths: ------------- trunk/nhibernate/src/NHibernate/Linq/CommandData.cs trunk/nhibernate/src/NHibernate/Linq/Visitors/ProjectionEvaluator.cs Property changes on: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/output ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Deleted: trunk/nhibernate/src/NHibernate/Linq/CommandData.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/CommandData.cs 2009-12-16 21:36:34 UTC (rev 4895) +++ trunk/nhibernate/src/NHibernate/Linq/CommandData.cs 2009-12-16 21:52:08 UTC (rev 4896) @@ -1,64 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using NHibernate.Hql.Ast; - -namespace NHibernate.Linq -{ - public class CommandData - { - private readonly List<LambdaExpression> _itemTransformers; - private readonly List<LambdaExpression> _listTransformers; - private readonly List<Action<IQuery>> _additionalCriteria; - - public CommandData(HqlQuery statement, List<LambdaExpression> itemTransformers, List<LambdaExpression> listTransformers, List<Action<IQuery>> additionalCriteria) - { - _itemTransformers = itemTransformers; - _listTransformers = listTransformers; - - Statement = statement; - _additionalCriteria = additionalCriteria; - } - - public HqlQuery Statement { get; private set; } - - public void AddAdditionalCriteria(IQuery query) - { - foreach (var criteria in _additionalCriteria) - { - criteria(query); - } - } - - public void SetResultTransformer(IQuery query) - { - var itemTransformer = MergeLambdas(_itemTransformers); - var listTransformer = MergeLambdas(_listTransformers); - - if (itemTransformer != null || listTransformer != null) - { - query.SetResultTransformer(new ResultTransformer(itemTransformer, listTransformer)); - } - } - - private static LambdaExpression MergeLambdas(IList<LambdaExpression> transformations) - { - if (transformations == null || transformations.Count == 0) - { - return null; - } - - var listTransformLambda = transformations[0]; - - for (int i = 1; i < transformations.Count; i++) - { - var invoked = Expression.Invoke(transformations[i], listTransformLambda.Body); - - listTransformLambda = Expression.Lambda(invoked, listTransformLambda.Parameters.ToArray()); - } - - return listTransformLambda; - } - } -} \ No newline at end of file Deleted: trunk/nhibernate/src/NHibernate/Linq/Visitors/ProjectionEvaluator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/ProjectionEvaluator.cs 2009-12-16 21:36:34 UTC (rev 4895) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/ProjectionEvaluator.cs 2009-12-16 21:52:08 UTC (rev 4896) @@ -1,71 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq.Expressions; -using NHibernate.Engine.Query; -using NHibernate.Hql.Ast; -using Remotion.Data.Linq.Parsing; - -namespace NHibernate.Linq.Visitors -{ - public class ProjectionEvaluator : ExpressionTreeVisitor - { - private HashSet<Expression> _hqlNodes; - private readonly ParameterExpression _inputParameter; - private readonly Func<Expression, bool> _predicate; - private readonly IDictionary<ConstantExpression, NamedParameter> _parameters; - private readonly IList<NamedParameterDescriptor> _requiredHqlParameters; - private int _iColumn; - private readonly List<HqlExpression> _hqlTreeNodes = new List<HqlExpression>(); - - public ProjectionEvaluator(System.Type inputType, Func<Expression, bool> predicate, IDictionary<ConstantExpression, NamedParameter> parameters, IList<NamedParameterDescriptor> requiredHqlParameters) - { - _inputParameter = Expression.Parameter(inputType, "input"); - _predicate = predicate; - _parameters = parameters; - _requiredHqlParameters = requiredHqlParameters; - } - - public LambdaExpression ProjectionExpression { get; private set; } - - public IEnumerable<HqlExpression> GetHqlNodes() - { - return _hqlTreeNodes; - } - - public void Visit(Expression expression) - { - // First, find the sub trees that can be expressed purely in HQL - _hqlNodes = new Nominator(_predicate).Nominate(expression); - - // Now visit the tree - Expression projection = VisitExpression(expression); - - if ((projection != expression) && !_hqlNodes.Contains(expression)) - { - ProjectionExpression = Expression.Lambda(projection, _inputParameter); - } - } - - protected override Expression VisitExpression(Expression expression) - { - if (expression == null) - { - return null; - } - - if (_hqlNodes.Contains(expression)) - { - // Pure HQL evaluation - TODO - cache the Visitor? - var hqlVisitor = new HqlGeneratorExpressionTreeVisitor(_parameters, _requiredHqlParameters); - - _hqlTreeNodes.Add(hqlVisitor.Visit(expression).AsExpression()); - - return Expression.Convert(Expression.ArrayIndex(_inputParameter, Expression.Constant(_iColumn++)), - expression.Type); - } - - // Can't handle this node with HQL. Just recurse down, and emit the expression - return base.VisitExpression(expression); - } - } -} \ 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: <ste...@us...> - 2009-12-16 21:36:52
|
Revision: 4895 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4895&view=rev Author: steverstrong Date: 2009-12-16 21:36:34 +0000 (Wed, 16 Dec 2009) Log Message: ----------- More Linq test cases and supporting fixes. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/PolymorphicQuerySourceDetector.cs trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs trunk/nhibernate/src/NHibernate/Impl/AbstractQueryImpl.cs trunk/nhibernate/src/NHibernate/Impl/ExpressionQueryImpl.cs trunk/nhibernate/src/NHibernate/Linq/ExpressionToHqlTranslationResults.cs trunk/nhibernate/src/NHibernate/Linq/Expressions/NhExpressionType.cs trunk/nhibernate/src/NHibernate/Linq/Expressions/NhNewExpression.cs trunk/nhibernate/src/NHibernate/Linq/Functions/BaseHqlGeneratorForType.cs trunk/nhibernate/src/NHibernate/Linq/Functions/FunctionRegistry.cs trunk/nhibernate/src/NHibernate/Linq/Functions/IHqlGeneratorForType.cs trunk/nhibernate/src/NHibernate/Linq/Functions/QueryableGenerator.cs trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs trunk/nhibernate/src/NHibernate/Linq/NhLinqExpression.cs trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs trunk/nhibernate/src/NHibernate/Linq/ReWriters/MergeAggregatingResultsRewriter.cs trunk/nhibernate/src/NHibernate/Linq/ReWriters/RemoveUnnecessaryBodyOperators.cs trunk/nhibernate/src/NHibernate/Linq/ResultOperators/ClientSideTransformOperator.cs trunk/nhibernate/src/NHibernate/Linq/ResultTransformer.cs trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs trunk/nhibernate/src/NHibernate/Linq/Visitors/NhExpressionTreeVisitor.cs trunk/nhibernate/src/NHibernate/Linq/Visitors/Nominator.cs trunk/nhibernate/src/NHibernate/Linq/Visitors/QueryModelVisitor.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.ByteCode.LinFu/NHibernate.ByteCode.LinFu.csproj trunk/nhibernate/src/NHibernate.DomainModel/NHibernate.DomainModel.csproj trunk/nhibernate/src/NHibernate.Test/App.config trunk/nhibernate/src/NHibernate.Test/Linq/Entities/Northwind.cs trunk/nhibernate/src/NHibernate.Test/Linq/LinqQuerySamples.cs trunk/nhibernate/src/NHibernate.Test/Linq/ParameterisedQueries.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Linq/Visitors/SelectClauseVisitor.cs trunk/nhibernate/src/NHibernate.Test/Linq/CollectionAssert.cs trunk/nhibernate/src/NHibernate.Test/Linq/Entities/UserDto.cs trunk/nhibernate/src/NHibernate.Test/Linq/RegresstionTests.cs trunk/nhibernate/src/NHibernate.Test/Linq/SelectionTests.cs trunk/nhibernate/src/NHibernate.Test/Linq/WhereSubqueryTests.cs trunk/nhibernate/src/NHibernate.Test/Linq/WhereTests.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/PolymorphicQuerySourceDetector.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/PolymorphicQuerySourceDetector.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/PolymorphicQuerySourceDetector.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -27,20 +27,17 @@ var className = GetClassName(querySource); var classType = _sessionFactoryHelper.GetImportedClass(className); - if (classType != null) - { - AddImplementorsToMap(querySource, classType); - } + AddImplementorsToMap(querySource, classType == null ? className : classType.FullName); } return _map; } - private void AddImplementorsToMap(IASTNode querySource, System.Type classType) + private void AddImplementorsToMap(IASTNode querySource, string className) { - var implementors = _sfi.GetImplementors(classType.FullName); + var implementors = _sfi.GetImplementors(className); - if (implementors.Length == 1 && implementors[0] == classType.FullName) + if (implementors.Length == 1 && implementors[0] == className) { // No need to change things return; Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -341,11 +341,6 @@ return new HqlConcat(_factory, args); } - public HqlExpressionList ExpressionList() - { - return new HqlExpressionList(_factory); - } - public HqlMethodCall MethodCall(string methodName, IEnumerable<HqlExpression> parameters) { return new HqlMethodCall(_factory, methodName, parameters); @@ -370,6 +365,30 @@ { return new HqlIsNotNull(_factory, lhs); } + + public HqlTreeNode ExpressionList(IEnumerable<HqlExpression> expressions) + { + return new HqlExpressionList(_factory, expressions); + } + + public HqlStar Star() + { + return new HqlStar(_factory); + } + + public HqlTrue True() + { + return new HqlTrue(_factory); + } + + public HqlFalse False() + { + return new HqlFalse(_factory); + } + + public HqlIn In(HqlExpression itemExpression, HqlTreeNode source) + { + return new HqlIn(_factory, itemExpression, source); + } } - } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -8,11 +8,13 @@ { public class HqlTreeNode { + public IASTFactory Factory { get; private set; } private readonly IASTNode _node; private readonly List<HqlTreeNode> _children; protected HqlTreeNode(int type, string text, IASTFactory factory, IEnumerable<HqlTreeNode> children) { + Factory = factory; _node = factory.CreateNode(type, text); _children = new List<HqlTreeNode>(); @@ -107,18 +109,27 @@ _node.AddChild(child.AstNode); } } + } - public HqlExpression AsExpression() + public static class HqlTreeNodeExtensions + { + public static HqlExpression AsExpression(this HqlTreeNode node) { // TODO - nice error handling if cast fails - return (HqlExpression) this; + return (HqlExpression)node; } - public virtual HqlBooleanExpression AsBooleanExpression() + public static HqlBooleanExpression AsBooleanExpression(this HqlTreeNode node) { + if (node is HqlDot) + { + return new HqlBooleanDot(node.Factory, (HqlDot) node); + } + // TODO - nice error handling if cast fails - return (HqlBooleanExpression)this; + return (HqlBooleanExpression)node; } + } public abstract class HqlStatement : HqlTreeNode @@ -329,20 +340,10 @@ public class HqlDot : HqlExpression { - private readonly IASTFactory _factory; - public HqlDot(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) : base(HqlSqlWalker.DOT, ".", factory, lhs, rhs) { - _factory = factory; } - - public override HqlBooleanExpression AsBooleanExpression() - { - // If we are of boolean type, then we can acts as boolean expression - // TODO - implement type check - return new HqlBooleanDot(_factory, this); - } } public class HqlBooleanDot : HqlBooleanExpression @@ -408,6 +409,23 @@ } } + public class HqlFalse : HqlConstant + { + public HqlFalse(IASTFactory factory) + : base(factory, HqlSqlWalker.FALSE, "false") + { + } + } + + public class HqlTrue : HqlConstant + { + public HqlTrue(IASTFactory factory) + : base(factory, HqlSqlWalker.TRUE, "true") + { + } + } + + public class HqlNull : HqlConstant { public HqlNull(IASTFactory factory) @@ -430,15 +448,23 @@ Descending } - public class HqlDirectionAscending : HqlStatement + public class HqlDirectionStatement : HqlStatement { + public HqlDirectionStatement(int type, string text, IASTFactory factory) + : base(type, text, factory) + { + } + } + + public class HqlDirectionAscending : HqlDirectionStatement + { public HqlDirectionAscending(IASTFactory factory) : base(HqlSqlWalker.ASCENDING, "asc", factory) { } } - public class HqlDirectionDescending : HqlStatement + public class HqlDirectionDescending : HqlDirectionStatement { public HqlDirectionDescending(IASTFactory factory) : base(HqlSqlWalker.DESCENDING, "desc", factory) @@ -733,4 +759,28 @@ { } } + + public class HqlStar : HqlExpression + { + public HqlStar(IASTFactory factory) : base(HqlSqlWalker.ROW_STAR, "*", factory) + { + } + } + + public class HqlIn : HqlBooleanExpression + { + public HqlIn(IASTFactory factory, HqlExpression itemExpression, HqlTreeNode source) + : base(HqlSqlWalker.IN, "in", factory, itemExpression) + { + AddChild(new HqlInList(factory, source)); + } + } + + public class HqlInList : HqlTreeNode + { + public HqlInList(IASTFactory factory, HqlTreeNode source) + : base(HqlSqlWalker.IN_LIST, "inlist", factory, source) + { + } + } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Impl/AbstractQueryImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/AbstractQueryImpl.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Impl/AbstractQueryImpl.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -27,7 +27,7 @@ private readonly ArrayList values = new ArrayList(4); private readonly List<IType> types = new List<IType>(4); private readonly Dictionary<string, TypedValue> namedParameters = new Dictionary<string, TypedValue>(4); - private readonly Dictionary<string, TypedValue> namedParameterLists = new Dictionary<string, TypedValue>(4); + protected readonly Dictionary<string, TypedValue> namedParameterLists = new Dictionary<string, TypedValue>(4); private bool cacheable; private string cacheRegion; private bool readOnly; Modified: trunk/nhibernate/src/NHibernate/Impl/ExpressionQueryImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/ExpressionQueryImpl.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Impl/ExpressionQueryImpl.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -1,8 +1,17 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; +using System.Linq; +using System.Text; using NHibernate.Engine; using NHibernate.Engine.Query; +using NHibernate.Engine.Query.Sql; +using NHibernate.Hql.Ast.ANTLR; +using NHibernate.Hql.Ast.ANTLR.Tree; +using NHibernate.Hql.Ast.ANTLR.Util; +using NHibernate.Hql.Classic; +using NHibernate.Type; +using NHibernate.Util; namespace NHibernate.Impl { @@ -12,12 +21,12 @@ public IQueryExpression QueryExpression { get; private set; } - public ExpressionQueryImpl(IQueryExpression queryExpression, ISessionImplementor session, ParameterMetadata parameterMetadata) + public ExpressionQueryImpl(IQueryExpression queryExpression, ISessionImplementor session, ParameterMetadata parameterMetadata) : base(queryExpression.Key, FlushMode.Unspecified, session, parameterMetadata) { QueryExpression = queryExpression; } - + public override IQuery SetLockMode(string alias, LockMode lockMode) { _lockModes[alias] = lockMode; @@ -51,7 +60,7 @@ Before(); try { - return Session.List(QueryExpression, GetQueryParameters(namedParams)); + return Session.List(ExpandParameters(namedParams), GetQueryParameters(namedParams)); } finally { @@ -59,6 +68,65 @@ } } + /// <summary> + /// Warning: adds new parameters to the argument by side-effect, as well as mutating the query expression tree! + /// </summary> + protected IQueryExpression ExpandParameters(IDictionary<string, TypedValue> namedParamsCopy) + { + if (namedParameterLists.Count == 0) + { + // Short circuit straight out + return QueryExpression; + } + + // Build a map from single parameters to lists + var map = new Dictionary<string, List<string>>(); + + foreach (var me in namedParameterLists) + { + string name = me.Key; + var vals = (ICollection) me.Value.Value; + var type = me.Value.Type; + + if (vals.Count == 1) + { + // No expansion needed here + var iter = vals.GetEnumerator(); + iter.MoveNext(); + namedParamsCopy[name] = new TypedValue(type, iter.Current, Session.EntityMode); + continue; + } + + var aliases = new List<string>(); + var i = 0; + var isJpaPositionalParam = parameterMetadata.GetNamedParameterDescriptor(name).JpaStyle; + + foreach (var obj in vals) + { + var alias = (isJpaPositionalParam ? 'x' + name : name + StringHelper.Underscore) + i++ + StringHelper.Underscore; + namedParamsCopy[alias] = new TypedValue(type, obj, Session.EntityMode); + aliases.Add(alias); + } + + map.Add(name, aliases); + + } + + var newTree = ParameterExpander.Expand(QueryExpression.Translate(Session.Factory), map); + var key = new StringBuilder(QueryExpression.Key); + + map.Aggregate(key, (sb, kvp) => + { + sb.Append(' '); + sb.Append(kvp.Key); + sb.Append(':'); + kvp.Value.Aggregate(sb, (sb2, str) => sb2.Append(str)); + return sb; + }); + + return new ExpandedQueryExpression(QueryExpression, newTree, key.ToString()); + } + public override void List(IList results) { throw new NotImplementedException(); @@ -69,4 +137,141 @@ throw new NotImplementedException(); } } + + internal class ExpandedQueryExpression : IQueryExpression + { + private readonly IASTNode _tree; + + public ExpandedQueryExpression(IQueryExpression queryExpression, IASTNode tree, string key) + { + _tree = tree; + Key = key; + Type = queryExpression.Type; + ParameterDescriptors = queryExpression.ParameterDescriptors; + } + + public IASTNode Translate(ISessionFactory sessionFactory) + { + return _tree; + } + + public string Key { get; private set; } + + public System.Type Type { get; private set; } + + public IList<NamedParameterDescriptor> ParameterDescriptors { get; private set; } + } + + internal class ParameterExpander + { + private readonly IASTNode _tree; + private readonly Dictionary<string, List<string>> _map; + + private ParameterExpander(IASTNode tree, Dictionary<string, List<string>> map) + { + _tree = tree; + _map = map; + } + + public static IASTNode Expand(IASTNode tree, Dictionary<string, List<string>> map) + { + var expander = new ParameterExpander(tree, map); + + return expander.Expand(); + } + + private IASTNode Expand() + { + var parameters = ParameterDetector.LocateParameters(_tree, new HashSet<string>(_map.Keys)); + var nodeMapping = new Dictionary<IASTNode, IEnumerable<IASTNode>>(); + + foreach (var param in parameters) + { + var paramName = param.GetChild(0); + var aliases = _map[paramName.Text]; + var astAliases = new List<IASTNode>(); + + foreach (var alias in aliases) + { + var astAlias = param.DupNode(); + var astAliasName = paramName.DupNode(); + astAliasName.Text = alias; + astAlias.AddChild(astAliasName); + + astAliases.Add(astAlias); + } + + nodeMapping.Add(param, astAliases); + } + + return DuplicateTree(_tree, nodeMapping); + } + + private static IASTNode DuplicateTree(IASTNode ast, IDictionary<IASTNode, IEnumerable<IASTNode>> nodeMapping) + { + var thisNode = ast.DupNode(); + + foreach (var child in ast) + { + IEnumerable<IASTNode> candidate; + + if (nodeMapping.TryGetValue(child, out candidate)) + { + foreach (var replacement in candidate) + { + thisNode.AddChild(replacement); + } + } + else + { + thisNode.AddChild(DuplicateTree(child, nodeMapping)); + } + } + + return thisNode; + } + } + + internal class ParameterDetector : IVisitationStrategy + { + private readonly IASTNode _tree; + private readonly HashSet<string> _parameterNames; + private readonly List<IASTNode> _nodes; + + private ParameterDetector(IASTNode tree, HashSet<string> parameterNames) + { + _tree = tree; + _parameterNames = parameterNames; + _nodes = new List<IASTNode>(); + } + + public static IList<IASTNode> LocateParameters(IASTNode tree, HashSet<string> parameterNames) + { + var detector = new ParameterDetector(tree, parameterNames); + + return detector.LocateParameters(); + } + + private IList<IASTNode> LocateParameters() + { + var nodeTraverser = new NodeTraverser(this); + nodeTraverser.TraverseDepthFirst(_tree); + + return _nodes; + } + + public void Visit(IASTNode node) + { + if ((node.Type == HqlSqlWalker.PARAM) || (node.Type == HqlSqlWalker.COLON)) + { + var name = node.GetChild(0).Text; + + if (_parameterNames.Contains(name)) + { + _nodes.Add(node); + } + } + } + + } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Linq/ExpressionToHqlTranslationResults.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/ExpressionToHqlTranslationResults.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Linq/ExpressionToHqlTranslationResults.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -9,17 +9,24 @@ { public class ExpressionToHqlTranslationResults { - public HqlQuery Statement { get; private set; } + public HqlTreeNode Statement { get; private set; } public ResultTransformer ResultTransformer { get; private set; } - public List<Action<IQuery, IDictionary<string, Pair<object, IType>>>> AdditionalCriteria { get; private set; } + public Delegate PostExecuteTransformer { get; private set; } + public List<Action<IQuery, IDictionary<string, Tuple<object, IType>>>> AdditionalCriteria { get; private set; } - public ExpressionToHqlTranslationResults(HqlQuery statement, IList<LambdaExpression> itemTransformers, IList<LambdaExpression> listTransformers, List<Action<IQuery, IDictionary<string, Pair<object, IType>>>> additionalCriteria) + public ExpressionToHqlTranslationResults(HqlTreeNode statement, + IList<LambdaExpression> itemTransformers, + IList<LambdaExpression> listTransformers, + IList<LambdaExpression> postExecuteTransformers, + List<Action<IQuery, IDictionary<string, Tuple<object, IType>>>> additionalCriteria) { Statement = statement; - var itemTransformer = MergeLambdas(itemTransformers); - var listTransformer = MergeLambdas(listTransformers); + PostExecuteTransformer = MergeLambdasAndCompile(postExecuteTransformers); + var itemTransformer = MergeLambdasAndCompile(itemTransformers); + var listTransformer = MergeLambdasAndCompile(listTransformers); + if (itemTransformer != null || listTransformer != null) { ResultTransformer = new ResultTransformer(itemTransformer, listTransformer); @@ -28,7 +35,7 @@ AdditionalCriteria = additionalCriteria; } - private static LambdaExpression MergeLambdas(IList<LambdaExpression> transformations) + private static Delegate MergeLambdasAndCompile(IList<LambdaExpression> transformations) { if (transformations == null || transformations.Count == 0) { @@ -44,7 +51,7 @@ listTransformLambda = Expression.Lambda(invoked, listTransformLambda.Parameters.ToArray()); } - return listTransformLambda; + return listTransformLambda.Compile(); } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Linq/Expressions/NhExpressionType.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Expressions/NhExpressionType.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Linq/Expressions/NhExpressionType.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -8,6 +8,7 @@ Sum, Count, Distinct, - New + New, + Star } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Linq/Expressions/NhNewExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Expressions/NhNewExpression.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Linq/Expressions/NhNewExpression.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq.Expressions; @@ -26,4 +27,17 @@ get { return _members; } } } + + public class NhStarExpression : Expression + { + public NhStarExpression(Expression expression) : base((ExpressionType) NhExpressionType.Star, expression.Type) + { + Expression = expression; + } + + public Expression Expression + { + get; private set; + } + } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/BaseHqlGeneratorForType.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Functions/BaseHqlGeneratorForType.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Linq/Functions/BaseHqlGeneratorForType.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Reflection; using NHibernate.Linq.Visitors; namespace NHibernate.Linq.Functions @@ -26,5 +28,15 @@ } } } + + public virtual bool SupportsMethod(MethodInfo method) + { + return false; + } + + public virtual IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method) + { + throw new NotSupportedException(); + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/FunctionRegistry.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Functions/FunctionRegistry.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Linq/Functions/FunctionRegistry.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -36,12 +36,14 @@ registry.Register(new QueryableGenerator()); registry.Register(new StringGenerator()); registry.Register(new DateTimeGenerator()); + registry.Register(new ICollectionGenerator()); return registry; } 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>(); public IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method) { @@ -58,14 +60,23 @@ } // No method generator registered. Look to see if it's a standard LinqExtensionMethod - var attr = (LinqExtensionMethodAttribute) method.GetCustomAttributes(typeof (LinqExtensionMethodAttribute), false)[0]; - if (attr != null) + var attr = method.GetCustomAttributes(typeof (LinqExtensionMethodAttribute), false); + if (attr.Length == 1) { // It is // TODO - cache this? Is it worth it? - return new HqlGeneratorForExtensionMethod(attr, method); + return new HqlGeneratorForExtensionMethod((LinqExtensionMethodAttribute) attr[0], method); } + // Not that either. Let's query each type generator to see if it can handle it + foreach (var typeGenerator in _typeGenerators) + { + if (typeGenerator.SupportsMethod(method)) + { + return typeGenerator.GetMethodGenerator(method); + } + } + throw new NotSupportedException(method.ToString()); } @@ -94,6 +105,7 @@ private void Register(IHqlGeneratorForType typeMethodGenerator) { + _typeGenerators.Add(typeMethodGenerator); typeMethodGenerator.Register(this); } } Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/IHqlGeneratorForType.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Functions/IHqlGeneratorForType.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Linq/Functions/IHqlGeneratorForType.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -1,7 +1,11 @@ -namespace NHibernate.Linq.Functions +using System.Reflection; + +namespace NHibernate.Linq.Functions { public interface IHqlGeneratorForType { void Register(FunctionRegistry functionRegistry); + bool SupportsMethod(MethodInfo method); + IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method); } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/QueryableGenerator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Functions/QueryableGenerator.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Linq/Functions/QueryableGenerator.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -1,4 +1,6 @@ -using System.Collections.ObjectModel; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Linq.Expressions; using System.Reflection; @@ -126,4 +128,74 @@ } } } + + public class ICollectionGenerator : BaseHqlGeneratorForType + { + public ICollectionGenerator() + { + // TODO - could use reflection + MethodRegistry.Add(new ContainsGenerator()); + } + + public override bool SupportsMethod(MethodInfo method) + { + var declaringType = method.DeclaringType; + + if (declaringType.IsGenericType) + { + if (declaringType.GetGenericTypeDefinition() == typeof(ICollection<>) || + declaringType.GetGenericTypeDefinition() == typeof(IEnumerable<>)) + { + if (method.Name == "Contains") + { + return true; + } + } + } + + return false; + } + + public override IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method) + { + // TODO - ick + if (method.Name == "Contains") + { + return new ContainsGenerator(); + } + + throw new NotSupportedException(method.Name); + } + + class ContainsGenerator : BaseHqlGeneratorForMethod + { + public ContainsGenerator() + { + SupportedMethods = new MethodInfo[0]; + } + + 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)); + } + } + + } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -24,10 +24,19 @@ return (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)); } + public static bool IsNullableOrReference(this System.Type type) + { + return !type.IsValueType || (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)); + } + public static System.Type NullableOf(this System.Type type) { return type.GetGenericArguments()[0]; } + public static T As<T>(this object source) + { + return (T) source; + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Linq/NhLinqExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/NhLinqExpression.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Linq/NhLinqExpression.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -9,7 +9,6 @@ using NHibernate.Type; using Remotion.Data.Linq; using Remotion.Data.Linq.Clauses; -using Remotion.Data.Linq.Clauses.StreamedData; using Remotion.Data.Linq.Parsing.ExpressionTreeVisitors; using Remotion.Data.Linq.Parsing.Structure; using Remotion.Data.Linq.Parsing.Structure.IntermediateModel; @@ -26,14 +25,15 @@ public NhLinqExpressionReturnType ReturnType { get; private set; } - public IDictionary<string, Pair<object, IType>> ParameterValuesByName { get; private set; } + public IDictionary<string, Tuple<object, IType>> ParameterValuesByName { get; private set; } public ExpressionToHqlTranslationResults ExpressionToHqlTranslationResults { get; private set; } private readonly Expression _expression; private readonly IDictionary<ConstantExpression, NamedParameter> _constantToParameterMap; + private IASTNode _astNode; - public NhLinqExpression(Expression expression) + public NhLinqExpression(Expression expression) { _expression = PartialEvaluatingExpressionTreeVisitor.EvaluateIndependentSubtrees(expression); @@ -43,8 +43,8 @@ ParameterValuesByName = _constantToParameterMap.Values.ToDictionary(p => p.Name, p => - new Pair<object, IType> - {Left = p.Value, Right = p.Type}); + new Tuple<object, IType> + {First = p.Value, Second = p.Type}); Key = ExpressionKeyVisitor.Visit(_expression, _constantToParameterMap); @@ -62,16 +62,22 @@ public IASTNode Translate(ISessionFactory sessionFactory) { - var requiredHqlParameters = new List<NamedParameterDescriptor>(); + //if (_astNode == null) + { + var requiredHqlParameters = new List<NamedParameterDescriptor>(); - // TODO - can we cache any of this? - var queryModel = NhRelinqQueryParser.Parse(_expression); + // TODO - can we cache any of this? + var queryModel = NhRelinqQueryParser.Parse(_expression); - ExpressionToHqlTranslationResults = QueryModelVisitor.GenerateHqlQuery(queryModel, _constantToParameterMap, requiredHqlParameters); + ExpressionToHqlTranslationResults = QueryModelVisitor.GenerateHqlQuery(queryModel, + _constantToParameterMap, + requiredHqlParameters); - ParameterDescriptors = requiredHqlParameters.AsReadOnly(); + ParameterDescriptors = requiredHqlParameters.AsReadOnly(); + _astNode = ExpressionToHqlTranslationResults.Statement.AstNode; + } - return ExpressionToHqlTranslationResults.Statement.AstNode; + return _astNode; } } @@ -89,6 +95,14 @@ MethodCallExpressionNodeTypeRegistry.GetRegisterableMethodDefinition(ReflectionHelper.GetMethod(() => Queryable.Aggregate<object, object>(null, null, null))) }, typeof (AggregateExpressionNode)); + + MethodCallRegistry.Register( + new [] + { + MethodCallExpressionNodeTypeRegistry.GetRegisterableMethodDefinition(ReflectionHelper.GetMethod((List<object> l) => l.Contains(null))), + + }, + typeof(ContainsExpressionNode)); } public static QueryModel Parse(Expression expression) @@ -179,15 +193,5 @@ Accumulator = accumulator; OptionalSelector = optionalSelector; } - - public override IStreamedDataInfo GetOutputDataInfo(IStreamedDataInfo inputInfo) - { - throw new NotImplementedException(); - } - - public override ResultOperatorBase Clone(CloneContext cloneContext) - { - throw new NotImplementedException(); - } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -1,7 +1,9 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Reflection; using NHibernate.Impl; using NHibernate.Type; @@ -22,12 +24,26 @@ var query = _session.CreateQuery(nhLinqExpression); + var nhQuery = query.As<ExpressionQueryImpl>().QueryExpression.As<NhLinqExpression>(); + SetParameters(query, nhLinqExpression.ParameterValuesByName); - SetResultTransformerAndAdditionalCriteria(query, nhLinqExpression.ParameterValuesByName); + SetResultTransformerAndAdditionalCriteria(query, nhQuery, nhLinqExpression.ParameterValuesByName); var results = query.List(); - if (nhLinqExpression.ReturnType == NhLinqExpressionReturnType.Sequence) + if (nhQuery.ExpressionToHqlTranslationResults.PostExecuteTransformer != null) + { + try + { + return nhQuery.ExpressionToHqlTranslationResults.PostExecuteTransformer.DynamicInvoke(results.AsQueryable()); + } + catch (TargetInvocationException e) + { + throw e.InnerException; + } + } + + if (nhLinqExpression.ReturnType == NhLinqExpressionReturnType.Sequence) { return results.AsQueryable(); } @@ -52,28 +68,39 @@ return new NhQueryable<T>(this, expression); } - static void SetParameters(IQuery query, IDictionary<string, Pair<object, IType>> parameters) + static void SetParameters(IQuery query, IDictionary<string, Tuple<object, IType>> parameters) { foreach (var parameterName in query.NamedParameters) { var param = parameters[parameterName]; - if (param.Left == null) + + if (param.First == null) { - query.SetParameter(parameterName, param.Left, param.Right); + if (typeof(ICollection).IsAssignableFrom(param.Second.ReturnedClass)) + { + query.SetParameterList(parameterName, null, param.Second); + } + else + { + query.SetParameter(parameterName, null, param.Second); + } } else { - query.SetParameter(parameterName, param.Left); + if (param.First is ICollection) + { + query.SetParameterList(parameterName, (ICollection) param.First); + } + else + { + query.SetParameter(parameterName, param.First); + } } } } - public void SetResultTransformerAndAdditionalCriteria(IQuery query, IDictionary<string, Pair<object, IType>> parameters) + public void SetResultTransformerAndAdditionalCriteria(IQuery query, NhLinqExpression nhExpression, IDictionary<string, Tuple<object, IType>> parameters) { - var queryImpl = (ExpressionQueryImpl) query; - - var nhExpression = (NhLinqExpression) queryImpl.QueryExpression; - query.SetResultTransformer(nhExpression.ExpressionToHqlTranslationResults.ResultTransformer); foreach (var criteria in nhExpression.ExpressionToHqlTranslationResults.AdditionalCriteria) @@ -83,9 +110,17 @@ } } - public class Pair<TLeft, TRight> + public class Tuple<T1, T2> { - public TLeft Left { get; set; } - public TRight Right { get; set; } + public T1 First { get; set; } + public T2 Second { get; set; } + } + + public class Tuple<T1, T2, T3> + { + public T1 First { get; set; } + public T2 Second { get; set; } + public T3 Third { get; set; } + } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Linq/ReWriters/MergeAggregatingResultsRewriter.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/ReWriters/MergeAggregatingResultsRewriter.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Linq/ReWriters/MergeAggregatingResultsRewriter.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -53,29 +53,40 @@ } else if (resultOperator is CountResultOperator) { - queryModel.SelectClause.Selector = new NhShortCountExpression(queryModel.SelectClause.Selector); + queryModel.SelectClause.Selector = new NhShortCountExpression(new NhStarExpression(queryModel.SelectClause.Selector)); queryModel.ResultOperators.Remove(resultOperator); } else if (resultOperator is LongCountResultOperator) { - queryModel.SelectClause.Selector = new NhLongCountExpression(queryModel.SelectClause.Selector); + queryModel.SelectClause.Selector = new NhLongCountExpression(new NhStarExpression(queryModel.SelectClause.Selector)); queryModel.ResultOperators.Remove(resultOperator); } base.VisitResultOperator(resultOperator, queryModel, index); } - + public override void VisitSelectClause(SelectClause selectClause, QueryModel queryModel) { - selectClause.TransformExpressions(s => new MergeAggregatingResultsInExpressionRewriter().Visit(s)); + selectClause.TransformExpressions(MergeAggregatingResultsInExpressionRewriter.Rewrite); } + + public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index) + { + whereClause.TransformExpressions(MergeAggregatingResultsInExpressionRewriter.Rewrite); + } } - + internal class MergeAggregatingResultsInExpressionRewriter : NhExpressionTreeVisitor { - public Expression Visit(Expression expression) + private MergeAggregatingResultsInExpressionRewriter() + { + } + + public static Expression Rewrite(Expression expression) { - return VisitExpression(expression); + var visitor = new MergeAggregatingResultsInExpressionRewriter(); + + return visitor.VisitExpression(expression); } protected override Expression VisitSubQueryExpression(SubQueryExpression expression) @@ -83,7 +94,7 @@ MergeAggregatingResultsRewriter.ReWrite(expression.QueryModel); return expression; } - + protected override Expression VisitMethodCallExpression(MethodCallExpression m) { if (m.Method.DeclaringType == typeof(Queryable) || @@ -94,36 +105,43 @@ { case "Count": return CreateAggregate(m.Arguments[0], (LambdaExpression)m.Arguments[1], - e => new NhShortCountExpression(e)); + e => new NhShortCountExpression(e), + () => new CountResultOperator()); case "Min": return CreateAggregate(m.Arguments[0], (LambdaExpression) m.Arguments[1], - e => new NhMinExpression(e)); + e => new NhMinExpression(e), + () => new MinResultOperator()); case "Max": return CreateAggregate(m.Arguments[0], (LambdaExpression)m.Arguments[1], - e => new NhMaxExpression(e)); + e => new NhMaxExpression(e), + () => new MaxResultOperator()); case "Sum": return CreateAggregate(m.Arguments[0], (LambdaExpression)m.Arguments[1], - e => new NhSumExpression(e)); + e => new NhSumExpression(e), + () => new SumResultOperator()); case "Average": return CreateAggregate(m.Arguments[0], (LambdaExpression)m.Arguments[1], - e => new NhAverageExpression(e)); + e => new NhAverageExpression(e), + () => new AverageResultOperator()); } } return base.VisitMethodCallExpression(m); } - private Expression CreateAggregate(Expression fromClauseExpression, LambdaExpression body, Func<Expression,Expression> factory) + private Expression CreateAggregate(Expression fromClauseExpression, LambdaExpression body, Func<Expression,Expression> aggregateFactory, Func<ResultOperatorBase> resultOperatorFactory) { + // TODO - need generated name here var fromClause = new MainFromClause("x2", body.Parameters[0].Type, fromClauseExpression); var selectClause = body.Body; selectClause = ReplacingExpressionTreeVisitor.Replace(body.Parameters[0], new QuerySourceReferenceExpression( fromClause), selectClause); var queryModel = new QueryModel(fromClause, - new SelectClause(factory(selectClause))); + new SelectClause(aggregateFactory(selectClause))); - queryModel.ResultOperators.Add(new AverageResultOperator()); + // TODO - this sucks, but we use it to get the Type of the SubQueryExpression correct + queryModel.ResultOperators.Add(resultOperatorFactory()); var subQuery = new SubQueryExpression(queryModel); Modified: trunk/nhibernate/src/NHibernate/Linq/ReWriters/RemoveUnnecessaryBodyOperators.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/ReWriters/RemoveUnnecessaryBodyOperators.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Linq/ReWriters/RemoveUnnecessaryBodyOperators.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -1,8 +1,11 @@ using System; using System.Linq; +using System.Linq.Expressions; +using NHibernate.Linq.Expressions; using Remotion.Data.Linq; using Remotion.Data.Linq.Clauses; using Remotion.Data.Linq.Clauses.ResultOperators; +using Remotion.Data.Linq.Parsing; namespace NHibernate.Linq.ReWriters { Modified: trunk/nhibernate/src/NHibernate/Linq/ResultOperators/ClientSideTransformOperator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/ResultOperators/ClientSideTransformOperator.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Linq/ResultOperators/ClientSideTransformOperator.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -13,7 +13,7 @@ public override IStreamedDataInfo GetOutputDataInfo(IStreamedDataInfo inputInfo) { - throw new NotImplementedException(); + return null; } public override ResultOperatorBase Clone(CloneContext cloneContext) Modified: trunk/nhibernate/src/NHibernate/Linq/ResultTransformer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/ResultTransformer.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Linq/ResultTransformer.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -13,16 +13,10 @@ private readonly Delegate _listTransformation; private readonly Delegate _itemTransformation; - public ResultTransformer(LambdaExpression itemTransformation, LambdaExpression listTransformation) + public ResultTransformer(Delegate itemTransformation, Delegate listTransformation) { - if (itemTransformation != null) - { - _itemTransformation = itemTransformation.Compile(); - } - if (listTransformation != null) - { - _listTransformation = listTransformation.Compile(); - } + _itemTransformation = itemTransformation; + _listTransformation = listTransformation; } public object TransformTuple(object[] tuple, string[] aliases) @@ -39,9 +33,9 @@ object transformResult = collection; - if (collection.Count > 0) + //if (collection.Count > 0) { - if (collection[0] is object[]) + if (collection.Count > 0 && collection[0] is object[]) { if ( ((object[])collection[0]).Length != 1) { Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Linq.Expressions; using NHibernate.Engine.Query; using NHibernate.Hql.Ast; @@ -16,6 +17,13 @@ private readonly IList<NamedParameterDescriptor> _requiredHqlParameters; static private readonly FunctionRegistry FunctionRegistry = FunctionRegistry.Initialise(); + public static HqlTreeNode Visit(Expression expression, IDictionary<ConstantExpression, NamedParameter> parameters, IList<NamedParameterDescriptor> requiredHqlParameters) + { + var visitor = new HqlGeneratorExpressionTreeVisitor(parameters, requiredHqlParameters); + + return visitor.VisitExpression(expression); + } + public HqlGeneratorExpressionTreeVisitor(IDictionary<ConstantExpression, NamedParameter> parameters, IList<NamedParameterDescriptor> requiredHqlParameters) { _parameters = parameters; @@ -23,7 +31,7 @@ _hqlTreeBuilder = new HqlTreeBuilder(); } - public virtual HqlTreeNode Visit(Expression expression) + public HqlTreeNode Visit(Expression expression) { return VisitExpression(expression); } @@ -122,6 +130,8 @@ return VisitNhCount((NhCountExpression)expression); case NhExpressionType.Distinct: return VisitNhDistinct((NhDistinctExpression)expression); + case NhExpressionType.Star: + return VisitNhStar((NhStarExpression) expression); //case NhExpressionType.New: // return VisitNhNew((NhNewExpression)expression); } @@ -130,6 +140,11 @@ } } + protected HqlTreeNode VisitNhStar(NhStarExpression expression) + { + return _hqlTreeBuilder.Star(); + } + private HqlTreeNode VisitInvocationExpression(InvocationExpression expression) { return VisitExpression(expression.Expression); @@ -206,7 +221,7 @@ } // Also check for nullability - if (expression.Left.Type.IsNullable() || expression.Right.Type.IsNullable()) + if (expression.Left.Type.IsNullableOrReference() || expression.Right.Type.IsNullableOrReference()) { // TODO - yuck. This clone is needed because the AST tree nodes are not immutable, // and sharing nodes between multiple branches will cause issues in the hqlSqlWalker phase - @@ -247,7 +262,7 @@ } // Also check for nullability - if (expression.Left.Type.IsNullable() || expression.Right.Type.IsNullable()) + if (expression.Left.Type.IsNullableOrReference() || expression.Right.Type.IsNullableOrReference()) { var lhs2 = VisitExpression(expression.Left).AsExpression(); var rhs2 = VisitExpression(expression.Right).AsExpression(); Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/NhExpressionTreeVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/NhExpressionTreeVisitor.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/NhExpressionTreeVisitor.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -25,13 +25,23 @@ return VisitNhAggregate((NhAggregatedExpression)expression); case NhExpressionType.New: return VisitNhNew((NhNewExpression) expression); + case NhExpressionType.Star: + return VisitNhStar((NhStarExpression) expression); + } return base.VisitExpression(expression); } - protected virtual Expression VisitNhNew(NhNewExpression expression) + protected virtual Expression VisitNhStar(NhStarExpression expression) { + var newExpression = VisitExpression(expression.Expression); + + return newExpression != expression.Expression ? new NhStarExpression(newExpression) : expression; + } + + protected virtual Expression VisitNhNew(NhNewExpression expression) + { var arguments = VisitExpressionList(expression.Arguments); return arguments != expression.Arguments ? new NhNewExpression(expression.Members, arguments) : expression; @@ -60,42 +70,42 @@ protected virtual Expression VisitNhDistinct(NhDistinctExpression expression) { - Expression nx = base.VisitExpression(expression.Expression); + Expression nx = VisitExpression(expression.Expression); return nx != expression.Expression ? new NhDistinctExpression(nx) : expression; } protected virtual Expression VisitNhCount(NhCountExpression expression) { - Expression nx = base.VisitExpression(expression.Expression); + Expression nx = VisitExpression(expression.Expression); return nx != expression.Expression ? new NhShortCountExpression(nx) : expression; } protected virtual Expression VisitNhSum(NhSumExpression expression) { - Expression nx = base.VisitExpression(expression.Expression); + Expression nx = VisitExpression(expression.Expression); return nx != expression.Expression ? new NhSumExpression(nx) : expression; } protected virtual Expression VisitNhMax(NhMaxExpression expression) { - Expression nx = base.VisitExpression(expression.Expression); + Expression nx = VisitExpression(expression.Expression); return nx != expression.Expression ? new NhMaxExpression(nx) : expression; } protected virtual Expression VisitNhMin(NhMinExpression expression) { - Expression nx = base.VisitExpression(expression.Expression); + Expression nx = VisitExpression(expression.Expression); return nx != expression.Expression ? new NhMinExpression(nx) : expression; } protected virtual Expression VisitNhAverage(NhAverageExpression expression) { - Expression nx = base.VisitExpression(expression.Expression); + Expression nx = VisitExpression(expression.Expression); return nx != expression.Expression ? new NhAverageExpression(nx) : expression; } Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/Nominator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/Nominator.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/Nominator.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -9,18 +9,21 @@ /// </summary> class Nominator : NhExpressionTreeVisitor { - readonly Func<Expression, bool> _fnIsCandidate; - HashSet<Expression> _candidates; - bool _cannotBeCandidate; + private readonly Func<Expression, bool> _fnIsCandidate; + private readonly Func<Expression, bool> _fnIsCandidateShortcut; + private HashSet<Expression> _candidates; + private bool _canBeCandidate; - internal Nominator(Func<Expression, bool> fnIsCandidate) + internal Nominator(Func<Expression, bool> fnIsCandidate, Func<Expression, bool> fnIsCandidateShortcut) { _fnIsCandidate = fnIsCandidate; + _fnIsCandidateShortcut = fnIsCandidateShortcut; } internal HashSet<Expression> Nominate(Expression expression) { _candidates = new HashSet<Expression>(); + _canBeCandidate = true; VisitExpression(expression); return _candidates; } @@ -29,12 +32,18 @@ { if (expression != null) { - bool saveCannotBeEvaluated = _cannotBeCandidate; - _cannotBeCandidate = false; + bool saveCanBeCandidate = _canBeCandidate; + _canBeCandidate = true; + if (_fnIsCandidateShortcut(expression)) + { + _candidates.Add(expression); + return expression; + } + base.VisitExpression(expression); - if (!_cannotBeCandidate) + if (_canBeCandidate) { if (_fnIsCandidate(expression)) { @@ -42,11 +51,11 @@ } else { - _cannotBeCandidate = true; + _canBeCandidate = false; } } - _cannotBeCandidate |= saveCannotBeEvaluated; + _canBeCandidate = _canBeCandidate & saveCanBeCandidate; } return expression; Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/QueryModelVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/QueryModelVisitor.cs 2009-12-05 22:14:08 UTC (rev 4894) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/QueryModelVisitor.cs 2009-12-16 21:36:34 UTC (rev 4895) @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Reflection; using NHibernate.Engine.Query; using NHibernate.Hql.Ast; using NHibernate.Linq.GroupBy; @@ -14,6 +15,7 @@ using Remotion.Data.Linq.Clauses; using Remotion.Data.Linq.Clauses.Expressions; using Remotion.Data.Linq.Clauses.ResultOperators; +using Remotion.Data.Linq.Clauses.StreamedData; namespace NHibernate.Linq.Visitors { @@ -50,144 +52,115 @@ private readonly HqlTreeBuilder _hqlTreeBuilder; - private readonly List<Action<IQuery, IDictionary<string, Pair<object, IType>>>> _additionalCriteria = new List<Action<IQuery, IDictionary<string, Pair<object, IType>>>>(); + private readonly List<Action<IQuery, IDictionary<string, Tuple<object, IType>>>> _additionalCriteria = new List<Action<IQuery, IDictionary<string, Tuple<object, IType>>>>(); private readonly List<LambdaExpression> _listTransformers = new List<LambdaExpression>(); ... [truncated message content] |
From: <ric...@us...> - 2009-12-05 22:14:16
|
Revision: 4894 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4894&view=rev Author: ricbrown Date: 2009-12-05 22:14:08 +0000 (Sat, 05 Dec 2009) Log Message: ----------- Fix NH-2030 (Thread unsafe method in SqlTypeFactory) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/SqlTypes/SqlTypeFactory.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2030/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2030/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2030/Mappings.hbm.xml Modified: trunk/nhibernate/src/NHibernate/SqlTypes/SqlTypeFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/SqlTypes/SqlTypeFactory.cs 2009-12-02 15:07:16 UTC (rev 4893) +++ trunk/nhibernate/src/NHibernate/SqlTypes/SqlTypeFactory.cs 2009-12-05 22:14:08 UTC (rev 4894) @@ -47,8 +47,14 @@ SqlType result; if (!SqlTypes.TryGetValue(key, out result)) { - result = createDelegate(length); - SqlTypes.Add(key, result); + lock(SqlTypes) + { + if (!SqlTypes.TryGetValue(key, out result)) + { + result = createDelegate(length); + SqlTypes.Add(key, result); + } + } } return (T) result; } Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2030 ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2030/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2030/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2030/Fixture.cs 2009-12-05 22:14:08 UTC (rev 4894) @@ -0,0 +1,66 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using NHibernate.Dialect; +using NHibernate.SqlTypes; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2030 +{ + [TestFixture] + public class Fixture : BugTestCase + { + + [Test] + public void GetTypeWithLenShouldBeThreadSafe() + { + object sync = new object(); + List<Exception> exceptions = new List<Exception>(); + + ManualResetEvent startEvent = new ManualResetEvent(false); + var action = new ThreadStart + (() => + { + startEvent.WaitOne(); + try + { + for (int i = 0; i < 1000; i++) + { + SqlTypeFactory.GetString(i); + } + } + catch (Exception e) + { + lock (sync) + { + exceptions.Add(e); + } + } + }); + + const int threadCount = 30; + Thread[] threads = new Thread[threadCount]; + for (int i = 0; i < threadCount; i++) + { + threads[i] = new Thread(action); + threads[i].Start(); + } + startEvent.Set(); + foreach (var thread in threads) + { + thread.Join(); + } + + if(exceptions.Count > 0) + { + foreach(var e in exceptions) + Console.WriteLine(e); + + throw exceptions[0]; + } + + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2030/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2030/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2030/Mappings.hbm.xml 2009-12-05 22:14:08 UTC (rev 4894) @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2030"> +</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-12-02 15:07:16 UTC (rev 4893) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-12-05 22:14:08 UTC (rev 4894) @@ -674,6 +674,7 @@ <Compile Include="NHSpecificTest\NH2003\Model.cs" /> <Compile Include="NHSpecificTest\NH2011\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2011\Model.cs" /> + <Compile Include="NHSpecificTest\NH2030\Fixture.cs" /> <Compile Include="NHSpecificTest\NH473\Child.cs" /> <Compile Include="NHSpecificTest\NH473\Fixture.cs" /> <Compile Include="NHSpecificTest\NH473\Parent.cs" /> @@ -2087,6 +2088,7 @@ <EmbeddedResource Include="CfgTest\Loquacious\EntityToCache.hbm.xml" /> <EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH2030\Mappings.hbm.xml" /> <EmbeddedResource Include="Linq\Mappings\Patient.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2011\Mappings.hbm.xml" /> <EmbeddedResource Include="Linq\Mappings\Animal.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ste...@us...> - 2009-12-02 15:07:25
|
Revision: 4893 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4893&view=rev Author: steverstrong Date: 2009-12-02 15:07:16 +0000 (Wed, 02 Dec 2009) Log Message: ----------- Refactoring of HQLQueryPlan changes Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Engine/Query/HQLQueryPlan.cs trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/ASTQueryTranslatorFactory.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs trunk/nhibernate/src/NHibernate/Hql/Classic/ClassicQueryTranslatorFactory.cs trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs trunk/nhibernate/src/NHibernate/Hql/IQueryTranslator.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/BulkManipulation/BaseFixture.cs trunk/nhibernate/src/NHibernate.Test/HQL/Ast/BaseFixture.cs Added Paths: ----------- trunk/nhibernate/src/NHibernate/Engine/Query/HQLExpressionQueryPlan.cs trunk/nhibernate/src/NHibernate/Engine/Query/HQLStringQueryPlan.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/AstPolymorphicProcessor.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/CrossJoinDictionaryArrays.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/PolymorphicQuerySourceDetector.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QuerySourceDetector.cs Added: trunk/nhibernate/src/NHibernate/Engine/Query/HQLExpressionQueryPlan.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/Query/HQLExpressionQueryPlan.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Engine/Query/HQLExpressionQueryPlan.cs 2009-12-02 15:07:16 UTC (rev 4893) @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using NHibernate.Hql; +using NHibernate.Hql.Ast.ANTLR; + +namespace NHibernate.Engine.Query +{ + [Serializable] + public class HQLExpressionQueryPlan : HQLQueryPlan, IQueryExpressionPlan + { + public IQueryExpression QueryExpression + { + get; + protected set; + } + + public HQLExpressionQueryPlan(string expressionStr, IQueryExpression queryExpression, bool shallow, + IDictionary<string, IFilter> enabledFilters, ISessionFactoryImplementor factory) + : this(expressionStr, queryExpression, null, shallow, enabledFilters, factory) + { + } + + protected internal HQLExpressionQueryPlan(string expressionStr, IQueryExpression queryExpression, string collectionRole, bool shallow, + IDictionary<string, IFilter> enabledFilters, ISessionFactoryImplementor factory) + : base(expressionStr, CreateTranslators(expressionStr, queryExpression, collectionRole, shallow, enabledFilters, factory)) + { + QueryExpression = queryExpression; + } + + private static IQueryTranslator[] CreateTranslators(string expressionStr, IQueryExpression queryExpression, string collectionRole, bool shallow, IDictionary<string, IFilter> enabledFilters, ISessionFactoryImplementor factory) + { + IQueryTranslatorFactory2 qtFactory = new ASTQueryTranslatorFactory(); + + return qtFactory.CreateQueryTranslators(expressionStr, queryExpression, collectionRole, shallow, enabledFilters, factory); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Engine/Query/HQLQueryPlan.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/Query/HQLQueryPlan.cs 2009-12-02 05:30:33 UTC (rev 4892) +++ trunk/nhibernate/src/NHibernate/Engine/Query/HQLQueryPlan.cs 2009-12-02 15:07:16 UTC (rev 4893) @@ -1,13 +1,10 @@ using System; using System.Collections; using System.Collections.Generic; -using Iesi.Collections; using Iesi.Collections.Generic; using log4net; using NHibernate.Event; using NHibernate.Hql; -using NHibernate.Hql.Ast.ANTLR; -using NHibernate.Impl; using NHibernate.Type; using NHibernate.Util; @@ -38,39 +35,42 @@ private readonly string _sourceQuery; - protected HQLQueryPlan(string sourceQuery) + protected HQLQueryPlan(string sourceQuery, IQueryTranslator[] translators) { + Translators = translators; _sourceQuery = sourceQuery; + + FinaliseQueryPlan(); } - public ISet<string> QuerySpaces + public ISet<string> QuerySpaces { get; - protected set; + private set; } public ParameterMetadata ParameterMetadata { get; - protected set; + private set; } public ReturnMetadata ReturnMetadata { get; - protected set; + private set; } public string[] SqlStrings { get; - protected set; + private set; } public IQueryTranslator[] Translators { get; - protected set; + private set; } public void PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results) @@ -156,8 +156,26 @@ return new SafetyEnumerable<T>(PerformIterate(queryParameters, session)); } - private void DoIterate(QueryParameters queryParameters, IEventSource session, out bool? isMany, - out IEnumerable[] results, out IEnumerable result) + public int PerformExecuteUpdate(QueryParameters queryParameters, ISessionImplementor session) + { + if (Log.IsDebugEnabled) + { + Log.Debug("executeUpdate: " + _sourceQuery); + queryParameters.LogParameters(session.Factory); + } + if (Translators.Length != 1) + { + Log.Warn("manipulation query [" + _sourceQuery + "] resulted in [" + Translators.Length + "] split queries"); + } + int result = 0; + for (int i = 0; i < Translators.Length; i++) + { + result += Translators[i].ExecuteUpdate(queryParameters, session); + } + return result; + } + + void DoIterate(QueryParameters queryParameters, IEventSource session, out bool? isMany, out IEnumerable[] results, out IEnumerable result) { isMany = null; results = null; @@ -190,176 +208,23 @@ } } - public int PerformExecuteUpdate(QueryParameters queryParameters, ISessionImplementor session) - { - if (Log.IsDebugEnabled) - { - Log.Debug("executeUpdate: " + _sourceQuery); - queryParameters.LogParameters(session.Factory); - } - if (Translators.Length != 1) - { - Log.Warn("manipulation query [" + _sourceQuery + "] resulted in [" + Translators.Length + "] split queries"); - } - int result = 0; - for (int i = 0; i < Translators.Length; i++) - { - result += Translators[i].ExecuteUpdate(queryParameters, session); - } - return result; - } - - protected void BuildSqlStringsAndQuerySpaces() + void FinaliseQueryPlan() { - var combinedQuerySpaces = new HashedSet<string>(); - var sqlStringList = new List<string>(); - - foreach (var translator in Translators) - { - foreach (var qs in translator.QuerySpaces) - { - combinedQuerySpaces.Add(qs); - } - - sqlStringList.AddRange(translator.CollectSqlStrings); - } - - SqlStrings = sqlStringList.ToArray(); - QuerySpaces = combinedQuerySpaces; + BuildSqlStringsAndQuerySpaces(); + BuildMetaData(); } - } - [Serializable] - public class HQLStringQueryPlan : HQLQueryPlan - { - public HQLStringQueryPlan(string hql, bool shallow, - IDictionary<string, IFilter> enabledFilters, ISessionFactoryImplementor factory) - : this(hql, (string) null, shallow, enabledFilters, factory) - { - } - - protected internal HQLStringQueryPlan(string hql, string collectionRole, bool shallow, - IDictionary<string, IFilter> enabledFilters, ISessionFactoryImplementor factory) - :base(hql) - { - Translators = factory.Settings.QueryTranslatorFactory.CreateQueryTranslators(hql, collectionRole, shallow, enabledFilters, factory); - - BuildSqlStringsAndQuerySpaces(); - + void BuildMetaData() + { if (Translators.Length == 0) - { - ParameterMetadata = new ParameterMetadata(null, null); - ReturnMetadata = null; - } - else - { - ParameterMetadata = BuildParameterMetadata(Translators[0].GetParameterTranslations(), hql); - if (Translators[0].IsManipulationStatement) - { - ReturnMetadata = null; - } - else - { - if (Translators.Length > 1) - { - int returns = Translators[0].ReturnTypes.Length; - ReturnMetadata = new ReturnMetadata(Translators[0].ReturnAliases, new IType[returns]); - } - else - { - ReturnMetadata = new ReturnMetadata(Translators[0].ReturnAliases, Translators[0].ReturnTypes); - } - } - } - } - - private static ParameterMetadata BuildParameterMetadata(IParameterTranslations parameterTranslations, string hql) - { - long start = DateTime.Now.Ticks; - ParamLocationRecognizer recognizer = ParamLocationRecognizer.ParseLocations(hql); - long end = DateTime.Now.Ticks; - if (Log.IsDebugEnabled) { - Log.Debug("HQL param location recognition took " + (end - start) + " mills (" + hql + ")"); - } - - int ordinalParamCount = parameterTranslations.OrdinalParameterCount; - int[] locations = recognizer.OrdinalParameterLocationList.ToArray(); - if (parameterTranslations.SupportsOrdinalParameterMetadata && locations.Length != ordinalParamCount) - { - throw new HibernateException("ordinal parameter mismatch"); - } - ordinalParamCount = locations.Length; - OrdinalParameterDescriptor[] ordinalParamDescriptors = new OrdinalParameterDescriptor[ordinalParamCount]; - for (int i = 1; i <= ordinalParamCount; i++) - { - ordinalParamDescriptors[i - 1] = - new OrdinalParameterDescriptor(i, - parameterTranslations.SupportsOrdinalParameterMetadata - ? parameterTranslations.GetOrdinalParameterExpectedType(i) - : null, locations[i - 1]); - } - - Dictionary<string, NamedParameterDescriptor> namedParamDescriptorMap = new Dictionary<string, NamedParameterDescriptor>(); - foreach (KeyValuePair<string, ParamLocationRecognizer.NamedParameterDescription> entry in recognizer.NamedParameterDescriptionMap) - { - string name = entry.Key; - ParamLocationRecognizer.NamedParameterDescription description = entry.Value; - namedParamDescriptorMap[name] = - new NamedParameterDescriptor(name, parameterTranslations.GetNamedParameterExpectedType(name), - description.BuildPositionsArray(), description.JpaStyle); - - } - return new ParameterMetadata(ordinalParamDescriptors, namedParamDescriptorMap); - } - } - - [Serializable] - public class HQLLinqQueryPlan : HQLQueryPlan, IQueryExpressionPlan - { - public IQueryExpression QueryExpression - { - get; - protected set; - } - - public HQLLinqQueryPlan(string expressionStr, IQueryExpression queryExpression, bool shallow, - IDictionary<string, IFilter> enabledFilters, ISessionFactoryImplementor factory) - : this(expressionStr, queryExpression, null, shallow, enabledFilters, factory) - { - } - - protected internal HQLLinqQueryPlan(string expressionStr, IQueryExpression queryExpression, string collectionRole, bool shallow, - IDictionary<string, IFilter> enabledFilters, ISessionFactoryImplementor factory) - : base (expressionStr) - { - QueryExpression = queryExpression; - - IQueryTranslatorFactory2 qtFactory = new ASTQueryTranslatorFactory(); - - Translators = qtFactory.CreateQueryTranslators(expressionStr, queryExpression, collectionRole, shallow, enabledFilters, factory); - - BuildSqlStringsAndQuerySpaces(); - - if (Translators.Length == 0) - { ParameterMetadata = new ParameterMetadata(null, null); ReturnMetadata = null; } else { - var parameterTranslations = Translators[0].GetParameterTranslations(); + ParameterMetadata = Translators[0].BuildParameterMetadata(); - var namedParamDescriptorMap = new Dictionary<string, NamedParameterDescriptor>(); - foreach (NamedParameterDescriptor entry in queryExpression.ParameterDescriptors) - { - namedParamDescriptorMap[entry.Name] = - new NamedParameterDescriptor(entry.Name, parameterTranslations.GetNamedParameterExpectedType(entry.Name), - entry.SourceLocations, entry.JpaStyle); - } - - ParameterMetadata = new ParameterMetadata(new OrdinalParameterDescriptor[0], namedParamDescriptorMap); - if (Translators[0].IsManipulationStatement) { ReturnMetadata = null; @@ -378,5 +243,24 @@ } } } + + void BuildSqlStringsAndQuerySpaces() + { + var combinedQuerySpaces = new HashedSet<string>(); + var sqlStringList = new List<string>(); + + foreach (var translator in Translators) + { + foreach (var qs in translator.QuerySpaces) + { + combinedQuerySpaces.Add(qs); + } + + sqlStringList.AddRange(translator.CollectSqlStrings); + } + + SqlStrings = sqlStringList.ToArray(); + QuerySpaces = combinedQuerySpaces; + } } } Added: trunk/nhibernate/src/NHibernate/Engine/Query/HQLStringQueryPlan.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/Query/HQLStringQueryPlan.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Engine/Query/HQLStringQueryPlan.cs 2009-12-02 15:07:16 UTC (rev 4893) @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using NHibernate.Hql; + +namespace NHibernate.Engine.Query +{ + [Serializable] + public class HQLStringQueryPlan : HQLQueryPlan + { + public HQLStringQueryPlan(string hql, bool shallow, + IDictionary<string, IFilter> enabledFilters, ISessionFactoryImplementor factory) + : this(hql, (string) null, shallow, enabledFilters, factory) + { + } + + protected internal HQLStringQueryPlan(string hql, string collectionRole, bool shallow, + IDictionary<string, IFilter> enabledFilters, ISessionFactoryImplementor factory) + : base(hql, CreateTranslators(hql, collectionRole, shallow, enabledFilters, factory)) + { + } + + private static IQueryTranslator[] CreateTranslators(string hql, string collectionRole, bool shallow, IDictionary<string, IFilter> enabledFilters, ISessionFactoryImplementor factory) + { + return factory.Settings.QueryTranslatorFactory.CreateQueryTranslators(hql, collectionRole, shallow, enabledFilters, factory); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs 2009-12-02 05:30:33 UTC (rev 4892) +++ trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs 2009-12-02 15:07:16 UTC (rev 4893) @@ -85,7 +85,7 @@ { log.Debug("unable to locate HQL query plan in cache; generating (" + expressionStr + ")"); } - plan = new HQLLinqQueryPlan(expressionStr, queryExpression, shallow, enabledFilters, factory); + plan = new HQLExpressionQueryPlan(expressionStr, queryExpression, shallow, enabledFilters, factory); planCache.Put(key, plan); } else Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/ASTQueryTranslatorFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/ASTQueryTranslatorFactory.cs 2009-12-02 05:30:33 UTC (rev 4892) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/ASTQueryTranslatorFactory.cs 2009-12-02 15:07:16 UTC (rev 4893) @@ -1,12 +1,7 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using System.Text; -using Antlr.Runtime; using NHibernate.Engine; using NHibernate.Hql.Ast.ANTLR.Tree; -using NHibernate.Hql.Ast.ANTLR.Util; -using NHibernate.Hql.Util; namespace NHibernate.Hql.Ast.ANTLR { @@ -21,37 +16,21 @@ { public IQueryTranslator[] CreateQueryTranslators(string queryString, string collectionRole, bool shallow, IDictionary<string, IFilter> filters, ISessionFactoryImplementor factory) { - var isFilter = collectionRole != null; - var parser = new HqlParseEngine(queryString, isFilter, factory); - parser.Parse(); + var ast = new HqlParseEngine(queryString, collectionRole != null, factory).Parse(); - HqlParseEngine[] polymorphicParsers = AstPolymorphicProcessor.Process(parser, factory); + return CreateQueryTranslators(ast, queryString, collectionRole, shallow, + filters, factory); + } - var translators = polymorphicParsers - .Select(hql => new QueryTranslatorImpl(queryString, hql, filters, factory)) - .ToArray(); - - foreach (var translator in translators) - { - if (collectionRole == null) - { - translator.Compile(factory.Settings.QuerySubstitutions, shallow); - } - else - { - translator.Compile(collectionRole, factory.Settings.QuerySubstitutions, shallow); - } - } - - return translators; - } - public IQueryTranslator[] CreateQueryTranslators(string queryIdentifier, IQueryExpression queryExpression, string collectionRole, bool shallow, IDictionary<string, IFilter> filters, ISessionFactoryImplementor factory) { - var isFilter = collectionRole != null; - var parser = new HqlParseEngine(queryExpression.Translate(factory), factory); + return CreateQueryTranslators(queryExpression.Translate(factory), queryIdentifier, collectionRole, shallow, + filters, factory); + } - HqlParseEngine[] polymorphicParsers = AstPolymorphicProcessor.Process(parser, factory); + static IQueryTranslator[] CreateQueryTranslators(IASTNode ast, string queryIdentifier, string collectionRole, bool shallow, IDictionary<string, IFilter> filters, ISessionFactoryImplementor factory) + { + var polymorphicParsers = AstPolymorphicProcessor.Process(ast, factory); var translators = polymorphicParsers .Select(hql => new QueryTranslatorImpl(queryIdentifier, hql, filters, factory)) @@ -70,196 +49,7 @@ } return translators; + } } - - public class AstPolymorphicProcessor - { - public static HqlParseEngine[] Process(HqlParseEngine parser, ISessionFactoryImplementor factory) - { - // Find all the polymorphic "froms" - var fromDetector = new FromDetector(factory); - var polymorphic = new NodeTraverser(fromDetector); - polymorphic.TraverseDepthFirst(parser.Ast); - - if (fromDetector.Map.Count > 0) - { - var parsers = DuplicateTree(parser.Ast, fromDetector.Map); - - return parsers.Select(p => new HqlParseEngine(p, factory)).ToArray(); - } - else - { - return new [] { parser }; - } - } - - private static IEnumerable<IASTNode> DuplicateTree(IASTNode ast, IEnumerable<KeyValuePair<IASTNode, IASTNode[]>> nodeMapping) - { - var replacements = ExpandDictionaryArrays(nodeMapping); - - var dups = new IASTNode[replacements.Count()]; - - for (var i = 0; i < replacements.Count(); i++) - { - dups[i] = DuplicateTree(ast, replacements[i]); - } - - return dups; - } - - private static IASTNode DuplicateTree(IASTNode ast, Dictionary<IASTNode, IASTNode> nodeMapping) - { - IASTNode candidate; - - if (nodeMapping.TryGetValue(ast, out candidate)) - { - return candidate; - } - - var dup = ast.DupNode(); - - foreach (var child in ast) - { - dup.AddChild(DuplicateTree(child, nodeMapping)); - } - - return dup; - } - - static IList<Dictionary<IASTNode, IASTNode>> ExpandDictionaryArrays(IEnumerable<KeyValuePair<IASTNode, IASTNode[]>> input) - { - return (from list in ExpandDictionaryArraysInner(input) - select list.ToDictionary(kvp => kvp.Key, kvp => kvp.Value)).ToList(); - } - - static IEnumerable<IEnumerable<KeyValuePair<IASTNode, IASTNode>>> ExpandDictionaryArraysInner(IEnumerable<KeyValuePair<IASTNode, IASTNode[]>> input) - { - var output = new List<IEnumerable<KeyValuePair<IASTNode, IASTNode>>>(); - - foreach (var value in input.First().Value) - { - var inner = new List<KeyValuePair<IASTNode, IASTNode>> - {new KeyValuePair<IASTNode, IASTNode>(input.First().Key, value)}; - - if (input.Count() > 1) - { - output.AddRange(ExpandDictionaryArraysInner(input.Skip(1)).Select(c => c.Union(inner))); - } - else - { - output.Add(inner); - } - } - - return output; - } - - } - - - internal class FromDetector : IVisitationStrategy - { - private readonly ISessionFactoryImplementor _sfi; - private readonly Dictionary<IASTNode, IASTNode[]> _map = new Dictionary<IASTNode, IASTNode[]>(); - - public FromDetector(ISessionFactoryImplementor sfi) - { - _sfi = sfi; - } - - public IDictionary<IASTNode, IASTNode[]> Map - { - get { return _map; } - } - - public void Visit(IASTNode node) - { - if (node.Type == HqlSqlWalker.FROM && node.ChildCount > 0) - { - foreach (var child in node) - { - string className = null; - IASTNode identifer = null; - - if (child.Type == HqlSqlWalker.RANGE) - { - identifer = child.GetChild(0); - - if (identifer.Type == HqlSqlWalker.IDENT) - { - className = identifer.Text; - } - else if (identifer.Type == HqlSqlWalker.DOT) - { - className = BuildPath(identifer); - } - else - { - // TODO - throw new NotSupportedException(); - } - } - else - { - // TODO - stuff for joins? - } - - if (className != null) - { - System.Type classType = (new SessionFactoryHelper(_sfi)).GetImportedClass(className); - - if (classType != null) - { - string[] implementors = _sfi.GetImplementors(classType.FullName); - - if (implementors != null) - { - if (implementors.Length == 1 && - ((implementors[0] == className) || (implementors[0] == classType.FullName))) - { - // No need to change things - return; - } - - Map.Add(identifer, - implementors.Select(implementor => MakeIdent(identifer, implementor)).ToArray()); - } - } - } - } - } - } - - private IASTNode MakeIdent(IASTNode source, string text) - { - var ident = source.DupNode(); - ident.Type = HqlSqlWalker.IDENT; - ident.Text = text; - return ident; - } - - private static string BuildPath(IASTNode node) - { - var sb = new StringBuilder(); - BuildPath(node, sb); - return sb.ToString(); - } - - private static void BuildPath(IASTNode node, StringBuilder sb) - { - if (node.Type == HqlSqlWalker.DOT) - { - BuildPath(node.GetChild(0), sb); - - sb.Append('.'); - sb.Append(node.GetChild(1).Text); - } - else - { - sb.Append(node.Text); - } - } - } - } Added: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/AstPolymorphicProcessor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/AstPolymorphicProcessor.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/AstPolymorphicProcessor.cs 2009-12-02 15:07:16 UTC (rev 4893) @@ -0,0 +1,75 @@ +using System.Collections.Generic; +using System.Linq; +using NHibernate.Engine; +using NHibernate.Hql.Ast.ANTLR.Tree; + +namespace NHibernate.Hql.Ast.ANTLR +{ + public class AstPolymorphicProcessor + { + private readonly IASTNode _ast; + private readonly ISessionFactoryImplementor _factory; + private IEnumerable<KeyValuePair<IASTNode, IASTNode[]>> _nodeMapping; + + private AstPolymorphicProcessor(IASTNode ast, ISessionFactoryImplementor factory) + { + _ast = ast; + _factory = factory; + } + + public static IASTNode[] Process(IASTNode ast, ISessionFactoryImplementor factory) + { + var processor = new AstPolymorphicProcessor(ast, factory); + + return processor.Process(); + } + + private IASTNode[] Process() + { + // Find all the polymorphic query sources + _nodeMapping = new PolymorphicQuerySourceDetector(_factory).Process(_ast); + + if (_nodeMapping.Count() > 0) + { + return DuplicateTree().ToArray(); + } + else + { + return new[] { _ast }; + } + } + + private IEnumerable<IASTNode> DuplicateTree() + { + var replacements = CrossJoinDictionaryArrays.PerformCrossJoin(_nodeMapping); + + var dups = new IASTNode[replacements.Count()]; + + for (var i = 0; i < replacements.Count(); i++) + { + dups[i] = DuplicateTree(_ast, replacements[i]); + } + + return dups; + } + + private static IASTNode DuplicateTree(IASTNode ast, IDictionary<IASTNode, IASTNode> nodeMapping) + { + IASTNode candidate; + + if (nodeMapping.TryGetValue(ast, out candidate)) + { + return candidate; + } + + var dup = ast.DupNode(); + + foreach (var child in ast) + { + dup.AddChild(DuplicateTree(child, nodeMapping)); + } + + return dup; + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/CrossJoinDictionaryArrays.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/CrossJoinDictionaryArrays.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/CrossJoinDictionaryArrays.cs 2009-12-02 15:07:16 UTC (rev 4893) @@ -0,0 +1,33 @@ +using System.Collections.Generic; +using System.Linq; +using NHibernate.Hql.Ast.ANTLR.Tree; + +namespace NHibernate.Hql.Ast.ANTLR +{ + public static class CrossJoinDictionaryArrays + { + public static IList<Dictionary<IASTNode, IASTNode>> PerformCrossJoin(IEnumerable<KeyValuePair<IASTNode, IASTNode[]>> input) + { + return (from list in CrossJoinKeyValuePairList(input) + select list.ToDictionary(kvp => kvp.Key, kvp => kvp.Value)).ToList(); + } + + static IEnumerable<IEnumerable<KeyValuePair<IASTNode, IASTNode>>> CrossJoinKeyValuePairList(IEnumerable<KeyValuePair<IASTNode, IASTNode[]>> input) + { + if (input.Count() == 1) + { + return ExpandKeyValuePair(input.First()); + } + + return from headEntry in ExpandKeyValuePair(input.First()) + from tailEntry in CrossJoinKeyValuePairList(input.Skip(1)) + select headEntry.Union(tailEntry); + } + + static IEnumerable<IEnumerable<KeyValuePair<IASTNode, IASTNode>>> ExpandKeyValuePair(KeyValuePair<IASTNode, IASTNode[]> input) + { + return from i in input.Value + select new List<KeyValuePair<IASTNode, IASTNode>> { new KeyValuePair<IASTNode, IASTNode>(input.Key, i) }.AsEnumerable(); + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/PolymorphicQuerySourceDetector.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/PolymorphicQuerySourceDetector.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/PolymorphicQuerySourceDetector.cs 2009-12-02 15:07:16 UTC (rev 4893) @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NHibernate.Engine; +using NHibernate.Hql.Ast.ANTLR.Tree; +using NHibernate.Hql.Util; + +namespace NHibernate.Hql.Ast.ANTLR +{ + internal class PolymorphicQuerySourceDetector + { + private readonly ISessionFactoryImplementor _sfi; + private readonly Dictionary<IASTNode, IASTNode[]> _map = new Dictionary<IASTNode, IASTNode[]>(); + private readonly SessionFactoryHelper _sessionFactoryHelper; + + public PolymorphicQuerySourceDetector(ISessionFactoryImplementor sfi) + { + _sfi = sfi; + _sessionFactoryHelper = new SessionFactoryHelper(sfi); + } + + public Dictionary<IASTNode, IASTNode[]> Process(IASTNode tree) + { + foreach (var querySource in new QuerySourceDetector(tree).LocateQuerySources()) + { + var className = GetClassName(querySource); + var classType = _sessionFactoryHelper.GetImportedClass(className); + + if (classType != null) + { + AddImplementorsToMap(querySource, classType); + } + } + + return _map; + } + + private void AddImplementorsToMap(IASTNode querySource, System.Type classType) + { + var implementors = _sfi.GetImplementors(classType.FullName); + + if (implementors.Length == 1 && implementors[0] == classType.FullName) + { + // No need to change things + return; + } + + _map.Add(querySource, + implementors.Select(implementor => MakeIdent(querySource, implementor)).ToArray()); + } + + private static string GetClassName(IASTNode querySource) + { + switch (querySource.Type) + { + case HqlSqlWalker.IDENT: + return querySource.Text; + case HqlSqlWalker.DOT: + return BuildPath(querySource); + } + + // TODO + throw new NotSupportedException(); + } + + private static IASTNode MakeIdent(IASTNode source, string text) + { + var ident = source.DupNode(); + ident.Type = HqlSqlWalker.IDENT; + ident.Text = text; + return ident; + } + + private static string BuildPath(IASTNode node) + { + var sb = new StringBuilder(); + BuildPath(node, sb); + return sb.ToString(); + } + + private static void BuildPath(IASTNode node, StringBuilder sb) + { + if (node.Type == HqlSqlWalker.DOT) + { + BuildPath(node.GetChild(0), sb); + + sb.Append('.'); + sb.Append(node.GetChild(1).Text); + } + else + { + sb.Append(node.Text); + } + } + + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QuerySourceDetector.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QuerySourceDetector.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QuerySourceDetector.cs 2009-12-02 15:07:16 UTC (rev 4893) @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using System.Linq; +using NHibernate.Hql.Ast.ANTLR.Tree; +using NHibernate.Hql.Ast.ANTLR.Util; + +namespace NHibernate.Hql.Ast.ANTLR +{ + internal class QuerySourceDetector : IVisitationStrategy + { + private readonly IASTNode _tree; + private readonly List<IASTNode> _nodes; + + public QuerySourceDetector(IASTNode tree) + { + _tree = tree; + _nodes = new List<IASTNode>(); + } + + public IList<IASTNode> LocateQuerySources() + { + // Find all the polymorphic query sources + var nodeTraverser = new NodeTraverser(this); + nodeTraverser.TraverseDepthFirst(_tree); + + return _nodes; + } + + public void Visit(IASTNode node) + { + if (node.Type == HqlSqlWalker.FROM) + { + _nodes.AddRange(node.Where(child => child.Type == HqlSqlWalker.RANGE).Select(range => range.GetChild(0))); + } + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs 2009-12-02 05:30:33 UTC (rev 4892) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QueryTranslatorImpl.cs 2009-12-02 15:07:16 UTC (rev 4893) @@ -6,6 +6,7 @@ using Iesi.Collections.Generic; using log4net; using NHibernate.Engine; +using NHibernate.Engine.Query; using NHibernate.Hql.Ast.ANTLR.Exec; using NHibernate.Hql.Ast.ANTLR.Loader; using NHibernate.Hql.Ast.ANTLR.Tree; @@ -23,63 +24,41 @@ { private static readonly ILog log = LogManager.GetLogger(typeof(QueryTranslatorImpl)); - private bool _shallowQuery; + private readonly string _queryIdentifier; + private readonly IASTNode _stageOneAst; + private readonly ISessionFactoryImplementor _factory; + + private bool _shallowQuery; private bool _compiled; - private readonly string _queryIdentifier; - private readonly string _hql; - private IDictionary<string, IFilter> _enabledFilters; - private readonly ISessionFactoryImplementor _factory; + private IDictionary<string, IFilter> _enabledFilters; private QueryLoader _queryLoader; - private IStatementExecutor statementExecutor; - private IStatement sqlAst; + private IStatementExecutor _statementExecutor; + private IStatement _sqlAst; private ParameterTranslationsImpl _paramTranslations; - private IDictionary<string, string> tokenReplacements; - private HqlParseEngine _parser; + private IDictionary<string, string> _tokenReplacements; private HqlSqlGenerator _generator; /// <summary> /// Creates a new AST-based query translator. /// </summary> /// <param name="queryIdentifier">The query-identifier (used in stats collection)</param> - /// <param name="query">The hql query to translate</param> + /// <param name="parsedQuery">The hql query to translate</param> /// <param name="enabledFilters">Currently enabled filters</param> /// <param name="factory">The session factory constructing this translator instance.</param> public QueryTranslatorImpl( string queryIdentifier, - HqlParseEngine parsedQuery, + IASTNode parsedQuery, IDictionary<string, IFilter> enabledFilters, ISessionFactoryImplementor factory) { _queryIdentifier = queryIdentifier; - _parser = parsedQuery; + _stageOneAst = parsedQuery; _compiled = false; _shallowQuery = false; _enabledFilters = enabledFilters; _factory = factory; } - /// <summary> - /// Creates a new AST-based query translator. - /// </summary> - /// <param name="queryIdentifier">The query-identifier (used in stats collection)</param> - /// <param name="queryExpression">The hql query to translate</param> - /// <param name="enabledFilters">Currently enabled filters</param> - /// <param name="factory">The session factory constructing this translator instance.</param> - public QueryTranslatorImpl( - string queryIdentifier, - IQueryExpression queryExpression, - IDictionary<string, IFilter> enabledFilters, - ISessionFactoryImplementor factory) - { - _queryIdentifier = queryIdentifier; - _hql = queryExpression.ToString(); - _compiled = false; - _shallowQuery = false; - _enabledFilters = enabledFilters; - _factory = factory; - _parser = new HqlParseEngine(queryExpression.Translate(factory), factory); - } - /// <summary> /// Compile a "normal" query. This method may be called multiple /// times. Subsequent invocations are no-ops. @@ -91,11 +70,23 @@ DoCompile( replacements, shallow, null ); } + /// <summary> + /// Compile a filter. This method may be called multiple + /// times. Subsequent invocations are no-ops. + /// </summary> + /// <param name="collectionRole">the role name of the collection used as the basis for the filter.</param> + /// <param name="replacements">Defined query substitutions.</param> + /// <param name="shallow">Does this represent a shallow (scalar or entity-id) select?</param> + public void Compile(string collectionRole, IDictionary<string, string> replacements, bool shallow) + { + DoCompile(replacements, shallow, collectionRole); + } + public IList List(ISessionImplementor session, QueryParameters queryParameters) { // Delegate to the QueryLoader... ErrorIfDML(); - var query = ( QueryNode ) sqlAst; + var query = ( QueryNode ) _sqlAst; bool hasLimit = queryParameters.RowSelection != null && queryParameters.RowSelection.DefinesLimits; bool needsDistincting = ( query.GetSelectClause().IsDistinct || hasLimit ) && ContainsCollectionFetches; @@ -168,14 +159,14 @@ public int ExecuteUpdate(QueryParameters queryParameters, ISessionImplementor session) { ErrorIfSelect(); - return statementExecutor.Execute(queryParameters, session); + return _statementExecutor.Execute(queryParameters, session); } private void ErrorIfSelect() { - if (!sqlAst.NeedsExecutor) + if (!_sqlAst.NeedsExecutor) { - throw new QueryExecutionRequestException("Not supported for select queries:", _hql); + throw new QueryExecutionRequestException("Not supported for select queries:", _queryIdentifier); } } @@ -189,17 +180,44 @@ get { return _queryLoader.ReturnTypes; } } - public string[][] GetColumnNames() + public ParameterMetadata BuildParameterMetadata() + { + var parameterTranslations = GetParameterTranslations(); + + var ordinalDescriptors = new OrdinalParameterDescriptor[parameterTranslations.OrdinalParameterCount]; + + for (var i = 1; i <= ordinalDescriptors.Length; i++) + { + ordinalDescriptors[i - 1] = + new OrdinalParameterDescriptor(i, + parameterTranslations.SupportsOrdinalParameterMetadata + ? parameterTranslations.GetOrdinalParameterExpectedType(i) + : null, parameterTranslations.GetOrdinalParameterSqlLocation(i)); + } + + var namedDescriptorMap = new Dictionary<string, NamedParameterDescriptor>(); + foreach (var name in parameterTranslations.GetNamedParameterNames()) + { + namedDescriptorMap[name] = + new NamedParameterDescriptor(name, parameterTranslations.GetNamedParameterExpectedType(name), + parameterTranslations.GetNamedParameterSqlLocations(name), false);// description.JpaStyle); + + } + + return new ParameterMetadata(ordinalDescriptors, namedDescriptorMap); + } + + public string[][] GetColumnNames() { ErrorIfDML(); - return sqlAst.Walker.SelectClause.ColumnNames; + return _sqlAst.Walker.SelectClause.ColumnNames; } public IParameterTranslations GetParameterTranslations() { if (_paramTranslations == null) { - _paramTranslations = new ParameterTranslationsImpl(sqlAst.Walker.Parameters); + _paramTranslations = new ParameterTranslationsImpl(_sqlAst.Walker.Parameters); } return _paramTranslations; @@ -207,7 +225,7 @@ public ISet<string> QuerySpaces { - get { return sqlAst.Walker.QuerySpaces; } + get { return _sqlAst.Walker.QuerySpaces; } } public string SQLString @@ -217,7 +235,7 @@ public IStatement SqlAST { - get { return sqlAst; } + get { return _sqlAst; } } public IList<IParameterSpecification> CollectedParameterSpecifications @@ -242,7 +260,7 @@ var list = new List<string>(); if (IsManipulationStatement) { - foreach (var sqlStatement in statementExecutor.SqlStatements) + foreach (var sqlStatement in _statementExecutor.SqlStatements) { if (sqlStatement != null) { @@ -260,7 +278,7 @@ public string QueryString { - get { return _hql; } + get { return _queryIdentifier; } } public IDictionary<string, IFilter> EnabledFilters @@ -273,7 +291,7 @@ get { ErrorIfDML(); - return sqlAst.Walker.ReturnTypes; + return _sqlAst.Walker.ReturnTypes; } } @@ -282,7 +300,7 @@ get { ErrorIfDML(); - return sqlAst.Walker.ReturnAliases; + return _sqlAst.Walker.ReturnAliases; } } @@ -291,28 +309,16 @@ get { ErrorIfDML(); - IList<IASTNode> collectionFetches = ((QueryNode)sqlAst).FromClause.GetCollectionFetches(); + IList<IASTNode> collectionFetches = ((QueryNode)_sqlAst).FromClause.GetCollectionFetches(); return collectionFetches != null && collectionFetches.Count > 0; } } public bool IsManipulationStatement { - get { return sqlAst.NeedsExecutor; } + get { return _sqlAst.NeedsExecutor; } } - /// <summary> - /// Compile a filter. This method may be called multiple - /// times. Subsequent invocations are no-ops. - /// </summary> - /// <param name="collectionRole">the role name of the collection used as the basis for the filter.</param> - /// <param name="replacements">Defined query substitutions.</param> - /// <param name="shallow">Does this represent a shallow (scalar or entity-id) select?</param> - public void Compile(string collectionRole, IDictionary<string, string> replacements, bool shallow) - { - DoCompile(replacements, shallow, collectionRole); - } - public bool IsShallowQuery { get { return _shallowQuery; } @@ -337,20 +343,17 @@ } // Remember the parameters for the compilation. - tokenReplacements = replacements ?? new Dictionary<string, string>(1); + _tokenReplacements = replacements ?? new Dictionary<string, string>(1); _shallowQuery = shallow; try { - // PHASE 1 : Parse the HQL into an AST. - HqlParseEngine parser = Parse(true); + // PHASE 1 : Analyze the HQL AST, and produce an SQL AST. + var translator = Analyze(collectionRole); - // PHASE 2 : Analyze the HQL AST, and produce an SQL AST. - var translator = Analyze(parser, collectionRole); + _sqlAst = translator.SqlStatement; - sqlAst = translator.SqlStatement; - // at some point the generate phase needs to be moved out of here, // because a single object-level DML might spawn multiple SQL DML // command executions. @@ -362,24 +365,24 @@ // QueryLoader currently even has a dependency on this at all; does // it need it? Ideally like to see the walker itself given to the delegates directly... - if (sqlAst.NeedsExecutor) + if (_sqlAst.NeedsExecutor) { - statementExecutor = BuildAppropriateStatementExecutor(sqlAst); + _statementExecutor = BuildAppropriateStatementExecutor(_sqlAst); } else { - // PHASE 3 : Generate the SQL. - _generator = new HqlSqlGenerator(sqlAst, parser.Tokens, _factory); + // PHASE 2 : Generate the SQL. + _generator = new HqlSqlGenerator(_sqlAst, _factory); _generator.Generate(); - _queryLoader = new QueryLoader(this, _factory, sqlAst.Walker.SelectClause); + _queryLoader = new QueryLoader(this, _factory, _sqlAst.Walker.SelectClause); } _compiled = true; } catch ( QueryException qe ) { - qe.QueryString = _hql; + qe.QueryString = _queryIdentifier; throw; } catch ( RecognitionException e ) @@ -390,13 +393,13 @@ { log.Info( "converted antlr.RecognitionException", e ); } - throw QuerySyntaxException.Convert( e, _hql ); + throw QuerySyntaxException.Convert(e, _queryIdentifier); } _enabledFilters = null; //only needed during compilation phase... } - private IStatementExecutor BuildAppropriateStatementExecutor(IStatement statement) + private static IStatementExecutor BuildAppropriateStatementExecutor(IStatement statement) { HqlSqlWalker walker = statement.Walker; if (walker.StatementType == HqlSqlWalker.DELETE) @@ -438,30 +441,20 @@ } } - private HqlSqlTranslator Analyze(HqlParseEngine parser, string collectionRole) + private HqlSqlTranslator Analyze(string collectionRole) { - var translator = new HqlSqlTranslator(parser.Ast, parser.Tokens, this, _factory, tokenReplacements, - collectionRole); + var translator = new HqlSqlTranslator(_stageOneAst, this, _factory, _tokenReplacements, collectionRole); + translator.Translate(); return translator; } - private HqlParseEngine Parse(bool isFilter) - { - if (_parser == null) - { - _parser = new HqlParseEngine(_hql, isFilter, _factory); - _parser.Parse(); - } - return _parser; - } - private void ErrorIfDML() { - if (sqlAst.NeedsExecutor) + if (_sqlAst.NeedsExecutor) { - throw new QueryExecutionRequestException("Not supported for DML operations", _hql); + throw new QueryExecutionRequestException("Not supported for DML operations", _queryIdentifier); } } } @@ -473,7 +466,6 @@ private readonly string _hql; private CommonTokenStream _tokens; private readonly bool _filter; - private IASTNode _ast; private readonly ISessionFactoryImplementor _sfi; public HqlParseEngine(string hql, bool filter, ISessionFactoryImplementor sfi) @@ -483,60 +475,38 @@ _sfi = sfi; } - public HqlParseEngine(IASTNode ast, ISessionFactoryImplementor sfi) + public IASTNode Parse() { - _sfi = sfi; - _ast = ast; - } + // Parse the query string into an HQL AST. + var lex = new HqlLexer(new CaseInsensitiveStringStream(_hql)); + _tokens = new CommonTokenStream(lex); - public IASTNode Ast - { - get { return _ast; } - } + var parser = new HqlParser(_tokens) {TreeAdaptor = new ASTTreeAdaptor(), Filter = _filter}; - public CommonTokenStream Tokens - { - get { return _tokens; } - } + if (log.IsDebugEnabled) + { + log.Debug("parse() - HQL: " + _hql); + } - public void Parse() - { - if (_ast == null) - { - // Parse the query string into an HQL AST. - var lex = new HqlLexer(new CaseInsensitiveStringStream(_hql)); - _tokens = new CommonTokenStream(lex); + try + { + var ast = (IASTNode) parser.statement().Tree; - var parser = new HqlParser(_tokens); - parser.TreeAdaptor = new ASTTreeAdaptor(); + var walker = new NodeTraverser(new ConstantConverter(_sfi)); + walker.TraverseDepthFirst(ast); - parser.Filter = _filter; - - if (log.IsDebugEnabled) - { - log.Debug("parse() - HQL: " + _hql); - } - - try - { - _ast = (IASTNode)parser.statement().Tree; - - var walker = new NodeTraverser(new ConstantConverter(_sfi)); - walker.TraverseDepthFirst(_ast); - - //showHqlAst( hqlAst ); - } + return ast; + } finally - { - parser.ParseErrorHandler.ThrowQueryException(); - } - } + { + parser.ParseErrorHandler.ThrowQueryException(); + } } class ConstantConverter : IVisitationStrategy { - private IASTNode dotRoot; - private ISessionFactoryImplementor _sfi; + private IASTNode _dotRoot; + private readonly ISessionFactoryImplementor _sfi; public ConstantConverter(ISessionFactoryImplementor sfi) { @@ -545,31 +515,31 @@ public void Visit(IASTNode node) { - if (dotRoot != null) + if (_dotRoot != null) { // we are already processing a dot-structure - if (ASTUtil.IsSubtreeChild(dotRoot, node)) + if (ASTUtil.IsSubtreeChild(_dotRoot, node)) { // ignore it... return; } // we are now at a new tree level - dotRoot = null; + _dotRoot = null; } - if (dotRoot == null && node.Type == HqlSqlWalker.DOT) + if (_dotRoot == null && node.Type == HqlSqlWalker.DOT) { - dotRoot = node; - HandleDotStructure(dotRoot); + _dotRoot = node; + HandleDotStructure(_dotRoot); } } private void HandleDotStructure(IASTNode dotStructureRoot) { - String expression = ASTUtil.GetPathText(dotStructureRoot); + var expression = ASTUtil.GetPathText(dotStructureRoot); - object constant = ReflectHelper.GetConstantValue(expression, _sfi); + var constant = ReflectHelper.GetConstantValue(expression, _sfi); if (constant != null) { @@ -584,17 +554,15 @@ internal class HqlSqlTranslator { private readonly IASTNode _inputAst; - private readonly CommonTokenStream _tokens; private readonly QueryTranslatorImpl _qti; private readonly ISessionFactoryImplementor _sfi; private readonly IDictionary<string, string> _tokenReplacements; private readonly string _collectionRole; private IStatement _resultAst; - public HqlSqlTranslator(IASTNode ast, CommonTokenStream tokens, QueryTranslatorImpl qti, ISessionFactoryImplementor sfi, IDictionary<string, string> tokenReplacements, string collectionRole) + public HqlSqlTranslator(IASTNode ast, QueryTranslatorImpl qti, ISessionFactoryImplementor sfi, IDictionary<string, string> tokenReplacements, string collectionRole) { _inputAst = ast; - _tokens = tokens; _qti = qti; _sfi = sfi; _tokenReplacements = tokenReplacements; @@ -608,26 +576,25 @@ public IStatement Translate() { - if (_resultAst == null) - { - var nodes = new HqlSqlWalkerTreeNodeStream(_inputAst); - nodes.TokenStream = _tokens; + if (_resultAst == null) + { + var nodes = new HqlSqlWalkerTreeNodeStream(_inputAst); - var hqlSqlWalker = new HqlSqlWalker(_qti, _sfi, nodes, _tokenReplacements, _collectionRole); - hqlSqlWalker.TreeAdaptor = new HqlSqlWalkerTreeAdaptor(hqlSqlWalker); + var hqlSqlWalker = new HqlSqlWalker(_qti, _sfi, nodes, _tokenReplacements, _collectionRole); + hqlSqlWalker.TreeAdaptor = new HqlSqlWalkerTreeAdaptor(hqlSqlWalker); - try - { - // Transform the tree. - _resultAst = (IStatement)hqlSqlWalker.statement().Tree; - } - finally - { - hqlSqlWalker.ParseErrorHandler.ThrowQueryException(); - } - } + try + { + // Transform the tree. + _resultAst = (IStatement) hqlSqlWalker.statement().Tree; + } + finally + { + hqlSqlWalker.ParseErrorHandler.ThrowQueryException(); + } + } - return _resultAst; + return _resultAst; } } @@ -636,15 +603,13 @@ private static readonly ILog log = LogManager.GetLogger(typeof(HqlSqlGenerator)); private readonly IASTNode _ast; - private readonly ITokenStream _tokens; private readonly ISessionFactoryImplementor _sfi; private SqlString _sql; private IList<IParameterSpecification> _parameters; - public HqlSqlGenerator(IStatement ast, ITokenStream tokens, ISessionFactoryImplementor sfi) + public HqlSqlGenerator(IStatement ast, ISessionFactoryImplementor sfi) { _ast = (IASTNode)ast; - _tokens = tokens; _sfi = sfi; } @@ -660,34 +625,30 @@ public SqlString Generate() { - if (_sql == null) - { - var nodes = new CommonTreeNodeStream(_ast); - nodes.TokenStream = _tokens; + if (_sql == null) + { + var gen = new SqlGenerator(_sfi, new CommonTreeNodeStream(_ast)); - var gen = new SqlGenerator(_sfi, nodes); - //gen.TreeAdaptor = new ASTTreeAdaptor(); + try + { + gen.statement(); - try - { - gen.statement(); + _sql = gen.GetSQL(); - _sql = gen.GetSQL(); + if (log.IsDebugEnabled) + { + log.Debug("SQL: " + _sql); + } + } + finally + { + gen.ParseErrorHandler.ThrowQueryException(); + } - if (log.IsDebugEnabled) - { - log.Debug("SQL: " + _sql); - } + _parameters = gen.GetCollectedParameters(); } - finally - { - gen.ParseErrorHandler.ThrowQueryException(); - } - _parameters = gen.GetCollectedParameters(); - } - - return _sql; + return _sql; } } } Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/ClassicQueryTranslatorFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/ClassicQueryTranslatorFactory.cs 2009-12-02 05:30:33 UTC (rev 4892) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/ClassicQueryTranslatorFactory.cs 2009-12-02 15:07:16 UTC (rev 4893) @@ -13,8 +13,8 @@ public IQueryTranslator[] CreateQueryTranslators(string queryString, string collectionRole, bool shallow, IDictionary<string, IFilter> filters, ISessionFactoryImplementor factory) { var translators = QuerySplitter.ConcreteQueries(queryString, factory) - .Select(hql => new QueryTranslator(queryString, hql, filters, factory)) - .ToArray(); + .Select(hql => new QueryTranslator(queryString, hql, filters, factory)) + .ToArray(); foreach (var translator in translators) { Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2009-12-02 05:30:33 UTC (rev 4892) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2009-12-02 15:07:16 UTC (rev 4893) @@ -10,6 +10,7 @@ using log4net; using NHibernate.Engine; +using NHibernate.Engine.Query; using NHibernate.Hql.Util; using NHibernate.Impl; using NHibernate.Loader; @@ -366,7 +367,52 @@ get { return actualReturnTypes; } } - public virtual string[][] ScalarColumnNames + public ParameterMetadata BuildParameterMetadata() + { + return BuildParameterMetadata(GetParameterTranslations(), queryString); + } + + private static ParameterMetadata BuildParameterMetadata(IParameterTranslations parameterTranslations, string hql) + { + long start = DateTime.Now.Ticks; + ParamLocationRecognizer recognizer = ParamLocationRecognizer.ParseLocations(hql); + long end = DateTime.Now.Ticks; + if (log.IsDebugEnabled) + { + log.Debug("HQL param location recognition took " + (end - start) + " mills (" + hql + ")"); + } + + int ordinalParamCount = parameterTranslations.OrdinalParameterCount; + int[] locations = recognizer.OrdinalParameterLocationList.ToArray(); + if (parameterTranslations.SupportsOrdinalParameterMetadata && locations.Length != ordinalParamCount) + { + throw new HibernateException("ordinal parameter mismatch"); + } + ordinalParamCount = locations.Length; + OrdinalParameterDescriptor[] ordinalParamDescriptors = new OrdinalParameterDescriptor[ordinalParamCount]; + for (int i = 1; i <= ordinalParamCount; i++) + { + ordinalParamDescriptors[i - 1] = + new OrdinalParameterDescriptor(i, + parameterTranslations.SupportsOrdinalParameterMetadata + ? parameterTranslations.GetOrdinalParameterExpectedType(i) + : null, locations[i - 1]); + } + + Dictionary<string, NamedParameterDescriptor> namedParamDescriptorMap = new Dictionary<string, NamedParameterDescriptor>(); + foreach (KeyValuePair<string, ParamLocationRecognizer.NamedParameterDescription> entry in recognizer.NamedParameterDescriptionMap) + { + str... [truncated message content] |
From: <fab...@us...> - 2009-12-02 05:30:44
|
Revision: 4892 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4892&view=rev Author: fabiomaulo Date: 2009-12-02 05:30:33 +0000 (Wed, 02 Dec 2009) Log Message: ----------- Encapsulated namespaceManager Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/JoinedSubclassBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/MappingRootBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/SubclassBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/UnionSubclassBinder.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-12-02 05:10:21 UTC (rev 4891) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-12-02 05:30:33 UTC (rev 4892) @@ -13,7 +13,7 @@ public abstract class ClassBinder : Binder { protected readonly Dialect.Dialect dialect; - protected readonly XmlNamespaceManager namespaceManager; + private readonly XmlNamespaceManager namespaceManager; protected ClassBinder(Mappings mappings, XmlNamespaceManager namespaceManager, Dialect.Dialect dialect) : base(mappings) @@ -26,9 +26,14 @@ : base(parent.Mappings) { dialect = parent.dialect; - namespaceManager = parent.namespaceManager; + namespaceManager = parent.NamespaceManager; } + public XmlNamespaceManager NamespaceManager + { + get { return namespaceManager; } + } + protected void BindClass(IEntityMapping classMapping, PersistentClass model, IDictionary<string, MetaAttribute> inheritedMetas) { // handle the lazy attribute @@ -212,7 +217,7 @@ join.CreateForeignKey(); // PROPERTIES - new PropertiesBinder(Mappings, persistentClass, namespaceManager, dialect).Bind(joinMapping.Properties, join.Table, + new PropertiesBinder(Mappings, persistentClass, NamespaceManager, dialect).Bind(joinMapping.Properties, join.Table, inheritedMetas, p => { }, join.AddProperty); @@ -244,14 +249,12 @@ } } - protected PersistentClass GetSuperclass(XmlNode subnode) + protected PersistentClass GetSuperclass(string extendsName) { - XmlAttribute extendsAttr = subnode.Attributes["extends"]; - if (extendsAttr == null) + if (string.IsNullOrEmpty(extendsName)) { - throw new MappingException("'extends' attribute is not found."); + throw new MappingException("'extends' attribute is not found or is empty."); } - string extendsName = extendsAttr.Value; PersistentClass superModel = mappings.GetClass(extendsName); if(superModel == null) { @@ -276,7 +279,7 @@ { //GENERATOR - XmlNode subnode = node.SelectSingleNode(HbmConstants.nsGenerator, namespaceManager); + XmlNode subnode = node.SelectSingleNode(HbmConstants.nsGenerator, NamespaceManager); if (subnode != null) { if (subnode.Attributes["class"] == null) @@ -295,7 +298,7 @@ if (mappings.SchemaName != null) parms.Add(Id.PersistentIdGeneratorParmsNames.Schema, dialect.QuoteForSchemaName(mappings.SchemaName)); - foreach (XmlNode childNode in subnode.SelectNodes(HbmConstants.nsParam, namespaceManager)) + foreach (XmlNode childNode in subnode.SelectNodes(HbmConstants.nsParam, NamespaceManager)) parms.Add( childNode.Attributes["name"].Value, childNode.InnerText @@ -326,7 +329,7 @@ model.RoleName = path; - inheritedMetas = GetMetas(node.SelectNodes(HbmConstants.nsMeta, namespaceManager), inheritedMetas); + inheritedMetas = GetMetas(node.SelectNodes(HbmConstants.nsMeta, NamespaceManager), inheritedMetas); model.MetaAttributes = inheritedMetas; XmlAttribute classNode = node.Attributes["class"]; @@ -371,7 +374,7 @@ IValue value = null; - CollectionBinder binder = new CollectionBinder(Mappings, namespaceManager, dialect); + CollectionBinder binder = new CollectionBinder(Mappings, NamespaceManager, dialect); if (binder.CanCreate(name)) { @@ -510,7 +513,7 @@ "\" for property: " + propName); } - property.MetaAttributes = GetMetas(node.SelectNodes(HbmConstants.nsMeta, namespaceManager), inheritedMetas); + property.MetaAttributes = GetMetas(node.SelectNodes(HbmConstants.nsMeta, NamespaceManager), inheritedMetas); property.LogMapped(log); } @@ -552,7 +555,7 @@ if (typeNode != null) typeName = typeNode.Value; - XmlNode typeChild = node.SelectSingleNode(HbmConstants.nsType, namespaceManager); + XmlNode typeChild = node.SelectSingleNode(HbmConstants.nsType, NamespaceManager); if (typeName == null && typeChild != null) { originalTypeName = typeChild.Attributes["name"].Value; @@ -612,7 +615,7 @@ } else { - var fcn = node.SelectSingleNode(HbmConstants.nsFormula, namespaceManager); + var fcn = node.SelectSingleNode(HbmConstants.nsFormula, NamespaceManager); return fcn != null && !string.IsNullOrEmpty(fcn.InnerText) ? fcn.InnerText : null; } } @@ -661,7 +664,7 @@ if (metaAttribute != null) { model.MetaType = metaAttribute.Value; - XmlNodeList metaValues = node.SelectNodes(HbmConstants.nsMetaValue, namespaceManager); + XmlNodeList metaValues = node.SelectNodes(HbmConstants.nsMetaValue, NamespaceManager); if (metaValues != null && metaValues.Count > 0) { IDictionary<object, string> values = new Dictionary<object, string>(); @@ -811,7 +814,7 @@ { int count = 0; - foreach (XmlNode columnElement in node.SelectNodes(HbmConstants.nsColumn, namespaceManager)) + foreach (XmlNode columnElement in node.SelectNodes(HbmConstants.nsColumn, NamespaceManager)) { Column col = new Column(); col.Value = model; @@ -1011,7 +1014,7 @@ typeName = typeAttribute.Value; else { - XmlNode typeNode = node.SelectSingleNode(HbmConstants.nsType, namespaceManager); + XmlNode typeNode = node.SelectSingleNode(HbmConstants.nsType, NamespaceManager); if (typeNode == null) //we will have to use reflection return null; XmlAttribute nameAttribute = typeNode.Attributes["name"]; //we know it exists because the schema validate it @@ -1039,7 +1042,7 @@ protected XmlNodeList SelectNodes(XmlNode node, string xpath) { - return node.SelectNodes(xpath, namespaceManager); + return node.SelectNodes(xpath, NamespaceManager); } protected static string GetPropertyName(XmlNode node) Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs 2009-12-02 05:10:21 UTC (rev 4891) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs 2009-12-02 05:30:33 UTC (rev 4892) @@ -233,7 +233,7 @@ model.ExtraLazy = true; } - XmlNode oneToManyNode = node.SelectSingleNode(HbmConstants.nsOneToMany, namespaceManager); + XmlNode oneToManyNode = node.SelectSingleNode(HbmConstants.nsOneToMany, NamespaceManager); if (oneToManyNode != null) { OneToMany oneToMany = new OneToMany(model.Owner); @@ -326,14 +326,14 @@ else AddCollectionSecondPass(node, model, inheritedMetas); - foreach (XmlNode filter in node.SelectNodes(HbmConstants.nsFilter, namespaceManager)) + foreach (XmlNode filter in node.SelectNodes(HbmConstants.nsFilter, NamespaceManager)) ParseFilter(filter, model); - XmlNode loader = node.SelectSingleNode(HbmConstants.nsLoader, namespaceManager); + XmlNode loader = node.SelectSingleNode(HbmConstants.nsLoader, NamespaceManager); if (loader != null) model.LoaderName = XmlHelper.GetAttributeValue(loader, "query-ref"); - XmlNode key = node.SelectSingleNode(HbmConstants.nsKey, namespaceManager); + XmlNode key = node.SelectSingleNode(HbmConstants.nsKey, NamespaceManager); if (key != null) model.ReferencedPropertyName = XmlHelper.GetAttributeValue(key, "property-ref"); @@ -438,7 +438,7 @@ private void HandleCustomSQL(XmlNode node, Mapping.Collection model) { - XmlNode element = node.SelectSingleNode(HbmConstants.nsSqlInsert, namespaceManager); + XmlNode element = node.SelectSingleNode(HbmConstants.nsSqlInsert, NamespaceManager); if (element != null) { @@ -446,21 +446,21 @@ model.SetCustomSQLInsert(element.InnerText.Trim(), callable, GetResultCheckStyle(element, callable)); } - element = node.SelectSingleNode(HbmConstants.nsSqlDelete, namespaceManager); + element = node.SelectSingleNode(HbmConstants.nsSqlDelete, NamespaceManager); if (element != null) { bool callable = IsCallable(element); model.SetCustomSQLDelete(element.InnerText.Trim(), callable, GetResultCheckStyle(element, callable)); } - element = node.SelectSingleNode(HbmConstants.nsSqlUpdate, namespaceManager); + element = node.SelectSingleNode(HbmConstants.nsSqlUpdate, NamespaceManager); if (element != null) { bool callable = IsCallable(element); model.SetCustomSQLUpdate(element.InnerText.Trim(), callable, GetResultCheckStyle(element, callable)); } - element = node.SelectSingleNode(HbmConstants.nsSqlDeleteAll, namespaceManager); + element = node.SelectSingleNode(HbmConstants.nsSqlDeleteAll, NamespaceManager); if (element != null) { bool callable = IsCallable(element); @@ -499,8 +499,8 @@ { BindCollectionSecondPass(node, model, persistentClasses, inheritedMetas); - XmlNode subnode = node.SelectSingleNode(HbmConstants.nsListIndex, namespaceManager); - if (subnode == null) { subnode = node.SelectSingleNode(HbmConstants.nsIndex, namespaceManager); } + XmlNode subnode = node.SelectSingleNode(HbmConstants.nsListIndex, NamespaceManager); + if (subnode == null) { subnode = node.SelectSingleNode(HbmConstants.nsIndex, NamespaceManager); } SimpleValue iv = new SimpleValue(model.CollectionTable); BindIntegerValue(subnode, iv, IndexedCollection.DefaultIndexColumnName, model.IsOneToMany); model.Index = iv; @@ -522,7 +522,7 @@ { BindCollectionSecondPass(node, model, persitentClasses, inheritedMetas); - XmlNode subnode = node.SelectSingleNode(HbmConstants.nsCollectionId, namespaceManager); + XmlNode subnode = node.SelectSingleNode(HbmConstants.nsCollectionId, NamespaceManager); SimpleValue id = new SimpleValue(model.CollectionTable); BindSimpleValue(subnode, id, false, IdentifierCollection.DefaultIdentifierColumnName); model.Identifier = id; @@ -715,7 +715,7 @@ collection.ManyToManyOrdering = orderFragment; // Bind the filters - if ((manyToManyNode.SelectSingleNode(HbmConstants.nsFilter, namespaceManager) != null || + if ((manyToManyNode.SelectSingleNode(HbmConstants.nsFilter, NamespaceManager) != null || whereCondition != null) && collection.FetchMode == FetchMode.Join && collection.Element.FetchMode != FetchMode.Join) @@ -723,7 +723,7 @@ "many-to-many defining filter or where without join fetching " + "not valid within collection using join fetching [" + collection.Role + "]" ); - foreach (XmlNode filterElement in manyToManyNode.SelectNodes(HbmConstants.nsFilter, namespaceManager)) + foreach (XmlNode filterElement in manyToManyNode.SelectNodes(HbmConstants.nsFilter, NamespaceManager)) { string name = XmlHelper.GetAttributeValue(filterElement, "name"); string condition = filterElement.InnerText.Trim(); Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/JoinedSubclassBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/JoinedSubclassBinder.cs 2009-12-02 05:10:21 UTC (rev 4891) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/JoinedSubclassBinder.cs 2009-12-02 05:30:33 UTC (rev 4892) @@ -18,9 +18,9 @@ { } - public void Bind(XmlNode node, HbmJoinedSubclass joinedSubclassMapping, IDictionary<string, MetaAttribute> inheritedMetas) + public void Bind(HbmJoinedSubclass joinedSubclassMapping, IDictionary<string, MetaAttribute> inheritedMetas) { - PersistentClass superModel = GetSuperclass(node); + PersistentClass superModel = GetSuperclass(joinedSubclassMapping.extends); HandleJoinedSubclass(superModel, joinedSubclassMapping, inheritedMetas); } @@ -64,7 +64,7 @@ mytable.AddCheckConstraint(joinedSubclassMapping.check); // properties - new PropertiesBinder(mappings, subclass, namespaceManager, dialect).Bind(joinedSubclassMapping.Properties, inheritedMetas); + new PropertiesBinder(mappings, subclass, NamespaceManager, dialect).Bind(joinedSubclassMapping.Properties, inheritedMetas); BindJoinedSubclasses(joinedSubclassMapping.JoinedSubclasses, subclass, inheritedMetas); Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/MappingRootBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/MappingRootBinder.cs 2009-12-02 05:10:21 UTC (rev 4891) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/MappingRootBinder.cs 2009-12-02 05:30:33 UTC (rev 4892) @@ -100,7 +100,7 @@ { var binder = new UnionSubclassBinder(Mappings, GetNamespaceManager(parentNode), dialect); - binder.Bind(parentNode, unionSubclass, inheritedMetas); + binder.Bind(unionSubclass, inheritedMetas); } private void AddJoinedSubclasses(XmlNode parentNode, HbmJoinedSubclass joinedSubclass, @@ -108,14 +108,14 @@ { var binder = new JoinedSubclassBinder(Mappings, GetNamespaceManager(parentNode), dialect); - binder.Bind(parentNode, joinedSubclass, inheritedMetas); + binder.Bind(joinedSubclass, inheritedMetas); } private void AddSubclasses(XmlNode parentNode, HbmSubclass subClass, IDictionary<string, MetaAttribute> inheritedMetas) { var binder = new SubclassBinder(this, GetNamespaceManager(parentNode), dialect); - binder.Bind(parentNode, subClass, inheritedMetas); + binder.Bind(subClass, inheritedMetas); } private void AddQueries(HbmMapping mappingSchema) Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs 2009-12-02 05:10:21 UTC (rev 4891) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs 2009-12-02 05:30:33 UTC (rev 4892) @@ -67,7 +67,7 @@ } else if ((collectionMapping = entityPropertyMapping as ICollectionPropertyMapping) != null) { - var collectionBinder = new CollectionBinder(Mappings, namespaceManager, dialect); + var collectionBinder = new CollectionBinder(Mappings, NamespaceManager, dialect); Mapping.Collection collection = collectionBinder.Create(collectionMapping, entityName, propertyName, model, model.MappedClass, inheritedMetas); Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs 2009-12-02 05:10:21 UTC (rev 4891) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs 2009-12-02 05:30:33 UTC (rev 4892) @@ -57,7 +57,7 @@ rootClass.CreatePrimaryKey(dialect); BindNaturalId(classSchema.naturalid, rootClass, inheritedMetas); - new PropertiesBinder(mappings, rootClass, namespaceManager, dialect).Bind(classSchema.Properties, inheritedMetas); + new PropertiesBinder(mappings, rootClass, NamespaceManager, dialect).Bind(classSchema.Properties, inheritedMetas); BindJoins(classSchema.Joins, rootClass, inheritedMetas); BindSubclasses(classSchema.Subclasses, rootClass, inheritedMetas); @@ -76,7 +76,7 @@ return; } //by default, natural-ids are "immutable" (constant) - var propBinder = new PropertiesBinder(mappings, rootClass, namespaceManager, dialect); + var propBinder = new PropertiesBinder(mappings, rootClass, NamespaceManager, dialect); var uk = new UniqueKey { Name = "_UniqueKey", Table = rootClass.Table }; propBinder.Bind(naturalid.Properties, inheritedMetas, property => { Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/SubclassBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/SubclassBinder.cs 2009-12-02 05:10:21 UTC (rev 4891) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/SubclassBinder.cs 2009-12-02 05:30:33 UTC (rev 4892) @@ -18,9 +18,9 @@ { } - public void Bind(XmlNode node, HbmSubclass subClassMapping, IDictionary<string, MetaAttribute> inheritedMetas) + public void Bind(HbmSubclass subClassMapping, IDictionary<string, MetaAttribute> inheritedMetas) { - PersistentClass superModel = GetSuperclass(node); + PersistentClass superModel = GetSuperclass(subClassMapping.extends); HandleSubclass(superModel, subClassMapping, inheritedMetas); } @@ -37,7 +37,7 @@ log.InfoFormat("Mapping subclass: {0} -> {1}", subclass.EntityName, subclass.Table.Name); // properties - new PropertiesBinder(mappings, subclass, namespaceManager, dialect).Bind(subClassMapping.Properties, inheritedMetas); + new PropertiesBinder(mappings, subclass, NamespaceManager, dialect).Bind(subClassMapping.Properties, inheritedMetas); BindJoins(subClassMapping.Joins, subclass, inheritedMetas); BindSubclasses(subClassMapping.Subclasses, subclass, inheritedMetas); Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/UnionSubclassBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/UnionSubclassBinder.cs 2009-12-02 05:10:21 UTC (rev 4891) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/UnionSubclassBinder.cs 2009-12-02 05:30:33 UTC (rev 4892) @@ -18,9 +18,9 @@ { } - public void Bind(XmlNode node, HbmUnionSubclass unionSubclassMapping, IDictionary<string, MetaAttribute> inheritedMetas) + public void Bind(HbmUnionSubclass unionSubclassMapping, IDictionary<string, MetaAttribute> inheritedMetas) { - PersistentClass superModel = GetSuperclass(node); + PersistentClass superModel = GetSuperclass(unionSubclassMapping.extends); HandleUnionSubclass(superModel, unionSubclassMapping, inheritedMetas); } @@ -48,7 +48,7 @@ log.InfoFormat("Mapping union-subclass: {0} -> {1}", unionSubclass.EntityName, unionSubclass.Table.Name); // properties - new PropertiesBinder(mappings, unionSubclass, namespaceManager, dialect).Bind(unionSubclassMapping.Properties, inheritedMetas); + new PropertiesBinder(mappings, unionSubclass, NamespaceManager, dialect).Bind(unionSubclassMapping.Properties, inheritedMetas); BindUnionSubclasses(unionSubclassMapping.UnionSubclasses, unionSubclass, inheritedMetas); model.AddSubclass(unionSubclass); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-12-02 05:10:32
|
Revision: 4891 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4891&view=rev Author: fabiomaulo Date: 2009-12-02 05:10:21 +0000 (Wed, 02 Dec 2009) Log Message: ----------- binders refactoring - minor logging Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/MappingLogExtensions.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-12-02 04:56:46 UTC (rev 4890) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-12-02 05:10:21 UTC (rev 4891) @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Xml; using NHibernate.Cfg.MappingSchema; using NHibernate.Engine; @@ -511,18 +510,8 @@ "\" for property: " + propName); } - if (log.IsDebugEnabled) - { - string msg = "Mapped property: " + property.Name; - string columns = Columns(property.Value); - if (columns.Length > 0) - msg += " -> " + columns; - if (property.Type != null) - msg += ", type: " + property.Type.Name; - log.Debug(msg); - } - property.MetaAttributes = GetMetas(node.SelectNodes(HbmConstants.nsMeta, namespaceManager), inheritedMetas); + property.LogMapped(log); } protected static PropertyGeneration ParsePropertyGeneration(string name) @@ -538,21 +527,6 @@ } } - protected static string Columns(IValue val) - { - StringBuilder columns = new StringBuilder(); - bool first = true; - foreach (ISelectable col in val.ColumnIterator) - { - if (first) - first = false; - else - columns.Append(", "); - columns.Append(col.Text); - } - return columns.ToString(); - } - //automatically makes a column with the default name if none is specified by XML protected void BindSimpleValue(XmlNode node, SimpleValue model, bool isNullable, string path) { @@ -1078,23 +1052,6 @@ return null; } - protected static void LogMappedProperty(Mapping.Property property) - { - if (log.IsDebugEnabled) - { - string msg = "Mapped property: " + property.Name; - string columns = Columns(property.Value); - - if (columns.Length > 0) - msg += " -> " + columns; - - if (property.Type != null) - msg += ", type: " + property.Type.Name; - - log.Debug(msg); - } - } - protected static void BindIndex(string indexAttribute, Table table, Column column) { if (indexAttribute != null && table != null) Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs 2009-12-02 04:56:46 UTC (rev 4890) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs 2009-12-02 05:10:21 UTC (rev 4891) @@ -122,7 +122,7 @@ property.Generation = PropertyGeneration.Never; property.MetaAttributes = new Dictionary<string, MetaAttribute>(); - LogMappedProperty(property); + property.LogMapped(log); } private System.Type GetPropertyType(System.Type containingType, string propertyName, HbmCompositeId idSchema) @@ -212,7 +212,7 @@ property.Generation = PropertyGeneration.Never; property.MetaAttributes = new Dictionary<string, MetaAttribute>(); - LogMappedProperty(property); + property.LogMapped(log); } private void BindSimpleValue(HbmKeyProperty keyPropertySchema, SimpleValue model, bool isNullable, string path) @@ -268,7 +268,7 @@ property.IsOptimisticLocked = true; property.Generation = PropertyGeneration.Never; property.MetaAttributes = new Dictionary<string, MetaAttribute>(); - LogMappedProperty(property); + property.LogMapped(log); } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs 2009-12-02 04:56:46 UTC (rev 4890) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs 2009-12-02 05:10:21 UTC (rev 4891) @@ -60,7 +60,7 @@ rootClass.IdentifierProperty = property; - LogMappedProperty(property); + property.LogMapped(log); } } Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs 2009-12-02 04:56:46 UTC (rev 4890) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs 2009-12-02 05:10:21 UTC (rev 4891) @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Xml; using NHibernate.Mapping; @@ -479,14 +480,14 @@ if (log.IsDebugEnabled) { - string msg = "Mapped collection key: " + Columns(collection.Key); + string msg = "Mapped collection key: " + string.Join(",", collection.Key.ColumnIterator.Select(c => c.Text).ToArray()); if (collection.IsIndexed) - msg += ", index: " + Columns(((IndexedCollection)collection).Index); + msg += ", index: " + string.Join(",", ((IndexedCollection)collection).Index.ColumnIterator.Select(c => c.Text).ToArray()); if (collection.IsOneToMany) msg += ", one-to-many: " + collection.Element.Type.Name; else { - msg += ", element: " + Columns(collection.Element); + msg += ", element: " + string.Join(",", collection.Element.ColumnIterator.Select(c => c.Text).ToArray()); msg += ", type: " + collection.Element.Type.Name; } log.Debug(msg); Added: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/MappingLogExtensions.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/MappingLogExtensions.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/MappingLogExtensions.cs 2009-12-02 05:10:21 UTC (rev 4891) @@ -0,0 +1,22 @@ +using System.Linq; +using log4net; + +namespace NHibernate.Cfg.XmlHbmBinding +{ + public static class MappingLogExtensions + { + public static void LogMapped(this Mapping.Property property, ILog log) + { + if (log.IsDebugEnabled) + { + string msg = "Mapped property: " + property.Name; + string columns = string.Join(",", property.Value.ColumnIterator.Select(c => c.Text).ToArray()); + if (columns.Length > 0) + msg += " -> " + columns; + if (property.Type != null) + msg += ", type: " + property.Type.Name; + log.Debug(msg); + } + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs 2009-12-02 04:56:46 UTC (rev 4890) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs 2009-12-02 05:10:21 UTC (rev 4891) @@ -172,7 +172,7 @@ property.MetaAttributes = GetMetas(timestampSchema, inheritedMetas); - LogMappedProperty(property); + property.LogMapped(log); } private static PropertyGeneration Convert(HbmVersionGeneration versionGeneration) @@ -253,7 +253,7 @@ property.MetaAttributes = GetMetas(versionSchema, inheritedMetas); - LogMappedProperty(property); + property.LogMapped(log); } private static void BindCache(HbmCache cacheSchema, RootClass rootClass) Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-12-02 04:56:46 UTC (rev 4890) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-12-02 05:10:21 UTC (rev 4891) @@ -548,6 +548,7 @@ <Compile Include="Cfg\MappingSchema\IDecoratable.cs" /> <Compile Include="Cfg\XmlHbmBinding\ColumnsBinder.cs" /> <Compile Include="Cfg\XmlHbmBinding\FiltersBinder.cs" /> + <Compile Include="Cfg\XmlHbmBinding\MappingLogExtensions.cs" /> <Compile Include="Cfg\XmlHbmBinding\PropertiesBinder.cs"> <SubType>Code</SubType> </Compile> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-12-02 04:57:00
|
Revision: 4890 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4890&view=rev Author: fabiomaulo Date: 2009-12-02 04:56:46 +0000 (Wed, 02 Dec 2009) Log Message: ----------- binders refactoring - removed unused code Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/JoinedSubclassBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ValuePropertyBinder.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-12-02 04:27:58 UTC (rev 4889) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-12-02 04:56:46 UTC (rev 4890) @@ -65,7 +65,7 @@ { foreach (var joinedSubclass in joinedSubclasses) { - new JoinedSubclassBinder(this).HandleJoinedSubclass(persistentClass, Serialize(joinedSubclass), joinedSubclass, inheritedMetas); + new JoinedSubclassBinder(this).HandleJoinedSubclass(persistentClass, joinedSubclass, inheritedMetas); } } Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/JoinedSubclassBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/JoinedSubclassBinder.cs 2009-12-02 04:27:58 UTC (rev 4889) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/JoinedSubclassBinder.cs 2009-12-02 04:56:46 UTC (rev 4890) @@ -21,12 +21,12 @@ public void Bind(XmlNode node, HbmJoinedSubclass joinedSubclassMapping, IDictionary<string, MetaAttribute> inheritedMetas) { PersistentClass superModel = GetSuperclass(node); - HandleJoinedSubclass(superModel, node, joinedSubclassMapping, inheritedMetas); + HandleJoinedSubclass(superModel, joinedSubclassMapping, inheritedMetas); } - public void HandleJoinedSubclass(PersistentClass model, XmlNode subnode, HbmJoinedSubclass joinedSubclassMapping, IDictionary<string, MetaAttribute> inheritedMetas) + public void HandleJoinedSubclass(PersistentClass model, HbmJoinedSubclass joinedSubclassMapping, IDictionary<string, MetaAttribute> inheritedMetas) { - JoinedSubclass subclass = new JoinedSubclass(model); + var subclass = new JoinedSubclass(model); BindClass(joinedSubclassMapping, subclass, inheritedMetas); inheritedMetas = GetMetas(joinedSubclassMapping, inheritedMetas, true); // get meta's from <joined-subclass> @@ -50,12 +50,7 @@ log.InfoFormat("Mapping joined-subclass: {0} -> {1}", subclass.EntityName, subclass.Table.Name); // KEY - XmlNode keyNode = subnode.SelectSingleNode(HbmConstants.nsKey, namespaceManager); - SimpleValue key = new DependantValue(mytable, subclass.Identifier); - subclass.Key = key; - if (keyNode.Attributes["on-delete"] != null) - key.IsCascadeDeleteEnabled = "cascade".Equals(keyNode.Attributes["on-delete"].Value); - BindSimpleValue(keyNode, key, false, subclass.EntityName); + BindKey(subclass, joinedSubclassMapping.key, mytable); subclass.CreatePrimaryKey(dialect); @@ -77,5 +72,15 @@ mappings.AddClass(subclass); } + private void BindKey(JoinedSubclass subclass, HbmKey keyMapping, Table mytable) + { + // TODO : property-ref ?? + SimpleValue key = new DependantValue(mytable, subclass.Identifier); + subclass.Key = key; + key.IsCascadeDeleteEnabled = keyMapping.ondelete == HbmOndelete.Cascade; + key.ForeignKeyName = keyMapping.foreignkey; + + new ValuePropertyBinder(key, Mappings).BindSimpleValue(keyMapping, subclass.EntityName, false); + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ValuePropertyBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ValuePropertyBinder.cs 2009-12-02 04:27:58 UTC (rev 4889) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ValuePropertyBinder.cs 2009-12-02 04:56:46 UTC (rev 4890) @@ -51,5 +51,19 @@ }); } } + + public void BindSimpleValue(HbmKey propertyMapping, string propertyPath, bool isNullable) + { + new ColumnsBinder(value, Mappings).Bind(propertyMapping.Columns, isNullable, + () => + new HbmColumn + { + name = mappings.NamingStrategy.PropertyToColumnName(propertyPath), + notnull = propertyMapping.notnull, + notnullSpecified = propertyMapping.notnullSpecified, + unique = propertyMapping.unique, + uniqueSpecified = propertyMapping.uniqueSpecified, + }); + } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |