提交 0d6dd081 authored 作者: noelgrandin's avatar noelgrandin

fix for DataType#isGeometry method. Patch from Niclos Fortin.

We need two methods - one for testing the Class<?> and one for testing an Object
上级 186bd839
......@@ -961,6 +961,19 @@ public class DataType {
}
}
/**
* Check whether a given class matches the Geometry class.
*
* @param x the class
* @return true if it is a Geometry class
*/
public static boolean isGeometry(Class<?> x) {
if (x == null || GEOMETRY_CLASS == null) {
return false;
}
return GEOMETRY_CLASS.isAssignableFrom(x);
}
/**
* Check whether a given object is a Geometry object.
*
......@@ -968,10 +981,10 @@ public class DataType {
* @return true if it is a Geometry object
*/
public static boolean isGeometry(Object x) {
if (x == null || GEOMETRY_CLASS == null) {
if (x == null) {
return false;
}
return GEOMETRY_CLASS.isAssignableFrom(x.getClass());
return isGeometry(x.getClass());
}
/**
......
......@@ -16,6 +16,7 @@ import org.h2.test.TestBase;
import org.h2.tools.SimpleResultSet;
import org.h2.tools.SimpleRowSource;
import org.h2.value.DataType;
import org.h2.value.Value;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
......@@ -57,6 +58,7 @@ public class TestSpatial extends TestBase {
testJavaAlias();
testJavaAliasTableFunction();
testMemorySpatialIndex();
testGeometryDataType();
deleteDb("spatial");
}
}
......@@ -504,4 +506,9 @@ public class TestSpatial extends TestBase {
}
}
private void testGeometryDataType() {
GeometryFactory geometryFactory = new GeometryFactory();
Geometry geometry = geometryFactory.createPoint(new Coordinate(0, 0));
assertEquals(Value.GEOMETRY, DataType.getTypeFromClass(geometry.getClass()));
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论