KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > event > def > DefaultDirtyCheckEventListener


1 //$Id: DefaultDirtyCheckEventListener.java,v 1.2 2005/02/22 03:09:34 oneovthafew Exp $
2
package org.hibernate.event.def;
3
4 import org.hibernate.HibernateException;
5 import org.hibernate.event.DirtyCheckEvent;
6 import org.hibernate.event.DirtyCheckEventListener;
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9
10 /**
11  * Defines the default dirty-check event listener used by hibernate for
12  * checking the session for dirtiness in response to generated dirty-check
13  * events.
14  *
15  * @author Steve Ebersole
16  */

17 public class DefaultDirtyCheckEventListener extends AbstractFlushingEventListener implements DirtyCheckEventListener {
18
19     private static final Log log = LogFactory.getLog(DefaultDirtyCheckEventListener.class);
20
21     /** Handle the given dirty-check event.
22      *
23      * @param event The dirty-check event to be handled.
24      * @throws HibernateException
25      */

26     public boolean onDirtyCheck(DirtyCheckEvent event) throws HibernateException {
27
28         boolean wasNeeded = false;
29         int oldSize = event.getSession().getActionQueue().numberOfCollectionRemovals();
30
31         try {
32             flushEverythingToExecutions(event);
33             wasNeeded = event.getSession().getActionQueue().hasAnyQueuedActions();
34             log.debug( wasNeeded ? "session dirty" : "session not dirty" );
35             return wasNeeded;
36         }
37         finally {
38             event.getSession().getActionQueue().clearFromFlushNeededCheck( oldSize );
39         }
40     }
41 }
42
Popular Tags