/
MultiplicityType.cs
153 lines (134 loc) · 3.41 KB
/
MultiplicityType.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
using System;
using System.Data;
using NHibernate.Engine;
using NHibernate.Type;
using NHibernate.UserTypes;
namespace NHibernate.DomainModel
{
[Serializable]
public class MultiplicityType : ICompositeUserType
{
private static readonly string[] PROP_NAMES = new String[]
{
"count", "glarch"
};
private static readonly IType[] TYPES = new IType[]
{
NHibernateUtil.Int32, NHibernateUtil.Entity(typeof(Glarch))
};
public String[] PropertyNames
{
get { return PROP_NAMES; }
}
public IType[] PropertyTypes
{
get { return TYPES; }
}
public object GetPropertyValue(object component, int property)
{
Multiplicity o = (Multiplicity) component;
return property == 0 ?
(object) o.count :
(object) o.glarch;
}
public void SetPropertyValue(object component, int property, object value)
{
Multiplicity o = (Multiplicity) component;
if (property == 0)
{
o.count = (int) value;
}
else
{
o.glarch = (Glarch) value;
}
}
public System.Type ReturnedClass
{
get { return typeof(Multiplicity); }
}
public new bool Equals(object x, object y)
{
Multiplicity mx = (Multiplicity) x;
Multiplicity my = (Multiplicity) y;
if (mx == my) return true;
if (mx == null || my == null) return false;
return mx.count == my.count && mx.glarch == my.glarch;
}
public int GetHashCode(object x)
{
unchecked
{
Multiplicity o = (Multiplicity) x;
return o.count + o.glarch.GetHashCode();
}
}
public object NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner)
{
int c = (int) NHibernateUtil.Int32.NullSafeGet(rs, names[0], session, owner);
GlarchProxy g = (GlarchProxy) NHibernateUtil.Entity(typeof(Glarch)).NullSafeGet(rs, names[1], session, owner);
Multiplicity m = new Multiplicity();
m.count = (c == 0 ? 0 : c);
m.glarch = g;
return m;
}
public void NullSafeSet(IDbCommand st, Object value, int index, ISessionImplementor session)
{
Multiplicity o = (Multiplicity) value;
GlarchProxy g;
int c;
if (o == null)
{
g = null;
c = 0;
}
else
{
g = o.glarch;
c = o.count;
}
NHibernateUtil.Int32.NullSafeSet(st, c, index, session);
NHibernateUtil.Entity(typeof(Glarch)).NullSafeSet(st, g, index + 1, session);
}
public object DeepCopy(object value)
{
if (value == null) return null;
Multiplicity v = (Multiplicity) value;
Multiplicity m = new Multiplicity();
m.count = v.count;
m.glarch = v.glarch;
return m;
}
public bool IsMutable
{
get { return true; }
}
public object Assemble(object cached, ISessionImplementor session, Object owner)
{
if (cached == null)
{
return null;
}
object[] o = (object[]) cached;
Multiplicity m = new Multiplicity();
m.count = (int) o[0];
m.glarch = o[1] == null ?
null :
(GlarchProxy) session.InternalLoad(typeof(Glarch).FullName, o[1], false, false);
return m;
}
public object Disassemble(Object value, ISessionImplementor session)
{
if (value == null)
{
return null;
}
Multiplicity m = (Multiplicity) value;
return new object[] {m.count, ForeignKeys.GetEntityIdentifierIfNotUnsaved(null, m.glarch, session)};
}
public object Replace(object original, object target, ISessionImplementor session, object owner)
{
return Assemble(Disassemble(original, session), session, owner);
}
}
}