提交 76b374c4 authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #477 from marschall/fix-doc-generation

Fix doc generation
......@@ -1695,11 +1695,11 @@ Please note that this SQL statement can only be executed before any tables are d
<h2 id="custom_data_types_handler_api">Custom Data Types Handler API</h2>
<p>
It is possible to extend the type system of the database by providing your own implementation
It is possible to extend the type system of the database by providing your own implementation
of minimal required API basically consisting of type identification and conversion routines.
</p>
<p>
In order to enable this feature, set the system property <code>h2.customDataTypesHandler</code> (default: null) to the fully qualified name of the class providing <a href="../javadoc/org/h2/api/CustomDataTypesHandler.html">CustomDataTypesHandler</a> interface implementation. <br>
In order to enable this feature, set the system property <code>h2.customDataTypesHandler</code> (default: null) to the fully qualified name of the class providing <a href="../javadoc/org/h2/api/CustomDataTypesHandler.html">CustomDataTypesHandler</a> interface implementation. <br />
The instance of that class will be created by H2 and used to:
<ul>
<li>resolve the names and identifiers of extrinsic data types.
......
......@@ -84,8 +84,8 @@ public interface CustomDataTypesHandler {
* Converts {@link org.h2.value.Value} object
* to the specified class.
*
* @param value
* @param cls
* @param value the value to convert
* @param cls the target class
* @return result
*/
Object getObject(Value value, Class<?> cls);
......
......@@ -608,9 +608,11 @@ public class ValueDataType implements DataType {
int len = readVarInt(buff);
byte[] b = DataUtils.newBytes(len);
buff.get(b, 0, len);
return JdbcUtils.customDataTypesHandler.convert(ValueBytes.getNoCopy(b), customType);
return JdbcUtils.customDataTypesHandler.convert(
ValueBytes.getNoCopy(b), customType);
}
throw DbException.get(ErrorCode.UNKNOWN_DATA_TYPE_1, "No CustomDataTypesHandler has been set up");
throw DbException.get(ErrorCode.UNKNOWN_DATA_TYPE_1,
"No CustomDataTypesHandler has been set up");
}
default:
if (type >= INT_0_15 && type < INT_0_15 + 16) {
......
......@@ -127,7 +127,8 @@ public class JdbcUtils {
String customTypeHandlerClass = SysProperties.CUSTOM_DATA_TYPES_HANDLER;
if (customTypeHandlerClass != null) {
try {
customDataTypesHandler = (CustomDataTypesHandler) loadUserClass(customTypeHandlerClass).newInstance();
customDataTypesHandler = (CustomDataTypesHandler)
loadUserClass(customTypeHandlerClass).newInstance();
} catch (Exception e) {
throw DbException.convert(e);
}
......
......@@ -1109,7 +1109,8 @@ public class DataType {
return LocalDateTimeUtils.offsetDateTimeToValue(x);
} else {
if (JdbcUtils.customDataTypesHandler != null) {
return JdbcUtils.customDataTypesHandler.getValue(type, x, session.getDataHandler());
return JdbcUtils.customDataTypesHandler.getValue(type, x,
session.getDataHandler());
}
return ValueJavaObject.getNoCopy(x, null, session.getDataHandler());
}
......
......@@ -711,7 +711,8 @@ public class Transfer {
return ValueGeometry.get(readString());
default:
if (JdbcUtils.customDataTypesHandler != null) {
return JdbcUtils.customDataTypesHandler.convert(ValueBytes.getNoCopy(readBytes()), type);
return JdbcUtils.customDataTypesHandler.convert(
ValueBytes.getNoCopy(readBytes()), type);
}
throw DbException.get(ErrorCode.CONNECTION_BROKEN_1, "type=" + type);
}
......
......@@ -84,7 +84,8 @@ public class TestCustomDataTypesHandler extends TestBase {
assertEquals(ComplexNumber.class.getName(), rs.getMetaData().getColumnClassName(1));
//Test insert
PreparedStatement stmt = conn.prepareStatement("insert into t(id, val) values (0, '1.0+1.0i'), (1, ?), (2, ?), (3, ?)");
PreparedStatement stmt = conn.prepareStatement(
"insert into t(id, val) values (0, '1.0+1.0i'), (1, ?), (2, ?), (3, ?)");
stmt.setObject(1, new ComplexNumber(1, -1));
stmt.setObject(2, "5.0+2.0i");
stmt.setObject(3, 100.1);
......@@ -98,7 +99,8 @@ public class TestCustomDataTypesHandler extends TestBase {
expected[3] = new ComplexNumber(100.1, 0);
for (int id = 0; id < expected.length; ++id) {
PreparedStatement prepStat = conn.prepareStatement("select val from t where id = ?");
PreparedStatement prepStat =conn.prepareStatement(
"select val from t where id = ?");
prepStat.setInt(1, id);
rs = prepStat.executeQuery();
assertTrue(rs.next());
......@@ -106,7 +108,8 @@ public class TestCustomDataTypesHandler extends TestBase {
}
for (int id = 0; id < expected.length; ++id) {
PreparedStatement prepStat = conn.prepareStatement("select id from t where val = ?");
PreparedStatement prepStat = conn.prepareStatement(
"select id from t where val = ?");
prepStat.setObject(1, expected[id]);
rs = prepStat.executeQuery();
assertTrue(rs.next());
......@@ -117,7 +120,8 @@ public class TestCustomDataTypesHandler extends TestBase {
stat.execute("create index val_idx on t(val)");
for (int id = 0; id < expected.length; ++id) {
PreparedStatement prepStat = conn.prepareStatement("select id from t where val = ?");
PreparedStatement prepStat = conn.prepareStatement(
"select id from t where val = ?");
prepStat.setObject(1, expected[id]);
rs = prepStat.executeQuery();
assertTrue(rs.next());
......@@ -130,7 +134,8 @@ public class TestCustomDataTypesHandler extends TestBase {
assertTrue(rs.getObject(1).equals(new ComplexNumber(107.1, 2)));
// user function
stat.execute("create alias complex_mod for \""+ getClass().getName() + ".complexMod\"");
stat.execute("create alias complex_mod for \""
+ getClass().getName() + ".complexMod\"");
rs = stat.executeQuery("select complex_mod(val) from t where id=2");
rs.next();
assertEquals(complexMod(expected[2]), rs.getDouble(1));
......@@ -143,10 +148,10 @@ public class TestCustomDataTypesHandler extends TestBase {
}
/**
* modulus function
* @param val complex number
* @return result
*/
* modulus function
* @param val complex number
* @return result
*/
public static double complexMod(ComplexNumber val) {
return val.mod();
}
......@@ -221,15 +226,18 @@ public class TestCustomDataTypesHandler extends TestBase {
switch (source.getType()) {
case Value.JAVA_OBJECT: {
assert source instanceof ValueJavaObject;
return ValueComplex.get((ComplexNumber)JdbcUtils.deserialize(source.getBytesNoCopy(), null));
return ValueComplex.get((ComplexNumber)
JdbcUtils.deserialize(source.getBytesNoCopy(), null));
}
case Value.STRING: {
assert source instanceof ValueString;
return ValueComplex.get(ComplexNumber.parseComplexNumber(source.getString()));
return ValueComplex.get(
ComplexNumber.parseComplexNumber(source.getString()));
}
case Value.BYTES: {
assert source instanceof ValueBytes;
return ValueComplex.get((ComplexNumber)JdbcUtils.deserialize(source.getBytesNoCopy(), null));
return ValueComplex.get((ComplexNumber)
JdbcUtils.deserialize(source.getBytesNoCopy(), null));
}
case Value.DOUBLE: {
assert source instanceof ValueDouble;
......@@ -527,13 +535,13 @@ public class TestCustomDataTypesHandler extends TestBase {
/** {@inheritDoc} */
@Override
public String toString() {
if (im == 0.0) {
return REAL_FMT.format(re);
}
if (re == 0.0) {
return IMG_FMT.format(im);
}
return REAL_FMT.format(re) + "" + IMG_FMT.format(im);
if (im == 0.0) {
return REAL_FMT.format(re);
}
if (re == 0.0) {
return IMG_FMT.format(im);
}
return REAL_FMT.format(re) + "" + IMG_FMT.format(im);
}
/**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论