01: //$Id: ScrollMode.java 4369 2004-08-18 00:28:43Z oneovthafew $
02: package org.hibernate;
03:
04: import java.io.Serializable;
05: import java.sql.ResultSet;
06: import java.util.HashMap;
07: import java.util.Map;
08:
09: /**
10: * Specifies the type of JDBC scrollable result set to use
11: * underneath a <tt>ScrollableResults</tt>
12: *
13: * @see Query#scroll(ScrollMode)
14: * @see ScrollableResults
15: * @author Gavin King
16: */
17: public final class ScrollMode implements Serializable {
18: private final int resultSetType;
19: private final String name;
20: private static final Map INSTANCES = new HashMap();
21:
22: private ScrollMode(int level, String name) {
23: this .resultSetType = level;
24: this .name = name;
25: }
26:
27: public String toString() {
28: return name;
29: }
30:
31: /**
32: * @return the JDBC result set type code
33: */
34: public int toResultSetType() {
35: return resultSetType;
36: }
37:
38: /**
39: * @see java.sql.ResultSet.TYPE_FORWARD_ONLY
40: */
41: public static final ScrollMode FORWARD_ONLY = new ScrollMode(
42: ResultSet.TYPE_FORWARD_ONLY, "FORWARD_ONLY");
43: /**
44: * @see java.sql.ResultSet.TYPE_SCROLL_SENSITIVE
45: */
46: public static final ScrollMode SCROLL_SENSITIVE = new ScrollMode(
47: ResultSet.TYPE_SCROLL_SENSITIVE, "SCROLL_SENSITIVE");
48: /**
49: * Note that since the Hibernate session acts as a cache, you
50: * might need to expicitly evict objects, if you need to see
51: * changes made by other transactions.
52: * @see java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE
53: */
54: public static final ScrollMode SCROLL_INSENSITIVE = new ScrollMode(
55: ResultSet.TYPE_SCROLL_INSENSITIVE, "SCROLL_INSENSITIVE");
56:
57: public boolean lessThan(ScrollMode other) {
58: return this .resultSetType < other.resultSetType;
59: }
60:
61: static {
62: INSTANCES.put(FORWARD_ONLY.name, FORWARD_ONLY);
63: INSTANCES.put(SCROLL_INSENSITIVE.name, SCROLL_INSENSITIVE);
64: INSTANCES.put(SCROLL_SENSITIVE.name, SCROLL_SENSITIVE);
65: }
66:
67: private Object readResolve() {
68: return INSTANCES.get(name);
69: }
70:
71: }
|