forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJoin.cs
175 lines (150 loc) · 4.74 KB
/
Join.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using System;
using System.Collections.Generic;
using System.Linq;
using NHibernate.Engine;
using NHibernate.SqlCommand;
namespace NHibernate.Mapping
{
[Serializable]
public class Join : ISqlCustomizable
{
private static readonly Alias PK_ALIAS = new Alias(15, "PK");
private readonly List<Property> properties = new List<Property>();
private Table table;
private IKeyValue key;
private PersistentClass persistentClass;
private bool isSequentialSelect;
private bool isInverse;
private bool isOptional;
private bool? isLazy;
// Custom SQL
private SqlString customSQLInsert;
private bool customInsertCallable;
private ExecuteUpdateResultCheckStyle insertCheckStyle;
private SqlString customSQLUpdate;
private bool customUpdateCallable;
private ExecuteUpdateResultCheckStyle updateCheckStyle;
private SqlString customSQLDelete;
private bool customDeleteCallable;
private ExecuteUpdateResultCheckStyle deleteCheckStyle;
public void AddProperty(Property prop)
{
properties.Add(prop);
prop.PersistentClass = PersistentClass;
}
//if we are joining to a non pk, this is the property of the class that serves as id
public Property RefIdProperty { get; set; }
public bool ContainsProperty(Property prop)
{
return properties.Contains(prop);
}
public IEnumerable<Property> PropertyIterator
{
get { return properties; }
}
public virtual Table Table
{
get { return table; }
set { table = value; }
}
public virtual IKeyValue Key
{
get { return key; }
set { key = value; }
}
public virtual PersistentClass PersistentClass
{
get { return persistentClass; }
set { persistentClass = value; }
}
public void CreateForeignKey()
{
// TODO: The "if (!IsInverse)" condition is not in H3.2.
// Not sure if this H3.2 does it in a different way. The reason
// this condition is put in is because when a <join> is mapped with
// inverse="true", the joined rows should not be deleted (see
// comments in NH-466). In other words, the joined row is
// outside of the parent row's life cycle. If this foreign
// key is added, the parent row cannot be deleted independent
// of the joined row. Perhaps we need more clarification
// on how this should behave.
if (!IsInverse)
{
Key.CreateForeignKeyOfEntity(persistentClass.EntityName);
}
}
//Since v5.2
[Obsolete("Please use overload without dialect parameter.")]
public void CreatePrimaryKey(Dialect.Dialect dialect)
{
CreatePrimaryKey();
}
public void CreatePrimaryKey()
{
//Primary key constraint
PrimaryKey pk = new PrimaryKey();
pk.Table = table;
pk.Name = PK_ALIAS.ToAliasString(table.Name);
table.PrimaryKey = pk;
pk.AddColumns(Key.ColumnIterator);
}
public int PropertySpan
{
get { return properties.Count; }
}
public SqlString CustomSQLInsert { get { return customSQLInsert; } }
public SqlString CustomSQLDelete { get { return customSQLDelete; } }
public SqlString CustomSQLUpdate { get { return customSQLUpdate; } }
public bool IsCustomInsertCallable { get { return customInsertCallable; } }
public bool IsCustomDeleteCallable { get { return customDeleteCallable; } }
public bool IsCustomUpdateCallable { get { return customUpdateCallable; } }
public ExecuteUpdateResultCheckStyle CustomSQLInsertCheckStyle { get { return insertCheckStyle; } }
public ExecuteUpdateResultCheckStyle CustomSQLDeleteCheckStyle { get { return deleteCheckStyle; } }
public ExecuteUpdateResultCheckStyle CustomSQLUpdateCheckStyle { get { return updateCheckStyle; } }
public void SetCustomSQLInsert(string sql, bool callable, ExecuteUpdateResultCheckStyle checkStyle)
{
customSQLInsert = SqlString.Parse(sql);
customInsertCallable = callable;
insertCheckStyle = checkStyle;
}
public void SetCustomSQLDelete(string sql, bool callable, ExecuteUpdateResultCheckStyle checkStyle)
{
customSQLDelete = SqlString.Parse(sql);
customDeleteCallable = callable;
deleteCheckStyle = checkStyle;
}
public void SetCustomSQLUpdate(string sql, bool callable, ExecuteUpdateResultCheckStyle checkStyle)
{
customSQLUpdate = SqlString.Parse(sql);
customUpdateCallable = callable;
updateCheckStyle = checkStyle;
}
public virtual bool IsSequentialSelect
{
get { return isSequentialSelect; }
set { isSequentialSelect = value; }
}
public virtual bool IsInverse
{
get { return isInverse; }
set { isInverse = value; }
}
public bool IsLazy
{
get
{
if (!isLazy.HasValue)
{
var hasAllLazyProperties = !PropertyIterator.Any(property=> property.IsLazy == false);
isLazy = hasAllLazyProperties;
}
return isLazy.Value;
}
}
public virtual bool IsOptional
{
get { return isOptional; }
set { isOptional = value; }
}
}
}