KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > FlushMode


1 //$Id: FlushMode.java,v 1.2 2004/08/15 03:13:38 oneovthafew Exp $
2
package org.hibernate;
3
4 import java.io.Serializable JavaDoc;
5 import java.util.HashMap JavaDoc;
6 import java.util.Map JavaDoc;
7
8 /**
9  * Represents a flushing strategy. The flush process synchronizes
10  * database state with session state by detecting state changes
11  * and executing SQL statements.
12  *
13  * @see Session#setFlushMode(FlushMode)
14  * @author Gavin King
15  */

16 public final class FlushMode implements Serializable JavaDoc {
17     private final int level;
18     private final String JavaDoc name;
19     private static final Map JavaDoc INSTANCES = new HashMap JavaDoc();
20
21     private FlushMode(int level, String JavaDoc name) {
22         this.level=level;
23         this.name=name;
24     }
25     public String JavaDoc toString() {
26         return name;
27     }
28     /**
29      * The <tt>Session</tt> is never flushed unless <tt>flush()</tt>
30      * is explicitly called by the application. This mode is very
31      * efficient for read only transactions.
32      */

33     public static final FlushMode NEVER = new FlushMode(0, "NEVER");
34     /**
35      * The <tt>Session</tt> is flushed when <tt>Transaction.commit()</tt>
36      * is called.
37      */

38     public static final FlushMode COMMIT = new FlushMode(5, "COMMIT");
39     /**
40      * The <tt>Session</tt> is sometimes flushed before query execution
41      * in order to ensure that queries never return stale state. This
42      * is the default flush mode.
43      */

44     public static final FlushMode AUTO = new FlushMode(10, "AUTO");
45     /**
46      * The <tt>Session</tt> is flushed before every query. This is
47      * almost always unnecessary and inefficient.
48      */

49     public static final FlushMode ALWAYS = new FlushMode(20, "ALWAYS");
50     
51     public boolean lessThan(FlushMode other) {
52         return this.level<other.level;
53     }
54
55     static {
56         INSTANCES.put( NEVER.name, NEVER );
57         INSTANCES.put( AUTO.name, AUTO );
58         INSTANCES.put( ALWAYS.name, ALWAYS );
59         INSTANCES.put( COMMIT.name, COMMIT );
60     }
61
62     private Object JavaDoc readResolve() {
63         return INSTANCES.get(name);
64     }
65
66 }
67
68
69
70
71
72
73
Popular Tags