01: //$Id: FetchMode.java 5060 2004-12-24 03:11:05Z oneovthafew $
02: package org.hibernate;
03:
04: import java.io.Serializable;
05: import java.util.HashMap;
06: import java.util.Map;
07:
08: /**
09: * Represents an association fetching strategy. This is used
10: * together with the <tt>Criteria</tt> API to specify runtime
11: * fetching strategies.<br>
12: * <br>
13: * For HQL queries, use the <tt>FETCH</tt> keyword instead.
14: *
15: * @see Criteria#setFetchMode(java.lang.String, FetchMode)
16: * @author Gavin King
17: */
18: public final class FetchMode implements Serializable {
19: private final String name;
20: private static final Map INSTANCES = new HashMap();
21:
22: private FetchMode(String name) {
23: this .name = name;
24: }
25:
26: public String toString() {
27: return name;
28: }
29:
30: /**
31: * Default to the setting configured in the mapping file.
32: */
33: public static final FetchMode DEFAULT = new FetchMode("DEFAULT");
34:
35: /**
36: * Fetch using an outer join. Equivalent to <tt>fetch="join"</tt>.
37: */
38: public static final FetchMode JOIN = new FetchMode("JOIN");
39: /**
40: * Fetch eagerly, using a separate select. Equivalent to
41: * <tt>fetch="select"</tt>.
42: */
43: public static final FetchMode SELECT = new FetchMode("SELECT");
44:
45: /**
46: * Fetch lazily. Equivalent to <tt>outer-join="false"</tt>.
47: * @deprecated use <tt>FetchMode.SELECT</tt>
48: */
49: public static final FetchMode LAZY = SELECT;
50: /**
51: * Fetch eagerly, using an outer join. Equivalent to
52: * <tt>outer-join="true"</tt>.
53: * @deprecated use <tt>FetchMode.JOIN</tt>
54: */
55: public static final FetchMode EAGER = JOIN;
56:
57: static {
58: INSTANCES.put(JOIN.name, JOIN);
59: INSTANCES.put(SELECT.name, SELECT);
60: INSTANCES.put(DEFAULT.name, DEFAULT);
61: }
62:
63: private Object readResolve() {
64: return INSTANCES.get(name);
65: }
66:
67: }
|