提交 23492d1a authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Delegate creation of TypeInfo for custom types to CustomDataTypesHandler

上级 992f5c7f
......@@ -7,6 +7,8 @@ package org.h2.api;
import org.h2.store.DataHandler;
import org.h2.value.DataType;
import org.h2.value.ExtTypeInfo;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
/**
......@@ -36,6 +38,17 @@ public interface CustomDataTypesHandler {
*/
DataType getDataTypeById(int type);
/**
* Get type info for the given data type identity.
*
* @param type identifier of a data type
* @param precision precision
* @param scale scale
* @param extTypeInfo the extended type information, or null
* @return type information
*/
TypeInfo getTypeInfoById(int type, long precision, int scale, ExtTypeInfo extTypeInfo);
/**
* Get order for custom data type given its integer id
*
......
......@@ -5,6 +5,7 @@
*/
package org.h2.value;
import org.h2.api.CustomDataTypesHandler;
import org.h2.api.ErrorCode;
import org.h2.message.DbException;
import org.h2.util.JdbcUtils;
......@@ -208,10 +209,11 @@ public class TypeInfo {
return t;
}
}
if (JdbcUtils.customDataTypesHandler != null) {
DataType dt = JdbcUtils.customDataTypesHandler.getDataTypeById(type);
CustomDataTypesHandler handler = JdbcUtils.customDataTypesHandler;
if (handler != null) {
DataType dt = handler.getDataTypeById(type);
if (dt != null) {
return createTypeInfo(type, dt);
return handler.getTypeInfoById(type, dt.maxPrecision, dt.maxScale, null);
}
}
return TYPE_NULL;
......@@ -342,10 +344,10 @@ public class TypeInfo {
return new TypeInfo(type, precision, scale, ValueInterval.getDisplaySize(type, (int) precision, scale),
null);
}
if (JdbcUtils.customDataTypesHandler != null) {
DataType dt = JdbcUtils.customDataTypesHandler.getDataTypeById(type);
if (dt != null) {
return createTypeInfo(type, dt);
CustomDataTypesHandler handler = JdbcUtils.customDataTypesHandler;
if (handler != null) {
if (handler.getDataTypeById(type) != null) {
return handler.getTypeInfoById(type, precision, scale, extTypeInfo);
}
}
return TYPE_NULL;
......
......@@ -191,7 +191,6 @@ public class TestCustomDataTypesHandler extends TestDb {
if (name.toLowerCase(Locale.ENGLISH).equals(COMPLEX_DATA_TYPE_NAME)) {
return complexDataType;
}
return null;
}
......@@ -203,6 +202,11 @@ public class TestCustomDataTypesHandler extends TestDb {
return null;
}
@Override
public TypeInfo getTypeInfoById(int type, long precision, int scale, ExtTypeInfo extTypeInfo) {
return new TypeInfo(type, 0, 0, ValueDouble.DISPLAY_SIZE * 2 + 1, null);
}
@Override
public String getDataTypeClassName(int type) {
if (type == COMPLEX_DATA_TYPE_ID) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论