forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSet.cs
97 lines (88 loc) · 2.13 KB
/
Set.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
using System;
using System.Collections;
using NHibernate.Type;
namespace NHibernate.Mapping
{
/// <summary>
/// A Set with no nullable element columns will have a primary
/// key consisting of all table columns (ie - key columns +
/// element columns).
/// </summary>
[Serializable]
public class Set : Collection
{
public Set(PersistentClass owner) : base(owner)
{
}
public override bool IsSet
{
get { return true; }
}
public override CollectionType DefaultCollectionType
{
get
{
System.Type elementType = typeof (object);
// If this set is part of a dynamic component, IsGeneric will be false, in
// which case we default to typing as object.
// TODO: For sets in dynamic component, grab the element type from the class attribute in the mappings.
if (this.IsGeneric)
{
CheckGenericArgumentsLength(1);
elementType = this.GenericArguments[0];
//throw new NotSupportedException("Only generic sets are supported.");
}
if (IsSorted)
{
return TypeFactory.GenericSortedSet(Role, ReferencedPropertyName, Comparer, elementType);
}
else if (HasOrder)
{
return TypeFactory.GenericOrderedSet(Role, ReferencedPropertyName, elementType);
}
else
{
return TypeFactory.GenericSet(Role, ReferencedPropertyName, elementType);
}
}
}
public override void CreatePrimaryKey()
{
if (!IsOneToMany)
{
PrimaryKey pk = new PrimaryKey();
foreach (ISelectable selectable in Key.ColumnIterator)
{
if (!selectable.IsFormula)
{
Column col = (Column)selectable;
pk.AddColumn(col);
}
}
bool nullable = false;
foreach (ISelectable selectable in Element.ColumnIterator)
{
if (!selectable.IsFormula)
{
Column col = (Column) selectable;
if (col.IsNullable)
{
nullable = true;
}
pk.AddColumn(col);
}
}
// some databases (Postgres) will tolerate nullable
// column in a primary key - others (DB2) won't
if (!nullable)
{
CollectionTable.PrimaryKey = pk;
}
}
else
{
// Create an index on the key columns?
}
}
}
}