@@ -1186,113 +1186,9 @@ finally
1186
1186
The <literal >IInterceptor</literal > interface provides callbacks from the session to the
1187
1187
application allowing the application to inspect and / or manipulate properties of a
1188
1188
persistent object before it is saved, updated, deleted or loaded. One
1189
- possible use for this is to track auditing information. For example, the following
1190
- <literal >IInterceptor</literal > automatically sets the <literal >CreateTimestamp</literal >
1191
- when an <literal >IAuditable</literal > is created and updates the
1192
- <literal >LastUpdateTimestamp</literal > property when an <literal >IAuditable</literal > is
1193
- updated.
1189
+ possible use for this is to track auditing information. See
1190
+ <xref linkend =" objectstate-interceptors" /> for more information.
1194
1191
</para >
1195
-
1196
- <programlisting ><![CDATA[ using System;
1197
- using NHibernate.Type;
1198
-
1199
- namespace NHibernate.Test
1200
- {
1201
- [Serializable]
1202
- public class AuditInterceptor : IInterceptor
1203
- {
1204
-
1205
- private int updates;
1206
- private int creates;
1207
-
1208
- public void OnDelete(object entity,
1209
- object id,
1210
- object[] state,
1211
- string[] propertyNames,
1212
- IType[] types)
1213
- {
1214
- // do nothing
1215
- }
1216
-
1217
- public boolean OnFlushDirty(object entity,
1218
- object id,
1219
- object[] currentState,
1220
- object[] previousState,
1221
- string[] propertyNames,
1222
- IType[] types) {
1223
-
1224
- if ( entity is IAuditable )
1225
- {
1226
- updates++;
1227
- for ( int i=0; i < propertyNames.Length; i++ )
1228
- {
1229
- if ( "LastUpdateTimestamp" == propertyNames[i] )
1230
- {
1231
- currentState[i] = DateTime.Now;
1232
- return true;
1233
- }
1234
- }
1235
- }
1236
- return false;
1237
- }
1238
-
1239
- public boolean OnLoad(object entity,
1240
- object id,
1241
- object[] state,
1242
- string[] propertyNames,
1243
- IType[] types)
1244
- {
1245
- return false;
1246
- }
1247
-
1248
- public boolean OnSave(object entity,
1249
- object id,
1250
- object[] state,
1251
- string[] propertyNames,
1252
- IType[] types)
1253
- {
1254
- if ( entity is IAuditable )
1255
- {
1256
- creates++;
1257
- for ( int i=0; i<propertyNames.Length; i++ )
1258
- {
1259
- if ( "CreateTimestamp" == propertyNames[i] )
1260
- {
1261
- state[i] = DateTime.Now;
1262
- return true;
1263
- }
1264
- }
1265
- }
1266
- return false;
1267
- }
1268
-
1269
- public void PostFlush(ICollection entities)
1270
- {
1271
- Console.Out.WriteLine("Creations: {0}, Updates: {1}", creates, updates);
1272
- }
1273
-
1274
- public void PreFlush(ICollection entities) {
1275
- updates=0;
1276
- creates=0;
1277
- }
1278
-
1279
- ......
1280
- ......
1281
- }
1282
- }]]> </programlisting >
1283
-
1284
- <para >
1285
- The interceptor would be specified when a session is created.
1286
- </para >
1287
-
1288
- <programlisting ><![CDATA[ ISession session = sf.OpenSession( new AuditInterceptor() );]]> </programlisting >
1289
-
1290
- <para >
1291
- You may also set an interceptor on a global level, using the <literal >Configuration</literal >:
1292
- </para >
1293
-
1294
- <programlisting ><![CDATA[ new Configuration().SetInterceptor( new AuditInterceptor() );]]> </programlisting >
1295
-
1296
1192
</sect1 >
1297
1193
1298
1194
<sect1 id =" manipulatingdata-metadata" >
0 commit comments