Skip to content

Commit 606a079

Browse files
author
Sergey Koshcheyev
committed
Added fetch="select/join" attribute from Hibernate 3. fetch="select" is equivalent to outer-join="false", and fetch="join" is equivalent to outer-join="true".
This is experimental for now, and there are no tests using fetch attribute. SVN: trunk@1733
1 parent 9280632 commit 606a079

File tree

4 files changed

+59
-17
lines changed

4 files changed

+59
-17
lines changed

src/NHibernate/Cfg/Binder.cs

+31-11
Original file line numberDiff line numberDiff line change
@@ -1111,24 +1111,44 @@ private static IType GetTypeFromXML( XmlNode node )
11111111

11121112
private static void InitOuterJoinFetchSetting( XmlNode node, IFetchable model )
11131113
{
1114-
XmlAttribute jfNode = node.Attributes[ "outer-join" ];
1115-
if( jfNode == null )
1116-
{
1117-
model.OuterJoinFetchSetting = OuterJoinFetchStrategy.Auto;
1118-
}
1119-
else
1114+
XmlAttribute fetchNode = node.Attributes[ "fetch" ];
1115+
1116+
OuterJoinFetchStrategy fetchStyle;
1117+
1118+
if( fetchNode == null )
11201119
{
1121-
string eoj = jfNode.Value;
1122-
if( "auto".Equals( eoj ) )
1120+
XmlAttribute jfNode = node.Attributes[ "outer-join" ];
1121+
if( jfNode == null )
11231122
{
1124-
model.OuterJoinFetchSetting = OuterJoinFetchStrategy.Auto;
1123+
fetchStyle = OuterJoinFetchStrategy.Auto;
11251124
}
11261125
else
11271126
{
1128-
model.OuterJoinFetchSetting = ( "true".Equals( eoj ) ) ?
1129-
OuterJoinFetchStrategy.Eager : OuterJoinFetchStrategy.Lazy;
1127+
// use old (HB 2.1) defaults if outer-join is specified
1128+
string eoj = jfNode.Value;
1129+
if( "auto".Equals( eoj ) )
1130+
{
1131+
// TODO: H3 has two special cases here, for many-to-many and one-to-one
1132+
fetchStyle = OuterJoinFetchStrategy.Auto;
1133+
}
1134+
else
1135+
{
1136+
bool join = "true".Equals( eoj );
1137+
fetchStyle = join ?
1138+
OuterJoinFetchStrategy.Join :
1139+
OuterJoinFetchStrategy.Select;
1140+
}
11301141
}
11311142
}
1143+
else
1144+
{
1145+
bool join = "join".Equals( fetchNode.Value );
1146+
fetchStyle = join ?
1147+
OuterJoinFetchStrategy.Join :
1148+
OuterJoinFetchStrategy.Select;
1149+
}
1150+
1151+
model.OuterJoinFetchSetting = fetchStyle;
11321152
}
11331153

11341154
private static void MakeIdentifier( XmlNode node, SimpleValue model, Mappings mappings )

src/NHibernate/FetchMode.cs

+9-4
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@ public enum FetchMode
2020
/// </summary>
2121
Default = 0,
2222
/// <summary>
23-
/// Fetch lazily. Equivalent to <c>outer-join="false"</c>
23+
/// Fetch eagerly, using a separate select. Equivalent to
24+
/// <c>fetch="select"</c> (and <c>outer-join="false"</c>)
2425
/// </summary>
25-
Lazy = 1,
26+
Select = 1,
2627
/// <summary>
27-
/// Fetch eagerly, using an outer join. Equivalent to <c>outer-join="true"</c>
28+
/// Fetch using an outer join. Equivalent to
29+
/// <c>fetch="join"</c> (and <c>outer-join="true"</c>)
2830
/// </summary>
29-
Eager = 2
31+
Join = 2,
32+
33+
Lazy = Select,
34+
Eager = Join
3035
}
3136
}

src/NHibernate/Loader/OuterJoinLoader.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@
1111

1212
namespace NHibernate.Loader
1313
{
14-
/// <summary></summary>
14+
// TODO: This is actually the same as enum FetchMode, except that
15+
// the underlying values are different. There are instances in the code
16+
// where an enum value is compared to 0 or -1, so I'm afraid to unify
17+
// the two types. - Sergey K
1518
public enum OuterJoinFetchStrategy
1619
{
1720
Lazy = -1,
1821
Auto = 0,
19-
Eager = 1
22+
Eager = 1,
23+
24+
Default = Auto,
25+
Join = Eager,
26+
Select = Lazy
2027
}
2128

2229
/// <summary>

src/NHibernate/nhibernate-mapping-2.0.xsd

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
<xs:enumeration value="false"/>
1616
</xs:restriction>
1717
</xs:simpleType>
18+
<xs:simpleType name="fetchMode">
19+
<xs:restriction base="xs:string">
20+
<xs:enumeration value="select"/> <!-- equivalent to outer-join="false" -->
21+
<xs:enumeration value="join"/> <!-- equivalent to outer-join="true" -->
22+
</xs:restriction>
23+
</xs:simpleType>
1824
<xs:simpleType name="cascadeStyle">
1925
<xs:annotation>
2026
<xs:documentation>Rule as to how to operate on child objects (for more information, read topics about "persistence by reachability" or "transparent/transitive/cascading persistence")</xs:documentation>
@@ -63,6 +69,7 @@
6369
</xs:annotation>
6470
</xs:attribute>
6571
<xs:attribute name="outer-join" type="outerJoinStrategy" use="optional"/>
72+
<xs:attribute name="fetch" type="fetchMode" use="optional" />
6673
<xs:attribute name="cascade" type="cascadeStyle" use="optional"/>
6774
<xs:attribute name="where" type="xs:string" use="optional"/>
6875
<xs:attribute name="inverse" type="xs:boolean" use="optional" default="false"/>
@@ -693,6 +700,7 @@
693700
<xs:attribute name="column" type="xs:string"/>
694701
<xs:attribute name="foreign-key" type="xs:string" use="optional"/>
695702
<xs:attribute name="outer-join" type="outerJoinStrategy" default="auto"/>
703+
<xs:attribute name="fetch" type="fetchMode" use="optional" />
696704
</xs:complexType>
697705
</xs:element>
698706
<xs:element name="many-to-one">
@@ -709,6 +717,7 @@
709717
<xs:attribute name="unique" type="xs:boolean" default="false"/>
710718
<xs:attribute name="cascade" type="cascadeStyle"/>
711719
<xs:attribute name="outer-join" type="outerJoinStrategy" default="auto"/>
720+
<xs:attribute name="fetch" type="fetchMode" use="optional" />
712721
<xs:attribute name="update" type="xs:boolean" default="true"/>
713722
<xs:attribute name="insert" type="xs:boolean" default="true"/>
714723
<xs:attribute name="foreign-key" type="xs:string" use="optional"/>
@@ -751,6 +760,7 @@
751760
<xs:attribute name="class" type="xs:string"/>
752761
<xs:attribute name="cascade" type="cascadeStyle"/>
753762
<xs:attribute name="outer-join" type="outerJoinStrategy" default="auto"/>
763+
<xs:attribute name="fetch" type="fetchMode" use="optional" />
754764
<xs:attribute name="constrained" type="xs:boolean" default="false"/>
755765
<xs:attribute name="foreign-key" type="xs:string" use="optional"/>
756766
<xs:attribute name="property-ref" type="xs:string"/>

0 commit comments

Comments
 (0)