From: <one...@us...> - 2002-12-15 10:51:34
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate In directory sc8-pr-cvs1:/tmp/cvs-serv31987/hibernate Added Files: FlushMode.java Log Message: added FlushMode API --- NEW FILE: FlushMode.java --- //$Id: FlushMode.java,v 1.1 2002/12/15 10:51:31 oneovthafew Exp $ package cirrus.hibernate; import java.io.Serializable; import java.util.HashMap; import java.util.Map; /** * Represents a flushing strategy. The flush process synchronizes * database state with session state by detecting state changes * and executing SQL statements. * * @see Session#setFlushMode(FlushMode) */ public final class FlushMode implements Serializable { private final int level; private final String name; private static final Map instances = new HashMap(); private FlushMode(int level, String name) { this.level=level; this.name=name; } public String toString() { return name; } /** * Does this mode flush more often than the given flush mode? */ public boolean greaterThan(FlushMode mode) { return level > mode.level; } /** * Does this mode flush less often than the given flush mode? */ public boolean lessThan(FlushMode mode) { return level < mode.level; } /** * The <tt>Session</tt> is never flushed unless <tt>flush()</tt> * is explicitly called by the application. This mode is very * efficient for read only transactions. */ public static final FlushMode NEVER = new FlushMode(0, "NEVER"); /** * The <tt>Session</tt> is flushed when <tt>Transaction.commit()</tt> * is called. */ public static final FlushMode COMMIT = new FlushMode(5, "COMMIT"); /** * The <tt>Session</tt> is sometimes flushed before query execution * in order to ensure that queries never return stale state. This * is the default flush mode. */ public static final FlushMode AUTO = new FlushMode(10, "AUTO"); static { instances.put( new Integer(NEVER.level), NEVER ); instances.put( new Integer(AUTO.level), AUTO ); instances.put( new Integer(COMMIT.level), COMMIT ); } Object readResolve() { return instances.get( new Integer(level) ); } } |