Use TypeInfo in Value implementations

无相关合并请求
......@@ -4020,7 +4020,7 @@ public class Parser {
}
break;
case 'D':
if (currentTokenType == VALUE && currentValue.getType() == Value.STRING &&
if (currentTokenType == VALUE && currentValue.getValueType() == Value.STRING &&
(equalsToken("DATE", name) || equalsToken("D", name))) {
String date = currentValue.getString();
read();
......@@ -4028,7 +4028,7 @@ public class Parser {
}
break;
case 'E':
if (currentTokenType == VALUE && currentValue.getType() == Value.STRING && equalsToken("E", name)) {
if (currentTokenType == VALUE && currentValue.getValueType() == Value.STRING && equalsToken("E", name)) {
String text = currentValue.getString();
// the PostgreSQL ODBC driver uses
// LIKE E'PROJECT\\_DATA' instead of LIKE
......@@ -4043,7 +4043,8 @@ public class Parser {
if (equalsToken("NEXT", name) && readIf("VALUE")) {
read(FOR);
return new SequenceValue(readSequence());
} else if (currentTokenType == VALUE && currentValue.getType() == Value.STRING && equalsToken("N", name)) {
} else if (currentTokenType == VALUE && currentValue.getValueType() == Value.STRING
&& equalsToken("N", name)) {
// SQL-92 "National Language" strings
String text = currentValue.getString();
read();
......@@ -4066,7 +4067,7 @@ public class Parser {
read("TIME");
read("ZONE");
}
if (currentTokenType == VALUE && currentValue.getType() == Value.STRING) {
if (currentTokenType == VALUE && currentValue.getValueType() == Value.STRING) {
String time = currentValue.getString();
read();
return ValueExpression.get(ValueTime.parse(time));
......@@ -4077,7 +4078,7 @@ public class Parser {
if (readIf(WITH)) {
read("TIME");
read("ZONE");
if (currentTokenType != VALUE || currentValue.getType() != Value.STRING) {
if (currentTokenType != VALUE || currentValue.getValueType() != Value.STRING) {
throw getSyntaxError();
}
String timestamp = currentValue.getString();
......@@ -4089,7 +4090,7 @@ public class Parser {
read("TIME");
read("ZONE");
}
if (currentTokenType == VALUE && currentValue.getType() == Value.STRING) {
if (currentTokenType == VALUE && currentValue.getValueType() == Value.STRING) {
String timestamp = currentValue.getString();
read();
return ValueExpression.get(ValueTimestamp.parse(timestamp, database.getMode()));
......@@ -4099,7 +4100,7 @@ public class Parser {
}
} else if (equalsToken("TODAY", name)) {
return readFunctionWithoutParameters("CURRENT_DATE");
} else if (currentTokenType == VALUE && currentValue.getType() == Value.STRING) {
} else if (currentTokenType == VALUE && currentValue.getValueType() == Value.STRING) {
if (equalsToken("T", name)) {
String time = currentValue.getString();
read();
......@@ -4112,7 +4113,7 @@ public class Parser {
}
break;
case 'X':
if (currentTokenType == VALUE && currentValue.getType() == Value.STRING && equalsToken("X", name)) {
if (currentTokenType == VALUE && currentValue.getValueType() == Value.STRING && equalsToken("X", name)) {
byte[] buffer = StringUtils.convertHexToBytes(currentValue.getString());
read();
return ValueExpression.get(ValueBytes.getNoCopy(buffer));
......@@ -7685,7 +7686,7 @@ public class Parser {
if (readIf("AUTO_INCREMENT")) {
read(EQUAL);
if (currentTokenType != VALUE ||
currentValue.getType() != Value.INT) {
currentValue.getValueType() != Value.INT) {
throw DbException.getSyntaxError(sqlCommand, parseIndex,
"integer");
}
......
......@@ -44,7 +44,7 @@ public class Call extends Prepared {
@Override
public int update() {
Value v = expression.getValue(session);
int type = v.getType();
int type = v.getValueType();
switch (type) {
case Value.RESULT_SET:
// this will throw an exception
......
......@@ -362,7 +362,7 @@ public abstract class Query extends Prepared {
Database db = s.getDatabase();
for (int i = 0; i < params.length; i++) {
Value a = lastParams[i], b = params[i];
if (a.getType() != b.getType() || !db.areEqual(a, b)) {
if (a.getValueType() != b.getValueType() || !db.areEqual(a, b)) {
return false;
}
}
......
......@@ -413,12 +413,12 @@ public class ScriptCommand extends ScriptBase {
buff.append(", ");
}
Value v = row.getValue(j);
if (v.getPrecision() > lobBlockSize) {
if (v.getType().getPrecision() > lobBlockSize) {
int id;
if (v.getType() == Value.CLOB) {
if (v.getValueType() == Value.CLOB) {
id = writeLobStream(v);
buff.append("SYSTEM_COMBINE_CLOB(").append(id).append(')');
} else if (v.getType() == Value.BLOB) {
} else if (v.getValueType() == Value.BLOB) {
id = writeLobStream(v);
buff.append("SYSTEM_COMBINE_BLOB(").append(id).append(')');
} else {
......@@ -459,7 +459,7 @@ public class ScriptCommand extends ScriptBase {
tempLobTableCreated = true;
}
int id = nextLobId++;
switch (v.getType()) {
switch (v.getValueType()) {
case Value.BLOB: {
byte[] bytes = new byte[lobBlockSize];
try (InputStream input = v.getInputStream()) {
......@@ -499,7 +499,7 @@ public class ScriptCommand extends ScriptBase {
break;
}
default:
DbException.throwInternalError("type:" + v.getType());
DbException.throwInternalError("type:" + v.getValueType());
}
return id;
}
......
......@@ -403,7 +403,7 @@ public class FunctionAlias extends SchemaObjectBase {
Object o;
if (Value.class.isAssignableFrom(paramClass)) {
o = v;
} else if (v.getType() == Value.ARRAY &&
} else if (v.getValueType() == Value.ARRAY &&
paramClass.isArray() &&
paramClass.getComponentType() != Object.class) {
Value[] array = ((ValueArray) v).getList();
......
......@@ -1745,7 +1745,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
@Override
public void addTemporaryLob(Value v) {
if (!DataType.isLargeObject(v.getType())) {
if (!DataType.isLargeObject(v.getValueType())) {
return;
}
if (v.getTableId() == LobStorageFrontend.TABLE_RESULT
......
......@@ -395,9 +395,7 @@ public abstract class Expression {
ExpressionColumn[] expr = new ExpressionColumn[list.length];
for (int i = 0, len = list.length; i < len; i++) {
Value v = list[i];
Column col = new Column("C" + (i + 1), v.getType(),
v.getPrecision(), v.getScale(),
v.getDisplaySize());
Column col = new Column("C" + (i + 1), v.getType());
expr[i] = new ExpressionColumn(session.getDatabase(), col);
}
return expr;
......
......@@ -144,7 +144,7 @@ public class IntervalOperation extends Expression {
if (l == ValueNull.INSTANCE || r == ValueNull.INSTANCE) {
return ValueNull.INSTANCE;
}
int lType = l.getType(), rType = r.getType();
int lType = l.getValueType(), rType = r.getValueType();
switch (opType) {
case INTERVAL_PLUS_INTERVAL:
case INTERVAL_MINUS_INTERVAL: {
......
......@@ -63,7 +63,7 @@ public class Parameter extends Expression implements ParameterInterface {
@Override
public int getType() {
if (value != null) {
return value.getType();
return value.getValueType();
}
if (column != null) {
return column.getType().getValueType();
......@@ -111,7 +111,7 @@ public class Parameter extends Expression implements ParameterInterface {
@Override
public int getScale() {
if (value != null) {
return value.getScale();
return value.getType().getScale();
}
if (column != null) {
return column.getType().getScale();
......@@ -122,7 +122,7 @@ public class Parameter extends Expression implements ParameterInterface {
@Override
public long getPrecision() {
if (value != null) {
return value.getPrecision();
return value.getType().getPrecision();
}
if (column != null) {
return column.getType().getPrecision();
......@@ -133,7 +133,7 @@ public class Parameter extends Expression implements ParameterInterface {
@Override
public int getDisplaySize() {
if (value != null) {
return value.getDisplaySize();
return value.getType().getDisplaySize();
}
if (column != null) {
return column.getType().getDisplaySize();
......
......@@ -56,17 +56,17 @@ public class ParameterRemote implements ParameterInterface {
@Override
public int getType() {
return value == null ? dataType : value.getType();
return value == null ? dataType : value.getValueType();
}
@Override
public long getPrecision() {
return value == null ? precision : value.getPrecision();
return value == null ? precision : value.getType().getPrecision();
}
@Override
public int getScale() {
return value == null ? scale : value.getScale();
return value == null ? scale : value.getType().getScale();
}
@Override
......
......@@ -76,12 +76,12 @@ public class ValueExpression extends Expression {
@Override
public int getType() {
return value.getType();
return value.getValueType();
}
@Override
public void createIndexConditions(Session session, TableFilter filter) {
if (value.getType() == Value.BOOLEAN) {
if (value.getValueType() == Value.BOOLEAN) {
boolean v = ((ValueBoolean) value).getBoolean();
if (!v) {
filter.addIndexCondition(IndexCondition.get(Comparison.FALSE, null, this));
......@@ -122,17 +122,17 @@ public class ValueExpression extends Expression {
@Override
public int getScale() {
return value.getScale();
return value.getType().getScale();
}
@Override
public long getPrecision() {
return value.getPrecision();
return value.getType().getPrecision();
}
@Override
public int getDisplaySize() {
return value.getDisplaySize();
return value.getType().getDisplaySize();
}
@Override
......
......@@ -32,12 +32,12 @@ public class Variable extends Expression {
@Override
public int getDisplaySize() {
return lastValue.getDisplaySize();
return lastValue.getType().getDisplaySize();
}
@Override
public long getPrecision() {
return lastValue.getPrecision();
return lastValue.getType().getPrecision();
}
@Override
......@@ -48,12 +48,12 @@ public class Variable extends Expression {
@Override
public int getScale() {
return lastValue.getScale();
return lastValue.getType().getScale();
}
@Override
public int getType() {
return lastValue.getType();
return lastValue.getValueType();
}
@Override
......
......@@ -497,7 +497,7 @@ public class Aggregate extends AbstractAggregate {
String sep = groupConcatSeparator == null ? "," : groupConcatSeparator.getValue(session).getString();
for (Value val : array) {
String s;
if (val.getType() == Value.ARRAY) {
if (val.getValueType() == Value.ARRAY) {
s = ((ValueArray) val).getList()[0].getString();
} else {
s = val.getString();
......
......@@ -43,7 +43,7 @@ class AggregateDataDefault extends AggregateData {
if (value == null) {
value = v.convertTo(dataType);
} else {
v = v.convertTo(value.getType());
v = v.convertTo(value.getValueType());
value = value.add(v);
}
break;
......@@ -51,7 +51,7 @@ class AggregateDataDefault extends AggregateData {
if (value == null) {
value = v.convertTo(DataType.getAddProofType(dataType));
} else {
v = v.convertTo(value.getType());
v = v.convertTo(value.getValueType());
value = value.add(v);
}
break;
......@@ -174,7 +174,7 @@ class AggregateDataDefault extends AggregateData {
if (by == 0) {
return ValueNull.INSTANCE;
}
int type = Value.getHigherOrder(a.getType(), Value.LONG);
int type = Value.getHigherOrder(a.getValueType(), Value.LONG);
Value b = ValueLong.get(by).convertTo(type);
a = a.convertTo(type).divide(b);
return a;
......
......@@ -322,7 +322,7 @@ public final class WindowFrame {
int sortIndex = sortOrder.getQueryColumnIndexes()[0];
Value[] row = orderedRows.get(currentRow);
Value currentValue = row[sortIndex];
int type = currentValue.getType();
int type = currentValue.getValueType();
Value newValue;
Value range = getValueOffset(bound, orderedRows.get(currentRow), session);
switch (type) {
......
......@@ -226,7 +226,7 @@ public class Comparison extends Condition {
}
}
int colType = left.getType();
int constType = r.getType();
int constType = r.getValueType();
int resType = Value.getHigherOrder(colType, constType);
// If not, the column values will need to be promoted
// to constant type, but vise versa, then let's do this here
......
......@@ -77,7 +77,7 @@ public class ConditionInParameter extends Condition {
boolean hasNull = false;
if (value.containsNull()) {
hasNull = true;
} else if (value.getType() == Value.RESULT_SET) {
} else if (value.getValueType() == Value.RESULT_SET) {
for (ResultInterface ri = value.getResult(); ri.next();) {
Value r = ri.currentRow()[0];
Value cmp = Comparison.compare(database, l, r, Comparison.EQUAL);
......
......@@ -76,7 +76,7 @@ public class ConditionInSelect extends Condition {
if (dataType == Value.NULL) {
return ValueBoolean.FALSE;
}
if (l.getType() == Value.ROW) {
if (l.getValueType() == Value.ROW) {
Value[] leftList = ((ValueRow) l).getList();
if (leftList.length != 1) {
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
......@@ -125,7 +125,8 @@ public class ConditionInSelect extends Condition {
private Value compare(Value l, ResultInterface rows) {
Value[] currentRow = rows.currentRow();
Value r = l.getType() != Value.ROW && query.getColumnCount() == 1 ? currentRow[0] : ValueRow.get(currentRow);
Value r = l.getValueType() != Value.ROW && query.getColumnCount() == 1 ? currentRow[0]
: ValueRow.get(currentRow);
return Comparison.compare(database, l, r, compareType);
}
......
......@@ -1099,7 +1099,7 @@ public class Function extends Expression implements FunctionCall {
}
private static Value[] getArray(Value v0) {
int t = v0.getType();
int t = v0.getValueType();
Value[] list;
if (t == Value.ARRAY || t == Value.ROW) {
list = ((ValueCollectionBase) v0).getList();
......@@ -1243,15 +1243,15 @@ public class Function extends Expression implements FunctionCall {
break;
}
case TRUNCATE: {
if (v0.getType() == Value.TIMESTAMP) {
if (v0.getValueType() == Value.TIMESTAMP) {
result = ValueTimestamp.fromDateValueAndNanos(((ValueTimestamp) v0).getDateValue(), 0);
} else if (v0.getType() == Value.DATE) {
} else if (v0.getValueType() == Value.DATE) {
result = ValueTimestamp.fromDateValueAndNanos(((ValueDate) v0).getDateValue(), 0);
} else if (v0.getType() == Value.TIMESTAMP_TZ) {
} else if (v0.getValueType() == Value.TIMESTAMP_TZ) {
ValueTimestampTimeZone ts = (ValueTimestampTimeZone) v0;
result = ValueTimestampTimeZone.fromDateValueAndNanos(ts.getDateValue(), 0,
ts.getTimeZoneOffsetMins());
} else if (v0.getType() == Value.STRING) {
} else if (v0.getValueType() == Value.STRING) {
ValueTimestamp ts = ValueTimestamp.parse(v0.getString(), session.getDatabase().getMode());
result = ValueTimestamp.fromDateValueAndNanos(ts.getDateValue(), 0);
} else {
......@@ -1408,7 +1408,7 @@ public class Function extends Expression implements FunctionCall {
database.getMode().treatEmptyStringsAsNull);
break;
case TO_CHAR:
switch (v0.getType()){
switch (v0.getValueType()){
case Value.TIME:
case Value.DATE:
case Value.TIMESTAMP:
......@@ -1776,12 +1776,12 @@ public class Function extends Expression implements FunctionCall {
}
private static long length(Value v) {
switch (v.getType()) {
switch (v.getValueType()) {
case Value.BLOB:
case Value.CLOB:
case Value.BYTES:
case Value.JAVA_OBJECT:
return v.getPrecision();
return v.getType().getPrecision();
default:
return v.getString().length();
}
......@@ -2057,7 +2057,7 @@ public class Function extends Expression implements FunctionCall {
private static MessageDigest hashImpl(Value value, String algorithm) {
MessageDigest md;
switch (value.getType()) {
switch (value.getValueType()) {
case Value.NULL:
return null;
case Value.STRING:
......
......@@ -105,7 +105,7 @@ public class TableFunction extends Function {
if (v == ValueNull.INSTANCE) {
list[i] = new Value[0];
} else {
int type = v.getType();
int type = v.getValueType();
if (type != Value.ARRAY && type != Value.ROW) {
v = v.convertTo(Value.ARRAY);
}
......
......@@ -44,8 +44,8 @@ public class JdbcBlob extends JdbcLob implements Blob {
try {
debugCodeCall("length");
checkReadable();
if (value.getType() == Value.BLOB) {
long precision = value.getPrecision();
if (value.getValueType() == Value.BLOB) {
long precision = value.getType().getPrecision();
if (precision > 0) {
return precision;
}
......@@ -144,7 +144,7 @@ public class JdbcBlob extends JdbcLob implements Blob {
throw DbException.getInvalidValueException("pos", pos);
}
completeWrite(conn.createBlob(new ByteArrayInputStream(bytes, offset, len), -1));
return (int) value.getPrecision();
return (int) value.getType().getPrecision();
} catch (Exception e) {
throw logAndConvert(e);
}
......
......@@ -44,8 +44,8 @@ public class JdbcClob extends JdbcLob implements NClob {
try {
debugCodeCall("length");
checkReadable();
if (value.getType() == Value.CLOB) {
long precision = value.getPrecision();
if (value.getValueType() == Value.CLOB) {
long precision = value.getType().getPrecision();
if (precision > 0) {
return precision;
}
......@@ -206,7 +206,7 @@ public class JdbcClob extends JdbcLob implements NClob {
throw DbException.getInvalidValueException("str", str);
}
completeWrite(conn.createClob(new RangeReader(new StringReader(str), offset, len), -1));
return (int) value.getPrecision();
return (int) value.getType().getPrecision();
} catch (Exception e) {
throw logAndConvert(e);
}
......
......@@ -2047,7 +2047,7 @@ public class JdbcConnection extends TraceObject
* @return the object
*/
Object convertToDefaultObject(Value v) {
switch (v.getType()) {
switch (v.getValueType()) {
case Value.CLOB: {
int id = getNextId(TraceObject.CLOB);
return new JdbcClob(this, v, JdbcLob.State.WITH_VALUE, id);
......
......@@ -225,7 +225,7 @@ public class FunctionsMySQL extends FunctionsBase {
v1 == null ? fromUnixTime(v0.getInt()) : fromUnixTime(v0.getInt(), v1.getString()));
break;
case DATE:
switch (v0.getType()) {
switch (v0.getValueType()) {
case Value.DATE:
result = v0;
break;
......
......@@ -206,7 +206,7 @@ public class ValueDataType implements DataType {
buff.put((byte) 0);
return;
}
int type = v.getType();
int type = v.getValueType();
switch (type) {
case Value.BOOLEAN:
buff.put((byte) (v.getBoolean() ? BOOLEAN_TRUE : BOOLEAN_FALSE));
......@@ -392,7 +392,7 @@ public class ValueDataType implements DataType {
buff.putVarInt(-3).
putVarInt(lob.getTableId()).
putVarLong(lob.getLobId()).
putVarLong(lob.getPrecision());
putVarLong(lob.getType().getPrecision());
} else {
buff.putVarInt(small.length).
put(small);
......@@ -483,7 +483,7 @@ public class ValueDataType implements DataType {
put(b);
break;
}
DbException.throwInternalError("type=" + v.getType());
DbException.throwInternalError("type=" + v.getValueType());
}
}
......
......@@ -63,7 +63,7 @@ public class RowList implements AutoCloseable {
buff.writeByte((byte) 0);
} else {
buff.writeByte((byte) 1);
if (DataType.isLargeObject(v.getType())) {
if (DataType.isLargeObject(v.getValueType())) {
// need to keep a reference to temporary lobs,
// otherwise the temp file is deleted
if (v.getSmall() == null && v.getTableId() == 0) {
......
......@@ -573,7 +573,7 @@ public class TcpServerThread implements Runnable {
}
private void writeValue(Value v) throws IOException {
if (DataType.isLargeObject(v.getType())) {
if (DataType.isLargeObject(v.getValueType())) {
if (v instanceof ValueLobDb) {
ValueLobDb lob = (ValueLobDb) v;
if (lob.isStored()) {
......
......@@ -423,7 +423,7 @@ public class Data {
data[pos++] = 0;
return;
}
int type = v.getType();
int type = v.getValueType();
switch (type) {
case Value.BOOLEAN:
writeByte((byte) (v.getBoolean() ? BOOLEAN_TRUE : BOOLEAN_FALSE));
......@@ -636,7 +636,7 @@ public class Data {
writeVarInt(t);
writeVarInt(lob.getTableId());
writeVarInt(lob.getObjectId());
writeVarLong(lob.getPrecision());
writeVarLong(lob.getType().getPrecision());
writeByte((byte) (lob.isCompressed() ? 1 : 0));
if (t == -2) {
writeString(lob.getFileName());
......@@ -652,7 +652,7 @@ public class Data {
writeVarInt(-3);
writeVarInt(lob.getTableId());
writeVarLong(lob.getLobId());
writeVarLong(lob.getPrecision());
writeVarLong(lob.getType().getPrecision());
} else {
writeVarInt(small.length);
write(small, 0, small.length);
......@@ -737,7 +737,7 @@ public class Data {
write(b, 0, b.length);
break;
}
DbException.throwInternalError("type=" + v.getType());
DbException.throwInternalError("type=" + v.getValueType());
}
assert pos - start == getValueLen(v)
: "value size error: got " + (pos - start) + " expected " + getValueLen(v);
......@@ -978,7 +978,7 @@ public class Data {
if (v == ValueNull.INSTANCE) {
return 1;
}
switch (v.getType()) {
switch (v.getValueType()) {
case Value.BOOLEAN:
return 1;
case Value.BYTE:
......@@ -1125,7 +1125,7 @@ public class Data {
len += getVarIntLen(t);
len += getVarIntLen(lob.getTableId());
len += getVarIntLen(lob.getObjectId());
len += getVarLongLen(lob.getPrecision());
len += getVarLongLen(lob.getType().getPrecision());
len += 1;
if (t == -2) {
len += getStringLen(lob.getFileName());
......@@ -1141,7 +1141,7 @@ public class Data {
len += getVarIntLen(-3);
len += getVarIntLen(lob.getTableId());
len += getVarLongLen(lob.getLobId());
len += getVarLongLen(lob.getPrecision());
len += getVarLongLen(lob.getType().getPrecision());
} else {
len += getVarIntLen(small.length);
len += small.length;
......@@ -1204,10 +1204,10 @@ public class Data {
default:
if (JdbcUtils.customDataTypesHandler != null) {
byte[] b = v.getBytesNoCopy();
return 1 + getVarIntLen(v.getType())
return 1 + getVarIntLen(v.getValueType())
+ getVarIntLen(b.length) + b.length;
}
throw DbException.throwInternalError("type=" + v.getType());
throw DbException.throwInternalError("type=" + v.getValueType());
}
}
......
......@@ -434,7 +434,7 @@ public class LobStorageBackend implements LobStorageInterface {
@Override
public ValueLobDb copyLob(ValueLobDb old, int tableId, long length) {
int type = old.getType();
int type = old.getValueType();
long oldLobId = old.getLobId();
assertNotHolds(conn.getSession());
// see locking discussion at the top
......
......@@ -245,9 +245,9 @@ public class LobStorageMap implements LobStorageInterface {
@Override
public ValueLobDb copyLob(ValueLobDb old, int tableId, long length) {
init();
int type = old.getType();
int type = old.getValueType();
long oldLobId = old.getLobId();
long oldLength = old.getPrecision();
long oldLength = old.getType().getPrecision();
if (oldLength != length) {
throw DbException.throwInternalError("Length is different");
}
......
......@@ -634,7 +634,7 @@ public class PageLog {
} else {
for (int i = 0; i < columns; i++) {
Value v = row.getValue(i);
if (v.getType() == Value.BYTES) {
if (v.getValueType() == Value.BYTES) {
data.writeValue(ValueNull.INSTANCE);
} else {
data.writeValue(v);
......
......@@ -373,11 +373,12 @@ public class Column {
if (s.length() > 127) {
s = s.substring(0, 128) + "...";
}
throw DbException.get(ErrorCode.VALUE_TOO_LONG_2,
getCreateSQL(), s + " (" + value.getPrecision() + ")");
throw DbException.get(ErrorCode.VALUE_TOO_LONG_2, getCreateSQL(),
s + " (" + value.getType().getPrecision() + ')');
}
}
if (value != ValueNull.INSTANCE && DataType.isExtInfoType(type.getValueType()) && type.getExtTypeInfo() != null) {
if (value != ValueNull.INSTANCE && DataType.isExtInfoType(type.getValueType())
&& type.getExtTypeInfo() != null) {
value = type.getExtTypeInfo().cast(value);
}
updateSequenceIfRequired(session, value);
......
......@@ -423,7 +423,7 @@ public class Recover extends Tool implements DataHandler {
byte[] small = lob.getSmall();
if (small == null) {
String file = lob.getFileName();
String type = lob.getType() == Value.BLOB ? "BLOB" : "CLOB";
String type = lob.getValueType() == Value.BLOB ? "BLOB" : "CLOB";
if (lob.isCompressed()) {
dumpLob(file, true);
file += ".comp";
......@@ -435,9 +435,9 @@ public class Recover extends Tool implements DataHandler {
ValueLobDb lob = (ValueLobDb) v;
byte[] small = lob.getSmall();
if (small == null) {
int type = lob.getType();
int type = lob.getValueType();
long id = lob.getLobId();
long precision = lob.getPrecision();
long precision = lob.getType().getPrecision();
String columnType;
if (type == Value.BLOB) {
columnType = "BLOB";
......
......@@ -429,7 +429,7 @@ public class LocalDateTimeUtils {
if (!(value instanceof ValueInterval)) {
value = value.convertTo(Value.INTERVAL_YEAR_TO_MONTH);
}
if (!DataType.isYearMonthIntervalType(value.getType())) {
if (!DataType.isYearMonthIntervalType(value.getValueType())) {
throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, (Throwable) null, value.getString());
}
ValueInterval v = (ValueInterval) value;
......@@ -460,7 +460,7 @@ public class LocalDateTimeUtils {
if (!(value instanceof ValueInterval)) {
value = value.convertTo(Value.INTERVAL_DAY_TO_SECOND);
}
if (DataType.isYearMonthIntervalType(value.getType())) {
if (DataType.isYearMonthIntervalType(value.getValueType())) {
throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, (Throwable) null, value.getString());
}
BigInteger[] dr = IntervalUtils.intervalToAbsolute((ValueInterval) value)
......
......@@ -70,7 +70,7 @@ public class DataType {
*/
private static final ArrayList<DataType> TYPES = new ArrayList<>(96);
private static final HashMap<String, DataType> TYPES_BY_NAME = new HashMap<>(128);
private static final HashMap<Integer, DataType> TYPES_BY_VALUE_TYPE = new HashMap<>(64);
static final DataType[] TYPES_BY_VALUE_TYPE = new DataType[Value.TYPE_COUNT];
/**
* The value type of this data type.
......@@ -183,8 +183,11 @@ public class DataType {
}
GEOMETRY_CLASS = g;
DataType dataType = new DataType();
dataType.defaultPrecision = dataType.maxPrecision = ValueNull.PRECISION;
dataType.defaultDisplaySize = ValueNull.DISPLAY_SIZE;
add(Value.NULL, Types.NULL,
new DataType(),
dataType,
new String[]{"NULL"},
// the value is always in the cache
0
......@@ -331,6 +334,10 @@ public class DataType {
new String[]{"LONGVARBINARY"},
32
);
dataType = new DataType();
dataType.prefix = dataType.suffix = "'";
dataType.defaultPrecision = dataType.maxPrecision = ValueUuid.PRECISION;
dataType.defaultDisplaySize = ValueUuid.DISPLAY_SIZE;
add(Value.UUID, Types.BINARY,
createString(false),
// UNIQUEIDENTIFIER is the MSSQL mode equivalent
......@@ -361,9 +368,9 @@ public class DataType {
new String[]{"GEOMETRY"},
32
);
DataType dataType = new DataType();
dataType.prefix = "(";
dataType.suffix = "')";
dataType = new DataType();
dataType.prefix = "ARRAY[";
dataType.suffix = "]";
add(Value.ARRAY, Types.ARRAY,
dataType,
new String[]{"ARRAY"},
......@@ -386,9 +393,14 @@ public class DataType {
for (int i = Value.INTERVAL_YEAR; i <= Value.INTERVAL_MINUTE_TO_SECOND; i++) {
addInterval(i);
}
for (Integer i : TYPES_BY_VALUE_TYPE.keySet()) {
Value.getOrder(i);
}
// Row value doesn't have a type name
dataType = new DataType();
dataType.type = Value.ROW;
dataType.name = "ROW";
dataType.sqlType = Types.OTHER;
dataType.prefix = "ROW(";
dataType.suffix = ")";
TYPES_BY_VALUE_TYPE[Value.ROW] = dataType;
}
private static void addDecimal() {
......@@ -466,8 +478,8 @@ public class DataType {
}
}
TYPES_BY_NAME.put(dt.name, dt);
if (TYPES_BY_VALUE_TYPE.get(type) == null) {
TYPES_BY_VALUE_TYPE.put(type, dt);
if (TYPES_BY_VALUE_TYPE[type] == null) {
TYPES_BY_VALUE_TYPE[type] = dt;
}
TYPES.add(dt);
}
......@@ -955,14 +967,19 @@ public class DataType {
if (type == Value.UNKNOWN) {
throw DbException.get(ErrorCode.UNKNOWN_DATA_TYPE_1, "?");
}
DataType dt = TYPES_BY_VALUE_TYPE.get(type);
if (dt == null && JdbcUtils.customDataTypesHandler != null) {
dt = JdbcUtils.customDataTypesHandler.getDataTypeById(type);
if (type >= Value.NULL && type < Value.TYPE_COUNT) {
DataType dt = TYPES_BY_VALUE_TYPE[type];
if (dt != null) {
return dt;
}
}
if (dt == null) {
dt = TYPES_BY_VALUE_TYPE.get(Value.NULL);
if (JdbcUtils.customDataTypesHandler != null) {
DataType dt = JdbcUtils.customDataTypesHandler.getDataTypeById(type);
if (dt != null) {
return dt;
}
}
return dt;
return TYPES_BY_VALUE_TYPE[Value.NULL];
}
/**
......@@ -1598,7 +1615,7 @@ public class DataType {
} else if (paramClass == Array.class) {
return new JdbcArray(conn, v, 0);
}
switch (v.getType()) {
switch (v.getValueType()) {
case Value.JAVA_OBJECT: {
Object o = SysProperties.serializeJavaObject ? JdbcUtils.deserialize(v.getBytes(),
conn.getSession().getDataHandler()) : v.getObject();
......
......@@ -29,13 +29,13 @@ public final class ExtTypeInfoEnum extends ExtTypeInfo {
* if both values do not have enumerators
*/
public static ExtTypeInfoEnum getEnumeratorsForBinaryOperation(Value left, Value right) {
if (left.getType() == Value.ENUM) {
if (left.getValueType() == Value.ENUM) {
return ((ValueEnum) left).getEnumerators();
} else if (right.getType() == Value.ENUM) {
} else if (right.getValueType() == Value.ENUM) {
return ((ValueEnum) right).getEnumerators();
} else {
throw DbException.get(ErrorCode.UNKNOWN_DATA_TYPE_1,
"type1=" + left.getType() + ", type2=" + right.getType());
"type1=" + left.getValueType() + ", type2=" + right.getValueType());
}
}
......@@ -94,7 +94,7 @@ public final class ExtTypeInfoEnum extends ExtTypeInfo {
@Override
public Value cast(Value value) {
switch (value.getType()) {
switch (value.getValueType()) {
case Value.ENUM:
if (value instanceof ValueEnum && ((ValueEnum) value).getEnumerators().equals(this)) {
return value;
......
......@@ -51,7 +51,7 @@ public final class ExtTypeInfoGeometry extends ExtTypeInfo {
@Override
public Value cast(Value value) {
if (value.getType() != Value.GEOMETRY) {
if (value.getValueType() != Value.GEOMETRY) {
value = value.convertTo(Value.GEOMETRY);
}
ValueGeometry g = (ValueGeometry) value;
......
......@@ -321,7 +321,7 @@ public class Transfer {
* @param v the value
*/
public void writeValue(Value v) throws IOException {
int type = v.getType();
int type = v.getValueType();
switch (type) {
case Value.NULL:
writeInt(Value.NULL);
......@@ -425,12 +425,12 @@ public class Transfer {
if (version >= Constants.TCP_PROTOCOL_VERSION_12) {
writeBytes(calculateLobMac(lob.getLobId()));
}
writeLong(lob.getPrecision());
writeLong(lob.getType().getPrecision());
break;
}
}
}
long length = v.getPrecision();
long length = v.getType().getPrecision();
if (length < 0) {
throw DbException.get(
ErrorCode.CONNECTION_BROKEN_1, "length=" + length);
......@@ -456,12 +456,12 @@ public class Transfer {
if (version >= Constants.TCP_PROTOCOL_VERSION_12) {
writeBytes(calculateLobMac(lob.getLobId()));
}
writeLong(lob.getPrecision());
writeLong(lob.getType().getPrecision());
break;
}
}
}
long length = v.getPrecision();
long length = v.getType().getPrecision();
if (length < 0) {
throw DbException.get(
ErrorCode.CONNECTION_BROKEN_1, "length=" + length);
......
......@@ -5,11 +5,112 @@
*/
package org.h2.value;
import org.h2.api.ErrorCode;
import org.h2.message.DbException;
import org.h2.util.JdbcUtils;
/**
* Data type with parameters.
*/
public class TypeInfo {
/**
* NULL type with parameters.
*/
public static final TypeInfo TYPE_NULL;
/**
* BOOLEAN type with parameters.
*/
public static final TypeInfo TYPE_BOOLEAN;
/**
* BYTE type with parameters.
*/
public static final TypeInfo TYPE_BYTE;
/**
* SHORT type with parameters.
*/
public static final TypeInfo TYPE_SHORT;
/**
* INT type with parameters.
*/
public static final TypeInfo TYPE_INT;
/**
* LONG type with parameters.
*/
public static final TypeInfo TYPE_LONG;
/**
* DOUBLE type with parameters.
*/
public static final TypeInfo TYPE_DOUBLE;
/**
* FLOAT type with parameters.
*/
public static final TypeInfo TYPE_FLOAT;
/**
* TIME type with parameters.
*/
public static final TypeInfo TYPE_TIME;
/**
* DATE type with parameters.
*/
public static final TypeInfo TYPE_DATE;
/**
* TIMESTAMP type with parameters.
*/
public static final TypeInfo TYPE_TIMESTAMP;
/**
* ARRAY type with parameters.
*/
public static final TypeInfo TYPE_ARRAY;
/**
* RESULT_SET type with parameters.
*/
public static final TypeInfo TYPE_RESULT_SET;
/**
* JAVA_OBJECT type with parameters.
*/
public static final TypeInfo TYPE_JAVA_OBJECT;
/**
* UUID type with parameters.
*/
public static final TypeInfo TYPE_UUID;
/**
* GEOMETRY type with default parameters.
*/
public static final TypeInfo TYPE_GEOMETRY;
/**
* TIMESTAMP WITH TIME ZONE type with parameters.
*/
public static final TypeInfo TYPE_TIMESTAMP_TZ;
/**
* ENUM type with undefined parameters.
*/
public static final TypeInfo TYPE_ENUM_UNDEFINED;
/**
* ROW (row value) type with parameters.
*/
public static final TypeInfo TYPE_ROW;
private static final TypeInfo[] TYPE_INFOS_BY_VALUE_TYPE;
private final int valueType;
private final long precision;
......@@ -20,6 +121,68 @@ public class TypeInfo {
private final ExtTypeInfo extTypeInfo;
static {
DataType[] type = DataType.TYPES_BY_VALUE_TYPE;
TypeInfo[] infos = new TypeInfo[Value.TYPE_COUNT];
for (int i = 0; i < type.length; i++) {
DataType dt = type[i];
if (dt != null) {
Value.getOrder(i);
infos[i] = createTypeInfo(i, dt);
}
}
TYPE_NULL = infos[Value.NULL];
TYPE_BOOLEAN = infos[Value.BOOLEAN];
TYPE_BYTE = infos[Value.BYTE];
TYPE_SHORT = infos[Value.SHORT];
TYPE_INT = infos[Value.INT];
TYPE_LONG = infos[Value.LONG];
TYPE_DOUBLE = infos[Value.DOUBLE];
TYPE_FLOAT = infos[Value.FLOAT];
TYPE_TIME = infos[Value.TIME];
TYPE_DATE = infos[Value.DATE];
TYPE_TIMESTAMP = infos[Value.TIMESTAMP];
TYPE_ARRAY = infos[Value.ARRAY];
TYPE_RESULT_SET = infos[Value.RESULT_SET];
TYPE_JAVA_OBJECT = infos[Value.JAVA_OBJECT];
TYPE_UUID = infos[Value.UUID];
TYPE_GEOMETRY = infos[Value.GEOMETRY];
TYPE_TIMESTAMP_TZ = infos[Value.TIMESTAMP_TZ];
TYPE_ENUM_UNDEFINED = infos[Value.ENUM];
TYPE_ROW = infos[Value.ROW];
TYPE_INFOS_BY_VALUE_TYPE = infos;
}
/**
* Get the data type with parameters object for the given value type and
* maximum parameters.
*
* @param type the value type
* @return the data type with parameters object
*/
public static TypeInfo getTypeInfo(int type) {
if (type == Value.UNKNOWN) {
throw DbException.get(ErrorCode.UNKNOWN_DATA_TYPE_1, "?");
}
if (type >= Value.NULL && type < Value.TYPE_COUNT) {
TypeInfo t = TypeInfo.TYPE_INFOS_BY_VALUE_TYPE[type];
if (t != null) {
return t;
}
}
if (JdbcUtils.customDataTypesHandler != null) {
DataType dt = JdbcUtils.customDataTypesHandler.getDataTypeById(type);
if (dt != null) {
return createTypeInfo(type, dt);
}
}
return TypeInfo.TYPE_INFOS_BY_VALUE_TYPE[Value.NULL];
}
private static TypeInfo createTypeInfo(int valueType, DataType dataType) {
return new TypeInfo(valueType, dataType.maxPrecision, dataType.maxScale, dataType.defaultDisplaySize, null);
}
/**
* Creates new instance of data type with parameters.
*
......
......@@ -62,8 +62,13 @@ public class ValueArray extends ValueCollectionBase {
}
@Override
public int getType() {
return Value.ARRAY;
public TypeInfo getType() {
return TypeInfo.TYPE_ARRAY;
}
@Override
public int getValueType() {
return ARRAY;
}
public Class<?> getComponentType() {
......@@ -109,7 +114,7 @@ public class ValueArray extends ValueCollectionBase {
for (int i = 0; i < len; i++) {
final Value value = values[i];
if (!SysProperties.OLD_RESULT_SET_GET_OBJECT) {
final int type = value.getType();
final int type = value.getValueType();
if (type == Value.BYTE || type == Value.SHORT) {
list[i] = value.getInt();
continue;
......@@ -189,7 +194,7 @@ public class ValueArray extends ValueCollectionBase {
}
// empty byte arrays or strings have precision 0
// they count as precision 1 here
precision -= Math.max(1, v.getPrecision());
precision -= Math.max(1, v.getType().getPrecision());
if (precision < 0) {
break;
}
......
......@@ -41,8 +41,13 @@ public class ValueBoolean extends Value {
}
@Override
public int getType() {
return Value.BOOLEAN;
public TypeInfo getType() {
return TypeInfo.TYPE_BOOLEAN;
}
@Override
public int getValueType() {
return BOOLEAN;
}
@Override
......@@ -70,11 +75,6 @@ public class ValueBoolean extends Value {
return Boolean.compare(value, ((ValueBoolean) o).value);
}
@Override
public long getPrecision() {
return PRECISION;
}
@Override
public int hashCode() {
return value ? 1 : 0;
......@@ -101,11 +101,6 @@ public class ValueBoolean extends Value {
return b ? TRUE : FALSE;
}
@Override
public int getDisplaySize() {
return DISPLAY_SIZE;
}
@Override
public boolean equals(Object other) {
// there are only ever two instances, so the instance must match
......
......@@ -93,8 +93,13 @@ public class ValueByte extends Value {
}
@Override
public int getType() {
return Value.BYTE;
public TypeInfo getType() {
return TypeInfo.TYPE_BYTE;
}
@Override
public int getValueType() {
return BYTE;
}
@Override
......@@ -117,11 +122,6 @@ public class ValueByte extends Value {
return Integer.toString(value);
}
@Override
public long getPrecision() {
return PRECISION;
}
@Override
public int hashCode() {
return value;
......@@ -148,11 +148,6 @@ public class ValueByte extends Value {
return (ValueByte) Value.cache(new ValueByte(i));
}
@Override
public int getDisplaySize() {
return DISPLAY_SIZE;
}
@Override
public boolean equals(Object other) {
return other instanceof ValueByte && value == ((ValueByte) other).value;
......
......@@ -31,6 +31,8 @@ public class ValueBytes extends Value {
*/
protected byte[] value;
private TypeInfo type;
/**
* The hash code.
*/
......@@ -74,8 +76,18 @@ public class ValueBytes extends Value {
}
@Override
public int getType() {
return Value.BYTES;
public TypeInfo getType() {
TypeInfo type = this.type;
if (type == null) {
long precision = value.length;
this.type = type = new TypeInfo(BYTES, precision, 0, MathUtils.convertLongToInt(precision * 2), null);
}
return type;
}
@Override
public int getValueType() {
return BYTES;
}
@Override
......@@ -108,11 +120,6 @@ public class ValueBytes extends Value {
return StringUtils.convertBytesToHex(value);
}
@Override
public long getPrecision() {
return value.length;
}
@Override
public int hashCode() {
if (hash == 0) {
......@@ -132,11 +139,6 @@ public class ValueBytes extends Value {
prep.setBytes(parameterIndex, value);
}
@Override
public int getDisplaySize() {
return MathUtils.convertLongToInt(value.length * 2L);
}
@Override
public int getMemory() {
return value.length + 24;
......
......@@ -21,6 +21,8 @@ public abstract class ValueCollectionBase extends Value {
*/
final Value[] values;
private TypeInfo type;
private int hash;
ValueCollectionBase(Value[] values) {
......@@ -36,7 +38,7 @@ public abstract class ValueCollectionBase extends Value {
if (hash != 0) {
return hash;
}
int h = getType();
int h = getValueType();
for (Value v : values) {
h = h * 31 + v.hashCode();
}
......@@ -45,21 +47,19 @@ public abstract class ValueCollectionBase extends Value {
}
@Override
public long getPrecision() {
long p = 0;
for (Value v : values) {
p += v.getPrecision();
}
return p;
}
@Override
public int getDisplaySize() {
long size = 0;
for (Value v : values) {
size += v.getDisplaySize();
public TypeInfo getType() {
TypeInfo type = this.type;
if (type == null) {
long precision = 0, displaySize = 0;
for (Value v : values) {
TypeInfo t = v.getType();
precision += t.getPrecision();
displaySize += t.getDisplaySize();
}
this.type = type = new TypeInfo(getValueType(), precision, 0, MathUtils.convertLongToInt(displaySize),
null);
}
return MathUtils.convertLongToInt(size);
return type;
}
@Override
......@@ -68,8 +68,8 @@ public abstract class ValueCollectionBase extends Value {
return Integer.MIN_VALUE;
}
ValueCollectionBase l = this;
int leftType = l.getType();
int rightType = v.getType();
int leftType = l.getValueType();
int rightType = v.getValueType();
if (rightType != ARRAY && rightType != ROW) {
throw v.getDataConversionError(leftType);
}
......
......@@ -87,8 +87,13 @@ public class ValueDate extends Value {
}
@Override
public int getType() {
return Value.DATE;
public TypeInfo getType() {
return TypeInfo.TYPE_DATE;
}
@Override
public int getValueType() {
return DATE;
}
@Override
......@@ -105,16 +110,6 @@ public class ValueDate extends Value {
return builder.append('\'');
}
@Override
public long getPrecision() {
return PRECISION;
}
@Override
public int getDisplaySize() {
return PRECISION;
}
@Override
public int compareTypeSafe(Value o, CompareMode mode) {
return Long.compare(dateValue, ((ValueDate) o).dateValue);
......
......@@ -52,8 +52,8 @@ public class ValueDecimal extends Value {
private static final int BIG_DECIMAL_SCALE_MAX = 100_000;
private final BigDecimal value;
private TypeInfo type;
private String valueString;
private int precision;
private ValueDecimal(BigDecimal value) {
if (value == null) {
......@@ -123,8 +123,20 @@ public class ValueDecimal extends Value {
}
@Override
public int getType() {
return Value.DECIMAL;
public TypeInfo getType() {
TypeInfo type = this.type;
if (type == null) {
long precision = value.precision();
this.type = type = new TypeInfo(DECIMAL, precision, value.scale(),
// add 2 characters for '-' and '.'
MathUtils.convertLongToInt(precision + 2), null);
}
return type;
}
@Override
public int getValueType() {
return DECIMAL;
}
@Override
......@@ -155,25 +167,12 @@ public class ValueDecimal extends Value {
return valueString;
}
@Override
public long getPrecision() {
if (precision == 0) {
precision = value.precision();
}
return precision;
}
@Override
public boolean checkPrecision(long prec) {
if (prec == DEFAULT_PRECISION) {
return true;
}
return getPrecision() <= prec;
}
@Override
public int getScale() {
return value.scale();
return value.precision() <= prec;
}
@Override
......@@ -208,7 +207,7 @@ public class ValueDecimal extends Value {
@Override
public Value convertPrecision(long precision, boolean force) {
if (getPrecision() <= precision) {
if (value.precision() <= precision) {
return this;
}
if (force) {
......@@ -234,12 +233,6 @@ public class ValueDecimal extends Value {
return (ValueDecimal) Value.cache(new ValueDecimal(dec));
}
@Override
public int getDisplaySize() {
// add 2 characters for '-' and '.'
return MathUtils.convertLongToInt(getPrecision() + 2);
}
@Override
public boolean equals(Object other) {
// Two BigDecimal objects are considered equal only if they are equal in
......
......@@ -106,8 +106,13 @@ public class ValueDouble extends Value {
}
@Override
public int getType() {
return Value.DOUBLE;
public TypeInfo getType() {
return TypeInfo.TYPE_DOUBLE;
}
@Override
public int getValueType() {
return DOUBLE;
}
@Override
......@@ -130,16 +135,6 @@ public class ValueDouble extends Value {
return Double.toString(value);
}
@Override
public long getPrecision() {
return PRECISION;
}
@Override
public int getScale() {
return 0;
}
@Override
public int hashCode() {
/*
......@@ -179,11 +174,6 @@ public class ValueDouble extends Value {
return (ValueDouble) Value.cache(new ValueDouble(d));
}
@Override
public int getDisplaySize() {
return DISPLAY_SIZE;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof ValueDouble)) {
......
......@@ -17,6 +17,11 @@ public class ValueEnum extends ValueEnumBase {
this.enumerators = enumerators;
}
@Override
public TypeInfo getType() {
return new TypeInfo(ENUM, PRECISION, 0, DISPLAY_SIZE, enumerators);
}
public ExtTypeInfoEnum getEnumerators() {
return enumerators;
}
......
......@@ -18,8 +18,8 @@ import org.h2.util.StringUtils;
* client-server communication.
*/
public class ValueEnumBase extends Value {
private static final int PRECISION = 10;
private static final int DISPLAY_SIZE = 11;
static final int PRECISION = 10;
static final int DISPLAY_SIZE = 11;
private final String label;
private final int ordinal;
......@@ -63,11 +63,6 @@ public class ValueEnumBase extends Value {
return new ValueEnumBase(label, ordinal);
}
@Override
public int getDisplaySize() {
return DISPLAY_SIZE;
}
@Override
public int getInt() {
return ordinal;
......@@ -83,11 +78,6 @@ public class ValueEnumBase extends Value {
return label;
}
@Override
public long getPrecision() {
return PRECISION;
}
@Override
public int getSignum() {
return Integer.signum(ordinal);
......@@ -104,8 +94,13 @@ public class ValueEnumBase extends Value {
}
@Override
public int getType() {
return Value.ENUM;
public TypeInfo getType() {
return TypeInfo.TYPE_ENUM_UNDEFINED;
}
@Override
public int getValueType() {
return ENUM;
}
@Override
......
......@@ -106,8 +106,13 @@ public class ValueFloat extends Value {
}
@Override
public int getType() {
return Value.FLOAT;
public TypeInfo getType() {
return TypeInfo.TYPE_FLOAT;
}
@Override
public int getValueType() {
return FLOAT;
}
@Override
......@@ -130,16 +135,6 @@ public class ValueFloat extends Value {
return Float.toString(value);
}
@Override
public long getPrecision() {
return PRECISION;
}
@Override
public int getScale() {
return 0;
}
@Override
public int hashCode() {
/*
......@@ -178,11 +173,6 @@ public class ValueFloat extends Value {
return (ValueFloat) Value.cache(new ValueFloat(d));
}
@Override
public int getDisplaySize() {
return DISPLAY_SIZE;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof ValueFloat)) {
......
......@@ -263,8 +263,13 @@ public class ValueGeometry extends Value {
}
@Override
public int getType() {
return Value.GEOMETRY;
public TypeInfo getType() {
return TypeInfo.TYPE_GEOMETRY;
}
@Override
public int getValueType() {
return GEOMETRY;
}
@Override
......@@ -284,11 +289,6 @@ public class ValueGeometry extends Value {
return getEWKT();
}
@Override
public long getPrecision() {
return 0;
}
@Override
public int hashCode() {
return hashCode;
......@@ -317,11 +317,6 @@ public class ValueGeometry extends Value {
prep.setBytes(parameterIndex, bytes);
}
@Override
public int getDisplaySize() {
return getEWKT().length();
}
@Override
public int getMemory() {
return bytes.length * 20 + 24;
......
......@@ -126,8 +126,13 @@ public class ValueInt extends Value {
}
@Override
public int getType() {
return Value.INT;
public TypeInfo getType() {
return TypeInfo.TYPE_INT;
}
@Override
public int getValueType() {
return INT;
}
@Override
......@@ -150,11 +155,6 @@ public class ValueInt extends Value {
return Integer.toString(value);
}
@Override
public long getPrecision() {
return PRECISION;
}
@Override
public int hashCode() {
return value;
......@@ -171,11 +171,6 @@ public class ValueInt extends Value {
prep.setInt(parameterIndex, value);
}
@Override
public int getDisplaySize() {
return DISPLAY_SIZE;
}
@Override
public boolean equals(Object other) {
return other instanceof ValueInt && value == ((ValueInt) other).value;
......
......@@ -44,7 +44,9 @@ public class ValueInterval extends Value {
*/
public static final int MAXIMUM_SCALE = 9;
private final int type;
private final int valueType;
private TypeInfo type;
private final boolean negative;
......@@ -134,7 +136,7 @@ public class ValueInterval extends Value {
}
private ValueInterval(int type, boolean negative, long leading, long remaining) {
this.type = type;
this.valueType = type;
this.negative = negative;
this.leading = leading;
this.remaining = remaining;
......@@ -146,19 +148,27 @@ public class ValueInterval extends Value {
}
@Override
public int getType() {
public TypeInfo getType() {
TypeInfo type = this.type;
if (type == null) {
long l = leading;
int precision = 0;
while (l > 0) {
precision++;
l /= 10;
}
if (precision == 0) {
precision = 1;
}
this.type = type = new TypeInfo(valueType, precision, 0,
getDisplaySize(valueType, MAXIMUM_PRECISION, MAXIMUM_SCALE), null);
}
return type;
}
@Override
public long getPrecision() {
long l = leading;
int precision = 0;
while (l > 0) {
precision++;
l /= 10;
}
return precision > 0 ? precision : 1;
public int getValueType() {
return valueType;
}
@Override
......@@ -178,7 +188,7 @@ public class ValueInterval extends Value {
return this;
}
long l = leading;
switch (type) {
switch (valueType) {
case INTERVAL_SECOND:
if (r >= NANOS_PER_SECOND) {
l++;
......@@ -207,11 +217,6 @@ public class ValueInterval extends Value {
return from(qualifier, negative, l, r);
}
@Override
public int getDisplaySize() {
return getDisplaySize(type, MAXIMUM_PRECISION, MAXIMUM_SCALE);
}
@Override
public String getString() {
return IntervalUtils.appendInterval(new StringBuilder(), getQualifier(), negative, leading, remaining)
......@@ -229,7 +234,7 @@ public class ValueInterval extends Value {
* @return the interval qualifier
*/
public IntervalQualifier getQualifier() {
return IntervalQualifier.valueOf(type - INTERVAL_YEAR);
return IntervalQualifier.valueOf(valueType - INTERVAL_YEAR);
}
/**
......@@ -270,7 +275,7 @@ public class ValueInterval extends Value {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + type;
result = prime * result + valueType;
result = prime * result + (negative ? 1231 : 1237);
result = prime * result + (int) (leading ^ leading >>> 32);
result = prime * result + (int) (remaining ^ remaining >>> 32);
......@@ -286,7 +291,7 @@ public class ValueInterval extends Value {
return false;
}
ValueInterval other = (ValueInterval) obj;
return type == other.type && negative == other.negative && leading == other.leading
return valueType == other.valueType && negative == other.negative && leading == other.leading
&& remaining == other.remaining;
}
......
......@@ -59,8 +59,13 @@ public class ValueJavaObject extends ValueBytes {
}
@Override
public int getType() {
return Value.JAVA_OBJECT;
public TypeInfo getType() {
return TypeInfo.TYPE_JAVA_OBJECT;
}
@Override
public int getValueType() {
return JAVA_OBJECT;
}
@Override
......@@ -80,7 +85,7 @@ public class ValueJavaObject extends ValueBytes {
private Object javaObject;
private int displaySize = -1;
private TypeInfo type;
NotSerialized(Object javaObject, byte[] v, DataHandler dataHandler) {
super(v, dataHandler);
......@@ -139,17 +144,26 @@ public class ValueJavaObject extends ValueBytes {
}
@Override
public String getString() {
String str = getObject().toString();
if (displaySize == -1) {
displaySize = str.length();
public TypeInfo getType() {
TypeInfo type = this.type;
if (type == null) {
String string = getString();
this.type = type = createType(string);
}
return str;
return type;
}
private static TypeInfo createType(String string) {
return new TypeInfo(JAVA_OBJECT, 0, 0, string.length(), null);
}
@Override
public long getPrecision() {
return 0;
public String getString() {
String str = getObject().toString();
if (type == null) {
type = createType(str);
}
return str;
}
@Override
......@@ -168,18 +182,10 @@ public class ValueJavaObject extends ValueBytes {
return javaObject;
}
@Override
public int getDisplaySize() {
if (displaySize == -1) {
displaySize = getString().length();
}
return displaySize;
}
@Override
public int getMemory() {
if (value == null) {
return DataType.getDataType(getType()).memory;
return DataType.getDataType(getValueType()).memory;
}
int mem = super.getMemory();
if (javaObject != null) {
......
......@@ -98,8 +98,8 @@ public class ValueLob extends Value {
* @return result of comparison
*/
static int compare(Value v1, Value v2) {
int valueType = v1.getType();
assert valueType == v2.getType();
int valueType = v1.getValueType();
assert valueType == v2.getValueType();
if (v1 instanceof ValueLobDb && v2 instanceof ValueLobDb) {
byte[] small1 = v1.getSmall(), small2 = v2.getSmall();
if (small1 != null && small2 != null) {
......@@ -110,7 +110,7 @@ public class ValueLob extends Value {
}
}
}
long minPrec = Math.min(v1.getPrecision(), v2.getPrecision());
long minPrec = Math.min(v1.getType().getPrecision(), v2.getType().getPrecision());
if (valueType == Value.BLOB) {
try (InputStream is1 = v1.getInputStream();
InputStream is2 = v2.getInputStream()) {
......@@ -184,6 +184,7 @@ public class ValueLob extends Value {
* either Value.BLOB or Value.CLOB
*/
private final int valueType;
private TypeInfo type;
private final long precision;
private final DataHandler handler;
private int tableId;
......@@ -448,13 +449,17 @@ public class ValueLob extends Value {
}
@Override
public int getType() {
return valueType;
public TypeInfo getType() {
TypeInfo type = this.type;
if (type == null) {
this.type = type = new TypeInfo(valueType, precision, 0, MathUtils.convertLongToInt(precision), null);
}
return type;
}
@Override
public long getPrecision() {
return precision;
public int getValueType() {
return valueType;
}
@Override
......@@ -558,7 +563,7 @@ public class ValueLob extends Value {
@Override
public void set(PreparedStatement prep, int parameterIndex)
throws SQLException {
long p = getPrecision();
long p = precision;
if (p > Integer.MAX_VALUE || p <= 0) {
p = -1;
}
......@@ -584,9 +589,9 @@ public class ValueLob extends Value {
public String getTraceSQL() {
StringBuilder buff = new StringBuilder();
if (valueType == Value.CLOB) {
buff.append("SPACE(").append(getPrecision());
buff.append("SPACE(").append(precision);
} else {
buff.append("CAST(REPEAT('00', ").append(getPrecision()).append(") AS BINARY");
buff.append("CAST(REPEAT('00', ").append(precision).append(") AS BINARY");
}
buff.append(" /* ").append(fileName).append(" */)");
return buff.toString();
......@@ -602,11 +607,6 @@ public class ValueLob extends Value {
return null;
}
@Override
public int getDisplaySize() {
return MathUtils.convertLongToInt(getPrecision());
}
@Override
public boolean equals(Object other) {
if (other instanceof ValueLob) {
......
......@@ -43,6 +43,8 @@ public class ValueLobDb extends Value {
* the value type (Value.BLOB or CLOB)
*/
private final int valueType;
private TypeInfo type;
/**
* If the LOB is managed by the one the LobStorageBackend classes, these are the
* unique key inside that storage.
......@@ -261,14 +263,14 @@ public class ValueLobDb extends Value {
@Override
public Value copy(DataHandler database, int tableId) {
if (small == null) {
return handler.getLobStorage().copyLob(this, tableId, getPrecision());
return handler.getLobStorage().copyLob(this, tableId, precision);
} else if (small.length > database.getMaxLengthInplaceLob()) {
LobStorageInterface s = database.getLobStorage();
Value v;
if (valueType == Value.BLOB) {
v = s.createBlob(getInputStream(), getPrecision());
v = s.createBlob(getInputStream(), precision);
} else {
v = s.createClob(getReader(), getPrecision());
v = s.createClob(getReader(), precision);
}
Value v2 = v.copy(database, tableId);
v.remove();
......@@ -288,13 +290,17 @@ public class ValueLobDb extends Value {
}
@Override
public int getType() {
return valueType;
public TypeInfo getType() {
TypeInfo type = this.type;
if (type == null) {
this.type = type = new TypeInfo(valueType, precision, 0, MathUtils.convertLongToInt(precision), null);
}
return type;
}
@Override
public long getPrecision() {
return precision;
public int getValueType() {
return valueType;
}
@Override
......@@ -449,7 +455,7 @@ public class ValueLobDb extends Value {
@Override
public void set(PreparedStatement prep, int parameterIndex)
throws SQLException {
long p = getPrecision();
long p = precision;
if (p > Integer.MAX_VALUE || p <= 0) {
p = -1;
}
......@@ -473,14 +479,14 @@ public class ValueLobDb extends Value {
@Override
public String getTraceSQL() {
if (small != null && getPrecision() <= SysProperties.MAX_TRACE_DATA_LENGTH) {
if (small != null && precision <= SysProperties.MAX_TRACE_DATA_LENGTH) {
return getSQL();
}
StringBuilder buff = new StringBuilder();
if (valueType == Value.CLOB) {
buff.append("SPACE(").append(getPrecision());
buff.append("SPACE(").append(precision);
} else {
buff.append("CAST(REPEAT('00', ").append(getPrecision()).append(") AS BINARY");
buff.append("CAST(REPEAT('00', ").append(precision).append(") AS BINARY");
}
buff.append(" /* table: ").append(tableId).append(" id: ")
.append(lobId).append(" */)");
......@@ -497,11 +503,6 @@ public class ValueLobDb extends Value {
return small;
}
@Override
public int getDisplaySize() {
return MathUtils.convertLongToInt(getPrecision());
}
@Override
public boolean equals(Object other) {
if (!(other instanceof ValueLobDb))
......@@ -546,8 +547,7 @@ public class ValueLobDb extends Value {
if (s.isReadOnly()) {
return this;
}
return s.copyLob(this, LobStorageFrontend.TABLE_RESULT,
getPrecision());
return s.copyLob(this, LobStorageFrontend.TABLE_RESULT, precision);
}
public long getLobId() {
......
......@@ -151,8 +151,13 @@ public class ValueLong extends Value {
}
@Override
public int getType() {
return Value.LONG;
public TypeInfo getType() {
return TypeInfo.TYPE_LONG;
}
@Override
public int getValueType() {
return LONG;
}
@Override
......@@ -170,11 +175,6 @@ public class ValueLong extends Value {
return Long.toString(value);
}
@Override
public long getPrecision() {
return PRECISION;
}
@Override
public int hashCode() {
return (int) (value ^ (value >> 32));
......@@ -204,11 +204,6 @@ public class ValueLong extends Value {
return (ValueLong) Value.cache(new ValueLong(i));
}
@Override
public int getDisplaySize() {
return DISPLAY_SIZE;
}
@Override
public boolean equals(Object other) {
return other instanceof ValueLong && value == ((ValueLong) other).value;
......
......@@ -37,12 +37,12 @@ public class ValueNull extends Value {
/**
* The precision of NULL.
*/
private static final int PRECISION = 1;
static final int PRECISION = 1;
/**
* The display size of the textual representation of NULL.
*/
private static final int DISPLAY_SIZE = 4;
static final int DISPLAY_SIZE = 4;
private ValueNull() {
// don't allow construction
......@@ -54,8 +54,13 @@ public class ValueNull extends Value {
}
@Override
public int getType() {
return Value.NULL;
public TypeInfo getType() {
return TypeInfo.TYPE_NULL;
}
@Override
public int getValueType() {
return NULL;
}
@Override
......@@ -148,11 +153,6 @@ public class ValueNull extends Value {
return true;
}
@Override
public long getPrecision() {
return PRECISION;
}
@Override
public int hashCode() {
return 0;
......@@ -169,11 +169,6 @@ public class ValueNull extends Value {
prep.setNull(parameterIndex, Types.NULL);
}
@Override
public int getDisplaySize() {
return DISPLAY_SIZE;
}
@Override
public boolean equals(Object other) {
return other == this;
......
......@@ -98,19 +98,13 @@ public class ValueResultSet extends Value {
}
@Override
public int getType() {
return Value.RESULT_SET;
public TypeInfo getType() {
return TypeInfo.TYPE_RESULT_SET;
}
@Override
public long getPrecision() {
return Integer.MAX_VALUE;
}
@Override
public int getDisplaySize() {
// it doesn't make sense to calculate it
return Integer.MAX_VALUE;
public int getValueType() {
return RESULT_SET;
}
@Override
......
......@@ -48,8 +48,13 @@ public class ValueRow extends ValueCollectionBase {
}
@Override
public int getType() {
return Value.ROW;
public TypeInfo getType() {
return TypeInfo.TYPE_ROW;
}
@Override
public int getValueType() {
return ROW;
}
@Override
......@@ -92,7 +97,7 @@ public class ValueRow extends ValueCollectionBase {
for (int i = 0; i < len; i++) {
final Value value = values[i];
if (!SysProperties.OLD_RESULT_SET_GET_OBJECT) {
final int type = value.getType();
final int type = value.getValueType();
if (type == Value.BYTE || type == Value.SHORT) {
list[i] = value.getInt();
continue;
......@@ -172,7 +177,7 @@ public class ValueRow extends ValueCollectionBase {
}
// empty byte arrays or strings have precision 0
// they count as precision 1 here
precision -= Math.max(1, v.getPrecision());
precision -= Math.max(1, v.getType().getPrecision());
if (precision < 0) {
break;
}
......
......@@ -93,8 +93,13 @@ public class ValueShort extends Value {
}
@Override
public int getType() {
return Value.SHORT;
public TypeInfo getType() {
return TypeInfo.TYPE_SHORT;
}
@Override
public int getValueType() {
return SHORT;
}
@Override
......@@ -117,11 +122,6 @@ public class ValueShort extends Value {
return Integer.toString(value);
}
@Override
public long getPrecision() {
return PRECISION;
}
@Override
public int hashCode() {
return value;
......@@ -148,11 +148,6 @@ public class ValueShort extends Value {
return (ValueShort) Value.cache(new ValueShort(i));
}
@Override
public int getDisplaySize() {
return DISPLAY_SIZE;
}
@Override
public boolean equals(Object other) {
return other instanceof ValueShort && value == ((ValueShort) other).value;
......
......@@ -29,6 +29,8 @@ public class ValueString extends Value {
*/
protected final String value;
private TypeInfo type;
protected ValueString(String value) {
this.value = value;
}
......@@ -54,11 +56,6 @@ public class ValueString extends Value {
return value;
}
@Override
public long getPrecision() {
return value.length();
}
@Override
public Object getObject() {
return value;
......@@ -70,11 +67,6 @@ public class ValueString extends Value {
prep.setString(parameterIndex, value);
}
@Override
public int getDisplaySize() {
return value.length();
}
@Override
public int getMemory() {
return value.length() * 2 + 48;
......@@ -122,8 +114,18 @@ public class ValueString extends Value {
}
@Override
public int getType() {
return Value.STRING;
public final TypeInfo getType() {
TypeInfo type = this.type;
if (type == null) {
int length = value.length();
this.type = type = new TypeInfo(getValueType(), length, 0, length, null);
}
return type;
}
@Override
public int getValueType() {
return STRING;
}
/**
......
......@@ -58,8 +58,8 @@ public class ValueStringFixed extends ValueString {
}
@Override
public int getType() {
return Value.STRING_FIXED;
public int getValueType() {
return STRING_FIXED;
}
/**
......
......@@ -22,8 +22,8 @@ public class ValueStringIgnoreCase extends ValueString {
}
@Override
public int getType() {
return Value.STRING_IGNORECASE;
public int getValueType() {
return STRING_IGNORECASE;
}
@Override
......
......@@ -127,8 +127,13 @@ public class ValueTime extends Value {
}
@Override
public int getType() {
return Value.TIME;
public TypeInfo getType() {
return TypeInfo.TYPE_TIME;
}
@Override
public int getValueType() {
return TIME;
}
@Override
......@@ -145,16 +150,6 @@ public class ValueTime extends Value {
return builder.append('\'');
}
@Override
public long getPrecision() {
return MAXIMUM_PRECISION;
}
@Override
public int getDisplaySize() {
return MAXIMUM_PRECISION;
}
@Override
public boolean checkPrecision(long precision) {
// TIME data type does not have precision parameter
......
......@@ -177,8 +177,13 @@ public class ValueTimestamp extends Value {
}
@Override
public int getType() {
return Value.TIMESTAMP;
public TypeInfo getType() {
return TypeInfo.TYPE_TIMESTAMP;
}
@Override
public int getValueType() {
return TIMESTAMP;
}
@Override
......@@ -199,21 +204,6 @@ public class ValueTimestamp extends Value {
return builder.append('\'');
}
@Override
public long getPrecision() {
return MAXIMUM_PRECISION;
}
@Override
public int getScale() {
return MAXIMUM_SCALE;
}
@Override
public int getDisplaySize() {
return MAXIMUM_PRECISION;
}
@Override
public boolean checkPrecision(long precision) {
// TIMESTAMP data type does not have precision parameter
......
......@@ -169,8 +169,13 @@ public class ValueTimestampTimeZone extends Value {
}
@Override
public int getType() {
return Value.TIMESTAMP_TZ;
public TypeInfo getType() {
return TypeInfo.TYPE_TIMESTAMP_TZ;
}
@Override
public int getValueType() {
return TIMESTAMP_TZ;
}
@Override
......@@ -187,21 +192,6 @@ public class ValueTimestampTimeZone extends Value {
return builder.append('\'');
}
@Override
public long getPrecision() {
return MAXIMUM_PRECISION;
}
@Override
public int getScale() {
return MAXIMUM_SCALE;
}
@Override
public int getDisplaySize() {
return MAXIMUM_PRECISION;
}
@Override
public boolean checkPrecision(long precision) {
// TIMESTAMP WITH TIME ZONE data type does not have precision parameter
......
......@@ -23,13 +23,13 @@ public class ValueUuid extends Value {
/**
* The precision of this value in number of bytes.
*/
private static final int PRECISION = 16;
static final int PRECISION = 16;
/**
* The display size of the textual representation of a UUID.
* Example: cd38d882-7ada-4589-b5fb-7da0ca559d9a
*/
private static final int DISPLAY_SIZE = 36;
static final int DISPLAY_SIZE = 36;
private final long high, low;
......@@ -132,13 +132,13 @@ public class ValueUuid extends Value {
}
@Override
public int getType() {
return Value.UUID;
public TypeInfo getType() {
return TypeInfo.TYPE_UUID;
}
@Override
public long getPrecision() {
return PRECISION;
public int getValueType() {
return UUID;
}
@Override
......@@ -220,9 +220,4 @@ public class ValueUuid extends Value {
return low;
}
@Override
public int getDisplaySize() {
return DISPLAY_SIZE;
}
}
......@@ -26,6 +26,7 @@ import org.h2.util.StringUtils;
import org.h2.value.CompareMode;
import org.h2.value.DataType;
import org.h2.value.ExtTypeInfo;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
import org.h2.value.ValueBytes;
import org.h2.value.ValueDouble;
......@@ -221,11 +222,11 @@ public class TestCustomDataTypesHandler extends TestDb {
@Override
public Value convert(Value source, int targetType) {
if (source.getType() == targetType) {
if (source.getValueType() == targetType) {
return source;
}
if (targetType == COMPLEX_DATA_TYPE_ID) {
switch (source.getType()) {
switch (source.getValueType()) {
case Value.JAVA_OBJECT: {
assert source instanceof ValueJavaObject;
return ValueComplex.get((ComplexNumber)
......@@ -275,13 +276,13 @@ public class TestCustomDataTypesHandler extends TestDb {
@Override
public Object getObject(Value value, Class<?> cls) {
if (cls.equals(ComplexNumber.class)) {
if (value.getType() == COMPLEX_DATA_TYPE_ID) {
if (value.getValueType() == COMPLEX_DATA_TYPE_ID) {
return value.getObject();
}
return convert(value, COMPLEX_DATA_TYPE_ID).getObject();
}
throw DbException.get(
ErrorCode.UNKNOWN_DATA_TYPE_1, "type:" + value.getType());
ErrorCode.UNKNOWN_DATA_TYPE_1, "type:" + value.getValueType());
}
@Override
......@@ -342,18 +343,13 @@ public class TestCustomDataTypesHandler extends TestDb {
}
@Override
public int getType() {
return TestOnlyCustomDataTypesHandler.COMPLEX_DATA_TYPE_ID;
public TypeInfo getType() {
return TypeInfo.getTypeInfo(TestOnlyCustomDataTypesHandler.COMPLEX_DATA_TYPE_ID);
}
@Override
public long getPrecision() {
return 0;
}
@Override
public int getDisplaySize() {
return 0;
public int getValueType() {
return TestOnlyCustomDataTypesHandler.COMPLEX_DATA_TYPE_ID;
}
@Override
......@@ -396,7 +392,7 @@ public class TestCustomDataTypesHandler extends TestDb {
@Override
public Value convertTo(int targetType, int precision, Mode mode, Object column, ExtTypeInfo extTypeInfo) {
if (getType() == targetType) {
if (getValueType() == targetType) {
return this;
}
switch (targetType) {
......
......@@ -218,7 +218,7 @@ public class TestDataPage extends TestBase implements DataHandler {
private void testValue(Value v) {
testValue(v, false);
switch (v.getType()) {
switch (v.getValueType()) {
case Value.DATE:
case Value.TIME:
case Value.TIMESTAMP:
......@@ -228,12 +228,12 @@ public class TestDataPage extends TestBase implements DataHandler {
private void testValue(Value v, boolean storeLocalTime) {
Data data = Data.create(null, 1024, storeLocalTime);
data.checkCapacity((int) v.getPrecision());
data.checkCapacity((int) v.getType().getPrecision());
data.writeValue(v);
data.writeInt(123);
data.reset();
Value v2 = data.readValue();
assertEquals(v.getType(), v2.getType());
assertEquals(v.getValueType(), v2.getValueType());
assertEquals(0, v.compareTo(v2, null, compareMode));
assertEquals(123, data.readInt());
}
......
......@@ -19,6 +19,7 @@ import org.h2.message.DbException;
import org.h2.test.TestBase;
import org.h2.test.utils.AssertThrows;
import org.h2.util.DateTimeUtils;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
import org.h2.value.ValueDate;
import org.h2.value.ValueDouble;
......@@ -71,11 +72,12 @@ public class TestDate extends TestBase {
assertEquals("2001-01-01", d1.getDate().toString());
assertEquals("DATE '2001-01-01'", d1.getSQL());
assertEquals("DATE '2001-01-01'", d1.toString());
assertEquals(Value.DATE, d1.getType());
assertEquals(Value.DATE, d1.getValueType());
long dv = d1.getDateValue();
assertEquals((int) ((dv >>> 32) ^ dv), d1.hashCode());
assertEquals(d1.getString().length(), d1.getDisplaySize());
assertEquals(ValueDate.PRECISION, d1.getPrecision());
TypeInfo type = d1.getType();
assertEquals(d1.getString().length(), type.getDisplaySize());
assertEquals(ValueDate.PRECISION, type.getPrecision());
assertEquals("java.sql.Date", d1.getObject().getClass().getName());
ValueDate d1b = ValueDate.parse("2001-01-01");
assertTrue(d1 == d1b);
......@@ -136,12 +138,13 @@ public class TestDate extends TestBase {
assertEquals("TIME '11:11:11'", t1.toString());
assertEquals("05:35:35.5", t1.multiply(ValueDouble.get(0.5)).getString());
assertEquals("22:22:22", t1.divide(ValueDouble.get(0.5)).getString());
assertEquals(Value.TIME, t1.getType());
assertEquals(Value.TIME, t1.getValueType());
long nanos = t1.getNanos();
assertEquals((int) ((nanos >>> 32) ^ nanos), t1.hashCode());
// Literals return maximum precision
assertEquals(ValueTime.MAXIMUM_PRECISION, t1.getDisplaySize());
assertEquals(ValueTime.MAXIMUM_PRECISION, t1.getPrecision());
TypeInfo type = t1.getType();
assertEquals(ValueTime.MAXIMUM_PRECISION, type.getDisplaySize());
assertEquals(ValueTime.MAXIMUM_PRECISION, type.getPrecision());
assertEquals("java.sql.Time", t1.getObject().getClass().getName());
ValueTime t1b = ValueTime.parse("11:11:11");
assertTrue(t1 == t1b);
......@@ -210,16 +213,17 @@ public class TestDate extends TestBase {
assertEquals("01:01:01", t1.getTime().toString());
assertEquals("TIMESTAMP '2001-01-01 01:01:01.111'", t1.getSQL());
assertEquals("TIMESTAMP '2001-01-01 01:01:01.111'", t1.toString());
assertEquals(Value.TIMESTAMP, t1.getType());
assertEquals(Value.TIMESTAMP, t1.getValueType());
long dateValue = t1.getDateValue();
long nanos = t1.getTimeNanos();
assertEquals((int) ((dateValue >>> 32) ^ dateValue ^
(nanos >>> 32) ^ nanos),
t1.hashCode());
// Literals return maximum precision
assertEquals(ValueTimestamp.MAXIMUM_PRECISION, t1.getDisplaySize());
assertEquals(ValueTimestamp.MAXIMUM_PRECISION, t1.getPrecision());
assertEquals(9, t1.getScale());
TypeInfo type = t1.getType();
assertEquals(ValueTimestamp.MAXIMUM_PRECISION, type.getDisplaySize());
assertEquals(ValueTimestamp.MAXIMUM_PRECISION, type.getPrecision());
assertEquals(9, type.getScale());
assertEquals("java.sql.Timestamp", t1.getObject().getClass().getName());
ValueTimestamp t1b = ValueTimestamp.parse("2001-01-01 01:01:01.111");
assertTrue(t1 == t1b);
......
......@@ -131,7 +131,7 @@ public class TestValue extends TestDb {
rs.next();
Value v = DataType.readValue(null, rs, 1, valueType);
Value v2 = DataType.convertToValue(null, obj, valueType);
if (v.getType() == Value.RESULT_SET) {
if (v.getValueType() == Value.RESULT_SET) {
assertEquals(v.toString(), v2.toString());
} else {
assertTrue(v.equals(v2));
......@@ -166,21 +166,21 @@ public class TestValue extends TestDb {
v = ValueArray.get(new Value[] { ValueString.get("hello"),
ValueString.get("world") });
assertEquals(10, v.getPrecision());
assertEquals(5, v.convertPrecision(5, true).getPrecision());
assertEquals(10, v.getType().getPrecision());
assertEquals(5, v.convertPrecision(5, true).getType().getPrecision());
v = ValueArray.get(new Value[]{ValueString.get(""), ValueString.get("")});
assertEquals(0, v.getPrecision());
assertEquals(0, v.getType().getPrecision());
assertEquals("['']", v.convertPrecision(1, true).toString());
v = ValueBytes.get(spaces.getBytes());
assertEquals(100, v.getPrecision());
assertEquals(10, v.convertPrecision(10, false).getPrecision());
assertEquals(100, v.getType().getPrecision());
assertEquals(10, v.convertPrecision(10, false).getType().getPrecision());
assertEquals(10, v.convertPrecision(10, false).getBytes().length);
assertEquals(32, v.convertPrecision(10, false).getBytes()[9]);
assertEquals(10, v.convertPrecision(10, true).getPrecision());
assertEquals(10, v.convertPrecision(10, true).getType().getPrecision());
final Value vd = ValueDecimal.get(new BigDecimal("1234567890.123456789"));
assertEquals(19, vd.getPrecision());
assertEquals(19, vd.getType().getPrecision());
assertEquals("1234567890.1234567", vd.convertPrecision(10, true).getString());
new AssertThrows(ErrorCode.NUMERIC_VALUE_OUT_OF_RANGE_1) {
@Override
......@@ -190,32 +190,32 @@ public class TestValue extends TestDb {
};
v = ValueLobDb.createSmallLob(Value.CLOB, spaces.getBytes(), 100);
assertEquals(100, v.getPrecision());
assertEquals(10, v.convertPrecision(10, false).getPrecision());
assertEquals(100, v.getType().getPrecision());
assertEquals(10, v.convertPrecision(10, false).getType().getPrecision());
assertEquals(10, v.convertPrecision(10, false).getString().length());
assertEquals(" ", v.convertPrecision(10, false).getString());
assertEquals(10, v.convertPrecision(10, true).getPrecision());
assertEquals(10, v.convertPrecision(10, true).getType().getPrecision());
v = ValueLobDb.createSmallLob(Value.BLOB, spaces.getBytes(), 100);
assertEquals(100, v.getPrecision());
assertEquals(10, v.convertPrecision(10, false).getPrecision());
assertEquals(100, v.getType().getPrecision());
assertEquals(10, v.convertPrecision(10, false).getType().getPrecision());
assertEquals(10, v.convertPrecision(10, false).getBytes().length);
assertEquals(32, v.convertPrecision(10, false).getBytes()[9]);
assertEquals(10, v.convertPrecision(10, true).getPrecision());
assertEquals(10, v.convertPrecision(10, true).getType().getPrecision());
SimpleResult rs = new SimpleResult();
rs.addColumn("X", "X", Value.INT, 0, 0, ValueInt.DISPLAY_SIZE);
rs.addRow(ValueInt.get(1));
v = ValueResultSet.get(rs);
assertEquals(Integer.MAX_VALUE, v.getPrecision());
assertEquals(Integer.MAX_VALUE, v.convertPrecision(10, false).getPrecision());
assertEquals(Integer.MAX_VALUE, v.getType().getPrecision());
assertEquals(Integer.MAX_VALUE, v.convertPrecision(10, false).getType().getPrecision());
assertEquals(1, v.convertPrecision(10, false).getResult().getRowCount());
assertEquals(0, v.convertPrecision(10, true).getResult().getRowCount());
assertEquals(Integer.MAX_VALUE, v.convertPrecision(10, true).getPrecision());
assertEquals(Integer.MAX_VALUE, v.convertPrecision(10, true).getType().getPrecision());
v = ValueString.get(spaces);
assertEquals(100, v.getPrecision());
assertEquals(10, v.convertPrecision(10, false).getPrecision());
assertEquals(100, v.getType().getPrecision());
assertEquals(10, v.convertPrecision(10, false).getType().getPrecision());
assertEquals(" ", v.convertPrecision(10, false).getString());
assertEquals(" ", v.convertPrecision(10, true).getString());
......@@ -367,7 +367,7 @@ public class TestValue extends TestDb {
private void testArray() {
ValueArray src = ValueArray.get(String.class,
new Value[] {ValueString.get("1"), ValueString.get("22"), ValueString.get("333")});
assertEquals(6, src.getPrecision());
assertEquals(6, src.getType().getPrecision());
assertSame(src, src.convertPrecision(5, false));
assertSame(src, src.convertPrecision(6, true));
ValueArray exp = ValueArray.get(String.class,
......
......@@ -90,7 +90,7 @@ public class TestValueMemory extends TestBase implements DataHandler {
continue;
}
Value v = create(i);
String s = "type: " + v.getType() +
String s = "type: " + v.getValueType() +
" calculated: " + v.getMemory() +
" real: " + MemoryFootprint.getObjectSize(v) + " " +
v.getClass().getName() + ": " + v.toString();
......@@ -111,7 +111,7 @@ public class TestValueMemory extends TestBase implements DataHandler {
// jts not in the classpath, OK
continue;
}
assertEquals(i, v.getType());
assertEquals(i, v.getValueType());
testType(i);
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论