Skip to content

Commit f646fc9

Browse files
Merge branch 'master' into ObsoleteMultiQuery
2 parents 765fe45 + 25777a3 commit f646fc9

File tree

7 files changed

+96
-27
lines changed

7 files changed

+96
-27
lines changed

doc/reference/modules/basic_mapping.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3982,12 +3982,11 @@
39823982
</para>
39833983

39843984
<para>
3985-
The <literal>ICompositeUserType</literal>, <literal>IEnhancedUserType</literal>,
3986-
<literal>INullableUserType</literal>, <literal>IUserCollectionType</literal>,
3987-
and <literal>IUserVersionType</literal> interfaces provide support for more specialized
3988-
uses.
3985+
The <literal>IEnhancedUserType</literal>, <literal>IUserVersionType</literal>,
3986+
and <literal>IUserCollectionType</literal> interfaces provide support for more specialized
3987+
uses. The later is to be used with collections, see <xref linkend="collections-persistent" />.
39893988
</para>
3990-
3989+
39913990
<para>
39923991
You may even supply parameters to an <literal>IUserType</literal> in the mapping file. To
39933992
do this, your <literal>IUserType</literal> must implement the

doc/reference/modules/performance.xml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,4 +1405,67 @@ var items = list.GetEnumerable();]]></programlisting>
14051405
</para>
14061406

14071407
</sect1>
1408+
1409+
<sect1 id="performance-future">
1410+
<title>Future results</title>
1411+
1412+
<para>
1413+
Queries can be converted to future results instead of being directly executed. Future
1414+
results are not evaluated till one gets executed. At that point, all defined future
1415+
results are evaluated in one single round-trip to the database.
1416+
</para>
1417+
1418+
<para>
1419+
Future results are an alternative to using <xref linkend="performance-multi-query"/>.
1420+
They avoid the need to explicitly regroup queries, but they also hide which queries will
1421+
get executed: any pending future results of the session will be batched together, no
1422+
matter where they were defined, included out-of-scope pending future results.
1423+
</para>
1424+
1425+
<para>
1426+
Future results are obtained by calling <literal>Future</literal> or
1427+
<literal>FutureValue</literal> methods of a HQL, Criteria, QueryOver or SQL query.
1428+
For LINQ queries, the methods are named <literal>ToFuture</literal> and
1429+
<literal>ToFutureValue</literal>, see <xref linkend="querylinq-futureresults"/> for
1430+
an example.
1431+
</para>
1432+
1433+
<programlisting><![CDATA[// Define queries
1434+
IFutureEnumerable<Cat> cats =
1435+
session.CreateQuery("from Cat c where c.Color = :color")
1436+
.SetString("color", "black")
1437+
.Future();
1438+
IFutureValue<int> catCount =
1439+
session.QueryOver<Cat>()
1440+
.ToRowCountQuery()
1441+
.FutureValue<int>();
1442+
// Execute them
1443+
foreach(Cat cat in cats.GetEnumerable())
1444+
{
1445+
// Do something
1446+
}
1447+
if (catCount.Value > 10)
1448+
{
1449+
// Do something
1450+
}
1451+
]]></programlisting>
1452+
1453+
<para>
1454+
In the above example, accessing <literal>catCount.Value</literal> does not trigger a round-trip
1455+
to the database: it has been evaluated with <literal>cats.GetEnumerable()</literal> call. If
1456+
instead <literal>catCount.Value</literal> was accessed first, it would have executed both
1457+
future results and <literal>cats.GetEnumerable()</literal> would not have triggered a round-trip
1458+
to the database.
1459+
</para>
1460+
1461+
<para>
1462+
As showcased in the previous example, <literal>Future</literal> allows to get a future enumerable
1463+
result, and <literal>FutureValue</literal> is meant to obtain a single value result.
1464+
</para>
1465+
1466+
<para>
1467+
Note: in NHibernate v5.1 and previous versions, Criteria/QueryOver future results were batched
1468+
separately. Since NHibernate v5.2, they are batched with other querying API future results.
1469+
</para>
1470+
</sect1>
14081471
</chapter>

doc/reference/modules/query_linq.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ using NHibernate.Linq;]]></programlisting>
425425

426426
<para>
427427
Future results are supported by the Linq provider. They are not evaluated till one gets executed.
428-
At that point, all defined future results are evaluated in one single round-trip to database.
428+
At that point, all defined future results are evaluated in one single round-trip to the database.
429429
</para>
430430
<programlisting><![CDATA[// Define queries
431431
IFutureEnumerable<Cat> cats =
@@ -446,10 +446,7 @@ if (catCount.Value > 10)
446446
}
447447
]]></programlisting>
448448
<para>
449-
In above example, accessing <literal>catCount.Value</literal> does not trigger a round-trip to database:
450-
it has been evaluated with <literal>cats.GetEnumerable()</literal> call. If instead
451-
<literal>catCount.Value</literal> was accessed first, it would have executed both future and
452-
<literal>cats.GetEnumerable()</literal> would have not trigger a round-trip to database.
449+
See <xref linkend="performance-future" /> for more information.
453450
</para>
454451
</sect1>
455452

src/NHibernate/UserTypes/ICompositeUserType.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@ namespace NHibernate.UserTypes
99
/// A UserType that may be dereferenced in a query.
1010
/// This interface allows a custom type to define "properties".
1111
/// These need not necessarily correspond to physical .NET style properties.
12-
///
13-
/// A ICompositeUserType may be used in almost every way
12+
/// </summary>
13+
/// <remarks>
14+
/// <para>
15+
/// An <c>ICompositeUserType</c> may be used in almost every way
1416
/// that a component may be used. It may even contain many-to-one
1517
/// associations.
16-
///
17-
/// Implementors must be immutable and must declare a public
18-
/// default constructor.
19-
///
20-
/// Unlike UserType, cacheability does not depend upon
21-
/// serializability. Instead, Assemble() and
22-
/// Disassemble() provide conversion to/from a cacheable
18+
/// </para>
19+
/// <para>
20+
/// Implementors must declare a public default constructor.
21+
/// </para>
22+
/// <para>
23+
/// For ensuring cacheability, <see cref="Assemble" /> and
24+
/// <see cref="Disassemble" /> must provide conversion to/from a cacheable
2325
/// representation.
24-
/// </summary>
26+
/// </para>
27+
/// </remarks>
2528
public interface ICompositeUserType
2629
{
2730
/// <summary>
@@ -135,4 +138,4 @@ public interface ICompositeUserType
135138
/// </summary>
136139
object Replace(object original, object target, ISessionImplementor session, object owner);
137140
}
138-
}
141+
}

src/NHibernate/UserTypes/IEnhancedUserType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace NHibernate.UserTypes
44
{
55
/// <summary>
66
/// A custom type that may function as an identifier or discriminator
7-
/// type, or may be marshalled to and from an XML document.
7+
/// type.
88
/// </summary>
99
public interface IEnhancedUserType : IUserType
1010
{

src/NHibernate/UserTypes/ILoggableUserType.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using NHibernate.Engine;
23

34
namespace NHibernate.UserTypes
@@ -6,6 +7,8 @@ namespace NHibernate.UserTypes
67
/// Marker interface for user types which want to perform custom
78
/// logging of their corresponding values
89
/// </summary>
10+
// Since 5.2
11+
[Obsolete("This interface has no usage and will be removed in a future version")]
912
public interface ILoggableUserType
1013
{
1114
/// <summary> Generate a loggable string representation of the collection (value). </summary>

src/NHibernate/UserTypes/IUserType.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,23 @@ namespace NHibernate.UserTypes
1010
/// <remarks>
1111
/// <para>
1212
/// The interface abstracts user code from future changes to the <see cref="Type.IType"/> interface,
13-
/// simplifies the implementation of custom types and hides certain "internal interfaces from
13+
/// simplifies the implementation of custom types and hides certain "internal interfaces" from
1414
/// user code.
1515
/// </para>
1616
/// <para>
17-
/// Implementers must be immutable and must declare a public default constructor.
17+
/// Implementers must declare a public default constructor.
1818
/// </para>
1919
/// <para>
20-
/// The actual class mapped by a <c>IUserType</c> may be just about anything. However, if it is to
21-
/// be cacheble by a persistent cache, it must be serializable.
20+
/// The actual class mapped by a <c>IUserType</c> may be just about anything.
21+
/// </para>
22+
/// <para>
23+
/// For ensuring cacheability, <see cref="Assemble" /> and
24+
/// <see cref="Disassemble" /> must provide conversion to/from a cacheable
25+
/// representation.
2226
/// </para>
2327
/// <para>
2428
/// Alternatively, custom types could implement <see cref="Type.IType"/> directly or extend one of the
25-
/// abstract classes in <c>NHibernate.Type</c>. This approach risks future incompatible changes
29+
/// abstract classes in <c>NHibernate.Type</c>. This approach risks more future incompatible changes
2630
/// to classes or interfaces in the package.
2731
/// </para>
2832
/// </remarks>

0 commit comments

Comments
 (0)