// Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
package jodd.db;
import jodd.util.ObjectUtil;
import jodd.util.HashCodeUtil;
import java.sql.ResultSet;
/**
* {@link DbQuery} mode.
*/
public class DbQueryMode {
public DbQueryMode() {
type = TYPE_FORWARD_ONLY;
concurrencyType = CONCUR_READ_ONLY;
holdability = CLOSE_CURSORS_AT_COMMIT;
debug = false;
}
// ---------------------------------------------------------------- types
/**
* @see java.sql.ResultSet#TYPE_FORWARD_ONLY
*/
public static final int TYPE_FORWARD_ONLY = ResultSet.TYPE_FORWARD_ONLY;
/**
* @see java.sql.ResultSet#TYPE_SCROLL_SENSITIVE
*/
public static final int TYPE_SCROLL_SENSITIVE = ResultSet.TYPE_SCROLL_SENSITIVE;
/**
* @see java.sql.ResultSet#TYPE_SCROLL_INSENSITIVE
*/
public static final int TYPE_SCROLL_INSENSITIVE = ResultSet.TYPE_SCROLL_INSENSITIVE;
private int type;
public int getType() {
return type;
}
public DbQueryMode setType(int type) {
this.type = type;
return this;
}
public DbQueryMode typeForwardOnly() {
this.type = TYPE_FORWARD_ONLY;
return this;
}
public DbQueryMode typeScrollSensitive() {
this.type = TYPE_SCROLL_SENSITIVE;
return this;
}
public DbQueryMode typeScrollInsensitive() {
this.type = TYPE_SCROLL_SENSITIVE;
return this;
}
// ---------------------------------------------------------------- concurrency
/**
* @see java.sql.ResultSet#CONCUR_READ_ONLY
*/
public static final int CONCUR_READ_ONLY = ResultSet.CONCUR_READ_ONLY;
/**
* @see java.sql.ResultSet#CONCUR_UPDATABLE
*/
public static final int CONCUR_UPDATABLE = ResultSet.CONCUR_UPDATABLE;
private int concurrencyType;
public int getConcurrencyType() {
return concurrencyType;
}
public DbQueryMode setConcurrencyType(int concurrencyType) {
this.concurrencyType = concurrencyType;
return this;
}
public DbQueryMode concurReadOnly() {
this.concurrencyType = CONCUR_READ_ONLY;
return this;
}
public DbQueryMode concurUpdatable() {
this.concurrencyType = CONCUR_UPDATABLE;
return this;
}
// ---------------------------------------------------------------- holdability
/**
* @see java.sql.ResultSet#CLOSE_CURSORS_AT_COMMIT
*/
public static final int CLOSE_CURSORS_AT_COMMIT = ResultSet.CLOSE_CURSORS_AT_COMMIT;
/**
* @see java.sql.ResultSet#HOLD_CURSORS_OVER_COMMIT
*/
public static final int HOLD_CURSORS_OVER_COMMIT = ResultSet.HOLD_CURSORS_OVER_COMMIT;
private int holdability;
public int getHoldability() {
return holdability;
}
public DbQueryMode setHoldability(int holdability) {
this.holdability = holdability;
return this;
}
public DbQueryMode holdCursorsOverCommit() {
this.holdability = HOLD_CURSORS_OVER_COMMIT;
return this;
}
public DbQueryMode closeCursorsAtCommit() {
this.holdability = CLOSE_CURSORS_AT_COMMIT;
return this;
}
// ---------------------------------------------------------------- debug mode
private boolean debug;
public boolean isDebug() {
return debug;
}
public DbQueryMode setDebug(boolean debug) {
this.debug = debug;
return this;
}
public DbQueryMode debug() {
this.debug = true;
return this;
}
// ---------------------------------------------------------------- equals & hashCode
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (ObjectUtil.equalsType(object, this) == false) {
return false;
}
final DbQueryMode mode = (DbQueryMode) object;
return (mode.getType() == this.type) &&
(mode.getConcurrencyType() == this.concurrencyType) &&
(mode.getHoldability() == this.holdability) &&
(mode.isDebug() == this.debug);
}
@Override
public int hashCode() {
int result = HashCodeUtil.SEED;
result = HashCodeUtil.hash(result, this.type);
result = HashCodeUtil.hash(result, this.concurrencyType);
result = HashCodeUtil.hash(result, this.holdability);
result = HashCodeUtil.hash(result, this.debug);
return result;
}
}
|