Skip to content

Commit 95680e7

Browse files
committed
Implement ICollectionSqlsWithCheckMapper
1 parent ffd7774 commit 95680e7

18 files changed

+334
-33
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using NHibernate.Util;
2+
3+
namespace NHibernate.Mapping.ByCode
4+
{
5+
//6.0 TODO: merge into ICollectionSqlsMapper
6+
public interface ICollectionSqlsWithCheckMapper
7+
{
8+
void SqlInsert(string sql, SqlCheck sqlCheck);
9+
void SqlUpdate(string sql, SqlCheck sqlCheck);
10+
void SqlDelete(string sql, SqlCheck sqlCheck);
11+
void SqlDeleteAll(string sql, SqlCheck sqlCheck);
12+
}
13+
14+
public static class CollectionSqlsWithCheckMapperExtensions
15+
{
16+
public static void SqlInsert(this ICollectionSqlsMapper mapper, string sql, SqlCheck sqlCheck)
17+
{
18+
ReflectHelper
19+
.CastOrThrow<ICollectionSqlsWithCheckMapper>(mapper, "SqlInsert with sqlCheck")
20+
.SqlInsert(sql, sqlCheck);
21+
}
22+
23+
public static void SqlUpdate(this ICollectionSqlsMapper mapper, string sql, SqlCheck sqlCheck)
24+
{
25+
ReflectHelper
26+
.CastOrThrow<ICollectionSqlsWithCheckMapper>(mapper, "SqlUpdate with sqlCheck")
27+
.SqlUpdate(sql, sqlCheck);
28+
}
29+
30+
public static void SqlDelete(this ICollectionSqlsMapper mapper, string sql, SqlCheck sqlCheck)
31+
{
32+
ReflectHelper
33+
.CastOrThrow<ICollectionSqlsWithCheckMapper>(mapper, "SqlDelete with sqlCheck")
34+
.SqlDelete(sql, sqlCheck);
35+
}
36+
37+
public static void SqlDeleteAll(this ICollectionSqlsMapper mapper, string sql, SqlCheck sqlCheck)
38+
{
39+
ReflectHelper
40+
.CastOrThrow<ICollectionSqlsWithCheckMapper>(mapper, "SqlDeleteAll with sqlCheck")
41+
.SqlDeleteAll(sql, sqlCheck);
42+
}
43+
}
44+
}

src/NHibernate/Mapping/ByCode/Impl/BagMapper.cs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace NHibernate.Mapping.ByCode.Impl
1010
{
11-
public class BagMapper : IBagPropertiesMapper
11+
public class BagMapper : IBagPropertiesMapper, ICollectionSqlsWithCheckMapper
1212
{
1313
private readonly IAccessorPropertyMapper entityPropertyMapper;
1414
private readonly KeyMapper keyMapper;
@@ -249,6 +249,16 @@ public void SqlInsert(string sql)
249249
mapping.sqlinsert.Text = new[] {sql};
250250
}
251251

252+
public void SqlInsert(string sql, SqlCheck sqlCheck)
253+
{
254+
if (mapping.SqlInsert == null)
255+
{
256+
mapping.sqlinsert = new HbmCustomSQL();
257+
}
258+
mapping.sqlinsert.Text = new[] {sql};
259+
mapping.sqlinsert.check = sqlCheck.ToHbmSqlCheck();
260+
}
261+
252262
public void SqlUpdate(string sql)
253263
{
254264
if (mapping.SqlUpdate == null)
@@ -258,6 +268,17 @@ public void SqlUpdate(string sql)
258268
mapping.sqlupdate.Text = new[] {sql};
259269
}
260270

271+
public void SqlUpdate(string sql, SqlCheck sqlCheck)
272+
{
273+
if (mapping.SqlUpdate == null)
274+
{
275+
mapping.sqlupdate = new HbmCustomSQL();
276+
}
277+
mapping.sqlupdate.Text = new[] {sql};
278+
mapping.sqlupdate.checkSpecified = true;
279+
mapping.sqlupdate.check = sqlCheck.ToHbmSqlCheck();
280+
}
281+
261282
public void SqlDelete(string sql)
262283
{
263284
if (mapping.SqlDelete == null)
@@ -267,6 +288,17 @@ public void SqlDelete(string sql)
267288
mapping.sqldelete.Text = new[] {sql};
268289
}
269290

291+
public void SqlDelete(string sql, SqlCheck sqlCheck)
292+
{
293+
if (mapping.SqlDelete == null)
294+
{
295+
mapping.sqldelete = new HbmCustomSQL();
296+
}
297+
mapping.sqldelete.Text = new[] {sql};
298+
mapping.sqldelete.checkSpecified = true;
299+
mapping.sqldelete.check = sqlCheck.ToHbmSqlCheck();
300+
}
301+
270302
public void SqlDeleteAll(string sql)
271303
{
272304
if (mapping.SqlDeleteAll == null)
@@ -276,6 +308,17 @@ public void SqlDeleteAll(string sql)
276308
mapping.sqldeleteall.Text = new[] {sql};
277309
}
278310

311+
public void SqlDeleteAll(string sql, SqlCheck sqlCheck)
312+
{
313+
if (mapping.SqlDeleteAll == null)
314+
{
315+
mapping.sqldeleteall = new HbmCustomSQL();
316+
}
317+
mapping.sqldeleteall.Text = new[] {sql};
318+
mapping.sqldeleteall.checkSpecified = true;
319+
mapping.sqldeleteall.check = sqlCheck.ToHbmSqlCheck();
320+
}
321+
279322
public void Subselect(string sql)
280323
{
281324
if (mapping.Subselect == null)
@@ -286,5 +329,6 @@ public void Subselect(string sql)
286329
}
287330

288331
#endregion
332+
289333
}
290-
}
334+
}

src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public void SqlInsert(string sql, SqlCheck sqlCheck)
376376
classMapping.sqlinsert = new HbmCustomSQL();
377377
}
378378
classMapping.sqlinsert.checkSpecified = true;
379-
classMapping.sqlinsert.check = (HbmCustomSQLCheck)Enum.Parse(typeof(HbmCustomSQLCheck), sqlCheck.ToString(), true);
379+
classMapping.sqlinsert.check = sqlCheck.ToHbmSqlCheck();
380380
classMapping.sqlinsert.Text = new[] { sql };
381381
}
382382

@@ -396,7 +396,7 @@ public void SqlUpdate(string sql, SqlCheck sqlCheck)
396396
classMapping.sqlupdate = new HbmCustomSQL();
397397
}
398398
classMapping.sqlupdate.checkSpecified = true;
399-
classMapping.sqlupdate.check = (HbmCustomSQLCheck)Enum.Parse(typeof(HbmCustomSQLCheck), sqlCheck.ToString(), true);
399+
classMapping.sqlupdate.check = sqlCheck.ToHbmSqlCheck();
400400
classMapping.sqlupdate.Text = new[] { sql };
401401
}
402402

@@ -416,7 +416,7 @@ public void SqlDelete(string sql, SqlCheck sqlCheck)
416416
classMapping.sqldelete = new HbmCustomSQL();
417417
}
418418
classMapping.sqldelete.checkSpecified = true;
419-
classMapping.sqldelete.check = (HbmCustomSQLCheck)Enum.Parse(typeof(HbmCustomSQLCheck), sqlCheck.ToString(), true);
419+
classMapping.sqldelete.check = sqlCheck.ToHbmSqlCheck();
420420
classMapping.sqldelete.Text = new[] { sql };
421421
}
422422

src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ClassCustomizer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl
88
{
9-
public class ClassCustomizer<TEntity> : PropertyContainerCustomizer<TEntity>, IClassMapper<TEntity>, IConformistHoldersProvider where TEntity : class
9+
public class ClassCustomizer<TEntity> : PropertyContainerCustomizer<TEntity>, IClassMapper<TEntity>, IConformistHoldersProvider, IEntitySqlsWithCheckMapper where TEntity : class
1010
{
1111
private Dictionary<string, IJoinMapper<TEntity>> joinCustomizers;
1212

@@ -306,4 +306,4 @@ IModelExplicitDeclarationsHolder IConformistHoldersProvider.ExplicitDeclarations
306306
get { return ExplicitDeclarationsHolder; }
307307
}
308308
}
309-
}
309+
}

src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/CollectionPropertiesCustomizer.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl
88
{
9-
public class CollectionPropertiesCustomizer<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement>
9+
public class CollectionPropertiesCustomizer<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement>, ICollectionSqlsWithCheckMapper
1010
{
1111
private readonly IKeyMapper<TEntity> keyMapper;
1212

@@ -157,26 +157,46 @@ public void SqlInsert(string sql)
157157
CustomizersHolder.AddCustomizer(PropertyPath, (ICollectionPropertiesMapper x) => x.SqlInsert(sql));
158158
}
159159

160+
public void SqlInsert(string sql, SqlCheck sqlCheck)
161+
{
162+
CustomizersHolder.AddCustomizer(PropertyPath, (ICollectionPropertiesMapper x) => x.SqlInsert(sql, sqlCheck));
163+
}
164+
160165
public void SqlUpdate(string sql)
161166
{
162167
CustomizersHolder.AddCustomizer(PropertyPath, (ICollectionPropertiesMapper x) => x.SqlUpdate(sql));
163168
}
164169

170+
public void SqlUpdate(string sql, SqlCheck sqlCheck)
171+
{
172+
CustomizersHolder.AddCustomizer(PropertyPath, (ICollectionPropertiesMapper x) => x.SqlUpdate(sql, sqlCheck));
173+
}
174+
165175
public void SqlDelete(string sql)
166176
{
167177
CustomizersHolder.AddCustomizer(PropertyPath, (ICollectionPropertiesMapper x) => x.SqlDelete(sql));
168178
}
169179

180+
public void SqlDelete(string sql, SqlCheck sqlCheck)
181+
{
182+
CustomizersHolder.AddCustomizer(PropertyPath, (ICollectionPropertiesMapper x) => x.SqlDelete(sql, sqlCheck));
183+
}
184+
170185
public void SqlDeleteAll(string sql)
171186
{
172187
CustomizersHolder.AddCustomizer(PropertyPath, (ICollectionPropertiesMapper x) => x.SqlDeleteAll(sql));
173188
}
174189

190+
public void SqlDeleteAll(string sql, SqlCheck sqlCheck)
191+
{
192+
CustomizersHolder.AddCustomizer(PropertyPath, (ICollectionPropertiesMapper x) => x.SqlDeleteAll(sql, sqlCheck));
193+
}
194+
175195
public void Subselect(string sql)
176196
{
177197
CustomizersHolder.AddCustomizer(PropertyPath, (ICollectionPropertiesMapper x) => x.Subselect(sql));
178198
}
179199

180200
#endregion
181201
}
182-
}
202+
}

src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinCustomizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl
77
{
8-
public class JoinCustomizer<TEntity> : PropertyContainerCustomizer<TEntity>, IJoinMapper<TEntity>
8+
public class JoinCustomizer<TEntity> : PropertyContainerCustomizer<TEntity>, IJoinMapper<TEntity>, IEntitySqlsWithCheckMapper
99
where TEntity : class
1010
{
1111
private readonly string splitGroupId;

src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinedSubclassCustomizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl
55
{
6-
public class JoinedSubclassCustomizer<TEntity> : PropertyContainerCustomizer<TEntity>, IJoinedSubclassMapper<TEntity>, IConformistHoldersProvider where TEntity : class
6+
public class JoinedSubclassCustomizer<TEntity> : PropertyContainerCustomizer<TEntity>, IJoinedSubclassMapper<TEntity>, IConformistHoldersProvider, IEntitySqlsWithCheckMapper where TEntity : class
77
{
88
private readonly IKeyMapper<TEntity> keyMapper;
99

src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/SubclassCustomizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl
66
{
7-
public class SubclassCustomizer<TEntity> : PropertyContainerCustomizer<TEntity>, ISubclassMapper<TEntity>, IConformistHoldersProvider where TEntity : class
7+
public class SubclassCustomizer<TEntity> : PropertyContainerCustomizer<TEntity>, ISubclassMapper<TEntity>, IConformistHoldersProvider, IEntitySqlsWithCheckMapper where TEntity : class
88
{
99
private Dictionary<string, IJoinMapper<TEntity>> joinCustomizers;
1010

src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/UnionSubclassCustomizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl
55
{
6-
public class UnionSubclassCustomizer<TEntity> : PropertyContainerCustomizer<TEntity>, IUnionSubclassMapper<TEntity>, IConformistHoldersProvider where TEntity : class
6+
public class UnionSubclassCustomizer<TEntity> : PropertyContainerCustomizer<TEntity>, IUnionSubclassMapper<TEntity>, IConformistHoldersProvider, IEntitySqlsWithCheckMapper where TEntity : class
77
{
88
public UnionSubclassCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder)
99
: base(explicitDeclarationsHolder, customizersHolder, null)

src/NHibernate/Mapping/ByCode/Impl/IdBagMapper.cs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace NHibernate.Mapping.ByCode.Impl
1010
{
11-
public class IdBagMapper : IIdBagPropertiesMapper
11+
public class IdBagMapper : IIdBagPropertiesMapper, ICollectionSqlsWithCheckMapper
1212
{
1313
private readonly IAccessorPropertyMapper entityPropertyMapper;
1414
private readonly KeyMapper keyMapper;
@@ -259,6 +259,16 @@ public void SqlInsert(string sql)
259259
mapping.sqlinsert.Text = new[] {sql};
260260
}
261261

262+
public void SqlInsert(string sql, SqlCheck sqlCheck)
263+
{
264+
if (mapping.SqlInsert == null)
265+
{
266+
mapping.sqlinsert = new HbmCustomSQL();
267+
}
268+
mapping.sqlinsert.Text = new[] {sql};
269+
mapping.sqlinsert.check = sqlCheck.ToHbmSqlCheck();
270+
}
271+
262272
public void SqlUpdate(string sql)
263273
{
264274
if (mapping.SqlUpdate == null)
@@ -268,6 +278,17 @@ public void SqlUpdate(string sql)
268278
mapping.sqlupdate.Text = new[] {sql};
269279
}
270280

281+
public void SqlUpdate(string sql, SqlCheck sqlCheck)
282+
{
283+
if (mapping.SqlUpdate == null)
284+
{
285+
mapping.sqlupdate = new HbmCustomSQL();
286+
}
287+
mapping.sqlupdate.Text = new[] {sql};
288+
mapping.sqlupdate.checkSpecified = true;
289+
mapping.sqlupdate.check = sqlCheck.ToHbmSqlCheck();
290+
}
291+
271292
public void SqlDelete(string sql)
272293
{
273294
if (mapping.SqlDelete == null)
@@ -277,6 +298,17 @@ public void SqlDelete(string sql)
277298
mapping.sqldelete.Text = new[] {sql};
278299
}
279300

301+
public void SqlDelete(string sql, SqlCheck sqlCheck)
302+
{
303+
if (mapping.SqlDelete == null)
304+
{
305+
mapping.sqldelete = new HbmCustomSQL();
306+
}
307+
mapping.sqldelete.Text = new[] {sql};
308+
mapping.sqldelete.checkSpecified = true;
309+
mapping.sqldelete.check = sqlCheck.ToHbmSqlCheck();
310+
}
311+
280312
public void SqlDeleteAll(string sql)
281313
{
282314
if (mapping.SqlDeleteAll == null)
@@ -286,6 +318,17 @@ public void SqlDeleteAll(string sql)
286318
mapping.sqldeleteall.Text = new[] {sql};
287319
}
288320

321+
public void SqlDeleteAll(string sql, SqlCheck sqlCheck)
322+
{
323+
if (mapping.SqlDeleteAll == null)
324+
{
325+
mapping.sqldeleteall = new HbmCustomSQL();
326+
}
327+
mapping.sqldeleteall.Text = new[] {sql};
328+
mapping.sqldeleteall.checkSpecified = true;
329+
mapping.sqldeleteall.check = sqlCheck.ToHbmSqlCheck();
330+
}
331+
289332
public void Subselect(string sql)
290333
{
291334
if (mapping.Subselect == null)
@@ -297,4 +340,4 @@ public void Subselect(string sql)
297340

298341
#endregion
299342
}
300-
}
343+
}

src/NHibernate/Mapping/ByCode/Impl/JoinMapper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void SqlInsert(string sql, SqlCheck sqlCheck)
8686
hbmJoin.sqlinsert = new HbmCustomSQL();
8787
}
8888
hbmJoin.sqlinsert.checkSpecified = true;
89-
hbmJoin.sqlinsert.check = (HbmCustomSQLCheck)Enum.Parse(typeof(HbmCustomSQLCheck), sqlCheck.ToString(), true);
89+
hbmJoin.sqlinsert.check = sqlCheck.ToHbmSqlCheck();
9090
hbmJoin.sqlinsert.Text = new[] { sql };
9191
}
9292

@@ -106,7 +106,7 @@ public void SqlUpdate(string sql, SqlCheck sqlCheck)
106106
hbmJoin.sqlupdate = new HbmCustomSQL();
107107
}
108108
hbmJoin.sqlupdate.checkSpecified = true;
109-
hbmJoin.sqlupdate.check = (HbmCustomSQLCheck)Enum.Parse(typeof(HbmCustomSQLCheck), sqlCheck.ToString(), true);
109+
hbmJoin.sqlupdate.check = sqlCheck.ToHbmSqlCheck();
110110
hbmJoin.sqlupdate.Text = new[] { sql };
111111
}
112112

@@ -126,7 +126,7 @@ public void SqlDelete(string sql, SqlCheck sqlCheck)
126126
hbmJoin.sqldelete = new HbmCustomSQL();
127127
}
128128
hbmJoin.sqldelete.checkSpecified = true;
129-
hbmJoin.sqldelete.check = (HbmCustomSQLCheck)Enum.Parse(typeof(HbmCustomSQLCheck), sqlCheck.ToString(), true);
129+
hbmJoin.sqldelete.check = sqlCheck.ToHbmSqlCheck();
130130
hbmJoin.sqldelete.Text = new[] { sql };
131131
}
132132

0 commit comments

Comments
 (0)