提交 8516540e authored 作者: Noel Grandin's avatar Noel Grandin

Fix NPE in querying spatial data through a sub-select

上级 30ad944b
...@@ -21,6 +21,8 @@ Change Log ...@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul> <ul>
<li>Fix NPE in querying spatial data through a sub-select.
</li>
<li>Fix bug where a lock on the SYS table was not released when closing a session that contained a temp <li>Fix bug where a lock on the SYS table was not released when closing a session that contained a temp
table with an LOB column. table with an LOB column.
</li> </li>
......
...@@ -164,7 +164,7 @@ public class IndexCursor implements Cursor { ...@@ -164,7 +164,7 @@ public class IndexCursor implements Cursor {
if (!alwaysFalse) { if (!alwaysFalse) {
if (intersects != null && index instanceof SpatialIndex) { if (intersects != null && index instanceof SpatialIndex) {
cursor = ((SpatialIndex) index).findByGeometry(tableFilter, cursor = ((SpatialIndex) index).findByGeometry(tableFilter,
intersects); start, end, intersects);
} else { } else {
cursor = index.find(tableFilter, start, end); cursor = index.find(tableFilter, start, end);
} }
......
...@@ -24,6 +24,6 @@ public interface SpatialIndex extends Index { ...@@ -24,6 +24,6 @@ public interface SpatialIndex extends Index {
* null for anything * null for anything
* @return the cursor to iterate over the results * @return the cursor to iterate over the results
*/ */
Cursor findByGeometry(TableFilter filter, SearchRow intersection); Cursor findByGeometry(TableFilter filter, SearchRow first, SearchRow last, SearchRow intersection);
} }
...@@ -168,9 +168,9 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex { ...@@ -168,9 +168,9 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
} }
@Override @Override
public Cursor findByGeometry(TableFilter filter, SearchRow intersection) { public Cursor findByGeometry(TableFilter filter, SearchRow first, SearchRow last, SearchRow intersection) {
if (intersection == null) { if (intersection == null) {
return find(filter.getSession()); return find(filter.getSession(), first, last);
} }
return new SpatialCursor( return new SpatialCursor(
treeMap.findIntersectingKeys(getKey(intersection)), table, treeMap.findIntersectingKeys(getKey(intersection)), table,
......
...@@ -160,8 +160,8 @@ public class ViewIndex extends BaseIndex implements SpatialIndex { ...@@ -160,8 +160,8 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
} }
@Override @Override
public Cursor findByGeometry(TableFilter filter, SearchRow intersection) { public Cursor findByGeometry(TableFilter filter, SearchRow first, SearchRow last, SearchRow intersection) {
return find(filter.getSession(), null, null, intersection); return find(filter.getSession(), first, last, intersection);
} }
private static Query prepareSubQuery(String sql, Session session, int[] masks, private static Query prepareSubQuery(String sql, Session session, int[] masks,
......
...@@ -197,10 +197,10 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex { ...@@ -197,10 +197,10 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
} }
@Override @Override
public Cursor findByGeometry(TableFilter filter, SearchRow intersection) { public Cursor findByGeometry(TableFilter filter, SearchRow first, SearchRow last, SearchRow intersection) {
Session session = filter.getSession(); Session session = filter.getSession();
if (intersection == null) { if (intersection == null) {
return find(session); return find(session, first, last);
} }
Iterator<SpatialKey> cursor = Iterator<SpatialKey> cursor =
spatialMap.findIntersectingKeys(getKey(intersection)); spatialMap.findIntersectingKeys(getKey(intersection));
......
...@@ -39,7 +39,7 @@ import org.h2.value.ValueGeometry; ...@@ -39,7 +39,7 @@ import org.h2.value.ValueGeometry;
*/ */
public class TestSpatial extends TestBase { public class TestSpatial extends TestBase {
private String url = "spatial"; private static final String url = "spatial";
/** /**
* Run just this test. * Run just this test.
...@@ -60,13 +60,13 @@ public class TestSpatial extends TestBase { ...@@ -60,13 +60,13 @@ public class TestSpatial extends TestBase {
} }
if (DataType.GEOMETRY_CLASS != null) { if (DataType.GEOMETRY_CLASS != null) {
deleteDb("spatial"); deleteDb("spatial");
url = "spatial";
testSpatial(); testSpatial();
deleteDb("spatial"); deleteDb("spatial");
} }
} }
private void testSpatial() throws SQLException { private void testSpatial() throws SQLException {
testBug1();
testSpatialValues(); testSpatialValues();
testOverlap(); testOverlap();
testNotOverlap(); testNotOverlap();
...@@ -94,6 +94,19 @@ public class TestSpatial extends TestBase { ...@@ -94,6 +94,19 @@ public class TestSpatial extends TestBase {
testNullableGeometryInsert(); testNullableGeometryInsert();
testNullableGeometryUpdate(); testNullableGeometryUpdate();
} }
private void testBug1() throws SQLException {
deleteDb("spatial");
Connection conn = getConnection(url);
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE VECTORS (ID INTEGER NOT NULL, GEOM GEOMETRY, S INTEGER)");
stat.execute("INSERT INTO VECTORS(ID, GEOM, S) VALUES(0, 'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))', 1)");
stat.executeQuery("select * from (select * from VECTORS) WHERE S=1 AND GEOM && 'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))'");
conn.close();
deleteDb("spatial");
}
private void testHashCode() { private void testHashCode() {
ValueGeometry geomA = ValueGeometry ValueGeometry geomA = ValueGeometry
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论