My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
176
177
178
179
using System;
using JetBrains.Annotations;
using NHibernate.Cfg.MappingSchema;
using NHibernateHbmToFluent.Converter.Extensions;
using NHibernateHbmToFluent.Converter.Extensions.NHibernate;
using NHibernateHbmToFluent.Converter.Types;

namespace NHibernateHbmToFluent.Converter
{
public class PropertyMappingType : NamedConstant<PropertyMappingType>
{
public static readonly PropertyMappingType Id = new PropertyMappingType(typeof (HbmId),
"id",
x => ((HbmId) x).GetPropertyName(),
x => ((HbmId) x).GetColumnName(),
x => ((HbmId) x).GetMaxLength(),
x => ((HbmId) x).CanBeNull(),
x => ((HbmId) x).GetReturnType(),
x => ((HbmId) x).IsUnique(),
x => ((HbmId) x).GetUniqueIndex(),
x => ((HbmId) x).GetSqlType(),
(prefix, builder, item) => new Id(builder).Start(prefix, item));

public static readonly PropertyMappingType Property = new PropertyMappingType(typeof (HbmProperty),
"property",
x => ((HbmProperty) x).GetPropertyName(),
x => ((HbmProperty) x).GetColumnName(),
x => ((HbmProperty) x).GetMaxLength(),
x => ((HbmProperty) x).CanBeNull(),
x => ((HbmProperty) x).GetReturnType(),
x => ((HbmProperty) x).IsUnique(),
x => ((HbmProperty) x).GetUniqueIndex(),
x => ((HbmProperty) x).GetSqlType(),
(prefix, builder, item) => new Map(builder).Start(prefix, item));

public static readonly PropertyMappingType ManyToOne = new PropertyMappingType(typeof (HbmManyToOne),
"many-to-one",
x =>
((HbmManyToOne) x).GetPropertyName(),
x => ((HbmManyToOne) x).GetColumnName(),
x => ((HbmManyToOne) x).GetMaxLength(),
x => ((HbmManyToOne) x).CanBeNull(),
x => ((HbmManyToOne) x).GetReturnType(),
x => ((HbmManyToOne) x).IsUnique(),
x =>
((HbmManyToOne) x).GetUniqueIndex(),
x => ((HbmManyToOne) x).GetSqlType(),
(prefix, builder, item) => new References(builder).Start(prefix, item));

public static readonly PropertyMappingType ManyToMany = new PropertyMappingType(typeof (HbmManyToMany),
"many-to-many",
null,
x =>
((HbmManyToMany) x).GetColumnName(),
x => null,
null,
x =>
((HbmManyToMany) x).GetReturnType(),
null,
null,
null,
(prefix, builder, item) => builder.StartMethod(prefix, "?(x => x." + item.ReturnType + ")"));

public static readonly PropertyMappingType OneToOne = new PropertyMappingType(typeof (HbmOneToOne),
"one-to-one",
null,
null,
x => null,
null,
null,
null,
null,
null,
(prefix, builder, item) => builder.StartMethod(prefix, "?(x => x." + item.ReturnType + ")"));

public static readonly PropertyMappingType OneToMany = new PropertyMappingType(typeof (HbmOneToMany),
"one-to-many",
null,
null,
x => null,
null,
x => ((HbmOneToMany) x).GetReturnType(),
null,
null,
null,
(prefix, builder, item) => builder.StartMethod(prefix, "?(x => x." + item.ReturnType + ")"));

public static readonly PropertyMappingType Set = new PropertyMappingType(typeof (HbmSet),
"set",
x => ((HbmSet) x).GetPropertyName(),
x => ((HbmSet) x).GetColumnName(),
x => null,
x => ((HbmSet) x).CanBeNull(),
x => ((HbmSet) x).GetReturnType(),
x => ((HbmSet) x).IsUnique(),
x => null,
x => "NUMBER",
(prefix, builder, item) => new Set(builder).Start(prefix, item));

public static readonly PropertyMappingType Bag = new PropertyMappingType(typeof (HbmBag),
"bag",
x => ((HbmBag) x).GetPropertyName(),
x => ((HbmBag) x).GetColumnName(),
x => null,
x => ((HbmBag) x).CanBeNull(),
x => ((HbmBag) x).GetReturnType(),
x => ((HbmBag) x).IsUnique(),
x => null,
x => "NUMBER",
(prefix, builder, item) => new Bag(builder).Start(prefix, item));

public static readonly PropertyMappingType Component = new PropertyMappingType(typeof (HbmComponent),
"component",
x =>
((HbmComponent) x).GetPropertyName(),
null,
x => null,
x => null,
x => ((HbmComponent) x).GetReturnType(),
x => null,
x => null,
null,
(prefix, builder, item) => new Component(builder).Start(prefix, item));

public Type HbmType { get; private set; }
public string XmlTagName { get; private set; }
public Func<object, string> GetPropertyName { get; private set; }
public Func<object, string> GetColumnName { get; private set; }
public Func<object, int?> GetMaxLength { get; private set; }
public Func<object, bool?> GetNullability { get; private set; }
public Func<object, string> GetReturnType { get; private set; }
public Func<object, bool?> GetIsUnique { get; private set; }
public Func<object, string> GetUniqueIndex { get; private set; }
public Func<object, string> GetColumnType { get; private set; }
public Action<string, CodeFileBuilder, MappedPropertyInfo> StartMethod { get; set; }

private PropertyMappingType(Type hbmType, string xmlTagName, Func<object, string> getPropertyName,
Func<object, string> getColumnName, Func<object, int?> getMaxLength,
Func<object, bool?> getNullability, Func<object, string> getReturnType,
Func<object, bool?> getIsUnique, Func<object, string> getUniqueIndex,
Func<object, string> getColumnType, Action<string, CodeFileBuilder, MappedPropertyInfo> startMethod)
{
HbmType = hbmType;
XmlTagName = xmlTagName;
GetPropertyName = getPropertyName;
GetColumnName = getColumnName;
GetMaxLength = getMaxLength;
GetNullability = getNullability;
GetReturnType = getReturnType;
GetIsUnique = getIsUnique;
GetUniqueIndex = getUniqueIndex;
GetColumnType = getColumnType;
StartMethod = startMethod;
Add(xmlTagName.ToLower(), this);
Add(hbmType.Name.ToLower(), this);
}

[NotNull]
public static PropertyMappingType GetByXmlTagName(string typeName)
{
PropertyMappingType propertyMappingType = Get(typeName.ToLower());
if (propertyMappingType == null)
{
throw new Exception("Received request for unsupported type '" + typeName + "'");
}
return propertyMappingType;
}

public static PropertyMappingType GetByHbmTypeName(string hbmTypeName)
{
PropertyMappingType propertyMappingType = Get(hbmTypeName.ToLower());
if (propertyMappingType == null)
{
throw new Exception("Received request for unsupported type '" + hbmTypeName + "'");
}
return propertyMappingType;
}
}
}

Change log

r2 by gar3ts on Aug 19, 2009   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 13756 bytes, 179 lines
Powered by Google Project Hosting