1 package org.hibernate.event.def; 3 4 import org.apache.commons.logging.Log; 5 import org.apache.commons.logging.LogFactory; 6 import org.hibernate.FlushMode; 7 import org.hibernate.HibernateException; 8 import org.hibernate.event.AutoFlushEvent; 9 import org.hibernate.event.AutoFlushEventListener; 10 import org.hibernate.event.EventSource; 11 12 18 public class DefaultAutoFlushEventListener extends AbstractFlushingEventListener implements AutoFlushEventListener { 19 20 private static final Log log = LogFactory.getLog(DefaultAutoFlushEventListener.class); 21 22 27 public boolean onAutoFlush(AutoFlushEvent event) throws HibernateException { 28 29 final EventSource source = event.getSession(); 30 31 final boolean flushMightBeNeeded = !source.getFlushMode().lessThan(FlushMode.AUTO) && 32 source.getDontFlushFromFind() == 0 && 33 source.getPersistenceContext().hasNonReadOnlyEntities(); 34 35 if (flushMightBeNeeded) { 36 37 final int oldSize = source.getActionQueue().numberOfCollectionRemovals(); 38 39 flushEverythingToExecutions(event); 40 41 final boolean flushIsReallyNeeded = source.getActionQueue() 42 .areTablesToBeUpdated( event.getQuerySpaces() ) || 43 source.getFlushMode()==FlushMode.ALWAYS; 44 45 if (flushIsReallyNeeded) { 46 47 log.trace("Need to execute flush"); 48 49 performExecutions(source); 50 postFlush(source); 51 54 if ( source.getFactory().getStatistics().isStatisticsEnabled() ) { 55 source.getFactory().getStatisticsImplementor().flush(); 56 } 57 58 } 59 else { 60 61 log.trace("Dont need to execute flush"); 62 source.getActionQueue().clearFromFlushNeededCheck( oldSize ); 63 } 64 65 return flushIsReallyNeeded; 66 67 } 68 69 return false; 70 71 } 72 73 } 74 | Popular Tags |