File tree Expand file tree Collapse file tree 4 files changed +19
-11
lines changed
NHibernate.Test/VersionTest/Db Expand file tree Collapse file tree 4 files changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ public void CollectionVersion()
42
42
admin = s . Get < Group > ( admin . Id ) ;
43
43
guy . Groups . Add ( admin ) ;
44
44
admin . Users . Add ( guy ) ;
45
+ guy . NoOptimisticLock = "changed" ;
45
46
t . Commit ( ) ;
46
47
s . Close ( ) ;
47
48
Original file line number Diff line number Diff line change @@ -11,8 +11,10 @@ public class User
11
11
12
12
public virtual string Username { get ; set ; }
13
13
14
+ public virtual string NoOptimisticLock { get ; set ; }
15
+
14
16
public virtual ISet < Group > Groups { get ; set ; }
15
17
16
18
public virtual ISet < Permission > Permissions { get ; set ; }
17
19
}
18
- }
20
+ }
Original file line number Diff line number Diff line change 1
- <?xml version =" 1.0" encoding =" utf-8" ?>
1
+ <?xml version =" 1.0" encoding =" utf-8" ?>
2
2
<!--
3
3
Demonstrates how to control the optimistic locking behavior
4
4
of a collection (do changes to the collection result in
14
14
</id >
15
15
<timestamp name =" Timestamp" column =" ts" source =" db" />
16
16
<property name =" Username" column =" user_name" type =" string" unique =" true" />
17
+ <property name =" NoOptimisticLock" column =" no_optimistic_lock" type =" string" optimistic-lock =" false" />
17
18
<set name =" Groups" table =" db_vers_user_group" batch-size =" 9" inverse =" true" optimistic-lock =" true" lazy =" true" cascade =" none" >
18
19
<key column =" user_id" />
19
20
<many-to-many column =" group_id" class =" Group" lazy =" false" fetch =" join" />
45
46
<property name =" Context" column =" ctx" type =" string" />
46
47
<property name =" Access" column =" priv" type =" string" />
47
48
</class >
48
- </hibernate-mapping >
49
+ </hibernate-mapping >
Original file line number Diff line number Diff line change @@ -389,18 +389,22 @@ protected bool IsUpdateNecessary(FlushEntityEvent @event)
389
389
}
390
390
else
391
391
{
392
+ // call to HasDirtyCollections must not be optimized away because of its side effect
393
+ bool hasDirtyCollections = HasDirtyCollections ( @event , persister , status ) ;
394
+
392
395
int [ ] dirtyProperties = @event . DirtyProperties ;
393
- if ( dirtyProperties != null && dirtyProperties . Length != 0 )
394
- {
395
- return true ; //TODO: suck into event class
396
- }
397
- else
398
- {
399
- return HasDirtyCollections ( @event , persister , status ) ;
400
- }
396
+ return dirtyProperties != null && dirtyProperties . Length != 0 || hasDirtyCollections ;
401
397
}
402
398
}
403
399
400
+ /// <summary>
401
+ /// Check if there are any dirty collections.
402
+ /// Has a side effect of setting the HasDirtyCollection property of the event.
403
+ /// </summary>
404
+ /// <param name="event"></param>
405
+ /// <param name="persister"></param>
406
+ /// <param name="status"></param>
407
+ /// <returns></returns>
404
408
private bool HasDirtyCollections ( FlushEntityEvent @event , IEntityPersister persister , Status status )
405
409
{
406
410
if ( IsCollectionDirtyCheckNecessary ( persister , status ) )
You can’t perform that action at this time.
0 commit comments