From: Michael D. <mik...@us...> - 2004-10-31 04:31:14
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Loader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14662/NHibernate/Loader Modified Files: CriteriaLoader.cs Loader.cs Log Message: Added class QueryParameters to reduce the number of params in methods. It was taken from h2.1.6 Index: Loader.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Loader/Loader.cs,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** Loader.cs 29 Oct 2004 05:53:49 -0000 1.37 --- Loader.cs 31 Oct 2004 04:31:00 -0000 1.38 *************** *** 93,98 **** return false; } ! ! /// <summary> /// Execute an SQL query and attempt to instantiate instances of the class mapped by the given --- 93,97 ---- return false; } ! /// <summary> /// Execute an SQL query and attempt to instantiate instances of the class mapped by the given *************** *** 117,134 **** private IList DoFind( ISessionImplementor session, ! object[] values, ! IType[] types, object optionalObject, object optionalID, PersistentCollection optionalCollection, object optionalCollectionOwner, ! bool returnProxies, ! RowSelection selection, ! IDictionary namedParams, ! IDictionary lockModes) { ! int maxRows = (selection==null || selection.MaxRows==RowSelection.NoValue) ? ! int.MaxValue : selection.MaxRows; ILoadable[] persisters = Persisters; --- 116,129 ---- private IList DoFind( ISessionImplementor session, ! QueryParameters parameters, object optionalObject, object optionalID, PersistentCollection optionalCollection, object optionalCollectionOwner, ! bool returnProxies) { ! int maxRows = ( parameters.RowSelection==null || parameters.RowSelection.MaxRows==RowSelection.NoValue ) ? ! int.MaxValue : parameters.RowSelection.MaxRows; ILoadable[] persisters = Persisters; *************** *** 139,143 **** string[] suffixes = Suffixes; ! LockMode[] lockModeArray = GetLockModes(lockModes); // this is a CollectionInitializer and we are loading up a single collection --- 134,138 ---- string[] suffixes = Suffixes; ! LockMode[] lockModeArray = GetLockModes( parameters.LockModes ); // this is a CollectionInitializer and we are loading up a single collection *************** *** 164,171 **** st = PrepareCommand( ! ApplyLocks(SqlString, lockModes, session.Factory.Dialect), ! values, types, namedParams, selection, false, session); ! IDataReader rs = GetResultSet(st, selection, session); try --- 159,168 ---- st = PrepareCommand( ! ApplyLocks(SqlString, parameters.LockModes, session.Factory.Dialect), ! parameters, ! false, ! session); ! IDataReader rs = GetResultSet(st, parameters.RowSelection, session); try *************** *** 547,550 **** --- 544,555 ---- } + // [Obsolete("use QueryParameters instead.")] + // protected virtual IDbCommand PrepareCommand(SqlString sqlString, object[] values, IType[] types, IDictionary namedParams, RowSelection selection, bool scroll, ISessionImplementor session) + // { + // QueryParameters qp = new QueryParameters( types, values, namedParams, null, selection ); + // return PrepareCommand( sqlString, qp, scroll, session ); + // + // } + /// <summary> /// Creates an IDbCommand object and populates it with the values necessary to execute it against the *************** *** 559,568 **** /// <param name="session">The SessionImpl this Command is being prepared in.</param> /// <returns>An IDbCommand that is ready to be executed.</returns> ! protected virtual IDbCommand PrepareCommand(SqlString sqlString, object[] values, IType[] types, IDictionary namedParams, RowSelection selection, bool scroll, ISessionImplementor session) { Dialect.Dialect dialect = session.Factory.Dialect; ! bool useLimit = UseLimit(selection, dialect); ! bool scrollable = scroll || (!useLimit && GetFirstRow(selection)!=0); if(useLimit) sqlString = dialect.GetLimitString(sqlString); --- 564,573 ---- /// <param name="session">The SessionImpl this Command is being prepared in.</param> /// <returns>An IDbCommand that is ready to be executed.</returns> ! protected virtual IDbCommand PrepareCommand(SqlString sqlString, QueryParameters parameters, bool scroll, ISessionImplementor session) { Dialect.Dialect dialect = session.Factory.Dialect; ! bool useLimit = UseLimit( parameters.RowSelection, dialect ); ! bool scrollable = scroll || (!useLimit && GetFirstRow(parameters.RowSelection)!=0); if(useLimit) sqlString = dialect.GetLimitString(sqlString); *************** *** 571,577 **** try { ! if (selection!=null && selection.Timeout!=RowSelection.NoValue) { ! command.CommandTimeout = selection.Timeout; } --- 576,582 ---- try { ! if( parameters.RowSelection!=null && parameters.RowSelection.Timeout!=RowSelection.NoValue) { ! command.CommandTimeout = parameters.RowSelection.Timeout; } *************** *** 580,605 **** if( useLimit && dialect.BindLimitParametersFirst ) { ! BindLimitParameters(command, colIndex, selection, session); colIndex+=2; } ! for (int i=0; i < values.Length; i++) { ! types[i].NullSafeSet( command, values[i], colIndex, session); ! colIndex += types[i].GetColumnSpan( session.Factory ); } //if (namedParams!=null) ! colIndex += BindNamedParameters(command, namedParams, colIndex, session); if( useLimit && !dialect.BindLimitParametersFirst ) { ! BindLimitParameters(command, colIndex, selection, session); } ! if(!useLimit) SetMaxRows(command, selection); ! if(selection!=null && selection.Timeout!=RowSelection.NoValue) { ! command.CommandTimeout = selection.Timeout; } --- 585,610 ---- if( useLimit && dialect.BindLimitParametersFirst ) { ! BindLimitParameters(command, colIndex, parameters.RowSelection, session); colIndex+=2; } ! for (int i=0; i < parameters.PositionalParameterValues.Length; i++) { ! parameters.PositionalParameterTypes[i].NullSafeSet( command, parameters.PositionalParameterValues[i], colIndex, session); ! colIndex += parameters.PositionalParameterTypes[i].GetColumnSpan( session.Factory ); } //if (namedParams!=null) ! colIndex += BindNamedParameters(command, parameters.NamedParameters, colIndex, session); if( useLimit && !dialect.BindLimitParametersFirst ) { ! BindLimitParameters(command, colIndex, parameters.RowSelection, session); } ! if(!useLimit) SetMaxRows( command, parameters.RowSelection ); ! if(parameters.RowSelection!=null && parameters.RowSelection.Timeout!=RowSelection.NoValue) { ! command.CommandTimeout = parameters.RowSelection.Timeout; } *************** *** 719,725 **** object optionalObject, object optionalID, ! bool returnProxies) { ! ! return DoFind(session, values, types, optionalObject, optionalID, null, null, returnProxies, null, null, null); } --- 724,731 ---- object optionalObject, object optionalID, ! bool returnProxies) ! { ! QueryParameters qp = new QueryParameters( types, values ); ! return DoFind( session, qp, optionalObject, optionalID, null, null, returnProxies ); } *************** *** 731,735 **** PersistentCollection collection) { ! return DoFind(session, new object[] {id}, new IType[] {type}, null, null, collection, owner, true, null, null, null); } --- 737,742 ---- PersistentCollection collection) { ! QueryParameters qp = new QueryParameters( new IType[] {type}, new object[] {id} ); ! return DoFind( session, qp, null, null, collection, owner, true ); } *************** *** 737,761 **** /// Called by subclasses that implement queries. /// </summary> - /// <param name="session"></param> - /// <param name="values"></param> - /// <param name="types"></param> - /// <param name="returnProxies"></param> - /// <param name="selection"></param> - /// <param name="namedParams"></param> - /// <param name="lockModes"></param> - /// <returns></returns> protected virtual IList Find( ISessionImplementor session, ! object[] values, ! IType[] types, ! bool returnProxies, ! RowSelection selection, ! IDictionary namedParams, ! IDictionary lockModes) { ! return DoFind(session, values, types, null, null, null, null, returnProxies, selection, namedParams, lockModes); } ! ! private string[][] suffixedKeyColumns; private string[][] suffixedVersionColumnNames; --- 744,755 ---- /// Called by subclasses that implement queries. /// </summary> protected virtual IList Find( ISessionImplementor session, ! QueryParameters parameters, ! bool returnProxies) { ! return DoFind( session, parameters, null, null, null, null, returnProxies ); } ! private string[][] suffixedKeyColumns; private string[][] suffixedVersionColumnNames; Index: CriteriaLoader.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Loader/CriteriaLoader.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CriteriaLoader.cs 2 Sep 2004 04:00:39 -0000 1.8 --- CriteriaLoader.cs 31 Oct 2004 04:31:00 -0000 1.9 *************** *** 72,76 **** IType[] typeArray = (IType[]) types.ToArray(typeof(IType)); ! return Find(session, valueArray, typeArray, true, criteria.Selection, null, null); } --- 72,77 ---- IType[] typeArray = (IType[]) types.ToArray(typeof(IType)); ! QueryParameters qp = new QueryParameters( typeArray, valueArray, null, criteria.Selection ); ! return Find( session, qp, true ); } |