From: Sergey K. <jus...@us...> - 2005-04-24 19:38:05
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31965/src/NHibernate/Impl Modified Files: EnumerableImpl.cs Log Message: Integrated two more tests from H2.1, fixed uncovered bugs. Index: EnumerableImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/EnumerableImpl.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** EnumerableImpl.cs 5 Apr 2005 14:24:34 -0000 1.10 --- EnumerableImpl.cs 24 Apr 2005 19:37:57 -0000 1.11 *************** *** 22,26 **** private IType[ ] _types; private bool _single; ! private object[ ] _currentResults; private bool _hasNext; private string[ ][ ] _names; --- 22,26 ---- private IType[ ] _types; private bool _single; ! private object _currentResult; private bool _hasNext; private string[ ][ ] _names; *************** *** 31,34 **** --- 31,35 ---- private int _currentRow = -1; + private System.Reflection.ConstructorInfo _holderConstructor; private RowSelection _selection; *************** *** 42,49 **** /// <param name="columnNames">The names of the columns in the <see cref="IDataReader"/>.</param> /// <param name="selection">The <see cref="RowSelection"/> that should be applied to the <see cref="IDataReader"/>.</param> /// <remarks> /// The <see cref="IDataReader"/> should already be positioned on the first record in <see cref="RowSelection"/>. /// </remarks> ! public EnumerableImpl( IDataReader reader, IDbCommand cmd, ISessionImplementor sess, IType[ ] types, string[ ][ ] columnNames, RowSelection selection ) { _reader = reader; --- 43,52 ---- /// <param name="columnNames">The names of the columns in the <see cref="IDataReader"/>.</param> /// <param name="selection">The <see cref="RowSelection"/> that should be applied to the <see cref="IDataReader"/>.</param> + /// <param name="holderType">Optional type of the result holder (used for "select new SomeClass(...)" queries).</param> /// <remarks> /// The <see cref="IDataReader"/> should already be positioned on the first record in <see cref="RowSelection"/>. /// </remarks> ! public EnumerableImpl( IDataReader reader, IDbCommand cmd, ISessionImplementor sess, IType[ ] types, string[ ][ ] columnNames, RowSelection selection, ! System.Type holderType ) { _reader = reader; *************** *** 54,57 **** --- 57,66 ---- _selection = selection; + if( holderType != null ) + { + _holderConstructor = NHibernate.Util.ReflectHelper.GetConstructor( + holderType, types ); + } + _single = _types.Length == 1; } *************** *** 69,73 **** { log.Debug( "exhausted results" ); ! _currentResults = null; _sess.Batcher.CloseQueryCommand( _cmd, _reader ); } --- 78,82 ---- { log.Debug( "exhausted results" ); ! _currentResult = null; _sess.Batcher.CloseQueryCommand( _cmd, _reader ); } *************** *** 75,89 **** { log.Debug( "retreiving next results" ); - _currentResults = new object[_types.Length]; ! // move through each of the ITypes contained in the IDataReader and convert them ! // to their objects. ! for( int i = 0; i < _types.Length; i++ ) { ! // The IType knows how to extract its value out of the IDataReader. If the IType ! // is a value type then the value will simply be pulled out of the IDataReader. If ! // the IType is an Entity type then the IType will extract the id from the IDataReader ! // and use the ISession to load an instance of the object. ! _currentResults[ i ] = _types[ i ].NullSafeGet( _reader, _names[ i ], _sess, null ); } } --- 84,129 ---- { log.Debug( "retreiving next results" ); ! if( _single ) { ! _currentResult = _types[ 0 ].NullSafeGet( _reader, _names[ 0 ], _sess, null ); ! } ! else ! { ! object[ ] currentResults = new object[_types.Length]; ! ! // move through each of the ITypes contained in the IDataReader and convert them ! // to their objects. ! for( int i = 0; i < _types.Length; i++ ) ! { ! // The IType knows how to extract its value out of the IDataReader. If the IType ! // is a value type then the value will simply be pulled out of the IDataReader. If ! // the IType is an Entity type then the IType will extract the id from the IDataReader ! // and use the ISession to load an instance of the object. ! currentResults[ i ] = _types[ i ].NullSafeGet( _reader, _names[ i ], _sess, null ); ! } ! ! _currentResult = currentResults; ! } ! ! if( _holderConstructor != null ) ! { ! try ! { ! if( _currentResult == null || !_currentResult.GetType().IsArray ) ! { ! _currentResult = _holderConstructor.Invoke( new object[] { _currentResult } ); ! } ! else ! { ! _currentResult = _holderConstructor.Invoke( ( object[ ] )_currentResult ); ! } ! } ! catch( Exception e ) ! { ! throw new QueryException( "Could not instantiate: " ! + _holderConstructor.DeclaringType.FullName, ! e ); ! } } } *************** *** 118,129 **** get { ! if( _single ) ! { ! return _currentResults[ 0 ]; ! } ! else ! { ! return _currentResults; ! } } } --- 158,162 ---- get { ! return _currentResult; } } *************** *** 201,205 **** if( _hasNext ) { ! _currentResults = null; _sess.Batcher.CloseQueryCommand( _cmd, _reader ); } --- 234,238 ---- if( _hasNext ) { ! _currentResult = null; _sess.Batcher.CloseQueryCommand( _cmd, _reader ); } |