提交 56fe701d authored 作者: Thomas Mueller's avatar Thomas Mueller

A persistent multi-version map: rename built-in data type classes

上级 0d1713bb
...@@ -16,11 +16,11 @@ import org.h2.mvstore.type.DataType; ...@@ -16,11 +16,11 @@ import org.h2.mvstore.type.DataType;
* can have a minimum and a maximum value of type float. For each dimension, the * can have a minimum and a maximum value of type float. For each dimension, the
* maximum value is only stored when it is not the same as the minimum. * maximum value is only stored when it is not the same as the minimum.
*/ */
public class SpatialType implements DataType { public class SpatialDataType implements DataType {
private final int dimensions; private final int dimensions;
public SpatialType(int dimensions) { public SpatialDataType(int dimensions) {
if (dimensions <= 0 || dimensions > 255) { if (dimensions <= 0 || dimensions > 255) {
throw new IllegalArgumentException("Dimensions: " + dimensions); throw new IllegalArgumentException("Dimensions: " + dimensions);
} }
...@@ -33,8 +33,8 @@ public class SpatialType implements DataType { ...@@ -33,8 +33,8 @@ public class SpatialType implements DataType {
* @param s the string * @param s the string
* @return the value * @return the value
*/ */
public static SpatialType fromString(String s) { public static SpatialDataType fromString(String s) {
return new SpatialType(Integer.parseInt(s.substring(1))); return new SpatialDataType(Integer.parseInt(s.substring(1)));
} }
@Override @Override
......
...@@ -17,7 +17,7 @@ import org.h2.util.Utils; ...@@ -17,7 +17,7 @@ import org.h2.util.Utils;
* A data type implementation for the most common data types, including * A data type implementation for the most common data types, including
* serializable objects. * serializable objects.
*/ */
public class ObjectType implements DataType { public class ObjectDataType implements DataType {
// TODO maybe support InputStream, Reader // TODO maybe support InputStream, Reader
// TODO maybe support ResultSet, Date, Time, Timestamp // TODO maybe support ResultSet, Date, Time, Timestamp
...@@ -341,10 +341,10 @@ public class ObjectType implements DataType { ...@@ -341,10 +341,10 @@ public class ObjectType implements DataType {
*/ */
abstract class AutoDetectDataType implements DataType { abstract class AutoDetectDataType implements DataType {
protected final ObjectType base; protected final ObjectDataType base;
protected final int typeId; protected final int typeId;
AutoDetectDataType(ObjectType base, int typeId) { AutoDetectDataType(ObjectDataType base, int typeId) {
this.base = base; this.base = base;
this.typeId = typeId; this.typeId = typeId;
} }
...@@ -411,7 +411,7 @@ public class ObjectType implements DataType { ...@@ -411,7 +411,7 @@ public class ObjectType implements DataType {
*/ */
class BooleanType extends AutoDetectDataType { class BooleanType extends AutoDetectDataType {
BooleanType(ObjectType base) { BooleanType(ObjectDataType base) {
super(base, TYPE_BOOLEAN); super(base, TYPE_BOOLEAN);
} }
...@@ -457,7 +457,7 @@ public class ObjectType implements DataType { ...@@ -457,7 +457,7 @@ public class ObjectType implements DataType {
*/ */
class ByteType extends AutoDetectDataType { class ByteType extends AutoDetectDataType {
ByteType(ObjectType base) { ByteType(ObjectDataType base) {
super(base, TYPE_BYTE); super(base, TYPE_BYTE);
} }
...@@ -502,7 +502,7 @@ public class ObjectType implements DataType { ...@@ -502,7 +502,7 @@ public class ObjectType implements DataType {
*/ */
class CharacterType extends AutoDetectDataType { class CharacterType extends AutoDetectDataType {
CharacterType(ObjectType base) { CharacterType(ObjectDataType base) {
super(base, TYPE_CHARACTER); super(base, TYPE_CHARACTER);
} }
...@@ -548,7 +548,7 @@ public class ObjectType implements DataType { ...@@ -548,7 +548,7 @@ public class ObjectType implements DataType {
*/ */
class ShortType extends AutoDetectDataType { class ShortType extends AutoDetectDataType {
ShortType(ObjectType base) { ShortType(ObjectDataType base) {
super(base, TYPE_SHORT); super(base, TYPE_SHORT);
} }
...@@ -594,7 +594,7 @@ public class ObjectType implements DataType { ...@@ -594,7 +594,7 @@ public class ObjectType implements DataType {
*/ */
class IntegerType extends AutoDetectDataType { class IntegerType extends AutoDetectDataType {
IntegerType(ObjectType base) { IntegerType(ObjectDataType base) {
super(base, TYPE_INTEGER); super(base, TYPE_INTEGER);
} }
...@@ -667,7 +667,7 @@ public class ObjectType implements DataType { ...@@ -667,7 +667,7 @@ public class ObjectType implements DataType {
*/ */
public class LongType extends AutoDetectDataType { public class LongType extends AutoDetectDataType {
LongType(ObjectType base) { LongType(ObjectDataType base) {
super(base, TYPE_LONG); super(base, TYPE_LONG);
} }
...@@ -740,7 +740,7 @@ public class ObjectType implements DataType { ...@@ -740,7 +740,7 @@ public class ObjectType implements DataType {
*/ */
class FloatType extends AutoDetectDataType { class FloatType extends AutoDetectDataType {
FloatType(ObjectType base) { FloatType(ObjectDataType base) {
super(base, TYPE_FLOAT); super(base, TYPE_FLOAT);
} }
...@@ -771,9 +771,9 @@ public class ObjectType implements DataType { ...@@ -771,9 +771,9 @@ public class ObjectType implements DataType {
if (obj instanceof Float) { if (obj instanceof Float) {
float x = (Float) obj; float x = (Float) obj;
int f = Float.floatToIntBits(x); int f = Float.floatToIntBits(x);
if (f == ObjectType.FLOAT_ZERO_BITS) { if (f == ObjectDataType.FLOAT_ZERO_BITS) {
buff.put((byte) TAG_FLOAT_0); buff.put((byte) TAG_FLOAT_0);
} else if (f == ObjectType.FLOAT_ONE_BITS) { } else if (f == ObjectDataType.FLOAT_ONE_BITS) {
buff.put((byte) TAG_FLOAT_1); buff.put((byte) TAG_FLOAT_1);
} else { } else {
int value = Integer.reverse(f); int value = Integer.reverse(f);
...@@ -810,7 +810,7 @@ public class ObjectType implements DataType { ...@@ -810,7 +810,7 @@ public class ObjectType implements DataType {
*/ */
class DoubleType extends AutoDetectDataType { class DoubleType extends AutoDetectDataType {
DoubleType(ObjectType base) { DoubleType(ObjectDataType base) {
super(base, TYPE_DOUBLE); super(base, TYPE_DOUBLE);
} }
...@@ -841,9 +841,9 @@ public class ObjectType implements DataType { ...@@ -841,9 +841,9 @@ public class ObjectType implements DataType {
if (obj instanceof Double) { if (obj instanceof Double) {
double x = (Double) obj; double x = (Double) obj;
long d = Double.doubleToLongBits(x); long d = Double.doubleToLongBits(x);
if (d == ObjectType.DOUBLE_ZERO_BITS) { if (d == ObjectDataType.DOUBLE_ZERO_BITS) {
buff.put((byte) TAG_DOUBLE_0); buff.put((byte) TAG_DOUBLE_0);
} else if (d == ObjectType.DOUBLE_ONE_BITS) { } else if (d == ObjectDataType.DOUBLE_ONE_BITS) {
buff.put((byte) TAG_DOUBLE_1); buff.put((byte) TAG_DOUBLE_1);
} else { } else {
long value = Long.reverse(d); long value = Long.reverse(d);
...@@ -880,7 +880,7 @@ public class ObjectType implements DataType { ...@@ -880,7 +880,7 @@ public class ObjectType implements DataType {
*/ */
class BigIntegerType extends AutoDetectDataType { class BigIntegerType extends AutoDetectDataType {
BigIntegerType(ObjectType base) { BigIntegerType(ObjectDataType base) {
super(base, TYPE_BIG_INTEGER); super(base, TYPE_BIG_INTEGER);
} }
...@@ -964,7 +964,7 @@ public class ObjectType implements DataType { ...@@ -964,7 +964,7 @@ public class ObjectType implements DataType {
*/ */
class BigDecimalType extends AutoDetectDataType { class BigDecimalType extends AutoDetectDataType {
BigDecimalType(ObjectType base) { BigDecimalType(ObjectDataType base) {
super(base, TYPE_BIG_DECIMAL); super(base, TYPE_BIG_DECIMAL);
} }
...@@ -1068,7 +1068,7 @@ public class ObjectType implements DataType { ...@@ -1068,7 +1068,7 @@ public class ObjectType implements DataType {
*/ */
class StringType extends AutoDetectDataType { class StringType extends AutoDetectDataType {
StringType(ObjectType base) { StringType(ObjectDataType base) {
super(base, TYPE_STRING); super(base, TYPE_STRING);
} }
...@@ -1131,7 +1131,7 @@ public class ObjectType implements DataType { ...@@ -1131,7 +1131,7 @@ public class ObjectType implements DataType {
*/ */
class UUIDType extends AutoDetectDataType { class UUIDType extends AutoDetectDataType {
UUIDType(ObjectType base) { UUIDType(ObjectDataType base) {
super(base, TYPE_UUID); super(base, TYPE_UUID);
} }
...@@ -1183,7 +1183,7 @@ public class ObjectType implements DataType { ...@@ -1183,7 +1183,7 @@ public class ObjectType implements DataType {
*/ */
class ByteArrayType extends AutoDetectDataType { class ByteArrayType extends AutoDetectDataType {
ByteArrayType(ObjectType base) { ByteArrayType(ObjectDataType base) {
super(base, TYPE_BYTE_ARRAY); super(base, TYPE_BYTE_ARRAY);
} }
...@@ -1250,7 +1250,7 @@ public class ObjectType implements DataType { ...@@ -1250,7 +1250,7 @@ public class ObjectType implements DataType {
*/ */
class CharArrayType extends AutoDetectDataType { class CharArrayType extends AutoDetectDataType {
CharArrayType(ObjectType base) { CharArrayType(ObjectDataType base) {
super(base, TYPE_CHAR_ARRAY); super(base, TYPE_CHAR_ARRAY);
} }
...@@ -1310,7 +1310,7 @@ public class ObjectType implements DataType { ...@@ -1310,7 +1310,7 @@ public class ObjectType implements DataType {
*/ */
class IntArrayType extends AutoDetectDataType { class IntArrayType extends AutoDetectDataType {
IntArrayType(ObjectType base) { IntArrayType(ObjectDataType base) {
super(base, TYPE_INT_ARRAY); super(base, TYPE_INT_ARRAY);
} }
...@@ -1370,7 +1370,7 @@ public class ObjectType implements DataType { ...@@ -1370,7 +1370,7 @@ public class ObjectType implements DataType {
*/ */
class LongArrayType extends AutoDetectDataType { class LongArrayType extends AutoDetectDataType {
LongArrayType(ObjectType base) { LongArrayType(ObjectDataType base) {
super(base, TYPE_LONG_ARRAY); super(base, TYPE_LONG_ARRAY);
} }
...@@ -1430,7 +1430,7 @@ public class ObjectType implements DataType { ...@@ -1430,7 +1430,7 @@ public class ObjectType implements DataType {
*/ */
class SerializedObjectType extends AutoDetectDataType { class SerializedObjectType extends AutoDetectDataType {
SerializedObjectType(ObjectType base) { SerializedObjectType(ObjectDataType base) {
super(base, TYPE_SERIALIZED_OBJECT); super(base, TYPE_SERIALIZED_OBJECT);
} }
......
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
*/ */
package org.h2.mvstore.type; package org.h2.mvstore.type;
import org.h2.mvstore.rtree.SpatialType; import org.h2.mvstore.rtree.SpatialDataType;
/** /**
* A data type factory. * A data type factory.
*/ */
public class ObjectTypeFactory implements DataTypeFactory { public class ObjectDataTypeFactory implements DataTypeFactory {
@Override @Override
public void setParent(DataTypeFactory parent) { public void setParent(DataTypeFactory parent) {
...@@ -20,16 +20,16 @@ public class ObjectTypeFactory implements DataTypeFactory { ...@@ -20,16 +20,16 @@ public class ObjectTypeFactory implements DataTypeFactory {
@Override @Override
public DataType buildDataType(String s) { public DataType buildDataType(String s) {
if ("s".equals(s)) { if ("s".equals(s)) {
return SpatialType.fromString(s); return SpatialDataType.fromString(s);
} else if ("o".equals(s)) { } else if ("o".equals(s)) {
return new ObjectType(); return new ObjectDataType();
} }
return null; return null;
} }
@Override @Override
public String getDataType(Class<?> objectClass) { public String getDataType(Class<?> objectClass) {
if (objectClass == SpatialType.class) { if (objectClass == SpatialDataType.class) {
return "s"; return "s";
} }
return "o"; return "o";
......
...@@ -12,9 +12,9 @@ import org.h2.mvstore.DataUtils; ...@@ -12,9 +12,9 @@ import org.h2.mvstore.DataUtils;
/** /**
* A string type. * A string type.
*/ */
public class StringType implements DataType { public class StringDataType implements DataType {
public static final StringType INSTANCE = new StringType(); public static final StringDataType INSTANCE = new StringDataType();
public int compare(Object a, Object b) { public int compare(Object a, Object b) {
return a.toString().compareTo(b.toString()); return a.toString().compareTo(b.toString());
......
...@@ -15,13 +15,13 @@ import org.h2.util.StringUtils; ...@@ -15,13 +15,13 @@ import org.h2.util.StringUtils;
/** /**
* A row type. * A row type.
*/ */
public class RowType implements DataType { public class RowDataType implements DataType {
static final String PREFIX = "org.h2.test.store.row"; static final String PREFIX = "org.h2.test.store.row";
private final DataType[] types; private final DataType[] types;
RowType(DataType[] types) { RowDataType(DataType[] types) {
this.types = types; this.types = types;
} }
...@@ -107,7 +107,7 @@ public class RowType implements DataType { ...@@ -107,7 +107,7 @@ public class RowType implements DataType {
* @param factory the data type factory * @param factory the data type factory
* @return the row type * @return the row type
*/ */
static RowType fromString(String t, DataTypeFactory factory) { static RowDataType fromString(String t, DataTypeFactory factory) {
if (!t.startsWith(PREFIX) || !t.endsWith(")")) { if (!t.startsWith(PREFIX) || !t.endsWith(")")) {
throw new RuntimeException("Unknown type: " + t); throw new RuntimeException("Unknown type: " + t);
} }
...@@ -117,7 +117,7 @@ public class RowType implements DataType { ...@@ -117,7 +117,7 @@ public class RowType implements DataType {
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
types[i] = factory.buildDataType(array[i]); types[i] = factory.buildDataType(array[i]);
} }
return new RowType(types); return new RowDataType(types);
} }
} }
...@@ -13,13 +13,13 @@ import java.sql.Timestamp; ...@@ -13,13 +13,13 @@ import java.sql.Timestamp;
import java.util.Arrays; import java.util.Arrays;
import java.util.Random; import java.util.Random;
import java.util.UUID; import java.util.UUID;
import org.h2.mvstore.type.ObjectType; import org.h2.mvstore.type.ObjectDataType;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/** /**
* Test the ObjectType class. * Test the ObjectType class.
*/ */
public class TestObjectType extends TestBase { public class TestObjectDataType extends TestBase {
/** /**
* Run just this test. * Run just this test.
...@@ -37,7 +37,7 @@ public class TestObjectType extends TestBase { ...@@ -37,7 +37,7 @@ public class TestObjectType extends TestBase {
private void testCommonValues() { private void testCommonValues() {
BigInteger largeBigInt = BigInteger.probablePrime(200, new Random(1)); BigInteger largeBigInt = BigInteger.probablePrime(200, new Random(1));
ObjectType ot = new ObjectType(); ObjectDataType ot = new ObjectDataType();
assertEquals("o", ot.asString()); assertEquals("o", ot.asString());
Object[] array = { Object[] array = {
false, true, false, true,
...@@ -104,7 +104,7 @@ public class TestObjectType extends TestBase { ...@@ -104,7 +104,7 @@ public class TestObjectType extends TestBase {
} }
private void test(Object last, Object x) { private void test(Object last, Object x) {
ObjectType ot = new ObjectType(); ObjectDataType ot = new ObjectDataType();
// switch to the last type before every operation, // switch to the last type before every operation,
// to test switching types // to test switching types
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论