@@ -1271,14 +1271,14 @@ private object InitializeLazyPropertiesFromDatastore(string fieldName, object en
1271
1271
catch ( DbException sqle )
1272
1272
{
1273
1273
var exceptionContext = new AdoExceptionContextInfo
1274
- {
1275
- SqlException = sqle ,
1276
- Message =
1277
- "could not initialize lazy properties: " + MessageHelper . InfoString ( this , id , Factory ) ,
1278
- Sql = SQLLazySelectString . ToString ( ) ,
1279
- EntityName = EntityName ,
1280
- EntityId = id
1281
- } ;
1274
+ {
1275
+ SqlException = sqle ,
1276
+ Message =
1277
+ "could not initialize lazy properties: " + MessageHelper . InfoString ( this , id , Factory ) ,
1278
+ Sql = SQLLazySelectString . ToString ( ) ,
1279
+ EntityName = EntityName ,
1280
+ EntityId = id
1281
+ } ;
1282
1282
throw ADOExceptionHelper . Convert ( Factory . SQLExceptionConverter , exceptionContext ) ;
1283
1283
}
1284
1284
}
@@ -1444,13 +1444,13 @@ public object[] GetDatabaseSnapshot(object id, ISessionImplementor session)
1444
1444
catch ( DbException sqle )
1445
1445
{
1446
1446
var exceptionContext = new AdoExceptionContextInfo
1447
- {
1448
- SqlException = sqle ,
1449
- Message = "could not retrieve snapshot: " + MessageHelper . InfoString ( this , id , Factory ) ,
1450
- Sql = SQLSnapshotSelectString . ToString ( ) ,
1451
- EntityName = EntityName ,
1452
- EntityId = id
1453
- } ;
1447
+ {
1448
+ SqlException = sqle ,
1449
+ Message = "could not retrieve snapshot: " + MessageHelper . InfoString ( this , id , Factory ) ,
1450
+ Sql = SQLSnapshotSelectString . ToString ( ) ,
1451
+ EntityName = EntityName ,
1452
+ EntityId = id
1453
+ } ;
1454
1454
throw ADOExceptionHelper . Convert ( Factory . SQLExceptionConverter , exceptionContext ) ;
1455
1455
}
1456
1456
}
@@ -1627,13 +1627,13 @@ public object ForceVersionIncrement(object id, object currentVersion, ISessionIm
1627
1627
catch ( DbException sqle )
1628
1628
{
1629
1629
var exceptionContext = new AdoExceptionContextInfo
1630
- {
1631
- SqlException = sqle ,
1632
- Message = "could not retrieve version: " + MessageHelper . InfoString ( this , id , Factory ) ,
1633
- Sql = VersionSelectString . ToString ( ) ,
1634
- EntityName = EntityName ,
1635
- EntityId = id
1636
- } ;
1630
+ {
1631
+ SqlException = sqle ,
1632
+ Message = "could not retrieve version: " + MessageHelper . InfoString ( this , id , Factory ) ,
1633
+ Sql = VersionSelectString . ToString ( ) ,
1634
+ EntityName = EntityName ,
1635
+ EntityId = id
1636
+ } ;
1637
1637
throw ADOExceptionHelper . Convert ( Factory . SQLExceptionConverter , exceptionContext ) ;
1638
1638
}
1639
1639
return nextVersion ;
@@ -1689,13 +1689,13 @@ public object GetCurrentVersion(object id, ISessionImplementor session)
1689
1689
catch ( DbException sqle )
1690
1690
{
1691
1691
var exceptionContext = new AdoExceptionContextInfo
1692
- {
1693
- SqlException = sqle ,
1694
- Message = "could not retrieve version: " + MessageHelper . InfoString ( this , id , Factory ) ,
1695
- Sql = VersionSelectString . ToString ( ) ,
1696
- EntityName = EntityName ,
1697
- EntityId = id
1698
- } ;
1692
+ {
1693
+ SqlException = sqle ,
1694
+ Message = "could not retrieve version: " + MessageHelper . InfoString ( this , id , Factory ) ,
1695
+ Sql = VersionSelectString . ToString ( ) ,
1696
+ EntityName = EntityName ,
1697
+ EntityId = id
1698
+ } ;
1699
1699
throw ADOExceptionHelper . Convert ( Factory . SQLExceptionConverter , exceptionContext ) ;
1700
1700
}
1701
1701
}
@@ -2137,7 +2137,7 @@ private void InitIdentifierPropertyPaths(IMapping mapping)
2137
2137
private void InitDiscriminatorPropertyPath ( )
2138
2138
{
2139
2139
propertyMapping . InitPropertyPaths ( EntityClass , DiscriminatorType , new string [ ] { DiscriminatorColumnName } ,
2140
- new string [ ] { DiscriminatorFormulaTemplate } , Factory ) ;
2140
+ new string [ ] { DiscriminatorFormulaTemplate } , Factory ) ;
2141
2141
}
2142
2142
2143
2143
private void InitPropertyPaths ( IMapping mapping )
@@ -2664,13 +2664,13 @@ protected void Insert(object id, object[] fields, bool[] notNull, int j,
2664
2664
catch ( DbException sqle )
2665
2665
{
2666
2666
var exceptionContext = new AdoExceptionContextInfo
2667
- {
2668
- SqlException = sqle ,
2669
- Message = "could not insert: " + MessageHelper . InfoString ( this , id ) ,
2670
- Sql = sql . ToString ( ) ,
2671
- EntityName = EntityName ,
2672
- EntityId = id
2673
- } ;
2667
+ {
2668
+ SqlException = sqle ,
2669
+ Message = "could not insert: " + MessageHelper . InfoString ( this , id ) ,
2670
+ Sql = sql . ToString ( ) ,
2671
+ EntityName = EntityName ,
2672
+ EntityId = id
2673
+ } ;
2674
2674
throw ADOExceptionHelper . Convert ( Factory . SQLExceptionConverter , exceptionContext ) ;
2675
2675
}
2676
2676
}
@@ -2807,13 +2807,13 @@ protected bool Update(object id, object[] fields, object[] oldFields, object row
2807
2807
catch ( DbException sqle )
2808
2808
{
2809
2809
var exceptionContext = new AdoExceptionContextInfo
2810
- {
2811
- SqlException = sqle ,
2812
- Message = "could not update: " + MessageHelper . InfoString ( this , id , Factory ) ,
2813
- Sql = sql . Text . ToString ( ) ,
2810
+ {
2811
+ SqlException = sqle ,
2812
+ Message = "could not update: " + MessageHelper . InfoString ( this , id , Factory ) ,
2813
+ Sql = sql . Text . ToString ( ) ,
2814
2814
EntityName = EntityName ,
2815
2815
EntityId = id
2816
- } ;
2816
+ } ;
2817
2817
throw ADOExceptionHelper . Convert ( Factory . SQLExceptionConverter , exceptionContext ) ;
2818
2818
}
2819
2819
}
@@ -2927,13 +2927,13 @@ public void Delete(object id, object version, int j, object obj, SqlCommandInfo
2927
2927
catch ( DbException sqle )
2928
2928
{
2929
2929
var exceptionContext = new AdoExceptionContextInfo
2930
- {
2931
- SqlException = sqle ,
2932
- Message = "could not delete: " + MessageHelper . InfoString ( this , id , Factory ) ,
2933
- Sql = sql . Text . ToString ( ) ,
2934
- EntityName = EntityName ,
2935
- EntityId = id
2936
- } ;
2930
+ {
2931
+ SqlException = sqle ,
2932
+ Message = "could not delete: " + MessageHelper . InfoString ( this , id , Factory ) ,
2933
+ Sql = sql . Text . ToString ( ) ,
2934
+ EntityName = EntityName ,
2935
+ EntityId = id
2936
+ } ;
2937
2937
throw ADOExceptionHelper . Convert ( Factory . SQLExceptionConverter , exceptionContext ) ;
2938
2938
}
2939
2939
}
@@ -3199,73 +3199,11 @@ protected void LogStaticSQL()
3199
3199
public virtual string FilterFragment ( string alias , IDictionary < string , IFilter > enabledFilters )
3200
3200
{
3201
3201
StringBuilder sessionFilterFragment = new StringBuilder ( ) ;
3202
-
3203
- filterHelper . Render ( sessionFilterFragment , GenerateFilterConditionAlias ( alias ) , GetColumnsToTableAliasMap ( alias ) , enabledFilters ) ;
3202
+ filterHelper . Render ( sessionFilterFragment , GenerateFilterConditionAlias ( alias ) , enabledFilters ) ;
3204
3203
3205
3204
return sessionFilterFragment . Append ( FilterFragment ( alias ) ) . ToString ( ) ;
3206
3205
}
3207
3206
3208
- private IDictionary < string , string > GetColumnsToTableAliasMap ( string rootAlias )
3209
- {
3210
- IDictionary < PropertyKey , string > propDictionary = new Dictionary < PropertyKey , string > ( ) ;
3211
- for ( int i = 0 ; i < SubclassPropertyNameClosure . Length ; i ++ )
3212
- {
3213
- string property = SubclassPropertyNameClosure [ i ] ;
3214
- string [ ] cols = GetSubclassPropertyColumnNames ( property ) ;
3215
-
3216
- if ( cols != null && cols . Length > 0 )
3217
- {
3218
- PropertyKey key = new PropertyKey ( cols [ 0 ] , GetSubclassPropertyTableNumber ( i ) ) ;
3219
- propDictionary [ key ] = property ;
3220
- }
3221
- }
3222
-
3223
- IDictionary < string , string > dict = new Dictionary < string , string > ( ) ;
3224
- for ( int i = 0 ; i < SubclassColumnTableNumberClosure . Length ; i ++ )
3225
- {
3226
- string col = SubclassColumnClosure [ i ] ;
3227
- string alias = GenerateTableAlias ( rootAlias , SubclassColumnTableNumberClosure [ i ] ) ;
3228
-
3229
- string fullColumn = string . Format ( "{0}.{1}" , alias , col ) ;
3230
-
3231
- PropertyKey key = new PropertyKey ( col , SubclassColumnTableNumberClosure [ i ] ) ;
3232
- if ( propDictionary . ContainsKey ( key ) )
3233
- {
3234
- dict [ propDictionary [ key ] ] = fullColumn ;
3235
- }
3236
-
3237
- if ( ! dict . ContainsKey ( col ) )
3238
- {
3239
- dict [ col ] = fullColumn ;
3240
- }
3241
- }
3242
-
3243
- return dict ;
3244
- }
3245
-
3246
- private class PropertyKey
3247
- {
3248
- public string Column { get ; set ; }
3249
- public int TableNumber { get ; set ; }
3250
-
3251
- public PropertyKey ( string column , int tableNumber )
3252
- {
3253
- Column = column ;
3254
- TableNumber = tableNumber ;
3255
- }
3256
-
3257
- public override int GetHashCode ( )
3258
- {
3259
- return Column . GetHashCode ( ) ^ TableNumber . GetHashCode ( ) ;
3260
- }
3261
-
3262
- public override bool Equals ( object other )
3263
- {
3264
- PropertyKey otherTuple = other as PropertyKey ;
3265
- return otherTuple == null ? false : Column . Equals ( otherTuple . Column ) && TableNumber . Equals ( otherTuple . TableNumber ) ;
3266
- }
3267
- }
3268
-
3269
3207
public virtual string GenerateFilterConditionAlias ( string rootAlias )
3270
3208
{
3271
3209
return rootAlias ;
@@ -3746,34 +3684,35 @@ public virtual void AfterReassociate(object entity, ISessionImplementor session)
3746
3684
return true ;
3747
3685
}
3748
3686
3749
- // check the id unsaved-value
3750
- // We do this first so we don't have to hydrate the version property if the id property already gives us the info we need (NH-3505).
3751
- bool ? result2 = entityMetamodel . IdentifierProperty . UnsavedValue . IsUnsaved ( id ) ;
3752
- if ( result2 . HasValue )
3753
- {
3754
- if ( IdentifierGenerator is Assigned )
3755
- {
3756
- // if using assigned identifier, we can only make assumptions
3757
- // if the value is a known unsaved-value
3758
- if ( result2 . Value )
3759
- return true ;
3760
- }
3761
- else
3762
- {
3763
- return result2 ;
3764
- }
3765
- }
3766
-
3767
- // check the version unsaved-value, if appropriate
3768
- if ( IsVersioned )
3769
- {
3770
- object version = GetVersion ( entity , session . EntityMode ) ;
3771
- bool ? result = entityMetamodel . VersionProperty . UnsavedValue . IsUnsaved ( version ) ;
3772
- if ( result . HasValue )
3773
- {
3774
- return result ;
3775
- }
3776
- }
3687
+ // check the version unsaved-value, if appropriate
3688
+ if ( IsVersioned )
3689
+ {
3690
+ object version = GetVersion ( entity , session . EntityMode ) ;
3691
+ // let this take precedence if defined, since it works for
3692
+ // assigned identifiers
3693
+ bool ? result = entityMetamodel . VersionProperty . UnsavedValue . IsUnsaved ( version ) ;
3694
+ if ( result . HasValue )
3695
+ {
3696
+ return result ;
3697
+ }
3698
+ }
3699
+
3700
+ // check the id unsaved-value
3701
+ bool ? result2 = entityMetamodel . IdentifierProperty . UnsavedValue . IsUnsaved ( id ) ;
3702
+ if ( result2 . HasValue )
3703
+ {
3704
+ if ( IdentifierGenerator is Assigned )
3705
+ {
3706
+ // if using assigned identifier, we can only make assumptions
3707
+ // if the value is a known unsaved-value
3708
+ if ( result2 . Value )
3709
+ return true ;
3710
+ }
3711
+ else
3712
+ {
3713
+ return result2 ;
3714
+ }
3715
+ }
3777
3716
3778
3717
// check to see if it is in the second-level cache
3779
3718
if ( HasCache )
@@ -4167,13 +4106,13 @@ public virtual object[] GetNaturalIdentifierSnapshot(object id, ISessionImplemen
4167
4106
catch ( DbException sqle )
4168
4107
{
4169
4108
var exceptionContext = new AdoExceptionContextInfo
4170
- {
4171
- SqlException = sqle ,
4172
- Message = "could not retrieve snapshot: " + MessageHelper . InfoString ( this , id , Factory ) ,
4173
- Sql = sql . ToString ( ) ,
4174
- EntityName = EntityName ,
4175
- EntityId = id
4176
- } ;
4109
+ {
4110
+ SqlException = sqle ,
4111
+ Message = "could not retrieve snapshot: " + MessageHelper . InfoString ( this , id , Factory ) ,
4112
+ Sql = sql . ToString ( ) ,
4113
+ EntityName = EntityName ,
4114
+ EntityId = id
4115
+ } ;
4177
4116
throw ADOExceptionHelper . Convert ( Factory . SQLExceptionConverter , exceptionContext ) ;
4178
4117
}
4179
4118
}
0 commit comments