|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 | + * Copyright Red Hat Inc. and Hibernate Authors |
| 4 | + */ |
| 5 | +package org.hibernate.spatial.dialect.oracle.hhh19227; |
| 6 | + |
| 7 | + |
| 8 | +import org.hibernate.dialect.OracleDialect; |
| 9 | +import org.hibernate.query.Query; |
| 10 | +import org.hibernate.spatial.testing.SpatialSessionFactoryAware; |
| 11 | +import org.hibernate.testing.orm.domain.StandardDomainModel; |
| 12 | +import org.hibernate.testing.orm.junit.DomainModel; |
| 13 | +import org.hibernate.testing.orm.junit.JiraKey; |
| 14 | +import org.hibernate.testing.orm.junit.RequiresDialect; |
| 15 | +import org.hibernate.testing.orm.junit.SessionFactory; |
| 16 | +import org.junit.jupiter.api.Test; |
| 17 | +import org.locationtech.jts.geom.Geometry; |
| 18 | +import org.locationtech.jts.io.ParseException; |
| 19 | +import org.locationtech.jts.io.WKTReader; |
| 20 | + |
| 21 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 22 | +import static org.hamcrest.Matchers.is; |
| 23 | + |
| 24 | +@JiraKey(value = "HHH-19227") |
| 25 | +@RequiresDialect(value = OracleDialect.class) |
| 26 | +@DomainModel(standardModels = StandardDomainModel.ANIMAL) |
| 27 | +@SessionFactory |
| 28 | +public class TestSDODescriptorBug extends SpatialSessionFactoryAware { |
| 29 | + |
| 30 | + private static Geometry parse(String wkt) { |
| 31 | + try { |
| 32 | + return new WKTReader().read( wkt ); |
| 33 | + } |
| 34 | + catch (ParseException e) { |
| 35 | + throw new RuntimeException( e ); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + private static final Geometry REFERENCE = |
| 40 | + parse( "POLYGON ((10 10, 10 20, 20 20, 20 10, 10 10))" ); |
| 41 | + private static final Geometry EQUALS_REFERENCE = |
| 42 | + parse( "POLYGON ((10 20, 20 20, 20 10, 10 10, 10 20))" ); |
| 43 | + private static final Geometry DISJOINT_WITH_REFERENCE = |
| 44 | + parse( "POLYGON ((25 20, 35 20, 35 10, 25 10, 25 20))" ); |
| 45 | + private static final Geometry TOUCHES_REFERENCE = |
| 46 | + parse( "POLYGON ((20 25, 30 25, 30 15, 20 15, 20 25))" ); |
| 47 | + private static final Geometry OVERLAPS_REFERENCE = |
| 48 | + parse( "POLYGON ((15 15, 15 25, 25 25, 25 15, 15 15))" ); |
| 49 | + private static final Geometry CROSSES_REFERENCE = |
| 50 | + parse( "LINESTRING (25 15, 15 15)" ); |
| 51 | + private static final Geometry CONTAINED_BY_REFERENCE = |
| 52 | + parse( "POLYGON ((15 15, 15 20, 20 20, 20 15, 15 15))" ); |
| 53 | + private static final Geometry CONTAINS_REFERENCE = |
| 54 | + parse( "POLYGON ((10 10, 10 25, 25 25, 25 10, 10 10))" ); |
| 55 | + private static final Geometry INTERSECTS_BOUNDARY = |
| 56 | + parse( "POLYGON ((20 25, 30 25, 30 15, 20 15, 20 25))" ); |
| 57 | + private static final Geometry INTERSECTS_INTERIOR = |
| 58 | + parse( "POLYGON ((15 15, 15 25, 25 25, 25 15, 15 15))" ); |
| 59 | + |
| 60 | + |
| 61 | + @Test |
| 62 | + void ogcEquals() { |
| 63 | + scope.inSession( session -> { |
| 64 | + Query<Boolean> query = session.createQuery( "select equals(:a, :b)", Boolean.class ); |
| 65 | + query.setParameter( "a", REFERENCE ); |
| 66 | + query.setParameter( "b", EQUALS_REFERENCE ); |
| 67 | + Object result = query.getSingleResult(); |
| 68 | + assertThat( result, is( true ) ); |
| 69 | + } ); |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + void ogcDisjoint() { |
| 75 | + scope.inSession( session -> { |
| 76 | + Query<Boolean> query = session.createQuery( "select disjoint(:a, :b)", Boolean.class ); |
| 77 | + query.setParameter( "a", REFERENCE ); |
| 78 | + query.setParameter( "b", DISJOINT_WITH_REFERENCE ); |
| 79 | + Object result = query.getSingleResult(); |
| 80 | + assertThat( result, is( true ) ); |
| 81 | + } ); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + void ogcTouches() { |
| 86 | + scope.inSession( session -> { |
| 87 | + Query<Boolean> query = session.createQuery( "select touches(:a, :b)", Boolean.class ); |
| 88 | + query.setParameter( "a", REFERENCE ); |
| 89 | + query.setParameter( "b", TOUCHES_REFERENCE ); |
| 90 | + Object result = query.getSingleResult(); |
| 91 | + assertThat( result, is( true ) ); |
| 92 | + } ); |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + void ogcOverlaps() { |
| 97 | + scope.inSession( session -> { |
| 98 | + Query<Boolean> query = session.createQuery( "select overlaps(:a, :b)", Boolean.class ); |
| 99 | + query.setParameter( "a", REFERENCE ); |
| 100 | + query.setParameter( "b", OVERLAPS_REFERENCE ); |
| 101 | + Object result = query.getSingleResult(); |
| 102 | + assertThat( result, is( true ) ); |
| 103 | + } ); |
| 104 | + } |
| 105 | + |
| 106 | + @Test |
| 107 | + void ogcCrosses() { |
| 108 | + scope.inSession( session -> { |
| 109 | + Query<Boolean> query = session.createQuery( "select crosses(:a, :b)", Boolean.class ); |
| 110 | + query.setParameter( "a", REFERENCE ); |
| 111 | + query.setParameter( "b", CROSSES_REFERENCE ); |
| 112 | + Object result = query.getSingleResult(); |
| 113 | + assertThat( result, is( true ) ); |
| 114 | + } ); |
| 115 | + } |
| 116 | + |
| 117 | + @Test |
| 118 | + void ogcContains() { |
| 119 | + scope.inSession( session -> { |
| 120 | + Query<Boolean> query = session.createQuery( "select contains(:a, :b)", Boolean.class ); |
| 121 | + query.setParameter( "a", REFERENCE ); |
| 122 | + query.setParameter( "b", CONTAINED_BY_REFERENCE ); |
| 123 | + Object result = query.getSingleResult(); |
| 124 | + assertThat( result, is( true ) ); |
| 125 | + } ); |
| 126 | + } |
| 127 | + |
| 128 | + @Test |
| 129 | + void ogcWithin() { |
| 130 | + scope.inSession( session -> { |
| 131 | + Query<Boolean> query = session.createQuery( "select within(:a, :b)", Boolean.class ); |
| 132 | + query.setParameter( "a", REFERENCE ); |
| 133 | + query.setParameter( "b", CONTAINS_REFERENCE ); |
| 134 | + Object result = query.getSingleResult(); |
| 135 | + assertThat( result, is( true ) ); |
| 136 | + } ); |
| 137 | + } |
| 138 | + |
| 139 | + @Test |
| 140 | + void ogcIntersects_polygonal() { |
| 141 | + scope.inSession( session -> { |
| 142 | + Query<Boolean> query = session.createQuery( "select intersects(:a, :b)", Boolean.class ); |
| 143 | + query.setParameter( "a", REFERENCE ); |
| 144 | + query.setParameter( "b", INTERSECTS_BOUNDARY ); |
| 145 | + Object result = query.getSingleResult(); |
| 146 | + assertThat( result, is( true ) ); |
| 147 | + } ); |
| 148 | + } |
| 149 | + |
| 150 | + @Test |
| 151 | + void ogcIntersects_lineal() { |
| 152 | + scope.inSession( session -> { |
| 153 | + Query<Boolean> query = session.createQuery( "select intersects(:a, :b)", Boolean.class ); |
| 154 | + query.setParameter( "a", REFERENCE ); |
| 155 | + query.setParameter( "b", INTERSECTS_INTERIOR ); |
| 156 | + Object result = query.getSingleResult(); |
| 157 | + assertThat( result, is( true ) ); |
| 158 | + } ); |
| 159 | + } |
| 160 | + |
| 161 | + |
| 162 | +} |
0 commit comments