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.sql.ResultSet; |
||
29 | import java.util.HashMap; |
||
30 | import java.util.Map; |
||
31 | |||
32 | /** |
||
33 | * Specifies the type of JDBC scrollable result set to use |
||
34 | * underneath a <tt>ScrollableResults</tt> |
||
35 | * |
||
36 | * @see Query#scroll(ScrollMode) |
||
37 | * @see ScrollableResults |
||
38 | * @author Gavin King |
||
39 | */ |
||
40 | public final class ScrollMode implements Serializable { |
||
41 | private final int resultSetType; |
||
42 | private final String name; |
||
43 | private static final Map INSTANCES = new HashMap(); |
||
44 | |||
45 | private ScrollMode(int level, String name) { |
||
46 | this.resultSetType=level; |
||
47 | this.name=name; |
||
48 | } |
||
49 | |||
50 | public String toString() { |
||
51 | return name; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @return the JDBC result set type code |
||
56 | */ |
||
57 | public int toResultSetType() { |
||
58 | return resultSetType; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @see java.sql.ResultSet.TYPE_FORWARD_ONLY |
||
63 | */ |
||
64 | public static final ScrollMode FORWARD_ONLY = new ScrollMode(ResultSet.TYPE_FORWARD_ONLY, "FORWARD_ONLY"); |
||
65 | /** |
||
66 | * @see java.sql.ResultSet.TYPE_SCROLL_SENSITIVE |
||
67 | */ |
||
68 | public static final ScrollMode SCROLL_SENSITIVE = new ScrollMode(ResultSet.TYPE_SCROLL_SENSITIVE, "SCROLL_SENSITIVE"); |
||
69 | /** |
||
70 | * Note that since the Hibernate session acts as a cache, you |
||
71 | * might need to expicitly evict objects, if you need to see |
||
72 | * changes made by other transactions. |
||
73 | * @see java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE |
||
74 | */ |
||
75 | public static final ScrollMode SCROLL_INSENSITIVE = new ScrollMode(ResultSet.TYPE_SCROLL_INSENSITIVE, "SCROLL_INSENSITIVE"); |
||
76 | |||
77 | public boolean lessThan(ScrollMode other) { |
||
78 | return this.resultSetType<other.resultSetType; |
||
79 | } |
||
80 | |||
81 | static { |
||
82 | INSTANCES.put( FORWARD_ONLY.name, FORWARD_ONLY ); |
||
83 | INSTANCES.put( SCROLL_INSENSITIVE.name, SCROLL_INSENSITIVE ); |
||
84 | INSTANCES.put( SCROLL_SENSITIVE.name, SCROLL_SENSITIVE ); |
||
85 | } |
||
86 | |||
87 | private Object readResolve() { |
||
88 | return INSTANCES.get(name); |
||
89 | } |
||
90 | |||
91 | } |
||
92 | |||
93 | |||
94 | |||
95 | |||
96 | |||
97 |