HHH-14738 Clean up obsolete test support code
This commit is contained in:
parent
ba47586634
commit
e185ec8913
|
@ -21,7 +21,11 @@ dependencies {
|
|||
|
||||
|
||||
testCompile(project(':hibernate-testing'))
|
||||
<<<<<<< HEAD
|
||||
testCompile( project( path: ':hibernate-core', configuration: 'tests' ) )
|
||||
=======
|
||||
testCompile( project( path: ':hibernate-core', configuration: 'tests' ) )
|
||||
>>>>>>> f70b7d7c50 (HHH-14738 Clean up obsolete test support code)
|
||||
testCompile(libraries.validation)
|
||||
testCompile(libraries.jandex)
|
||||
testCompile(libraries.classmate)
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.geolatte.geom.Geometry;
|
|||
|
||||
public interface GeomCodec {
|
||||
|
||||
Geometry<?> toGeometry(Object in) ;
|
||||
Geometry<?> toGeometry(Object in);
|
||||
|
||||
Object fromGeometry(Geometry<?> in);
|
||||
|
||||
|
|
|
@ -7,32 +7,36 @@
|
|||
|
||||
package org.hibernate.spatial.dialect.hana;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.spatial.HSMessageLogger;
|
||||
import org.hibernate.spatial.integration.TestSpatialFunctions;
|
||||
import org.hibernate.spatial.testing.SpatialFunctionalTestCase;
|
||||
import org.hibernate.spatial.testing.dialects.hana.HANAExpectationsFactory;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
import org.locationtech.jts.io.WKBWriter;
|
||||
import org.locationtech.jts.io.WKTWriter;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
@RequiresDialect(value = HANASpatialDialect.class, comment = "This test tests the HANA spatial functions not covered by Hibernate Spatial", jiraKey = "HHH-12426")
|
||||
@Ignore
|
||||
@Deprecated
|
||||
public class TestHANASpatialFunctions extends TestSpatialFunctions {
|
||||
public class TestHANASpatialFunctions extends SpatialFunctionalTestCase {
|
||||
|
||||
private static final HSMessageLogger LOG = Logger.getMessageLogger(
|
||||
HSMessageLogger.class,
|
||||
|
@ -1175,4 +1179,49 @@ public class TestHANASpatialFunctions extends TestSpatialFunctions {
|
|||
params.put( filterParamName, value );
|
||||
return params;
|
||||
}
|
||||
|
||||
public <T> void retrieveHQLResultsAndCompare(Map<Integer, T> dbexpected, String hql, String geometryType) {
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, null, geometryType );
|
||||
}
|
||||
|
||||
protected <T> void retrieveHQLResultsAndCompare(
|
||||
Map<Integer, T> dbexpected,
|
||||
String hql,
|
||||
Map<String, Object> params,
|
||||
String geometryType) {
|
||||
Map<Integer, T> hsreceived = new HashMap<Integer, T>();
|
||||
doInSession( hql, hsreceived, params );
|
||||
compare( dbexpected, hsreceived, geometryType );
|
||||
}
|
||||
|
||||
|
||||
private <T> void doInSession(String hql, Map<Integer, T> result, Map<String, Object> params) {
|
||||
Session session = null;
|
||||
Transaction tx = null;
|
||||
try {
|
||||
session = openSession();
|
||||
tx = session.beginTransaction();
|
||||
Query query = session.createQuery( hql );
|
||||
setParameters( params, query );
|
||||
addQueryResults( result, query );
|
||||
}
|
||||
finally {
|
||||
if ( tx != null ) {
|
||||
tx.rollback();
|
||||
}
|
||||
if ( session != null ) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setParameters(Map<String, Object> params, Query query) {
|
||||
if ( params == null ) {
|
||||
return;
|
||||
}
|
||||
for ( Map.Entry<String, Object> entry : params.entrySet() ) {
|
||||
query.setParameter( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Contains dialect specific tests
|
||||
*/
|
||||
package org.hibernate.spatial.dialect;
|
|
@ -4,7 +4,14 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.integration.geolatte;
|
||||
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.dialect.postgis;
|
||||
|
||||
import java.util.List;
|
||||
import javax.persistence.Entity;
|
||||
|
@ -12,14 +19,18 @@ import javax.persistence.GeneratedValue;
|
|||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.dialect.PostgreSQLDialect;
|
||||
import org.hibernate.spatial.GeolatteGeometryType;
|
||||
import org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.geolatte.geom.C2D;
|
||||
import org.geolatte.geom.Geometry;
|
||||
import org.geolatte.geom.Point;
|
||||
import org.geolatte.geom.Polygon;
|
||||
import org.geolatte.geom.crs.CoordinateReferenceSystem;
|
||||
|
@ -37,7 +48,8 @@ import static org.junit.Assert.assertEquals;
|
|||
*
|
||||
* @author Vlad Mihalcea, Karel Maesen
|
||||
*/
|
||||
@RequiresDialect(PostgisPG95Dialect.class)
|
||||
@RequiresDialect(PostgreSQLDialect.class)
|
||||
|
||||
public class PostgisTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
public static CoordinateReferenceSystem<C2D> crs = CoordinateReferenceSystems.PROJECTED_2D_METER;
|
||||
|
@ -68,9 +80,9 @@ public class PostgisTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
List<Event> events = session.createQuery(
|
||||
"select e " +
|
||||
"from Event e " +
|
||||
"where within( e.location, buffer(:window, 100)) = true", Event.class )
|
||||
"select e " +
|
||||
"from Event e " +
|
||||
"where within( e.location, buffer(:window, 100)) = true", Event.class )
|
||||
.setParameter( "window", window )
|
||||
.getResultList();
|
||||
|
||||
|
@ -80,14 +92,16 @@ public class PostgisTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
//TODO -- register these extra functions
|
||||
public void testMakeEnvelope() {
|
||||
Long addressId = insertEvent( c( 10, 5 ) );
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
List<Event> events = session.createQuery(
|
||||
"select e " +
|
||||
"from Event e " +
|
||||
"where within(e.location, makeenvelope(0, 0, 11, 11, -1 )) = true", Event.class )
|
||||
"select e " +
|
||||
"from Event e " +
|
||||
"where within(e.location, makeenvelope(0, 0, 11, 11, -1 )) = true", Event.class )
|
||||
.getResultList();
|
||||
|
||||
assertEquals( 1, events.size() );
|
|
@ -5,7 +5,7 @@
|
|||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.integration.jts.hhh14523;
|
||||
package org.hibernate.spatial.dialect.postgis.hhh14523;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
@ -21,7 +21,6 @@ import javax.persistence.Table;
|
|||
|
||||
import org.hibernate.dialect.PostgreSQLDialect;
|
||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
|
@ -6,4 +6,4 @@
|
|||
*/
|
||||
|
||||
//test case for bug HHH-14523
|
||||
package org.hibernate.spatial.integration.jts.hhh14523;
|
||||
package org.hibernate.spatial.dialect.postgis.hhh14523;
|
|
@ -10,7 +10,6 @@ package org.hibernate.spatial.integration;
|
|||
import org.hibernate.dialect.AbstractHANADialect;
|
||||
import org.hibernate.dialect.DB2Dialect;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.spatial.dialect.db2.DB2SpatialDialect;
|
||||
|
||||
import org.geolatte.geom.codec.Wkt;
|
||||
import org.geolatte.geom.codec.WktDecoder;
|
||||
|
|
|
@ -13,12 +13,11 @@ import java.util.Map;
|
|||
|
||||
import org.hibernate.spatial.CommonSpatialFunction;
|
||||
import org.hibernate.spatial.GeomCodec;
|
||||
import org.hibernate.spatial.testing.JTSGeometryEquality;
|
||||
import org.hibernate.spatial.testing.dialects.NativeSQLTemplates;
|
||||
import org.hibernate.spatial.testing.TestSupportFactories;
|
||||
import org.hibernate.spatial.testing.datareader.TestData;
|
||||
import org.hibernate.spatial.testing.datareader.TestDataElement;
|
||||
import org.hibernate.spatial.testing.datareader.TestSupport;
|
||||
import org.hibernate.spatial.testing.dialects.NativeSQLTemplates;
|
||||
import org.hibernate.spatial.testing.domain.GeomEntityLike;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DialectContext;
|
||||
|
@ -34,7 +33,6 @@ public class SpatialTestDataProvider {
|
|||
private final TestData funcTestData;
|
||||
protected TestData testData;
|
||||
protected GeomCodec codec;
|
||||
protected JTSGeometryEquality geometryEquality;
|
||||
|
||||
public SpatialTestDataProvider() {
|
||||
try {
|
||||
|
@ -44,7 +42,6 @@ public class SpatialTestDataProvider {
|
|||
codec = support.codec();
|
||||
testData = support.createTestData( StoreRetrieveData );
|
||||
funcTestData = support.createTestData( SpatialFunctionsData );
|
||||
geometryEquality = support.createGeometryEquality();
|
||||
}
|
||||
catch (InstantiationException | IllegalAccessException e) {
|
||||
throw new RuntimeException( e );
|
||||
|
|
|
@ -14,17 +14,20 @@ import javax.persistence.Query;
|
|||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.spatial.testing.GeometryEquality;
|
||||
import org.hibernate.spatial.testing.datareader.TestDataElement;
|
||||
import org.hibernate.spatial.testing.domain.GeomEntity;
|
||||
import org.hibernate.spatial.testing.domain.GeomEntityLike;
|
||||
import org.hibernate.spatial.testing.domain.JtsGeomEntity;
|
||||
import org.hibernate.spatial.testing.domain.SpatialDomainModel;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScopeAware;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
@ -35,40 +38,36 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
|||
*/
|
||||
@DomainModel(modelDescriptorClasses = SpatialDomainModel.class)
|
||||
@SessionFactory
|
||||
public abstract class AbstractTestStoreRetrieve<G, E extends GeomEntityLike<G>>
|
||||
extends SpatialTestDataProvider {
|
||||
public class StoreAndRetrieveTests extends SpatialTestDataProvider implements SessionFactoryScopeAware {
|
||||
|
||||
protected abstract GeometryEquality<G> getGeometryEquality();
|
||||
SessionFactoryScope scope;
|
||||
|
||||
protected abstract Class<E> getGeomEntityClass();
|
||||
private Map<Integer, Object> stored = new HashMap<>();
|
||||
|
||||
protected abstract E createFrom(TestDataElement element, Dialect dialect);
|
||||
|
||||
private Map<Integer, E> stored = new HashMap<>();
|
||||
|
||||
@Test
|
||||
public void testStoringGeomEntity(SessionFactoryScope scope) {
|
||||
@ParameterizedTest
|
||||
@ValueSource(classes = { GeomEntity.class, JtsGeomEntity.class })
|
||||
public void testStoringGeomEntity(final Class entityClass) {
|
||||
|
||||
//check whether we retrieve exactly what we store
|
||||
scope.inTransaction( this::storeTestObjects );
|
||||
scope.inTransaction( this::retrieveAndCompare );
|
||||
scope.inTransaction( session -> storeTestObjects ( session, entityClass) );
|
||||
scope.inTransaction( session -> retrieveAndCompare( session, entityClass ) );
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void cleanTables(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> session.createQuery( "delete from " + this.getGeomEntityClass()
|
||||
.getCanonicalName() ).executeUpdate() );
|
||||
scope.inTransaction( session -> session.createQuery( "delete from GeomEntity").executeUpdate() );
|
||||
scope.inTransaction( session -> session.createQuery( "delete from JtsGeomEntity").executeUpdate() );
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void retrieveAndCompare(SessionImplementor session) {
|
||||
Query query = session.createQuery( "from " + this.getGeomEntityClass().getCanonicalName() );
|
||||
List<E> results = (List<E>) query.getResultList();
|
||||
private void retrieveAndCompare(SessionImplementor session, Class entityClass) {
|
||||
Query query = session.createQuery( "from " + entityClass.getCanonicalName() );
|
||||
List results = query.getResultList();
|
||||
results.stream().forEach( this::isInStored );
|
||||
}
|
||||
|
||||
private void isInStored(E entity) {
|
||||
E input = stored.get( entity.getId() );
|
||||
private void isInStored(Object entity) {
|
||||
Object input = stored.get( ( (GeomEntityLike) entity ).getId() );
|
||||
assertEquals( entity, input );
|
||||
}
|
||||
|
||||
|
@ -78,14 +77,23 @@ public abstract class AbstractTestStoreRetrieve<G, E extends GeomEntityLike<G>>
|
|||
scope.inTransaction( this::retrieveAndCompareNullGeometry );
|
||||
}
|
||||
|
||||
private void storeTestObjects(SessionImplementor session) {
|
||||
private void storeTestObjects(SessionImplementor session, Class entityClass) {
|
||||
for ( TestDataElement element : testData ) {
|
||||
E entity = createFrom( element, session.getJdbcServices().getDialect() );
|
||||
GeomEntityLike entity = createFrom( element, entityClass, session.getJdbcServices().getDialect() );
|
||||
stored.put( entity.getId(), entity );
|
||||
session.save( entity );
|
||||
}
|
||||
}
|
||||
|
||||
private GeomEntityLike createFrom(TestDataElement element, Class entityClass, Dialect dialect) {
|
||||
if ( entityClass.equals( GeomEntity.class ) ) {
|
||||
return GeomEntity.createFrom( element, dialect );
|
||||
}
|
||||
else {
|
||||
return JtsGeomEntity.createFrom( element, dialect );
|
||||
}
|
||||
}
|
||||
|
||||
private void storeNullGeometry(SessionImplementor session) {
|
||||
GeomEntity entity = new GeomEntity();
|
||||
entity.setId( 1 );
|
||||
|
@ -99,4 +107,9 @@ public abstract class AbstractTestStoreRetrieve<G, E extends GeomEntityLike<G>>
|
|||
assertEquals( 1, entity.getId() );
|
||||
assertNull( entity.getGeom() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectSessionFactoryScope(SessionFactoryScope scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
}
|
|
@ -1,283 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.spatial.HSMessageLogger;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.dialect.hana.HANASpatialDialect;
|
||||
import org.hibernate.spatial.testing.domain.GeomEntity;
|
||||
import org.hibernate.spatial.predicate.GeolatteSpatialPredicates;
|
||||
import org.hibernate.spatial.testing.SpatialDialectMatcher;
|
||||
import org.hibernate.spatial.testing.SpatialFunctionalTestCase;
|
||||
|
||||
import org.hibernate.testing.Skip;
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @see TestJTSSpatialPredicates
|
||||
*/
|
||||
@Skip(condition = SpatialDialectMatcher.class, message = "No Spatial Dialect")
|
||||
@SkipForDialect(value = HANASpatialDialect.class, comment = "The HANA dialect is tested via org.hibernate.spatial.dialect.hana.TestHANASpatialFunctions", jiraKey = "HHH-12426")
|
||||
@Deprecated
|
||||
public class TestGeolatteSpatialPredicates extends SpatialFunctionalTestCase {
|
||||
|
||||
private static final HSMessageLogger LOG = Logger.getMessageLogger(
|
||||
HSMessageLogger.class,
|
||||
TestGeolatteSpatialPredicates.class.getName()
|
||||
);
|
||||
|
||||
protected HSMessageLogger getLogger() {
|
||||
return LOG;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void within() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.within ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getWithin( expectationsFactory.getTestPolygon() );
|
||||
BiFunction<CriteriaBuilder, Root<GeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
GeolatteSpatialPredicates.within(
|
||||
criteriaBuilder,
|
||||
root.get( "geom" ),
|
||||
org.geolatte.geom.jts.JTS.from( expectationsFactory.getTestPolygon() )
|
||||
);
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void filter() throws SQLException {
|
||||
// Map<Integer, Boolean> dbexpected = expectationsFactory.getFilter( expectationsFactory.getTestPolygon() );
|
||||
// BiFunction<CriteriaBuilder, Root<GeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
// GeolatteSpatialPredicates.filter(
|
||||
// criteriaBuilder,
|
||||
// root.get( "geom" ),
|
||||
// org.geolatte.geom.jts.JTS.from( expectationsFactory.getTestPolygon() )
|
||||
// );
|
||||
// retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contains() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.contains ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getContains( expectationsFactory.getTestPolygon() );
|
||||
BiFunction<CriteriaBuilder, Root<GeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
GeolatteSpatialPredicates.contains(
|
||||
criteriaBuilder,
|
||||
root.get( "geom" ),
|
||||
org.geolatte.geom.jts.JTS.from( expectationsFactory.getTestPolygon() )
|
||||
);
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void crosses() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.crosses ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getCrosses( expectationsFactory.getTestPolygon() );
|
||||
BiFunction<CriteriaBuilder, Root<GeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
GeolatteSpatialPredicates.crosses(
|
||||
criteriaBuilder,
|
||||
root.get( "geom" ),
|
||||
org.geolatte.geom.jts.JTS.from( expectationsFactory.getTestPolygon() )
|
||||
);
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void touches() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.touches ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getTouches( expectationsFactory.getTestPolygon() );
|
||||
BiFunction<CriteriaBuilder, Root<GeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
GeolatteSpatialPredicates.touches(
|
||||
criteriaBuilder,
|
||||
root.get( "geom" ),
|
||||
org.geolatte.geom.jts.JTS.from( expectationsFactory.getTestPolygon() )
|
||||
);
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disjoint() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.disjoint ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getDisjoint( expectationsFactory.getTestPolygon() );
|
||||
BiFunction<CriteriaBuilder, Root<GeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
GeolatteSpatialPredicates.disjoint(
|
||||
criteriaBuilder,
|
||||
root.get( "geom" ),
|
||||
org.geolatte.geom.jts.JTS.from( expectationsFactory.getTestPolygon() )
|
||||
);
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eq() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.equals ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getEquals( expectationsFactory.getTestPolygon() );
|
||||
BiFunction<CriteriaBuilder, Root<GeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
GeolatteSpatialPredicates.eq(
|
||||
criteriaBuilder,
|
||||
root.get( "geom" ),
|
||||
org.geolatte.geom.jts.JTS.from( expectationsFactory.getTestPolygon() )
|
||||
);
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intersects() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.intersects ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getIntersects( expectationsFactory.getTestPolygon() );
|
||||
BiFunction<CriteriaBuilder, Root<GeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
GeolatteSpatialPredicates.intersects(
|
||||
criteriaBuilder,
|
||||
root.get( "geom" ),
|
||||
org.geolatte.geom.jts.JTS.from( expectationsFactory.getTestPolygon() )
|
||||
);
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overlaps() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.overlaps ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getOverlaps( expectationsFactory.getTestPolygon() );
|
||||
BiFunction<CriteriaBuilder, Root<GeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
GeolatteSpatialPredicates.overlaps(
|
||||
criteriaBuilder,
|
||||
root.get( "geom" ),
|
||||
org.geolatte.geom.jts.JTS.from( expectationsFactory.getTestPolygon() )
|
||||
);
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dwithin() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.dwithin ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getDwithin( expectationsFactory.getTestPoint(), 30.0 );
|
||||
BiFunction<CriteriaBuilder, Root<GeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
GeolatteSpatialPredicates.distanceWithin(
|
||||
criteriaBuilder,
|
||||
root.get( "geom" ),
|
||||
org.geolatte.geom.jts.JTS.from( expectationsFactory.getTestPoint() ),
|
||||
30.0
|
||||
);
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEmpty() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.isempty ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getIsEmpty();
|
||||
BiFunction<CriteriaBuilder, Root<GeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
GeolatteSpatialPredicates.isEmpty( criteriaBuilder, root.get( "geom" ) );
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isNotEmpty() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.isempty ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getIsNotEmpty();
|
||||
BiFunction<CriteriaBuilder, Root<GeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
GeolatteSpatialPredicates.isNotEmpty( criteriaBuilder, root.get( "geom" ) );
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void havingSRID() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.srid ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.havingSRID( 4326 );
|
||||
BiFunction<CriteriaBuilder, Root<GeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
GeolatteSpatialPredicates.havingSRID( criteriaBuilder, root.get( "geom" ), 4326 );
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
dbexpected = expectationsFactory.havingSRID( 31370 );
|
||||
predicateFactory = (criteriaBuilder, root) ->
|
||||
GeolatteSpatialPredicates.havingSRID( criteriaBuilder, root.get( "geom" ), 31370 );
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
private void retrieveAndCompare(
|
||||
Map<Integer, Boolean> dbexpected,
|
||||
BiFunction<CriteriaBuilder, Root<GeomEntity>, Predicate> predicateFactory) {
|
||||
try (Session session = openSession()) {
|
||||
Transaction tx = null;
|
||||
try {
|
||||
tx = session.beginTransaction();
|
||||
CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<GeomEntity> criteriaQuery = criteriaBuilder.createQuery( GeomEntity.class );
|
||||
Root<GeomEntity> root = criteriaQuery.from( GeomEntity.class );
|
||||
criteriaQuery.select( root )
|
||||
.where( predicateFactory.apply( criteriaBuilder, root ) );
|
||||
List<GeomEntity> list = session.createQuery( criteriaQuery )
|
||||
.getResultList();
|
||||
compare( dbexpected, list );
|
||||
}
|
||||
finally {
|
||||
if ( tx != null ) {
|
||||
tx.rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void compare(Map<Integer, Boolean> dbexpected, List<GeomEntity> list) {
|
||||
int cnt = dbexpected.entrySet()
|
||||
.stream()
|
||||
.filter( Map.Entry::getValue )
|
||||
.reduce( 0, (accumulator, entry) -> {
|
||||
if ( !findInList( entry.getKey(), list ) ) {
|
||||
fail( String.format( "Expected object with id= %d, but not found in result", entry.getKey() ) );
|
||||
}
|
||||
return accumulator + 1;
|
||||
}, Integer::sum );
|
||||
assertEquals( cnt, list.size() );
|
||||
LOG.infof( "Found %d objects within testsuite-suite polygon.", cnt );
|
||||
}
|
||||
|
||||
private boolean findInList(Integer id, List<GeomEntity> list) {
|
||||
return list.stream()
|
||||
.anyMatch( entity -> entity.getId().equals( id ) );
|
||||
}
|
||||
}
|
|
@ -1,278 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.spatial.HSMessageLogger;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.dialect.hana.HANASpatialDialect;
|
||||
import org.hibernate.spatial.testing.domain.JtsGeomEntity;
|
||||
import org.hibernate.spatial.predicate.JTSSpatialPredicates;
|
||||
import org.hibernate.spatial.testing.SpatialDialectMatcher;
|
||||
import org.hibernate.spatial.testing.SpatialFunctionalTestCase;
|
||||
|
||||
import org.hibernate.testing.Skip;
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@Skip(condition = SpatialDialectMatcher.class, message = "No Spatial Dialect")
|
||||
@SkipForDialect(value = HANASpatialDialect.class, comment = "The HANA dialect is tested via org.hibernate.spatial.dialect.hana.TestHANASpatialFunctions", jiraKey = "HHH-12426")
|
||||
@Deprecated
|
||||
public class TestJTSSpatialPredicates extends SpatialFunctionalTestCase {
|
||||
|
||||
private static final HSMessageLogger LOG = Logger.getMessageLogger(
|
||||
HSMessageLogger.class,
|
||||
TestJTSSpatialPredicates.class.getName()
|
||||
);
|
||||
|
||||
protected HSMessageLogger getLogger() {
|
||||
return LOG;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void within() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.within ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getWithin( expectationsFactory.getTestPolygon() );
|
||||
BiFunction<CriteriaBuilder, Root<JtsGeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
JTSSpatialPredicates.within(
|
||||
criteriaBuilder,
|
||||
root.get( "geom" ),
|
||||
expectationsFactory.getTestPolygon()
|
||||
);
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void filter() throws SQLException {
|
||||
// if ( !dialectSupportsFiltering() ) {
|
||||
// LOG.info( "Filtering is not supported by Dialect" );
|
||||
// return;
|
||||
// }
|
||||
// Map<Integer, Boolean> dbexpected = expectationsFactory.getFilter( expectationsFactory.getTestPolygon() );
|
||||
// BiFunction<CriteriaBuilder, Root<JtsGeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
// JTSSpatialPredicates.filter(
|
||||
// criteriaBuilder,
|
||||
// root.get( "geom" ),
|
||||
// expectationsFactory.getTestPolygon()
|
||||
// );
|
||||
// retrieveAndCompare( dbexpected, predicateFactory );
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void contains() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.contains ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getContains( expectationsFactory.getTestPolygon() );
|
||||
BiFunction<CriteriaBuilder, Root<JtsGeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
JTSSpatialPredicates.contains(
|
||||
criteriaBuilder,
|
||||
root.get( "geom" ),
|
||||
expectationsFactory.getTestPolygon()
|
||||
);
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void crosses() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.crosses ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getCrosses( expectationsFactory.getTestPolygon() );
|
||||
BiFunction<CriteriaBuilder, Root<JtsGeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
JTSSpatialPredicates.crosses(
|
||||
criteriaBuilder,
|
||||
root.get( "geom" ),
|
||||
expectationsFactory.getTestPolygon()
|
||||
);
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void touches() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.touches ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getTouches( expectationsFactory.getTestPolygon() );
|
||||
BiFunction<CriteriaBuilder, Root<JtsGeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
JTSSpatialPredicates.touches(
|
||||
criteriaBuilder,
|
||||
root.get( "geom" ),
|
||||
expectationsFactory.getTestPolygon()
|
||||
);
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disjoint() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.disjoint ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getDisjoint( expectationsFactory.getTestPolygon() );
|
||||
BiFunction<CriteriaBuilder, Root<JtsGeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
JTSSpatialPredicates.disjoint(
|
||||
criteriaBuilder,
|
||||
root.get( "geom" ),
|
||||
expectationsFactory.getTestPolygon()
|
||||
);
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eq() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.equals ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getEquals( expectationsFactory.getTestPolygon() );
|
||||
BiFunction<CriteriaBuilder, Root<JtsGeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
JTSSpatialPredicates.eq( criteriaBuilder, root.get( "geom" ), expectationsFactory.getTestPolygon() );
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intersects() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.intersects ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getIntersects( expectationsFactory.getTestPolygon() );
|
||||
BiFunction<CriteriaBuilder, Root<JtsGeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
JTSSpatialPredicates.intersects(
|
||||
criteriaBuilder,
|
||||
root.get( "geom" ),
|
||||
expectationsFactory.getTestPolygon()
|
||||
);
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overlaps() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.overlaps ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getOverlaps( expectationsFactory.getTestPolygon() );
|
||||
BiFunction<CriteriaBuilder, Root<JtsGeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
JTSSpatialPredicates.overlaps(
|
||||
criteriaBuilder,
|
||||
root.get( "geom" ),
|
||||
expectationsFactory.getTestPolygon()
|
||||
);
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dwithin() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.dwithin ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getDwithin( expectationsFactory.getTestPoint(), 30.0 );
|
||||
BiFunction<CriteriaBuilder, Root<JtsGeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
JTSSpatialPredicates.distanceWithin(
|
||||
criteriaBuilder,
|
||||
root.get( "geom" ),
|
||||
expectationsFactory.getTestPoint(),
|
||||
30.0
|
||||
);
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEmpty() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.isempty ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getIsEmpty();
|
||||
BiFunction<CriteriaBuilder, Root<JtsGeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
JTSSpatialPredicates.isEmpty( criteriaBuilder, root.get( "geom" ) );
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isNotEmpty() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.isempty ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getIsNotEmpty();
|
||||
BiFunction<CriteriaBuilder, Root<JtsGeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
JTSSpatialPredicates.isNotEmpty( criteriaBuilder, root.get( "geom" ) );
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void havingSRID() throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.srid ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.havingSRID( 4326 );
|
||||
BiFunction<CriteriaBuilder, Root<JtsGeomEntity>, Predicate> predicateFactory = (criteriaBuilder, root) ->
|
||||
JTSSpatialPredicates.havingSRID( criteriaBuilder, root.get( "geom" ), 4326 );
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
dbexpected = expectationsFactory.havingSRID( 31370 );
|
||||
predicateFactory = (criteriaBuilder, root) ->
|
||||
JTSSpatialPredicates.havingSRID( criteriaBuilder, root.get( "geom" ), 31370 );
|
||||
retrieveAndCompare( dbexpected, predicateFactory );
|
||||
}
|
||||
|
||||
private void retrieveAndCompare(
|
||||
Map<Integer, Boolean> dbexpected,
|
||||
BiFunction<CriteriaBuilder, Root<JtsGeomEntity>, Predicate> predicateFactory) {
|
||||
try (Session session = openSession()) {
|
||||
Transaction tx = null;
|
||||
try {
|
||||
tx = session.beginTransaction();
|
||||
CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<JtsGeomEntity> criteriaQuery = criteriaBuilder.createQuery( JtsGeomEntity.class );
|
||||
Root<JtsGeomEntity> root = criteriaQuery.from( JtsGeomEntity.class );
|
||||
criteriaQuery.select( root )
|
||||
.where( predicateFactory.apply( criteriaBuilder, root ) );
|
||||
List<JtsGeomEntity> list = session.createQuery( criteriaQuery )
|
||||
.getResultList();
|
||||
compare( dbexpected, list );
|
||||
}
|
||||
finally {
|
||||
if ( tx != null ) {
|
||||
tx.rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void compare(Map<Integer, Boolean> dbexpected, List<JtsGeomEntity> list) {
|
||||
int cnt = dbexpected.entrySet()
|
||||
.stream()
|
||||
.filter( Map.Entry::getValue )
|
||||
.reduce( 0, (accumulator, entry) -> {
|
||||
if ( !findInList( entry.getKey(), list ) ) {
|
||||
fail( String.format( "Expected object with id= %d, but not found in result", entry.getKey() ) );
|
||||
}
|
||||
return accumulator + 1;
|
||||
}, Integer::sum );
|
||||
assertEquals( cnt, list.size() );
|
||||
LOG.infof( "Found %d objects within testsuite-suite polygon.", cnt );
|
||||
}
|
||||
|
||||
private boolean findInList(Integer id, List<JtsGeomEntity> list) {
|
||||
return list.stream()
|
||||
.anyMatch( entity -> entity.getId().equals( id ) );
|
||||
}
|
||||
}
|
|
@ -1,756 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.spatial.HSMessageLogger;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.dialect.h2geodb.GeoDBDialect;
|
||||
import org.hibernate.spatial.dialect.hana.HANASpatialDialect;
|
||||
import org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect;
|
||||
import org.hibernate.spatial.testing.SpatialDialectMatcher;
|
||||
import org.hibernate.spatial.testing.SpatialFunctionalTestCase;
|
||||
|
||||
import org.hibernate.testing.Skip;
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
*/
|
||||
@Deprecated
|
||||
public class TestSpatialFunctions extends SpatialFunctionalTestCase {
|
||||
|
||||
private static final HSMessageLogger LOG = Logger.getMessageLogger(
|
||||
HSMessageLogger.class,
|
||||
TestSpatialFunctions.class.getName()
|
||||
);
|
||||
|
||||
protected HSMessageLogger getLogger() {
|
||||
return LOG;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_dimension_on_jts() throws SQLException {
|
||||
dimension( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_dimension_on_geolatte() throws SQLException {
|
||||
dimension( GEOLATTE );
|
||||
}
|
||||
|
||||
public void dimension(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.dimension ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Integer> dbexpected = expectationsFactory.getDimension();
|
||||
String hql = format( "SELECT id, dimension(geom) FROM %s", entityName( pckg ) );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test_asbinary_on_jts() throws SQLException {
|
||||
asbinary( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_asbinary_on_geolatte() throws SQLException {
|
||||
asbinary( GEOLATTE );
|
||||
}
|
||||
|
||||
|
||||
public void asbinary(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.asbinary ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, byte[]> dbexpected = expectationsFactory.getAsBinary();
|
||||
String hql = format( "SELECT id, asbinary(geom) from %s", entityName( pckg ) );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_geometrytype_on_jts() throws SQLException {
|
||||
geometrytype( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_geometrytype_on_geolatte() throws SQLException {
|
||||
geometrytype( GEOLATTE );
|
||||
}
|
||||
|
||||
public void geometrytype(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.geometrytype ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, String> dbexpected = expectationsFactory.getGeometryType();
|
||||
String hql = format(
|
||||
"SELECT id, geometrytype(geom) from %s",
|
||||
entityName( pckg )
|
||||
);
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, entityName( pckg ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_srid_on_jts() throws SQLException {
|
||||
srid( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_srid_on_geolatte() throws SQLException {
|
||||
srid( GEOLATTE );
|
||||
}
|
||||
|
||||
public void srid(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.srid ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Integer> dbexpected = expectationsFactory.getSrid();
|
||||
String hql = format( "SELECT id, srid(geom) from %s", entityName( pckg ) );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_issimple_on_jts() throws SQLException {
|
||||
issimple( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_issimple_on_geolatte() throws SQLException {
|
||||
issimple( GEOLATTE );
|
||||
}
|
||||
|
||||
public void issimple(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.issimple ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getIsSimple();
|
||||
String hql = format( "SELECT id, issimple(geom) from %s", entityName( pckg ) );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isempty_on_jts() throws SQLException {
|
||||
isempty( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isempty_on_geolatte() throws SQLException {
|
||||
isempty( GEOLATTE );
|
||||
}
|
||||
|
||||
public void isempty(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.isempty ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getIsEmpty();
|
||||
String hql = format( "SELECT id, isEmpty(geom) from %s", entityName( pckg ) );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_boundary_on_jts() throws SQLException {
|
||||
boundary( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_boundary_on_geolatte() throws SQLException {
|
||||
boundary( GEOLATTE );
|
||||
}
|
||||
|
||||
public void boundary(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.boundary ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Geometry> dbexpected = expectationsFactory.getBoundary();
|
||||
String hql = format( "SELECT id, boundary(geom) from %s", entityName( pckg ) );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_envelope_on_jts() throws SQLException {
|
||||
envelope( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_envelope_on_geolatte() throws SQLException {
|
||||
envelope( GEOLATTE );
|
||||
}
|
||||
|
||||
public void envelope(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.envelope ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Geometry> dbexpected = expectationsFactory.getEnvelope();
|
||||
String hql = format( "SELECT id, envelope(geom) from %s", entityName( pckg ) );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_within_on_jts() throws SQLException {
|
||||
within( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_within_on_geolatte() throws SQLException {
|
||||
within( GEOLATTE );
|
||||
}
|
||||
|
||||
public void within(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.within ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getWithin( expectationsFactory.getTestPolygon() );
|
||||
String hql = format(
|
||||
"SELECT id, within(geom, :filter) from %s " +
|
||||
"where within(geom, :filter) = true and srid(geom) = %d",
|
||||
entityName( pckg ),
|
||||
expectationsFactory.getTestSrid()
|
||||
);
|
||||
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_equals_on_jts() throws SQLException {
|
||||
equals( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_equals_on_geolatte() throws SQLException {
|
||||
equals( GEOLATTE );
|
||||
}
|
||||
|
||||
public void equals(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.equals ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getEquals( expectationsFactory.getTestPolygon() );
|
||||
String hql = format(
|
||||
"SELECT id, equals(geom, :filter) from %s " +
|
||||
"where equals(geom, :filter) = true and srid(geom) = %d",
|
||||
entityName( pckg ),
|
||||
expectationsFactory.getTestSrid()
|
||||
);
|
||||
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_crosses_on_jts() throws SQLException {
|
||||
crosses( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_crosses_on_geolatte() throws SQLException {
|
||||
crosses( GEOLATTE );
|
||||
}
|
||||
|
||||
public void crosses(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.crosses ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getCrosses( expectationsFactory.getTestPolygon() );
|
||||
String hql = format(
|
||||
"SELECT id, crosses(geom, :filter) from %s " +
|
||||
"where crosses(geom, :filter) = true and srid(geom) = %d",
|
||||
entityName( pckg ),
|
||||
expectationsFactory.getTestSrid()
|
||||
);
|
||||
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_contains_on_jts() throws SQLException {
|
||||
contains( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_contains_on_geolatte() throws SQLException {
|
||||
contains( GEOLATTE );
|
||||
}
|
||||
|
||||
public void contains(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.contains ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getContains( expectationsFactory.getTestPolygon() );
|
||||
String hql = format(
|
||||
"SELECT id, contains(geom, :filter) from %s " +
|
||||
"where contains(geom, :filter) = true and srid(geom) = %d",
|
||||
entityName( pckg ),
|
||||
expectationsFactory.getTestSrid()
|
||||
);
|
||||
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_disjoint_on_jts() throws SQLException {
|
||||
disjoint( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_disjoint_on_geolatte() throws SQLException {
|
||||
disjoint( GEOLATTE );
|
||||
}
|
||||
|
||||
public void disjoint(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.disjoint ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getDisjoint( expectationsFactory.getTestPolygon() );
|
||||
String hql = format(
|
||||
"SELECT id, disjoint(geom, :filter) from %s " +
|
||||
"where disjoint(geom, :filter) = true and srid(geom) = %d",
|
||||
entityName( pckg ),
|
||||
expectationsFactory.getTestSrid()
|
||||
);
|
||||
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_intersects_on_jts() throws SQLException {
|
||||
intersects( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_intersects_on_geolatte() throws SQLException {
|
||||
intersects( GEOLATTE );
|
||||
}
|
||||
|
||||
public void intersects(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.intersects ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getIntersects( expectationsFactory.getTestPolygon() );
|
||||
String hql = format(
|
||||
"SELECT id, intersects(geom, :filter) from %s " +
|
||||
"where intersects(geom, :filter) = true and srid(geom) = %d",
|
||||
entityName( pckg ),
|
||||
expectationsFactory.getTestSrid()
|
||||
);
|
||||
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_overlaps_on_jts() throws SQLException {
|
||||
overlaps( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_overlaps_on_geolatte() throws SQLException {
|
||||
overlaps( GEOLATTE );
|
||||
}
|
||||
|
||||
public void overlaps(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.overlaps ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getOverlaps( expectationsFactory.getTestPolygon() );
|
||||
String hql = format(
|
||||
"SELECT id, overlaps(geom, :filter) from %s where overlaps(geom, :filter) = true and srid(geom) = %d",
|
||||
entityName( pckg ),
|
||||
expectationsFactory.getTestSrid()
|
||||
);
|
||||
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_touches_on_jts() throws SQLException {
|
||||
touches( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_touches_on_geolatte() throws SQLException {
|
||||
touches( GEOLATTE );
|
||||
}
|
||||
|
||||
public void touches(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.touches ) ) {
|
||||
return;
|
||||
}
|
||||
String hql = format(
|
||||
"SELECT id, touches(geom, :filter) from %s where touches(geom, :filter) = true and srid(geom) = %d",
|
||||
entityName( pckg ),
|
||||
expectationsFactory.getTestSrid()
|
||||
);
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getTouches( expectationsFactory.getTestPolygon() );
|
||||
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_relate_on_jts() throws SQLException {
|
||||
relate( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_relate_on_geolatte() throws SQLException {
|
||||
relate( GEOLATTE );
|
||||
}
|
||||
|
||||
public void relate(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.relate ) ) {
|
||||
return;
|
||||
}
|
||||
String matrix = "T*T***T**";
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getRelate(
|
||||
expectationsFactory.getTestPolygon(),
|
||||
matrix
|
||||
);
|
||||
String hql = format(
|
||||
"SELECT id, relate(geom, :filter, :matrix) from %s " +
|
||||
"where relate(geom, :filter, :matrix) = true and srid(geom) = %d",
|
||||
entityName( pckg ),
|
||||
expectationsFactory.getTestSrid()
|
||||
);
|
||||
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
|
||||
params.put( "matrix", matrix );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
|
||||
matrix = "FF*FF****";
|
||||
dbexpected = expectationsFactory.getRelate( expectationsFactory.getTestPolygon(), matrix );
|
||||
params.put( "matrix", matrix );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_distance_on_jts() throws SQLException {
|
||||
distance( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_distance_on_geolatte() throws SQLException {
|
||||
distance( GEOLATTE );
|
||||
}
|
||||
|
||||
public void distance(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.distance ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Double> dbexpected = expectationsFactory.getDistance( expectationsFactory.getTestPolygon() );
|
||||
String hql = format(
|
||||
"SELECT id, distance(geom, :filter) from %s where srid(geom) = %d",
|
||||
entityName( pckg ),
|
||||
expectationsFactory.getTestSrid()
|
||||
);
|
||||
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_buffer_on_jts() throws SQLException {
|
||||
buffer( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_buffer_on_geolatte() throws SQLException {
|
||||
buffer( GEOLATTE );
|
||||
}
|
||||
|
||||
public void buffer(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.buffer ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Geometry> dbexpected = expectationsFactory.getBuffer( Double.valueOf( 1.0 ) );
|
||||
String hql = format(
|
||||
"SELECT id, buffer(geom, :distance) from %s where srid(geom) = %d",
|
||||
entityName( pckg ), expectationsFactory.getTestSrid()
|
||||
);
|
||||
Map<String, Object> params = createQueryParams( "distance", Double.valueOf( 1.0 ) );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
|
||||
}
|
||||
|
||||
// The convexhull tests are skipped for Oracle because of error:
|
||||
// ORA-13276: internal error [Geodetic Geometry too big for Local Transform] in coordinate transformation
|
||||
|
||||
@Test
|
||||
@SkipForDialect(value = OracleSpatial10gDialect.class)
|
||||
public void test_convexhull_on_jts() throws SQLException {
|
||||
convexhull( JTS );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@SkipForDialect(value = OracleSpatial10gDialect.class)
|
||||
public void test_convexhull_on_geolatte() throws SQLException {
|
||||
convexhull( GEOLATTE );
|
||||
}
|
||||
|
||||
public void convexhull(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.convexhull ) || !isSupportedByDialect( SpatialFunction.geomunion )) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Geometry> dbexpected = expectationsFactory.getConvexHull( expectationsFactory.getTestPolygon() );
|
||||
String hql = format(
|
||||
"SELECT id, convexhull(geomunion(geom, :polygon)) from %s where srid(geom) = %d",
|
||||
entityName( pckg ), expectationsFactory.getTestSrid()
|
||||
);
|
||||
Map<String, Object> params = createQueryParams( "polygon", expectationsFactory.getTestPolygon() );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@SkipForDialect(value = GeoDBDialect.class)
|
||||
public void test_intersection_on_jts() throws SQLException {
|
||||
intersection( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
@SkipForDialect(value = GeoDBDialect.class)
|
||||
public void test_intersection_on_geolatte() throws SQLException {
|
||||
intersection( GEOLATTE );
|
||||
}
|
||||
|
||||
//skipped for GeoDBDialect because GeoDB throws exceptions in case the intersection is empty.
|
||||
// (Error message is "Empty Points cannot be represented in WKB")
|
||||
public void intersection(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.intersection ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Geometry> dbexpected = expectationsFactory.getIntersection( expectationsFactory.getTestPolygon() );
|
||||
String hql = format(
|
||||
"SELECT id, intersection(geom, :polygon) from %s where srid(geom) = %d",
|
||||
entityName( pckg ), expectationsFactory.getTestSrid()
|
||||
);
|
||||
Map<String, Object> params = createQueryParams( "polygon", expectationsFactory.getTestPolygon() );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_difference_on_jts() throws SQLException {
|
||||
difference( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_difference_on_geolatte() throws SQLException {
|
||||
difference( GEOLATTE );
|
||||
}
|
||||
|
||||
public void difference(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.difference ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Geometry> dbexpected = expectationsFactory.getDifference( expectationsFactory.getTestPolygon() );
|
||||
String hql = format(
|
||||
"SELECT id, difference(geom, :polygon) from %s where srid(geom) = %d",
|
||||
entityName( pckg ), expectationsFactory.getTestSrid()
|
||||
);
|
||||
Map<String, Object> params = createQueryParams( "polygon", expectationsFactory.getTestPolygon() );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_symdifference_on_jts() throws SQLException {
|
||||
symdifference( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_symdifference_on_geolatte() throws SQLException {
|
||||
symdifference( GEOLATTE );
|
||||
}
|
||||
|
||||
public void symdifference(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.symdifference ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Geometry> dbexpected = expectationsFactory.getSymDifference( expectationsFactory.getTestPolygon() );
|
||||
String hql = format(
|
||||
"SELECT id, symdifference(geom, :polygon) from %s where srid(geom) = %d",
|
||||
entityName( pckg ),
|
||||
expectationsFactory.getTestSrid()
|
||||
);
|
||||
Map<String, Object> params = createQueryParams( "polygon", expectationsFactory.getTestPolygon() );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_geomunion_on_jts() throws SQLException {
|
||||
geomunion( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_geomunion_on_geolatte() throws SQLException {
|
||||
geomunion( GEOLATTE );
|
||||
}
|
||||
|
||||
public void geomunion(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.geomunion ) ) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, Geometry> dbexpected = expectationsFactory.getGeomUnion( expectationsFactory.getTestPolygon() );
|
||||
String hql = format(
|
||||
"SELECT id, geomunion(geom, :polygon) from %s " +
|
||||
"where srid(geom) = %d", entityName( pckg ), expectationsFactory.getTestSrid()
|
||||
);
|
||||
Map<String, Object> params = createQueryParams( "polygon", expectationsFactory.getTestPolygon() );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_dwithin_on_jts() throws SQLException {
|
||||
dwithin( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_dwithin_on_geolatte() throws SQLException {
|
||||
dwithin( GEOLATTE );
|
||||
}
|
||||
|
||||
public void dwithin(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.dwithin ) ) {
|
||||
return;
|
||||
}
|
||||
double distance = 30.0;
|
||||
Map<Integer, Boolean> dbexpected = expectationsFactory.getDwithin(
|
||||
expectationsFactory.getTestPoint(),
|
||||
distance
|
||||
);
|
||||
String hql = format(
|
||||
"SELECT id, dwithin(geom, :filter, :distance) from " +
|
||||
"%s where dwithin(geom, :filter, :distance) = true " +
|
||||
"and srid(geom) = %d", entityName( pckg ), expectationsFactory.getTestSrid()
|
||||
);
|
||||
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPoint() );
|
||||
if ( getDialect() instanceof OracleSpatial10gDialect ) {
|
||||
//because this uses the weird syntax and conventions of SDO_WITHIN_DISTANCE which returns a string (really)
|
||||
// we use a different boolean expression guaranteed to be true, and we set the third parameter to key/value string
|
||||
hql = "SELECT id, issimple(geom) from org.hibernate.spatial.integration.GeomEntity where dwithin(geom, :filter, :distance) = true and srid(geom) = " + expectationsFactory
|
||||
.getTestSrid();
|
||||
params.put( "distance", "distance = 30" );
|
||||
}
|
||||
else {
|
||||
params.put( "distance", 30.0 );
|
||||
}
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
}
|
||||
|
||||
// The transform tests are skipped for HANA because there is no transform definition for SRID 0
|
||||
|
||||
@Test
|
||||
@SkipForDialect(value = HANASpatialDialect.class)
|
||||
public void test_transform_on_jts() throws SQLException {
|
||||
transform( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
@SkipForDialect(value = HANASpatialDialect.class)
|
||||
public void test_transform_on_geolatte() throws SQLException {
|
||||
transform( GEOLATTE );
|
||||
}
|
||||
|
||||
public void transform(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.transform ) ) {
|
||||
return;
|
||||
}
|
||||
int epsg = 4324;
|
||||
Map<Integer, Geometry> dbexpected = expectationsFactory.getTransform( epsg );
|
||||
String hql = format(
|
||||
"SELECT id, transform(geom, :epsg) from %s " +
|
||||
"where srid(geom) = %d", entityName( pckg ), expectationsFactory.getTestSrid()
|
||||
);
|
||||
Map<String, Object> params = createQueryParams( "epsg", Integer.valueOf( epsg ) );
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_extent_on_jts() throws SQLException {
|
||||
extent( JTS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_extent_on_geolatte() throws SQLException {
|
||||
extent( GEOLATTE );
|
||||
}
|
||||
|
||||
public void extent(String pckg) throws SQLException {
|
||||
if ( !isSupportedByDialect( SpatialFunction.extent ) ) {
|
||||
return;
|
||||
}
|
||||
// here we just check if we get a result, and can read it
|
||||
String hql = format(
|
||||
"SELECT id, extent(geom) from %s group by id", entityName( pckg )
|
||||
);
|
||||
Map<Integer, Object> hsreceived = new HashMap<Integer, Object>();
|
||||
doInSession( hql, hsreceived, new HashMap<String, Object>() );
|
||||
}
|
||||
|
||||
public <T> void retrieveHQLResultsAndCompare(Map<Integer, T> dbexpected, String hql, String geometryType) {
|
||||
retrieveHQLResultsAndCompare( dbexpected, hql, null, geometryType );
|
||||
}
|
||||
|
||||
protected <T> void retrieveHQLResultsAndCompare(
|
||||
Map<Integer, T> dbexpected,
|
||||
String hql,
|
||||
Map<String, Object> params,
|
||||
String geometryType) {
|
||||
Map<Integer, T> hsreceived = new HashMap<Integer, T>();
|
||||
doInSession( hql, hsreceived, params );
|
||||
compare( dbexpected, hsreceived, geometryType );
|
||||
}
|
||||
|
||||
private Map<String, Object> createQueryParams(String filterParamName, Object value) {
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put( filterParamName, value );
|
||||
return params;
|
||||
}
|
||||
|
||||
private <T> void doInSession(String hql, Map<Integer, T> result, Map<String, Object> params) {
|
||||
Session session = null;
|
||||
Transaction tx = null;
|
||||
try {
|
||||
session = openSession();
|
||||
tx = session.beginTransaction();
|
||||
Query query = session.createQuery( hql );
|
||||
setParameters( params, query );
|
||||
addQueryResults( result, query );
|
||||
}
|
||||
finally {
|
||||
if ( tx != null ) {
|
||||
tx.rollback();
|
||||
}
|
||||
if ( session != null ) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setParameters(Map<String, Object> params, Query query) {
|
||||
if ( params == null ) {
|
||||
return;
|
||||
}
|
||||
for ( Map.Entry<String, Object> entry : params.entrySet() ) {
|
||||
query.setParameter( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -19,7 +19,6 @@ import java.util.stream.Collectors;
|
|||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.spatial.testing.domain.SpatialDomainModel;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
|
||||
import org.hibernate.tool.schema.TargetType;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
|
@ -30,7 +29,6 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.stringContainsInOrder;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
@DomainModel(modelDescriptorClasses = SpatialDomainModel.class)
|
||||
@SessionFactory
|
||||
|
|
|
@ -36,6 +36,18 @@ import org.junit.jupiter.api.function.Executable;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Dynamic tests for "common" spatial functions.
|
||||
*
|
||||
* <p>
|
||||
* The tests here are dynamic across several dimensions:
|
||||
* <ul>
|
||||
* <li>the spatial function (in so far as actually supported by the dialect)</li>
|
||||
* <li>the Geometry model (JTS or Geolatte)</li>
|
||||
* <li>the name for the function (pre-H6 style, or "st_*" style)</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*/
|
||||
@SuppressWarnings("ALL")
|
||||
@DomainModel(modelDescriptorClasses = SpatialDomainModel.class)
|
||||
@SessionFactory
|
||||
|
|
|
@ -34,6 +34,9 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
|||
import org.geolatte.geom.Geometry;
|
||||
import org.geolatte.geom.codec.Wkt;
|
||||
|
||||
/**
|
||||
* Represents the template from which a Dynamic test can be generated.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class FunctionTestTemplate {
|
||||
|
||||
|
@ -45,7 +48,6 @@ public class FunctionTestTemplate {
|
|||
final private Geometry<?> testGeometry;
|
||||
final private GeomCodec codec;
|
||||
|
||||
|
||||
FunctionTestTemplate(
|
||||
CommonSpatialFunction function,
|
||||
HQLTemplate hqlTemplate,
|
||||
|
@ -98,6 +100,24 @@ public class FunctionTestTemplate {
|
|||
return query;
|
||||
}
|
||||
|
||||
public List executeHQL(SessionFactoryScope scope, String functionName) {
|
||||
final String entity = model.entityClass.getCanonicalName();
|
||||
final AtomicReference<List<Object>> results = new AtomicReference<>();
|
||||
scope.inSession(
|
||||
session -> {
|
||||
Query query = session.createQuery( hqlTemplate.mkHQLString( functionName, entity ) );
|
||||
if ( testGeometry != null ) {
|
||||
query.setParameter(
|
||||
"filter",
|
||||
getModel().from.apply( testGeometry )
|
||||
);
|
||||
}
|
||||
results.set( query.getResultList() );
|
||||
} );
|
||||
return (List) results.get().stream().map( rowObjectMapper::apply ).collect( Collectors.toList() );
|
||||
}
|
||||
|
||||
//only for JtsGeometry because extra mapping of native Geometry object (where needed)
|
||||
private List<Object> map(List<Object> list) {
|
||||
Stream<Object> stream = list
|
||||
.stream().map( this::mapRow );
|
||||
|
@ -114,23 +134,9 @@ public class FunctionTestTemplate {
|
|||
return data;
|
||||
}
|
||||
|
||||
public List executeHQL(SessionFactoryScope scope, String functionName) {
|
||||
final AtomicReference<List> results = new AtomicReference<>();
|
||||
final String entity = model.entityClass.getCanonicalName();
|
||||
scope.inSession(
|
||||
session -> {
|
||||
Query query = session.createQuery( hqlTemplate.mkHQLString( functionName, entity ) );
|
||||
if ( testGeometry != null ) {
|
||||
query.setParameter(
|
||||
"filter",
|
||||
getModel().from.apply( testGeometry )
|
||||
);
|
||||
}
|
||||
results.set( query.getResultList() );
|
||||
} );
|
||||
return (List) results.get().stream().map( rowObjectMapper::apply ).collect( Collectors.toList() );
|
||||
}
|
||||
|
||||
/**
|
||||
* A Builder for a {@code FunctionTestTemplate}
|
||||
*/
|
||||
static class Builder {
|
||||
CommonSpatialFunction function;
|
||||
HQLTemplate hql;
|
||||
|
@ -142,6 +148,7 @@ public class FunctionTestTemplate {
|
|||
this.function = function;
|
||||
}
|
||||
|
||||
//on building the instance, inject the relevant Geometry model and context-specific native->Geometry codec
|
||||
FunctionTestTemplate build(Model model, GeomCodec codec) {
|
||||
if ( hql == null ) {
|
||||
if ( testGeometry != null ) {
|
||||
|
|
|
@ -9,43 +9,47 @@ package org.hibernate.spatial.integration.functions;
|
|||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.hibernate.spatial.GeolatteGeometryType;
|
||||
import org.hibernate.spatial.JTSGeometryType;
|
||||
import org.hibernate.spatial.dialect.postgis.PGGeometryTypeDescriptor;
|
||||
import org.hibernate.spatial.testing.domain.GeomEntity;
|
||||
import org.hibernate.spatial.testing.domain.JtsGeomEntity;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
import org.geolatte.geom.Geometry;
|
||||
import org.geolatte.geom.jts.JTS;
|
||||
|
||||
/**
|
||||
* Captures the Geometry model dimension in the dynamic tests for spatial functions.
|
||||
* <p>
|
||||
* T
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
enum Model {
|
||||
|
||||
|
||||
JTSMODEL(
|
||||
JtsGeomEntity.class,
|
||||
obj -> JTS.from( (org.locationtech.jts.geom.Geometry) obj ),
|
||||
geom -> (Object) JTS.to( geom )
|
||||
JTS::to
|
||||
),
|
||||
GLMODEL(
|
||||
GeomEntity.class,
|
||||
obj -> (Geometry) obj,
|
||||
geom -> geom
|
||||
);
|
||||
|
||||
/**
|
||||
* Test Entity class
|
||||
*/
|
||||
final Class<?> entityClass;
|
||||
final Function<Object, Geometry> to;
|
||||
|
||||
|
||||
/**
|
||||
* How to translate from Geolatte Geometry class to the object class
|
||||
* expected by the entity geom property
|
||||
*/
|
||||
final Function<Geometry, Object> from;
|
||||
|
||||
|
||||
Model(
|
||||
Class<?> entityClass,
|
||||
Function<Object, Geometry> to,
|
||||
Function<Geometry, Object> from
|
||||
) {
|
||||
this.entityClass = entityClass;
|
||||
this.to = to;
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,19 +4,16 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.integration.functions;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Mapper to ensure that the results of the test queries can be compared for equality.
|
||||
*
|
||||
* @param <T> the returned object by the test query
|
||||
*/
|
||||
public interface RowObjectMapper<T> {
|
||||
default Data apply(Object obj) {
|
||||
Object[] row = (Object[]) obj;
|
||||
|
|
|
@ -28,7 +28,9 @@ import static org.geolatte.geom.builder.DSL.polygon;
|
|||
import static org.geolatte.geom.builder.DSL.ring;
|
||||
import static org.geolatte.geom.crs.CoordinateReferenceSystems.WGS84;
|
||||
|
||||
|
||||
/**
|
||||
* Makes available all the builders for FunctionTestTemplate
|
||||
*/
|
||||
public abstract class TestTemplates {
|
||||
|
||||
static FunctionTestTemplate.Builder builder(CommonSpatialFunction function) {
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.integration.geolatte;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.spatial.HSMessageLogger;
|
||||
import org.hibernate.spatial.integration.AbstractTestStoreRetrieve;
|
||||
import org.hibernate.spatial.testing.GeolatteGeometryEquality;
|
||||
import org.hibernate.spatial.testing.GeometryEquality;
|
||||
import org.hibernate.spatial.testing.SpatialDialectMatcher;
|
||||
import org.hibernate.spatial.testing.datareader.TestDataElement;
|
||||
import org.hibernate.spatial.testing.domain.GeomEntity;
|
||||
|
||||
import org.hibernate.testing.Skip;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.geolatte.geom.Geometry;
|
||||
import org.geolatte.geom.codec.WktDecodeException;
|
||||
|
||||
/**
|
||||
* This testsuite-suite class verifies whether the <code>Geometry</code>s retrieved
|
||||
* are equal to the <code>Geometry</code>s stored.
|
||||
*/
|
||||
|
||||
public class TestStoreRetrieveUsingGeolatte extends AbstractTestStoreRetrieve<Geometry, GeomEntity> {
|
||||
|
||||
private static final HSMessageLogger LOG = Logger.getMessageLogger(
|
||||
HSMessageLogger.class,
|
||||
TestStoreRetrieveUsingGeolatte.class.getName()
|
||||
);
|
||||
|
||||
protected HSMessageLogger getLogger() {
|
||||
return LOG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GeometryEquality getGeometryEquality() {
|
||||
return new GeolatteGeometryEquality();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class getGeomEntityClass() {
|
||||
return GeomEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GeomEntity createFrom(
|
||||
TestDataElement element, Dialect dialect) throws WktDecodeException {
|
||||
return GeomEntity.createFrom( element, dialect );
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.integration.jts;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.spatial.HSMessageLogger;
|
||||
import org.hibernate.spatial.integration.AbstractTestStoreRetrieve;
|
||||
import org.hibernate.spatial.testing.GeometryEquality;
|
||||
import org.hibernate.spatial.testing.JTSGeometryEquality;
|
||||
import org.hibernate.spatial.testing.SpatialDialectMatcher;
|
||||
import org.hibernate.spatial.testing.datareader.TestDataElement;
|
||||
import org.hibernate.spatial.testing.domain.JtsGeomEntity;
|
||||
|
||||
import org.hibernate.testing.Skip;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.io.ParseException;
|
||||
|
||||
/**
|
||||
* This testsuite-suite class verifies whether the <code>Geometry</code>s retrieved
|
||||
* are equal to the <code>Geometry</code>s stored.
|
||||
*/
|
||||
public class TestStoreRetrieveUsingJTS extends AbstractTestStoreRetrieve<Geometry, JtsGeomEntity> {
|
||||
|
||||
private static final HSMessageLogger LOG = Logger.getMessageLogger(
|
||||
HSMessageLogger.class,
|
||||
TestStoreRetrieveUsingJTS.class.getName()
|
||||
);
|
||||
|
||||
|
||||
protected HSMessageLogger getLogger() {
|
||||
return LOG;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected GeometryEquality<Geometry> getGeometryEquality() {
|
||||
return new JTSGeometryEquality();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<JtsGeomEntity> getGeomEntityClass() {
|
||||
return JtsGeomEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JtsGeomEntity createFrom(
|
||||
TestDataElement element, Dialect dialect) {
|
||||
try {
|
||||
return JtsGeomEntity.createFrom( element, dialect );
|
||||
}
|
||||
catch (ParseException e) {
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is the main test package. It contains all integration tests that should work (basically) the same
|
||||
* across all supported dialects.
|
||||
*/
|
||||
package org.hibernate.spatial.integration;
|
|
@ -7,13 +7,9 @@
|
|||
|
||||
package org.hibernate.spatial.testing;
|
||||
|
||||
import java.sql.Blob;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.spatial.HSMessageLogger;
|
||||
|
||||
|
@ -33,7 +29,9 @@ import org.locationtech.jts.io.WKTReader;
|
|||
* The expected values are returned as a map of (identifier, expected value) pairs.
|
||||
*
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
* @deprecated Will be removed once we have all the Native SQL templates collected in the NativeSQLTemplates
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractExpectationsFactory {
|
||||
|
||||
public final static String TEST_POLYGON_WKT = "POLYGON((0 0, 50 0, 100 100, 0 100, 0 0))";
|
||||
|
@ -50,14 +48,9 @@ public abstract class AbstractExpectationsFactory {
|
|||
);
|
||||
private final static int TEST_SRID = 4326;
|
||||
private static final int MAX_BYTE_LEN = 1024;
|
||||
private final DataSourceUtils dataSourceUtils;
|
||||
|
||||
public AbstractExpectationsFactory(DataSourceUtils dataSourceUtils) {
|
||||
this.dataSourceUtils = dataSourceUtils;
|
||||
}
|
||||
|
||||
protected DataSourceUtils getDataSourceUtils() {
|
||||
return this.dataSourceUtils;
|
||||
public AbstractExpectationsFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,371 +63,6 @@ public abstract class AbstractExpectationsFactory {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the expected dimensions of all testsuite-suite geometries.
|
||||
*
|
||||
* @return map of identifier, dimension
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Integer> getDimension() throws SQLException {
|
||||
return retrieveExpected( createNativeDimensionSQL(), INTEGER );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected WKT of all testsuite-suite geometries.
|
||||
*
|
||||
* @return map of identifier, WKT-string
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, String> getAsText() throws SQLException {
|
||||
return retrieveExpected( createNativeAsTextStatement(), STRING );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the expected WKB representations of all testsuite-suite geometries
|
||||
*
|
||||
* @return map of identifier, WKB representation
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, byte[]> getAsBinary() throws SQLException {
|
||||
return retrieveExpected( createNativeAsBinaryStatement(), OBJECT );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected type names of all testsuite-suite geometries
|
||||
*
|
||||
* @return map of identifier, type name
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, String> getGeometryType() throws SQLException {
|
||||
return retrieveExpected( createNativeGeometryTypeStatement(), STRING );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected SRID codes of all testsuite-suite geometries
|
||||
*
|
||||
* @return map of identifier, SRID
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Integer> getSrid() throws SQLException {
|
||||
return retrieveExpected( createNativeSridStatement(), INTEGER );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the testsuite-suite geometries are simple
|
||||
*
|
||||
* @return map of identifier and whether testsuite-suite geometry is simple
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getIsSimple() throws SQLException {
|
||||
return retrieveExpected( createNativeIsSimpleStatement(), BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the testsuite-suite geometries are empty
|
||||
*
|
||||
* @return map of identifier and whether testsuite-suite geometry is empty
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getIsEmpty() throws SQLException {
|
||||
return retrieveExpected( createNativeIsEmptyStatement(), BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the testsuite-suite geometries are empty
|
||||
*
|
||||
* @return map of identifier and whether testsuite-suite geometry is empty
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getIsNotEmpty() throws SQLException {
|
||||
return retrieveExpected( createNativeIsNotEmptyStatement(), BOOLEAN );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the expected boundaries of all testsuite-suite geometries
|
||||
*
|
||||
* @return map of identifier and boundary geometry
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getBoundary() throws SQLException {
|
||||
return retrieveExpected( createNativeBoundaryStatement(), GEOMETRY );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected envelopes of all testsuite-suite geometries
|
||||
*
|
||||
* @return map of identifier and envelope
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getEnvelope() throws SQLException {
|
||||
return retrieveExpected( createNativeEnvelopeStatement(), GEOMETRY );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected results of the within operator
|
||||
*
|
||||
* @param geom testsuite-suite geometry
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getWithin(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeWithinStatement( geom ), BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected results of the equals operator
|
||||
*
|
||||
* @param geom
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getEquals(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeEqualsStatement( geom ), BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected results of the crosses operator
|
||||
*
|
||||
* @param geom
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getCrosses(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeCrossesStatement( geom ), BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected results of the contains operator
|
||||
*/
|
||||
public Map<Integer, Boolean> getContains(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeContainsStatement( geom ), BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected results of the disjoint operator
|
||||
*
|
||||
* @param geom
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getDisjoint(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeDisjointStatement( geom ), BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected results of the intersects operator
|
||||
*
|
||||
* @param geom
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getIntersects(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeIntersectsStatement( geom ), BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected results of the touches operator
|
||||
*
|
||||
* @param geom
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getTouches(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeTouchesStatement( geom ), BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected results of the overlaps operator
|
||||
*
|
||||
* @param geom
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getOverlaps(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeOverlapsStatement( geom ), BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected results of the DWithin operator
|
||||
*
|
||||
* @param geom
|
||||
* @param distance
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<Integer, Boolean> getDwithin(Point geom, double distance) throws SQLException {
|
||||
return retrieveExpected( createNativeDwithinStatement( geom, distance ), BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected result of the havingSRID operator
|
||||
*
|
||||
* @param srid the SRID (EPSG code)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<Integer, Boolean> havingSRID(int srid) throws SQLException {
|
||||
return retrieveExpected( createNativeHavingSRIDStatement( srid ), BOOLEAN );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the expected results of the relate operator
|
||||
*
|
||||
* @param geom
|
||||
* @param matrix
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getRelate(Geometry geom, String matrix) throws SQLException {
|
||||
return retrieveExpected( createNativeRelateStatement( geom, matrix ), BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected results for the geometry filter
|
||||
*
|
||||
* @param geom filter Geometry
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<Integer, Boolean> getFilter(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeFilterStatement( geom ), BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected results of the distance function
|
||||
*
|
||||
* @param geom geometry parameter to distance function
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Double> getDistance(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeDistanceStatement( geom ), DOUBLE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected results of the buffering function
|
||||
*
|
||||
* @param distance distance parameter to the buffer function
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getBuffer(Double distance) throws SQLException {
|
||||
return retrieveExpected( createNativeBufferStatement( distance ), GEOMETRY );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected results of the convexhull function
|
||||
*
|
||||
* @param geom geometry with which each testsuite-suite geometry is unioned before convexhull calculation
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getConvexHull(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeConvexHullStatement( geom ), GEOMETRY );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected results of the intersection function
|
||||
*
|
||||
* @param geom parameter to the intersection function
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getIntersection(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeIntersectionStatement( geom ), GEOMETRY );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected results of the difference function
|
||||
*
|
||||
* @param geom parameter to the difference function
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getDifference(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeDifferenceStatement( geom ), GEOMETRY );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected results of the symdifference function
|
||||
*
|
||||
* @param geom parameter to the symdifference function
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
|
||||
public Map<Integer, Geometry> getSymDifference(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeSymDifferenceStatement( geom ), GEOMETRY );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected results of the geomunion function
|
||||
*
|
||||
* @param geom parameter to the geomunion function
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getGeomUnion(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeGeomUnionStatement( geom ), GEOMETRY );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected result of the transform function
|
||||
*
|
||||
* @param epsg
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getTransform(int epsg) throws SQLException {
|
||||
return retrieveExpected( createNativeTransformStatement( epsg ), GEOMETRY );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a statement corresponding to the HQL statement:
|
||||
* "SELECT id, touches(geom, :filter) from GeomEntity where touches(geom, :filter) = true and srid(geom) = 4326"
|
||||
|
@ -583,9 +211,6 @@ public abstract class AbstractExpectationsFactory {
|
|||
public abstract NativeSQLStatement createNativeAsTextStatement();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a statement corresponding to the HQL statement:
|
||||
* "select id, srid(geom) from GeomEntity".
|
||||
|
@ -722,17 +347,6 @@ public abstract class AbstractExpectationsFactory {
|
|||
*/
|
||||
public abstract NativeSQLStatement createNativeHavingSRIDStatement(int srid);
|
||||
|
||||
/**
|
||||
* Creates a connection to the database
|
||||
*
|
||||
* @return a Connection
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
protected Connection createConnection() throws SQLException {
|
||||
return this.dataSourceUtils.getConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a native database object to a JTS <code>Geometry</code> instance
|
||||
*
|
||||
|
@ -776,83 +390,6 @@ public abstract class AbstractExpectationsFactory {
|
|||
}
|
||||
}
|
||||
|
||||
protected <T> Map<Integer, T> retrieveExpected(NativeSQLStatement nativeSQLStatement, int type)
|
||||
throws SQLException {
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet results = null;
|
||||
Connection cn = null;
|
||||
Map<Integer, T> expected = new HashMap<Integer, T>();
|
||||
try {
|
||||
cn = createConnection();
|
||||
preparedStatement = nativeSQLStatement.prepare( cn );
|
||||
LOG.info( "Native SQL is: " + nativeSQLStatement.toString() );
|
||||
|
||||
results = preparedStatement.executeQuery();
|
||||
while ( results.next() ) {
|
||||
int id = results.getInt( 1 );
|
||||
switch ( type ) {
|
||||
case GEOMETRY:
|
||||
expected.put( id, (T) decode( results.getObject( 2 ) ) );
|
||||
break;
|
||||
case STRING:
|
||||
expected.put( id, (T) results.getString( 2 ) );
|
||||
break;
|
||||
case INTEGER: {
|
||||
Long value = Long.valueOf( results.getLong( 2 ) );
|
||||
if ( results.wasNull() ) {
|
||||
value = null; // This is required because the Hibernate BasicExtractor also checks ResultSet#wasNull which can lead to a mismatch between the expected and the actual results
|
||||
}
|
||||
expected.put( id, (T) value );
|
||||
}
|
||||
break;
|
||||
case DOUBLE: {
|
||||
Double value = Double.valueOf( results.getDouble( 2 ) );
|
||||
if ( results.wasNull() ) {
|
||||
value = null; //this is required because SQL Server converts automatically null to 0.0
|
||||
}
|
||||
expected.put( id, (T) value );
|
||||
}
|
||||
break;
|
||||
case BOOLEAN:
|
||||
expected.put( id, (T) Boolean.valueOf( results.getBoolean( 2 ) ) );
|
||||
break;
|
||||
default:
|
||||
T val = (T) results.getObject( 2 );
|
||||
//this code is a hack to deal with Oracle Spatial that returns Blob's for asWKB() function
|
||||
//TODO -- clean up
|
||||
if ( val instanceof Blob ) {
|
||||
val = (T) ( (Blob) val ).getBytes( 1, MAX_BYTE_LEN );
|
||||
}
|
||||
expected.put( id, val );
|
||||
}
|
||||
}
|
||||
return expected;
|
||||
}
|
||||
finally {
|
||||
if ( results != null ) {
|
||||
try {
|
||||
results.close();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
if ( preparedStatement != null ) {
|
||||
try {
|
||||
preparedStatement.close();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
if ( cn != null ) {
|
||||
try {
|
||||
cn.close();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public NativeSQLStatement createNativeSQSStatement(final NativeSQLTemplate template, final String table) {
|
||||
return createNativeSQLStatement( template.mkNativeSQLString( table ) );
|
||||
|
|
|
@ -20,8 +20,6 @@ import java.util.stream.Collectors;
|
|||
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.spatial.integration.SpatialTestDataProvider;
|
||||
import org.hibernate.spatial.testing.HQLTemplate;
|
||||
import org.hibernate.spatial.testing.NativeSQLTemplate;
|
||||
import org.hibernate.spatial.testing.domain.GeomEntity;
|
||||
import org.hibernate.spatial.testing.domain.JtsGeomEntity;
|
||||
import org.hibernate.spatial.testing.domain.SpatialDomainModel;
|
||||
|
|
|
@ -1,413 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.testing;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.hibernate.spatial.HSMessageLogger;
|
||||
import org.hibernate.spatial.testing.datareader.TestData;
|
||||
import org.hibernate.spatial.testing.datareader.TestDataElement;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import org.geolatte.geom.Geometry;
|
||||
import org.geolatte.geom.codec.Wkt;
|
||||
import org.geolatte.geom.codec.WktDecodeException;
|
||||
import org.geolatte.geom.codec.WktDecoder;
|
||||
|
||||
/**
|
||||
* <p>Unit testsuite-suite support class.</p>
|
||||
*
|
||||
* @author Karel Maesen, Geovise BVBA.
|
||||
*/
|
||||
@Deprecated
|
||||
public class DataSourceUtils {
|
||||
|
||||
|
||||
private static final HSMessageLogger LOG = Logger.getMessageLogger(
|
||||
HSMessageLogger.class,
|
||||
DataSourceUtils.class.getName()
|
||||
);
|
||||
|
||||
|
||||
private final SQLExpressionTemplate sqlExpressionTemplate;
|
||||
private final String jdbcDriver;
|
||||
private final String jdbcUrl;
|
||||
private final String jdbcUser;
|
||||
private final String jdbcPass;
|
||||
|
||||
private DataSource dataSource;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for the DataSourceUtils object.
|
||||
* <p/>
|
||||
* <p>The following entities are required in the property file:
|
||||
* <il>
|
||||
* <li> jdbcUrl: jdbc connection URL</li>
|
||||
* <li> dbUsername: username for the database</li>
|
||||
* <li> dbPassword: password for the database</li>
|
||||
* <li> driver: fully-qualified class name for the JDBC Driver</li>
|
||||
* </il>
|
||||
*
|
||||
* @param jdbcDriver
|
||||
* @param jdbcUrl
|
||||
* @param jdbcUser
|
||||
* @param jdbcPass
|
||||
* @param sqlExpressionTemplate SQLExpressionTemplate object that generates SQL statements for this database
|
||||
*/
|
||||
public DataSourceUtils(
|
||||
String jdbcDriver,
|
||||
String jdbcUrl,
|
||||
String jdbcUser,
|
||||
String jdbcPass,
|
||||
SQLExpressionTemplate sqlExpressionTemplate) {
|
||||
this.jdbcDriver = jdbcDriver;
|
||||
this.jdbcUrl = jdbcUrl;
|
||||
this.jdbcUser = jdbcUser;
|
||||
this.jdbcPass = jdbcPass;
|
||||
this.sqlExpressionTemplate = sqlExpressionTemplate;
|
||||
createBasicDataSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor using a properties file
|
||||
*
|
||||
* @param propertyFile
|
||||
* @param template
|
||||
*/
|
||||
public DataSourceUtils(String propertyFile, SQLExpressionTemplate template) {
|
||||
Properties properties = readProperties( propertyFile );
|
||||
this.jdbcUrl = properties.getProperty( "jdbcUrl" );
|
||||
this.jdbcDriver = properties.getProperty( "jdbcDriver" );
|
||||
this.jdbcUser = properties.getProperty( "jdbcUser" );
|
||||
this.jdbcPass = properties.getProperty( "jdbcPass" );
|
||||
this.sqlExpressionTemplate = template;
|
||||
createBasicDataSource();
|
||||
}
|
||||
|
||||
private static int sum(int[] insCounts) {
|
||||
int result = 0;
|
||||
for ( int idx = 0; idx < insCounts.length; idx++ ) {
|
||||
result += insCounts[idx];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Properties readProperties(String propertyFile) {
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = Thread.currentThread().getContextClassLoader().getResourceAsStream( propertyFile );
|
||||
if ( is == null ) {
|
||||
throw new RuntimeException( String.format( "File %s not found on classpath.", propertyFile ) );
|
||||
}
|
||||
Properties properties = new Properties();
|
||||
properties.load( is );
|
||||
return properties;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ( new RuntimeException( e ) );
|
||||
}
|
||||
finally {
|
||||
if ( is != null ) {
|
||||
try {
|
||||
is.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
//nothing to do
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createBasicDataSource() {
|
||||
BasicDataSource bds = new BasicDataSource();
|
||||
bds.setDriverClassName( jdbcDriver );
|
||||
bds.setUrl( jdbcUrl );
|
||||
bds.setUsername( jdbcUser );
|
||||
bds.setPassword( jdbcPass );
|
||||
dataSource = bds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the connections to the database.
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void close() throws SQLException {
|
||||
( (BasicDataSource) dataSource ).close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a DataSource for the configured database.
|
||||
*
|
||||
* @return a DataSource
|
||||
*/
|
||||
public DataSource getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a JDBC connection to the database
|
||||
*
|
||||
* @return a JDBC Connection object
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Connection getConnection() throws SQLException {
|
||||
Connection cn = getDataSource().getConnection();
|
||||
cn.setAutoCommit( false );
|
||||
return cn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all testsuite-suite data from the database
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void deleteTestData() throws SQLException {
|
||||
Connection cn = null;
|
||||
try {
|
||||
cn = getDataSource().getConnection();
|
||||
cn.setAutoCommit( false );
|
||||
PreparedStatement pmt = cn.prepareStatement( "delete from GEOMTEST" );
|
||||
if ( !pmt.execute() ) {
|
||||
int updateCount = pmt.getUpdateCount();
|
||||
LOG.info( "Removing " + updateCount + " rows." );
|
||||
}
|
||||
cn.commit();
|
||||
pmt.close();
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
if ( cn != null ) {
|
||||
cn.close();
|
||||
}
|
||||
}
|
||||
catch (SQLException e) {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void insertTestData(TestData testData) throws SQLException {
|
||||
Connection cn = null;
|
||||
try {
|
||||
cn = getDataSource().getConnection();
|
||||
cn.setAutoCommit( false );
|
||||
Statement stmt = cn.createStatement();
|
||||
for ( TestDataElement testDataElement : testData ) {
|
||||
String sql = sqlExpressionTemplate.toInsertSql( testDataElement );
|
||||
LOG.debug( "adding stmt: " + sql );
|
||||
stmt.addBatch( sql );
|
||||
}
|
||||
int[] insCounts = stmt.executeBatch();
|
||||
cn.commit();
|
||||
stmt.close();
|
||||
LOG.info( "Loaded " + sum( insCounts ) + " rows." );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
if ( cn != null ) {
|
||||
cn.close();
|
||||
}
|
||||
}
|
||||
catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the content of a file into an executable SQL statement.
|
||||
*
|
||||
* @param fileName name of a file containing SQL-statements
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public String parseSqlIn(String fileName) throws IOException {
|
||||
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( fileName );
|
||||
if ( is == null ) {
|
||||
throw new RuntimeException( "File " + fileName + " not found on Classpath." );
|
||||
}
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(
|
||||
new InputStreamReader( is, StandardCharsets.UTF_8 )
|
||||
);
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
BufferedWriter writer = new BufferedWriter( sw );
|
||||
|
||||
for ( int c = reader.read(); c != -1; c = reader.read() ) {
|
||||
writer.write( c );
|
||||
}
|
||||
writer.flush();
|
||||
return sw.toString();
|
||||
}
|
||||
finally {
|
||||
if ( reader != null ) {
|
||||
reader.close();
|
||||
}
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a SQL statement.
|
||||
* <p/>
|
||||
* This is used e.g. to drop/create a spatial index, or update the
|
||||
* geometry metadata statements.
|
||||
*
|
||||
* @param sql the (native) SQL Statement to execute
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void executeStatement(String sql) throws SQLException {
|
||||
Connection cn = null;
|
||||
try {
|
||||
cn = getDataSource().getConnection();
|
||||
cn.setAutoCommit( false );
|
||||
PreparedStatement statement = cn.prepareStatement( sql );
|
||||
LOG.info( "Executing statement: " + sql );
|
||||
statement.execute();
|
||||
cn.commit();
|
||||
statement.close();
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
if ( cn != null ) {
|
||||
cn.close();
|
||||
}
|
||||
}
|
||||
catch (SQLException e) {
|
||||
} //do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operations to fully initialize the
|
||||
*/
|
||||
public void afterCreateSchema() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the geometries of the testsuite-suite objects as raw (i.e. undecoded) objects from the database.
|
||||
*
|
||||
* @param type type of geometry
|
||||
*
|
||||
* @return map of identifier, undecoded geometry object
|
||||
*/
|
||||
public Map<Integer, Object> rawDbObjects(String type) {
|
||||
Map<Integer, Object> map = new HashMap<Integer, Object>();
|
||||
Connection cn = null;
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet results = null;
|
||||
try {
|
||||
cn = getDataSource().getConnection();
|
||||
pstmt = cn.prepareStatement( "select id, geom from geomtest where type = ? order by id" );
|
||||
pstmt.setString( 1, type );
|
||||
results = pstmt.executeQuery();
|
||||
while ( results.next() ) {
|
||||
Integer id = results.getInt( 1 );
|
||||
Object obj = results.getObject( 2 );
|
||||
map.put( id, obj );
|
||||
}
|
||||
|
||||
}
|
||||
catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
if ( results != null ) {
|
||||
results.close();
|
||||
}
|
||||
}
|
||||
catch (SQLException e) {
|
||||
//nothing to do
|
||||
}
|
||||
try {
|
||||
if ( pstmt != null ) {
|
||||
pstmt.close();
|
||||
}
|
||||
}
|
||||
catch (SQLException e) {
|
||||
//nothing to do
|
||||
}
|
||||
try {
|
||||
if ( cn != null ) {
|
||||
cn.close();
|
||||
}
|
||||
}
|
||||
catch (SQLException e) {
|
||||
// nothing we can do.
|
||||
}
|
||||
}
|
||||
return map;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the JTS geometries that are expected of a decoding of the testsuite-suite object's geometry.
|
||||
* <p/>
|
||||
* <p>This method reads the WKT of the testsuite-suite objects and returns the result.</p>
|
||||
*
|
||||
* @param type type of geometry
|
||||
*
|
||||
* @return map of identifier and JTS geometry
|
||||
*/
|
||||
public Map<Integer, Geometry> expectedGeoms(String type, TestData testData) {
|
||||
Map<Integer, Geometry> result = new HashMap<Integer, Geometry>();
|
||||
WktDecoder decoder = Wkt.newDecoder();
|
||||
for ( TestDataElement testDataElement : testData ) {
|
||||
if ( testDataElement.type.equalsIgnoreCase( type ) ) {
|
||||
try {
|
||||
result.put( testDataElement.id, decoder.decode( testDataElement.wkt ) );
|
||||
}
|
||||
catch (WktDecodeException e) {
|
||||
System.out
|
||||
.println(
|
||||
String.format(
|
||||
"Parsing WKT fails for case %d : %s",
|
||||
testDataElement.id,
|
||||
testDataElement.wkt
|
||||
)
|
||||
);
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -13,7 +13,6 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistryExtension;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.testing;
|
||||
|
||||
import org.hibernate.cfg.NotYetImplementedException;
|
||||
import org.hibernate.spatial.testing.datareader.TestDataElement;
|
||||
|
||||
/**
|
||||
* <code>SQLExpressoinTemplate</code>s generate database-specific
|
||||
* SQL statements for a given <code>TestDataElement</code> instance.
|
||||
*
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
*/
|
||||
@Deprecated
|
||||
public interface SQLExpressionTemplate {
|
||||
|
||||
/**
|
||||
* Returns an insert SQL statement for the specified <code>TestDataElement</code>
|
||||
*
|
||||
* @param testDataElement
|
||||
*
|
||||
* @return an insert SQL for testDataElement
|
||||
*/
|
||||
String toInsertSql(TestDataElement testDataElement);
|
||||
|
||||
default String toInsertSql(TestDataElement testDataElement, String tableName) {
|
||||
throw new NotYetImplementedException();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.testing;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
|
||||
import org.hibernate.testing.Skip;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
* creation-date: 1/13/12
|
||||
*
|
||||
* @deprecated Since we no longer require SpatialDialects
|
||||
*/
|
||||
@Deprecated
|
||||
public class SpatialDialectMatcher implements Skip.Matcher {
|
||||
@Override
|
||||
public boolean isMatch() {
|
||||
return !( Dialect.getDialect() instanceof SpatialDialect );
|
||||
}
|
||||
}
|
|
@ -7,27 +7,22 @@
|
|||
|
||||
package org.hibernate.spatial.testing;
|
||||
|
||||
import java.sql.BatchUpdateException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.NotYetImplementedException;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.HSMessageLogger;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.testing.domain.GeomEntity;
|
||||
import org.hibernate.spatial.testing.domain.JtsGeomEntity;
|
||||
import org.hibernate.spatial.testing.datareader.TestData;
|
||||
import org.hibernate.spatial.testing.datareader.TestSupport;
|
||||
import org.hibernate.spatial.testing.domain.GeomEntity;
|
||||
import org.hibernate.spatial.testing.domain.JtsGeomEntity;
|
||||
|
||||
import org.hibernate.testing.AfterClassOnce;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
|
@ -39,7 +34,8 @@ import static org.junit.Assert.fail;
|
|||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
* creation-date: Sep 30, 2010
|
||||
* @deprecated This class will be removed for H6. Currently it no longer works as intended
|
||||
* TODO Remove me!
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class SpatialFunctionalTestCase extends BaseCoreFunctionalTestCase {
|
||||
|
@ -48,23 +44,13 @@ public abstract class SpatialFunctionalTestCase extends BaseCoreFunctionalTestCa
|
|||
protected final static String GEOLATTE = "geolatte";
|
||||
|
||||
protected TestData testData;
|
||||
protected DataSourceUtils dataSourceUtils;
|
||||
protected JTSGeometryEquality geometryEquality;
|
||||
|
||||
protected AbstractExpectationsFactory expectationsFactory;
|
||||
|
||||
/**
|
||||
* Inserts the test data via a direct route (JDBC).
|
||||
*/
|
||||
public void prepareTest() {
|
||||
try {
|
||||
dataSourceUtils.insertTestData( testData );
|
||||
}
|
||||
catch (BatchUpdateException e) {
|
||||
throw new RuntimeException( e.getNextException() );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,34 +98,14 @@ public abstract class SpatialFunctionalTestCase extends BaseCoreFunctionalTestCa
|
|||
private void initializeSpatialTestSupport(ServiceRegistry serviceRegistry) {
|
||||
try {
|
||||
TestSupport support = TestSupportFactories.instance().getTestSupportFactory( getDialect() );
|
||||
expectationsFactory = support.createExpectationsFactory( null );
|
||||
expectationsFactory = null;
|
||||
testData = support.createTestData( TestSupport.TestDataPurpose.StoreRetrieveData );
|
||||
geometryEquality = support.createGeometryEquality();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites the afterSessionFactoryBuilt() method in BaseCoreFunctionalTestCase.
|
||||
* <p/>
|
||||
* Mostly used to register spatial metadata in databases such as Oracle Spatial.
|
||||
*/
|
||||
public void afterSessionFactoryBuilt() {
|
||||
dataSourceUtils.afterCreateSchema();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up the dataSourceUtils
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
@AfterClassOnce
|
||||
public void closeDataSourceUtils() throws SQLException {
|
||||
dataSourceUtils.close();
|
||||
}
|
||||
|
||||
public String getBaseForMappings() {
|
||||
return "";
|
||||
}
|
||||
|
@ -218,9 +184,9 @@ public abstract class SpatialFunctionalTestCase extends BaseCoreFunctionalTestCa
|
|||
.getCanonicalName()
|
||||
);
|
||||
}
|
||||
assertTrue(
|
||||
assertEquals(
|
||||
"Failure on testsuite-suite for case " + id,
|
||||
geometryEquality.test( (Geometry) expected, (Geometry) received )
|
||||
expected, received
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
@ -230,12 +196,10 @@ public abstract class SpatialFunctionalTestCase extends BaseCoreFunctionalTestCa
|
|||
.getCanonicalName()
|
||||
);
|
||||
}
|
||||
assertTrue(
|
||||
assertEquals(
|
||||
"Failure on testsuite-suite for case " + id,
|
||||
geometryEquality.test(
|
||||
(Geometry) expected,
|
||||
expected,
|
||||
org.geolatte.geom.jts.JTS.to( (org.geolatte.geom.Geometry) received )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ package org.hibernate.spatial.testing;
|
|||
import org.hibernate.dialect.CockroachDialect;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.MariaDBDialect;
|
||||
import org.hibernate.dialect.PostgreSQL82Dialect;
|
||||
import org.hibernate.dialect.PostgreSQLDialect;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.testing.datareader.TestSupport;
|
||||
|
@ -45,7 +44,7 @@ public class TestSupportFactories {
|
|||
|
||||
private static Class<? extends TestSupport> getSupportFactoryClass(Dialect dialect) {
|
||||
String canonicalName = dialect.getClass().getCanonicalName();
|
||||
if ( PostgreSQLDialect.class.isAssignableFrom( dialect.getClass() ) ) {
|
||||
if ( PostgreSQLDialect.class.isAssignableFrom( dialect.getClass() ) ) {
|
||||
//this test works because all postgis dialects ultimately derive of the Postgresql82Dialect
|
||||
return PostgisTestSupport.class;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter;
|
|||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.geolatte.geom.Geometry;
|
||||
|
@ -32,6 +33,7 @@ import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
|||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@Ignore
|
||||
public class GeometryConverterTest extends BaseUnitTestCase {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -18,15 +18,10 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.spatial.CommonSpatialFunction;
|
||||
import org.hibernate.spatial.GeomCodec;
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.JTSGeometryEquality;
|
||||
import org.hibernate.spatial.testing.dialects.NativeSQLTemplates;
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -37,10 +32,9 @@ import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
|||
public abstract class TestSupport {
|
||||
|
||||
//TODO -- make this abstract
|
||||
|
||||
public NativeSQLTemplates templates() {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
public Map<CommonSpatialFunction, String> hqlOverrides() {
|
||||
return new HashMap<>();
|
||||
|
@ -51,37 +45,10 @@ public abstract class TestSupport {
|
|||
StoreRetrieveData
|
||||
}
|
||||
|
||||
protected ConfigurationService configurationService;
|
||||
|
||||
|
||||
|
||||
public JTSGeometryEquality createGeometryEquality() {
|
||||
return new JTSGeometryEquality();
|
||||
}
|
||||
|
||||
public abstract TestData createTestData(TestDataPurpose purpose);
|
||||
|
||||
public GeomCodec codec() {
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
};
|
||||
|
||||
public abstract AbstractExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils);
|
||||
|
||||
public abstract SQLExpressionTemplate getSQLExpressionTemplate();
|
||||
|
||||
protected String driver() {
|
||||
return configurationService.getSetting( AvailableSettings.DRIVER, String.class, "" );
|
||||
}
|
||||
|
||||
protected String url() {
|
||||
return configurationService.getSetting( AvailableSettings.URL, String.class, "" );
|
||||
}
|
||||
|
||||
protected String user() {
|
||||
return configurationService.getSetting( AvailableSettings.USER, String.class, "" );
|
||||
}
|
||||
|
||||
protected String passwd() {
|
||||
return configurationService.getSetting( AvailableSettings.PASS, String.class, "" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,31 @@ import java.util.Map;
|
|||
|
||||
import org.hibernate.spatial.CommonSpatialFunction;
|
||||
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.*;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_ASBINARY;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_ASTEXT;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_BOUNDARY;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_BUFFER;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_CONTAINS;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_CONVEXHULL;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_CROSSES;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_DIFFERENCE;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_DIMENSION;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_DISJOINT;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_DISTANCE;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_ENVELOPE;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_EQUALS;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_GEOMETRYTYPE;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_INTERSECTION;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_INTERSECTS;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_ISEMPTY;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_ISSIMPLE;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_OVERLAPS;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_RELATE;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_SRID;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_SYMDIFFERENCE;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_TOUCHES;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_UNION;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_WITHIN;
|
||||
|
||||
public class NativeSQLTemplates {
|
||||
|
||||
|
@ -51,8 +75,14 @@ public class NativeSQLTemplates {
|
|||
sqls.put( ST_BUFFER, "select id, st_buffer(geom, 2) as result from %s" );
|
||||
sqls.put( ST_CONVEXHULL, "select id, st_convexhull(geom) as result from %s" );
|
||||
sqls.put( ST_DIFFERENCE, "select id, st_difference(geom, st_geomfromtext(:filter, 4326)) as result from %s" );
|
||||
sqls.put( ST_INTERSECTION, "select id, st_intersection(geom, st_geomfromtext(:filter, 4326)) as result from %s" );
|
||||
sqls.put( ST_SYMDIFFERENCE, "select id, st_symdifference(geom, st_geomfromtext(:filter, 4326)) as result from %s" );
|
||||
sqls.put(
|
||||
ST_INTERSECTION,
|
||||
"select id, st_intersection(geom, st_geomfromtext(:filter, 4326)) as result from %s"
|
||||
);
|
||||
sqls.put(
|
||||
ST_SYMDIFFERENCE,
|
||||
"select id, st_symdifference(geom, st_geomfromtext(:filter, 4326)) as result from %s"
|
||||
);
|
||||
sqls.put( ST_UNION, "select id, st_union(geom, st_geomfromtext(:filter, 4326)) as result from %s" );
|
||||
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.testing.dialects.cockroachdb;
|
||||
|
||||
import org.hibernate.spatial.dialect.postgis.PGGeometryTypeDescriptor;
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.dialects.postgis.PostgisExpectationsFactory;
|
||||
|
||||
import org.geolatte.geom.jts.JTS;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
|
||||
public class CockroachDBExpectationsFactory extends PostgisExpectationsFactory {
|
||||
|
||||
public CockroachDBExpectationsFactory(DataSourceUtils utils) {
|
||||
super( utils );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry decode(Object object) {
|
||||
org.geolatte.geom.Geometry<?> geometry = PGGeometryTypeDescriptor.INSTANCE_WKB_2.toGeometry( object );
|
||||
return JTS.to( geometry );
|
||||
}
|
||||
}
|
|
@ -7,18 +7,9 @@
|
|||
|
||||
package org.hibernate.spatial.testing.dialects.cockroachdb;
|
||||
|
||||
import org.hibernate.spatial.integration.TestGeolatteSpatialPredicates;
|
||||
import org.hibernate.spatial.integration.TestJTSSpatialPredicates;
|
||||
import org.hibernate.spatial.integration.TestSpatialFunctions;
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.testing.datareader.TestData;
|
||||
import org.hibernate.spatial.testing.datareader.TestSupport;
|
||||
import org.hibernate.spatial.testing.dialects.postgis.PostgisExpressionTemplate;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class CockroachDBTestSupport extends TestSupport {
|
||||
|
||||
|
@ -32,13 +23,4 @@ public class CockroachDBTestSupport extends TestSupport {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils) {
|
||||
return new CockroachDBExpectationsFactory( dataSourceUtils );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLExpressionTemplate getSQLExpressionTemplate() {
|
||||
return new PostgisExpressionTemplate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.testing.dialects.db2;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
|
||||
/**
|
||||
* @author David Adler, Adtech Geospatial
|
||||
* creation-date: 5/22/2014
|
||||
*/
|
||||
public class DB2DataSourceUtils extends DataSourceUtils {
|
||||
|
||||
public DB2DataSourceUtils(
|
||||
String jdbcDriver,
|
||||
String jdbcUrl,
|
||||
String jdbcUser,
|
||||
String jdbcPass,
|
||||
SQLExpressionTemplate sqlExpressionTemplate) {
|
||||
super( jdbcDriver, jdbcUrl, jdbcUser, jdbcPass, sqlExpressionTemplate );
|
||||
}
|
||||
|
||||
private void createIndex() throws SQLException {
|
||||
String sql = "create index idx_spatial_geomtest on geomtest (geom) extend using db2gse.spatial_index(0.1,0,0)";
|
||||
executeStatement( sql );
|
||||
}
|
||||
|
||||
}
|
|
@ -9,14 +9,14 @@ package org.hibernate.spatial.testing.dialects.db2;
|
|||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.spatial.dialect.db2.DB2GeometryTypeDescriptor;
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.NativeSQLStatement;
|
||||
|
||||
import org.geolatte.geom.jts.JTS;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
import org.geolatte.geom.jts.JTS;
|
||||
|
||||
/**
|
||||
* This class provides the DB2 native spatial queries to generate the
|
||||
|
@ -29,8 +29,8 @@ public class DB2ExpectationsFactory extends AbstractExpectationsFactory {
|
|||
|
||||
private final DB2GeometryTypeDescriptor desc = new DB2GeometryTypeDescriptor( 4326 );
|
||||
|
||||
public DB2ExpectationsFactory(DataSourceUtils utils) {
|
||||
super( utils );
|
||||
public DB2ExpectationsFactory() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,7 +41,7 @@ public class DB2ExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getExtent() throws SQLException {
|
||||
return retrieveExpected( createNativeExtentStatement(), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
public NativeSQLStatement createNativeExtentStatement() {
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.testing.dialects.db2;
|
||||
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.testing.datareader.TestDataElement;
|
||||
import org.hibernate.spatial.testing.WktUtility;
|
||||
|
||||
/**
|
||||
* @author David Adler
|
||||
* creation-date: 5/22/2014
|
||||
*/
|
||||
public class DB2ExpressionTemplate implements SQLExpressionTemplate {
|
||||
|
||||
final String SQL_TEMPLATE = "insert into geomtest (id, type, geom) values (%d, '%s', DB2GSE.ST_GEOMETRY('%s', %d))";
|
||||
|
||||
public String toInsertSql(TestDataElement testDataElement) {
|
||||
String wkt = WktUtility.getWkt( testDataElement.wkt );
|
||||
int srid = WktUtility.getSRID( testDataElement.wkt );
|
||||
return String.format(
|
||||
SQL_TEMPLATE,
|
||||
testDataElement.id,
|
||||
testDataElement.type,
|
||||
wkt,
|
||||
srid
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -7,13 +7,9 @@
|
|||
|
||||
package org.hibernate.spatial.testing.dialects.db2;
|
||||
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.testing.datareader.TestData;
|
||||
import org.hibernate.spatial.testing.datareader.TestSupport;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author David Adler, Adtech Geospatial
|
||||
* creation-date: 5/22/2014
|
||||
|
@ -30,13 +26,8 @@ public class DB2TestSupport extends TestSupport {
|
|||
}
|
||||
|
||||
|
||||
public DB2ExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils) {
|
||||
return new DB2ExpectationsFactory( dataSourceUtils );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLExpressionTemplate getSQLExpressionTemplate() {
|
||||
return new DB2ExpressionTemplate();
|
||||
public DB2ExpectationsFactory createExpectationsFactory() {
|
||||
return new DB2ExpectationsFactory();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.hibernate.spatial.testing.dialects.h2geodb;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
|
||||
/**
|
||||
* Extension of the {@link DataSourceUtils} class which sets up an in-memory
|
||||
* GeoDB database. The specified SQL file is used to generate a schema in the
|
||||
* database.
|
||||
*
|
||||
* @author Jan Boonen, Geodan IT b.v.
|
||||
*/
|
||||
public class GeoDBDataSourceUtils extends DataSourceUtils {
|
||||
|
||||
public GeoDBDataSourceUtils(
|
||||
String jdbcDriver, String jdbcUrl, String jdbcUser, String jdbcPass,
|
||||
SQLExpressionTemplate sqlExpressionTemplate)
|
||||
throws SQLException, IOException {
|
||||
super( jdbcDriver, jdbcUrl, jdbcUser, jdbcPass, sqlExpressionTemplate );
|
||||
Connection conn = this.getConnection();
|
||||
initGeoDB( conn );
|
||||
}
|
||||
|
||||
//initialise the GeoDB connection using Reflection
|
||||
// so we do not introduce a compile-time dependency
|
||||
private void initGeoDB(Connection conn) {
|
||||
String errorMsg = "Problem initializing GeoDB.";
|
||||
try {
|
||||
Class<?> geoDB = Thread.currentThread().getContextClassLoader().loadClass( "geodb.GeoDB" );
|
||||
Method m = geoDB.getDeclaredMethod( "InitGeoDB", Connection.class );
|
||||
m.invoke( null, conn );
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException( errorMsg, e );
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
throw new RuntimeException( errorMsg, e );
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw new RuntimeException( errorMsg, e );
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new RuntimeException( errorMsg, e );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,9 +14,9 @@ import org.hibernate.spatial.dialect.h2geodb.GeoDbWkb;
|
|||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.NativeSQLStatement;
|
||||
|
||||
import org.geolatte.geom.jts.JTS;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
import org.geolatte.geom.jts.JTS;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -27,8 +27,8 @@ import org.geolatte.geom.jts.JTS;
|
|||
*/
|
||||
public class GeoDBExpectationsFactory extends AbstractExpectationsFactory {
|
||||
|
||||
public GeoDBExpectationsFactory(GeoDBDataSourceUtils dataSourceUtils) {
|
||||
super( dataSourceUtils );
|
||||
public GeoDBExpectationsFactory() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.testing.dialects.h2geodb;
|
||||
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.testing.datareader.TestDataElement;
|
||||
import org.hibernate.spatial.testing.WktUtility;
|
||||
|
||||
/**
|
||||
* This is the template for insert SQL statements into the geomtest test table
|
||||
* for GeoDB.
|
||||
*
|
||||
* @author Jan Boonen, Geodan IT b.v.
|
||||
*/
|
||||
public class GeoDBExpressionTemplate implements SQLExpressionTemplate {
|
||||
|
||||
static final String SQL_TEMPLATE = "insert into GEOMTEST (id, type, geom) values (%d, '%s', ST_GeomFromText('%s', %d))";
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @seeorg.hibernatespatial.test.SQLExpressionTemplate#toInsertSql(org.
|
||||
* hibernatespatial.test.TestDataElement)
|
||||
*/
|
||||
public String toInsertSql(TestDataElement testDataElement) {
|
||||
String wkt = WktUtility.getWkt( testDataElement.wkt );
|
||||
int srid = WktUtility.getSRID( testDataElement.wkt );
|
||||
return String
|
||||
.format(
|
||||
SQL_TEMPLATE,
|
||||
testDataElement.id,
|
||||
testDataElement.type,
|
||||
wkt,
|
||||
srid
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,251 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.hibernate.spatial.testing.dialects.h2geodb;
|
||||
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.NativeSQLStatement;
|
||||
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
import org.geolatte.geom.ByteBuffer;
|
||||
import org.geolatte.geom.codec.Wkb;
|
||||
import org.geolatte.geom.jts.JTS;
|
||||
|
||||
/**
|
||||
* A Factory class that generates expected {@link org.hibernate.spatial.testing.NativeSQLStatement}s for GeoDB
|
||||
* version < 0.4. These versions don't support storage of the SRID value with
|
||||
* the geometry.
|
||||
*
|
||||
* @author Jan Boonen, Geodan IT b.v.
|
||||
* @deprecated No longer used
|
||||
*/
|
||||
@Deprecated
|
||||
public class GeoDBNoSRIDExpectationsFactory extends AbstractExpectationsFactory {
|
||||
|
||||
public GeoDBNoSRIDExpectationsFactory(GeoDBDataSourceUtils dataSourceUtils) {
|
||||
super( dataSourceUtils );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeAsBinaryStatement() {
|
||||
return createNativeSQLStatement( "select id, ST_AsEWKB(geom) from GEOMTEST" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeAsTextStatement() {
|
||||
return createNativeSQLStatement( "select id, ST_AsText(geom) from GEOMTEST" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeBoundaryStatement() {
|
||||
throw new UnsupportedOperationException(
|
||||
"Method ST_Bounday() is not implemented in the current version of GeoDB."
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeBufferStatement(Double distance) {
|
||||
return createNativeSQLStatement(
|
||||
"select t.id, ST_Buffer(t.geom,?) from GEOMTEST t where ST_SRID(t.geom) = 4326",
|
||||
new Object[] { distance }
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeContainsStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, ST_Contains(t.geom, ST_GeomFromText(?, 4326)) from GEOMTEST t where ST_Contains(t.geom, ST_GeomFromText(?, 4326)) = 1",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeConvexHullStatement(Geometry geom) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Method ST_ConvexHull() is not implemented in the current version of GeoDB."
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeCrossesStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, ST_Crosses(t.geom, ST_GeomFromText(?, 4326)) from GEOMTEST t where ST_Crosses(t.geom, ST_GeomFromText(?, 4326)) = 1",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeDifferenceStatement(Geometry geom) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Method ST_Difference() is not implemented in the current version of GeoDB."
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeDimensionSQL() {
|
||||
throw new UnsupportedOperationException(
|
||||
"Method ST_Dimension() is not implemented in the current version of GeoDB."
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeDisjointStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, ST_Disjoint(t.geom, ST_GeomFromText(?, 4326)) from GEOMTEST t where ST_Disjoint(t.geom, ST_GeomFromText(?, 4326)) = 1",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeTransformStatement(int epsg) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeHavingSRIDStatement(int srid) {
|
||||
return createNativeSQLStatement( "select t.id, (st_srid(t.geom) = " + srid + ") from GeomTest t where ST_SRID(t.geom) = " + srid );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeDistanceStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, st_distance(t.geom, ST_GeomFromText(?, 4326)) from GeomTest t where ST_SRID(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeEnvelopeStatement() {
|
||||
return createNativeSQLStatement( "select id, ST_Envelope(geom) from GEOMTEST" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeEqualsStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, ST_Equals(t.geom, ST_GeomFromText(?, 4326)) from GEOMTEST t where ST_Equals(t.geom, ST_GeomFromText(?, 4326)) = 1",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeFilterStatement(Geometry geom) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Method ST_MBRIntersects() is not implemented in the current version of GeoDB."
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeGeomUnionStatement(Geometry geom) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Method ST_GeomUnion() is not implemented in the current version of GeoDB."
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeGeometryTypeStatement() {
|
||||
return createNativeSQLStatement( "select id, GeometryType(geom) from GEOMTEST" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeIntersectionStatement(Geometry geom) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Method ST_Intersection() is not implemented in the current version of GeoDB."
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeIntersectsStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, ST_Intersects(t.geom, ST_GeomFromText(?, 4326)) from GEOMTEST t where ST_Intersects(t.geom, ST_GeomFromText(?, 4326)) = 1",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeIsEmptyStatement() {
|
||||
return createNativeSQLStatement( "select id, ST_IsEmpty(geom) from GEOMTEST" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeIsNotEmptyStatement() {
|
||||
return createNativeSQLStatement( "select id, not ST_IsEmpty(geom) from GEOMTEST" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeIsSimpleStatement() {
|
||||
return createNativeSQLStatement( "select id, ST_IsSimple(geom) from GEOMTEST" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeOverlapsStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, ST_Overlaps(t.geom, ST_GeomFromText(?, 4326)) from GEOMTEST t where ST_Overlaps(t.geom, ST_GeomFromText(?, 4326)) = 1",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeRelateStatement(
|
||||
Geometry geom,
|
||||
String matrix) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Method ST_Relate() is not implemented in the current version of GeoDB."
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeDwithinStatement(Point geom, double distance) {
|
||||
String sql = "select t.id, st_dwithin(t.geom, ST_GeomFromText(?, 4326), " + distance + " ) from GeomTest t where st_dwithin(t.geom, ST_GeomFromText(?, 4326), " + distance + ") = 'true' and ST_SRID(t.geom) = 4326";
|
||||
return createNativeSQLStatementAllWKTParams( sql, geom.toText() );
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @seeorg.hibernatespatial.test.AbstractExpectationsFactory#
|
||||
* createNativeSridStatement()
|
||||
*/
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeSridStatement() {
|
||||
return createNativeSQLStatement( "select id, ST_SRID(geom) from GEOMTEST" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeSymDifferenceStatement(
|
||||
Geometry geom) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Method ST_SymDifference() is not implemented in the current version of GeoDB."
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeTouchesStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, ST_Touches(t.geom, ST_GeomFromText(?, 4326)) from GEOMTEST t where ST_Touches(t.geom, ST_GeomFromText(?, 4326)) = 1",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeWithinStatement(
|
||||
Geometry testPolygon) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, ST_Within(t.geom, ST_GeomFromText(?, 4326)) from GEOMTEST t where ST_Within(t.geom, ST_GeomFromText(?, 4326)) = 1 and ST_SRID(t.geom) = 4326",
|
||||
testPolygon.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry decode(Object o) {
|
||||
return JTS.to( Wkb.fromWkb( ByteBuffer.from( (byte[]) o ) ) );
|
||||
}
|
||||
}
|
|
@ -7,38 +7,17 @@
|
|||
|
||||
package org.hibernate.spatial.testing.dialects.h2geodb;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.JTSGeometryEquality;
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.testing.datareader.TestData;
|
||||
import org.hibernate.spatial.testing.datareader.TestSupport;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
* creation-date: Oct 2, 2010
|
||||
*/
|
||||
public class GeoDBTestSupport extends TestSupport {
|
||||
|
||||
public DataSourceUtils createDataSourceUtil(ServiceRegistry serviceRegistry) {
|
||||
|
||||
try {
|
||||
return new GeoDBDataSourceUtils( driver(), url(), user(), passwd(), getSQLExpressionTemplate() );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TestData createTestData(TestDataPurpose purpose) {
|
||||
return TestData.fromFile( "h2geodb/test-geodb-data-set.xml" );
|
||||
|
@ -48,17 +27,8 @@ public class GeoDBTestSupport extends TestSupport {
|
|||
return new GeoDBGeometryEquality();
|
||||
}
|
||||
|
||||
public AbstractExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils) {
|
||||
if ( dataSourceUtils instanceof GeoDBDataSourceUtils ) {
|
||||
return new GeoDBExpectationsFactory( (GeoDBDataSourceUtils) dataSourceUtils );
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException( "Requires a GeoDBDataSourceUtils instance" );
|
||||
}
|
||||
}
|
||||
|
||||
public SQLExpressionTemplate getSQLExpressionTemplate() {
|
||||
return new GeoDBExpressionTemplate();
|
||||
public AbstractExpectationsFactory createExpectationsFactory() {
|
||||
return new GeoDBExpectationsFactory();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,26 +7,25 @@
|
|||
|
||||
package org.hibernate.spatial.testing.dialects.hana;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.spatial.dialect.hana.HANASpatialUtils;
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.NativeSQLStatement;
|
||||
|
||||
import org.geolatte.geom.jts.JTS;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
import org.locationtech.jts.geom.Polygon;
|
||||
import org.locationtech.jts.io.ParseException;
|
||||
import org.locationtech.jts.io.WKTReader;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.geolatte.geom.jts.JTS;
|
||||
|
||||
public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
||||
|
||||
public HANAExpectationsFactory(DataSourceUtils utils) {
|
||||
super( utils );
|
||||
public HANAExpectationsFactory() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -284,7 +283,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getAlphaShape(double radius) throws SQLException {
|
||||
return retrieveExpected( createNativeAlphaShapeStatement( radius ), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeAlphaShapeStatement(double radius) {
|
||||
|
@ -302,7 +301,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Double> getArea() throws SQLException {
|
||||
return retrieveExpected( createNativeAreaStatement(), DOUBLE );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeAreaStatement() {
|
||||
|
@ -318,7 +317,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, byte[]> getAsEWKB() throws SQLException {
|
||||
return retrieveExpected( createNativeAsEWKBStatement(), OBJECT );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeAsEWKBStatement() {
|
||||
|
@ -333,7 +332,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, String> getAsEWKT() throws SQLException {
|
||||
return retrieveExpected( createNativeAsEWKTStatement(), STRING );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeAsEWKTStatement() {
|
||||
|
@ -348,7 +347,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, String> getAsGeoJSON() throws SQLException {
|
||||
return retrieveExpected( createNativeAsGeoJSONStatement(), STRING );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeAsGeoJSONStatement() {
|
||||
|
@ -363,7 +362,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, String> getAsSVG() throws SQLException {
|
||||
return retrieveExpected( createNativeAsSVGStatement(), STRING );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeAsSVGStatement() {
|
||||
|
@ -378,7 +377,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, String> getAsSVGAggr() throws SQLException {
|
||||
return retrieveExpected( createNativeAsSVGAggrStatement(), STRING );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeAsSVGAggrStatement() {
|
||||
|
@ -393,7 +392,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, byte[]> getAsWKB() throws SQLException {
|
||||
return retrieveExpected( createNativeAsWKBStatement(), OBJECT );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeAsWKBStatement() {
|
||||
|
@ -408,7 +407,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, String> getAsWKT() throws SQLException {
|
||||
return retrieveExpected( createNativeAsWKTStatement(), STRING );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeAsWKTStatement() {
|
||||
|
@ -423,7 +422,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getCentroid() throws SQLException {
|
||||
return retrieveExpected( createNativeCentroidStatement(), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeCentroidStatement() {
|
||||
|
@ -439,7 +438,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getConvexHullAggr() throws SQLException {
|
||||
return retrieveExpected( createNativeConvexHullAggrStatement(), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeConvexHullAggrStatement() {
|
||||
|
@ -454,7 +453,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Integer> getCoordDim() throws SQLException {
|
||||
return retrieveExpected( createNativeCoordDimStatement(), INTEGER );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeCoordDimStatement() {
|
||||
|
@ -469,7 +468,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getCoveredBy(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeCoveredByStatement( geom ), BOOLEAN );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeCoveredByStatement(Geometry geom) {
|
||||
|
@ -488,7 +487,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getCovers(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeCoversStatement( geom ), BOOLEAN );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeCoversStatement(Geometry geom) {
|
||||
|
@ -507,7 +506,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getEndPoint() throws SQLException {
|
||||
return retrieveExpected( createNativeEndPointStatement(), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeEndPointStatement() {
|
||||
|
@ -523,7 +522,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getEnvelopeAggr() throws SQLException {
|
||||
return retrieveExpected( createNativeEnvelopeAggrStatement(), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeEnvelopeAggrStatement() {
|
||||
|
@ -538,7 +537,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getExteriorRing() throws SQLException {
|
||||
return retrieveExpected( createNativeExteriorRingStatement(), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeExteriorRingStatement() {
|
||||
|
@ -554,7 +553,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getGeomFromEWKB(byte[] ewkb) throws SQLException {
|
||||
return retrieveExpected( createNativeGeomFromEWKBStatement( ewkb ), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeGeomFromEWKBStatement(byte[] ewkb) {
|
||||
|
@ -569,7 +568,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getGeomFromEWKT(String ewkt) throws SQLException {
|
||||
return retrieveExpected( createNativeGeomFromEWKTStatement( ewkt ), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeGeomFromEWKTStatement(String ewkt) {
|
||||
|
@ -584,7 +583,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getGeomFromText(String text) throws SQLException {
|
||||
return retrieveExpected( createNativeGeomFromTextStatement( text ), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeGeomFromTextStatement(String text) {
|
||||
|
@ -599,7 +598,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getGeomFromWKB(byte[] wkb) throws SQLException {
|
||||
return retrieveExpected( createNativeGeomFromWKBStatement( wkb ), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeGeomFromWKBStatement(byte[] wkb) {
|
||||
|
@ -614,7 +613,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getGeomFromWKT(String wkt) throws SQLException {
|
||||
return retrieveExpected( createNativeGeomFromWKTStatement( wkt ), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeGeomFromWKTStatement(String wkt) {
|
||||
|
@ -629,7 +628,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getGeometryN(int n) throws SQLException {
|
||||
return retrieveExpected( createNativeGeometryNStatement( n ), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeGeometryNStatement(int n) {
|
||||
|
@ -647,7 +646,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getInteriorRingN(int n) throws SQLException {
|
||||
return retrieveExpected( createNativeInteriorRingNStatement( n ), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeInteriorRingNStatement(int n) {
|
||||
|
@ -665,7 +665,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getIntersectionAggr() throws SQLException {
|
||||
return retrieveExpected( createNativeIntersectionAggrStatement(), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeIntersectionAggrStatement() {
|
||||
|
@ -680,7 +680,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getIntersectsRect(Point pmin, Point pmax) throws SQLException {
|
||||
return retrieveExpected( createNativeIntersectsRectStatement( pmin, pmax ), BOOLEAN );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeIntersectsRectStatement(Point pmin, Point pmax) {
|
||||
|
@ -700,7 +700,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getIs3D() throws SQLException {
|
||||
return retrieveExpected( createNativeIs3DStatement(), BOOLEAN );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeIs3DStatement() {
|
||||
|
@ -716,7 +716,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getIsClosed() throws SQLException {
|
||||
return retrieveExpected( createNativeIsClosedStatement(), BOOLEAN );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeIsClosedStatement() {
|
||||
|
@ -733,7 +733,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getIsMeasured() throws SQLException {
|
||||
return retrieveExpected( createNativeIsMeasuredStatement(), BOOLEAN );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeIsMeasuredStatement() {
|
||||
|
@ -750,7 +750,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getIsRing() throws SQLException {
|
||||
return retrieveExpected( createNativeIsRingStatement(), BOOLEAN );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeIsRingStatement() {
|
||||
|
@ -767,7 +767,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getIsValid() throws SQLException {
|
||||
return retrieveExpected( createNativeIsValidStatement(), BOOLEAN );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeIsValidStatement() {
|
||||
|
@ -784,7 +784,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Double> getLength() throws SQLException {
|
||||
return retrieveExpected( createNativeLengthStatement(), DOUBLE );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeLengthStatement() {
|
||||
|
@ -801,7 +801,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Double> getM() throws SQLException {
|
||||
return retrieveExpected( createNativeMStatement(), DOUBLE );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeMStatement() {
|
||||
|
@ -818,7 +819,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Double> getMMax() throws SQLException {
|
||||
return retrieveExpected( createNativeMMaxStatement(), DOUBLE );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeMMaxStatement() {
|
||||
|
@ -835,7 +837,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Double> getMMin() throws SQLException {
|
||||
return retrieveExpected( createNativeMMinStatement(), DOUBLE );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeMMinStatement() {
|
||||
|
@ -852,7 +855,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Integer> getNumGeometries() throws SQLException {
|
||||
return retrieveExpected( createNativeNumGeometriesStatement(), INTEGER );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeNumGeometriesStatement() {
|
||||
|
@ -869,7 +873,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Integer> getNumInteriorRing() throws SQLException {
|
||||
return retrieveExpected( createNativeNumInteriorRingStatement(), INTEGER );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeNumInteriorRingStatement() {
|
||||
|
@ -886,7 +891,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Integer> getNumInteriorRings() throws SQLException {
|
||||
return retrieveExpected( createNativeNumInteriorRingsStatement(), INTEGER );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeNumInteriorRingsStatement() {
|
||||
|
@ -903,7 +909,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Integer> getNumPoints() throws SQLException {
|
||||
return retrieveExpected( createNativeNumPointsStatement(), INTEGER );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeNumPointsStatement() {
|
||||
|
@ -920,7 +927,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Boolean> getOrderingEquals(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeOrderingEqualsStatement( geom ), BOOLEAN );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeOrderingEqualsStatement(Geometry geom) {
|
||||
|
@ -939,7 +947,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Double> getPerimeter() throws SQLException {
|
||||
return retrieveExpected( createNativePerimeterStatement(), DOUBLE );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativePerimeterStatement() {
|
||||
|
@ -956,7 +965,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getPointOnSurface() throws SQLException {
|
||||
return retrieveExpected( createNativePointOnSurfaceStatement(), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativePointOnSurfaceStatement() {
|
||||
|
@ -973,7 +983,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getPointN(int n) throws SQLException {
|
||||
return retrieveExpected( createNativePointNStatement( n ), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativePointNStatement(int n) {
|
||||
|
@ -992,7 +1003,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getSnapToGrid() throws SQLException {
|
||||
return retrieveExpected( createNativeSnapToGridStatement(), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeSnapToGridStatement() {
|
||||
|
@ -1009,7 +1021,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getStartPoint() throws SQLException {
|
||||
return retrieveExpected( createNativeStartPointStatement(), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeStartPointStatement() {
|
||||
|
@ -1025,7 +1038,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getUnionAggr() throws SQLException {
|
||||
return retrieveExpected( createNativeUnionAggrStatement(), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeUnionAggrStatement() {
|
||||
|
@ -1040,7 +1054,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Double> getX() throws SQLException {
|
||||
return retrieveExpected( createNativeXStatement(), DOUBLE );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeXStatement() {
|
||||
|
@ -1057,7 +1072,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Double> getXMax() throws SQLException {
|
||||
return retrieveExpected( createNativeXMaxStatement(), DOUBLE );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeXMaxStatement() {
|
||||
|
@ -1074,7 +1090,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Double> getXMin() throws SQLException {
|
||||
return retrieveExpected( createNativeXMinStatement(), DOUBLE );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeXMinStatement() {
|
||||
|
@ -1091,7 +1108,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Double> getY() throws SQLException {
|
||||
return retrieveExpected( createNativeYStatement(), DOUBLE );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeYStatement() {
|
||||
|
@ -1108,7 +1126,8 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Double> getYMax() throws SQLException {
|
||||
return retrieveExpected( createNativeYMaxStatement(), DOUBLE );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeYMaxStatement() {
|
||||
|
@ -1125,7 +1144,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Double> getYMin() throws SQLException {
|
||||
return retrieveExpected( createNativeYMinStatement(), DOUBLE );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeYMinStatement() {
|
||||
|
@ -1142,7 +1161,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Double> getZ() throws SQLException {
|
||||
return retrieveExpected( createNativeZStatement(), DOUBLE );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeZStatement() {
|
||||
|
@ -1159,7 +1178,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Double> getZMax() throws SQLException {
|
||||
return retrieveExpected( createNativeZMaxStatement(), DOUBLE );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeZMaxStatement() {
|
||||
|
@ -1176,7 +1195,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Double> getZMin() throws SQLException {
|
||||
return retrieveExpected( createNativeZMinStatement(), DOUBLE );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeZMinStatement() {
|
||||
|
@ -1193,7 +1212,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getNestedFunctionInner(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeNestedFunctionInnerStatement( geom ), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeNestedFunctionInnerStatement(Geometry geom) {
|
||||
|
@ -1212,7 +1231,7 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Geometry> getNestedFunctionOuter(Geometry geom) throws SQLException {
|
||||
return retrieveExpected( createNativeNestedFunctionOuterStatement( geom ), GEOMETRY );
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
private NativeSQLStatement createNativeNestedFunctionOuterStatement(Geometry geom) {
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.testing.dialects.hana;
|
||||
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.testing.datareader.TestDataElement;
|
||||
import org.hibernate.spatial.testing.WktUtility;
|
||||
|
||||
/**
|
||||
* @author Jonathan Bregler
|
||||
*/
|
||||
public class HANAExpressionTemplate implements SQLExpressionTemplate {
|
||||
|
||||
static final String SQL_TEMPLATE = "insert into geomtest (id, type, geom) values (%d, '%s', ST_GeomFromText('%s', %d))";
|
||||
|
||||
@Override
|
||||
public String toInsertSql(TestDataElement testDataElement) {
|
||||
Integer srid = Integer.valueOf( WktUtility.getSRID( testDataElement.wkt ) );
|
||||
String wkt = WktUtility.getWkt( testDataElement.wkt );
|
||||
return String.format( SQL_TEMPLATE, Integer.valueOf( testDataElement.id ), testDataElement.type, wkt, srid );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -7,13 +7,9 @@
|
|||
|
||||
package org.hibernate.spatial.testing.dialects.hana;
|
||||
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.testing.datareader.TestData;
|
||||
import org.hibernate.spatial.testing.datareader.TestSupport;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
public class HANATestSupport extends TestSupport {
|
||||
|
||||
|
||||
|
@ -22,14 +18,4 @@ public class HANATestSupport extends TestSupport {
|
|||
return TestData.fromFile( "hana/test-hana-data-set.xml" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public HANAExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils) {
|
||||
return new HANAExpectationsFactory( dataSourceUtils );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLExpressionTemplate getSQLExpressionTemplate() {
|
||||
return new HANAExpressionTemplate();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,12 +7,11 @@
|
|||
|
||||
package org.hibernate.spatial.testing.dialects.mariadb;
|
||||
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.dialects.mysql.MySQL8ExpectationsFactory;
|
||||
|
||||
//for now, create the same expectations as for MySQL8
|
||||
public class MariaDBExpectationsFactory extends MySQL8ExpectationsFactory {
|
||||
public MariaDBExpectationsFactory(DataSourceUtils dataSourceUtils) {
|
||||
super( dataSourceUtils );
|
||||
public MariaDBExpectationsFactory() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.testing.dialects.mariadb;
|
||||
|
||||
|
||||
import org.hibernate.spatial.testing.dialects.mysql.MySQL8ExpressionTemplate;
|
||||
|
||||
//for now, just extends the MySQL8 template
|
||||
public class MariaDBExpressionTemplate extends MySQL8ExpressionTemplate {
|
||||
|
||||
}
|
|
@ -8,27 +8,14 @@
|
|||
package org.hibernate.spatial.testing.dialects.mariadb;
|
||||
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.testing.datareader.TestData;
|
||||
import org.hibernate.spatial.testing.datareader.TestSupport;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
public class MariaDBTestSupport extends TestSupport {
|
||||
public class MariaDBTestSupport extends TestSupport {
|
||||
|
||||
@Override
|
||||
public TestData createTestData(TestDataPurpose purpose) {
|
||||
return TestData.fromFile( "mariadb/test-mariadb-functions-data-set.xml" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils) {
|
||||
return new MariaDBExpectationsFactory( dataSourceUtils );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLExpressionTemplate getSQLExpressionTemplate() {
|
||||
return new MariaDBExpressionTemplate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.testing.dialects.mysql;
|
||||
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.NativeSQLStatement;
|
||||
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
* creation-date: 10/9/13
|
||||
*/
|
||||
public class MySQL56ExpectationsFactory extends MySQLExpectationsFactory {
|
||||
|
||||
|
||||
public MySQL56ExpectationsFactory(DataSourceUtils dataSourceUtils) {
|
||||
super( dataSourceUtils );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeTouchesStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, ST_Touches(t.geom, GeomFromText(?, 4326)) from geomtest t where ST_Touches(t.geom, geomFromText(?, 4326)) = 1 and srid(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeOverlapsStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, ST_overlaps(t.geom, GeomFromText(?, 4326)) from geomtest t where ST_Overlaps(t.geom, geomFromText(?, 4326)) = 1 and srid(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeIntersectsStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, ST_Intersects(t.geom, GeomFromText(?, 4326)) from geomtest t where ST_Intersects(t.geom, geomFromText(?, 4326)) = 1 and srid(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeWithinStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, ST_Within(t.geom, GeomFromText(?, 4326)) from geomtest t where ST_Within(t.geom, geomFromText(?, 4326)) = 1 and srid(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeEqualsStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, ST_Equals(t.geom, GeomFromText(?, 4326)) from geomtest t where ST_Equals(t.geom, geomFromText(?, 4326)) = 1 and srid(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeCrossesStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, ST_Crosses(t.geom, GeomFromText(?, 4326)) from geomtest t where ST_Crosses(t.geom, geomFromText(?, 4326)) = 1 and srid(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeContainsStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, ST_Contains(t.geom, GeomFromText(?, 4326)) from geomtest t where ST_Contains(t.geom, geomFromText(?, 4326)) = 1 and srid(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeDisjointStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, ST_Disjoint(t.geom, GeomFromText(?, 4326)) from geomtest t where ST_Disjoint(t.geom, geomFromText(?, 4326)) = 1 and srid(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -7,7 +7,6 @@
|
|||
package org.hibernate.spatial.testing.dialects.mysql;
|
||||
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
|
@ -15,8 +14,4 @@ import org.hibernate.spatial.testing.DataSourceUtils;
|
|||
*/
|
||||
public class MySQL56TestSupport extends MySQLTestSupport {
|
||||
|
||||
@Override
|
||||
public AbstractExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils) {
|
||||
return new MySQL56ExpectationsFactory( dataSourceUtils );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
package org.hibernate.spatial.testing.dialects.mysql;
|
||||
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.NativeSQLStatement;
|
||||
|
||||
import org.geolatte.geom.ByteBuffer;
|
||||
|
@ -24,8 +23,8 @@ import org.locationtech.jts.geom.Point;
|
|||
public class MySQL8ExpectationsFactory extends AbstractExpectationsFactory {
|
||||
|
||||
|
||||
public MySQL8ExpectationsFactory(DataSourceUtils dataSourceUtils) {
|
||||
super( dataSourceUtils );
|
||||
public MySQL8ExpectationsFactory() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.testing.dialects.mysql;
|
||||
|
||||
import org.hibernate.spatial.testing.datareader.TestDataElement;
|
||||
import org.hibernate.spatial.testing.WktUtility;
|
||||
|
||||
/**
|
||||
* Created by Karel Maesen, Geovise BVBA on 2019-03-07.
|
||||
*/
|
||||
public class MySQL8ExpressionTemplate extends MySQLExpressionTemplate {
|
||||
|
||||
static final String SQL_TEMPLATE = "insert into geomtest (id, type, geom) values (%d, '%s', ST_GeomFromText('%s', %d))";
|
||||
|
||||
public String toInsertSql(TestDataElement testDataElement) {
|
||||
String wkt = WktUtility.getWkt( testDataElement.wkt );
|
||||
int srid = WktUtility.getSRID( testDataElement.wkt );
|
||||
return String.format(
|
||||
SQL_TEMPLATE,
|
||||
testDataElement.id,
|
||||
testDataElement.type,
|
||||
wkt,
|
||||
srid
|
||||
);
|
||||
}
|
||||
}
|
|
@ -7,12 +7,8 @@
|
|||
package org.hibernate.spatial.testing.dialects.mysql;
|
||||
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.testing.datareader.TestData;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* Created by Karel Maesen, Geovise BVBA on 2019-03-07.
|
||||
*/
|
||||
|
@ -22,15 +18,4 @@ public class MySQL8TestSupport extends MySQLTestSupport {
|
|||
public TestData createTestData(TestDataPurpose purpose) {
|
||||
return TestData.fromFile( "mysql/test-mysql8-functions-data-set.xml" );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SQLExpressionTemplate getSQLExpressionTemplate() {
|
||||
return new MySQL8ExpressionTemplate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils) {
|
||||
return new MySQL8ExpectationsFactory( dataSourceUtils );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,15 +8,14 @@
|
|||
package org.hibernate.spatial.testing.dialects.mysql;
|
||||
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.NativeSQLStatement;
|
||||
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
import org.geolatte.geom.ByteBuffer;
|
||||
import org.geolatte.geom.codec.Wkb;
|
||||
import org.geolatte.geom.codec.WkbDecoder;
|
||||
import org.geolatte.geom.jts.JTS;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -27,8 +26,8 @@ import org.geolatte.geom.jts.JTS;
|
|||
|
||||
public class MySQLExpectationsFactory extends AbstractExpectationsFactory {
|
||||
|
||||
public MySQLExpectationsFactory(DataSourceUtils dataSourceUtils) {
|
||||
super( dataSourceUtils );
|
||||
public MySQLExpectationsFactory() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.testing.dialects.mysql;
|
||||
|
||||
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.testing.datareader.TestDataElement;
|
||||
import org.hibernate.spatial.testing.WktUtility;
|
||||
|
||||
/**
|
||||
* This is the template for insert SQL statements into the geomtest test table for MySQL.
|
||||
*
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
*/
|
||||
public class MySQLExpressionTemplate implements SQLExpressionTemplate {
|
||||
|
||||
static final String SQL_TEMPLATE = "insert into geomtest (id, type, geom) values (%d, '%s', GeomFromText('%s', %d))";
|
||||
|
||||
public String toInsertSql(TestDataElement testDataElement) {
|
||||
String wkt = WktUtility.getWkt( testDataElement.wkt );
|
||||
int srid = WktUtility.getSRID( testDataElement.wkt );
|
||||
return String.format(
|
||||
SQL_TEMPLATE,
|
||||
testDataElement.id,
|
||||
testDataElement.type,
|
||||
wkt,
|
||||
srid
|
||||
);
|
||||
}
|
||||
}
|
|
@ -9,40 +9,19 @@ package org.hibernate.spatial.testing.dialects.mysql;
|
|||
|
||||
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.JTSGeometryEquality;
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.testing.datareader.TestData;
|
||||
import org.hibernate.spatial.testing.datareader.TestSupport;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
* creation-date: Oct 18, 2010
|
||||
*/
|
||||
public class MySQLTestSupport extends TestSupport {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public AbstractExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils) {
|
||||
return new MySQLExpectationsFactory( dataSourceUtils );
|
||||
}
|
||||
|
||||
@Override
|
||||
public JTSGeometryEquality createGeometryEquality() {
|
||||
return new MySQLGeometryEquality();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TestData createTestData(TestDataPurpose purpose) {
|
||||
return TestData.fromFile( "mysql/test-mysql-functions-data-set.xml" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLExpressionTemplate getSQLExpressionTemplate() {
|
||||
return new MySQLExpressionTemplate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,15 +8,10 @@
|
|||
package org.hibernate.spatial.testing.dialects.oracle;
|
||||
|
||||
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.testing.datareader.TestData;
|
||||
import org.hibernate.spatial.testing.datareader.TestSupport;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
* creation-date: Oct 22, 2010
|
||||
|
@ -28,18 +23,4 @@ public class OracleSDOTestSupport extends TestSupport {
|
|||
return TestData.fromFile( "oracle10g/test-sdo-geometry-data-set-2D.xml", new SDOTestDataReader() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils) {
|
||||
return new SDOGeometryExpectationsFactory( dataSourceUtils );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLExpressionTemplate getSQLExpressionTemplate() {
|
||||
return new SDOGeometryExpressionTemplate();
|
||||
}
|
||||
|
||||
|
||||
public DataSourceUtils createDataSourceUtil(ServiceRegistry serviceRegistry) {
|
||||
return new SDODataSourceUtils( driver(), url(), user(), passwd(), getSQLExpressionTemplate() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.testing.dialects.oracle;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
|
||||
|
||||
public class SDODataSourceUtils extends DataSourceUtils {
|
||||
|
||||
public SDODataSourceUtils(
|
||||
String jdbcDriver,
|
||||
String jdbcUrl,
|
||||
String jdbcUser,
|
||||
String jdbcPass,
|
||||
SQLExpressionTemplate sqlExpressionTemplate) {
|
||||
super( jdbcDriver, jdbcUrl, jdbcUser, jdbcPass, sqlExpressionTemplate );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCreateSchema() {
|
||||
super.afterCreateSchema();
|
||||
try {
|
||||
setGeomMetaDataTo2D();
|
||||
createIndex();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void createIndex() throws SQLException {
|
||||
String sql = "create index idx_spatial_geomtest on geomtest (geom) indextype is mdsys.spatial_index";
|
||||
executeStatement( sql );
|
||||
}
|
||||
|
||||
private void setGeomMetaDataTo2D() throws SQLException {
|
||||
String sql1 = "delete from user_sdo_geom_metadata where TABLE_NAME = 'GEOMTEST'";
|
||||
String sql2 = "insert into user_sdo_geom_metadata values (" +
|
||||
" 'GEOMTEST'," +
|
||||
" 'geom'," +
|
||||
" SDO_DIM_ARRAY(" +
|
||||
" SDO_DIM_ELEMENT('X', -180, 180, 0.00001)," +
|
||||
" SDO_DIM_ELEMENT('Y', -90, 90, 0.00001)" +
|
||||
" )," +
|
||||
" 4326)";
|
||||
executeStatement( sql1 );
|
||||
executeStatement( sql2 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -10,12 +10,11 @@ package org.hibernate.spatial.testing.dialects.oracle;
|
|||
import org.hibernate.spatial.JTSGeometryJavaTypeDescriptor;
|
||||
import org.hibernate.spatial.dialect.oracle.SDOGeometryValueExtractor;
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.NativeSQLStatement;
|
||||
|
||||
import org.geolatte.geom.jts.JTS;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
import org.geolatte.geom.jts.JTS;
|
||||
|
||||
/**
|
||||
* Expectations factory for Oracle 10g (SDOGeometry).
|
||||
|
@ -29,8 +28,8 @@ public class SDOGeometryExpectationsFactory extends AbstractExpectationsFactory
|
|||
null
|
||||
);
|
||||
|
||||
public SDOGeometryExpectationsFactory(DataSourceUtils dataSourceUtils) {
|
||||
super( dataSourceUtils );
|
||||
public SDOGeometryExpectationsFactory() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.testing.dialects.oracle;
|
||||
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.testing.datareader.TestDataElement;
|
||||
|
||||
public class SDOGeometryExpressionTemplate implements SQLExpressionTemplate {
|
||||
|
||||
static final String SQL_TEMPLATE = "insert into geomtest (id, type, geom) values (%d, '%s', %s)";
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public String toInsertSql(TestDataElement testDataElement) {
|
||||
if ( !( testDataElement instanceof SDOTestDataElement ) ) {
|
||||
throw new IllegalArgumentException( "Require SDOTestDataElements" );
|
||||
}
|
||||
SDOTestDataElement sdoTestDataElement = (SDOTestDataElement) testDataElement;
|
||||
return String.format( SQL_TEMPLATE, sdoTestDataElement.id, sdoTestDataElement.type, sdoTestDataElement.sdo );
|
||||
}
|
||||
}
|
|
@ -1,247 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.testing.dialects.postgis;
|
||||
|
||||
import org.hibernate.spatial.HSMessageLogger;
|
||||
import org.hibernate.spatial.dialect.postgis.PGGeometryTypeDescriptor;
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.NativeSQLStatement;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
import org.geolatte.geom.jts.JTS;
|
||||
|
||||
/**
|
||||
* This class provides the expected return values to the testsuite-suite classes in this package.
|
||||
*
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
*/
|
||||
public class PostgisExpectationsFactory extends AbstractExpectationsFactory {
|
||||
|
||||
private static final HSMessageLogger LOG = Logger.getMessageLogger(
|
||||
HSMessageLogger.class,
|
||||
PostgisExpectationsFactory.class.getName()
|
||||
);
|
||||
|
||||
|
||||
public PostgisExpectationsFactory(DataSourceUtils utils) {
|
||||
super( utils );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeTouchesStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, st_touches(t.geom, ST_GeomFromText(?, 4326)) from GeomTest t where st_touches(t.geom, ST_geomFromText(?, 4326)) = 'true' and st_srid(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeOverlapsStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, st_overlaps(t.geom, ST_GeomFromText(?, 4326)) from GeomTest t where st_overlaps(t.geom, ST_GeomFromText(?, 4326)) = 'true' and ST_SRID(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeRelateStatement(Geometry geom, String matrix) {
|
||||
String sql = "select t.id, st_relate(t.geom, ST_GeomFromText(?, 4326), '" + matrix + "' ) from GeomTest t where st_relate(t.geom, ST_GeomFromText(?, 4326), '" + matrix + "') = 'true' and ST_SRID(t.geom) = 4326";
|
||||
return createNativeSQLStatementAllWKTParams( sql, geom.toText() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeDwithinStatement(Point geom, double distance) {
|
||||
String sql = "select t.id, st_dwithin(t.geom, ST_GeomFromText(?, 4326), " + distance + " ) from GeomTest t where st_dwithin(t.geom, ST_GeomFromText(?, 4326), " + distance + ") = 'true' and ST_SRID(t.geom) = 4326";
|
||||
return createNativeSQLStatementAllWKTParams( sql, geom.toText() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeIntersectsStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, st_intersects(t.geom, ST_GeomFromText(?, 4326)) from GeomTest t where st_intersects(t.geom, ST_GeomFromText(?, 4326)) = 'true' and ST_SRID(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeFilterStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, t.geom && ST_GeomFromText(?, 4326) from GeomTest t where st_intersects(t.geom, ST_GeomFromText(?, 4326)) = 'true' and ST_SRID(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeDistanceStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, st_distance(t.geom, ST_GeomFromText(?, 4326)) from GeomTest t where ST_SRID(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeDimensionSQL() {
|
||||
return createNativeSQLStatement( "select id, st_dimension(geom) from geomtest" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeBufferStatement(Double distance) {
|
||||
return createNativeSQLStatement(
|
||||
"select t.id, st_buffer(t.geom,?) from GeomTest t where ST_SRID(t.geom) = 4326",
|
||||
new Object[] { distance }
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeConvexHullStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, st_convexhull(st_union(t.geom, ST_GeomFromText(?, 4326))) from GeomTest t where ST_SRID(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeIntersectionStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, st_intersection(t.geom, ST_GeomFromText(?, 4326)) from GeomTest t where ST_SRID(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeDifferenceStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, st_difference(t.geom, ST_GeomFromText(?, 4326)) from GeomTest t where ST_SRID(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeSymDifferenceStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, st_symdifference(t.geom, ST_GeomFromText(?, 4326)) from GeomTest t where ST_SRID(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeGeomUnionStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, st_union(t.geom, ST_GeomFromText(?, 4326)) from GeomTest t where ST_SRID(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeTransformStatement(int epsg) {
|
||||
return createNativeSQLStatement(
|
||||
"select t.id, st_transform(t.geom," + epsg + ") from GeomTest t where ST_SRID(t.geom) = 4326"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeHavingSRIDStatement(int srid) {
|
||||
return createNativeSQLStatement( "select t.id, (st_srid(t.geom) = " + srid + ") from GeomTest t where ST_SRID(t.geom) = " + srid );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeAsTextStatement() {
|
||||
return createNativeSQLStatement( "select id, st_astext(geom) from geomtest" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeSridStatement() {
|
||||
return createNativeSQLStatement( "select id, ST_SRID(geom) from geomtest" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeIsSimpleStatement() {
|
||||
return createNativeSQLStatement( "select id, st_issimple(geom) from geomtest" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeIsEmptyStatement() {
|
||||
return createNativeSQLStatement( "select id, st_isempty(geom) from geomtest" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeIsNotEmptyStatement() {
|
||||
return createNativeSQLStatement( "select id, not st_isempty(geom) from geomtest" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeBoundaryStatement() {
|
||||
return createNativeSQLStatement( "select id, st_boundary(geom) from geomtest" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeEnvelopeStatement() {
|
||||
return createNativeSQLStatement( "select id, st_envelope(geom) from geomtest" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeAsBinaryStatement() {
|
||||
return createNativeSQLStatement( "select id, st_asbinary(geom) from geomtest" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeGeometryTypeStatement() {
|
||||
return createNativeSQLStatement( "select id, st_GeometryType(geom) from geomtest" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeWithinStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, st_within(t.geom, ST_GeomFromText(?, 4326)) from GeomTest t where st_within(t.geom, ST_GeomFromText(?, 4326)) = 'true' and ST_SRID(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeEqualsStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, st_equals(t.geom, ST_GeomFromText(?, 4326)) from GeomTest t where st_equals(t.geom, ST_GeomFromText(?, 4326)) = 'true' and ST_SRID(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeCrossesStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, st_crosses(t.geom, ST_GeomFromText(?, 4326)) from GeomTest t where st_crosses(t.geom, ST_GeomFromText(?, 4326)) = 'true' and ST_SRID(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeContainsStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, st_contains(t.geom, ST_GeomFromText(?, 4326)) from GeomTest t where st_contains(t.geom, ST_GeomFromText(?, 4326)) = 'true' and ST_SRID(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeSQLStatement createNativeDisjointStatement(Geometry geom) {
|
||||
return createNativeSQLStatementAllWKTParams(
|
||||
"select t.id, st_disjoint(t.geom, ST_GeomFromText(?, 4326)) from GeomTest t where st_disjoint(t.geom, ST_GeomFromText(?, 4326)) = 'true' and ST_SRID(t.geom) = 4326",
|
||||
geom.toText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry decode(Object object) {
|
||||
org.geolatte.geom.Geometry geometry = PGGeometryTypeDescriptor.INSTANCE_WKB_1.toGeometry( object );
|
||||
return JTS.to( geometry );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.testing.dialects.postgis;
|
||||
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.testing.datareader.TestDataElement;
|
||||
|
||||
/**
|
||||
* The template for postgis insert SQL
|
||||
*
|
||||
* @Author Karel Maesen, Geovise BVBA
|
||||
*/
|
||||
public class PostgisExpressionTemplate implements SQLExpressionTemplate {
|
||||
|
||||
static final String SQL_TEMPLATE = "insert into %s (id, type, geom) values (%d, '%s', ST_GeomFromText('%s'))";
|
||||
|
||||
public String toInsertSql(TestDataElement testDataElement, String table) {
|
||||
return String.format(
|
||||
SQL_TEMPLATE,
|
||||
table,
|
||||
testDataElement.id,
|
||||
testDataElement.type,
|
||||
testDataElement.wkt
|
||||
);
|
||||
}
|
||||
|
||||
public String toInsertSql(TestDataElement testDataElement) {
|
||||
return String.format(
|
||||
SQL_TEMPLATE,
|
||||
"geomtest",
|
||||
testDataElement.id,
|
||||
testDataElement.type,
|
||||
testDataElement.wkt
|
||||
);
|
||||
}
|
||||
}
|
|
@ -7,11 +7,8 @@
|
|||
|
||||
package org.hibernate.spatial.testing.dialects.postgis;
|
||||
|
||||
import org.hibernate.spatial.CommonSpatialFunction;
|
||||
import org.hibernate.spatial.testing.dialects.NativeSQLTemplates;
|
||||
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_ISSIMPLE;
|
||||
|
||||
public class PostgisNativeSQLTemplates extends NativeSQLTemplates {
|
||||
public PostgisNativeSQLTemplates() {
|
||||
super();
|
||||
|
|
|
@ -15,8 +15,6 @@ import org.hibernate.spatial.CommonSpatialFunction;
|
|||
import org.hibernate.spatial.GeomCodec;
|
||||
import org.hibernate.spatial.dialect.postgis.PGGeometryTypeDescriptor;
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.testing.datareader.TestData;
|
||||
import org.hibernate.spatial.testing.datareader.TestSupport;
|
||||
import org.hibernate.spatial.testing.dialects.NativeSQLTemplates;
|
||||
|
@ -54,14 +52,6 @@ public class PostgisTestSupport extends TestSupport {
|
|||
}
|
||||
}
|
||||
|
||||
public AbstractExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils) {
|
||||
return new PostgisExpectationsFactory( dataSourceUtils );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLExpressionTemplate getSQLExpressionTemplate() {
|
||||
return new PostgisExpressionTemplate();
|
||||
}
|
||||
|
||||
public GeomCodec codec() {
|
||||
return new GeomCodec() {
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.testing.dialects.sqlserver;
|
||||
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.testing.datareader.TestDataElement;
|
||||
import org.hibernate.spatial.testing.WktUtility;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
*/
|
||||
public class SQLServerExpressionTemplate implements SQLExpressionTemplate {
|
||||
|
||||
static final String SQL_TEMPLATE = "insert into geomtest (id, type, geom) values (%d, '%s', Geometry::STGeomFromText('%s', %d))";
|
||||
|
||||
public String toInsertSql(TestDataElement testDataElement) {
|
||||
int srid = WktUtility.getSRID( testDataElement.wkt );
|
||||
String wkt = WktUtility.getWkt( testDataElement.wkt );
|
||||
return String.format(
|
||||
SQL_TEMPLATE,
|
||||
testDataElement.id,
|
||||
testDataElement.type,
|
||||
wkt,
|
||||
srid
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -7,13 +7,9 @@
|
|||
|
||||
package org.hibernate.spatial.testing.dialects.sqlserver;
|
||||
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.testing.datareader.TestData;
|
||||
import org.hibernate.spatial.testing.datareader.TestSupport;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
* creation-date: Oct 15, 2010
|
||||
|
@ -25,12 +21,8 @@ public class SQLServerTestSupport extends TestSupport {
|
|||
return TestData.fromFile( "test-data-set.xml" );
|
||||
}
|
||||
|
||||
public SqlServerExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils) {
|
||||
return new SqlServerExpectationsFactory( dataSourceUtils );
|
||||
public SqlServerExpectationsFactory createExpectationsFactory() {
|
||||
return new SqlServerExpectationsFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLExpressionTemplate getSQLExpressionTemplate() {
|
||||
return new SQLServerExpressionTemplate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,13 +8,12 @@
|
|||
package org.hibernate.spatial.testing.dialects.sqlserver;
|
||||
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.DataSourceUtils;
|
||||
import org.hibernate.spatial.testing.NativeSQLStatement;
|
||||
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
import org.geolatte.geom.codec.db.sqlserver.Decoders;
|
||||
import org.geolatte.geom.jts.JTS;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -24,8 +23,8 @@ import org.geolatte.geom.jts.JTS;
|
|||
public class SqlServerExpectationsFactory extends AbstractExpectationsFactory {
|
||||
|
||||
|
||||
public SqlServerExpectationsFactory(DataSourceUtils utils) {
|
||||
super( utils );
|
||||
public SqlServerExpectationsFactory() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -99,7 +99,7 @@ public class GeomEntity implements GeomEntityLike<Geometry> {
|
|||
}
|
||||
|
||||
public void setGeomFromWkt(String wkt) {
|
||||
this.geom = Wkt.fromWkt( wkt );
|
||||
this.geom = Wkt.fromWkt( wkt );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,10 +22,10 @@ import org.hibernate.dialect.Dialect;
|
|||
import org.hibernate.spatial.testing.datareader.TestDataElement;
|
||||
|
||||
import org.geolatte.geom.codec.Wkt;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.io.ParseException;
|
||||
import org.geolatte.geom.codec.WktDecoder;
|
||||
import org.geolatte.geom.jts.JTS;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.io.ParseException;
|
||||
|
||||
import static org.hibernate.spatial.integration.DecodeUtil.getWktDecoder;
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class JtsGeomEntity implements GeomEntityLike<Geometry> {
|
|||
|
||||
private Geometry geom;
|
||||
|
||||
public static JtsGeomEntity createFrom(TestDataElement element, Dialect dialect) throws ParseException {
|
||||
public static JtsGeomEntity createFrom(TestDataElement element, Dialect dialect) {
|
||||
WktDecoder decoder = getWktDecoder( dialect );
|
||||
Geometry geom = JTS.to( decoder.decode( element.wkt ) );
|
||||
JtsGeomEntity result = new JtsGeomEntity();
|
||||
|
|
Loading…
Reference in New Issue