internal IEnumerable GetEnumerable(QueryParameters queryParameters, IEventSource session) { CheckQuery(queryParameters); Stopwatch stopWatch = null; if (session.Factory.Statistics.IsStatisticsEnabled) { stopWatch = Stopwatch.StartNew(); } var cmd = PrepareQueryCommand(queryParameters, false, session); // This DbDataReader is disposed of in EnumerableImpl.Dispose var rs = GetResultSet(cmd, queryParameters, session, null); var resultTransformer = _selectNewTransformer ?? queryParameters.ResultTransformer; IEnumerable result = new EnumerableImpl(rs, cmd, session, queryParameters.IsReadOnly(session), _queryTranslator.ReturnTypes, _queryTranslator.GetColumnNames(), queryParameters.RowSelection, resultTransformer, _queryReturnAliases); if (stopWatch != null) { stopWatch.Stop(); session.Factory.StatisticsImplementor.QueryExecuted("HQL: " + _queryTranslator.QueryString, 0, stopWatch.Elapsed); // NH: Different behavior (H3.2 use QueryLoader in AST parser) we need statistic for orginal query too. // probably we have a bug some where else for statistic RowCount session.Factory.StatisticsImplementor.QueryExecuted(QueryIdentifier, 0, stopWatch.Elapsed); } return(result); }
internal async Task <IEnumerable> GetEnumerableAsync(QueryParameters queryParameters, IEventSource session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); CheckQuery(queryParameters); bool statsEnabled = session.Factory.Statistics.IsStatisticsEnabled; var stopWath = new Stopwatch(); if (statsEnabled) { stopWath.Start(); } var cmd = await(PrepareQueryCommandAsync(queryParameters, false, session, cancellationToken)).ConfigureAwait(false); // This DbDataReader is disposed of in EnumerableImpl.Dispose var rs = await(GetResultSetAsync(cmd, queryParameters.HasAutoDiscoverScalarTypes, false, queryParameters.RowSelection, session, cancellationToken)).ConfigureAwait(false); HolderInstantiator hi = HolderInstantiator.GetHolderInstantiator(_selectNewTransformer, queryParameters.ResultTransformer, _queryReturnAliases); IEnumerable result = new EnumerableImpl(rs, cmd, session, queryParameters.IsReadOnly(session), _queryTranslator.ReturnTypes, _queryTranslator.GetColumnNames(), queryParameters.RowSelection, hi); if (statsEnabled) { stopWath.Stop(); session.Factory.StatisticsImplementor.QueryExecuted("HQL: " + _queryTranslator.QueryString, 0, stopWath.Elapsed); // NH: Different behavior (H3.2 use QueryLoader in AST parser) we need statistic for orginal query too. // probably we have a bug some where else for statistic RowCount session.Factory.StatisticsImplementor.QueryExecuted(QueryIdentifier, 0, stopWath.Elapsed); } return(result); }
internal IEnumerable GetEnumerable(QueryParameters queryParameters, ISessionImplementor session) { CheckQuery(queryParameters); bool statsEnabled = session.Factory.Statistics.IsStatisticsEnabled; var stopWath = new Stopwatch(); if (statsEnabled) { stopWath.Start(); } IDbCommand cmd = PrepareQueryCommand(queryParameters, false, session); // This IDataReader is disposed of in EnumerableImpl.Dispose IDataReader rs = GetResultSet(cmd, queryParameters.HasAutoDiscoverScalarTypes, false, queryParameters.RowSelection, session); HolderInstantiator hi = HolderInstantiator.GetHolderInstantiator(_selectNewTransformer, queryParameters.ResultTransformer, _queryReturnAliases); IEnumerable result = new EnumerableImpl(rs, cmd, session, _queryTranslator.ReturnTypes, _queryTranslator.GetColumnNames(), queryParameters.RowSelection, hi); if (statsEnabled) { stopWath.Stop(); session.Factory.StatisticsImplementor.QueryExecuted("HQL: " + _queryTranslator.QueryString, 0, stopWath.Elapsed); // NH: Different behavior (H3.2 use QueryLoader in AST parser) we need statistic for orginal query too. // probably we have a bug some where else for statistic RowCount session.Factory.StatisticsImplementor.QueryExecuted(QueryIdentifier, 0, stopWath.Elapsed); } return(result); }
public void Create_Empty_Sequence() { var item = "Item to test"; var result = EnumerableImpl.Repeat(item, 0); var expectedResult = new string[0]; result.AssertSequenceEqual(expectedResult); }
public void Create_Sequence_With_Null() { string item = null; var count = 4; var result = EnumerableImpl.Repeat(item, count); var expectedResult = new string[] { null, null, null, null }; result.AssertSequenceEqual(expectedResult); }
public void Repeat_Item() { var item = "Item to test"; var count = 3; var result = EnumerableImpl.Repeat(item, count); var expectedResult = new[] { item, item, item }; result.AssertSequenceEqual(expectedResult); }
/// <summary> /// Close an <see cref="IEnumerable" /> returned by NHibernate immediately, /// instead of waiting until the session is closed or disconnected. /// </summary> public static void Close(IEnumerable enumerable) { EnumerableImpl hibernateEnumerable = enumerable as EnumerableImpl; if (hibernateEnumerable == null) { throw new ArgumentException("Not a NHibernate enumerable", "enumerable"); } hibernateEnumerable.Dispose(); }
/* * /// <summary> * /// Create a new Blob. The returned object will be initially immutable. * /// </summary> * /// <param name="bytes">a byte array</param> * /// <returns></returns> * public static Blob CreateBlob(byte[] bytes) { * return new BlobImpl(bytes); * } * * /// <summary> * /// Create a new Blob. The returned object will be initially immutable. * /// </summary> * /// <param name="stream">a binary stream</param> * /// <param name="length">the number of bytes in the stream</param> * /// <returns></returns> * public static Blob CreateBlob(TextReader stream, int length) { * return new BlobImpl(stream, length); * } * * /// <summary> * /// Create a new Blob. The returned object will be initially immutable. * /// </summary> * /// <param name="stream">a binary stream</param> * /// <param name="length">the number of bytes in the stream</param> * /// <returns></returns> * public static Blob CreateBlob(BinaryReader stream, int length) * { * return new BlobImpl(stream, length); * } * * /// <summary> * /// Create a new Blob. The returned object will be initially immutable. * /// </summary> * /// <param name="stream">a binary stream</param> * /// <returns></returns> * public static Blob CreateBlob(StreamReader stream) * { * return new BlobImpl( stream, stream.available() ); * } * * /// <summary> * /// Create a new Blob. The returned object will be initially immutable. * /// </summary> * /// <param name="stream">a binary stream</param> * /// <returns></returns> * public static Blob CreateBlob(BinaryReader stream) * { * return new BlobImpl( stream, stream.available() ); * } * * /// <summary> * /// Create a new Clob. The returned object will be * /// initially immutable. * /// </summary> * /// <param name="str">a String</param> * /// <returns></returns> * public static Clob CreateClob(string str) * { * return new ClobImpl(str); * } * * /// <summary> * /// Create a new Clob. The returned object will be initially immutable. * /// </summary> * /// <param name="reader">a character stream</param> * /// <param name="length">the number of characters in the stream</param> * /// <returns></returns> * public static Clob CreateClob(TextReader reader, int length) { * return new ClobImpl(reader, length); * } */ /// <summary> /// Close an <see cref="IEnumerator" /> obtained from an <see cref="IEnumerable" /> /// returned by NHibernate immediately, instead of waiting until the session is /// closed or disconnected. /// </summary> public static void Close(IEnumerator enumerator) { EnumerableImpl hibernateEnumerator = enumerator as EnumerableImpl; if (hibernateEnumerator == null) { throw new ArgumentException("Not a NHibernate enumerator", "enumerator"); } hibernateEnumerator.Dispose(); }
public void Equal() { Assert.ThrowsExact <ArgumentNullException>(() => Assert.Equal(null as object, null as object, null as IEqualityComparer <object>)); Assert.ThrowsExact <ArgumentNullException>(() => Assert.Equal(null as object, null as object, null as IEqualityComparer)); Assert.DoesNotThrow(() => Assert.Equal(1, 1)); Assert.ThrowsExact <AssertionException>(() => Assert.Equal(1, 0)); Assert.DoesNotThrow(() => Assert.Equal(null, null)); Assert.ThrowsExact <AssertionException>(() => Assert.Equal(null as string, "hello")); Assert.ThrowsExact <AssertionException>(() => Assert.Equal(null as string, 0)); Assert.ThrowsExact <AssertionException>(() => Assert.Equal("000", "0000")); Assert.ThrowsExact <AssertionException>(() => Assert.Equal(new[] { 1, 2 }, new[] { 1, 2, 3 })); Assert.ThrowsExact <AssertionException>(() => Assert.Equal(new[] { 1, 2, 4 }, new[] { 1, 2, 3 })); Assert.ThrowsExact <AssertionException>(() => Assert.Equal(new[] { 1, 2 }, null)); Assert.ThrowsExact <AssertionException>(() => Assert.Equal(new[] { 1, 2 }, new List <int>() { 1, 2 })); Assert.DoesNotThrow(() => Assert.Equal(new[] { 1, 2, 3 }, new[] { 1, 2, 3 })); var arr1 = new[] { new[] { 1, 2 }, new[] { 2, 1 }, }; Assert.DoesNotThrow(() => Assert.Equal(arr1, arr1)); var arr2 = new[] { new[] { 2, 1 }, new[] { 1, 2 }, }; Assert.ThrowsExact <AssertionException>(() => Assert.Equal(arr1, arr2)); arr2 = new[] { new[] { 1, 2 }, new[] { 2, 1 }, }; Assert.DoesNotThrow(() => Assert.Equal(arr1, arr2)); var enumImpl1 = new EnumerableImpl(1, 2); var enumImpl2 = new EnumerableImpl(2, 1); Assert.DoesNotThrow(() => Assert.Equal(enumImpl1, enumImpl1)); Assert.ThrowsExact <AssertionException>(() => Assert.Equal(enumImpl1, enumImpl2)); enumImpl2 = new EnumerableImpl(1, 2); Assert.DoesNotThrow(() => Assert.Equal(enumImpl1, enumImpl2)); Assert.DoesNotThrow(() => Assert.Equal("abc", "ABC", StringComparer.InvariantCultureIgnoreCase)); Assert.DoesNotThrow(() => Assert.Equal("abc" as object, "ABC" as object, StringComparer.InvariantCultureIgnoreCase)); Assert.ThrowsExact <AssertionException>(() => Assert.Equal("abc", "BBB", StringComparer.InvariantCultureIgnoreCase)); Assert.ThrowsExact <AssertionException>(() => Assert.Equal("abc" as object, "BBB" as object, StringComparer.InvariantCultureIgnoreCase)); }
public void Sequences_Are_The_Same_Instance_If_They_Have_The_Same_Type() { Assert.AreSame(EnumerableImpl.Empty <int>(), EnumerableImpl.Empty <int>()); Assert.AreSame(EnumerableImpl.Empty <double>(), EnumerableImpl.Empty <double>()); Assert.AreSame(EnumerableImpl.Empty <int>(), EnumerableImpl.Empty <int>()); Assert.AreSame(EnumerableImpl.Empty <object>(), EnumerableImpl.Empty <object>()); Assert.AreSame(EnumerableImpl.Empty <int>(), EnumerableImpl.Empty <int>()); Assert.AreSame(EnumerableImpl.Empty <long>(), EnumerableImpl.Empty <long>()); Assert.AreNotSame(EnumerableImpl.Empty <int>(), EnumerableImpl.Empty <long>()); Assert.AreNotSame(EnumerableImpl.Empty <double>(), EnumerableImpl.Empty <long>()); Assert.AreNotSame(EnumerableImpl.Empty <object>(), EnumerableImpl.Empty <long>()); }
public void Sequence_Is_Empty() { Assert.IsFalse(EnumerableImpl.Empty <int>().GetEnumerator().MoveNext()); }
public void Null_Predicate_Should_Throw_ArgumentNullException_In_LongCount() { Assert.Throws <ArgumentNullException>(() => EnumerableImpl.Repeat(1, 1).LongCount(null)); }
public void Count_List() { Assert.AreEqual(10, new List <int>(EnumerableImpl.Repeat(1, 10)).Count()); }
public void Count_SemiGenericCollection() { Assert.AreEqual(10, new SemiGenericCollection <int>(EnumerableImpl.Repeat(1, 10)).Count()); }
public void Count_Enumerable() { Assert.AreEqual(10, EnumerableImpl.Repeat(1, 10).Count()); }
public void Usage_Negative_Count_Should_Throw_Exception() { Assert.Throws <ArgumentOutOfRangeException>(() => EnumerableImpl.Repeat("Item to test", -1)); }
public void Range_With_Negative_Start_Value() { var range = EnumerableImpl.Range(-5, 5); range.AssertSequenceEqual(new[] { -5, -4, -3, -2, -1 }); }
public void Simple_Range() { var range = EnumerableImpl.Range(1, 3); range.AssertSequenceEqual(new[] { 1, 2, 3 }); }
public void Range_With_Count_Zero_Should_Be_Empty() { var range = EnumerableImpl.Range(int.MinValue, 0); range.AssertSequenceEqual(new int[0]); }
public ICRegILGen?ResolveNeedBy(Type type, object?key) { if (_container.Registrations.TryGetValue(new KeyAndType(key, type), out var registration)) { if (registration is ICRegMulti multi) { registration = ChooseFromMulti(multi, false) ?? multi.ChosenOne; } } if (registration == null) { if (type.IsDelegate()) { var resultType = type.GetMethod("Invoke") !.ReturnType; var nestedRegistration = ResolveNeedBy(resultType, key); if (nestedRegistration == null) { return(null); } registration = new DelegateImpl(key, type, nestedRegistration); } else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Lazy <>)) { var resultType = type.GetGenericArguments()[0]; var nestedRegistration = ResolveNeedBy(resultType, key); if (nestedRegistration == null) { return(null); } registration = new LazyImpl(type, nestedRegistration); } else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable <>)) { var resultType = type.GetGenericArguments()[0]; var child = MakeEnumEnabledChild(); var nestedRegistration = child.ResolveNeedBy(resultType, key); if (nestedRegistration == null) { if (key != null) { return(null); } registration = new EmptyEnumerableImpl(type, resultType); } else { registration = new EnumerableImpl(key, type, resultType, child, nestedRegistration); } } else if (type.IsArray && type.GetArrayRank() == 1) { var resultType = type.GetElementType(); var child = MakeEnumEnabledChild(); var nestedRegistration = child.ResolveNeedBy(resultType !, key); if (nestedRegistration == null) { return(null); } registration = new EnumerableImpl(key, type, resultType, child, nestedRegistration); } else if (type.IsGenericType && TupleTypes.Contains(type.GetGenericTypeDefinition())) { registration = new AlwaysNewImpl(type, type.GetConstructors()[0], false); } } if (registration != null) { if (registration is ICRegILGen result) { return(result); } throw new ArgumentException("Builder for " + type.ToSimpleName() + " is not ILGen capable"); } return(null); }
public void Range_With_Values_Out_Of_Range_Should_Throw_ArgumentOutOfRangeException() { Assert.Throws <ArgumentOutOfRangeException>(() => EnumerableImpl.Range(int.MaxValue, 2)); }
public void Range_With_Count_Less_Than_Zero_Should_Throw_ArgumentOutOfRangeException() { Assert.Throws <ArgumentOutOfRangeException>(() => EnumerableImpl.Range(10, -1)); }
public void Range_With_Count_One_Should_Return_One_Item() { var range = EnumerableImpl.Range(int.MaxValue, 1); range.AssertSequenceEqual(new[] { int.MaxValue }); }