KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > db > DbQueryMode


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.db;
4
5 import jodd.util.ObjectUtil;
6 import jodd.util.HashCodeUtil;
7
8 import java.sql.ResultSet JavaDoc;
9
10 /**
11  * {@link DbQuery} mode.
12  */

13 public class DbQueryMode {
14
15     public DbQueryMode() {
16         type = TYPE_FORWARD_ONLY;
17         concurrencyType = CONCUR_READ_ONLY;
18         holdability = CLOSE_CURSORS_AT_COMMIT;
19         debug = false;
20     }
21
22     // ---------------------------------------------------------------- types
23

24     /**
25      * @see java.sql.ResultSet#TYPE_FORWARD_ONLY
26      */

27     public static final int TYPE_FORWARD_ONLY = ResultSet.TYPE_FORWARD_ONLY;
28     /**
29      * @see java.sql.ResultSet#TYPE_SCROLL_SENSITIVE
30      */

31     public static final int TYPE_SCROLL_SENSITIVE = ResultSet.TYPE_SCROLL_SENSITIVE;
32     /**
33      * @see java.sql.ResultSet#TYPE_SCROLL_INSENSITIVE
34      */

35     public static final int TYPE_SCROLL_INSENSITIVE = ResultSet.TYPE_SCROLL_INSENSITIVE;
36
37
38     private int type;
39
40     public int getType() {
41         return type;
42     }
43
44     public DbQueryMode setType(int type) {
45         this.type = type;
46         return this;
47     }
48
49     public DbQueryMode typeForwardOnly() {
50         this.type = TYPE_FORWARD_ONLY;
51         return this;
52     }
53
54     public DbQueryMode typeScrollSensitive() {
55         this.type = TYPE_SCROLL_SENSITIVE;
56         return this;
57     }
58     public DbQueryMode typeScrollInsensitive() {
59         this.type = TYPE_SCROLL_SENSITIVE;
60         return this;
61     }
62
63     // ---------------------------------------------------------------- concurrency
64

65     /**
66      * @see java.sql.ResultSet#CONCUR_READ_ONLY
67      */

68     public static final int CONCUR_READ_ONLY = ResultSet.CONCUR_READ_ONLY;
69     /**
70      * @see java.sql.ResultSet#CONCUR_UPDATABLE
71      */

72     public static final int CONCUR_UPDATABLE = ResultSet.CONCUR_UPDATABLE;
73
74
75     private int concurrencyType;
76
77     public int getConcurrencyType() {
78         return concurrencyType;
79     }
80
81     public DbQueryMode setConcurrencyType(int concurrencyType) {
82         this.concurrencyType = concurrencyType;
83         return this;
84     }
85
86     public DbQueryMode concurReadOnly() {
87         this.concurrencyType = CONCUR_READ_ONLY;
88         return this;
89     }
90
91     public DbQueryMode concurUpdatable() {
92         this.concurrencyType = CONCUR_UPDATABLE;
93         return this;
94     }
95
96     // ---------------------------------------------------------------- holdability
97

98
99     /**
100      * @see java.sql.ResultSet#CLOSE_CURSORS_AT_COMMIT
101      */

102     public static final int CLOSE_CURSORS_AT_COMMIT = ResultSet.CLOSE_CURSORS_AT_COMMIT;
103
104     /**
105      * @see java.sql.ResultSet#HOLD_CURSORS_OVER_COMMIT
106      */

107     public static final int HOLD_CURSORS_OVER_COMMIT = ResultSet.HOLD_CURSORS_OVER_COMMIT;
108
109
110     private int holdability;
111
112     public int getHoldability() {
113         return holdability;
114     }
115
116     public DbQueryMode setHoldability(int holdability) {
117         this.holdability = holdability;
118         return this;
119     }
120
121     public DbQueryMode holdCursorsOverCommit() {
122         this.holdability = HOLD_CURSORS_OVER_COMMIT;
123         return this;
124     }
125
126     public DbQueryMode closeCursorsAtCommit() {
127         this.holdability = CLOSE_CURSORS_AT_COMMIT;
128         return this;
129     }
130
131
132     // ---------------------------------------------------------------- debug mode
133

134     private boolean debug;
135
136     public boolean isDebug() {
137         return debug;
138     }
139
140     public DbQueryMode setDebug(boolean debug) {
141         this.debug = debug;
142         return this;
143     }
144
145     public DbQueryMode debug() {
146         this.debug = true;
147         return this;
148     }
149
150
151     // ---------------------------------------------------------------- equals & hashCode
152

153     public boolean equals(Object JavaDoc object) {
154         if (this == object) {
155             return true;
156         }
157         if (ObjectUtil.equalsType(object, this) == false) {
158             return false;
159         }
160         final DbQueryMode mode = (DbQueryMode) object;
161
162         return (mode.getType() == this.type) &&
163                 (mode.getConcurrencyType() == this.concurrencyType) &&
164                 (mode.getHoldability() == this.holdability) &&
165                 (mode.isDebug() == this.debug);
166     }
167
168     public int hashCode() {
169         int result = HashCodeUtil.SEED;
170         result = HashCodeUtil.hash(result, this.type);
171         result = HashCodeUtil.hash(result, this.concurrencyType);
172         result = HashCodeUtil.hash(result, this.holdability);
173         result = HashCodeUtil.hash(result, this.debug);
174         return result;
175     }
176
177 }
Popular Tags