From: <fab...@us...> - 2011-04-25 12:13:06
|
Revision: 5759 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5759&view=rev Author: fabiomaulo Date: 2011-04-25 12:12:59 +0000 (Mon, 25 Apr 2011) Log Message: ----------- Fix NH-2661 implementing a new drive for MsSQL-2008 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs trunk/nhibernate/src/NHibernate/AdoNet/NonBatchingBatcher.cs trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs trunk/nhibernate/src/NHibernate/Driver/DriverBase.cs trunk/nhibernate/src/NHibernate/Driver/IDriver.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/App.config trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2660And2661/Test.cs Added Paths: ----------- trunk/nhibernate/src/NHibernate/Driver/Sql2008ClientDriver.cs Modified: trunk/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs =================================================================== --- trunk/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs 2011-04-25 05:57:46 UTC (rev 5758) +++ trunk/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs 2011-04-25 12:12:59 UTC (rev 5759) @@ -57,7 +57,7 @@ factory = connectionManager.Factory; } - private IDriver Driver + protected IDriver Driver { get { return factory.ConnectionProvider.Driver; } } Modified: trunk/nhibernate/src/NHibernate/AdoNet/NonBatchingBatcher.cs =================================================================== --- trunk/nhibernate/src/NHibernate/AdoNet/NonBatchingBatcher.cs 2011-04-25 05:57:46 UTC (rev 5758) +++ trunk/nhibernate/src/NHibernate/AdoNet/NonBatchingBatcher.cs 2011-04-25 12:12:59 UTC (rev 5759) @@ -36,6 +36,7 @@ public override void AddToBatch(IExpectation expectation) { IDbCommand cmd = CurrentCommand; + Driver.AdjustCommand(cmd); int rowCount = ExecuteNonQuery(cmd); expectation.VerifyOutcomeNonBatched(rowCount, cmd); } Modified: trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs =================================================================== --- trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs 2011-04-25 05:57:46 UTC (rev 5758) +++ trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs 2011-04-25 12:12:59 UTC (rev 5759) @@ -1,5 +1,7 @@ using System.Data; using System.Data.Common; +using System.Data.SqlClient; +using System.Linq; using System.Text; using NHibernate.AdoNet.Util; using NHibernate.Exceptions; @@ -49,7 +51,7 @@ { totalExpectedRowsAffected += expectation.ExpectedRowCount; IDbCommand batchUpdate = CurrentCommand; - + Driver.AdjustCommand(batchUpdate); string lineWithParameters = null; var sqlStatementLogger = Factory.Settings.SqlStatementLogger; if (sqlStatementLogger.IsDebugEnabled || log.IsDebugEnabled) Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs 2011-04-25 05:57:46 UTC (rev 5758) +++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs 2011-04-25 12:12:59 UTC (rev 5759) @@ -1,5 +1,7 @@ using System.Data; +using NHibernate.Cfg; using NHibernate.Dialect.Function; +using NHibernate.Driver; namespace NHibernate.Dialect { @@ -30,5 +32,11 @@ RegisterKeyword("time"); RegisterKeyword("hierarchyid"); } + + protected override void RegisterDefaultProperties() + { + base.RegisterDefaultProperties(); + DefaultProperties[Environment.ConnectionDriver] = typeof(Sql2008ClientDriver).AssemblyQualifiedName; + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Driver/DriverBase.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Driver/DriverBase.cs 2011-04-25 05:57:46 UTC (rev 5758) +++ trunk/nhibernate/src/NHibernate/Driver/DriverBase.cs 2011-04-25 12:12:59 UTC (rev 5759) @@ -255,6 +255,7 @@ public void PrepareCommand(IDbCommand command) { + AdjustCommand(command); OnBeforePrepare(command); if (SupportsPreparingCommands && prepareSql) @@ -272,6 +273,19 @@ { } + /// <summary> + /// Override to make any adjustments to each IDbCommand object before it added to the batcher. + /// </summary> + /// <param name="command">The command.</param> + /// <remarks> + /// This method is similar to the <see cref="OnBeforePrepare"/> but, instead be called just before execute the command (that can be a batch) + /// is executed before add each single command to the batcher and before <see cref="OnBeforePrepare"/> . + /// If you have to adjust parameters values/type (when the command is full filled) this is a good place where do it. + /// </remarks> + public virtual void AdjustCommand(IDbCommand command) + { + } + public IDbDataParameter GenerateOutputParameter(IDbCommand command) { IDbDataParameter param = GenerateParameter(command, "ReturnValue", SqlTypeFactory.Int32); Modified: trunk/nhibernate/src/NHibernate/Driver/IDriver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Driver/IDriver.cs 2011-04-25 05:57:46 UTC (rev 5758) +++ trunk/nhibernate/src/NHibernate/Driver/IDriver.cs 2011-04-25 12:12:59 UTC (rev 5759) @@ -73,7 +73,7 @@ /// Prepare the <paramref name="command" /> by calling <see cref="IDbCommand.Prepare()" />. /// May be a no-op if the driver does not support preparing commands, or for any other reason. /// </summary> - /// <param name="command"></param> + /// <param name="command">The command.</param> void PrepareCommand(IDbCommand command); /// <summary> @@ -99,5 +99,15 @@ IResultSetsCommand GetResultSetsCommand(ISessionImplementor session); bool SupportsMultipleQueries { get; } + + /// <summary> + /// Make any adjustments to each IDbCommand object before it is added to the batcher. + /// </summary> + /// <param name="command">The command.</param> + /// <remarks> + /// This method should be executed before add each single command to the batcher. + /// If you have to adjust parameters values/type (when the command is full filled) this is a good place where do it. + /// </remarks> + void AdjustCommand(IDbCommand command); } } \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Driver/Sql2008ClientDriver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Driver/Sql2008ClientDriver.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Driver/Sql2008ClientDriver.cs 2011-04-25 12:12:59 UTC (rev 5759) @@ -0,0 +1,28 @@ +using System; +using System.Data; +using System.Data.SqlClient; +using System.Linq; + +namespace NHibernate.Driver +{ + public class Sql2008ClientDriver : SqlClientDriver + { + protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlTypes.SqlType sqlType) + { + base.InitializeParameter(dbParam, name, sqlType); + if (sqlType.DbType == DbType.Time) + { + ((SqlParameter) dbParam).SqlDbType = SqlDbType.Time; + } + } + + public override void AdjustCommand(IDbCommand command) + { + foreach (var parameter in command.Parameters.Cast<SqlParameter>().Where(x => x.SqlDbType == SqlDbType.Time && (x.Value is DateTime))) + { + var dateTimeValue = (DateTime)parameter.Value; + parameter.Value = dateTimeValue.TimeOfDay; + } + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-25 05:57:46 UTC (rev 5758) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-25 12:12:59 UTC (rev 5759) @@ -157,6 +157,7 @@ <Compile Include="Driver\OleDbDriver.cs" /> <Compile Include="Driver\OracleClientDriver.cs" /> <Compile Include="Driver\OracleDataClientDriver.cs" /> + <Compile Include="Driver\Sql2008ClientDriver.cs" /> <Compile Include="Driver\SqlClientDriver.cs" /> <Compile Include="Driver\BasicResultSetsCommand.cs" /> <Compile Include="Driver\SQLiteDriver.cs" /> Modified: trunk/nhibernate/src/NHibernate.Test/App.config =================================================================== --- trunk/nhibernate/src/NHibernate.Test/App.config 2011-04-25 05:57:46 UTC (rev 5758) +++ trunk/nhibernate/src/NHibernate.Test/App.config 2011-04-25 12:12:59 UTC (rev 5759) @@ -53,7 +53,6 @@ <property name="format_sql">true</property> <!-- This is the System.Data.dll provider for MSSQL Server --> - <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property> <property name="connection.connection_string">Server=localhost\sqlexpress;initial catalog=nhibernate;Integrated Security=SSPI</property> Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2660And2661/Test.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2660And2661/Test.cs 2011-04-25 05:57:46 UTC (rev 5758) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2660And2661/Test.cs 2011-04-25 12:12:59 UTC (rev 5759) @@ -1,5 +1,7 @@ using System; +using NHibernate.Cfg; using NHibernate.Dialect; +using NHibernate.Driver; using NUnit.Framework; using SharpTestsEx; @@ -34,6 +36,13 @@ return dialect is MsSql2008Dialect; } + protected override void Configure(Configuration configuration) + { + // to be sure we are using the new drive + base.Configure(configuration); + configuration.DataBaseIntegration(x=> x.Driver<Sql2008ClientDriver>()); + } + [Test, Ignore("workaround to sqlserver DP, not fixed yet")] public void ShouldBeAbleToQueryEntity() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |