From: <hib...@li...> - 2006-06-15 07:51:33
|
Author: ste...@jb... Date: 2006-06-15 03:50:12 -0400 (Thu, 15 Jun 2006) New Revision: 10019 Modified: trunk/Hibernate3/src/org/hibernate/FlushMode.java trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java trunk/Hibernate3/src/org/hibernate/impl/SessionImpl.java trunk/Hibernate3/src/org/hibernate/persister/collection/NamedQueryCollectionInitializer.java trunk/Hibernate3/src/org/hibernate/persister/entity/NamedQueryLoader.java Log: HHH-1839 : added FlushMode.MANUAL; deprecated FlushMode.NEVER Modified: trunk/Hibernate3/src/org/hibernate/FlushMode.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/FlushMode.java 2006-06-15 05:21:06 UTC (rev 10018) +++ trunk/Hibernate3/src/org/hibernate/FlushMode.java 2006-06-15 07:50:12 UTC (rev 10019) @@ -14,34 +14,48 @@ * @author Gavin King */ public final class FlushMode implements Serializable { + private static final Map INSTANCES = new HashMap(); + 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; + this.level = level; + this.name = name; } public String toString() { return name; } + /** * 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. + * + * @deprecated use {@link #MANUAL} instead. */ - public static final FlushMode NEVER = new FlushMode(0, "NEVER"); + public static final FlushMode NEVER = new FlushMode( 0, "NEVER" ); + /** + * The <tt>Session</tt> is onyl eve flushed when <tt>flush()</tt> + * is explicitly called by the application. This mode is very + * efficient for read only transactions. + */ + public static final FlushMode MANUAL = new FlushMode( 0, "MANUAL" ); + + /** * 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"); + /** * The <tt>Session</tt> is flushed before every query. This is * almost always unnecessary and inefficient. @@ -54,11 +68,16 @@ static { INSTANCES.put( NEVER.name, NEVER ); + INSTANCES.put( MANUAL.name, MANUAL ); INSTANCES.put( AUTO.name, AUTO ); INSTANCES.put( ALWAYS.name, ALWAYS ); INSTANCES.put( COMMIT.name, COMMIT ); } + public static boolean isManualFlushMode(FlushMode mode) { + return MANUAL.level == mode.level; + } + private Object readResolve() { return INSTANCES.get( name ); } Modified: trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2006-06-15 05:21:06 UTC (rev 10018) +++ trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2006-06-15 07:50:12 UTC (rev 10019) @@ -2530,6 +2530,9 @@ else if ( "never".equals( flushMode ) ) { return FlushMode.NEVER; } + else if ( "manual".equals( flushMode ) ) { + return FlushMode.MANUAL; + } else if ( "always".equals( flushMode ) ) { return FlushMode.ALWAYS; } Modified: trunk/Hibernate3/src/org/hibernate/impl/SessionImpl.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/impl/SessionImpl.java 2006-06-15 05:21:06 UTC (rev 10018) +++ trunk/Hibernate3/src/org/hibernate/impl/SessionImpl.java 2006-06-15 07:50:12 UTC (rev 10019) @@ -322,7 +322,7 @@ } public boolean isFlushModeNever() { - return getFlushMode() == FlushMode.NEVER; + return FlushMode.isManualFlushMode( getFlushMode() ); } public boolean isFlushBeforeCompletionEnabled() { Modified: trunk/Hibernate3/src/org/hibernate/persister/collection/NamedQueryCollectionInitializer.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/persister/collection/NamedQueryCollectionInitializer.java 2006-06-15 05:21:06 UTC (rev 10018) +++ trunk/Hibernate3/src/org/hibernate/persister/collection/NamedQueryCollectionInitializer.java 2006-06-15 07:50:12 UTC (rev 10019) @@ -51,8 +51,8 @@ else { query.setParameter( 0, key, persister.getKeyType() ); } - query.setCollectionKey(key) - .setFlushMode(FlushMode.NEVER) + query.setCollectionKey( key ) + .setFlushMode( FlushMode.MANUAL ) .list(); } Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/NamedQueryLoader.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/persister/entity/NamedQueryLoader.java 2006-06-15 05:21:06 UTC (rev 10018) +++ trunk/Hibernate3/src/org/hibernate/persister/entity/NamedQueryLoader.java 2006-06-15 07:50:12 UTC (rev 10019) @@ -53,7 +53,7 @@ query.setOptionalId(id); query.setOptionalEntityName( persister.getEntityName() ); query.setOptionalObject(optionalObject); - query.setFlushMode(FlushMode.NEVER); + query.setFlushMode( FlushMode.MANUAL ); query.list(); // now look up the object we are really interested in! |