提交 67b3f30f authored 作者: Thomas Mueller's avatar Thomas Mueller

A persistent tree map (work in progress).

上级 a204eabd
...@@ -22,38 +22,28 @@ public class BtreeMap<K, V> { ...@@ -22,38 +22,28 @@ public class BtreeMap<K, V> {
private final DataType valueType; private final DataType valueType;
private Page root; private Page root;
private BtreeMap(BtreeMapStore store, String name, Class<K> keyClass, Class<V> valueClass) { private BtreeMap(BtreeMapStore store, String name, DataType keyType, DataType valueType) {
this.store = store; this.store = store;
this.name = name; this.name = name;
if (keyClass == Integer.class) { this.keyType = keyType;
keyType = new IntegerType(); this.valueType = valueType;
} else if (keyClass == String.class) {
keyType = new StringType();
} else {
throw new RuntimeException("Unsupported key class " + keyClass.toString());
}
if (valueClass == Integer.class) {
valueType = new IntegerType();
} else if (valueClass == String.class) {
valueType = new StringType();
} else {
throw new RuntimeException("Unsupported value class " + keyClass.toString());
}
} }
/** /**
* Get the class with the given tag name. * Open a map.
* *
* @param name the tag name * @param <K> the key type
* @return the class * @param <V> the value type
* @param store the tree store
* @param name the name of the map
* @param keyClass the key class
* @param valueClass the value class
* @return the map
*/ */
static Class<?> getClass(String name) { static <K, V> BtreeMap<K, V> open(BtreeMapStore store, String name, Class<K> keyClass, Class<V> valueClass) {
if (name.equals("i")) { DataType keyType = DataTypeFactory.getDataType(keyClass);
return Integer.class; DataType valueType = DataTypeFactory.getDataType(valueClass);
} else if (name.equals("s")) { return new BtreeMap<K, V>(store, name, keyType, valueType);
return String.class;
}
throw new RuntimeException("Unknown class name " + name);
} }
/** /**
...@@ -67,8 +57,8 @@ public class BtreeMap<K, V> { ...@@ -67,8 +57,8 @@ public class BtreeMap<K, V> {
* @param valueClass the value class * @param valueClass the value class
* @return the map * @return the map
*/ */
static <K, V> BtreeMap<K, V> open(BtreeMapStore store, String name, Class<K> keyClass, Class<V> valueClass) { static <K, V> BtreeMap<K, V> open(BtreeMapStore store, String name, DataType keyType, DataType valueType) {
return new BtreeMap<K, V>(store, name, keyClass, valueClass); return new BtreeMap<K, V>(store, name, keyType, valueType);
} }
/** /**
......
...@@ -513,8 +513,8 @@ public class BtreeMapStore { ...@@ -513,8 +513,8 @@ public class BtreeMapStore {
continue; continue;
} }
String[] d = StringUtils.arraySplit(v, ',', false); String[] d = StringUtils.arraySplit(v, ',', false);
Class<?> kt = BtreeMap.getClass(d[1]); DataType kt = DataTypeFactory.getDataType(d[1]);
Class<?> vt = BtreeMap.getClass(d[2]); DataType vt = DataTypeFactory.getDataType(d[2]);
BtreeMap<?, ?> oldData = BtreeMap.open(this, "old-" + k, kt, vt); BtreeMap<?, ?> oldData = BtreeMap.open(this, "old-" + k, kt, vt);
long oldDataRoot = Long.parseLong(d[0]); long oldDataRoot = Long.parseLong(d[0]);
if (oldDataRoot == 0) { if (oldDataRoot == 0) {
......
/*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.dev.store.btree;
/**
* A factory for data types.
*/
public class DataTypeFactory {
/**
* Get the class with the given name.
*
* @param name the name
* @return the data type
*/
static DataType getDataType(String name) {
if (name.equals("i")) {
return new IntegerType();
} else if (name.equals("s")) {
return new StringType();
}
throw new RuntimeException("Unknown data type name " + name);
}
/**
* Get the data type object for the given class.
*
* @param objectClass the class
* @return the data type object
*/
static DataType getDataType(Class<?> objectClass) {
if (objectClass == Integer.class) {
return new IntegerType();
} else if (objectClass == String.class) {
return new StringType();
}
throw new RuntimeException("Unsupported object class " + objectClass.toString());
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论