001: // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
002:
003: package jodd.db;
004:
005: import jodd.util.ObjectUtil;
006: import jodd.util.HashCodeUtil;
007:
008: import java.sql.ResultSet;
009:
010: /**
011: * {@link DbQuery} mode.
012: */
013: public class DbQueryMode {
014:
015: public DbQueryMode() {
016: type = TYPE_FORWARD_ONLY;
017: concurrencyType = CONCUR_READ_ONLY;
018: holdability = CLOSE_CURSORS_AT_COMMIT;
019: debug = false;
020: }
021:
022: // ---------------------------------------------------------------- types
023:
024: /**
025: * @see java.sql.ResultSet#TYPE_FORWARD_ONLY
026: */
027: public static final int TYPE_FORWARD_ONLY = ResultSet.TYPE_FORWARD_ONLY;
028: /**
029: * @see java.sql.ResultSet#TYPE_SCROLL_SENSITIVE
030: */
031: public static final int TYPE_SCROLL_SENSITIVE = ResultSet.TYPE_SCROLL_SENSITIVE;
032: /**
033: * @see java.sql.ResultSet#TYPE_SCROLL_INSENSITIVE
034: */
035: public static final int TYPE_SCROLL_INSENSITIVE = ResultSet.TYPE_SCROLL_INSENSITIVE;
036:
037: private int type;
038:
039: public int getType() {
040: return type;
041: }
042:
043: public DbQueryMode setType(int type) {
044: this .type = type;
045: return this ;
046: }
047:
048: public DbQueryMode typeForwardOnly() {
049: this .type = TYPE_FORWARD_ONLY;
050: return this ;
051: }
052:
053: public DbQueryMode typeScrollSensitive() {
054: this .type = TYPE_SCROLL_SENSITIVE;
055: return this ;
056: }
057:
058: public DbQueryMode typeScrollInsensitive() {
059: this .type = TYPE_SCROLL_SENSITIVE;
060: return this ;
061: }
062:
063: // ---------------------------------------------------------------- concurrency
064:
065: /**
066: * @see java.sql.ResultSet#CONCUR_READ_ONLY
067: */
068: public static final int CONCUR_READ_ONLY = ResultSet.CONCUR_READ_ONLY;
069: /**
070: * @see java.sql.ResultSet#CONCUR_UPDATABLE
071: */
072: public static final int CONCUR_UPDATABLE = ResultSet.CONCUR_UPDATABLE;
073:
074: private int concurrencyType;
075:
076: public int getConcurrencyType() {
077: return concurrencyType;
078: }
079:
080: public DbQueryMode setConcurrencyType(int concurrencyType) {
081: this .concurrencyType = concurrencyType;
082: return this ;
083: }
084:
085: public DbQueryMode concurReadOnly() {
086: this .concurrencyType = CONCUR_READ_ONLY;
087: return this ;
088: }
089:
090: public DbQueryMode concurUpdatable() {
091: this .concurrencyType = CONCUR_UPDATABLE;
092: return this ;
093: }
094:
095: // ---------------------------------------------------------------- holdability
096:
097: /**
098: * @see java.sql.ResultSet#CLOSE_CURSORS_AT_COMMIT
099: */
100: public static final int CLOSE_CURSORS_AT_COMMIT = ResultSet.CLOSE_CURSORS_AT_COMMIT;
101:
102: /**
103: * @see java.sql.ResultSet#HOLD_CURSORS_OVER_COMMIT
104: */
105: public static final int HOLD_CURSORS_OVER_COMMIT = ResultSet.HOLD_CURSORS_OVER_COMMIT;
106:
107: private int holdability;
108:
109: public int getHoldability() {
110: return holdability;
111: }
112:
113: public DbQueryMode setHoldability(int holdability) {
114: this .holdability = holdability;
115: return this ;
116: }
117:
118: public DbQueryMode holdCursorsOverCommit() {
119: this .holdability = HOLD_CURSORS_OVER_COMMIT;
120: return this ;
121: }
122:
123: public DbQueryMode closeCursorsAtCommit() {
124: this .holdability = CLOSE_CURSORS_AT_COMMIT;
125: return this ;
126: }
127:
128: // ---------------------------------------------------------------- debug mode
129:
130: private boolean debug;
131:
132: public boolean isDebug() {
133: return debug;
134: }
135:
136: public DbQueryMode setDebug(boolean debug) {
137: this .debug = debug;
138: return this ;
139: }
140:
141: public DbQueryMode debug() {
142: this .debug = true;
143: return this ;
144: }
145:
146: // ---------------------------------------------------------------- equals & hashCode
147:
148: @Override
149: public boolean equals(Object object) {
150: if (this == object) {
151: return true;
152: }
153: if (ObjectUtil.equalsType(object, this ) == false) {
154: return false;
155: }
156: final DbQueryMode mode = (DbQueryMode) object;
157:
158: return (mode.getType() == this .type)
159: && (mode.getConcurrencyType() == this .concurrencyType)
160: && (mode.getHoldability() == this .holdability)
161: && (mode.isDebug() == this .debug);
162: }
163:
164: @Override
165: public int hashCode() {
166: int result = HashCodeUtil.SEED;
167: result = HashCodeUtil.hash(result, this.type);
168: result = HashCodeUtil.hash(result, this.concurrencyType);
169: result = HashCodeUtil.hash(result, this.holdability);
170: result = HashCodeUtil.hash(result, this.debug);
171: return result;
172: }
173:
174: }
|