From: Michael D. <mik...@us...> - 2004-07-19 03:21:54
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14833/NHibernate/Impl Modified Files: PreparerImpl.cs Log Message: Preparer is now using the Driver to built the IDbCommand instead of having the SqlString build an IDbCommand. Index: PreparerImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/PreparerImpl.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PreparerImpl.cs 16 Jul 2004 03:57:56 -0000 1.6 --- PreparerImpl.cs 19 Jul 2004 03:21:32 -0000 1.7 *************** *** 7,22 **** using NHibernate.SqlCommand; ! namespace NHibernate.Impl { ! /// <summary> /// The implementing class for the Interface IPreparer. /// </summary> ! internal class PreparerImpl: IPreparer { ! private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(PreparerImpl)); - private ISessionFactoryImplementor factory; - private ISessionImplementor session; - // key = SqlString or a sql string // value = ADO.NET Command --- 7,25 ---- using NHibernate.SqlCommand; ! namespace NHibernate.Impl ! { /// <summary> /// The implementing class for the Interface IPreparer. /// </summary> ! /// <remarks> ! /// This provides a Session level cache of SqlString/string containing sql to an IDbCommand that has been built with ! /// it. ! /// </remarks> ! internal class PreparerImpl: IPreparer ! { private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(PreparerImpl)); + private readonly ISessionFactoryImplementor factory; + private readonly ISessionImplementor session; // key = SqlString or a sql string // value = ADO.NET Command *************** *** 31,38 **** private IDbConnection currentConnection; ! public PreparerImpl(ISessionFactoryImplementor factory, ISessionImplementor session){ this.factory = factory; this.session = session; - } --- 34,41 ---- private IDbConnection currentConnection; ! public PreparerImpl(ISessionFactoryImplementor factory, ISessionImplementor session) ! { this.factory = factory; this.session = session; } *************** *** 41,53 **** /// </summary> /// <remarks>If the Connection ever changes then we need to clear out the hashtables.</remarks> ! private IDbConnection DbConnection { ! get { return this.currentConnection; } ! set { ! if(currentConnection!=value) { ! ! if(currentConnection!=null) log.Warn("The current connection was not the same at the Connection from the Session"); // reset the prepared Commands because they are specific to --- 44,61 ---- /// </summary> /// <remarks>If the Connection ever changes then we need to clear out the hashtables.</remarks> ! private IDbConnection DbConnection ! { ! get ! { return this.currentConnection; } ! set ! { ! if(currentConnection!=value) ! { ! if(currentConnection!=null) ! { log.Warn("The current connection was not the same at the Connection from the Session"); + } // reset the prepared Commands because they are specific to *************** *** 58,79 **** currentConnection = value; } ! else { ! log.Info("PrepareImpl is using the same connection as the Session"); } } } ! public IDbCommand BuildCommand(string sql) { ! if(builtCommands.ContainsKey(sql)) { ! return (IDbCommand)builtCommands[sql]; ! } ! else { ! IDbCommand cmd = factory.ConnectionProvider.Driver.CreateCommand(); ! cmd.CommandText = sql; ! ! builtCommands.Add(sql, cmd); ! return cmd; } ! } --- 66,91 ---- currentConnection = value; } ! else ! { ! log.Debug("PrepareImpl is using the same connection as the Session"); } } } ! public IDbCommand BuildCommand(string sql) ! { ! IDbCommand cmd = builtCommands[sql] as IDbCommand; ! if( cmd==null ) ! { ! cmd = factory.ConnectionProvider.Driver.GenerateCommand(factory.Dialect, sql); ! if(log.IsDebugEnabled) ! { ! log.Debug( "Building an IDbCommand object for the sql: " + sql ); ! } } ! ! builtCommands[sql] = cmd; ! return cmd; ! } *************** *** 81,92 **** public IDbCommand BuildCommand(SqlString sqlString) { ! if(builtCommands.ContainsKey(sqlString)) ! return (IDbCommand) builtCommands[sqlString]; ! ! IDbCommand cmd = sqlString.BuildCommand(factory.ConnectionProvider.Driver); ! ! builtCommands.Add(sqlString, cmd); return cmd; --- 93,108 ---- public IDbCommand BuildCommand(SqlString sqlString) { + IDbCommand cmd = builtCommands[sqlString] as IDbCommand; ! if( cmd==null ) ! { ! cmd = factory.ConnectionProvider.Driver.GenerateCommand(factory.Dialect, sqlString); ! if(log.IsDebugEnabled) ! { ! log.Debug( "Building an IDbCommand object for the SqlString: " + sqlString.ToString() ); ! } ! } ! builtCommands[sqlString] = cmd; return cmd; *************** *** 99,104 **** /// <param name="command">The command to setup the Transaction on.</param> /// <returns>A IDbCommand with a valid Transaction property.</returns> ! private IDbCommand JoinTransaction(IDbCommand command) { ! IDbTransaction sessionAdoTrx = null; --- 115,120 ---- /// <param name="command">The command to setup the Transaction on.</param> /// <returns>A IDbCommand with a valid Transaction property.</returns> ! private IDbCommand JoinTransaction(IDbCommand command) ! { IDbTransaction sessionAdoTrx = null; *************** *** 112,120 **** // if the sessionAdoTrx is null then we don't want the command to be a part of // any Transaction - so lets set the command trx to null ! if(sessionAdoTrx==null) { ! ! if(command.Transaction!=null) log.Warn("set a nonnull IDbCommand.Transaction to null because the Session had no Transaction"); command.Transaction = null; - } --- 128,138 ---- // if the sessionAdoTrx is null then we don't want the command to be a part of // any Transaction - so lets set the command trx to null ! if(sessionAdoTrx==null) ! { ! if(command.Transaction!=null) ! { ! log.Warn("set a nonnull IDbCommand.Transaction to null because the Session had no Transaction"); ! } command.Transaction = null; } *************** *** 122,132 **** // in a different Transaction than the Session, but I don't understand all of the code // well enough yet to verify that. ! else if (sessionAdoTrx!=command.Transaction) { // got into here because the command was being initialized and had a null Transaction - probably // don't need to be confused by that - just a normal part of initialization... if(command.Transaction!=null) log.Warn("The IDbCommand had a different Transaction than the Session. This can occur when " + ! "Disconnecting and Reconnecting Sessions because the PreparedCommand Cache is Session specific."); command.Transaction = sessionAdoTrx; --- 140,153 ---- // in a different Transaction than the Session, but I don't understand all of the code // well enough yet to verify that. ! else if (sessionAdoTrx!=command.Transaction) ! { // got into here because the command was being initialized and had a null Transaction - probably // don't need to be confused by that - just a normal part of initialization... if(command.Transaction!=null) + { log.Warn("The IDbCommand had a different Transaction than the Session. This can occur when " + ! "Disconnecting and Reconnecting Sessions because the PreparedCommand Cache is Session specific."); ! } command.Transaction = sessionAdoTrx; *************** *** 136,142 **** } ! public IDbCommand PrepareCommand(IDbCommand dbCommand){ - try { dbCommand.Connection = this.DbConnection; dbCommand = JoinTransaction(dbCommand); --- 157,170 ---- } ! public IDbCommand PrepareCommand(IDbCommand dbCommand) ! { ! ! try ! { ! if(log.IsInfoEnabled) ! { ! log.Info(dbCommand.CommandText); ! } dbCommand.Connection = this.DbConnection; dbCommand = JoinTransaction(dbCommand); *************** *** 146,154 **** // one that cannot. // for example - with SqlServer2000 a Command with a binary type ! dbCommand.Prepare(); return dbCommand; } ! catch(Exception e) { throw new ApplicationException( "While preparing " + dbCommand.CommandText + " an error occurred" --- 174,186 ---- // one that cannot. // for example - with SqlServer2000 a Command with a binary type ! if(factory.ConnectionProvider.Driver.SupportsPreparingCommands) ! { ! dbCommand.Prepare(); ! } return dbCommand; } ! catch(Exception e) ! { throw new ApplicationException( "While preparing " + dbCommand.CommandText + " an error occurred" *************** *** 158,193 **** ! public IDbCommand PrepareCommand(string sql) { this.DbConnection = session.Connection; ! IDbCommand cmd = null; ! if(preparedCommands.ContainsKey(sql)) { ! return (IDbCommand)preparedCommands[sql]; } ! ! cmd = this.BuildCommand(sql); cmd = PrepareCommand(cmd); ! preparedCommands.Add(sql, cmd); return cmd; - } ! public IDbCommand PrepareCommand(SqlString sqlString) { this.DbConnection = session.Connection; ! IDbCommand cmd = null; ! if(preparedCommands.ContainsKey(sqlString)) { ! cmd = (IDbCommand)preparedCommands[sqlString]; ! cmd = JoinTransaction(cmd); ! return cmd; } - cmd = this.BuildCommand(sqlString); cmd = PrepareCommand(cmd); ! preparedCommands.Add(sqlString, cmd); ! return cmd; --- 190,221 ---- ! public IDbCommand PrepareCommand(string sql) ! { this.DbConnection = session.Connection; ! IDbCommand cmd = preparedCommands[sql] as IDbCommand; ! if( cmd==null ) { ! cmd = this.BuildCommand(sql); } ! cmd = PrepareCommand(cmd); ! preparedCommands[sql] = cmd; return cmd; } ! public IDbCommand PrepareCommand(SqlString sqlString) ! { this.DbConnection = session.Connection; ! IDbCommand cmd = preparedCommands[sqlString] as IDbCommand; ! if( cmd==null ) { ! cmd = this.BuildCommand(sqlString); } cmd = PrepareCommand(cmd); ! preparedCommands[sqlString] = cmd; return cmd; |