KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > CacheMode


1 //$Id: CacheMode.java,v 1.2 2005/02/12 07:19:50 steveebersole 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  * Controls how the session interacts with the second-level
10  * cache and query cache.
11  *
12  * @see Session#setCacheMode(CacheMode)
13  * @author Gavin King
14  */

15 public final class CacheMode implements Serializable JavaDoc {
16     private final String JavaDoc name;
17     private final boolean isPutEnabled;
18     private final boolean isGetEnabled;
19     private static final Map JavaDoc INSTANCES = new HashMap JavaDoc();
20
21     private CacheMode(String JavaDoc name, boolean isPutEnabled, boolean isGetEnabled) {
22         this.name=name;
23         this.isPutEnabled = isPutEnabled;
24         this.isGetEnabled = isGetEnabled;
25     }
26     public String JavaDoc toString() {
27         return name;
28     }
29     public boolean isPutEnabled() {
30         return isPutEnabled;
31     }
32     public boolean isGetEnabled() {
33         return isGetEnabled;
34     }
35     /**
36      * The session may read items from the cache, and add items to the cache
37      */

38     public static final CacheMode NORMAL = new CacheMode("NORMAL", true, true);
39     /**
40      * The session will never interact with the cache, except to invalidate
41      * cache items when updates occur
42      */

43     public static final CacheMode IGNORE = new CacheMode("IGNORE", false, false);
44     /**
45      * The session may read items from the cache, but will not add items,
46      * except to invalidate items when updates occur
47      */

48     public static final CacheMode GET = new CacheMode("GET", false, true);
49     /**
50      * The session will never read items from the cache, but will add items
51      * to the cache as it reads them from the database.
52      */

53     public static final CacheMode PUT = new CacheMode("PUT", true, false);
54     
55     /**
56      * The session will never read items from the cache, but will add items
57      * to the cache as it reads them from the database. In this mode, the
58      * effect of <tt>hibernate.cache.use_minimal_puts</tt> is bypassed, in
59      * order to <em>force</em> a cache refresh
60      */

61     public static final CacheMode REFRESH = new CacheMode("REFRESH", true, false);
62     
63     static {
64         INSTANCES.put( NORMAL.name, NORMAL );
65         INSTANCES.put( IGNORE.name, IGNORE );
66         INSTANCES.put( GET.name, GET );
67         INSTANCES.put( PUT.name, PUT );
68         INSTANCES.put( REFRESH.name, REFRESH );
69     }
70
71     private Object JavaDoc readResolve() {
72         return INSTANCES.get(name);
73     }
74
75 }
76
77
78
79
80
81
82
Popular Tags