Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
33 | PointedEar | 1 | /* |
2 | * Hibernate, Relational Persistence for Idiomatic Java |
||
3 | * |
||
4 | * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as |
||
5 | * indicated by the @author tags or express copyright attribution |
||
6 | * statements applied by the authors. All third-party contributions are |
||
7 | * distributed under license by Red Hat Middleware LLC. |
||
8 | * |
||
9 | * This copyrighted material is made available to anyone wishing to use, modify, |
||
10 | * copy, or redistribute it subject to the terms and conditions of the GNU |
||
11 | * Lesser General Public License, as published by the Free Software Foundation. |
||
12 | * |
||
13 | * This program is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
||
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
||
16 | * for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU Lesser General Public License |
||
19 | * along with this distribution; if not, write to: |
||
20 | * Free Software Foundation, Inc. |
||
21 | * 51 Franklin Street, Fifth Floor |
||
22 | * Boston, MA 02110-1301 USA |
||
23 | * |
||
24 | */ |
||
25 | package org.hibernate; |
||
26 | |||
27 | import java.io.Serializable; |
||
28 | import java.util.HashMap; |
||
29 | import java.util.Map; |
||
30 | |||
31 | /** |
||
32 | * Controls how the session interacts with the second-level |
||
33 | * cache and query cache. |
||
34 | * |
||
35 | * @see Session#setCacheMode(CacheMode) |
||
36 | * @author Gavin King |
||
37 | */ |
||
38 | public final class CacheMode implements Serializable { |
||
39 | private final String name; |
||
40 | private final boolean isPutEnabled; |
||
41 | private final boolean isGetEnabled; |
||
42 | private static final Map INSTANCES = new HashMap(); |
||
43 | |||
44 | private CacheMode(String name, boolean isPutEnabled, boolean isGetEnabled) { |
||
45 | this.name=name; |
||
46 | this.isPutEnabled = isPutEnabled; |
||
47 | this.isGetEnabled = isGetEnabled; |
||
48 | } |
||
49 | public String toString() { |
||
50 | return name; |
||
51 | } |
||
52 | public boolean isPutEnabled() { |
||
53 | return isPutEnabled; |
||
54 | } |
||
55 | public boolean isGetEnabled() { |
||
56 | return isGetEnabled; |
||
57 | } |
||
58 | /** |
||
59 | * The session may read items from the cache, and add items to the cache |
||
60 | */ |
||
61 | public static final CacheMode NORMAL = new CacheMode("NORMAL", true, true); |
||
62 | /** |
||
63 | * The session will never interact with the cache, except to invalidate |
||
64 | * cache items when updates occur |
||
65 | */ |
||
66 | public static final CacheMode IGNORE = new CacheMode("IGNORE", false, false); |
||
67 | /** |
||
68 | * The session may read items from the cache, but will not add items, |
||
69 | * except to invalidate items when updates occur |
||
70 | */ |
||
71 | public static final CacheMode GET = new CacheMode("GET", false, true); |
||
72 | /** |
||
73 | * The session will never read items from the cache, but will add items |
||
74 | * to the cache as it reads them from the database. |
||
75 | */ |
||
76 | public static final CacheMode PUT = new CacheMode("PUT", true, false); |
||
77 | |||
78 | /** |
||
79 | * The session will never read items from the cache, but will add items |
||
80 | * to the cache as it reads them from the database. In this mode, the |
||
81 | * effect of <tt>hibernate.cache.use_minimal_puts</tt> is bypassed, in |
||
82 | * order to <em>force</em> a cache refresh |
||
83 | */ |
||
84 | public static final CacheMode REFRESH = new CacheMode("REFRESH", true, false); |
||
85 | |||
86 | static { |
||
87 | INSTANCES.put( NORMAL.name, NORMAL ); |
||
88 | INSTANCES.put( IGNORE.name, IGNORE ); |
||
89 | INSTANCES.put( GET.name, GET ); |
||
90 | INSTANCES.put( PUT.name, PUT ); |
||
91 | INSTANCES.put( REFRESH.name, REFRESH ); |
||
92 | } |
||
93 | |||
94 | private Object readResolve() { |
||
95 | return INSTANCES.get( name ); |
||
96 | } |
||
97 | |||
98 | public static CacheMode parse(String name) { |
||
99 | return ( CacheMode ) INSTANCES.get( name ); |
||
100 | } |
||
101 | } |